Skip to content

Commit

Permalink
Remove support for actor by id
Browse files Browse the repository at this point in the history
Ruby 1.8.x responds to id for like everything which makes this suck.
Open to ideas if anyone has any, but for now I'm just removing and
forcing you to alias identifier to id or just pass in id.
  • Loading branch information
jnunemaker committed Sep 10, 2012
1 parent f27fa26 commit 5d84c0d
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 38 deletions.
3 changes: 0 additions & 3 deletions lib/flipper/types/actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Actor < Type
def self.wrappable?(thing)
thing.is_a?(Flipper::Types::Actor) ||
thing.respond_to?(:identifier) ||
thing.respond_to?(:id) ||
thing.respond_to?(:to_i)
end

Expand All @@ -24,8 +23,6 @@ def initialize(thing)
@thing = thing
@identifier = if thing.respond_to?(:identifier)
thing.identifier
elsif thing.respond_to?(:id)
thing.id
else
thing
end.to_i
Expand Down
18 changes: 0 additions & 18 deletions spec/flipper/dsl_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,6 @@ def feature(name)
end

describe "#actor" do
context "for something that responds to id" do
it "returns actor instance with identifier set to id" do
user = Struct.new(:id).new(23)
actor = subject.actor(user)
actor.should be_instance_of(Flipper::Types::Actor)
actor.identifier.should eq(23)
end
end

context "for something that responds to identifier" do
it "returns actor instance with identifier set to id" do
user = Struct.new(:identifier).new(45)
Expand All @@ -135,15 +126,6 @@ def feature(name)
end
end

context "for something that responds to identifier and id" do
it "returns actor instance with identifier set to identifier" do
user = Struct.new(:id, :identifier).new(1, 50)
actor = subject.actor(user)
actor.should be_instance_of(Flipper::Types::Actor)
actor.identifier.should eq(50)
end
end

context "for a number" do
it "returns actor instance with identifer set to number" do
actor = subject.actor(33)
Expand Down
8 changes: 4 additions & 4 deletions spec/flipper/registry_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
end

it "returns the keys" do
subject.keys.should eq([:admins, :devs])
subject.keys.map(&:to_s).sort.should eq(['admins', 'devs'])
end
end

Expand All @@ -76,7 +76,7 @@
end

it "returns the values" do
subject.values.should eq(['admins', 'devs'])
subject.values.map(&:to_s).sort.should eq(['admins', 'devs'])
end
end

Expand All @@ -95,8 +95,8 @@
values << value
end

keys.should eq([:admins, :devs])
values.should eq(['admins', 'devs'])
keys.map(&:to_s).sort.should eq(['admins', 'devs'])
values.sort.should eq(['admins', 'devs'])
end
end

Expand Down
15 changes: 2 additions & 13 deletions spec/flipper/types/actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,12 @@ def admin?
described_class.wrappable?(thing).should be_true
end

it "returns true if responds to id" do
thing = Struct.new(:id).new(10)
described_class.wrappable?(thing).should be_true
end

it "returns true if responds to to_i" do
described_class.wrappable?(1).should be_true
end

it "returns false if not actor and does not respond to identifier, id, nor to_i" do
described_class.wrappable?(:nope).should be_false
it "returns false if not actor and does not respond to identifier or to_i" do
described_class.wrappable?(Object.new).should be_false
end
end

Expand Down Expand Up @@ -73,12 +68,6 @@ def admin?
actor.identifier.should be(1)
end

it "initializes with object that responds to id" do
thing = Struct.new(:id).new(13)
actor = described_class.new(thing)
actor.identifier.should be(13)
end

it "raises error when initialized with nil" do
expect {
described_class.new(nil)
Expand Down

0 comments on commit 5d84c0d

Please sign in to comment.