mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
70ff31d69f
commit
9ffeb36265
4 changed files with 39 additions and 13 deletions
|
@ -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
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
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 @@ 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')
|
||||
|
|
|
@ -63,12 +63,15 @@ class ConfirmationValidationTest < ActiveModel::TestCase
|
|||
|
||||
Topic.validates_confirmation_of(:title)
|
||||
|
||||
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 @@ 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
|
||||
|
|
Loading…
Reference in a new issue