Skip to content

Commit

Permalink
Merge pull request #406 from jnunemaker/issue-405
Browse files Browse the repository at this point in the history
Allow shorthand block notation on group types
  • Loading branch information
jnunemaker authored Apr 22, 2019
2 parents 8dc581e + 84ca027 commit df0352b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/flipper/types/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(name, &block)

if block_given?
@block = block
@single_argument = @block.arity == 1
@single_argument = @block.arity.abs == 1
else
@block = ->(_thing, _context) { false }
@single_argument = false
Expand Down
22 changes: 22 additions & 0 deletions spec/flipper/types/group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@
expect(group.match?(double('Actor'), fake_context)).to be_falsey
end

it 'returns true for truthy shortand block results' do
actor = Class.new do
def admin?
true
end
end.new

group = described_class.new(:admin, &:admin?)
expect(group.match?(actor, fake_context)).to be_truthy
end

it 'returns false for falsy shortand block results' do
actor = Class.new do
def admin?
false
end
end.new

group = described_class.new(:admin, &:admin?)
expect(group.match?(actor, fake_context)).to be_falsey
end

it 'can yield without context as block argument' do
context = Flipper::FeatureCheckContext.new(
feature_name: :my_feature,
Expand Down

0 comments on commit df0352b

Please sign in to comment.