diff options
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/errors_test.rb | 12 | ||||
-rw-r--r-- | activemodel/test/cases/helper.rb | 5 | ||||
-rw-r--r-- | activemodel/test/cases/validations/length_validation_test.rb | 20 |
3 files changed, 28 insertions, 9 deletions
diff --git a/activemodel/test/cases/errors_test.rb b/activemodel/test/cases/errors_test.rb index da142ea2c0..f781a0017f 100644 --- a/activemodel/test/cases/errors_test.rb +++ b/activemodel/test/cases/errors_test.rb @@ -212,6 +212,12 @@ class ErrorsTest < ActiveModel::TestCase assert_equal 1, person.errors.size end + test "count calculates the number of error messages" do + person = Person.new + person.errors.add(:name, "cannot be blank") + assert_equal 1, person.errors.count + end + test "to_a returns the list of errors with complete messages containing the attribute names" do person = Person.new person.errors.add(:name, "cannot be blank") @@ -377,6 +383,12 @@ class ErrorsTest < ActiveModel::TestCase assert_empty errors.details[:name] end + test "delete returns the deleted messages" do + errors = ActiveModel::Errors.new(Person.new) + errors.add(:name, :invalid) + assert_equal ["is invalid"], errors.delete(:name) + end + test "clear removes details" do person = Person.new person.errors.add(:name, :invalid) diff --git a/activemodel/test/cases/helper.rb b/activemodel/test/cases/helper.rb index 3276f69f09..2b9de5e5d2 100644 --- a/activemodel/test/cases/helper.rb +++ b/activemodel/test/cases/helper.rb @@ -22,8 +22,3 @@ end def jruby_skip(message = '') skip message if defined?(JRUBY_VERSION) end - -# FIXME: we have tests that depend on run order, we should fix that and -# remove this method call. -require 'active_support/test_case' -ActiveSupport::TestCase.test_order = :sorted diff --git a/activemodel/test/cases/validations/length_validation_test.rb b/activemodel/test/cases/validations/length_validation_test.rb index 209903898e..ee901b75fb 100644 --- a/activemodel/test/cases/validations/length_validation_test.rb +++ b/activemodel/test/cases/validations/length_validation_test.rb @@ -319,8 +319,14 @@ class LengthValidationTest < ActiveModel::TestCase end def test_validates_length_of_with_block - Topic.validates_length_of :content, minimum: 5, too_short: "Your essay must be at least %{count} words.", - tokenizer: lambda {|str| str.scan(/\w+/) } + assert_deprecated do + Topic.validates_length_of( + :content, + minimum: 5, + too_short: "Your essay must be at least %{count} words.", + tokenizer: lambda {|str| str.scan(/\w+/) }, + ) + end t = Topic.new(content: "this content should be long enough") assert t.valid? @@ -332,8 +338,14 @@ class LengthValidationTest < ActiveModel::TestCase def test_validates_length_of_with_symbol - Topic.validates_length_of :content, minimum: 5, too_short: "Your essay must be at least %{count} words.", - tokenizer: :my_word_tokenizer + assert_deprecated do + Topic.validates_length_of( + :content, + minimum: 5, + too_short: "Your essay must be at least %{count} words.", + tokenizer: :my_word_tokenizer, + ) + end t = Topic.new(content: "this content should be long enough") assert t.valid? |