diff options
author | Akira Matsuda <ronnie@dio.jp> | 2013-10-23 22:01:14 +0900 |
---|---|---|
committer | Akira Matsuda <ronnie@dio.jp> | 2013-10-23 22:10:15 +0900 |
commit | 68db6bc431fbff0b2291f1f60ccf974b4eece596 (patch) | |
tree | 83e3ceeaa83e20ed65071aea33637826026d3464 /activemodel/test/cases | |
parent | dc8a20677d820aa09413c6a3e25c9d70ba24561a (diff) | |
download | rails-68db6bc431fbff0b2291f1f60ccf974b4eece596.tar.gz rails-68db6bc431fbff0b2291f1f60ccf974b4eece596.tar.bz2 rails-68db6bc431fbff0b2291f1f60ccf974b4eece596.zip |
Let validates_inclusion_of accept Time and DateTime ranges
fixes 4.0.0 regression introduced in 0317b93c17a46d7663a8c36edc26ad0ba3d75f85
Diffstat (limited to 'activemodel/test/cases')
-rw-r--r-- | activemodel/test/cases/validations/inclusion_validation_test.rb | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/activemodel/test/cases/validations/inclusion_validation_test.rb b/activemodel/test/cases/validations/inclusion_validation_test.rb index 01a373d85d..8b90856869 100644 --- a/activemodel/test/cases/validations/inclusion_validation_test.rb +++ b/activemodel/test/cases/validations/inclusion_validation_test.rb @@ -1,5 +1,6 @@ # encoding: utf-8 require 'cases/helper' +require 'active_support/all' require 'models/topic' require 'models/person' @@ -20,6 +21,27 @@ class InclusionValidationTest < ActiveModel::TestCase assert Topic.new("title" => "bbb", "content" => "abc").valid? end + def test_validates_inclusion_of_time_range + Topic.validates_inclusion_of(:created_at, in: 1.year.ago..Time.now) + assert Topic.new(title: 'aaa', created_at: 2.years.ago).invalid? + assert Topic.new(title: 'aaa', created_at: 3.months.ago).valid? + assert Topic.new(title: 'aaa', created_at: 37.weeks.from_now).invalid? + end + + def test_validates_inclusion_of_date_range + Topic.validates_inclusion_of(:created_at, in: 1.year.until(Date.today)..Date.today) + assert Topic.new(title: 'aaa', created_at: 2.years.until(Date.today)).invalid? + assert Topic.new(title: 'aaa', created_at: 3.months.until(Date.today)).valid? + assert Topic.new(title: 'aaa', created_at: 37.weeks.since(Date.today)).invalid? + end + + def test_validates_inclusion_of_date_time_range + Topic.validates_inclusion_of(:created_at, in: 1.year.until(DateTime.current)..DateTime.current) + assert Topic.new(title: 'aaa', created_at: 2.years.until(DateTime.current)).invalid? + assert Topic.new(title: 'aaa', created_at: 3.months.until(DateTime.current)).valid? + assert Topic.new(title: 'aaa', created_at: 37.weeks.since(DateTime.current)).invalid? + end + def test_validates_inclusion_of Topic.validates_inclusion_of(:title, in: %w( a b c d e f g )) |