Permalink
Browse files

Merge pull request #14315 from zuhao/activemodel_tests_in_random_order

Run ActiveModel test suites in random order.
  • Loading branch information...
2 parents ec23277 + 9ffeb36 commit 29bd586fed5753f5842eadf105042c27734c50ca @senny senny committed Mar 9, 2014
@@ -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
@@ -7,6 +7,10 @@ def setup
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')
@@ -63,12 +63,15 @@ def test_title_confirmation_with_i18n_attribute
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
@@ -19,6 +19,7 @@ def teardown
Person.clear_validators!
I18n.load_path.replace @old_load_path
I18n.backend = @old_backend
+ I18n.backend.reload!
end
def test_full_message_encoding

0 comments on commit 29bd586

Please sign in to comment.