-
-
Notifications
You must be signed in to change notification settings - Fork 730
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6801 from coopdevs/toggle-customer-balance-to-ent…
…ire-instance Toggle customer balance to entire instance
- Loading branch information
Showing
4 changed files
with
93 additions
and
18 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
require 'open_food_network/feature_toggle' | ||
|
||
beta_testers = ENV['BETA_TESTERS']&.split(/[\s,]+/) | ||
beta_testers = ENV['BETA_TESTERS']&.split(/[\s,]+/) || [] | ||
|
||
OpenFoodNetwork::FeatureToggle.enable(:customer_balance, beta_testers) | ||
OpenFoodNetwork::FeatureToggle.enable(:customer_balance) do |user| | ||
if beta_testers == ['all'] | ||
true | ||
else | ||
beta_testers.include?(user.email) | ||
end | ||
end |
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,65 @@ | ||
require 'spec_helper' | ||
|
||
describe 'config/initializers/feature_toggles.rb' do | ||
# Executes the initializer's code block by reading the Ruby file. Note that `Kernel#require` would | ||
# prevent this from happening twice. | ||
subject(:execute_initializer) do | ||
load Rails.root.join('config/initializers/feature_toggles.rb') | ||
end | ||
|
||
let(:user) { build(:user) } | ||
|
||
around do |example| | ||
original = ENV['BETA_TESTERS'] | ||
example.run | ||
ENV['BETA_TESTERS'] = original | ||
end | ||
|
||
context 'when beta_testers is ["all"]' do | ||
before { ENV['BETA_TESTERS'] = 'all' } | ||
|
||
it 'returns true' do | ||
execute_initializer | ||
|
||
enabled = OpenFoodNetwork::FeatureToggle.enabled?(:customer_balance, user) | ||
expect(enabled).to eq(true) | ||
end | ||
end | ||
|
||
context 'when beta_testers is a list of emails' do | ||
let(:other_user) { build(:user) } | ||
|
||
context 'and the user is in the list' do | ||
before { ENV['BETA_TESTERS'] = "#{user.email}, #{other_user.email}" } | ||
|
||
it 'enables the feature' do | ||
execute_initializer | ||
|
||
enabled = OpenFoodNetwork::FeatureToggle.enabled?(:customer_balance, user) | ||
expect(enabled).to eq(true) | ||
end | ||
end | ||
|
||
context 'and the user is not in the list' do | ||
before { ENV['BETA_TESTERS'] = "#{other_user.email}" } | ||
|
||
it 'disables the feature' do | ||
execute_initializer | ||
|
||
enabled = OpenFoodNetwork::FeatureToggle.enabled?(:customer_balance, user) | ||
expect(enabled).to eq(false) | ||
end | ||
end | ||
|
||
context 'and the list is empty' do | ||
before { ENV['BETA_TESTERS'] = '' } | ||
|
||
it 'disables the feature' do | ||
execute_initializer | ||
|
||
enabled = OpenFoodNetwork::FeatureToggle.enabled?(:customer_balance, user) | ||
expect(enabled).to eq(false) | ||
end | ||
end | ||
end | ||
end |
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