Skip to content

Commit

Permalink
Allow booleans to be given to validate_inclusion_of [#89 status:resol…
Browse files Browse the repository at this point in the history
…ved]
  • Loading branch information
josevalim committed Jul 16, 2009
1 parent 4e56579 commit c7a2323
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 6 deletions.
2 changes: 2 additions & 0 deletions remarkable_activerecord/CHANGELOG
@@ -1,3 +1,5 @@
* Allow booleans to be given to validate_inclusion_of [#89]

* Allow allow_values_for and allow_mass_assignment_of matchers to be executed in
the negative form by including Remarkable::Negative module [#85]

Expand Down
Expand Up @@ -14,10 +14,9 @@ class ValidateExclusionOfMatcher < AllowValuesForMatcher #:nodoc:
def valid_values
if @in_range
[ @options[:in].first - 1, @options[:in].last + 1 ]
elsif @options[:in].empty?
[]
else
[ @options[:in].map(&:to_s).max.to_s.next ]
value = @options[:in].select{ |i| i.is_a?(String) }.max
value ? [ value.next ] : []
end
end

Expand Down
Expand Up @@ -18,10 +18,9 @@ def valid_values
def invalid_values
if @in_range
[ @options[:in].first - 1, @options[:in].last + 1 ]
elsif @options[:in].empty?
[]
else
[ @options[:in].map(&:to_s).max.to_s.next ]
value = @options[:in].select{ |i| i.is_a?(String) }.max
value ? [ value.next ] : []
end
end

Expand Down
Expand Up @@ -49,6 +49,9 @@ def define_and_validate(options={})
it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('X', 'Y') }
it { should_not define_and_validate(:in => ['X', 'Y', 'Z']).in('A') }

it { should define_and_validate(:in => [true, false]).in(true, false) }
it { should_not define_and_validate(:in => [true, false]).in('A') }

it { should define_and_validate(:in => 2..3).in(2..3) }
it { should define_and_validate(:in => 2..20).in(2..20) }
it { should_not define_and_validate(:in => 2..20).in(1..20) }
Expand Down

0 comments on commit c7a2323

Please sign in to comment.