vendredi 15 septembre 2017

Create reusable factory for code generation

Currently I have 130 lines of code with similar Ruby code:

@acquirer = create(:acquirer,
                   name: 'OmniPay Datawire acquirer',
                   country_code: 372,
                   timezone: 'Europe/Dublin'
                  )

@reseller = create(:reseller,
                   name: 'OmniPay Datawire reseller',
                   domain: 'op-res-domain')
@merchant = create(:merchant,
                   name: 'OmniPay Datawire Merchant',
                   state_raw: 2,
                   supported_features: 15,
                   merchant_owner: @reseller,
                   login: 'test',
                   pwd: 'test',
                   notification_url: 'http://ift.tt/2xCJGi9')

@contract = create(:contract_supports_all,
                   name: 'Omnipay Datawire Contract',
                   gateway: 'test',
                   mpi: 'test',
                   acquirer: @acquirer,
                   contract_owner: @reseller,
                   merchant: @merchant,
                   descriptor: 'Descriptor',
                   activated: '1',                       
                  )

How I can create factory method for reusing this code?

I would like to save as much as possible space. Can you show me some very useful example which I can use as solution?

Aucun commentaire:

Enregistrer un commentaire