From 2908fd512faa53e6de9549bc4cfc9f6920f02290 Mon Sep 17 00:00:00 2001 From: Artur Beljajev Date: Wed, 4 Apr 2018 15:26:51 +0300 Subject: [PATCH] Reset setting after each test --- test/models/contact/identical_test.rb | 23 +++++++++++----------- test/models/contact/postal_address_test.rb | 5 +++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/test/models/contact/identical_test.rb b/test/models/contact/identical_test.rb index 43df8b7d2..61e960a7e 100644 --- a/test/models/contact/identical_test.rb +++ b/test/models/contact/identical_test.rb @@ -13,10 +13,15 @@ class ContactIdenticalTest < ActiveSupport::TestCase ] setup do + @original_address_processing = Setting.address_processing @contact = contacts(:william) @identical = contacts(:identical_to_william) end + teardown do + Setting.address_processing = @original_address_processing + end + def test_returns_identical assert_equal @identical, @contact.identical(@identical.registrar) end @@ -33,30 +38,24 @@ class ContactIdenticalTest < ActiveSupport::TestCase assert_nil @contact.identical(@identical.registrar) end - def test_takes_address_into_account_when_processing_enabled + def test_takes_address_into_account_when_address_processing_is_on + Setting.address_processing = true + Contact.address_attribute_names.each do |attribute| previous_value = @identical.public_send(attribute) @identical.update_attribute(attribute, 'other') - - Contact.stub :address_processing?, true do - assert_nil @contact.identical(@identical.registrar) - end - + assert_nil @contact.identical(@identical.registrar) @identical.update_attribute(attribute, previous_value) end end - def test_ignores_address_when_processing_disabled + def test_ignores_address_when_address_processing_is_off Setting.address_processing = false Contact.address_attribute_names.each do |attribute| previous_value = @identical.public_send(attribute) @identical.update_attribute(attribute, 'other') - - Contact.stub :address_processing?, false do - assert_equal @identical, @contact.identical(@identical.registrar) - end - + assert_equal @identical, @contact.identical(@identical.registrar) @identical.update_attribute(attribute, previous_value) end end diff --git a/test/models/contact/postal_address_test.rb b/test/models/contact/postal_address_test.rb index 24a5c8002..baf06d9f4 100644 --- a/test/models/contact/postal_address_test.rb +++ b/test/models/contact/postal_address_test.rb @@ -2,9 +2,14 @@ require 'test_helper' class ContactPostalAddressTest < ActiveSupport::TestCase setup do + @original_address_processing = Setting.address_processing @contact = contacts(:john) end + teardown do + Setting.address_processing = @original_address_processing + end + def test_invalid_if_country_code_is_invalid_and_address_processing_is_on Setting.address_processing = true @contact.country_code = 'invalid'