flipper 1.4.1 → 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 +136 -21
- 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 -19
- 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 -257
- data/spec/flipper/cloud/dsl_spec.rb +0 -90
- data/spec/flipper/cloud/message_verifier_spec.rb +0 -104
- data/spec/flipper/cloud/middleware_spec.rb +0 -307
- 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
data/spec/flipper/gate_spec.rb
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Gate do
|
|
2
|
-
let(:feature_name) { :stats }
|
|
3
|
-
|
|
4
|
-
subject do
|
|
5
|
-
described_class.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
describe '#inspect' do
|
|
9
|
-
context 'for subclass' do
|
|
10
|
-
let(:subclass) do
|
|
11
|
-
Class.new(described_class) do
|
|
12
|
-
def name
|
|
13
|
-
:name
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
def key
|
|
17
|
-
:key
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def data_type
|
|
21
|
-
:set
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
subject do
|
|
27
|
-
subclass.new
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
it 'includes attributes' do
|
|
31
|
-
string = subject.inspect
|
|
32
|
-
expect(string).to include(subject.object_id.to_s)
|
|
33
|
-
expect(string).to include('name=:name')
|
|
34
|
-
expect(string).to include('key=:key')
|
|
35
|
-
expect(string).to include('data_type=:set')
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
end
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
require 'flipper/gate_values'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Flipper::GateValues do
|
|
4
|
-
{
|
|
5
|
-
nil => false,
|
|
6
|
-
'' => false,
|
|
7
|
-
0 => false,
|
|
8
|
-
1 => true,
|
|
9
|
-
'0' => false,
|
|
10
|
-
'1' => true,
|
|
11
|
-
true => true,
|
|
12
|
-
false => false,
|
|
13
|
-
'true' => true,
|
|
14
|
-
'false' => false,
|
|
15
|
-
}.each do |value, expected|
|
|
16
|
-
context "with #{value.inspect} boolean" do
|
|
17
|
-
it "returns #{expected}" do
|
|
18
|
-
expect(described_class.new(boolean: value).boolean).to be(expected)
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
{
|
|
24
|
-
nil => 0,
|
|
25
|
-
'' => 0,
|
|
26
|
-
0 => 0,
|
|
27
|
-
1 => 1,
|
|
28
|
-
'1' => 1,
|
|
29
|
-
'99' => 99,
|
|
30
|
-
}.each do |value, expected|
|
|
31
|
-
context "with #{value.inspect} percentage of time" do
|
|
32
|
-
it "returns #{expected}" do
|
|
33
|
-
expect(described_class.new(percentage_of_time: value).percentage_of_time).to be(expected)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
{
|
|
39
|
-
nil => 0,
|
|
40
|
-
'' => 0,
|
|
41
|
-
0 => 0,
|
|
42
|
-
1 => 1,
|
|
43
|
-
'1' => 1,
|
|
44
|
-
'99' => 99,
|
|
45
|
-
}.each do |value, expected|
|
|
46
|
-
context "with #{value.inspect} percentage of actors" do
|
|
47
|
-
it "returns #{expected}" do
|
|
48
|
-
expect(described_class.new(percentage_of_actors: value).percentage_of_actors)
|
|
49
|
-
.to be(expected)
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
{
|
|
55
|
-
nil => Set.new,
|
|
56
|
-
'' => Set.new,
|
|
57
|
-
Set.new([1, 2]) => Set.new([1, 2]),
|
|
58
|
-
[1, 2] => Set.new([1, 2]),
|
|
59
|
-
}.each do |value, expected|
|
|
60
|
-
context "with #{value.inspect} actors" do
|
|
61
|
-
it "returns #{expected}" do
|
|
62
|
-
expect(described_class.new(actors: value).actors).to eq(expected)
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
{
|
|
68
|
-
nil => Set.new,
|
|
69
|
-
'' => Set.new,
|
|
70
|
-
Set.new([:admins, :preview_features]) => Set.new([:admins, :preview_features]),
|
|
71
|
-
[:admins, :preview_features] => Set.new([:admins, :preview_features]),
|
|
72
|
-
}.each do |value, expected|
|
|
73
|
-
context "with #{value.inspect} groups" do
|
|
74
|
-
it "returns #{expected}" do
|
|
75
|
-
expect(described_class.new(groups: value).groups).to eq(expected)
|
|
76
|
-
end
|
|
77
|
-
end
|
|
78
|
-
end
|
|
79
|
-
|
|
80
|
-
it 'raises argument error for percentage of time value that cannot be converted to an integer' do
|
|
81
|
-
expect do
|
|
82
|
-
described_class.new(percentage_of_time: ['asdf'])
|
|
83
|
-
end.to raise_error(ArgumentError, %(["asdf"] cannot be converted to a number))
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
it 'raises argument error for percentage of actors value that cannot be converted to an int' do
|
|
87
|
-
expect do
|
|
88
|
-
described_class.new(percentage_of_actors: ['asdf'])
|
|
89
|
-
end.to raise_error(ArgumentError, %(["asdf"] cannot be converted to a number))
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
it 'raises argument error for actors value that cannot be converted to a set' do
|
|
93
|
-
expect do
|
|
94
|
-
described_class.new(actors: 'asdf')
|
|
95
|
-
end.to raise_error(ArgumentError, %("asdf" cannot be converted to a set))
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
it 'raises argument error for groups value that cannot be converted to a set' do
|
|
99
|
-
expect do
|
|
100
|
-
described_class.new(groups: 'asdf')
|
|
101
|
-
end.to raise_error(ArgumentError, %("asdf" cannot be converted to a set))
|
|
102
|
-
end
|
|
103
|
-
end
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Gates::Boolean do
|
|
2
|
-
let(:feature_name) { :search }
|
|
3
|
-
|
|
4
|
-
subject do
|
|
5
|
-
described_class.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def context(bool)
|
|
9
|
-
Flipper::FeatureCheckContext.new(
|
|
10
|
-
feature_name: feature_name,
|
|
11
|
-
values: Flipper::GateValues.new(boolean: bool),
|
|
12
|
-
actors: [Flipper::Types::Actor.new(Flipper::Actor.new('1'))]
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe '#enabled?' do
|
|
17
|
-
context 'for true value' do
|
|
18
|
-
it 'returns true' do
|
|
19
|
-
expect(subject.enabled?(true)).to eq(true)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context 'for false value' do
|
|
24
|
-
it 'returns false' do
|
|
25
|
-
expect(subject.enabled?(false)).to eq(false)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
describe '#open?' do
|
|
31
|
-
context 'for true value' do
|
|
32
|
-
it 'returns true' do
|
|
33
|
-
expect(subject.open?(context(true))).to be(true)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
context 'for false value' do
|
|
38
|
-
it 'returns false' do
|
|
39
|
-
expect(subject.open?(context(false))).to be(false)
|
|
40
|
-
end
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
describe '#protects?' do
|
|
45
|
-
it 'returns true for boolean type' do
|
|
46
|
-
expect(subject.protects?(Flipper::Types::Boolean.new(true))).to be(true)
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'returns true for true' do
|
|
50
|
-
expect(subject.protects?(true)).to be(true)
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
it 'returns true for false' do
|
|
54
|
-
expect(subject.protects?(false)).to be(true)
|
|
55
|
-
end
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
describe '#wrap' do
|
|
59
|
-
it 'returns boolean type for boolean type' do
|
|
60
|
-
expect(subject.wrap(Flipper::Types::Boolean.new(true)))
|
|
61
|
-
.to be_instance_of(Flipper::Types::Boolean)
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
it 'returns boolean type for true' do
|
|
65
|
-
expect(subject.wrap(true)).to be_instance_of(Flipper::Types::Boolean)
|
|
66
|
-
expect(subject.wrap(true).value).to be(true)
|
|
67
|
-
end
|
|
68
|
-
|
|
69
|
-
it 'returns boolean type for true' do
|
|
70
|
-
expect(subject.wrap(false)).to be_instance_of(Flipper::Types::Boolean)
|
|
71
|
-
expect(subject.wrap(false).value).to be(false)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Gates::Expression do
|
|
2
|
-
let(:feature_name) { :search }
|
|
3
|
-
|
|
4
|
-
subject do
|
|
5
|
-
described_class.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def context(expression, properties: {})
|
|
9
|
-
Flipper::FeatureCheckContext.new(
|
|
10
|
-
feature_name: feature_name,
|
|
11
|
-
values: Flipper::GateValues.new(expression: expression),
|
|
12
|
-
actors: [Flipper::Types::Actor.new(Flipper::Actor.new(1, properties))]
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe '#enabled?' do
|
|
17
|
-
context 'for nil value' do
|
|
18
|
-
it 'returns false' do
|
|
19
|
-
expect(subject.enabled?(nil)).to eq(false)
|
|
20
|
-
end
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
context 'for empty value' do
|
|
24
|
-
it 'returns false' do
|
|
25
|
-
expect(subject.enabled?({})).to eq(false)
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
context "for not empty value" do
|
|
30
|
-
it 'returns true' do
|
|
31
|
-
expect(subject.enabled?({"Boolean" => [true]})).to eq(true)
|
|
32
|
-
end
|
|
33
|
-
end
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
describe '#open?' do
|
|
37
|
-
context 'for expression that evaluates to true' do
|
|
38
|
-
it 'returns true' do
|
|
39
|
-
expression = Flipper.boolean(true).eq(true)
|
|
40
|
-
expect(subject.open?(context(expression.value))).to be(true)
|
|
41
|
-
end
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
context 'for expression that evaluates to false' do
|
|
45
|
-
it 'returns false' do
|
|
46
|
-
expression = Flipper.boolean(true).eq(false)
|
|
47
|
-
expect(subject.open?(context(expression.value))).to be(false)
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context 'for properties that have string keys' do
|
|
52
|
-
it 'returns true when expression evalutes to true' do
|
|
53
|
-
expression = Flipper.property(:type).eq("User")
|
|
54
|
-
context = context(expression.value, properties: {"type" => "User"})
|
|
55
|
-
expect(subject.open?(context)).to be(true)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'returns false when expression evaluates to false' do
|
|
59
|
-
expression = Flipper.property(:type).eq("User")
|
|
60
|
-
context = context(expression.value, properties: {"type" => "Org"})
|
|
61
|
-
expect(subject.open?(context)).to be(false)
|
|
62
|
-
end
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
context 'for actor in context' do
|
|
66
|
-
it 'passes actor to expression context' do
|
|
67
|
-
actor = Flipper::Actor.new("User;1", {type: "User"})
|
|
68
|
-
wrapped_actor = Flipper::Types::Actor.new(actor)
|
|
69
|
-
expression = Flipper.property(:flipper_id).eq("User;1")
|
|
70
|
-
ctx = Flipper::FeatureCheckContext.new(
|
|
71
|
-
feature_name: feature_name,
|
|
72
|
-
values: Flipper::GateValues.new(expression: expression.value),
|
|
73
|
-
actors: [wrapped_actor]
|
|
74
|
-
)
|
|
75
|
-
expect(subject.open?(ctx)).to be(true)
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
it 'passes nil actor when no actors provided' do
|
|
79
|
-
expression = Flipper.boolean(true).eq(true)
|
|
80
|
-
ctx = Flipper::FeatureCheckContext.new(
|
|
81
|
-
feature_name: feature_name,
|
|
82
|
-
values: Flipper::GateValues.new(expression: expression.value),
|
|
83
|
-
actors: nil
|
|
84
|
-
)
|
|
85
|
-
expect(subject.open?(ctx)).to be(true)
|
|
86
|
-
end
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
context 'for properties that have symbol keys' do
|
|
90
|
-
it 'returns true when expression evalutes to true' do
|
|
91
|
-
expression = Flipper.property(:type).eq("User")
|
|
92
|
-
context = context(expression.value, properties: {type: "User"})
|
|
93
|
-
expect(subject.open?(context)).to be(true)
|
|
94
|
-
end
|
|
95
|
-
|
|
96
|
-
it 'returns false when expression evaluates to false' do
|
|
97
|
-
expression = Flipper.property(:type).eq("User")
|
|
98
|
-
context = context(expression.value, properties: {type: "Org"})
|
|
99
|
-
expect(subject.open?(context)).to be(false)
|
|
100
|
-
end
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
context 'for time-based expressions' do
|
|
104
|
-
it 'enables when now is past a scheduled epoch' do
|
|
105
|
-
past_epoch = Time.now.to_i - 86_400
|
|
106
|
-
expression = Flipper.now.gte(Flipper.time(past_epoch))
|
|
107
|
-
expect(subject.open?(context(expression.value))).to be(true)
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
it 'does not enable when now is before a future epoch' do
|
|
111
|
-
future_epoch = Time.now.to_i + 86_400
|
|
112
|
-
expression = Flipper.now.gte(Flipper.time(future_epoch))
|
|
113
|
-
expect(subject.open?(context(expression.value))).to be(false)
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
it 'enables when now is past a scheduled datetime' do
|
|
117
|
-
past_time = (Time.now.utc - 86_400).iso8601
|
|
118
|
-
expression = Flipper.now.gte(Flipper.time(past_time))
|
|
119
|
-
expect(subject.open?(context(expression.value))).to be(true)
|
|
120
|
-
end
|
|
121
|
-
|
|
122
|
-
it 'does not enable when now is before a future datetime' do
|
|
123
|
-
future_time = (Time.now.utc + 86_400).iso8601
|
|
124
|
-
expression = Flipper.now.gte(Flipper.time(future_time))
|
|
125
|
-
expect(subject.open?(context(expression.value))).to be(false)
|
|
126
|
-
end
|
|
127
|
-
|
|
128
|
-
it 'enables expiring features with lt' do
|
|
129
|
-
future_time = (Time.now.utc + 86_400).iso8601
|
|
130
|
-
expression = Flipper.now.lt(Flipper.time(future_time))
|
|
131
|
-
expect(subject.open?(context(expression.value))).to be(true)
|
|
132
|
-
end
|
|
133
|
-
|
|
134
|
-
it 'disables expired features with lt' do
|
|
135
|
-
past_time = (Time.now.utc - 86_400).iso8601
|
|
136
|
-
expression = Flipper.now.lt(Flipper.time(past_time))
|
|
137
|
-
expect(subject.open?(context(expression.value))).to be(false)
|
|
138
|
-
end
|
|
139
|
-
|
|
140
|
-
it 'enables within a time window using all' do
|
|
141
|
-
start_time = (Time.now.utc - 86_400).iso8601
|
|
142
|
-
end_time = (Time.now.utc + 86_400).iso8601
|
|
143
|
-
expression = Flipper.all(
|
|
144
|
-
Flipper.now.gte(Flipper.time(start_time)),
|
|
145
|
-
Flipper.now.lt(Flipper.time(end_time))
|
|
146
|
-
)
|
|
147
|
-
expect(subject.open?(context(expression.value))).to be(true)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
it 'does not enable outside a time window' do
|
|
151
|
-
start_time = (Time.now.utc + 86_400).iso8601
|
|
152
|
-
end_time = (Time.now.utc + 172_800).iso8601
|
|
153
|
-
expression = Flipper.all(
|
|
154
|
-
Flipper.now.gte(Flipper.time(start_time)),
|
|
155
|
-
Flipper.now.lt(Flipper.time(end_time))
|
|
156
|
-
)
|
|
157
|
-
expect(subject.open?(context(expression.value))).to be(false)
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
describe '#protects?' do
|
|
163
|
-
it 'returns true for Flipper::Expression' do
|
|
164
|
-
expression = Flipper.number(20).eq(20)
|
|
165
|
-
expect(subject.protects?(expression)).to be(true)
|
|
166
|
-
end
|
|
167
|
-
|
|
168
|
-
it 'returns true for Hash' do
|
|
169
|
-
expression = Flipper.number(20).eq(20)
|
|
170
|
-
expect(subject.protects?(expression.value)).to be(true)
|
|
171
|
-
end
|
|
172
|
-
|
|
173
|
-
it 'returns false for other things' do
|
|
174
|
-
expect(subject.protects?(false)).to be(false)
|
|
175
|
-
end
|
|
176
|
-
end
|
|
177
|
-
|
|
178
|
-
describe '#wrap' do
|
|
179
|
-
it 'returns self for Flipper::Expression' do
|
|
180
|
-
expression = Flipper.number(20).eq(20)
|
|
181
|
-
expect(subject.wrap(expression)).to be(expression)
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
it 'returns Flipper::Expression for Hash' do
|
|
185
|
-
expression = Flipper.number(20).eq(20)
|
|
186
|
-
expect(subject.wrap(expression.value)).to be_instance_of(Flipper::Expression)
|
|
187
|
-
expect(subject.wrap(expression.value)).to eq(expression)
|
|
188
|
-
end
|
|
189
|
-
end
|
|
190
|
-
end
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Gates::Group do
|
|
2
|
-
let(:feature_name) { :search }
|
|
3
|
-
|
|
4
|
-
subject do
|
|
5
|
-
described_class.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def context(set)
|
|
9
|
-
Flipper::FeatureCheckContext.new(
|
|
10
|
-
feature_name: feature_name,
|
|
11
|
-
values: Flipper::GateValues.new(groups: set),
|
|
12
|
-
actors: [Flipper::Types::Actor.new(Flipper::Actor.new('5'))]
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe '#open?' do
|
|
17
|
-
context 'with a group in adapter, but not registered' do
|
|
18
|
-
before do
|
|
19
|
-
Flipper.register(:staff) { |actor| true }
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
it 'ignores group' do
|
|
23
|
-
expect(subject.open?(context(Set[:newbs, :staff]))).to be(true)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
context 'thing that does not respond to method in group block' do
|
|
28
|
-
before do
|
|
29
|
-
Flipper.register(:stinkers, &:stinker?)
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
it 'raises error' do
|
|
33
|
-
expect do
|
|
34
|
-
subject.open?(context(Set[:stinkers]))
|
|
35
|
-
end.to raise_error(NoMethodError)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
describe '#wrap' do
|
|
41
|
-
it 'returns group instance for symbol' do
|
|
42
|
-
group = Flipper.register(:admins) {}
|
|
43
|
-
expect(subject.wrap(:admins)).to eq(group)
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
it 'returns group instance for group instance' do
|
|
47
|
-
group = Flipper.register(:admins) {}
|
|
48
|
-
expect(subject.wrap(group)).to eq(group)
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
describe '#protects?' do
|
|
53
|
-
it 'returns true for group' do
|
|
54
|
-
group = Flipper.register(:admins) {}
|
|
55
|
-
expect(subject.protects?(group)).to be(true)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
it 'returns true for symbol' do
|
|
59
|
-
expect(subject.protects?(:admins)).to be(true)
|
|
60
|
-
end
|
|
61
|
-
end
|
|
62
|
-
end
|
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Gates::PercentageOfActors do
|
|
2
|
-
let(:feature_name) { :search }
|
|
3
|
-
|
|
4
|
-
subject do
|
|
5
|
-
described_class.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def context(percentage_of_actors_value, feature = feature_name, actors = nil)
|
|
9
|
-
Flipper::FeatureCheckContext.new(
|
|
10
|
-
feature_name: feature,
|
|
11
|
-
values: Flipper::GateValues.new(percentage_of_actors: percentage_of_actors_value),
|
|
12
|
-
actors: Array(actors) || [Flipper::Types::Actor.new(Flipper::Actor.new('1'))]
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe '#open?' do
|
|
17
|
-
context 'when compared against two features' do
|
|
18
|
-
let(:percentage) { 0.05 }
|
|
19
|
-
let(:percentage_as_integer) { percentage * 100 }
|
|
20
|
-
let(:number_of_actors) { 10_000 }
|
|
21
|
-
|
|
22
|
-
let(:actors) do
|
|
23
|
-
(1..number_of_actors).map { |n| Flipper::Types::Actor.new(Flipper::Actor.new(n.to_s)) }
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
let(:feature_one_enabled_actors) do
|
|
27
|
-
actors.select { |actor| subject.open? context(percentage_as_integer, :name_one, actor) }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
let(:feature_two_enabled_actors) do
|
|
31
|
-
actors.select { |actor| subject.open? context(percentage_as_integer, :name_two, actor) }
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
it 'does not enable both features for same set of actors' do
|
|
35
|
-
expect(feature_one_enabled_actors).not_to eq(feature_two_enabled_actors)
|
|
36
|
-
end
|
|
37
|
-
|
|
38
|
-
it 'enables feature for accurate number of actors for each feature' do
|
|
39
|
-
margin_of_error = 0.02 * number_of_actors # 2 percent margin of error
|
|
40
|
-
expected_enabled_size = number_of_actors * percentage
|
|
41
|
-
|
|
42
|
-
[
|
|
43
|
-
feature_one_enabled_actors.size,
|
|
44
|
-
feature_two_enabled_actors.size,
|
|
45
|
-
].each do |actual_enabled_size|
|
|
46
|
-
expect(actual_enabled_size).to be_within(margin_of_error).of(expected_enabled_size)
|
|
47
|
-
end
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
context "with an array of actors" do
|
|
52
|
-
let(:percentage) { 0.05 }
|
|
53
|
-
let(:percentage_as_integer) { percentage * 100 }
|
|
54
|
-
let(:number_of_actors) { 3_000 }
|
|
55
|
-
|
|
56
|
-
let(:user_actors) do
|
|
57
|
-
(1..number_of_actors).map { |n| Flipper::Types::Actor.new(Flipper::Actor.new("User;#{n}")) }
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
let(:team_actors) do
|
|
61
|
-
(1..number_of_actors).map { |n| Flipper::Types::Actor.new(Flipper::Actor.new("Team;#{n}")) }
|
|
62
|
-
end
|
|
63
|
-
|
|
64
|
-
let(:org_actors) do
|
|
65
|
-
(1..number_of_actors).map { |n| Flipper::Types::Actor.new(Flipper::Actor.new("Org;#{n}")) }
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
let(:actors) { user_actors + team_actors + org_actors }
|
|
69
|
-
|
|
70
|
-
let(:feature_one_enabled_actors) do
|
|
71
|
-
actors.each_slice(3).select do |group|
|
|
72
|
-
context = context(percentage_as_integer, :name_one, group)
|
|
73
|
-
subject.open?(context)
|
|
74
|
-
end.flatten
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
let(:feature_two_enabled_actors) do
|
|
78
|
-
actors.each_slice(3).select do |group|
|
|
79
|
-
context = context(percentage_as_integer, :name_two, group)
|
|
80
|
-
subject.open?(context)
|
|
81
|
-
end.flatten
|
|
82
|
-
end
|
|
83
|
-
|
|
84
|
-
it 'does not enable both features for same set of actors' do
|
|
85
|
-
expect(feature_one_enabled_actors).not_to eq(feature_two_enabled_actors)
|
|
86
|
-
end
|
|
87
|
-
|
|
88
|
-
it 'enables feature for accurate number of actors for each feature' do
|
|
89
|
-
margin_of_error = 0.02 * actors.size # 2 percent margin of error
|
|
90
|
-
expected_enabled_size = actors.size * percentage
|
|
91
|
-
|
|
92
|
-
[
|
|
93
|
-
feature_one_enabled_actors.size,
|
|
94
|
-
feature_two_enabled_actors.size,
|
|
95
|
-
].each do |size|
|
|
96
|
-
expect(size).to be_within(margin_of_error).of(expected_enabled_size)
|
|
97
|
-
end
|
|
98
|
-
end
|
|
99
|
-
|
|
100
|
-
it "is consistent regardless of order of actors" do
|
|
101
|
-
actors = user_actors.first(10)
|
|
102
|
-
results = 100.times.map { |n| subject.open?(context(75, :some_feature, actors.shuffle)) }
|
|
103
|
-
expect(results.uniq).to eq([true])
|
|
104
|
-
end
|
|
105
|
-
end
|
|
106
|
-
|
|
107
|
-
context 'for fractional percentage' do
|
|
108
|
-
let(:decimal) { 0.001 }
|
|
109
|
-
let(:percentage) { decimal * 100 }
|
|
110
|
-
let(:number_of_actors) { 10_000 }
|
|
111
|
-
|
|
112
|
-
let(:actors) do
|
|
113
|
-
(1..number_of_actors).map { |n| Flipper::Types::Actor.new(Flipper::Actor.new(n.to_s)) }
|
|
114
|
-
end
|
|
115
|
-
|
|
116
|
-
subject { described_class.new }
|
|
117
|
-
|
|
118
|
-
it 'enables feature for accurate number of actors' do
|
|
119
|
-
margin_of_error = 0.02 * number_of_actors
|
|
120
|
-
expected_open_count = number_of_actors * decimal
|
|
121
|
-
|
|
122
|
-
open_count = actors.select do |actor|
|
|
123
|
-
context = context(percentage, :feature, [actor])
|
|
124
|
-
subject.open?(context)
|
|
125
|
-
end.size
|
|
126
|
-
|
|
127
|
-
expect(open_count).to be_within(margin_of_error).of(expected_open_count)
|
|
128
|
-
end
|
|
129
|
-
end
|
|
130
|
-
end
|
|
131
|
-
end
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Gates::PercentageOfTime do
|
|
2
|
-
let(:feature_name) { :search }
|
|
3
|
-
|
|
4
|
-
subject do
|
|
5
|
-
described_class.new
|
|
6
|
-
end
|
|
7
|
-
|
|
8
|
-
def context(percentage_of_time_value, feature = feature_name, actors = nil)
|
|
9
|
-
Flipper::FeatureCheckContext.new(
|
|
10
|
-
feature_name: feature,
|
|
11
|
-
values: Flipper::GateValues.new(percentage_of_time: percentage_of_time_value),
|
|
12
|
-
actors: Array(actors) || [Flipper::Types::Actor.new(Flipper::Actor.new('1'))]
|
|
13
|
-
)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
describe '#open?' do
|
|
17
|
-
context 'for fractional percentage' do
|
|
18
|
-
let(:decimal) { 0.001 }
|
|
19
|
-
let(:percentage) { decimal * 100 }
|
|
20
|
-
let(:number_of_invocations) { 10_000 }
|
|
21
|
-
|
|
22
|
-
subject { described_class.new }
|
|
23
|
-
|
|
24
|
-
it 'enables feature for accurate percentage of time' do
|
|
25
|
-
margin_of_error = 0.02 * number_of_invocations
|
|
26
|
-
expected_open_count = number_of_invocations * decimal
|
|
27
|
-
|
|
28
|
-
open_count = (1..number_of_invocations).select do |_actor|
|
|
29
|
-
context = context(percentage, :feature, Flipper::Actor.new("1"))
|
|
30
|
-
subject.open?(context)
|
|
31
|
-
end.size
|
|
32
|
-
|
|
33
|
-
expect(open_count).to be_within(margin_of_error).of(expected_open_count)
|
|
34
|
-
end
|
|
35
|
-
end
|
|
36
|
-
end
|
|
37
|
-
end
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
require 'flipper/identifier'
|
|
2
|
-
|
|
3
|
-
RSpec.describe Flipper::Identifier do
|
|
4
|
-
describe '#flipper_id' do
|
|
5
|
-
it 'uses class name and id' do
|
|
6
|
-
class BlahBlah < Struct.new(:id)
|
|
7
|
-
include Flipper::Identifier
|
|
8
|
-
end
|
|
9
|
-
expect(BlahBlah.new(5).flipper_id).to eq('BlahBlah;5')
|
|
10
|
-
end
|
|
11
|
-
end
|
|
12
|
-
end
|