mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-16 04:24:23 +00:00
This enables toggling features as best fits us in each case. With this new approach we can then toggle :customer_balance to an entire instance, which is what we want in France.
48 lines
1.4 KiB
Ruby
48 lines
1.4 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe 'config/initializers/feature_toggles.rb' do
|
|
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
|
|
require './config/initializers/feature_toggles' # execute the initializer's code block
|
|
|
|
enabled = OpenFoodNetwork::FeatureToggle.enabled?(:customer_balance, user)
|
|
expect(enabled).to eq(true)
|
|
end
|
|
end
|
|
|
|
context 'when beta_testers is a list of emails' do
|
|
context 'and the user is in the list' do
|
|
let(:other_user) { build(:user) }
|
|
before { ENV['BETA_TESTERS'] = "#{user.email}, #{other_user.email}" }
|
|
|
|
it 'enables the feature' do
|
|
require './config/initializers/feature_toggles' # execute the initializer's code block
|
|
|
|
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'] = '' }
|
|
|
|
it 'disables the feature' do
|
|
require './config/initializers/feature_toggles' # execute the initializer's code block
|
|
|
|
enabled = OpenFoodNetwork::FeatureToggle.enabled?(:customer_balance, user)
|
|
expect(enabled).to eq(false)
|
|
end
|
|
end
|
|
end
|
|
end
|