flipper 0.20.1 → 0.21.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +57 -0
  3. data/Changelog.md +66 -0
  4. data/Gemfile +1 -0
  5. data/README.md +103 -47
  6. data/docs/Adapters.md +9 -9
  7. data/docs/Caveats.md +2 -2
  8. data/docs/Gates.md +74 -74
  9. data/docs/Optimization.md +70 -47
  10. data/docs/http/README.md +12 -11
  11. data/docs/images/banner.jpg +0 -0
  12. data/docs/read-only/README.md +8 -5
  13. data/examples/basic.rb +1 -12
  14. data/examples/configuring_default.rb +2 -5
  15. data/examples/dsl.rb +13 -24
  16. data/examples/enabled_for_actor.rb +8 -15
  17. data/examples/group.rb +3 -6
  18. data/examples/group_dynamic_lookup.rb +5 -19
  19. data/examples/group_with_members.rb +4 -14
  20. data/examples/importing.rb +1 -1
  21. data/examples/individual_actor.rb +2 -5
  22. data/examples/instrumentation.rb +1 -2
  23. data/examples/memoizing.rb +3 -7
  24. data/examples/percentage_of_actors.rb +6 -16
  25. data/examples/percentage_of_actors_enabled_check.rb +7 -10
  26. data/examples/percentage_of_actors_group.rb +5 -18
  27. data/examples/percentage_of_time.rb +3 -6
  28. data/lib/flipper.rb +4 -1
  29. data/lib/flipper/adapters/http.rb +32 -28
  30. data/lib/flipper/adapters/memory.rb +20 -94
  31. data/lib/flipper/adapters/pstore.rb +4 -0
  32. data/lib/flipper/adapters/sync/interval_synchronizer.rb +1 -1
  33. data/lib/flipper/configuration.rb +33 -7
  34. data/lib/flipper/errors.rb +2 -3
  35. data/lib/flipper/identifier.rb +17 -0
  36. data/lib/flipper/middleware/memoizer.rb +29 -14
  37. data/lib/flipper/railtie.rb +38 -0
  38. data/lib/flipper/version.rb +1 -1
  39. data/spec/flipper/adapters/http_spec.rb +74 -8
  40. data/spec/flipper/adapters/memory_spec.rb +21 -1
  41. data/spec/flipper/configuration_spec.rb +20 -2
  42. data/spec/flipper/identifier_spec.rb +14 -0
  43. data/spec/flipper/middleware/memoizer_spec.rb +95 -35
  44. data/spec/flipper/middleware/setup_env_spec.rb +0 -16
  45. data/spec/flipper/railtie_spec.rb +69 -0
  46. data/spec/flipper_spec.rb +0 -1
  47. data/spec/support/spec_helpers.rb +20 -0
  48. data/test/test_helper.rb +1 -0
  49. metadata +12 -5
  50. 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
@@ -232,7 +232,6 @@ RSpec.describe Flipper do
232
232
  cloud_configuration = Flipper::Cloud::Configuration.new({
233
233
  token: "asdf",
234
234
  sync_secret: "tasty",
235
- sync_method: :webhook,
236
235
  })
237
236
 
238
237
  described_class.configure do |config|
@@ -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
@@ -1,3 +1,4 @@
1
+ require 'bundler/setup'
1
2
  require 'flipper'
2
3
  require 'minitest/autorun'
3
4
  require 'minitest/unit'
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.20.1
4
+ version: 0.21.0.rc2
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-31 00:00:00.000000000 Z
11
+ date: 2021-05-08 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description:
14
14
  email:
@@ -18,6 +18,7 @@ extensions: []
18
18
  extra_rdoc_files: []
19
19
  files:
20
20
  - ".codeclimate.yml"
21
+ - ".github/workflows/ci.yml"
21
22
  - CODE_OF_CONDUCT.md
22
23
  - Changelog.md
23
24
  - Dockerfile
@@ -34,12 +35,12 @@ files:
34
35
  - docs/Optimization.md
35
36
  - docs/api/README.md
36
37
  - docs/http/README.md
38
+ - docs/images/banner.jpg
37
39
  - docs/read-only/README.md
