diff --git a/Gemfile.lock b/Gemfile.lock index 35b6d9f..28727c0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -8,7 +8,7 @@ GIT PATH remote: . specs: - rollout_ui (0.2.0) + rollout_ui (0.3.0) rollout GEM diff --git a/lib/rollout_ui/monkey_patch.rb b/lib/rollout_ui/monkey_patch.rb index a456713..e69de29 100644 --- a/lib/rollout_ui/monkey_patch.rb +++ b/lib/rollout_ui/monkey_patch.rb @@ -1,8 +0,0 @@ -class Rollout - alias_method :original_active?, :active? - - def active?(feature, user=nil) - RolloutUi::Wrapper.new(self).add_feature(feature) - original_active?(feature, user) - end -end diff --git a/lib/rollout_ui/wrapper.rb b/lib/rollout_ui/wrapper.rb index ca11666..08d5809 100644 --- a/lib/rollout_ui/wrapper.rb +++ b/lib/rollout_ui/wrapper.rb @@ -12,13 +12,9 @@ def initialize(rollout = nil) def groups rollout.instance_variable_get("@groups").keys end - - def add_feature(feature) - redis.sadd(:features, feature) - end - + def features - features = redis.smembers(:features) + features = @rollout.features features ? features.sort : [] end diff --git a/spec/lib/rollout_ui/wrapper_spec.rb b/spec/lib/rollout_ui/wrapper_spec.rb index d0f332e..3959597 100644 --- a/spec/lib/rollout_ui/wrapper_spec.rb +++ b/spec/lib/rollout_ui/wrapper_spec.rb @@ -34,39 +34,31 @@ end describe "#features" do - it "returns an empty array if no features have been requested" do + it "returns an empty array if no features have been set" do @rollout_ui.features.should == [] end - it "returns all features that have been requested" do - $rollout.active?(:featureA, mock(:user, :id => 5)) - $rollout.active?(:featureB, mock(:user, :id => 6)) + it "returns all features that have been set" do + $rollout.activate_user(:featureA, mock(:user, :id => 5)) + $rollout.activate_user(:featureB, mock(:user, :id => 6)) - @rollout_ui.features.should == ["featureA", "featureB"] + @rollout_ui.features.should == [:featureA, :featureB] end it "lists each feature only once" do - $rollout.active?(:featureA, mock(:user, :id => 5)) - $rollout.active?(:featureA, mock(:user, :id => 6)) + $rollout.activate_user(:featureA, mock(:user, :id => 5)) + $rollout.activate_user(:featureA, mock(:user, :id => 6)) - @rollout_ui.features.should == ["featureA"] + @rollout_ui.features.should == [:featureA] end it "lists features in alphabetical order" do - $rollout.active?(:zFeature, mock(:user, :id => 1)) - $rollout.active?(:featureA, mock(:user, :id => 5)) - $rollout.active?(:featureB, mock(:user, :id => 6)) - $rollout.active?(:anotherFeature, mock(:user, :id => 8)) + $rollout.activate_user(:zFeature, mock(:user, :id => 1)) + $rollout.activate_user(:featureA, mock(:user, :id => 5)) + $rollout.activate_user(:featureB, mock(:user, :id => 6)) + $rollout.activate_user(:anotherFeature, mock(:user, :id => 8)) - @rollout_ui.features.should == %w(anotherFeature featureA featureB zFeature) - end - end - - describe "#add_feature" do - it "adds feature to the list of features" do - @rollout_ui.add_feature(:featureA) - - @rollout_ui.features.should == ["featureA"] + @rollout_ui.features.should == [:anotherFeature, :featureA, :featureB, :zFeature] end end end diff --git a/spec/requests/engine/engine_spec.rb b/spec/requests/engine/engine_spec.rb index 869fabd..ff4f2c2 100644 --- a/spec/requests/engine/engine_spec.rb +++ b/spec/requests/engine/engine_spec.rb @@ -5,7 +5,7 @@ let(:user) { mock(:user, :id => 5) } before do - $rollout.active?(:featureA, user) + $rollout.activate_user(:featureA, user) end it "shows requested rollout features" do @@ -93,8 +93,8 @@ describe "order" do before do - $rollout.active?(:featureB, user) - $rollout.active?(:anotherFeature, user) + $rollout.activate_user(:featureB, user) + $rollout.activate_user(:anotherFeature, user) end it "shows features in alphabetical order" do