Skip to content

Commit

Permalink
Merge pull request #559 from heka1024/fluent-boolean-filter
Browse files Browse the repository at this point in the history
Provide more fluent interface to handle boolean filter
  • Loading branch information
AaronLasseigne authored Apr 26, 2023
2 parents faa9eb0 + 97ad195 commit 1ec6da2
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/active_interaction/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ def initialize_filter(filter)

attr_accessor attribute

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

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 1ec6da2

Please sign in to comment.