Permalink
Browse files

Get things passing again with latest flipper.

  • Loading branch information...
1 parent a0db0b2 commit 049e2c78f1080f97e0c85c1a0ef6ea5d069370e0 @jnunemaker committed Feb 18, 2013
View
@@ -7,8 +7,6 @@ gem 'rspec'
gem 'rack-test'
gem 'activesupport'
-gem 'flipper', :git => 'https://github.com/jnunemaker/flipper.git'
-
group(:guard) do
gem 'guard'
gem 'guard-rspec'
View
@@ -16,7 +16,7 @@ Gem::Specification.new do |gem|
gem.version = Flipper::UI::VERSION
gem.add_dependency 'rack'
- gem.add_dependency 'flipper', '~> 0.4.0'
+ gem.add_dependency 'flipper', '~> 0.5.0'
gem.add_dependency 'erubis'
gem.add_dependency 'multi_json'
end
@@ -10,7 +10,8 @@ class Index < UI::Action
def get
@features = flipper.features.map { |feature|
- Decorators::Feature.new(feature)
+ gate_values = flipper.adapter.get(feature)
+ Decorators::Feature.new(feature, gate_values)
}
view_response :index
@@ -5,25 +5,40 @@ module Flipper
module UI
module Decorators
class Feature < SimpleDelegator
+ # Public: The feature being decorated.
alias_method :feature, :__getobj__
+ # Public: The values for each gate from the adapter.
+ attr_reader :gate_values
+
+ def initialize(feature, gate_values = nil)
+ super feature
+ @gate_values = gate_values || {}
+ end
+
# Public: Returns name titleized.
def pretty_name
@pretty_name ||= titleize(name)
end
+ # Public: Returns instance as hash that is ready to be json dumped.
def as_json
{
'id' => name.to_s,
'name' => pretty_name,
'state' => state.to_s,
'description' => description,
'gates' => gates.map { |gate|
- Decorators::Gate.new(gate).as_json
+ Decorators::Gate.new(gate, value_for(gate)).as_json
},
}
end
+ # Private: Returns the value for the provided gate.
+ def value_for(gate)
+ @gate_values[gate.key]
+ end
+
# Private
def titleize(str)
str.to_s.split('_').map { |word| word.capitalize }.join(' ')
@@ -4,13 +4,23 @@ module Flipper
module UI
module Decorators
class Gate < SimpleDelegator
+ # Public: The gate being decorated.
alias_method :gate, :__getobj__
+ # Public: The value for the gate from the adapter.
+ attr_reader :value
+
+ def initialize(gate, value = nil)
+ super gate
+ @value = value
+ end
+
+ # Public: Returns instance as hash that is ready to be json dumped.
def as_json
{
'key' => gate.key.to_s,
'name' => gate.name.to_s,
- 'value' => gate.value,
+ 'value' => @value,
}
end
end
@@ -28,6 +28,11 @@ def app
end
end
+ def gate_value(feature_name, gate_key)
+ values = flipper.adapter.get(flipper[feature_name])
+ values[gate_key]
+ end
+
describe "GET /flipper" do
before do
flipper[:stats].enable
@@ -131,7 +136,7 @@ def app
end
it "updates gate state" do
- flipper[:some_thing].gate(:percentage_of_actors).value.to_i.should be(5)
+ gate_value(:some_thing, :percentage_of_actors).to_i.should be(5)
end
end
@@ -171,7 +176,7 @@ def app
end
it "updates gate state" do
- flipper[:some_thing].gate(:percentage_of_random).value.to_i.should be(5)
+ gate_value(:some_thing, :percentage_of_random).to_i.should be(5)
end
end
@@ -212,7 +217,7 @@ def app
end
it "updates gate state" do
- flipper[:some_thing].gate(:actor).value.should include('11')
+ gate_value(:some_thing, :actors).should include('11')
end
end
@@ -232,7 +237,7 @@ def app
end
it "updates gate state" do
- flipper[:some_thing].gate(:actor).value.should_not include('11')
+ gate_value(:some_thing, :actors).should_not include('11')
end
end
@@ -282,7 +287,7 @@ def app
end
it "updates gate state" do
- flipper[:some_thing].gate(:group).value.should include('admins')
+ gate_value(:some_thing, :groups).should include('admins')
end
end
@@ -302,7 +307,7 @@ def app
end
it "updates gate state" do
- flipper[:some_thing].gate(:group).value.should_not include('admins')
+ gate_value(:some_thing, :groups).should_not include('admins')
end
end
@@ -8,11 +8,21 @@
let(:feature) { flipper[:some_awesome_feature] }
subject {
- described_class.new(feature)
+ described_class.new(feature, {
+ boolean: 'false',
+ })
}
- it "initializes with feature" do
- subject.feature.should be(feature)
+ describe "#initialize" do
+ it "sets the feature" do
+ subject.feature.should be(feature)
+ end
+
+ it "sets the gate values" do
+ subject.gate_values.should eq({
+ boolean: 'false',
+ })
+ end
end
describe "#pretty_name" do
@@ -48,7 +58,8 @@
it "includes gates" do
gates = subject.gates.map { |gate|
- Flipper::UI::Decorators::Gate.new(gate).as_json
+ value = subject.gate_values[gate.key]
+ Flipper::UI::Decorators::Gate.new(gate, value).as_json
}
@result['gates'].should eq(gates)
end
@@ -7,14 +7,20 @@
let(:adapter) { Flipper::Adapters::Memory.new(source) }
let(:flipper) { Flipper.new(adapter) }
let(:feature) { flipper[:some_awesome_feature] }
- let(:gate) { feature.gates.first }
+ let(:gate) { feature.gate(:boolean) }
subject {
- described_class.new(gate)
+ described_class.new(gate, 'false')
}
- it "initializes with gate" do
- subject.gate.should be(gate)
+ describe "#initialize" do
+ it "sets gate" do
+ subject.gate.should be(gate)
+ end
+
+ it "sets value" do
+ subject.value.should eq('false')
+ end
end
describe "#as_json" do
@@ -35,7 +41,7 @@
end
it "includes value" do
- @result['value'].should eq(false)
+ @result['value'].should eq('false')
end
end
end

0 comments on commit 049e2c7

Please sign in to comment.