spec/rollout_spec.rb in rollout-2.3.0 vs spec/rollout_spec.rb in rollout-2.4.0
- old
+ new
@@ -49,10 +49,16 @@
it "deactivates the rules for that group" do
expect(@rollout).not_to be_active(:chat, double(id: 10))
end
it "leaves the other groups active" do
+ expect(@rollout.get(:chat).groups).to eq [:fivesonly]
+ end
+
+ it "leaves the other groups active using sets" do
+ @options = @rollout.instance_variable_get("@options")
+ @options[:use_sets] = true
expect(@rollout.get(:chat).groups).to eq [:fivesonly].to_set
end
end
describe "deactivating a feature completely" do
@@ -167,10 +173,19 @@
it "that user should no longer be active" do
expect(@rollout).not_to be_active(:chat, double(id: 42))
end
it "remains active for other active users" do
+ @options = @rollout.instance_variable_get("@options")
+ @options[:use_sets] = false
+ expect(@rollout.get(:chat).users).to eq %w(24)
+ end
+
+ it "remains active for other active users using sets" do
+ @options = @rollout.instance_variable_get("@options")
+ @options[:use_sets] = true
+
expect(@rollout.get(:chat).users).to eq %w(24).to_set
end
end
describe "deactivating a group of users" do
@@ -217,10 +232,14 @@
end
it "activates the feature" do
expect(@rollout).to be_active(:chat)
end
+
+ it "sets @data to empty hash" do
+ expect(@rollout.get(:chat).data).to eq({})
+ end
end
describe "activating a feature for a percentage of users" do
before do
@rollout.activate_percentage(:chat, 20)
@@ -342,10 +361,18 @@
describe "deleting a feature" do
before do
@rollout.set(:chat, true)
end
+ context "when feature was passed as string" do
+ it "should be removed from features list" do
+ expect(@rollout.features.size).to eq 1
+ @rollout.delete('chat')
+ expect(@rollout.features.size).to eq 0
+ end
+ end
+
it "should be removed from features list" do
expect(@rollout.features.size).to eq 1
@rollout.delete(:chat)
expect(@rollout.features.size).to eq 0
end
@@ -385,10 +412,30 @@
@rollout.activate_user(:chat, double(id: 42))
end
it "returns the feature object" do
feature = @rollout.get(:chat)
+ expect(feature.groups).to eq [:caretakers, :greeters]
+ expect(feature.percentage).to eq 10
+ expect(feature.users).to eq %w(42)
+ expect(feature.to_hash).to eq(
+ groups: [:caretakers, :greeters],
+ percentage: 10,
+ users: %w(42)
+ )
+
+ feature = @rollout.get(:signup)
+ expect(feature.groups).to be_empty
+ expect(feature.users).to be_empty
+ expect(feature.percentage).to eq(100)
+ end
+
+ it "returns the feature objects using sets" do
+ @options = @rollout.instance_variable_get("@options")
+ @options[:use_sets] = true
+
+ feature = @rollout.get(:chat)
expect(feature.groups).to eq [:caretakers, :greeters].to_set
expect(feature.percentage).to eq 10
expect(feature.users).to eq %w(42).to_set
expect(feature.to_hash).to eq(
groups: [:caretakers, :greeters].to_set,
@@ -414,10 +461,22 @@
it "each feature is cleared" do
features.each do |feature|
expect(@rollout.get(feature).to_hash).to eq(
percentage: 0,
+ users: [],
+ groups: []
+ )
+ end
+ end
+
+ it "each feature is cleared with sets" do
+ @options = @rollout.instance_variable_get("@options")
+ @options[:use_sets] = true
+ features.each do |feature|
+ expect(@rollout.get(feature).to_hash).to eq(
+ percentage: 0,
users: Set.new,
groups: Set.new
)
end
end
@@ -513,20 +572,129 @@
it "returns false if activated for group" do
@rollout.activate_group(:chat, :all)
expect(@rollout.user_in_active_users?(:chat, "5")).to eq(false)
end
end
-end
-describe "Rollout::Feature" do
- before do
- @user = double("User", email: "test@test.com")
- @feature = Rollout::Feature.new(:chat, nil, id_user_by: :email)
+ describe "#multi_get" do
+ before do
+ @rollout.activate_percentage(:chat, 10)
+ @rollout.activate_group(:chat, :caretakers)
+ @rollout.activate_group(:videos, :greeters)
+ @rollout.activate(:signup)
+ @rollout.activate_user(:photos, double(id: 42))
+ end
+
+ it "returns an array of features" do
+ features = @rollout.multi_get(:chat, :videos, :signup)
+ expect(features[0].name).to eq :chat
+ expect(features[0].groups).to eq [:caretakers]
+ expect(features[0].percentage).to eq 10
+ expect(features[1].name).to eq :videos
+ expect(features[1].groups).to eq [:greeters]
+ expect(features[2].name).to eq :signup
+ expect(features[2].percentage).to eq 100
+ expect(features.size).to eq 3
+ end
end
+ describe "#set_feature_data" do
+ before do
+ @rollout.set_feature_data(:chat, description: 'foo', release_date: 'bar')
+ end
+
+ it 'sets the data attribute on feature' do
+ expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
+ end
+
+ it 'updates a data attribute' do
+ @rollout.set_feature_data(:chat, description: 'baz')
+ expect(@rollout.get(:chat).data).to include('description' => 'baz', 'release_date' => 'bar')
+ end
+
+ it 'only sets data on specified feature' do
+ @rollout.set_feature_data(:talk, image_url: 'kittens.png')
+ expect(@rollout.get(:chat).data).not_to include('image_url' => 'kittens.png')
+ expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
+ end
+
+ it 'does not modify @data if param is nil' do
+ expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
+ @rollout.set_feature_data(:chat, nil)
+ expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
+ end
+
+ it 'does not modify @data if param is empty string' do
+ expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
+ @rollout.set_feature_data(:chat, " ")
+ expect(@rollout.get(:chat).data).to include('description' => 'foo', 'release_date' => 'bar')
+ end
+
+ it 'properly parses data when it contains a |' do
+ user = double("User", id: 8)
+ @rollout.activate_user(:chat, user)
+ @rollout.set_feature_data(:chat, "|call||text|" => "a|bunch|of|stuff")
+ expect(@rollout.get(:chat).data).to include("|call||text|" => "a|bunch|of|stuff")
+ expect(@rollout.active?(:chat, user)).to be true
+ end
+ end
+
+ describe "#clear_feature_data" do
+ it 'resets data to empty string' do
+ @rollout.set_feature_data(:chat, description: 'foo')
+ expect(@rollout.get(:chat).data).to include('description' => 'foo')
+ @rollout.clear_feature_data(:chat)
+ expect(@rollout.get(:chat).data).to eq({})
+ end
+ end
+end
+
+describe "Rollout::Feature" do
describe "#add_user" do
it "ids a user using id_user_by" do
- @feature.add_user(@user)
- expect(@user).to have_received :email
+ user = double("User", email: "test@test.com")
+ feature = Rollout::Feature.new(:chat, nil, id_user_by: :email)
+ feature.add_user(user)
+ expect(user).to have_received :email
+ end
+ end
+
+ describe "#initialize" do
+ describe "when string does not exist" do
+ it 'clears feature attributes when string is not given' do
+ feature = Rollout::Feature.new(:chat)
+ expect(feature.groups).to be_empty
+ expect(feature.users).to be_empty
+ expect(feature.percentage).to eq 0
+ expect(feature.data).to eq({})
+ end
+
+ it 'clears feature attributes when string is nil' do
+ feature = Rollout::Feature.new(:chat, nil)
+ expect(feature.groups).to be_empty
+ expect(feature.users).to be_empty
+ expect(feature.percentage).to eq 0
+ expect(feature.data).to eq({})
+ end
+
+ it 'clears feature attributes when string is empty string' do
+ feature = Rollout::Feature.new(:chat, "")
+ expect(feature.groups).to be_empty
+ expect(feature.users).to be_empty
+ expect(feature.percentage).to eq 0
+ expect(feature.data).to eq({})
+ end
+
+ describe "when there is no data" do
+ it 'sets @data to empty hash' do
+ feature = Rollout::Feature.new(:chat, "0||")
+ expect(feature.data).to eq({})
+ end
+
+ it 'sets @data to empty hash' do
+ feature = Rollout::Feature.new(:chat, "||| ")
+ expect(feature.data).to eq({})
+ end
+ end
end
end
end