Emit BOOLEAN_ALLOWS_BOOLEAN_MESSAGE regardless of the order of the array of all booleans

Documented ensure_inclusion_of change
This commit is contained in:
Dave Schweisguth 2014-05-25 19:27:49 -07:00 committed by Elliot Winkler
parent d5c28418f4
commit 8376dd2fbf
3 changed files with 14 additions and 9 deletions

View File

@ -5,6 +5,9 @@
* Fix `delegate_method` so that it does not raise an error if the method that
returns the delegate object is private.
* Warn when `ensure_inclusion_of` is chained with `.in_array([false, true])`
as well as with `.in_array([true, false])`.
### Improvements
* `have_and_belongs_to_many` now checks to make sure that the join table

View File

@ -382,7 +382,7 @@ EOT
def disallows_value_outside_of_array?
if attribute_type == :boolean
case @array
when [true, false]
when [false, true], [true, false]
Shoulda::Matchers.warn BOOLEAN_ALLOWS_BOOLEAN_MESSAGE
return true
when [nil]

View File

@ -449,16 +449,18 @@ describe Shoulda::Matchers::ActiveModel::ValidateInclusionOfMatcher do
end
end
it 'prints a warning' do
valid_values = [true, false]
builder = build_object_allowing(valid_values)
message = 'You are using `validate_inclusion_of` to assert that a boolean column allows boolean values and disallows non-boolean ones'
[[false, true], [true, false]].each do |booleans|
it 'prints a warning' do
valid_values = booleans
builder = build_object_allowing(valid_values)
message = 'You are using `validate_inclusion_of` to assert that a boolean column allows boolean values and disallows non-boolean ones'
stderr = capture(:stderr) do
expect_to_match_in_array(builder, valid_values)
stderr = capture(:stderr) do
expect_to_match_in_array(builder, valid_values)
end
expect(stderr.gsub(/\n+/, ' ')).to include(message)
end
expect(stderr.gsub(/\n+/, ' ')).to include(message)
end
end
end