test/lib/workarea/klarna/gateway/request_test.rb in workarea-klarna-1.0.0.beta1 vs test/lib/workarea/klarna/gateway/request_test.rb in workarea-klarna-1.0.0.beta2
- old
+ new
@@ -2,12 +2,32 @@
module Workarea
module Klarna
class Gateway
class RequestTest < TestCase
- setup :configure_klarna_data, :payment
+ setup :clear_env, :configure_klarna_data, :payment
+ teardown :reset_env
+ def clear_env
+ @env_na_username = ENV['WORKAREA_KLARNA_NA_USERNAME']
+ @env_na_password = ENV['WORKAREA_KLARNA_NA_PASSWORD']
+ @env_eur_username = ENV['WORKAREA_KLARNA_EUR_USERNAME']
+ @env_eur_password = ENV['WORKAREA_KLARNA_EUR_PASSWORD']
+
+ ENV.delete('WORKAREA_KLARNA_NA_USERNAME')
+ ENV.delete('WORKAREA_KLARNA_NA_PASSWORD')
+ ENV.delete('WORKAREA_KLARNA_EUR_USERNAME')
+ ENV.delete('WORKAREA_KLARNA_EUR_PASSWORD')
+ end
+
+ def reset_env
+ ENV['WORKAREA_KLARNA_NA_USERNAME'] = @env_na_username
+ ENV['WORKAREA_KLARNA_NA_PASSWORD'] = @env_na_password
+ ENV['WORKAREA_KLARNA_EUR_USERNAME'] = @env_eur_username
+ ENV['WORKAREA_KLARNA_EUR_PASSWORD'] = @env_eur_password
+ end
+
def order
@order ||= create_order
end
def payment
@@ -41,15 +61,12 @@
assert_equal(Workarea.config.klarna_na_username, request.username)
payment.set_address(supported_eur_address)
assert_equal(Workarea.config.klarna_eur_username, request.username)
- @env_eur_user = ENV['WORKAREA_KLARNA_EUR_USERNAME']
ENV['WORKAREA_KLARNA_EUR_USERNAME'] = 'env_eur_user'
assert_equal('env_eur_user', request.username)
- ensure
- ENV['WORKAREA_KLARNA_EUR_USERNAME'] = @env_eur_user
end
def test_password
assert_nil(request.password)
@@ -60,14 +77,11 @@
assert_equal(Workarea.config.klarna_na_password, request.password)
payment.set_address(supported_eur_address)
assert_equal(Workarea.config.klarna_eur_password, request.password)
- @env_eur_pass = ENV['WORKAREA_KLARNA_EUR_PASSWORD']
ENV['WORKAREA_KLARNA_EUR_PASSWORD'] = 'env_eur_user'
assert_equal('env_eur_user', request.password)
- ensure
- ENV['WORKAREA_KLARNA_EUR_PASSWORD'] = @env_eur_pass
end
def test_continent_key
assert_nil(request.continent_key)