diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-26 19:05:03 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-12-26 19:05:03 -0300 |
commit | 93366c7c913bf0883f140fa782d3e198593477be (patch) | |
tree | 485791ef8b3bbc02ba9e4a37533261329c0d785c /activemodel/test | |
parent | 8c938dddd22f16e2e15471a648aaa96be380c562 (diff) | |
download | rails-93366c7c913bf0883f140fa782d3e198593477be.tar.gz rails-93366c7c913bf0883f140fa782d3e198593477be.tar.bz2 rails-93366c7c913bf0883f140fa782d3e198593477be.zip |
Fix `validates_presence_of` with `:allow_nil` or `:allow_blank` options.
Fix #8621
[Colin Kelley + Rafael Mendonça França]
Diffstat (limited to 'activemodel/test')
-rw-r--r-- | activemodel/test/cases/validations/presence_validation_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/presence_validation_test.rb b/activemodel/test/cases/validations/presence_validation_test.rb index 510c13a7c3..fbb008f9ff 100644 --- a/activemodel/test/cases/validations/presence_validation_test.rb +++ b/activemodel/test/cases/validations/presence_validation_test.rb @@ -70,4 +70,38 @@ class PresenceValidationTest < ActiveModel::TestCase p[:karma] = "Cold" assert p.valid? end + + def test_validates_presence_of_with_allow_nil_option + Topic.validates_presence_of(:title, :allow_nil => true) + + t = Topic.new(:title => "something") + assert t.valid? + + t.title = "" + assert t.invalid? + assert_equal ["can't be blank"], t.errors[:title] + + t.title = " " + assert t.invalid? + assert_equal ["can't be blank"], t.errors[:title] + + t.title = nil + assert t.valid? + end + + def test_validates_presence_of_with_allow_blank_option + Topic.validates_presence_of(:title, :allow_blank => true) + + t = Topic.new(:title => "something") + assert t.valid? + + t.title = "" + assert t.valid? + + t.title = " " + assert t.valid? + + t.title = nil + assert t.valid? + end end |