flipper 0.20.2 → 0.21.0
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/.github/workflows/ci.yml +9 -1
- data/Changelog.md +59 -0
- data/Gemfile +1 -0
- data/README.md +103 -47
- data/docs/Adapters.md +9 -9
- data/docs/Caveats.md +2 -2
- data/docs/Gates.md +74 -74
- data/docs/Optimization.md +70 -47
- data/docs/http/README.md +12 -11
- data/docs/images/banner.jpg +0 -0
- data/docs/read-only/README.md +8 -5
- data/examples/basic.rb +1 -12
- data/examples/configuring_default.rb +2 -5
- data/examples/dsl.rb +13 -24
- data/examples/enabled_for_actor.rb +8 -15
- data/examples/group.rb +3 -6
- data/examples/group_dynamic_lookup.rb +5 -19
- data/examples/group_with_members.rb +4 -14
- data/examples/importing.rb +1 -1
- data/examples/individual_actor.rb +2 -5
- data/examples/instrumentation.rb +1 -2
- data/examples/memoizing.rb +3 -7
- data/examples/percentage_of_actors.rb +6 -16
- data/examples/percentage_of_actors_enabled_check.rb +7 -10
- data/examples/percentage_of_actors_group.rb +5 -18
- data/examples/percentage_of_time.rb +3 -6
- data/lib/flipper.rb +4 -1
- data/lib/flipper/adapters/memory.rb +20 -94
- data/lib/flipper/adapters/pstore.rb +4 -0
- data/lib/flipper/configuration.rb +33 -7
- data/lib/flipper/errors.rb +2 -3
- data/lib/flipper/identifier.rb +17 -0
- data/lib/flipper/middleware/memoizer.rb +29 -14
- data/lib/flipper/railtie.rb +38 -0
- data/lib/flipper/version.rb +1 -1
- data/spec/flipper/adapters/memory_spec.rb +21 -1
- data/spec/flipper/configuration_spec.rb +20 -2
- data/spec/flipper/identifier_spec.rb +14 -0
- data/spec/flipper/middleware/memoizer_spec.rb +95 -35
- data/spec/flipper/middleware/setup_env_spec.rb +0 -16
- data/spec/flipper/railtie_spec.rb +69 -0
- data/spec/flipper_spec.rb +0 -1
- data/spec/helper.rb +2 -2
- data/spec/support/spec_helpers.rb +20 -0
- data/test/test_helper.rb +1 -0
- metadata +9 -3
- data/examples/example_setup.rb +0 -8
@@ -93,20 +93,4 @@ RSpec.describe Flipper::Middleware::SetupEnv do
|
|
93
93
|
expect(last_response.body).to eq(Flipper.object_id.to_s)
|
94
94
|
end
|
95
95
|
end
|
96
|
-
|
97
|
-
context 'when flipper instance or block are nil and default Flipper is NOT configured' do
|
98
|
-
let(:app) do
|
99
|
-
app = lambda do |env|
|
100
|
-
[200, { 'Content-Type' => 'text/html' }, [env['flipper'].enabled?(:search)]]
|
101
|
-
end
|
102
|
-
builder = Rack::Builder.new
|
103
|
-
builder.use described_class
|
104
|
-
builder.run app
|
105
|
-
builder
|
106
|
-
end
|
107
|
-
|
108
|
-
it 'can use env flipper' do
|
109
|
-
expect { get '/' }.to raise_error(Flipper::DefaultNotSet)
|
110
|
-
end
|
111
|
-
end
|
112
96
|
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'rails'
|
3
|
+
require 'flipper/railtie'
|
4
|
+
|
5
|
+
RSpec.describe Flipper::Railtie do
|
6
|
+
let(:application) do
|
7
|
+
app = Class.new(Rails::Application).new(
|
8
|
+
railties: [Flipper::Railtie],
|
9
|
+
ordered_railties: [Flipper::Railtie]
|
10
|
+
)
|
11
|
+
app.config.eager_load = false
|
12
|
+
app.config.logger = ActiveSupport::Logger.new($stdout)
|
13
|
+
app.run_load_hooks!
|
14
|
+
end
|
15
|
+
|
16
|
+
before do
|
17
|
+
Rails.application = nil
|
18
|
+
end
|
19
|
+
|
20
|
+
subject do
|
21
|
+
application.initialize!
|
22
|
+
application
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'initializers' do
|
26
|
+
it 'sets defaults' do
|
27
|
+
expect(application.config.flipper.env_key).to eq("flipper")
|
28
|
+
expect(application.config.flipper.memoize).to be(true)
|
29
|
+
expect(application.config.flipper.preload).to be(true)
|
30
|
+
end
|
31
|
+
|
32
|
+
it "configures instrumentor on default instance" do
|
33
|
+
subject
|
34
|
+
|
35
|
+
expect(Flipper.instance.instrumenter).to eq(ActiveSupport::Notifications)
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'uses Memoizer middleware if config.memoize = true' do
|
39
|
+
expect(subject.middleware.last).to eq(Flipper::Middleware::Memoizer)
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'does not use Memoizer middleware if config.memoize = false' do
|
43
|
+
# load but don't initialize
|
44
|
+
application.config.flipper.memoize = false
|
45
|
+
|
46
|
+
expect(subject.middleware.last).not_to eq(Flipper::Middleware::Memoizer)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'passes config to memoizer' do
|
50
|
+
# load but don't initialize
|
51
|
+
application.config.flipper.update(
|
52
|
+
env_key: 'my_flipper',
|
53
|
+
preload: [:stats, :search]
|
54
|
+
)
|
55
|
+
|
56
|
+
expect(Flipper::Middleware::Memoizer).to receive(:new).with(application.routes,
|
57
|
+
env_key: 'my_flipper', preload: [:stats, :search], if: nil
|
58
|
+
)
|
59
|
+
|
60
|
+
subject # initialize
|
61
|
+
end
|
62
|
+
|
63
|
+
it "defines #flipper_id on AR::Base" do
|
64
|
+
subject
|
65
|
+
require 'active_record'
|
66
|
+
expect(ActiveRecord::Base.ancestors).to include(Flipper::Identifier)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/spec/flipper_spec.rb
CHANGED
data/spec/helper.rb
CHANGED
@@ -14,8 +14,8 @@ require 'webmock/rspec'
|
|
14
14
|
WebMock.disable_net_connect!(allow_localhost: true)
|
15
15
|
|
16
16
|
require 'flipper'
|
17
|
-
require 'flipper
|
18
|
-
require 'flipper
|
17
|
+
require 'flipper/ui'
|
18
|
+
require 'flipper/api'
|
19
19
|
|
20
20
|
Dir[FlipperRoot.join('spec/support/**/*.rb')].sort.each { |f| require f }
|
21
21
|
|
@@ -61,9 +61,29 @@ module SpecHelpers
|
|
61
61
|
def with_modified_env(options, &block)
|
62
62
|
ClimateControl.modify(options, &block)
|
63
63
|
end
|
64
|
+
|
65
|
+
def silence
|
66
|
+
# Store the original stderr and stdout in order to restore them later
|
67
|
+
original_stderr = $stderr
|
68
|
+
original_stdout = $stdout
|
69
|
+
|
70
|
+
# Redirect stderr and stdout
|
71
|
+
output = $stderr = $stdout = StringIO.new
|
72
|
+
|
73
|
+
yield
|
74
|
+
|
75
|
+
$stderr = original_stderr
|
76
|
+
$stdout = original_stdout
|
77
|
+
|
78
|
+
# Return output
|
79
|
+
output.string
|
80
|
+
end
|
64
81
|
end
|
65
82
|
|
66
83
|
RSpec.configure do |config|
|
84
|
+
config.order = :random
|
85
|
+
Kernel.srand config.seed
|
86
|
+
|
67
87
|
config.include Rack::Test::Methods
|
68
88
|
config.include SpecHelpers
|
69
89
|
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Nunemaker
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email:
|
@@ -35,12 +35,12 @@ files:
|
|
35
35
|
- docs/Optimization.md
|
36
36
|
- docs/api/README.md
|
37
37
|
- docs/http/README.md
|
38
|
+
- docs/images/banner.jpg
|
38
39
|
- docs/read-only/README.md
|
39
40
|
- examples/basic.rb
|
40
41
|
- examples/configuring_default.rb
|
41
42
|
- examples/dsl.rb
|
42
43
|
- examples/enabled_for_actor.rb
|
43
|
-
- examples/example_setup.rb
|
44
44
|
- examples/group.rb
|
45
45
|
- examples/group_dynamic_lookup.rb
|
46
46
|
- examples/group_with_members.rb
|
@@ -82,6 +82,7 @@ files:
|
|
82
82
|
- lib/flipper/gates/group.rb
|
83
83
|
- lib/flipper/gates/percentage_of_actors.rb
|
84
84
|
- lib/flipper/gates/percentage_of_time.rb
|
85
|
+
- lib/flipper/identifier.rb
|
85
86
|
- lib/flipper/instrumentation/log_subscriber.rb
|
86
87
|
- lib/flipper/instrumentation/statsd.rb
|
87
88
|
- lib/flipper/instrumentation/statsd_subscriber.rb
|
@@ -91,6 +92,7 @@ files:
|
|
91
92
|
- lib/flipper/metadata.rb
|
92
93
|
- lib/flipper/middleware/memoizer.rb
|
93
94
|
- lib/flipper/middleware/setup_env.rb
|
95
|
+
- lib/flipper/railtie.rb
|
94
96
|
- lib/flipper/registry.rb
|
95
97
|
- lib/flipper/spec/shared_adapter_specs.rb
|
96
98
|
- lib/flipper/test/shared_adapter_test.rb
|
@@ -129,12 +131,14 @@ files:
|
|
129
131
|
- spec/flipper/gates/group_spec.rb
|
130
132
|
- spec/flipper/gates/percentage_of_actors_spec.rb
|
131
133
|
- spec/flipper/gates/percentage_of_time_spec.rb
|
134
|
+
- spec/flipper/identifier_spec.rb
|
132
135
|
- spec/flipper/instrumentation/log_subscriber_spec.rb
|
133
136
|
- spec/flipper/instrumentation/statsd_subscriber_spec.rb
|
134
137
|
- spec/flipper/instrumenters/memory_spec.rb
|
135
138
|
- spec/flipper/instrumenters/noop_spec.rb
|
136
139
|
- spec/flipper/middleware/memoizer_spec.rb
|
137
140
|
- spec/flipper/middleware/setup_env_spec.rb
|
141
|
+
- spec/flipper/railtie_spec.rb
|
138
142
|
- spec/flipper/registry_spec.rb
|
139
143
|
- spec/flipper/typecast_spec.rb
|
140
144
|
- spec/flipper/types/actor_spec.rb
|
@@ -204,12 +208,14 @@ test_files:
|
|
204
208
|
- spec/flipper/gates/group_spec.rb
|
205
209
|
- spec/flipper/gates/percentage_of_actors_spec.rb
|
206
210
|
- spec/flipper/gates/percentage_of_time_spec.rb
|
211
|
+
- spec/flipper/identifier_spec.rb
|
207
212
|
- spec/flipper/instrumentation/log_subscriber_spec.rb
|
208
213
|
- spec/flipper/instrumentation/statsd_subscriber_spec.rb
|
209
214
|
- spec/flipper/instrumenters/memory_spec.rb
|
210
215
|
- spec/flipper/instrumenters/noop_spec.rb
|
211
216
|
- spec/flipper/middleware/memoizer_spec.rb
|
212
217
|
- spec/flipper/middleware/setup_env_spec.rb
|
218
|
+
- spec/flipper/railtie_spec.rb
|
213
219
|
- spec/flipper/registry_spec.rb
|
214
220
|
- spec/flipper/typecast_spec.rb
|
215
221
|
- spec/flipper/types/actor_spec.rb
|
data/examples/example_setup.rb
DELETED