diff options
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/secure_password_test.rb | 10 | ||||
-rw-r--r-- | activemodel/test/cases/validations_test.rb | 30 | ||||
-rw-r--r-- | activemodel/test/models/automobile.rb | 13 |
3 files changed, 27 insertions, 26 deletions
diff --git a/activemodel/test/cases/secure_password_test.rb b/activemodel/test/cases/secure_password_test.rb index 6b21bc68fa..6d56c8344a 100644 --- a/activemodel/test/cases/secure_password_test.rb +++ b/activemodel/test/cases/secure_password_test.rb @@ -40,6 +40,11 @@ class SecurePasswordTest < ActiveModel::TestCase assert @user.valid?(:create), 'user should be valid' end + test "create a new user with validation and a spaces only password" do + @user.password = ' ' * 72 + assert @user.valid?(:create), 'user should be valid' + end + test "create a new user with validation and a blank password" do @user.password = '' assert !@user.valid?(:create), 'user should be invalid' @@ -105,6 +110,11 @@ class SecurePasswordTest < ActiveModel::TestCase assert @existing_user.valid?(:update), 'user should be valid' end + test "updating an existing user with validation and a spaces only password" do + @user.password = ' ' * 72 + assert @user.valid?(:update), 'user should be valid' + end + test "updating an existing user with validation and a blank password and password_confirmation" do @existing_user.password = '' @existing_user.password_confirmation = '' diff --git a/activemodel/test/cases/validations_test.rb b/activemodel/test/cases/validations_test.rb index 38e54b7f17..ba0aacc2a5 100644 --- a/activemodel/test/cases/validations_test.rb +++ b/activemodel/test/cases/validations_test.rb @@ -4,7 +4,6 @@ require 'cases/helper' require 'models/topic' require 'models/reply' require 'models/custom_reader' -require 'models/automobile' require 'active_support/json' require 'active_support/xml_mini' @@ -290,25 +289,30 @@ class ValidationsTest < ActiveModel::TestCase end def test_validations_on_the_instance_level - auto = Automobile.new + Topic.validates :title, :author_name, presence: true + Topic.validates :content, length: { minimum: 10 } - assert auto.invalid? - assert_equal 3, auto.errors.size - - auto.make = 'Toyota' - auto.model = 'Corolla' - auto.approved = '1' + topic = Topic.new + assert topic.invalid? + assert_equal 3, topic.errors.size - assert auto.valid? + topic.title = 'Some Title' + topic.author_name = 'Some Author' + topic.content = 'Some Content Whose Length is more than 10.' + assert topic.valid? end def test_validate - auto = Automobile.new + Topic.validate do + validates_presence_of :title, :author_name + validates_length_of :content, minimum: 10 + end - assert_empty auto.errors + topic = Topic.new + assert_empty topic.errors - auto.validate - assert_not_empty auto.errors + topic.validate + assert_not_empty topic.errors end def test_strict_validation_in_validates diff --git a/activemodel/test/models/automobile.rb b/activemodel/test/models/automobile.rb deleted file mode 100644 index 4df2fe8b3a..0000000000 --- a/activemodel/test/models/automobile.rb +++ /dev/null @@ -1,13 +0,0 @@ -class Automobile - include ActiveModel::Validations - - validate :validations - - attr_accessor :make, :model, :approved - - def validations - validates_presence_of :make - validates_length_of :model, within: 2..10 - validates_acceptance_of :approved, allow_nil: false - end -end |