flipper 1.4.2 → 1.5.0.rc2
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 +149 -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 +111 -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,518 +0,0 @@
|
|
|
1
|
-
require 'rack/test'
|
|
2
|
-
require 'active_support/cache'
|
|
3
|
-
require 'flipper/adapters/active_support_cache_store'
|
|
4
|
-
require 'flipper/adapters/operation_logger'
|
|
5
|
-
require 'flipper/adapters/actor_limit'
|
|
6
|
-
require 'flipper/adapters/sync'
|
|
7
|
-
|
|
8
|
-
RSpec.describe Flipper::Middleware::Memoizer do
|
|
9
|
-
include Rack::Test::Methods
|
|
10
|
-
|
|
11
|
-
let(:memory_adapter) { Flipper::Adapters::Memory.new }
|
|
12
|
-
let(:adapter) do
|
|
13
|
-
Flipper::Adapters::OperationLogger.new(memory_adapter)
|
|
14
|
-
end
|
|
15
|
-
let(:flipper) { Flipper.new(adapter) }
|
|
16
|
-
let(:env) { { 'flipper' => flipper } }
|
|
17
|
-
|
|
18
|
-
it 'raises if initialized with app and flipper instance' do
|
|
19
|
-
expect do
|
|
20
|
-
described_class.new(app, flipper)
|
|
21
|
-
end.to raise_error(/no longer initializes with a flipper/)
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
it 'raises if initialized with app and block' do
|
|
25
|
-
block = -> { flipper }
|
|
26
|
-
expect do
|
|
27
|
-
described_class.new(app, block)
|
|
28
|
-
end.to raise_error(/no longer initializes with a flipper/)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
RSpec.shared_examples_for 'flipper middleware' do
|
|
32
|
-
it 'delegates' do
|
|
33
|
-
called = false
|
|
34
|
-
app = lambda do |_env|
|
|
35
|
-
called = true
|
|
36
|
-
[200, {}, nil]
|
|
37
|
-
end
|
|
38
|
-
middleware = described_class.new(app)
|
|
39
|
-
middleware.call(env)
|
|
40
|
-
expect(called).to eq(true)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
it 'clears the local cache with a successful request' do
|
|
44
|
-
flipper.adapter.cache['hello'] = 'world'
|
|
45
|
-
get '/', {}, 'flipper' => flipper
|
|
46
|
-
expect(flipper.adapter.cache).to be_empty
|
|
47
|
-
end
|
|
48
|
-
|
|
49
|
-
it 'clears the local cache even when the request raises an error' do
|
|
50
|
-
flipper.adapter.cache['hello'] = 'world'
|
|
51
|
-
begin
|
|
52
|
-
get '/fail', {}, 'flipper' => flipper
|
|
53
|
-
rescue
|
|
54
|
-
nil
|
|
55
|
-
end
|
|
56
|
-
expect(flipper.adapter.cache).to be_empty
|
|
57
|
-
end
|
|
58
|
-
|
|
59
|
-
it 'caches getting a feature for duration of request' do
|
|
60
|
-
flipper[:stats].enable
|
|
61
|
-
|
|
62
|
-
# clear the log of operations
|
|
63
|
-
adapter.reset
|
|
64
|
-
|
|
65
|
-
app = lambda do |_env|
|
|
66
|
-
flipper[:stats].enabled?
|
|
67
|
-
flipper[:stats].enabled?
|
|
68
|
-
flipper[:stats].enabled?
|
|
69
|
-
flipper[:stats].enabled?
|
|
70
|
-
flipper[:stats].enabled?
|
|
71
|
-
flipper[:stats].enabled?
|
|
72
|
-
[200, {}, []]
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
middleware = described_class.new(app)
|
|
76
|
-
middleware.call(env)
|
|
77
|
-
|
|
78
|
-
expect(adapter.count(:get)).to be(1)
|
|
79
|
-
end
|
|
80
|
-
end
|
|
81
|
-
|
|
82
|
-
context 'with preload: true' do
|
|
83
|
-
let(:app) do
|
|
84
|
-
# ensure scoped for builder block, annoying...
|
|
85
|
-
flipper
|
|
86
|
-
middleware = described_class
|
|
87
|
-
|
|
88
|
-
Rack::Builder.new do
|
|
89
|
-
use middleware, preload: true
|
|
90
|
-
|
|
91
|
-
map '/' do
|
|
92
|
-
run ->(_env) { [200, {}, []] }
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
map '/fail' do
|
|
96
|
-
run ->(_env) { raise 'FAIL!' }
|
|
97
|
-
end
|
|
98
|
-
end.to_app
|
|
99
|
-
end
|
|
100
|
-
|
|
101
|
-
include_examples 'flipper middleware'
|
|
102
|
-
|
|
103
|
-
it 'eagerly caches known features for duration of request' do
|
|
104
|
-
flipper[:stats].enable
|
|
105
|
-
flipper[:shiny].enable
|
|
106
|
-
|
|
107
|
-
# clear the log of operations
|
|
108
|
-
adapter.reset
|
|
109
|
-
|
|
110
|
-
app = lambda do |_env|
|
|
111
|
-
flipper[:stats].enabled?
|
|
112
|
-
flipper[:stats].enabled?
|
|
113
|
-
flipper[:shiny].enabled?
|
|
114
|
-
flipper[:shiny].enabled?
|
|
115
|
-
[200, {}, []]
|
|
116
|
-
end
|
|
117
|
-
|
|
118
|
-
middleware = described_class.new(app, preload: true)
|
|
119
|
-
middleware.call(env)
|
|
120
|
-
|
|
121
|
-
expect(adapter.operations.size).to be(1)
|
|
122
|
-
expect(adapter.count(:get_all)).to be(1)
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
it 'caches unknown features for duration of request' do
|
|
126
|
-
# clear the log of operations
|
|
127
|
-
adapter.reset
|
|
128
|
-
|
|
129
|
-
app = lambda do |_env|
|
|
130
|
-
flipper[:other].enabled?
|
|
131
|
-
flipper[:other].enabled?
|
|
132
|
-
[200, {}, []]
|
|
133
|
-
end
|
|
134
|
-
|
|
135
|
-
middleware = described_class.new(app, preload: true)
|
|
136
|
-
middleware.call(env)
|
|
137
|
-
|
|
138
|
-
expect(adapter.count(:get)).to be(1)
|
|
139
|
-
expect(adapter.last(:get).args).to eq([flipper[:other]])
|
|
140
|
-
end
|
|
141
|
-
end
|
|
142
|
-
|
|
143
|
-
context 'with preload specific' do
|
|
144
|
-
let(:app) do
|
|
145
|
-
# ensure scoped for builder block, annoying...
|
|
146
|
-
flipper
|
|
147
|
-
middleware = described_class
|
|
148
|
-
|
|
149
|
-
Rack::Builder.new do
|
|
150
|
-
use middleware, preload: %i(stats)
|
|
151
|
-
|
|
152
|
-
map '/' do
|
|
153
|
-
run ->(_env) { [200, {}, []] }
|
|
154
|
-
end
|
|
155
|
-
|
|
156
|
-
map '/fail' do
|
|
157
|
-
run ->(_env) { raise 'FAIL!' }
|
|
158
|
-
end
|
|
159
|
-
end.to_app
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
include_examples 'flipper middleware'
|
|
163
|
-
|
|
164
|
-
it 'eagerly caches specified features for duration of request' do
|
|
165
|
-
# clear the log of operations
|
|
166
|
-
adapter.reset
|
|
167
|
-
|
|
168
|
-
app = lambda do |_env|
|
|
169
|
-
flipper[:stats].enabled?
|
|
170
|
-
flipper[:stats].enabled?
|
|
171
|
-
flipper[:shiny].enabled?
|
|
172
|
-
flipper[:shiny].enabled?
|
|
173
|
-
[200, {}, []]
|
|
174
|
-
end
|
|
175
|
-
|
|
176
|
-
middleware = described_class.new app, preload: %i(stats)
|
|
177
|
-
middleware.call(env)
|
|
178
|
-
|
|
179
|
-
expect(adapter.count(:get_multi)).to be(1)
|
|
180
|
-
expect(adapter.last(:get_multi).args).to eq([[flipper[:stats]]])
|
|
181
|
-
end
|
|
182
|
-
|
|
183
|
-
it 'caches unknown features for duration of request' do
|
|
184
|
-
# clear the log of operations
|
|
185
|
-
adapter.reset
|
|
186
|
-
|
|
187
|
-
app = lambda do |_env|
|
|
188
|
-
flipper[:other].enabled?
|
|
189
|
-
flipper[:other].enabled?
|
|
190
|
-
[200, {}, []]
|
|
191
|
-
end
|
|
192
|
-
|
|
193
|
-
middleware = described_class.new app, preload: %i(stats)
|
|
194
|
-
middleware.call(env)
|
|
195
|
-
|
|
196
|
-
expect(adapter.count(:get)).to be(1)
|
|
197
|
-
expect(adapter.last(:get).args).to eq([flipper[:other]])
|
|
198
|
-
end
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
context 'with preload block' do
|
|
202
|
-
let(:app) do
|
|
203
|
-
app = lambda do |_env|
|
|
204
|
-
flipper[:stats].enabled?
|
|
205
|
-
flipper[:stats].enabled?
|
|
206
|
-
flipper[:shiny].enabled?
|
|
207
|
-
flipper[:shiny].enabled?
|
|
208
|
-
[200, {}, []]
|
|
209
|
-
end
|
|
210
|
-
|
|
211
|
-
described_class.new(app, preload: ->(request) {
|
|
212
|
-
case request.path
|
|
213
|
-
when "/true"
|
|
214
|
-
true
|
|
215
|
-
when "/specific"
|
|
216
|
-
[:stats]
|
|
217
|
-
else
|
|
218
|
-
false
|
|
219
|
-
end
|
|
220
|
-
})
|
|
221
|
-
end
|
|
222
|
-
|
|
223
|
-
include_examples 'flipper middleware'
|
|
224
|
-
|
|
225
|
-
it 'eagerly caches known features for duration of request if block returns true' do
|
|
226
|
-
flipper[:stats].enable
|
|
227
|
-
flipper[:shiny].enable
|
|
228
|
-
|
|
229
|
-
# clear the log of operations
|
|
230
|
-
adapter.reset
|
|
231
|
-
|
|
232
|
-
get '/true', {}, 'flipper' => flipper
|
|
233
|
-
|
|
234
|
-
expect(adapter.operations.size).to be(1)
|
|
235
|
-
expect(adapter.count(:get_all)).to be(1)
|
|
236
|
-
expect(adapter.count(:get)).to be(0)
|
|
237
|
-
end
|
|
238
|
-
|
|
239
|
-
it 'does not eagerly cache known features if block returns false' do
|
|
240
|
-
flipper[:stats].enable
|
|
241
|
-
flipper[:shiny].enable
|
|
242
|
-
|
|
243
|
-
# clear the log of operations
|
|
244
|
-
adapter.reset
|
|
245
|
-
|
|
246
|
-
get '/false', {}, 'flipper' => flipper
|
|
247
|
-
|
|
248
|
-
expect(adapter.operations.size).to be(2)
|
|
249
|
-
expect(adapter.count(:get_all)).to be(0)
|
|
250
|
-
expect(adapter.count(:get)).to be(2)
|
|
251
|
-
end
|
|
252
|
-
|
|
253
|
-
it 'eagerly caches specified features for duration of request if block returns array of specified features' do
|
|
254
|
-
flipper[:stats].enable
|
|
255
|
-
flipper[:shiny].enable
|
|
256
|
-
|
|
257
|
-
# clear the log of operations
|
|
258
|
-
adapter.reset
|
|
259
|
-
|
|
260
|
-
get '/specific', {}, 'flipper' => flipper
|
|
261
|
-
|
|
262
|
-
expect(adapter.operations.size).to be(2)
|
|
263
|
-
expect(adapter.count(:get_multi)).to be(1)
|
|
264
|
-
expect(adapter.count(:get)).to be(1)
|
|
265
|
-
end
|
|
266
|
-
end
|
|
267
|
-
|
|
268
|
-
context 'with multiple instances' do
|
|
269
|
-
let(:app) do
|
|
270
|
-
# ensure scoped for builder block, annoying...
|
|
271
|
-
flipper
|
|
272
|
-
middleware = described_class
|
|
273
|
-
|
|
274
|
-
Rack::Builder.new do
|
|
275
|
-
use middleware, preload: %i(stats)
|
|
276
|
-
# Second instance should be a noop
|
|
277
|
-
use middleware, preload: true
|
|
278
|
-
|
|
279
|
-
map '/' do
|
|
280
|
-
run ->(_env) { [200, {}, []] }
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
map '/fail' do
|
|
284
|
-
run ->(_env) { raise 'FAIL!' }
|
|
285
|
-
end
|
|
286
|
-
end.to_app
|
|
287
|
-
end
|
|
288
|
-
|
|
289
|
-
def get(uri, params = {}, env = {}, &block)
|
|
290
|
-
capture_output { super(uri, params, env, &block) }
|
|
291
|
-
end
|
|
292
|
-
|
|
293
|
-
include_examples 'flipper middleware'
|
|
294
|
-
|
|
295
|
-
it 'does not call preload in second instance' do
|
|
296
|
-
expect(flipper).not_to receive(:preload_all)
|
|
297
|
-
|
|
298
|
-
output = get '/', {}, 'flipper' => flipper
|
|
299
|
-
|
|
300
|
-
expect(output).to match(/Flipper::Middleware::Memoizer appears to be running twice/)
|
|
301
|
-
expect(adapter.count(:get_multi)).to be(1)
|
|
302
|
-
expect(adapter.last(:get_multi).args).to eq([[flipper[:stats]]])
|
|
303
|
-
end
|
|
304
|
-
end
|
|
305
|
-
|
|
306
|
-
context 'when an app raises an exception' do
|
|
307
|
-
it 'resets memoize' do
|
|
308
|
-
begin
|
|
309
|
-
app = ->(_env) { raise }
|
|
310
|
-
middleware = described_class.new(app)
|
|
311
|
-
middleware.call(env)
|
|
312
|
-
rescue RuntimeError
|
|
313
|
-
expect(flipper.memoizing?).to be(false)
|
|
314
|
-
end
|
|
315
|
-
end
|
|
316
|
-
end
|
|
317
|
-
|
|
318
|
-
context 'with flipper setup in env' do
|
|
319
|
-
let(:app) do
|
|
320
|
-
# ensure scoped for builder block, annoying...
|
|
321
|
-
flipper
|
|
322
|
-
middleware = described_class
|
|
323
|
-
|
|
324
|
-
Rack::Builder.new do
|
|
325
|
-
use middleware
|
|
326
|
-
|
|
327
|
-
map '/' do
|
|
328
|
-
run ->(_env) { [200, {}, []] }
|
|
329
|
-
end
|
|
330
|
-
|
|
331
|
-
map '/fail' do
|
|
332
|
-
run ->(_env) { raise 'FAIL!' }
|
|
333
|
-
end
|
|
334
|
-
end.to_app
|
|
335
|
-
end
|
|
336
|
-
|
|
337
|
-
include_examples 'flipper middleware'
|
|
338
|
-
end
|
|
339
|
-
|
|
340
|
-
context 'with Flipper setup in env' do
|
|
341
|
-
it 'caches getting a feature for duration of request' do
|
|
342
|
-
Flipper.configure do |config|
|
|
343
|
-
config.adapter do
|
|
344
|
-
memory = Flipper::Adapters::Memory.new
|
|
345
|
-
Flipper::Adapters::OperationLogger.new(memory)
|
|
346
|
-
end
|
|
347
|
-
end
|
|
348
|
-
Flipper.enable(:stats)
|
|
349
|
-
Flipper.adapter.reset # clear the log of operations
|
|
350
|
-
|
|
351
|
-
app = lambda do |_env|
|
|
352
|
-
Flipper.enabled?(:stats)
|
|
353
|
-
Flipper.enabled?(:stats)
|
|
354
|
-
Flipper.enabled?(:stats)
|
|
355
|
-
[200, {}, []]
|
|
356
|
-
end
|
|
357
|
-
|
|
358
|
-
middleware = described_class.new(app)
|
|
359
|
-
middleware.call('flipper' => Flipper)
|
|
360
|
-
|
|
361
|
-
expect(Flipper.adapter.count(:get)).to be(1)
|
|
362
|
-
end
|
|
363
|
-
end
|
|
364
|
-
|
|
365
|
-
context 'defaults to Flipper' do
|
|
366
|
-
it 'caches getting a feature for duration of request' do
|
|
367
|
-
Flipper.configure do |config|
|
|
368
|
-
config.default do
|
|
369
|
-
memory_adapter = Flipper::Adapters::Memory.new
|
|
370
|
-
logged_adapter = Flipper::Adapters::OperationLogger.new(memory_adapter)
|
|
371
|
-
Flipper.new(logged_adapter)
|
|
372
|
-
end
|
|
373
|
-
end
|
|
374
|
-
Flipper.enable(:stats)
|
|
375
|
-
Flipper.adapter.reset # clear the log of operations
|
|
376
|
-
|
|
377
|
-
app = lambda do |_env|
|
|
378
|
-
Flipper.enabled?(:stats)
|
|
379
|
-
Flipper.enabled?(:stats)
|
|
380
|
-
Flipper.enabled?(:stats)
|
|
381
|
-
[200, {}, []]
|
|
382
|
-
end
|
|
383
|
-
|
|
384
|
-
middleware = described_class.new(app)
|
|
385
|
-
middleware.call({})
|
|
386
|
-
|
|
387
|
-
expect(Flipper.adapter.count(:get)).to be(1)
|
|
388
|
-
end
|
|
389
|
-
end
|
|
390
|
-
|
|
391
|
-
context 'with preload:true' do
|
|
392
|
-
let(:options) { {preload: true} }
|
|
393
|
-
|
|
394
|
-
let(:app) do
|
|
395
|
-
# ensure scoped for builder block, annoying...
|
|
396
|
-
middleware = described_class
|
|
397
|
-
opts = options
|
|
398
|
-
|
|
399
|
-
Rack::Builder.new do
|
|
400
|
-
use middleware, opts
|
|
401
|
-
|
|
402
|
-
map '/' do
|
|
403
|
-
run ->(_env) { [200, {}, []] }
|
|
404
|
-
end
|
|
405
|
-
|
|
406
|
-
map '/fail' do
|
|
407
|
-
run ->(_env) { raise 'FAIL!' }
|
|
408
|
-
end
|
|
409
|
-
end.to_app
|
|
410
|
-
end
|
|
411
|
-
|
|
412
|
-
context 'and unless option' do
|
|
413
|
-
before do
|
|
414
|
-
options[:unless] = ->(request) { request.path.start_with?("/assets") }
|
|
415
|
-
end
|
|
416
|
-
|
|
417
|
-
it 'does NOT preload if request matches unless block' do
|
|
418
|
-
expect(flipper).to receive(:preload_all).never
|
|
419
|
-
get '/assets/foo.png', {}, 'flipper' => flipper
|
|
420
|
-
end
|
|
421
|
-
|
|
422
|
-
it 'does preload if request does NOT match unless block' do
|
|
423
|
-
expect(flipper).to receive(:preload_all).once
|
|
424
|
-
get '/some/other/path', {}, 'flipper' => flipper
|
|
425
|
-
end
|
|
426
|
-
end
|
|
427
|
-
|
|
428
|
-
context 'and if option' do
|
|
429
|
-
before do
|
|
430
|
-
options[:if] = ->(request) { !request.path.start_with?("/assets") }
|
|
431
|
-
end
|
|
432
|
-
|
|
433
|
-
it 'does NOT preload if request does not match if block' do
|
|
434
|
-
expect(flipper).to receive(:preload_all).never
|
|
435
|
-
get '/assets/foo.png', {}, 'flipper' => flipper
|
|
436
|
-
end
|
|
437
|
-
|
|
438
|
-
it 'does preload if request matches if block' do
|
|
439
|
-
expect(flipper).to receive(:preload_all).once
|
|
440
|
-
get '/some/other/path', {}, 'flipper' => flipper
|
|
441
|
-
end
|
|
442
|
-
end
|
|
443
|
-
end
|
|
444
|
-
|
|
445
|
-
context 'with preload:true and caching adapter' do
|
|
446
|
-
let(:app) do
|
|
447
|
-
app = lambda do |_env|
|
|
448
|
-
flipper[:stats].enabled?
|
|
449
|
-
flipper[:stats].enabled?
|
|
450
|
-
flipper[:shiny].enabled?
|
|
451
|
-
flipper[:shiny].enabled?
|
|
452
|
-
[200, {}, []]
|
|
453
|
-
end
|
|
454
|
-
|
|
455
|
-
described_class.new(app, preload: true)
|
|
456
|
-
end
|
|
457
|
-
|
|
458
|
-
it 'eagerly caches known features for duration of request' do
|
|
459
|
-
memory = Flipper::Adapters::Memory.new
|
|
460
|
-
logged_memory = Flipper::Adapters::OperationLogger.new(memory)
|
|
461
|
-
cache = ActiveSupport::Cache::MemoryStore.new
|
|
462
|
-
cache.clear
|
|
463
|
-
cached = Flipper::Adapters::ActiveSupportCacheStore.new(logged_memory, cache)
|
|
464
|
-
logged_cached = Flipper::Adapters::OperationLogger.new(cached)
|
|
465
|
-
flipper = Flipper.new(logged_cached)
|
|
466
|
-
flipper[:stats].enable
|
|
467
|
-
flipper[:shiny].enable
|
|
468
|
-
|
|
469
|
-
# clear the log of operations
|
|
470
|
-
logged_memory.reset
|
|
471
|
-
logged_cached.reset
|
|
472
|
-
|
|
473
|
-
get '/', {}, 'flipper' => flipper
|
|
474
|
-
expect(logged_cached.count(:get_all)).to be(1)
|
|
475
|
-
expect(logged_memory.count(:get_all)).to be(1)
|
|
476
|
-
|
|
477
|
-
get '/', {}, 'flipper' => flipper
|
|
478
|
-
expect(logged_cached.count(:get_all)).to be(2)
|
|
479
|
-
expect(logged_memory.count(:get_all)).to be(1)
|
|
480
|
-
|
|
481
|
-
get '/', {}, 'flipper' => flipper
|
|
482
|
-
expect(logged_cached.count(:get_all)).to be(3)
|
|
483
|
-
expect(logged_memory.count(:get_all)).to be(1)
|
|
484
|
-
end
|
|
485
|
-
end
|
|
486
|
-
|
|
487
|
-
context 'with preload:true and Sync adapter wrapped with ActorLimit' do
|
|
488
|
-
it 'preloads even when remote has more actors than local limit' do
|
|
489
|
-
local = Flipper::Adapters::Memory.new
|
|
490
|
-
remote = Flipper::Adapters::Memory.new
|
|
491
|
-
remote_flipper = Flipper.new(remote)
|
|
492
|
-
|
|
493
|
-
# Remote has more actors than limit allows (actor-only enables, not boolean)
|
|
494
|
-
10.times { |i| remote_flipper[:stats].enable_actor Flipper::Actor.new("User;#{i}") }
|
|
495
|
-
|
|
496
|
-
# Sync adapter will sync from remote to local, then ActorLimit wraps it
|
|
497
|
-
# Use interval: 0 to force sync on every call
|
|
498
|
-
sync_adapter = Flipper::Adapters::Sync.new(local, remote, interval: 0)
|
|
499
|
-
limited_adapter = Flipper::Adapters::ActorLimit.new(sync_adapter, 5)
|
|
500
|
-
test_flipper = Flipper.new(limited_adapter)
|
|
501
|
-
|
|
502
|
-
app = lambda do |env|
|
|
503
|
-
f = env['flipper']
|
|
504
|
-
f[:stats].enabled?
|
|
505
|
-
[200, {}, []]
|
|
506
|
-
end
|
|
507
|
-
middleware = described_class.new(app, preload: true)
|
|
508
|
-
|
|
509
|
-
# Preload should work without raising ActorLimit::LimitExceeded
|
|
510
|
-
expect {
|
|
511
|
-
middleware.call('flipper' => test_flipper)
|
|
512
|
-
}.not_to raise_error
|
|
513
|
-
|
|
514
|
-
# Verify actors were synced (all 10, not just 5)
|
|
515
|
-
expect(test_flipper[:stats].actors_value.size).to eq(10)
|
|
516
|
-
end
|
|
517
|
-
end
|
|
518
|
-
end
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
RSpec.describe Flipper::Middleware::SetupEnv do
|
|
2
|
-
context 'with flipper instance' do
|
|
3
|
-
let(:app) do
|
|
4
|
-
app = lambda do |env|
|
|
5
|
-
[200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
|
|
6
|
-
end
|
|
7
|
-
builder = Rack::Builder.new
|
|
8
|
-
builder.use described_class, flipper
|
|
9
|
-
builder.run app
|
|
10
|
-
builder
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
it 'sets flipper in env' do
|
|
14
|
-
get '/'
|
|
15
|
-
expect(last_response.body).to eq(flipper.object_id.to_s)
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
context 'with block that returns flipper instance' do
|
|
20
|
-
let(:flipper_block) do
|
|
21
|
-
-> { flipper }
|
|
22
|
-
end
|
|
23
|
-
let(:app) do
|
|
24
|
-
app = lambda do |env|
|
|
25
|
-
[200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
|
|
26
|
-
end
|
|
27
|
-
builder = Rack::Builder.new
|
|
28
|
-
builder.use described_class, flipper_block
|
|
29
|
-
builder.run app
|
|
30
|
-
builder
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
it 'sets flipper in env' do
|
|
34
|
-
get '/'
|
|
35
|
-
expect(last_response.body).to eq(flipper.object_id.to_s)
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
context 'when env already has flipper setup' do
|
|
40
|
-
let(:app) do
|
|
41
|
-
app = lambda do |env|
|
|
42
|
-
[200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
|
|
43
|
-
end
|
|
44
|
-
builder = Rack::Builder.new
|
|
45
|
-
builder.use described_class, flipper
|
|
46
|
-
builder.run app
|
|
47
|
-
builder
|
|
48
|
-
end
|
|
49
|
-
|
|
50
|
-
it 'leaves env flipper alone' do
|
|
51
|
-
env_flipper = build_flipper
|
|
52
|
-
get '/', {}, 'flipper' => env_flipper
|
|
53
|
-
expect(last_response.body).to eq(env_flipper.object_id.to_s)
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
context 'when flipper instance or block are nil but env flipper is configured' do
|
|
58
|
-
let(:app) do
|
|
59
|
-
app = lambda do |env|
|
|
60
|
-
[200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
|
|
61
|
-
end
|
|
62
|
-
builder = Rack::Builder.new
|
|
63
|
-
builder.use described_class
|
|
64
|
-
builder.run app
|
|
65
|
-
builder
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
it 'can use env flipper' do
|
|
69
|
-
env_flipper = build_flipper
|
|
70
|
-
get '/', {}, 'flipper' => env_flipper
|
|
71
|
-
expect(last_response.body).to eq(env_flipper.object_id.to_s)
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
context 'when flipper instance or block are nil and default Flipper is configured' do
|
|
76
|
-
let(:app) do
|
|
77
|
-
Flipper.configure do |config|
|
|
78
|
-
config.default { flipper }
|
|
79
|
-
end
|
|
80
|
-
app = lambda do |env|
|
|
81
|
-
[200, { 'Content-Type' => 'text/html' }, [env['flipper'].object_id.to_s]]
|
|
82
|
-
end
|
|
83
|
-
builder = Rack::Builder.new
|
|
84
|
-
builder.use described_class
|
|
85
|
-
builder.run app
|
|
86
|
-
builder
|
|
87
|
-
end
|
|
88
|
-
|
|
89
|
-
it 'can use env flipper' do
|
|
90
|
-
get '/', {}, {}
|
|
91
|
-
expect(last_response.body).to eq(Flipper.object_id.to_s)
|
|
92
|
-
end
|
|
93
|
-
end
|
|
94
|
-
end
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
require 'active_record'
|
|
2
|
-
require 'flipper/model/active_record'
|
|
3
|
-
|
|
4
|
-
# Turn off migration logging for specs
|
|
5
|
-
ActiveRecord::Migration.verbose = false
|
|
6
|
-
|
|
7
|
-
RSpec.describe Flipper::Model::ActiveRecord do
|
|
8
|
-
before(:all) do
|
|
9
|
-
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
before(:each) do
|
|
13
|
-
ActiveRecord::Base.connection.execute <<-SQL
|
|
14
|
-
CREATE TABLE users (
|
|
15
|
-
id integer PRIMARY KEY,
|
|
16
|
-
name string NOT NULL,
|
|
17
|
-
age integer,
|
|
18
|
-
is_confirmed boolean,
|
|
19
|
-
created_at datetime NOT NULL,
|
|
20
|
-
updated_at datetime NOT NULL
|
|
21
|
-
)
|
|
22
|
-
SQL
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
after(:each) do
|
|
26
|
-
ActiveRecord::Base.connection.execute("DROP table IF EXISTS `users`")
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
class User < ActiveRecord::Base
|
|
30
|
-
include Flipper::Model::ActiveRecord
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class DelegatedUser < DelegateClass(User)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
class Admin < User
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "doesn't warn for to_ary" do
|
|
40
|
-
# looks like we should remove this but you are wrong, we have specs that
|
|
41
|
-
# fail if there are warnings and if this regresses it will print a warning
|
|
42
|
-
# so it is in fact testing something
|
|
43
|
-
user = User.create!(name: "Test")
|
|
44
|
-
Flipper.enabled?(:something, DelegatedUser.new(user))
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
describe "flipper_id" do
|
|
48
|
-
it "returns class name and id" do
|
|
49
|
-
expect(User.new(id: 1).flipper_id).to eq("User;1")
|
|
50
|
-
end
|
|
51
|
-
|
|
52
|
-
it "uses base class name" do
|
|
53
|
-
expect(Admin.new(id: 2).flipper_id).to eq("User;2")
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
|
|
57
|
-
describe "flipper_properties" do
|
|
58
|
-
subject { User.create!(name: "Test", age: 22, is_confirmed: true) }
|
|
59
|
-
|
|
60
|
-
it "includes all attributes" do
|
|
61
|
-
expect(subject.flipper_properties).to eq({
|
|
62
|
-
"type" => "User",
|
|
63
|
-
"id" => subject.id,
|
|
64
|
-
"name" => "Test",
|
|
65
|
-
"age" => 22,
|
|
66
|
-
"is_confirmed" => true,
|
|
67
|
-
"created_at" => subject.created_at,
|
|
68
|
-
"updated_at" => subject.updated_at
|
|
69
|
-
})
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|