blob: 30d119672831929a6285f56377a8975ec3f04c90 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
require 'spec_helper'
describe CookieRestriction do
subject { described_class.new(:my_feature) }
before do
allow(Feature).to receive(:enabled?).and_call_original
end
describe "#cookie_name" do
it "returns the name of the enable cookie" do
expect(subject.cookie_name).to eq "enable_my_feature"
end
end
describe "#cookie_feature" do
it "returns a feature name used to lift the cookie restriction" do
expect(subject.cookie_feature).to eq :skip_my_feature_cookie_restriction
end
end
describe "#cookie_required?" do
it "defaults to requiring a cookie" do
expect(subject.cookie_required?).to eq true
end
context "with the restriction disabled" do
before do
stub_feature_flags(skip_my_feature_cookie_restriction: true)
end
it "doesn't require a cookie set to use the feature" do
expect(subject.cookie_required?).to eq false
end
end
end
describe "#active?" do
it "is false by default when the cookie is not present" do
cookies = {}
expect(subject.active?(cookies)).to be_falsey
end
it "looks up cookies to enable the feature" do
cookies = { 'enable_my_feature' => "true" }
expect(subject.active?(cookies)).to eq true
end
it "can be disabled by cookie" do
cookies = { 'enable_my_feature' => "false" }
expect(subject.active?(cookies)).to eq false
end
it "is true when the cookie restriction has been lifted" do
stub_feature_flags(skip_my_feature_cookie_restriction: true)
cookies = []
expect(subject.active?(cookies)).to eq true
end
end
end
|