forked from fetlife/rollout
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Ergonomics of Rollout::Feature#active?
This changes signature of `Rollout::Feature#active?` to not require `rollout` instance as first argument. When querying same feature for different users, it was required to do something like: ```ruby feature = $rollout.get(:foo) users.each do |user| puts feature.active?($rollout, user) end ``` This PR changes API so it's possible to just do: ```ruby feature = $rollout.get(:foo) users.each do |user| puts feature.active?(user) end ``` ---- Note: This API was never advertised but just to be sure, we just bump major version when releasing this change.
- Loading branch information
1 parent
6538f23
commit 789362e
Showing
4 changed files
with
267 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
require "spec_helper" | ||
|
||
describe "Rollout::Feature" do | ||
let(:rollout) { Rollout.new(Redis.current) } | ||
|
||
describe "#add_user" do | ||
it "ids a user using id_user_by" do | ||
user = double("User", email: "[email protected]") | ||
feature = Rollout::Feature.new(:chat, state: nil, rollout: rollout, options: { 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, rollout: rollout) | ||
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, state: nil, rollout: rollout) | ||
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, state: "", rollout: rollout) | ||
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, state: "0||", rollout: rollout) | ||
expect(feature.data).to eq({}) | ||
end | ||
|
||
it 'sets @data to empty hash' do | ||
feature = Rollout::Feature.new(:chat, state: "||| ", rollout: rollout) | ||
expect(feature.data).to eq({}) | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.