spec/rollout_spec.rb in rollout-2.0.0 vs spec/rollout_spec.rb in rollout-2.1.0
- old
+ new
@@ -95,10 +95,24 @@
it "remains inactive for other users" do
@rollout.should_not be_active(:chat, stub(:id => 24))
end
end
+ describe "activating a specific user by ID" do
+ before do
+ @rollout.activate_user(:chat, 42)
+ end
+
+ it "is active for that user" do
+ @rollout.should be_active(:chat, stub(:id => 42))
+ end
+
+ it "remains inactive for other users" do
+ @rollout.should_not be_active(:chat, stub(:id => 24))
+ end
+ end
+
describe "activating a specific user with a string id" do
before do
@rollout.activate_user(:chat, stub(:id => 'user-72'))
end
@@ -204,10 +218,30 @@
it "becomes inactivate" do
@rollout.should_not be_active(:chat)
end
end
+ describe "setting a feature on" do
+ before do
+ @rollout.set(:chat, true)
+ end
+
+ it "becomes activated" do
+ @rollout.should be_active(:chat)
+ end
+ end
+
+ describe "setting a feature off" do
+ before do
+ @rollout.set(:chat, false)
+ end
+
+ it "becomes activated" do
+ @rollout.should_not be_active(:chat)
+ end
+ end
+
describe "keeps a list of features" do
it "saves the feature" do
@rollout.activate(:chat)
@rollout.features.should be_include(:chat)
end
@@ -215,10 +249,16 @@
it "does not contain doubles" do
@rollout.activate(:chat)
@rollout.activate(:chat)
@rollout.features.size.should == 1
end
+
+ it "does not contain doubles when using string" do
+ @rollout.activate(:chat)
+ @rollout.activate("chat")
+ @rollout.features.size.should == 1
+ end
end
describe "#get" do
before do
@rollout.activate_percentage(:chat, 10)
@@ -244,10 +284,34 @@
feature.users.should be_empty
feature.percentage.should == 100
end
end
+ describe "#clear" do
+ let(:features) { %w(signup beta alpha gm) }
+
+ before do
+ features.each { |f| @rollout.activate(f) }
+
+ @rollout.clear!
+ end
+
+ it "each feature is cleared" do
+ features.each do |feature|
+ @rollout.get(feature).to_hash.should == {
+ :percentage => 0,
+ :users => [],
+ :groups => []
+ }
+ end
+ end
+
+ it "removes all features" do
+ @rollout.features.should be_empty
+ end
+ end
+
describe "migration mode" do
before do
@legacy = Rollout::Legacy.new(@redis)
@legacy.activate_percentage(:chat, 12)
@legacy.activate_user(:chat, stub(:id => 42))
@@ -267,8 +331,27 @@
:percentage => 12,
:users => %w(24 42),
:groups => [:dope_people]
}
@redis.get("feature:chat").should_not be_nil
+ end
+
+ it "imports settings that were globally activated" do
+ @legacy.activate_globally(:video_chat)
+ @rollout.get(:video_chat).to_hash[:percentage].should == 100
+ end
+ end
+end
+
+describe "Rollout::Feature" do
+ before do
+ @user = stub("User", :email => "test@test.com")
+ @feature = Rollout::Feature.new(:chat, nil, :id_user_by => :email)
+ end
+
+ describe "#add_user" do
+ it "ids a user using id_user_by" do
+ @feature.add_user(@user)
+ @user.should have_received :email
end
end
end