test/test_helper.rb in pagarme-2.1.2 vs test/test_helper.rb in pagarme-2.1.3

- old
+ new

@@ -13,21 +13,24 @@ config.default_cassette_options[:match_requests_on] = [:method, :uri, :host, :path, :query, :body, :headers] config.default_cassette_options[:record] = :new_episodes config.hook_into :webmock end -class Test::Unit::TestCase +class PagarMeTestCase < Test::Unit::TestCase FIXED_API_KEY = 'ak_test_Q2D2qDYGJSyeR1KbI4sLzGACEr73MF' + FIXED_ENCRYPTION_KEY = 'ek_test_ZsiQ61rmOmB8mh055slzu1nxfVbAFa' include Fixtures::Helpers include Assertions def setup - PagarMe.api_key = temporary_api_key + PagarMe.encryption_key = temporary_company.encryption_key.test + PagarMe.api_key = temporary_company.api_key.test end def teardown + PagarMe.encryption_key = nil PagarMe.api_key = nil end protected def ensure_positive_balance @@ -42,28 +45,34 @@ VCR.use_cassette 'TestCase/ensure_waiting_funds' do PagarMe::Transaction.create transaction_with_customer_with_card_params(amount: 10_000_00, installments: 12) end end + def ensure_anticipable_default_recipient + VCR.use_cassette 'TestCase/ensure_anticipable_default_recipient' do + recipient = PagarMe::Recipient.default + recipient.anticipatable_volume_percentage = 100 + recipient.save + end + end + def fixed_api_key + PagarMe.encryption_key = FIXED_ENCRYPTION_KEY PagarMe.api_key = FIXED_API_KEY yield - PagarMe.api_key = temporary_api_key + PagarMe.encryption_key = temporary_company.encryption_key.test + PagarMe.api_key = temporary_company.api_key.test end - def temporary_api_key - return FIXED_API_KEY - - # TODO: Unfortunately, it's right now impossible to create - # temporary companies properly pre-configured to run all tests - VCR.use_cassette 'TestCase/tmp_company_api_key' do + def temporary_company + VCR.use_cassette 'TestCase/tmp_company' do PagarMe.api_key = FIXED_API_KEY - Company.temporary.api_key.test + PagarMe::Company.temporary end end # Monkey Patch that adds VCR everywhere def self.should(description, &block) - cassette_name = "#{ self.name.split('::').last }/should_#{ description.gsub /\s+/, '_' }" - super(description){ VCR.use_cassette(cassette_name){ self.instance_exec &block } } + cassette_name = "#{ self.name.split('::').last }/should_#{ description.gsub(/\s+/, '_') }" + super(description){ VCR.use_cassette(cassette_name){ self.instance_exec(&block) } } end end