Permalink
Browse files

Uses strings as actor identifiers.

Patch related to discussion at  jnunemaker/flipper-redis#3 where it was decided that internally Flipper needs to store id's as strings. This is because some adapters (redis) are typeless blob stores. This change also helps with other datastore compatibility (i.e. Mongo where id's are non-integer).
  • Loading branch information...
1 parent 3094b90 commit 3a2f57e9ccf666fb7b53a18a3602d4e39e0771f4 @chrislloyd chrislloyd committed Nov 21, 2012
Showing with 10 additions and 9 deletions.
  1. +1 −1 lib/flipper/types/actor.rb
  2. +2 −2 spec/flipper/dsl_spec.rb
  3. +7 −6 spec/flipper/types/actor_spec.rb
@@ -25,7 +25,7 @@ def initialize(thing)
thing.identifier
else
thing
- end.to_i
+ end.to_s
end
def value
@@ -122,15 +122,15 @@ def feature(name)
user = Struct.new(:identifier).new(45)
actor = subject.actor(user)
actor.should be_instance_of(Flipper::Types::Actor)
- actor.identifier.should eq(45)
+ actor.identifier.should eq('45')
end
end
context "for a number" do
it "returns actor instance with identifer set to number" do
actor = subject.actor(33)
actor.should be_instance_of(Flipper::Types::Actor)
- actor.identifier.should eq(33)
+ actor.identifier.should eq('33')
end
end
@@ -63,9 +63,10 @@ def admin?
end
it "initializes with object that responds to identifier" do
- thing = Struct.new(:identifier).new(1)
+ identifier = '1'
+ thing = Struct.new(:identifier).new(identifier)
actor = described_class.new(thing)
- actor.identifier.should be(1)
+ actor.identifier.should be(identifier)
end
it "raises error when initialized with nil" do
@@ -74,14 +75,14 @@ def admin?
}.to raise_error(ArgumentError)
end
- it "converts identifier to integer" do
- actor = described_class.new('2')
- actor.identifier.should eq(2)
+ it "converts identifier to string" do
+ actor = described_class.new(2)
+ actor.identifier.should eq('2')
end
it "has identifier" do
actor = described_class.new(2)
- actor.identifier.should eq(2)
+ actor.identifier.should eq('2')
end
it "proxies everything to thing" do

0 comments on commit 3a2f57e

Please sign in to comment.