Skip to content

Commit

Permalink
Merge pull request #365 from voondo/patch-1
Browse files Browse the repository at this point in the history
Update boolean_filter : on/off support
  • Loading branch information
tfausak committed Jun 7, 2016
2 parents 2ac54f7 + 10b6a47 commit 1c2b49e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lib/active_interaction/filters/boolean_filter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ class BooleanFilter < Filter

def cast(value, _interaction)
case value
when FalseClass, '0', /\Afalse\z/i
when FalseClass, '0', /\Afalse\z/i, /\Aoff\z/i
false
when TrueClass, '1', /\Atrue\z/i
when TrueClass, '1', /\Atrue\z/i, /\Aon\z/i
true
else
super
Expand Down
4 changes: 2 additions & 2 deletions spec/active_interaction/filters/boolean_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@

describe '#cast' do
context 'falsey' do
[false, '0', 'false', 'FALSE'].each do |value|
[false, '0', 'false', 'FALSE', 'off', 'OFF'].each do |value|
it "returns false for #{value.inspect}" do
expect(filter.cast(value, nil)).to be_falsey
end
end
end

context 'truthy' do
[true, '1', 'true', 'TRUE'].each do |value|
[true, '1', 'true', 'TRUE', 'on', 'ON'].each do |value|
it "returns true for #{value.inspect}" do
expect(filter.cast(value, nil)).to be_truthy
end
Expand Down

0 comments on commit 1c2b49e

Please sign in to comment.