Skip to content

Commit

Permalink
Provide more fluent interface to handle boolean filter
Browse files Browse the repository at this point in the history
  • Loading branch information
heka1024 committed Apr 15, 2023
1 parent 620b5f7 commit b63537f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/active_interaction/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ def initialize_filter(filter)
filters[attribute] = filter

attr_accessor attribute
if filter.is_a?(BooleanFilter)
alias_method "#{attribute}?", attribute
end

eagerly_evaluate_default(filter)
end
Expand Down
10 changes: 9 additions & 1 deletion spec/active_interaction/integration/boolean_interaction_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
RSpec.describe 'BooleanInteraction' do
BooleanInteraction = Class.new(TestInteraction) do
boolean :x
end

RSpec.describe BooleanInteraction do
it_behaves_like 'an interaction', :boolean, -> { [false, true].sample }

it "responds to #x?" do
expect(described_class.new).to respond_to(:x?)
end
end

0 comments on commit b63537f

Please sign in to comment.