Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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.
  • Loading branch information...
commit 9ffeb36265928e0fb6de7ffc4b4f3cb3e7fa3581 1 parent 70ff31d
@zuhao zuhao authored
View
32 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
View
4 activemodel/test/cases/translation_test.rb
@@ -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')
View
15 activemodel/test/cases/validations/confirmation_validation_test.rb
@@ -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
View
1  activemodel/test/cases/validations/i18n_validation_test.rb
@@ -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
Please sign in to comment.
Something went wrong with that request. Please try again.