aboutsummaryrefslogtreecommitdiffstats
path: root/activemodel
diff options
context:
space:
mode:
authorZuhao Wan <wanzuhao@gmail.com>2014-03-08 01:59:57 +0800
committerZuhao Wan <wanzuhao@gmail.com>2014-03-10 03:52:51 +0800
commit9ffeb36265928e0fb6de7ffc4b4f3cb3e7fa3581 (patch)
tree45c1d9bdaaf17febc0c42ef611bd75f9b98e7f02 /activemodel
parent70ff31d69f017d1bc674b913865d5a008de0c8a6 (diff)
downloadrails-9ffeb36265928e0fb6de7ffc4b4f3cb3e7fa3581.tar.gz
rails-9ffeb36265928e0fb6de7ffc4b4f3cb3e7fa3581.tar.bz2
rails-9ffeb36265928e0fb6de7ffc4b4f3cb3e7fa3581.zip
Run ActiveModel test suites in random order.
This gets the whole ActiveModel test suites working even if `self.i_suck_and_my_tests_are_order_dependent!` is disabled in `ActiveSupport::TestCase`. Two places are found that potentially leak global state. This patch makes sure states are restored so that none of the changes happen in a single test will be carried over to subsequence tests.
Diffstat (limited to 'activemodel')
-rw-r--r--activemodel/test/cases/secure_password_test.rb32
-rw-r--r--activemodel/test/cases/translation_test.rb4
-rw-r--r--activemodel/test/cases/validations/confirmation_validation_test.rb15
-rw-r--r--activemodel/test/cases/validations/i18n_validation_test.rb1
4 files changed, 39 insertions, 13 deletions
diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb
index 82fd291064..ffc534f0f4 100644
--- a/activemodel/test/cases/secure_password_test.rb
+++ b/activemodel/test/cases/secure_password_test.rb
@@ -147,7 +147,7 @@ class SecurePasswordTest < ActiveModel::TestCase
test "setting a nil password should clear an existing password" do
@existing_user.password = nil
assert_equal nil, @existing_user.password_digest
- end
+ end
test "authenticate" do
@user.password = "secret"
@@ -157,24 +157,42 @@ class SecurePasswordTest < ActiveModel::TestCase
end
test "Password digest cost defaults to bcrypt default cost when min_cost is false" do
+ original_min_cost = ActiveModel::SecurePassword.min_cost
ActiveModel::SecurePassword.min_cost = false
- @user.password = "secret"
- assert_equal BCrypt::Engine::DEFAULT_COST, @user.password_digest.cost
+ begin
+ @user.password = "secret"
+ assert_equal BCrypt::Engine::DEFAULT_COST, @user.password_digest.cost
+ ensure
+ ActiveModel::SecurePassword.min_cost = original_min_cost
+ end
end
test "Password digest cost honors bcrypt cost attribute when min_cost is false" do
+ original_min_cost = ActiveModel::SecurePassword.min_cost
+ original_cost = BCrypt::Engine.cost
+
ActiveModel::SecurePassword.min_cost = false
BCrypt::Engine.cost = 5
- @user.password = "secret"
- assert_equal BCrypt::Engine.cost, @user.password_digest.cost
+ begin
+ @user.password = "secret"
+ assert_equal BCrypt::Engine.cost, @user.password_digest.cost
+ ensure
+ ActiveModel::SecurePassword.min_cost = original_min_cost
+ BCrypt::Engine.cost = original_cost
+ end
end
test "Password digest cost can be set to bcrypt min cost to speed up tests" do
+ original_min_cost = ActiveModel::SecurePassword.min_cost
ActiveModel::SecurePassword.min_cost = true
- @user.password = "secret"
- assert_equal BCrypt::Engine::MIN_COST, @user.password_digest.cost
+ begin
+ @user.password = "secret"
+ assert_equal BCrypt::Engine::MIN_COST, @user.password_digest.cost
+ ensure
+ ActiveModel::SecurePassword.min_cost = original_min_cost
+ end
end
end
diff --git a/activemodel/test/cases/translation_test.rb b/activemodel/test/cases/translation_test.rb
index deb4e1ed0a..cedc812ec7 100644
--- a/activemodel/test/cases/translation_test.rb
+++ b/activemodel/test/cases/translation_test.rb
@@ -7,6 +7,10 @@ class ActiveModelI18nTests < ActiveModel::TestCase
I18n.backend = I18n::Backend::Simple.new
end
+ def teardown
+ I18n.backend.reload!
+ end
+
def test_translated_model_attributes
I18n.backend.store_translations 'en', activemodel: { attributes: { person: { name: 'person name attribute' } } }
assert_equal 'person name attribute', Person.human_attribute_name('name')
diff --git a/activemodel/test/cases/validations/confirmation_validation_test.rb b/activemodel/test/cases/validations/confirmation_validation_test.rb
index 4957ba5d0a..4c3d7a7615 100644
--- a/activemodel/test/cases/validations/confirmation_validation_test.rb
+++ b/activemodel/test/cases/validations/confirmation_validation_test.rb
@@ -63,12 +63,15 @@ class ConfirmationValidationTest < ActiveModel::TestCase
Topic.validates_confirmation_of(:title)
- t = Topic.new("title" => "We should be confirmed","title_confirmation" => "")
- assert t.invalid?
- assert_equal ["doesn't match Test Title"], t.errors[:title_confirmation]
-
- I18n.load_path.replace @old_load_path
- I18n.backend = @old_backend
+ begin
+ t = Topic.new("title" => "We should be confirmed","title_confirmation" => "")
+ assert t.invalid?
+ assert_equal ["doesn't match Test Title"], t.errors[:title_confirmation]
+ ensure
+ I18n.load_path.replace @old_load_path
+ I18n.backend = @old_backend
+ I18n.backend.reload!
+ end
end
test "does not override confirmation reader if present" do
diff --git a/activemodel/test/cases/validations/i18n_validation_test.rb b/activemodel/test/cases/validations/i18n_validation_test.rb
index d10010537e..96084a32ba 100644
--- a/activemodel/test/cases/validations/i18n_validation_test.rb
+++ b/activemodel/test/cases/validations/i18n_validation_test.rb
@@ -19,6 +19,7 @@ class I18nValidationTest < ActiveModel::TestCase
Person.clear_validators!
I18n.load_path.replace @old_load_path
I18n.backend = @old_backend
+ I18n.backend.reload!
end
def test_full_message_encoding