Skip to content

Commit

Permalink
Always send strings to the adapter change methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
jnunemaker committed Feb 5, 2013
1 parent e064f26 commit 95a877b
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 16 deletions.
6 changes: 3 additions & 3 deletions lib/flipper/adapter.rb
Expand Up @@ -101,7 +101,7 @@ def read(key)

# Public: Set a key to a value.
def write(key, value)
perform_update(:write, key, value)
perform_update(:write, key, value.to_s)
end

# Public: Deletes a key.
Expand All @@ -116,12 +116,12 @@ def set_members(key)

# Public: Adds a value to a set.
def set_add(key, value)
perform_update(:set_add, key, value)
perform_update(:set_add, key, value.to_s)
end

# Public: Deletes a value from a set.
def set_delete(key, value)
perform_update(:set_delete, key, value)
perform_update(:set_delete, key, value.to_s)
end

# Public: Determines equality for an adapter instance when compared to
Expand Down
6 changes: 3 additions & 3 deletions lib/flipper/adapters/memory.rb
Expand Up @@ -15,7 +15,7 @@ def read(key)

# Public
def write(key, value)
@source[key.to_s] = value
@source[key.to_s] = value.to_s
end

# Public
Expand All @@ -26,13 +26,13 @@ def delete(key)
# Public
def set_add(key, value)
ensure_set_initialized(key)
@source[key.to_s].add(value)
@source[key.to_s].add(value.to_s)
end

# Public
def set_delete(key, value)
ensure_set_initialized(key)
@source[key.to_s].delete(value)
@source[key.to_s].delete(value.to_s)
end

# Public
Expand Down
15 changes: 12 additions & 3 deletions lib/flipper/spec/shared_adapter_specs.rb
Expand Up @@ -82,18 +82,27 @@
Flipper.new(subject).should_not be_nil
end

context "integration spot-checks" do
context "working with sets" do
it "always returns strings" do
subject.set_add key, 1
subject.set_add key, 2
subject.set_members(key).should eq(Set['1', '2'])
subject.set_delete key, 2
subject.set_members(key).should eq(Set['1'])
end
end

context "integration spot-checks" do
let(:instance) { Flipper.new(subject) }
let(:feature) { instance[:feature] }
let(:actor) { Struct.new(:id).new(1) }

describe "percentage of actors" do
context "percentage of actors" do
let(:percentage) { instance.actors(10) }
it_should_behave_like 'a working percentage'
end

describe "random percentage" do
context "random percentage" do
let(:percentage) { instance.random(10) }
it_should_behave_like 'a working percentage'
end
Expand Down
15 changes: 8 additions & 7 deletions spec/flipper/adapter_spec.rb
Expand Up @@ -5,7 +5,8 @@

describe Flipper::Adapter do
let(:local_cache) { {} }
let(:adapter) { Flipper::Adapters::Memory.new }
let(:source) { {} }
let(:adapter) { Flipper::Adapters::Memory.new(source) }
let(:features_key) { described_class::FeaturesKey }

subject { described_class.new(adapter, :local_cache => local_cache) }
Expand Down Expand Up @@ -134,7 +135,7 @@

describe "#set_members" do
before do
adapter.write 'foo', Set['1', '2']
source['foo'] = Set['1', '2']
@result = subject.set_members('foo')
end

Expand Down Expand Up @@ -180,7 +181,7 @@

describe "#set_add" do
before do
adapter.write 'foo', Set['1']
source['foo'] = Set['1']
local_cache['foo'] = Set['1']
subject.set_add 'foo', '2'
end
Expand All @@ -196,7 +197,7 @@

describe "#set_delete" do
before do
adapter.write 'foo', Set['1', '2', '3']
source['foo'] = Set['1', '2', '3']
local_cache['foo'] = Set['1', '2', '3']
subject.set_delete 'foo', '3'
end
Expand Down Expand Up @@ -233,7 +234,7 @@

describe "#set_members" do
before do
adapter.write 'foo', Set['1', '2']
source['foo'] = Set['1', '2']
@result = subject.set_members('foo')
end

Expand Down Expand Up @@ -280,7 +281,7 @@

describe "#set_add" do
before do
adapter.write 'foo', Set['1']
source['foo'] = Set['1']
local_cache['foo'] = Set['1']
subject.set_add 'foo', '2'
end
Expand All @@ -296,7 +297,7 @@

describe "#set_delete" do
before do
adapter.write 'foo', Set['1', '2', '3']
source['foo'] = Set['1', '2', '3']
local_cache['foo'] = Set['1', '2', '3']
subject.set_delete 'foo', '3'
end
Expand Down

0 comments on commit 95a877b

Please sign in to comment.