diff options
Diffstat (limited to 'activemodel/test/cases/validations/inclusion_validation_test.rb')
-rw-r--r-- | activemodel/test/cases/validations/inclusion_validation_test.rb | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/activemodel/test/cases/validations/inclusion_validation_test.rb b/activemodel/test/cases/validations/inclusion_validation_test.rb index 9bd44175a6..732a8d362a 100644 --- a/activemodel/test/cases/validations/inclusion_validation_test.rb +++ b/activemodel/test/cases/validations/inclusion_validation_test.rb @@ -1,17 +1,16 @@ -require 'cases/helper' -require 'active_support/all' +require "cases/helper" +require "active_support/all" -require 'models/topic' -require 'models/person' +require "models/topic" +require "models/person" class InclusionValidationTest < ActiveModel::TestCase - def teardown Topic.clear_validators! end def test_validates_inclusion_of_range - Topic.validates_inclusion_of(:title, in: 'aaa'..'bbb') + Topic.validates_inclusion_of(:title, in: "aaa".."bbb") assert Topic.new("title" => "bbc", "content" => "abc").invalid? assert Topic.new("title" => "aa", "content" => "abc").invalid? assert Topic.new("title" => "aaab", "content" => "abc").invalid? @@ -24,35 +23,35 @@ class InclusionValidationTest < ActiveModel::TestCase range_begin = 1.year.ago range_end = Time.now Topic.validates_inclusion_of(:created_at, in: range_begin..range_end) - 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? - assert Topic.new(title: 'aaa', created_at: range_begin).valid? - assert Topic.new(title: 'aaa', created_at: range_end).valid? + 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? + assert Topic.new(title: "aaa", created_at: range_begin).valid? + assert Topic.new(title: "aaa", created_at: range_end).valid? end def test_validates_inclusion_of_date_range range_begin = 1.year.until(Date.today) range_end = Date.today Topic.validates_inclusion_of(:created_at, in: range_begin..range_end) - 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? - assert Topic.new(title: 'aaa', created_at: 1.year.until(Date.today)).valid? - assert Topic.new(title: 'aaa', created_at: Date.today).valid? - assert Topic.new(title: 'aaa', created_at: range_begin).valid? - assert Topic.new(title: 'aaa', created_at: range_end).valid? + 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? + assert Topic.new(title: "aaa", created_at: 1.year.until(Date.today)).valid? + assert Topic.new(title: "aaa", created_at: Date.today).valid? + assert Topic.new(title: "aaa", created_at: range_begin).valid? + assert Topic.new(title: "aaa", created_at: range_end).valid? end def test_validates_inclusion_of_date_time_range range_begin = 1.year.until(DateTime.current) range_end = DateTime.current Topic.validates_inclusion_of(:created_at, in: range_begin..range_end) - 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? - assert Topic.new(title: 'aaa', created_at: range_begin).valid? - assert Topic.new(title: 'aaa', created_at: range_end).valid? + 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? + assert Topic.new(title: "aaa", created_at: range_begin).valid? + assert Topic.new(title: "aaa", created_at: range_end).valid? end def test_validates_inclusion_of |