flipper 1.4.2 → 1.5.0.rc1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +70 -10
- data/lib/flipper/adapter.rb +24 -0
- data/lib/flipper/adapter_builder.rb +12 -1
- data/lib/flipper/adapters/actor_limit.rb +4 -3
- data/lib/flipper/adapters/cache_base.rb +17 -0
- data/lib/flipper/adapters/dual_write.rb +12 -0
- data/lib/flipper/adapters/failover.rb +15 -0
- data/lib/flipper/adapters/failsafe.rb +16 -0
- data/lib/flipper/adapters/http/client.rb +7 -3
- data/lib/flipper/adapters/http/redacted_debug_output.rb +70 -0
- data/lib/flipper/adapters/http.rb +42 -8
- data/lib/flipper/adapters/instrumented.rb +28 -0
- data/lib/flipper/adapters/memoizable.rb +21 -5
- data/lib/flipper/adapters/memory.rb +63 -31
- data/lib/flipper/adapters/poll.rb +51 -6
- data/lib/flipper/adapters/pstore.rb +15 -0
- data/lib/flipper/adapters/read_only.rb +1 -1
- data/lib/flipper/adapters/strict.rb +17 -1
- data/lib/flipper/adapters/sync/feature_synchronizer.rb +3 -1
- data/lib/flipper/adapters/sync/synchronizer.rb +20 -1
- data/lib/flipper/adapters/sync.rb +8 -0
- data/lib/flipper/adapters/wrapper.rb +7 -0
- data/lib/flipper/cli.rb +87 -22
- data/lib/flipper/cloud/configuration.rb +138 -19
- data/lib/flipper/cloud/dsl.rb +6 -0
- data/lib/flipper/cloud/memory_adapter.rb +43 -0
- data/lib/flipper/cloud/message_verifier.rb +1 -0
- data/lib/flipper/cloud/middleware.rb +8 -3
- data/lib/flipper/cloud/migrate.rb +3 -1
- data/lib/flipper/cloud/routes.rb +24 -2
- data/lib/flipper/cloud/shared_memory.rb +84 -0
- data/lib/flipper/cloud/telemetry.rb +56 -28
- data/lib/flipper/cloud/url_validator.rb +26 -0
- data/lib/flipper/cloud.rb +22 -4
- data/lib/flipper/configuration.rb +86 -3
- data/lib/flipper/dsl.rb +47 -3
- data/lib/flipper/engine.rb +64 -8
- data/lib/flipper/errors.rb +18 -0
- data/lib/flipper/export.rb +4 -0
- data/lib/flipper/exporters/json/export.rb +6 -0
- data/lib/flipper/exporters/json/v1.rb +5 -9
- data/lib/flipper/expression/constant.rb +6 -0
- data/lib/flipper/expression.rb +105 -1
- data/lib/flipper/expressions/comparable.rb +5 -0
- data/lib/flipper/expressions/feature_enabled.rb +11 -7
- data/lib/flipper/expressions/number.rb +2 -0
- data/lib/flipper/expressions/percentage.rb +3 -1
- data/lib/flipper/expressions/percentage_of_actors.rb +9 -0
- data/lib/flipper/expressions/random.rb +2 -0
- data/lib/flipper/expressions/sem_ver.rb +24 -0
- data/lib/flipper/expressions/time.rb +9 -1
- data/lib/flipper/feature.rb +153 -43
- data/lib/flipper/feature_check_context.rb +19 -1
- data/lib/flipper/gates/actor.rb +4 -1
- data/lib/flipper/gates/expression.rb +17 -2
- data/lib/flipper/gates/group.rb +1 -1
- data/lib/flipper/gates/percentage_of_actors.rb +19 -2
- data/lib/flipper/gates/percentage_of_time.rb +4 -1
- data/lib/flipper/groups.rb +66 -0
- data/lib/flipper/instrumentation/log_subscriber.rb +6 -1
- data/lib/flipper/instrumentation/subscriber.rb +21 -2
- data/lib/flipper/middleware/memoizer.rb +5 -2
- data/lib/flipper/named_configuration.rb +194 -0
- data/lib/flipper/named_proxy.rb +46 -0
- data/lib/flipper/poller.rb +39 -17
- data/lib/flipper/sem_ver.rb +84 -0
- data/lib/flipper/spec/shared_adapter_specs.rb +40 -0
- data/lib/flipper/sync_version.rb +61 -0
- data/lib/flipper/test_help.rb +50 -0
- data/lib/flipper/typecast.rb +15 -0
- data/lib/flipper/types/group.rb +2 -2
- data/lib/flipper/version.rb +1 -1
- data/lib/flipper.rb +183 -65
- data/lib/generators/flipper/setup_generator.rb +18 -0
- data/lib/generators/flipper/table_prefix.rb +44 -0
- data/lib/generators/flipper/templates/initializer.rb +7 -0
- data/lib/generators/flipper/templates/update/migrations/01_create_flipper_tables.rb.erb +13 -7
- data/lib/generators/flipper/templates/update/migrations/02_change_flipper_gates_value_to_text.rb.erb +12 -7
- data/lib/generators/flipper/update_generator.rb +3 -0
- metadata +42 -171
- data/.codeclimate.yml +0 -3
- data/.github/FUNDING.yml +0 -1
- data/.github/dependabot.yml +0 -6
- data/.github/workflows/ci.yml +0 -110
- data/.github/workflows/examples.yml +0 -105
- data/.github/workflows/release.yml +0 -54
- data/.rspec +0 -1
- data/.superset/config.json +0 -4
- data/CLAUDE.md +0 -93
- data/CODE_OF_CONDUCT.md +0 -46
- data/Dockerfile +0 -27
- data/Gemfile +0 -41
- data/Rakefile +0 -54
- data/benchmark/enabled_ips.rb +0 -10
- data/benchmark/enabled_multiple_actors_ips.rb +0 -20
- data/benchmark/enabled_profile.rb +0 -20
- data/benchmark/instrumentation_ips.rb +0 -21
- data/benchmark/typecast_ips.rb +0 -27
- data/docker-compose.yml +0 -37
- data/docs/DockerCompose.md +0 -18
- data/docs/README.md +0 -1
- data/docs/images/banner.jpg +0 -0
- data/docs/images/flipper_cloud.png +0 -0
- data/examples/api/basic.ru +0 -18
- data/examples/api/custom_memoized.ru +0 -36
- data/examples/api/memoized.ru +0 -42
- data/examples/basic.rb +0 -19
- data/examples/cloud/app.ru +0 -12
- data/examples/cloud/backoff_policy.rb +0 -13
- data/examples/cloud/basic.rb +0 -22
- data/examples/cloud/cloud_setup.rb +0 -20
- data/examples/cloud/forked.rb +0 -36
- data/examples/cloud/import.rb +0 -17
- data/examples/cloud/poll_interval/README.md +0 -111
- data/examples/cloud/poll_interval/client.rb +0 -108
- data/examples/cloud/poll_interval/server.rb +0 -98
- data/examples/cloud/threaded.rb +0 -33
- data/examples/configuring_default.rb +0 -19
- data/examples/dsl.rb +0 -57
- data/examples/enabled_for_actor.rb +0 -37
- data/examples/expressions.rb +0 -237
- data/examples/group.rb +0 -38
- data/examples/group_dynamic_lookup.rb +0 -75
- data/examples/group_with_members.rb +0 -83
- data/examples/importing.rb +0 -29
- data/examples/individual_actor.rb +0 -28
- data/examples/instrumentation.rb +0 -42
- data/examples/instrumentation_last_accessed_at.rb +0 -38
- data/examples/memoizing.rb +0 -35
- data/examples/mirroring.rb +0 -59
- data/examples/percentage_of_actors.rb +0 -31
- data/examples/percentage_of_actors_enabled_check.rb +0 -35
- data/examples/percentage_of_actors_group.rb +0 -35
- data/examples/percentage_of_time.rb +0 -27
- data/examples/strict.rb +0 -18
- data/flipper-cloud.gemspec +0 -19
- data/flipper.gemspec +0 -42
- data/package-lock.json +0 -41
- data/package.json +0 -10
- data/spec/fixtures/environment.rb +0 -1
- data/spec/fixtures/feature.json +0 -31
- data/spec/fixtures/flipper_pstore_1679087600.json +0 -46
- data/spec/flipper/actor_spec.rb +0 -56
- data/spec/flipper/adapter_builder_spec.rb +0 -72
- data/spec/flipper/adapter_spec.rb +0 -166
- data/spec/flipper/adapters/actor_limit_spec.rb +0 -75
- data/spec/flipper/adapters/dual_write_spec.rb +0 -82
- data/spec/flipper/adapters/failover_spec.rb +0 -141
- data/spec/flipper/adapters/failsafe_spec.rb +0 -58
- data/spec/flipper/adapters/http/client_spec.rb +0 -61
- data/spec/flipper/adapters/http_spec.rb +0 -596
- data/spec/flipper/adapters/instrumented_spec.rb +0 -167
- data/spec/flipper/adapters/memoizable_spec.rb +0 -377
- data/spec/flipper/adapters/memory_spec.rb +0 -36
- data/spec/flipper/adapters/operation_logger_spec.rb +0 -128
- data/spec/flipper/adapters/poll_spec.rb +0 -41
- data/spec/flipper/adapters/pstore_spec.rb +0 -16
- data/spec/flipper/adapters/read_only_spec.rb +0 -100
- data/spec/flipper/adapters/strict_spec.rb +0 -122
- data/spec/flipper/adapters/sync/feature_synchronizer_spec.rb +0 -247
- data/spec/flipper/adapters/sync/interval_synchronizer_spec.rb +0 -33
- data/spec/flipper/adapters/sync/synchronizer_spec.rb +0 -175
- data/spec/flipper/adapters/sync_spec.rb +0 -213
- data/spec/flipper/cli_spec.rb +0 -217
- data/spec/flipper/cloud/configuration_spec.rb +0 -251
- data/spec/flipper/cloud/dsl_spec.rb +0 -82
- data/spec/flipper/cloud/message_verifier_spec.rb +0 -104
- data/spec/flipper/cloud/middleware_spec.rb +0 -289
- data/spec/flipper/cloud/migrate_spec.rb +0 -160
- data/spec/flipper/cloud/telemetry/backoff_policy_spec.rb +0 -107
- data/spec/flipper/cloud/telemetry/metric_spec.rb +0 -87
- data/spec/flipper/cloud/telemetry/metric_storage_spec.rb +0 -58
- data/spec/flipper/cloud/telemetry/submitter_spec.rb +0 -145
- data/spec/flipper/cloud/telemetry_spec.rb +0 -208
- data/spec/flipper/cloud_spec.rb +0 -186
- data/spec/flipper/configuration_spec.rb +0 -50
- data/spec/flipper/dsl_spec.rb +0 -346
- data/spec/flipper/engine_spec.rb +0 -374
- data/spec/flipper/export_spec.rb +0 -13
- data/spec/flipper/exporter_spec.rb +0 -16
- data/spec/flipper/exporters/json/export_spec.rb +0 -60
- data/spec/flipper/exporters/json/v1_spec.rb +0 -33
- data/spec/flipper/expression/builder_spec.rb +0 -248
- data/spec/flipper/expression_spec.rb +0 -188
- data/spec/flipper/expressions/all_spec.rb +0 -15
- data/spec/flipper/expressions/any_spec.rb +0 -15
- data/spec/flipper/expressions/boolean_spec.rb +0 -15
- data/spec/flipper/expressions/equal_spec.rb +0 -24
- data/spec/flipper/expressions/greater_than_or_equal_to_spec.rb +0 -28
- data/spec/flipper/expressions/greater_than_spec.rb +0 -28
- data/spec/flipper/expressions/less_than_or_equal_to_spec.rb +0 -28
- data/spec/flipper/expressions/less_than_spec.rb +0 -32
- data/spec/flipper/expressions/not_equal_spec.rb +0 -15
- data/spec/flipper/expressions/now_spec.rb +0 -11
- data/spec/flipper/expressions/number_spec.rb +0 -21
- data/spec/flipper/expressions/percentage_of_actors_spec.rb +0 -20
- data/spec/flipper/expressions/percentage_spec.rb +0 -15
- data/spec/flipper/expressions/property_spec.rb +0 -13
- data/spec/flipper/expressions/random_spec.rb +0 -9
- data/spec/flipper/expressions/string_spec.rb +0 -11
- data/spec/flipper/expressions/time_spec.rb +0 -29
- data/spec/flipper/feature_check_context_spec.rb +0 -65
- data/spec/flipper/feature_spec.rb +0 -1227
- data/spec/flipper/gate_spec.rb +0 -39
- data/spec/flipper/gate_values_spec.rb +0 -103
- data/spec/flipper/gates/actor_spec.rb +0 -7
- data/spec/flipper/gates/boolean_spec.rb +0 -74
- data/spec/flipper/gates/expression_spec.rb +0 -190
- data/spec/flipper/gates/group_spec.rb +0 -62
- data/spec/flipper/gates/percentage_of_actors_spec.rb +0 -131
- data/spec/flipper/gates/percentage_of_time_spec.rb +0 -37
- data/spec/flipper/identifier_spec.rb +0 -12
- data/spec/flipper/instrumentation/log_subscriber_spec.rb +0 -122
- data/spec/flipper/instrumentation/statsd_subscriber_spec.rb +0 -95
- data/spec/flipper/instrumenters/memory_spec.rb +0 -43
- data/spec/flipper/instrumenters/noop_spec.rb +0 -27
- data/spec/flipper/middleware/memoizer_spec.rb +0 -518
- data/spec/flipper/middleware/setup_env_spec.rb +0 -94
- data/spec/flipper/model/active_record_spec.rb +0 -72
- data/spec/flipper/poller_spec.rb +0 -390
- data/spec/flipper/registry_spec.rb +0 -140
- data/spec/flipper/serializers/gzip_spec.rb +0 -13
- data/spec/flipper/serializers/json_spec.rb +0 -13
- data/spec/flipper/typecast_spec.rb +0 -232
- data/spec/flipper/types/actor_spec.rb +0 -132
- data/spec/flipper/types/boolean_spec.rb +0 -23
- data/spec/flipper/types/group_spec.rb +0 -112
- data/spec/flipper/types/percentage_of_actors_spec.rb +0 -5
- data/spec/flipper/types/percentage_of_time_spec.rb +0 -5
- data/spec/flipper/types/percentage_spec.rb +0 -46
- data/spec/flipper_integration_spec.rb +0 -783
- data/spec/flipper_spec.rb +0 -422
- data/spec/spec_helper.rb +0 -112
- data/spec/support/actor_names.yml +0 -1
- data/spec/support/descriptions.yml +0 -1
- data/spec/support/fail_on_output.rb +0 -8
- data/spec/support/fake_backoff_policy.rb +0 -15
- data/spec/support/fake_udp_socket.rb +0 -27
- data/spec/support/skippable.rb +0 -18
- data/spec/support/spec_helpers.rb +0 -111
- data/test/adapters/actor_limit_test.rb +0 -20
- data/test/adapters/memory_test.rb +0 -9
- data/test/adapters/pstore_test.rb +0 -17
- data/test/test_helper.rb +0 -7
- data/test_rails/generators/flipper/setup_generator_test.rb +0 -69
- data/test_rails/generators/flipper/update_generator_test.rb +0 -96
- data/test_rails/helper.rb +0 -31
- data/test_rails/system/test_help_test.rb +0 -52
|
@@ -1,783 +0,0 @@
|
|
|
1
|
-
require 'flipper/feature'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Flipper do
|
|
4
|
-
let(:adapter) { Flipper::Adapters::Memory.new }
|
|
5
|
-
let(:flipper) { described_class.new(adapter) }
|
|
6
|
-
let(:feature) { flipper[:search] }
|
|
7
|
-
let(:admin_group) { flipper.group(:admins) }
|
|
8
|
-
let(:dev_group) { flipper.group(:devs) }
|
|
9
|
-
|
|
10
|
-
let(:admin_actor) do
|
|
11
|
-
double 'Non Flipper Thing', flipper_id: 1, admin?: true, dev?: false, flipper_properties: {"admin" => true, "dev" => false}
|
|
12
|
-
end
|
|
13
|
-
let(:dev_actor) do
|
|
14
|
-
double 'Non Flipper Thing', flipper_id: 10, admin?: false, dev?: true, flipper_properties: {"admin" => false, "dev" => true}
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
let(:admin_truthy_actor) do
|
|
18
|
-
double 'Non Flipper Thing', flipper_id: 1, admin?: 'true-ish', dev?: false, flipper_properties: {"admin" => "true-ish", "dev" => false}
|
|
19
|
-
end
|
|
20
|
-
let(:admin_falsey_actor) do
|
|
21
|
-
double 'Non Flipper Thing', flipper_id: 1, admin?: nil, dev?: false, flipper_properties: {"admin" => nil, "dev" => false}
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
let(:basic_plan_actor) do
|
|
25
|
-
double 'Non Flipper Thing', flipper_id: 1, flipper_properties: {"plan" => "basic"}
|
|
26
|
-
end
|
|
27
|
-
let(:premium_plan_actor) do
|
|
28
|
-
double 'Non Flipper Thing', flipper_id: 10, flipper_properties: {"plan" => "premium"}
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
let(:pitt) { Flipper::Actor.new(1) }
|
|
32
|
-
let(:clooney) { Flipper::Actor.new(10) }
|
|
33
|
-
|
|
34
|
-
let(:five_percent_of_actors) { Flipper::Types::PercentageOfActors.new(5) }
|
|
35
|
-
let(:five_percent_of_time) { Flipper::Types::PercentageOfTime.new(5) }
|
|
36
|
-
|
|
37
|
-
before do
|
|
38
|
-
described_class.register(:admins, &:admin?)
|
|
39
|
-
described_class.register(:devs, &:dev?)
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
describe '#enable' do
|
|
43
|
-
context 'with no arguments' do
|
|
44
|
-
before do
|
|
45
|
-
@result = feature.enable
|
|
46
|
-
end
|
|
47
|
-
|
|
48
|
-
it 'returns true' do
|
|
49
|
-
expect(@result).to eq(true)
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it 'enables feature for all' do
|
|
53
|
-
expect(feature.enabled?).to eq(true)
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
it 'adds feature to set of features' do
|
|
57
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
58
|
-
end
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
context 'with a group' do
|
|
62
|
-
before do
|
|
63
|
-
@result = feature.enable(admin_group)
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
it 'returns true' do
|
|
67
|
-
expect(@result).to eq(true)
|
|
68
|
-
end
|
|
69
|
-
|
|
70
|
-
it 'enables feature for non flipper actor in group' do
|
|
71
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
it 'does not enable feature for non flipper actor in other group' do
|
|
75
|
-
expect(feature.enabled?(dev_actor)).to eq(false)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'enables feature for flipper actor in group' do
|
|
79
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(admin_actor))).to eq(true)
|
|
80
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
81
|
-
end
|
|
82
|
-
|
|
83
|
-
it 'does not enable for flipper actor not in group' do
|
|
84
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(dev_actor))).to eq(false)
|
|
85
|
-
expect(feature.enabled?(dev_actor)).to eq(false)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it 'does not enable feature for all' do
|
|
89
|
-
expect(feature.enabled?).to eq(false)
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it 'adds feature to set of features' do
|
|
93
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
94
|
-
end
|
|
95
|
-
end
|
|
96
|
-
|
|
97
|
-
context 'with an actor' do
|
|
98
|
-
before do
|
|
99
|
-
@result = feature.enable(pitt)
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
it 'returns true' do
|
|
103
|
-
expect(@result).to eq(true)
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
it 'enables feature for actor' do
|
|
107
|
-
expect(feature.enabled?(pitt)).to eq(true)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it 'does not enable feature for other actors' do
|
|
111
|
-
expect(feature.enabled?(clooney)).to eq(false)
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
it 'adds feature to set of features' do
|
|
115
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
116
|
-
end
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
context 'with a percentage of actors' do
|
|
120
|
-
before do
|
|
121
|
-
@result = feature.enable(five_percent_of_actors)
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
it 'returns true' do
|
|
125
|
-
expect(@result).to eq(true)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it 'enables feature for actor within percentage' do
|
|
129
|
-
enabled = (1..100).select do |i|
|
|
130
|
-
actor = Flipper::Actor.new(i)
|
|
131
|
-
feature.enabled?(actor)
|
|
132
|
-
end.size
|
|
133
|
-
|
|
134
|
-
expect(enabled).to be_within(2).of(5)
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
it 'adds feature to set of features' do
|
|
138
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
context 'with a float percentage of actors' do
|
|
143
|
-
before do
|
|
144
|
-
@result = feature.enable_percentage_of_actors 5.1
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
it 'returns true' do
|
|
148
|
-
expect(@result).to eq(true)
|
|
149
|
-
end
|
|
150
|
-
|
|
151
|
-
it 'enables feature for actor within percentage' do
|
|
152
|
-
enabled = (1..100).select do |i|
|
|
153
|
-
actor = Flipper::Actor.new(i)
|
|
154
|
-
feature.enabled?(actor)
|
|
155
|
-
end.size
|
|
156
|
-
|
|
157
|
-
expect(enabled).to be_within(2).of(5)
|
|
158
|
-
end
|
|
159
|
-
|
|
160
|
-
it 'adds feature to set of features' do
|
|
161
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
162
|
-
end
|
|
163
|
-
end
|
|
164
|
-
|
|
165
|
-
context 'with a percentage of time' do
|
|
166
|
-
before do
|
|
167
|
-
@gate = feature.gate(:percentage_of_time)
|
|
168
|
-
@result = feature.enable(five_percent_of_time)
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
it 'returns true' do
|
|
172
|
-
expect(@result).to eq(true)
|
|
173
|
-
end
|
|
174
|
-
|
|
175
|
-
it 'enables feature for time within percentage' do
|
|
176
|
-
allow(@gate).to receive_messages(rand: 0.04)
|
|
177
|
-
expect(feature.enabled?).to eq(true)
|
|
178
|
-
end
|
|
179
|
-
|
|
180
|
-
it 'does not enable feature for time not within percentage' do
|
|
181
|
-
allow(@gate).to receive_messages(rand: 0.10)
|
|
182
|
-
expect(feature.enabled?).to eq(false)
|
|
183
|
-
end
|
|
184
|
-
|
|
185
|
-
it 'adds feature to set of features' do
|
|
186
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
187
|
-
end
|
|
188
|
-
end
|
|
189
|
-
|
|
190
|
-
context 'with argument that has no gate' do
|
|
191
|
-
it 'raises error' do
|
|
192
|
-
actor = Object.new
|
|
193
|
-
expect do
|
|
194
|
-
feature.enable(actor)
|
|
195
|
-
end.to raise_error(Flipper::GateNotFound, "Could not find gate for #{actor.inspect}")
|
|
196
|
-
end
|
|
197
|
-
end
|
|
198
|
-
end
|
|
199
|
-
|
|
200
|
-
describe '#disable' do
|
|
201
|
-
context 'with no arguments' do
|
|
202
|
-
before do
|
|
203
|
-
# ensures that time gate is stubbed with result that would be true for pitt
|
|
204
|
-
@gate = feature.gate(:percentage_of_time)
|
|
205
|
-
allow(@gate).to receive_messages(rand: 0.04)
|
|
206
|
-
|
|
207
|
-
feature.enable admin_group
|
|
208
|
-
feature.enable pitt
|
|
209
|
-
feature.enable five_percent_of_actors
|
|
210
|
-
feature.enable five_percent_of_time
|
|
211
|
-
@result = feature.disable
|
|
212
|
-
end
|
|
213
|
-
|
|
214
|
-
it 'returns true' do
|
|
215
|
-
expect(@result).to be(true)
|
|
216
|
-
end
|
|
217
|
-
|
|
218
|
-
it 'disables feature' do
|
|
219
|
-
expect(feature.enabled?).to eq(false)
|
|
220
|
-
end
|
|
221
|
-
|
|
222
|
-
it 'disables for individual actor' do
|
|
223
|
-
expect(feature.enabled?(pitt)).to eq(false)
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
it 'disables actor in group' do
|
|
227
|
-
expect(feature.enabled?(admin_actor)).to eq(false)
|
|
228
|
-
end
|
|
229
|
-
|
|
230
|
-
it 'disables actor in percentage of actors' do
|
|
231
|
-
enabled = (1..100).select do |i|
|
|
232
|
-
actor = Flipper::Actor.new(i)
|
|
233
|
-
feature.enabled?(actor)
|
|
234
|
-
end.size
|
|
235
|
-
|
|
236
|
-
expect(enabled).to be(0)
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
it 'disables percentage of time' do
|
|
240
|
-
expect(feature.enabled?(pitt)).to eq(false)
|
|
241
|
-
end
|
|
242
|
-
|
|
243
|
-
it 'adds feature to set of features' do
|
|
244
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
245
|
-
end
|
|
246
|
-
end
|
|
247
|
-
|
|
248
|
-
context 'with a group' do
|
|
249
|
-
before do
|
|
250
|
-
feature.enable dev_group
|
|
251
|
-
feature.enable admin_group
|
|
252
|
-
@result = feature.disable(admin_group)
|
|
253
|
-
end
|
|
254
|
-
|
|
255
|
-
it 'returns true' do
|
|
256
|
-
expect(@result).to eq(true)
|
|
257
|
-
end
|
|
258
|
-
|
|
259
|
-
it 'disables the feature for non flipper actor in the group' do
|
|
260
|
-
expect(feature.enabled?(admin_actor)).to eq(false)
|
|
261
|
-
end
|
|
262
|
-
|
|
263
|
-
it 'does not disable feature for non flipper actor in other groups' do
|
|
264
|
-
expect(feature.enabled?(dev_actor)).to eq(true)
|
|
265
|
-
end
|
|
266
|
-
|
|
267
|
-
it 'disables feature for flipper actor in group' do
|
|
268
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(admin_actor))).to eq(false)
|
|
269
|
-
expect(feature.enabled?(admin_actor)).to eq(false)
|
|
270
|
-
end
|
|
271
|
-
|
|
272
|
-
it 'does not disable feature for flipper actor in other groups' do
|
|
273
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(dev_actor))).to eq(true)
|
|
274
|
-
expect(feature.enabled?(dev_actor)).to eq(true)
|
|
275
|
-
end
|
|
276
|
-
|
|
277
|
-
it 'adds feature to set of features' do
|
|
278
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
279
|
-
end
|
|
280
|
-
end
|
|
281
|
-
|
|
282
|
-
context 'with an actor' do
|
|
283
|
-
before do
|
|
284
|
-
feature.enable pitt
|
|
285
|
-
feature.enable clooney
|
|
286
|
-
@result = feature.disable(pitt)
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
it 'returns true' do
|
|
290
|
-
expect(@result).to eq(true)
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
it 'disables feature for actor' do
|
|
294
|
-
expect(feature.enabled?(pitt)).to eq(false)
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
it 'does not disable feature for other actors' do
|
|
298
|
-
expect(feature.enabled?(clooney)).to eq(true)
|
|
299
|
-
end
|
|
300
|
-
|
|
301
|
-
it 'adds feature to set of features' do
|
|
302
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
303
|
-
end
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
context 'with a percentage of actors' do
|
|
307
|
-
before do
|
|
308
|
-
@result = feature.disable(Flipper::Types::PercentageOfActors.new(0))
|
|
309
|
-
end
|
|
310
|
-
|
|
311
|
-
it 'returns true' do
|
|
312
|
-
expect(@result).to eq(true)
|
|
313
|
-
end
|
|
314
|
-
|
|
315
|
-
it 'disables feature' do
|
|
316
|
-
enabled = (1..100).select do |i|
|
|
317
|
-
actor = Flipper::Actor.new(i)
|
|
318
|
-
feature.enabled?(actor)
|
|
319
|
-
end.size
|
|
320
|
-
|
|
321
|
-
expect(enabled).to be(0)
|
|
322
|
-
end
|
|
323
|
-
|
|
324
|
-
it 'adds feature to set of features' do
|
|
325
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
326
|
-
end
|
|
327
|
-
end
|
|
328
|
-
|
|
329
|
-
context 'with a percentage of time' do
|
|
330
|
-
before do
|
|
331
|
-
@gate = feature.gate(:percentage_of_time)
|
|
332
|
-
@result = feature.disable(Flipper::Types::PercentageOfTime.new(0))
|
|
333
|
-
end
|
|
334
|
-
|
|
335
|
-
it 'returns true' do
|
|
336
|
-
expect(@result).to eq(true)
|
|
337
|
-
end
|
|
338
|
-
|
|
339
|
-
it 'disables feature for time within percentage' do
|
|
340
|
-
allow(@gate).to receive_messages(rand: 0.04)
|
|
341
|
-
expect(feature.enabled?).to eq(false)
|
|
342
|
-
end
|
|
343
|
-
|
|
344
|
-
it 'disables feature for time not within percentage' do
|
|
345
|
-
allow(@gate).to receive_messages(rand: 0.10)
|
|
346
|
-
expect(feature.enabled?).to eq(false)
|
|
347
|
-
end
|
|
348
|
-
|
|
349
|
-
it 'adds feature to set of features' do
|
|
350
|
-
expect(flipper.features.map(&:name)).to include(:search)
|
|
351
|
-
end
|
|
352
|
-
end
|
|
353
|
-
|
|
354
|
-
context 'with argument that has no gate' do
|
|
355
|
-
it 'raises error' do
|
|
356
|
-
actor = Object.new
|
|
357
|
-
expect do
|
|
358
|
-
feature.disable(actor)
|
|
359
|
-
end.to raise_error(Flipper::GateNotFound, "Could not find gate for #{actor.inspect}")
|
|
360
|
-
end
|
|
361
|
-
end
|
|
362
|
-
end
|
|
363
|
-
|
|
364
|
-
describe '#enabled?' do
|
|
365
|
-
context 'with no arguments' do
|
|
366
|
-
it 'defaults to false' do
|
|
367
|
-
expect(feature.enabled?).to eq(false)
|
|
368
|
-
end
|
|
369
|
-
end
|
|
370
|
-
|
|
371
|
-
context 'with no arguments, but boolean enabled' do
|
|
372
|
-
before do
|
|
373
|
-
feature.enable
|
|
374
|
-
end
|
|
375
|
-
|
|
376
|
-
it 'returns true' do
|
|
377
|
-
expect(feature.enabled?).to eq(true)
|
|
378
|
-
end
|
|
379
|
-
end
|
|
380
|
-
|
|
381
|
-
context 'for actor in enabled group' do
|
|
382
|
-
before do
|
|
383
|
-
feature.enable admin_group
|
|
384
|
-
end
|
|
385
|
-
|
|
386
|
-
it 'returns true' do
|
|
387
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(admin_actor))).to eq(true)
|
|
388
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
389
|
-
end
|
|
390
|
-
|
|
391
|
-
it 'returns true for truthy block values' do
|
|
392
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(admin_truthy_actor))).to eq(true)
|
|
393
|
-
expect(feature.enabled?(admin_truthy_actor)).to eq(true)
|
|
394
|
-
end
|
|
395
|
-
|
|
396
|
-
it 'returns true if any actor is in enabled group' do
|
|
397
|
-
expect(feature.enabled?(dev_actor, admin_actor)).to be(true)
|
|
398
|
-
end
|
|
399
|
-
end
|
|
400
|
-
|
|
401
|
-
context 'for actor in disabled group' do
|
|
402
|
-
it 'returns false' do
|
|
403
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(dev_actor))).to eq(false)
|
|
404
|
-
expect(feature.enabled?(dev_actor)).to eq(false)
|
|
405
|
-
end
|
|
406
|
-
|
|
407
|
-
it 'returns false for falsey block values' do
|
|
408
|
-
expect(feature.enabled?(Flipper::Types::Actor.new(admin_falsey_actor))).to eq(false)
|
|
409
|
-
expect(feature.enabled?(admin_falsey_actor)).to eq(false)
|
|
410
|
-
end
|
|
411
|
-
end
|
|
412
|
-
|
|
413
|
-
context 'for enabled actor' do
|
|
414
|
-
before do
|
|
415
|
-
feature.enable pitt
|
|
416
|
-
end
|
|
417
|
-
|
|
418
|
-
it 'returns true' do
|
|
419
|
-
expect(feature.enabled?(pitt)).to eq(true)
|
|
420
|
-
end
|
|
421
|
-
end
|
|
422
|
-
|
|
423
|
-
context 'for not enabled actor' do
|
|
424
|
-
it 'returns false' do
|
|
425
|
-
expect(feature.enabled?(clooney)).to eq(false)
|
|
426
|
-
end
|
|
427
|
-
|
|
428
|
-
it 'returns false if all actors are disabled' do
|
|
429
|
-
expect(feature.enabled?(clooney, pitt)).to be(false)
|
|
430
|
-
end
|
|
431
|
-
|
|
432
|
-
it 'returns true if boolean enabled' do
|
|
433
|
-
feature.enable
|
|
434
|
-
expect(feature.enabled?(clooney)).to eq(true)
|
|
435
|
-
end
|
|
436
|
-
end
|
|
437
|
-
|
|
438
|
-
context 'for enabled percentage of time' do
|
|
439
|
-
before do
|
|
440
|
-
# ensure percentage of time returns percentage that makes five percent
|
|
441
|
-
# of time true
|
|
442
|
-
@gate = feature.gate(:percentage_of_time)
|
|
443
|
-
allow(@gate).to receive_messages(rand: 0.04)
|
|
444
|
-
|
|
445
|
-
feature.enable five_percent_of_time
|
|
446
|
-
end
|
|
447
|
-
|
|
448
|
-
it 'returns true' do
|
|
449
|
-
expect(feature.enabled?).to eq(true)
|
|
450
|
-
expect(feature.enabled?(nil)).to eq(true)
|
|
451
|
-
expect(feature.enabled?(pitt)).to eq(true)
|
|
452
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
453
|
-
end
|
|
454
|
-
end
|
|
455
|
-
|
|
456
|
-
context 'for enabled float percentage of time' do
|
|
457
|
-
before do
|
|
458
|
-
# ensure percentage of time returns percentage that makes 4.1 percent
|
|
459
|
-
# of time true
|
|
460
|
-
@gate = feature.gate(:percentage_of_time)
|
|
461
|
-
allow(@gate).to receive_messages(rand: 0.04)
|
|
462
|
-
|
|
463
|
-
feature.enable_percentage_of_time 4.1
|
|
464
|
-
end
|
|
465
|
-
|
|
466
|
-
it 'returns true' do
|
|
467
|
-
expect(feature.enabled?).to eq(true)
|
|
468
|
-
expect(feature.enabled?(nil)).to eq(true)
|
|
469
|
-
expect(feature.enabled?(pitt)).to eq(true)
|
|
470
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
471
|
-
end
|
|
472
|
-
end
|
|
473
|
-
|
|
474
|
-
context 'for NOT enabled integer percentage of time' do
|
|
475
|
-
before do
|
|
476
|
-
# ensure percentage of time returns percentage that makes enabled? false
|
|
477
|
-
@gate = feature.gate(:percentage_of_time)
|
|
478
|
-
allow(@gate).to receive_messages(rand: 0.10)
|
|
479
|
-
|
|
480
|
-
feature.enable five_percent_of_time
|
|
481
|
-
end
|
|
482
|
-
|
|
483
|
-
it 'returns false' do
|
|
484
|
-
expect(feature.enabled?).to eq(false)
|
|
485
|
-
expect(feature.enabled?(nil)).to eq(false)
|
|
486
|
-
expect(feature.enabled?(pitt)).to eq(false)
|
|
487
|
-
expect(feature.enabled?(admin_actor)).to eq(false)
|
|
488
|
-
end
|
|
489
|
-
|
|
490
|
-
it 'returns true if boolean enabled' do
|
|
491
|
-
feature.enable
|
|
492
|
-
expect(feature.enabled?).to eq(true)
|
|
493
|
-
expect(feature.enabled?(nil)).to eq(true)
|
|
494
|
-
expect(feature.enabled?(pitt)).to eq(true)
|
|
495
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
496
|
-
end
|
|
497
|
-
end
|
|
498
|
-
|
|
499
|
-
context 'for NOT enabled float percentage of time' do
|
|
500
|
-
before do
|
|
501
|
-
# ensure percentage of time returns percentage that makes enabled? false
|
|
502
|
-
@gate = feature.gate(:percentage_of_time)
|
|
503
|
-
allow(@gate).to receive_messages(rand: 0.10)
|
|
504
|
-
|
|
505
|
-
feature.enable_percentage_of_time 9.9
|
|
506
|
-
end
|
|
507
|
-
|
|
508
|
-
it 'returns false' do
|
|
509
|
-
expect(feature.enabled?).to eq(false)
|
|
510
|
-
expect(feature.enabled?(nil)).to eq(false)
|
|
511
|
-
expect(feature.enabled?(pitt)).to eq(false)
|
|
512
|
-
expect(feature.enabled?(admin_actor)).to eq(false)
|
|
513
|
-
end
|
|
514
|
-
|
|
515
|
-
it 'returns true if boolean enabled' do
|
|
516
|
-
feature.enable
|
|
517
|
-
expect(feature.enabled?).to eq(true)
|
|
518
|
-
expect(feature.enabled?(nil)).to eq(true)
|
|
519
|
-
expect(feature.enabled?(pitt)).to eq(true)
|
|
520
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
521
|
-
end
|
|
522
|
-
end
|
|
523
|
-
|
|
524
|
-
context 'for a non flipper actor' do
|
|
525
|
-
before do
|
|
526
|
-
feature.enable admin_group
|
|
527
|
-
end
|
|
528
|
-
|
|
529
|
-
it 'returns true if in enabled group' do
|
|
530
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
531
|
-
end
|
|
532
|
-
|
|
533
|
-
it 'returns false if not in enabled group' do
|
|
534
|
-
expect(feature.enabled?(dev_actor)).to eq(false)
|
|
535
|
-
end
|
|
536
|
-
|
|
537
|
-
it 'retruns true if any actor is true' do
|
|
538
|
-
expect(feature.enabled?(admin_actor, dev_actor)).to eq(true)
|
|
539
|
-
end
|
|
540
|
-
|
|
541
|
-
it 'returns true if boolean enabled' do
|
|
542
|
-
feature.enable
|
|
543
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
544
|
-
expect(feature.enabled?(dev_actor)).to eq(true)
|
|
545
|
-
end
|
|
546
|
-
end
|
|
547
|
-
end
|
|
548
|
-
|
|
549
|
-
context 'enabling multiple groups, disabling everything, then enabling one group' do
|
|
550
|
-
before do
|
|
551
|
-
feature.enable(admin_group)
|
|
552
|
-
feature.enable(dev_group)
|
|
553
|
-
feature.disable
|
|
554
|
-
feature.enable(admin_group)
|
|
555
|
-
end
|
|
556
|
-
|
|
557
|
-
it 'enables feature for object in enabled group' do
|
|
558
|
-
expect(feature.enabled?(admin_actor)).to eq(true)
|
|
559
|
-
end
|
|
560
|
-
|
|
561
|
-
it 'does not enable feature for object in not enabled group' do
|
|
562
|
-
expect(feature.enabled?(dev_actor)).to eq(false)
|
|
563
|
-
end
|
|
564
|
-
end
|
|
565
|
-
|
|
566
|
-
context "for expression" do
|
|
567
|
-
it "works" do
|
|
568
|
-
feature.enable Flipper.property(:plan).eq("basic")
|
|
569
|
-
|
|
570
|
-
expect(feature.enabled?).to be(false)
|
|
571
|
-
expect(feature.enabled?(basic_plan_actor)).to be(true)
|
|
572
|
-
expect(feature.enabled?(premium_plan_actor)).to be(false)
|
|
573
|
-
expect(feature.enabled?(admin_actor)).to be(false)
|
|
574
|
-
end
|
|
575
|
-
|
|
576
|
-
it "works for true expression with no actor" do
|
|
577
|
-
feature.enable Flipper.boolean(true)
|
|
578
|
-
expect(feature.enabled?).to be(true)
|
|
579
|
-
end
|
|
580
|
-
|
|
581
|
-
it "works for multiple actors" do
|
|
582
|
-
feature.enable Flipper.property(:plan).eq("basic")
|
|
583
|
-
|
|
584
|
-
expect(feature.enabled?(basic_plan_actor, premium_plan_actor)).to be(true)
|
|
585
|
-
expect(feature.enabled?(premium_plan_actor, basic_plan_actor)).to be(true)
|
|
586
|
-
expect(feature.enabled?(premium_plan_actor, admin_actor)).to be(false)
|
|
587
|
-
end
|
|
588
|
-
end
|
|
589
|
-
|
|
590
|
-
context "for Any" do
|
|
591
|
-
it "works" do
|
|
592
|
-
expression = Flipper.any(
|
|
593
|
-
Flipper.property(:plan).eq("basic"),
|
|
594
|
-
Flipper.property(:plan).eq("plus"),
|
|
595
|
-
)
|
|
596
|
-
feature.enable expression
|
|
597
|
-
|
|
598
|
-
expect(feature.enabled?(basic_plan_actor)).to be(true)
|
|
599
|
-
expect(feature.enabled?(premium_plan_actor)).to be(false)
|
|
600
|
-
end
|
|
601
|
-
end
|
|
602
|
-
|
|
603
|
-
context "for FeatureEnabled" do
|
|
604
|
-
before do
|
|
605
|
-
@original_instance = Flipper.instance
|
|
606
|
-
Flipper.instance = flipper
|
|
607
|
-
end
|
|
608
|
-
|
|
609
|
-
after do
|
|
610
|
-
Flipper.instance = @original_instance
|
|
611
|
-
Thread.current[:flipper_evaluating_features] = nil
|
|
612
|
-
end
|
|
613
|
-
|
|
614
|
-
it "returns true when referenced feature is enabled" do
|
|
615
|
-
flipper.enable(:search_beta)
|
|
616
|
-
feature.enable Flipper.feature_enabled(:search_beta)
|
|
617
|
-
|
|
618
|
-
expect(feature.enabled?).to be(true)
|
|
619
|
-
end
|
|
620
|
-
|
|
621
|
-
it "returns false when referenced feature is disabled" do
|
|
622
|
-
feature.enable Flipper.feature_enabled(:search_beta)
|
|
623
|
-
|
|
624
|
-
expect(feature.enabled?).to be(false)
|
|
625
|
-
end
|
|
626
|
-
|
|
627
|
-
it "passes actor through to referenced feature" do
|
|
628
|
-
flipper.enable_actor(:search_beta, pitt)
|
|
629
|
-
feature.enable Flipper.feature_enabled(:search_beta)
|
|
630
|
-
|
|
631
|
-
expect(feature.enabled?(pitt)).to be(true)
|
|
632
|
-
expect(feature.enabled?(clooney)).to be(false)
|
|
633
|
-
end
|
|
634
|
-
|
|
635
|
-
it "returns false on circular dependency" do
|
|
636
|
-
feature.enable Flipper.feature_enabled(:other)
|
|
637
|
-
flipper[:other].enable Flipper.feature_enabled(:search)
|
|
638
|
-
|
|
639
|
-
expect(feature.enabled?).to be(false)
|
|
640
|
-
end
|
|
641
|
-
|
|
642
|
-
it "returns false on self-reference" do
|
|
643
|
-
feature.enable Flipper.feature_enabled(:search)
|
|
644
|
-
|
|
645
|
-
expect(feature.enabled?).to be(false)
|
|
646
|
-
end
|
|
647
|
-
|
|
648
|
-
it "cleans up thread-local state after evaluation" do
|
|
649
|
-
flipper.enable(:search_beta)
|
|
650
|
-
feature.enable Flipper.feature_enabled(:search_beta)
|
|
651
|
-
|
|
652
|
-
feature.enabled?
|
|
653
|
-
evaluating = Thread.current[:flipper_evaluating_features]
|
|
654
|
-
expect(evaluating.nil? || evaluating.empty?).to be(true)
|
|
655
|
-
end
|
|
656
|
-
|
|
657
|
-
it "cleans up thread-local state after self-reference" do
|
|
658
|
-
feature.enable Flipper.feature_enabled(:search)
|
|
659
|
-
|
|
660
|
-
feature.enabled?
|
|
661
|
-
evaluating = Thread.current[:flipper_evaluating_features]
|
|
662
|
-
expect(evaluating.nil? || evaluating.empty?).to be(true)
|
|
663
|
-
end
|
|
664
|
-
|
|
665
|
-
it "cleans up thread-local state after circular dependency" do
|
|
666
|
-
feature.enable Flipper.feature_enabled(:other)
|
|
667
|
-
flipper[:other].enable Flipper.feature_enabled(:search)
|
|
668
|
-
|
|
669
|
-
feature.enabled?
|
|
670
|
-
evaluating = Thread.current[:flipper_evaluating_features]
|
|
671
|
-
expect(evaluating.nil? || evaluating.empty?).to be(true)
|
|
672
|
-
end
|
|
673
|
-
end
|
|
674
|
-
|
|
675
|
-
context "for FeatureDisabled" do
|
|
676
|
-
before do
|
|
677
|
-
@original_instance = Flipper.instance
|
|
678
|
-
Flipper.instance = flipper
|
|
679
|
-
end
|
|
680
|
-
|
|
681
|
-
after do
|
|
682
|
-
Flipper.instance = @original_instance
|
|
683
|
-
Thread.current[:flipper_evaluating_features] = nil
|
|
684
|
-
end
|
|
685
|
-
|
|
686
|
-
it "returns true when referenced feature is disabled" do
|
|
687
|
-
feature.enable Flipper.feature_disabled(:old_checkout)
|
|
688
|
-
|
|
689
|
-
expect(feature.enabled?).to be(true)
|
|
690
|
-
end
|
|
691
|
-
|
|
692
|
-
it "returns false when referenced feature is enabled" do
|
|
693
|
-
flipper.enable(:old_checkout)
|
|
694
|
-
feature.enable Flipper.feature_disabled(:old_checkout)
|
|
695
|
-
|
|
696
|
-
expect(feature.enabled?).to be(false)
|
|
697
|
-
end
|
|
698
|
-
end
|
|
699
|
-
|
|
700
|
-
context "for FeatureEnabled composed with other expressions" do
|
|
701
|
-
before do
|
|
702
|
-
@original_instance = Flipper.instance
|
|
703
|
-
Flipper.instance = flipper
|
|
704
|
-
end
|
|
705
|
-
|
|
706
|
-
after do
|
|
707
|
-
Flipper.instance = @original_instance
|
|
708
|
-
Thread.current[:flipper_evaluating_features] = nil
|
|
709
|
-
end
|
|
710
|
-
|
|
711
|
-
it "works with Any" do
|
|
712
|
-
feature.enable Flipper.any(
|
|
713
|
-
Flipper.feature_enabled(:beta_program),
|
|
714
|
-
Flipper.property(:plan).eq("basic")
|
|
715
|
-
)
|
|
716
|
-
|
|
717
|
-
expect(feature.enabled?(basic_plan_actor)).to be(true)
|
|
718
|
-
expect(feature.enabled?(premium_plan_actor)).to be(false)
|
|
719
|
-
|
|
720
|
-
flipper.enable(:beta_program)
|
|
721
|
-
expect(feature.enabled?(premium_plan_actor)).to be(true)
|
|
722
|
-
end
|
|
723
|
-
|
|
724
|
-
it "works with All" do
|
|
725
|
-
flipper.enable(:basic_search)
|
|
726
|
-
feature.enable Flipper.all(
|
|
727
|
-
Flipper.feature_enabled(:basic_search),
|
|
728
|
-
Flipper.property(:plan).eq("basic")
|
|
729
|
-
)
|
|
730
|
-
|
|
731
|
-
expect(feature.enabled?(basic_plan_actor)).to be(true)
|
|
732
|
-
expect(feature.enabled?(premium_plan_actor)).to be(false)
|
|
733
|
-
end
|
|
734
|
-
end
|
|
735
|
-
|
|
736
|
-
context "for All" do
|
|
737
|
-
it "works" do
|
|
738
|
-
true_actor = Flipper::Actor.new("User;1", {
|
|
739
|
-
"plan" => "basic",
|
|
740
|
-
"age" => 21,
|
|
741
|
-
})
|
|
742
|
-
false_actor = Flipper::Actor.new("User;1", {
|
|
743
|
-
"plan" => "basic",
|
|
744
|
-
"age" => 20,
|
|
745
|
-
})
|
|
746
|
-
expression = Flipper.all(
|
|
747
|
-
Flipper.property(:plan).eq("basic"),
|
|
748
|
-
Flipper.property(:age).eq(21)
|
|
749
|
-
)
|
|
750
|
-
feature.enable expression
|
|
751
|
-
|
|
752
|
-
expect(feature.enabled?(true_actor)).to be(true)
|
|
753
|
-
expect(feature.enabled?(false_actor)).to be(false)
|
|
754
|
-
end
|
|
755
|
-
|
|
756
|
-
it "works when nested" do
|
|
757
|
-
admin_actor = Flipper::Actor.new("User;1", {
|
|
758
|
-
"admin" => true,
|
|
759
|
-
})
|
|
760
|
-
true_actor = Flipper::Actor.new("User;1", {
|
|
761
|
-
"plan" => "basic",
|
|
762
|
-
"age" => 21,
|
|
763
|
-
})
|
|
764
|
-
false_actor = Flipper::Actor.new("User;1", {
|
|
765
|
-
"plan" => "basic",
|
|
766
|
-
"age" => 20,
|
|
767
|
-
})
|
|
768
|
-
expression = Flipper.any(
|
|
769
|
-
Flipper.property(:admin).eq(true),
|
|
770
|
-
Flipper.all(
|
|
771
|
-
Flipper.property(:plan).eq("basic"),
|
|
772
|
-
Flipper.property(:age).eq(21)
|
|
773
|
-
)
|
|
774
|
-
)
|
|
775
|
-
|
|
776
|
-
feature.enable expression
|
|
777
|
-
|
|
778
|
-
expect(feature.enabled?(admin_actor)).to be(true)
|
|
779
|
-
expect(feature.enabled?(true_actor)).to be(true)
|
|
780
|
-
expect(feature.enabled?(false_actor)).to be(false)
|
|
781
|
-
end
|
|
782
|
-
end
|
|
783
|
-
end
|