Permalink
Browse files

Return an integer for fixnum columns for inclusion

  • Loading branch information...
drapergeek committed Aug 15, 2013
1 parent 9cd3f85 commit 87b80e2ca6e6e0e820e628665e271e9a8da69e89
View
@@ -1,5 +1,8 @@
# HEAD
* Fix a bug in `ensure_inclusion_of` that would cause issues with using
`in_array` with an integer value.
* Add support for PostgreSQL UUID columns to `validates_uniqueness_of` (#334).
* Fix `validates_numericality_of` so that `is_equal_to` submatcher works
@@ -23,6 +23,7 @@ def ensure_inclusion_of(attr)
class EnsureInclusionOfMatcher < ValidationMatcher # :nodoc:
ARBITRARY_OUTSIDE_STRING = 'shouldamatchersteststring'
ARBITRARY_OUTSIDE_FIXNUM = 123456789
def initialize(attribute)
super(attribute)
@@ -144,8 +145,21 @@ def disallows_value_outside_of_array?
end
def value_outside_of_array
if @array.include?(ARBITRARY_OUTSIDE_STRING)
if @array.include?(outside_value)
raise CouldNotDetermineValueOutsideOfArray
else
outside_value
end
end
def outside_value
@outside_value ||= find_outside_value
end
def find_outside_value
case @subject.send(@attribute.to_s)
when Fixnum
ARBITRARY_OUTSIDE_FIXNUM
else
ARBITRARY_OUTSIDE_STRING
end
@@ -8,6 +8,16 @@
end
end
context 'with an integer column' do
it 'can verify a zero in the array' do
model = define_model(:example, :attr => :integer) do
validates_inclusion_of :attr, :in => [0, 1, 2]
end.new
model.should ensure_inclusion_of(:attr).in_array([0,1,2])
end
end
context 'with true/false values' do
it 'can verify outside values to ensure the negative case' do
define_model(:example, :attr => :string).new.

0 comments on commit 87b80e2

Please sign in to comment.