Permalink
Browse files

Ensure always checking actor when possible with actor gate.

Also added several specs related to checking actual actors in groups
for enabled/disabled.
  • Loading branch information...
1 parent 23f3ce6 commit 84dc32cda3f8633f95d421425eef1bbdda190718 @jnunemaker committed Aug 8, 2012
Showing with 38 additions and 5 deletions.
  1. +4 −3 lib/flipper/gates/actor.rb
  2. +34 −2 spec/flipper/feature_spec.rb
@@ -12,9 +12,10 @@ def toggle_class
end
def open?(actor)
- if actor && actor.respond_to?(:identifier)
- identifiers.include?(actor.identifier)
- end
+ return if actor.nil?
+ return unless Types::Actor.wrappable?(actor)
+ actor = Types::Actor.wrap(actor)
+ identifiers.include?(actor.identifier)
end
def identifiers
@@ -15,8 +15,8 @@
let(:admin_group) { Flipper.group(:admins) }
let(:dev_group) { Flipper.group(:devs) }
- let(:admin_thing) { double 'Non Flipper Thing', :admin? => true, :dev? => false }
- let(:dev_thing) { double 'Non Flipper Thing', :admin? => false, :dev? => true }
+ let(:admin_thing) { double 'Non Flipper Thing', :identifier => 1, :admin? => true, :dev? => false }
+ let(:dev_thing) { double 'Non Flipper Thing', :identifier => 10, :admin? => false, :dev? => true }
let(:pitt) { Flipper::Types::Actor.new(1) }
let(:clooney) { Flipper::Types::Actor.new(10) }
@@ -62,6 +62,14 @@
subject.enabled?(dev_thing).should be_false
end
+ it "enables feature for flipper actor in group" do
+ subject.enabled?(Flipper::Types::Actor.new(admin_thing)).should be_true
+ end
+
+ it "does not enable for flipper actor not in group" do
+ subject.enabled?(Flipper::Types::Actor.new(dev_thing)).should be_false
+ end
+
it "does not enable feature for all" do
subject.enabled?.should be_false
end
@@ -153,6 +161,14 @@
it "does not disable feature for non flipper thing in other groups" do
subject.enabled?(dev_thing).should be_true
end
+
+ it "disables feature for flipper actor in group" do
+ subject.enabled?(Flipper::Types::Actor.new(admin_thing)).should be_false
+ end
+
+ it "does not disable feature for flipper actor in other groups" do
+ subject.enabled?(Flipper::Types::Actor.new(dev_thing)).should be_true
+ end
end
context "with an actor" do
@@ -230,6 +246,22 @@
end
end
+ context "for actor in enabled group" do
+ before do
+ adapter.set_add("#{subject.name}#{Flipper::Gate::Separator}#{group_key}", admin_group.name)
+ end
+
+ it "returns true" do
+ subject.enabled?(Flipper::Types::Actor.new(admin_thing)).should be_true
+ end
+ end
+
+ context "for actor in disbled group" do
+ it "returns false" do
+ subject.enabled?(Flipper::Types::Actor.new(dev_thing)).should be_false
+ end
+ end
+
context "for enabled actor" do
before do
adapter.set_add("#{subject.name}#{Flipper::Gate::Separator}#{actor_key}", pitt.identifier)

0 comments on commit 84dc32c

Please sign in to comment.