38
40
  - examples/basic.rb
39
41
  - examples/configuring_default.rb
40
42
  - examples/dsl.rb
41
43
  - examples/enabled_for_actor.rb
42
- - examples/example_setup.rb
43
44
  - examples/group.rb
44
45
  - examples/group_dynamic_lookup.rb
45
46
  - examples/group_with_members.rb
@@ -81,6 +82,7 @@ files:
81
82
  - lib/flipper/gates/group.rb
82
83
  - lib/flipper/gates/percentage_of_actors.rb
83
84
  - lib/flipper/gates/percentage_of_time.rb
85
+ - lib/flipper/identifier.rb
84
86
  - lib/flipper/instrumentation/log_subscriber.rb
85
87
  - lib/flipper/instrumentation/statsd.rb
86
88
  - lib/flipper/instrumentation/statsd_subscriber.rb
@@ -90,6 +92,7 @@ files:
90
92
  - lib/flipper/metadata.rb
91
93
  - lib/flipper/middleware/memoizer.rb
92
94
  - lib/flipper/middleware/setup_env.rb
95
+ - lib/flipper/railtie.rb
93
96
  - lib/flipper/registry.rb
94
97
  - lib/flipper/spec/shared_adapter_specs.rb
95
98
  - lib/flipper/test/shared_adapter_test.rb
@@ -128,12 +131,14 @@ files:
128
131
  - spec/flipper/gates/group_spec.rb
129
132
  - spec/flipper/gates/percentage_of_actors_spec.rb
130
133
  - spec/flipper/gates/percentage_of_time_spec.rb
134
+ - spec/flipper/identifier_spec.rb
131
135
  - spec/flipper/instrumentation/log_subscriber_spec.rb
132
136
  - spec/flipper/instrumentation/statsd_subscriber_spec.rb
133
137
  - spec/flipper/instrumenters/memory_spec.rb
134
138
  - spec/flipper/instrumenters/noop_spec.rb
135
139
  - spec/flipper/middleware/memoizer_spec.rb
136
140
  - spec/flipper/middleware/setup_env_spec.rb
141
+ - spec/flipper/railtie_spec.rb
137
142
  - spec/flipper/registry_spec.rb
138
143
  - spec/flipper/typecast_spec.rb
139
144
  - spec/flipper/types/actor_spec.rb
@@ -168,9 +173,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
168
173
  version: '0'
169
174
  required_rubygems_version: !ruby/object:Gem::Requirement
170
175
  requirements:
171
- - - ">="
176
+ - - ">"
172
177
  - !ruby/object:Gem::Version
173
- version: '0'
178
+ version: 1.3.1
174
179
  requirements: []
175
180
  rubygems_version: 3.0.3
176
181
  signing_key:
@@ -203,12 +208,14 @@ test_files:
203
208
  - spec/flipper/gates/group_spec.rb
204
209
  - spec/flipper/gates/percentage_of_actors_spec.rb
205
210
  - spec/flipper/gates/percentage_of_time_spec.rb
211
+ - spec/flipper/identifier_spec.rb
206
212
  - spec/flipper/instrumentation/log_subscriber_spec.rb
207
213
  - spec/flipper/instrumentation/statsd_subscriber_spec.rb
208
214
  - spec/flipper/instrumenters/memory_spec.rb
209
215
  - spec/flipper/instrumenters/noop_spec.rb
210
216
  - spec/flipper/middleware/memoizer_spec.rb
211
217
  - spec/flipper/middleware/setup_env_spec.rb
218
+ - spec/flipper/railtie_spec.rb
212
219
  - spec/flipper/registry_spec.rb
213
220
  - spec/flipper/typecast_spec.rb
214
221
  - spec/flipper/types/actor_spec.rb
@@ -1,8 +0,0 @@
1
- # Nothing to see here... move along.
2
- # Sets up load path for examples and requires some stuff
3
- require 'pp'
4
- require 'pathname'
5
-
6
- root_path = Pathname(__FILE__).dirname.join('..').expand_path
7
- lib_path = root_path.join('lib')
8
- $:.unshift(lib_path)