Clarify test users in feature toggle spec

This commit is contained in:
Maikel Linke
2021-04-09 16:54:35 +10:00
committed by Jean-Baptiste Bellet
parent f242dc8a19
commit 8a062b05eb

View File

@@ -41,7 +41,8 @@ module OpenFoodNetwork
end
context 'when specifying users' do
let(:user) { build(:user) }
let(:insider) { build(:user) }
let(:outsider) { build(:user, email: "different") }
context 'and the block does not specify arguments' do
before do
@@ -49,20 +50,20 @@ module OpenFoodNetwork
end
it "returns the block's return value" do
expect(FeatureToggle.enabled?(:foo, user)).to eq('return value')
expect(FeatureToggle.enabled?(:foo, insider)).to eq('return value')
end
end
context 'and the block specifies arguments' do
let(:users) { [user.email] }
let(:users) { [insider.email] }
before do
FeatureToggle.enable(:foo) { |user| users.include?(user&.email) }
end
it "returns the block's return value" do
expect(FeatureToggle.enabled?(:foo, user)).to eq(true)
expect(FeatureToggle.enabled?(:foo, OpenStruct.new(email: "different"))).to eq(false)
expect(FeatureToggle.enabled?(:foo, insider)).to eq(true)
expect(FeatureToggle.enabled?(:foo, outsider)).to eq(false)
expect(FeatureToggle.enabled?(:foo, nil)).to eq(false)
end
end