flipper 0.28.3 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/examples.yml +2 -2
  3. data/Changelog.md +190 -165
  4. data/Gemfile +5 -3
  5. data/docs/images/flipper_cloud.png +0 -0
  6. data/examples/cloud/app.ru +12 -0
  7. data/examples/cloud/basic.rb +22 -0
  8. data/examples/cloud/cloud_setup.rb +4 -0
  9. data/examples/cloud/forked.rb +31 -0
  10. data/examples/cloud/import.rb +17 -0
  11. data/examples/cloud/threaded.rb +36 -0
  12. data/examples/dsl.rb +0 -14
  13. data/flipper-cloud.gemspec +19 -0
  14. data/flipper.gemspec +3 -2
  15. data/lib/flipper/cloud/configuration.rb +189 -0
  16. data/lib/flipper/cloud/dsl.rb +27 -0
  17. data/lib/flipper/cloud/instrumenter.rb +48 -0
  18. data/lib/flipper/cloud/message_verifier.rb +95 -0
  19. data/lib/flipper/cloud/middleware.rb +63 -0
  20. data/lib/flipper/cloud/routes.rb +14 -0
  21. data/lib/flipper/cloud.rb +53 -0
  22. data/lib/flipper/dsl.rb +0 -46
  23. data/lib/flipper/{railtie.rb → engine.rb} +19 -3
  24. data/lib/flipper/metadata.rb +5 -1
  25. data/lib/flipper/middleware/memoizer.rb +1 -1
  26. data/lib/flipper/spec/shared_adapter_specs.rb +43 -43
  27. data/lib/flipper/test/shared_adapter_test.rb +43 -43
  28. data/lib/flipper/version.rb +1 -1
  29. data/lib/flipper.rb +3 -5
  30. data/spec/flipper/adapters/dual_write_spec.rb +2 -2
  31. data/spec/flipper/adapters/instrumented_spec.rb +1 -1
  32. data/spec/flipper/adapters/memoizable_spec.rb +6 -6
  33. data/spec/flipper/adapters/operation_logger_spec.rb +2 -2
  34. data/spec/flipper/adapters/read_only_spec.rb +6 -6
  35. data/spec/flipper/cloud/configuration_spec.rb +269 -0
  36. data/spec/flipper/cloud/dsl_spec.rb +82 -0
  37. data/spec/flipper/cloud/message_verifier_spec.rb +104 -0
  38. data/spec/flipper/cloud/middleware_spec.rb +289 -0
  39. data/spec/flipper/cloud_spec.rb +180 -0
  40. data/spec/flipper/dsl_spec.rb +0 -75
  41. data/spec/flipper/engine_spec.rb +190 -0
  42. data/spec/flipper_integration_spec.rb +12 -12
  43. data/spec/flipper_spec.rb +0 -30
  44. data/spec/spec_helper.rb +0 -12
  45. data/spec/support/climate_control.rb +7 -0
  46. metadata +54 -11
  47. data/.tool-versions +0 -1
  48. data/spec/flipper/railtie_spec.rb +0 -109
@@ -0,0 +1,53 @@
1
+ require "flipper"
2
+ require "flipper/middleware/setup_env"
3
+ require "flipper/middleware/memoizer"
4
+ require "flipper/cloud/configuration"
5
+ require "flipper/cloud/dsl"
6
+ require "flipper/cloud/middleware"
7
+
8
+ module Flipper
9
+ module Cloud
10
+ # Public: Returns a new Flipper instance with an http adapter correctly
11
+ # configured for flipper cloud.
12
+ #
13
+ # token - The String token for the environment from the website.
14
+ # options - The Hash of options. See Flipper::Cloud::Configuration.
15
+ # block - The block that configuration will be yielded to allowing you to
16
+ # customize this cloud instance and its adapter.
17
+ def self.new(options = {})
18
+ configuration = Configuration.new(options)
19
+ yield configuration if block_given?
20
+ DSL.new(configuration)
21
+ end
22
+
23
+ def self.app(flipper = nil, options = {})
24
+ env_key = options.fetch(:env_key, 'flipper')
25
+ memoizer_options = options.fetch(:memoizer_options, {})
26
+
27
+ app = ->(_) { [404, { 'content-type'.freeze => 'application/json'.freeze }, ['{}'.freeze]] }
28
+ builder = Rack::Builder.new
29
+ yield builder if block_given?
30
+ builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
31
+ builder.use Flipper::Middleware::Memoizer, memoizer_options.merge(env_key: env_key)
32
+ builder.use Flipper::Cloud::Middleware, env_key: env_key
33
+ builder.run app
34
+ klass = self
35
+ app = builder.to_app
36
+ app.define_singleton_method(:inspect) { klass.inspect } # pretty rake routes output
37
+ app
38
+ end
39
+
40
+ # Private: Configure Flipper to use Cloud by default
41
+ def self.set_default
42
+ if ENV["FLIPPER_CLOUD_TOKEN"]
43
+ Flipper.configure do |config|
44
+ config.default do
45
+ self.new(local_adapter: config.adapter)
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
53
+ Flipper::Cloud.set_default
data/lib/flipper/dsl.rb CHANGED
@@ -210,22 +210,6 @@ module Flipper
210
210
  # Returns an instance of Flipper::Feature.
211
211
  alias_method :[], :feature
212
212
 
213
- # Public: Shortcut for getting a boolean type instance.
214
- #
215
- # value - The true or false value for the boolean.
216
- #
217
- # Returns a Flipper::Types::Boolean instance.
218
- def boolean(value = true)
219
- Types::Boolean.new(value)
220
- end
221
-
222
- # Public: Even shorter shortcut for getting a boolean type instance.
223
- #
224
- # value - The true or false value for the boolean.
225
- #
226
- # Returns a Flipper::Types::Boolean instance.
227
- alias_method :bool, :boolean
228
-
229
213
  # Public: Access a flipper group by name.
230
214
  #
231
215
  # name - The String or Symbol name of the feature.
@@ -235,36 +219,6 @@ module Flipper
235
219
  Flipper.group(name)
236
220
  end
237
221
 
238
- # Public: Wraps an object as a flipper actor.
239
- #
240
- # actor - The object that you would like to wrap.
241
- #
242
- # Returns an instance of Flipper::Types::Actor.
243
- # Raises ArgumentError if actor does not respond to `flipper_id`.
244
- def actor(actor)
245
- Types::Actor.new(actor)
246
- end
247
-
248
- # Public: Shortcut for getting a percentage of time instance.
249
- #
250
- # number - The percentage of time that should be enabled.
251
- #
252
- # Returns Flipper::Types::PercentageOfTime.
253
- def time(number)
254
- Types::PercentageOfTime.new(number)
255
- end
256
- alias_method :percentage_of_time, :time
257
-
258
- # Public: Shortcut for getting a percentage of actors instance.
259
- #
260
- # number - The percentage of actors that should be enabled.
261
- #
262
- # Returns Flipper::Types::PercentageOfActors.
263
- def actors(number)
264
- Types::PercentageOfActors.new(number)
265
- end
266
- alias_method :percentage_of_actors, :actors
267
-
268
222
  # Public: Returns a Set of the known features for this adapter.
269
223
  #
270
224
  # Returns Set of Flipper::Feature instances.
@@ -1,12 +1,15 @@
1
1
  module Flipper
2
- class Railtie < Rails::Railtie
2
+ class Engine < Rails::Engine
3
+ paths["config/routes.rb"] = ["lib/flipper/cloud/routes.rb"]
4
+
3
5
  config.before_configuration do
4
6
  config.flipper = ActiveSupport::OrderedOptions.new.update(
5
7
  env_key: ENV.fetch('FLIPPER_ENV_KEY', 'flipper'),
6
8
  memoize: ENV.fetch('FLIPPER_MEMOIZE', 'true').casecmp('true').zero?,
7
9
  preload: ENV.fetch('FLIPPER_PRELOAD', 'true').casecmp('true').zero?,
8
10
  instrumenter: ENV.fetch('FLIPPER_INSTRUMENTER', 'ActiveSupport::Notifications').constantize,
9
- log: ENV.fetch('FLIPPER_LOG', 'true').casecmp('true').zero?
11
+ log: ENV.fetch('FLIPPER_LOG', 'true').casecmp('true').zero?,
12
+ cloud_path: "_flipper"
10
13
  )
11
14
  end
12
15
 
@@ -17,9 +20,18 @@ module Flipper
17
20
  end
18
21
 
19
22
  initializer "flipper.default", before: :load_config_initializers do |app|
23
+ require 'flipper/cloud' if cloud?
24
+
20
25
  Flipper.configure do |config|
21
26
  config.default do
22
- Flipper.new(config.adapter, instrumenter: app.config.flipper.instrumenter)
27
+ if cloud?
28
+ Flipper::Cloud.new(
29
+ local_adapter: config.adapter,
30
+ instrumenter: app.config.flipper.instrumenter
31
+ )
32
+ else
33
+ Flipper.new(config.adapter, instrumenter: app.config.flipper.instrumenter)
34
+ end
23
35
  end
24
36
  end
25
37
  end
@@ -43,5 +55,9 @@ module Flipper
43
55
  }
44
56
  end
45
57
  end
58
+
59
+ def cloud?
60
+ !!ENV["FLIPPER_CLOUD_TOKEN"]
61
+ end
46
62
  end
47
63
  end
@@ -1,5 +1,9 @@
1
1
  module Flipper
2
2
  METADATA = {
3
- 'changelog_uri' => 'https://github.com/jnunemaker/flipper/blob/main/Changelog.md',
3
+ "documentation_uri" => "https://www.flippercloud.io/docs",
4
+ "homepage_uri" => "https://www.flippercloud.io",
5
+ "source_code_uri" => "https://github.com/flippercloud/flipper",
6
+ "bug_tracker_uri" => "https://github.com/flippercloud/flipper/issues",
7
+ "changelog_uri" => "https://github.com/flippercloud/flipper/blob/main/Changelog.md",
4
8
  }.freeze
5
9
  end
@@ -58,7 +58,7 @@ module Flipper
58
58
 
59
59
  # Already memoizing. This instance does not need to do anything.
60
60
  if flipper.memoizing?
61
- warn "Flipper::Middleware::Memoizer appears to be running twice. Read how to resolve this at https://github.com/jnunemaker/flipper/pull/523"
61
+ warn "Flipper::Middleware::Memoizer appears to be running twice. Read how to resolve this at https://github.com/flippercloud/flipper/pull/523"
62
62
  return @app.call(env)
63
63
  end
64
64
 
@@ -46,12 +46,12 @@ RSpec.shared_examples_for 'a flipper adapter' do
46
46
  end
47
47
 
48
48
  it 'can enable, disable and get value for boolean gate' do
49
- expect(subject.enable(feature, boolean_gate, flipper.boolean)).to eq(true)
49
+ expect(subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
50
50
 
51
51
  result = subject.get(feature)
52
52
  expect(result[:boolean]).to eq('true')
53
53
 
54
- expect(subject.disable(feature, boolean_gate, flipper.boolean(false))).to eq(true)
54
+ expect(subject.disable(feature, boolean_gate, Flipper::Types::Boolean.new(false))).to eq(true)
55
55
 
56
56
  result = subject.get(feature)
57
57
  expect(result[:boolean]).to eq(nil)
@@ -59,13 +59,13 @@ RSpec.shared_examples_for 'a flipper adapter' do
59
59
 
60
60
  it 'fully disables all enabled things when boolean gate disabled' do
61
61
  actor22 = Flipper::Actor.new('22')
62
- expect(subject.enable(feature, boolean_gate, flipper.boolean)).to eq(true)
62
+ expect(subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
63
63
  expect(subject.enable(feature, group_gate, flipper.group(:admins))).to eq(true)
64
- expect(subject.enable(feature, actor_gate, flipper.actor(actor22))).to eq(true)
65
- expect(subject.enable(feature, actors_gate, flipper.actors(25))).to eq(true)
66
- expect(subject.enable(feature, time_gate, flipper.time(45))).to eq(true)
64
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor22))).to eq(true)
65
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(25))).to eq(true)
66
+ expect(subject.enable(feature, time_gate, Flipper::Types::PercentageOfTime.new(45))).to eq(true)
67
67
 
68
- expect(subject.disable(feature, boolean_gate, flipper.boolean(false))).to eq(true)
68
+ expect(subject.disable(feature, boolean_gate, Flipper::Types::Boolean.new(false))).to eq(true)
69
69
 
70
70
  expect(subject.get(feature)).to eq(subject.default_config)
71
71
  end
@@ -90,34 +90,34 @@ RSpec.shared_examples_for 'a flipper adapter' do
90
90
  actor22 = Flipper::Actor.new('22')
91
91
  actor_asdf = Flipper::Actor.new('asdf')
92
92
 
93
- expect(subject.enable(feature, actor_gate, flipper.actor(actor22))).to eq(true)
94
- expect(subject.enable(feature, actor_gate, flipper.actor(actor_asdf))).to eq(true)
93
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor22))).to eq(true)
94
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor_asdf))).to eq(true)
95
95
 
96
96
  result = subject.get(feature)
97
97
  expect(result[:actors]).to eq(Set['22', 'asdf'])
98
98
 
99
- expect(subject.disable(feature, actor_gate, flipper.actor(actor22))).to eq(true)
99
+ expect(subject.disable(feature, actor_gate, Flipper::Types::Actor.new(actor22))).to eq(true)
100
100
  result = subject.get(feature)
101
101
  expect(result[:actors]).to eq(Set['asdf'])
102
102
 
103
- expect(subject.disable(feature, actor_gate, flipper.actor(actor_asdf))).to eq(true)
103
+ expect(subject.disable(feature, actor_gate, Flipper::Types::Actor.new(actor_asdf))).to eq(true)
104
104
  result = subject.get(feature)
105
105
  expect(result[:actors]).to eq(Set.new)
106
106
  end
107
107
 
108
108
  it 'can enable, disable and get value for percentage of actors gate' do
109
- expect(subject.enable(feature, actors_gate, flipper.actors(15))).to eq(true)
109
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(15))).to eq(true)
110
110
  result = subject.get(feature)
111
111
  expect(result[:percentage_of_actors]).to eq('15')
112
112
 
113
- expect(subject.disable(feature, actors_gate, flipper.actors(0))).to eq(true)
113
+ expect(subject.disable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(0))).to eq(true)
114
114
  result = subject.get(feature)
115
115
  expect(result[:percentage_of_actors]).to eq('0')
116
116
  end
117
117
 
118
118
  it 'can enable percentage of actors gate many times and consistently return values' do
119
119
  (1..100).each do |percentage|
120
- expect(subject.enable(feature, actors_gate, flipper.actors(percentage))).to eq(true)
120
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(percentage))).to eq(true)
121
121
  result = subject.get(feature)
122
122
  expect(result[:percentage_of_actors]).to eq(percentage.to_s)
123
123
  end
@@ -125,25 +125,25 @@ RSpec.shared_examples_for 'a flipper adapter' do
125
125
 
126
126
  it 'can disable percentage of actors gate many times and consistently return values' do
127
127
  (1..100).each do |percentage|
128
- expect(subject.disable(feature, actors_gate, flipper.actors(percentage))).to eq(true)
128
+ expect(subject.disable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(percentage))).to eq(true)
129
129
  result = subject.get(feature)
130
130
  expect(result[:percentage_of_actors]).to eq(percentage.to_s)
131
131
  end
132
132
  end
133
133
 
134
134
  it 'can enable, disable and get value for percentage of time gate' do
135
- expect(subject.enable(feature, time_gate, flipper.time(10))).to eq(true)
135
+ expect(subject.enable(feature, time_gate, Flipper::Types::PercentageOfTime.new(10))).to eq(true)
136
136
  result = subject.get(feature)
137
137
  expect(result[:percentage_of_time]).to eq('10')
138
138
 
139
- expect(subject.disable(feature, time_gate, flipper.time(0))).to eq(true)
139
+ expect(subject.disable(feature, time_gate, Flipper::Types::PercentageOfTime.new(0))).to eq(true)
140
140
  result = subject.get(feature)
141
141
  expect(result[:percentage_of_time]).to eq('0')
142
142
  end
143
143
 
144
144
  it 'can enable percentage of time gate many times and consistently return values' do
145
145
  (1..100).each do |percentage|
146
- expect(subject.enable(feature, time_gate, flipper.time(percentage))).to eq(true)
146
+ expect(subject.enable(feature, time_gate, Flipper::Types::PercentageOfTime.new(percentage))).to eq(true)
147
147
  result = subject.get(feature)
148
148
  expect(result[:percentage_of_time]).to eq(percentage.to_s)
149
149
  end
@@ -151,20 +151,20 @@ RSpec.shared_examples_for 'a flipper adapter' do
151
151
 
152
152
  it 'can disable percentage of time gate many times and consistently return values' do
153
153
  (1..100).each do |percentage|
154
- expect(subject.disable(feature, time_gate, flipper.time(percentage))).to eq(true)
154
+ expect(subject.disable(feature, time_gate, Flipper::Types::PercentageOfTime.new(percentage))).to eq(true)
155
155
  result = subject.get(feature)
156
156
  expect(result[:percentage_of_time]).to eq(percentage.to_s)
157
157
  end
158
158
  end
159
159
 
160
160
  it 'converts boolean value to a string' do
161
- expect(subject.enable(feature, boolean_gate, flipper.boolean)).to eq(true)
161
+ expect(subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
162
162
  result = subject.get(feature)
163
163
  expect(result[:boolean]).to eq('true')
164
164
  end
165
165
 
166
166
  it 'converts the actor value to a string' do
167
- expect(subject.enable(feature, actor_gate, flipper.actor(Flipper::Actor.new(22)))).to eq(true)
167
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(Flipper::Actor.new(22)))).to eq(true)
168
168
  result = subject.get(feature)
169
169
  expect(result[:actors]).to eq(Set['22'])
170
170
  end
@@ -176,13 +176,13 @@ RSpec.shared_examples_for 'a flipper adapter' do
176
176
  end
177
177
 
178
178
  it 'converts percentage of time integer value to a string' do
179
- expect(subject.enable(feature, time_gate, flipper.time(10))).to eq(true)
179
+ expect(subject.enable(feature, time_gate, Flipper::Types::PercentageOfTime.new(10))).to eq(true)
180
180
  result = subject.get(feature)
181
181
  expect(result[:percentage_of_time]).to eq('10')
182
182
  end
183
183
 
184
184
  it 'converts percentage of actors integer value to a string' do
185
- expect(subject.enable(feature, actors_gate, flipper.actors(10))).to eq(true)
185
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(10))).to eq(true)
186
186
  result = subject.get(feature)
187
187
  expect(result[:percentage_of_actors]).to eq('10')
188
188
  end
@@ -205,11 +205,11 @@ RSpec.shared_examples_for 'a flipper adapter' do
205
205
 
206
206
  it 'clears all the gate values for the feature on remove' do
207
207
  actor22 = Flipper::Actor.new('22')
208
- expect(subject.enable(feature, boolean_gate, flipper.boolean)).to eq(true)
208
+ expect(subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
209
209
  expect(subject.enable(feature, group_gate, flipper.group(:admins))).to eq(true)
210
- expect(subject.enable(feature, actor_gate, flipper.actor(actor22))).to eq(true)
211
- expect(subject.enable(feature, actors_gate, flipper.actors(25))).to eq(true)
212
- expect(subject.enable(feature, time_gate, flipper.time(45))).to eq(true)
210
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor22))).to eq(true)
211
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(25))).to eq(true)
212
+ expect(subject.enable(feature, time_gate, Flipper::Types::PercentageOfTime.new(45))).to eq(true)
213
213
 
214
214
  expect(subject.remove(feature)).to eq(true)
215
215
 
@@ -221,11 +221,11 @@ RSpec.shared_examples_for 'a flipper adapter' do
221
221
  subject.add(feature)
222
222
  expect(subject.features).to include(feature.key)
223
223
 
224
- expect(subject.enable(feature, boolean_gate, flipper.boolean)).to eq(true)
224
+ expect(subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
225
225
  expect(subject.enable(feature, group_gate, flipper.group(:admins))).to eq(true)
226
- expect(subject.enable(feature, actor_gate, flipper.actor(actor22))).to eq(true)
227
- expect(subject.enable(feature, actors_gate, flipper.actors(25))).to eq(true)
228
- expect(subject.enable(feature, time_gate, flipper.time(45))).to eq(true)
226
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor22))).to eq(true)
227
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(25))).to eq(true)
228
+ expect(subject.enable(feature, time_gate, Flipper::Types::PercentageOfTime.new(45))).to eq(true)
229
229
 
230
230
  expect(subject.clear(feature)).to eq(true)
231
231
  expect(subject.features).to include(feature.key)
@@ -238,7 +238,7 @@ RSpec.shared_examples_for 'a flipper adapter' do
238
238
 
239
239
  it 'can get multiple features' do
240
240
  expect(subject.add(flipper[:stats])).to eq(true)
241
- expect(subject.enable(flipper[:stats], boolean_gate, flipper.boolean)).to eq(true)
241
+ expect(subject.enable(flipper[:stats], boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
242
242
  expect(subject.add(flipper[:search])).to eq(true)
243
243
 
244
244
  result = subject.get_multi([flipper[:stats], flipper[:search], flipper[:other]])
@@ -254,7 +254,7 @@ RSpec.shared_examples_for 'a flipper adapter' do
254
254
 
255
255
  it 'can get all features' do
256
256
  expect(subject.add(flipper[:stats])).to eq(true)
257
- expect(subject.enable(flipper[:stats], boolean_gate, flipper.boolean)).to eq(true)
257
+ expect(subject.enable(flipper[:stats], boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
258
258
  expect(subject.add(flipper[:search])).to eq(true)
259
259
 
260
260
  result = subject.get_all
@@ -277,8 +277,8 @@ RSpec.shared_examples_for 'a flipper adapter' do
277
277
 
278
278
  it 'can double enable an actor without error' do
279
279
  actor = Flipper::Actor.new('Flipper::Actor;22')
280
- expect(subject.enable(feature, actor_gate, flipper.actor(actor))).to eq(true)
281
- expect(subject.enable(feature, actor_gate, flipper.actor(actor))).to eq(true)
280
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor))).to eq(true)
281
+ expect(subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor))).to eq(true)
282
282
  expect(subject.get(feature).fetch(:actors)).to eq(Set['Flipper::Actor;22'])
283
283
  end
284
284
 
@@ -289,13 +289,13 @@ RSpec.shared_examples_for 'a flipper adapter' do
289
289
  end
290
290
 
291
291
  it 'can double enable percentage without error' do
292
- expect(subject.enable(feature, actors_gate, flipper.actors(25))).to eq(true)
293
- expect(subject.enable(feature, actors_gate, flipper.actors(25))).to eq(true)
292
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(25))).to eq(true)
293
+ expect(subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(25))).to eq(true)
294
294
  end
295
295
 
296
296
  it 'can double enable without error' do
297
- expect(subject.enable(feature, boolean_gate, flipper.boolean)).to eq(true)
298
- expect(subject.enable(feature, boolean_gate, flipper.boolean)).to eq(true)
297
+ expect(subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
298
+ expect(subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new)).to eq(true)
299
299
  end
300
300
 
301
301
  it 'can get_all features when there are none' do
@@ -305,11 +305,11 @@ RSpec.shared_examples_for 'a flipper adapter' do
305
305
 
306
306
  it 'clears other gate values on enable' do
307
307
  actor = Flipper::Actor.new('Flipper::Actor;22')
308
- subject.enable(feature, actors_gate, flipper.actors(25))
309
- subject.enable(feature, time_gate, flipper.time(25))
308
+ subject.enable(feature, actors_gate, Flipper::Types::PercentageOfActors.new(25))
309
+ subject.enable(feature, time_gate, Flipper::Types::PercentageOfTime.new(25))
310
310
  subject.enable(feature, group_gate, flipper.group(:admins))
311
- subject.enable(feature, actor_gate, flipper.actor(actor))
312
- subject.enable(feature, boolean_gate, flipper.boolean(true))
311
+ subject.enable(feature, actor_gate, Flipper::Types::Actor.new(actor))
312
+ subject.enable(feature, boolean_gate, Flipper::Types::Boolean.new(true))
313
313
  expect(subject.get(feature)).to eq(subject.default_config.merge(boolean: "true"))
314
314
  end
315
315
 
@@ -48,20 +48,20 @@ module Flipper
48
48
  end
49
49
 
50
50
  def test_can_enable_disable_and_get_value_for_boolean_gate
51
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean)
51
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new)
52
52
  assert_equal 'true', @adapter.get(@feature)[:boolean]
53
- assert_equal true, @adapter.disable(@feature, @boolean_gate, @flipper.boolean(false))
53
+ assert_equal true, @adapter.disable(@feature, @boolean_gate, Flipper::Types::Boolean.new(false))
54
54
  assert_nil @adapter.get(@feature)[:boolean]
55
55
  end
56
56
 
57
57
  def test_fully_disables_all_enabled_things_when_boolean_gate_disabled
58
58
  actor22 = Flipper::Actor.new('22')
59
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean)
59
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new)
60
60
  assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins))
61
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor22))
62
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25))
63
- assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(45))
64
- assert_equal true, @adapter.disable(@feature, @boolean_gate, @flipper.boolean(false))
61
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22))
62
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25))
63
+ assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(45))
64
+ assert_equal true, @adapter.disable(@feature, @boolean_gate, Flipper::Types::Boolean.new(false))
65
65
  assert_equal @adapter.default_config, @adapter.get(@feature)
66
66
  end
67
67
 
@@ -85,34 +85,34 @@ module Flipper
85
85
  actor22 = Flipper::Actor.new('22')
86
86
  actor_asdf = Flipper::Actor.new('asdf')
87
87
 
88
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor22))
89
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor_asdf))
88
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22))
89
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor_asdf))
90
90
 
91
91
  result = @adapter.get(@feature)
92
92
  assert_equal Set['22', 'asdf'], result[:actors]
93
93
 
94
- assert true, @adapter.disable(@feature, @actor_gate, @flipper.actor(actor22))
94
+ assert true, @adapter.disable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22))
95
95
  result = @adapter.get(@feature)
96
96
  assert_equal Set['asdf'], result[:actors]
97
97
 
98
- assert_equal true, @adapter.disable(@feature, @actor_gate, @flipper.actor(actor_asdf))
98
+ assert_equal true, @adapter.disable(@feature, @actor_gate, Flipper::Types::Actor.new(actor_asdf))
99
99
  result = @adapter.get(@feature)
100
100
  assert_equal Set.new, result[:actors]
101
101
  end
102
102
 
103
103
  def test_can_enable_disable_get_value_for_percentage_of_actors_gate
104
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(15))
104
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(15))
105
105
  result = @adapter.get(@feature)
106
106
  assert_equal '15', result[:percentage_of_actors]
107
107
 
108
- assert_equal true, @adapter.disable(@feature, @actors_gate, @flipper.actors(0))
108
+ assert_equal true, @adapter.disable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(0))
109
109
  result = @adapter.get(@feature)
110
110
  assert_equal '0', result[:percentage_of_actors]
111
111
  end
112
112
 
113
113
  def test_can_enable_percentage_of_actors_gate_many_times_and_consistently_return_values
114
114
  (1..100).each do |percentage|
115
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(percentage))
115
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(percentage))
116
116
  result = @adapter.get(@feature)
117
117
  assert_equal percentage.to_s, result[:percentage_of_actors]
118
118
  end
@@ -120,25 +120,25 @@ module Flipper
120
120
 
121
121
  def test_can_disable_percentage_of_actors_gate_many_times_and_consistently_return_values
122
122
  (1..100).each do |percentage|
123
- assert_equal true, @adapter.disable(@feature, @actors_gate, @flipper.actors(percentage))
123
+ assert_equal true, @adapter.disable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(percentage))
124
124
  result = @adapter.get(@feature)
125
125
  assert_equal percentage.to_s, result[:percentage_of_actors]
126
126
  end
127
127
  end
128
128
 
129
129
  def test_can_enable_disable_and_get_value_for_percentage_of_time_gate
130
- assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(10))
130
+ assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(10))
131
131
  result = @adapter.get(@feature)
132
132
  assert_equal '10', result[:percentage_of_time]
133
133
 
134
- assert_equal true, @adapter.disable(@feature, @time_gate, @flipper.time(0))
134
+ assert_equal true, @adapter.disable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(0))
135
135
  result = @adapter.get(@feature)
136
136
  assert_equal '0', result[:percentage_of_time]
137
137
  end
138
138
 
139
139
  def test_can_enable_percentage_of_time_gate_many_times_and_consistently_return_values
140
140
  (1..100).each do |percentage|
141
- assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(percentage))
141
+ assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(percentage))
142
142
  result = @adapter.get(@feature)
143
143
  assert_equal percentage.to_s, result[:percentage_of_time]
144
144
  end
@@ -146,21 +146,21 @@ module Flipper
146
146
 
147
147
  def test_can_disable_percentage_of_time_gate_many_times_and_consistently_return_values
148
148
  (1..100).each do |percentage|
149
- assert_equal true, @adapter.disable(@feature, @time_gate, @flipper.time(percentage))
149
+ assert_equal true, @adapter.disable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(percentage))
150
150
  result = @adapter.get(@feature)
151
151
  assert_equal percentage.to_s, result[:percentage_of_time]
152
152
  end
153
153
  end
154
154
 
155
155
  def test_converts_boolean_value_to_a_string
156
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean)
156
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new)
157
157
  result = @adapter.get(@feature)
158
158
  assert_equal 'true', result[:boolean]
159
159
  end
160
160
 
161
161
  def test_converts_the_actor_value_to_a_string
162
162
  assert_equal true,
163
- @adapter.enable(@feature, @actor_gate, @flipper.actor(Flipper::Actor.new(22)))
163
+ @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(Flipper::Actor.new(22)))
164
164
  result = @adapter.get(@feature)
165
165
  assert_equal Set['22'], result[:actors]
166
166
  end
@@ -172,13 +172,13 @@ module Flipper
172
172
  end
173
173
 
174
174
  def test_converts_percentage_of_time_integer_value_to_a_string
175
- assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(10))
175
+ assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(10))
176
176
  result = @adapter.get(@feature)
177
177
  assert_equal '10', result[:percentage_of_time]
178
178
  end
179
179
 
180
180
  def test_converts_percentage_of_actors_integer_value_to_a_string
181
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(10))
181
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(10))
182
182
  result = @adapter.get(@feature)
183
183
  assert_equal '10', result[:percentage_of_actors]
184
184
  end
@@ -201,11 +201,11 @@ module Flipper
201
201
 
202
202
  def test_clears_all_the_gate_values_for_the_feature_on_remove
203
203
  actor22 = Flipper::Actor.new('22')
204
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean)
204
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new)
205
205
  assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins))
206
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor22))
207
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25))
208
- assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(45))
206
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22))
207
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25))
208
+ assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(45))
209
209
 
210
210
  assert_equal true, @adapter.remove(@feature)
211
211
 
@@ -217,11 +217,11 @@ module Flipper
217
217
  @adapter.add(@feature)
218
218
  assert_includes @adapter.features, @feature.key
219
219
 
220
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean)
220
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new)
221
221
  assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins))
222
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor22))
223
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25))
224
- assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(45))
222
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor22))
223
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25))
224
+ assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(45))
225
225
 
226
226
  assert_equal true, @adapter.clear(@feature)
227
227
  assert_includes @adapter.features, @feature.key
@@ -234,7 +234,7 @@ module Flipper
234
234
 
235
235
  def test_can_get_multiple_features
236
236
  assert @adapter.add(@flipper[:stats])
237
- assert @adapter.enable(@flipper[:stats], @boolean_gate, @flipper.boolean)
237
+ assert @adapter.enable(@flipper[:stats], @boolean_gate, Flipper::Types::Boolean.new)
238
238
  assert @adapter.add(@flipper[:search])
239
239
 
240
240
  result = @adapter.get_multi([@flipper[:stats], @flipper[:search], @flipper[:other]])
@@ -250,7 +250,7 @@ module Flipper
250
250
 
251
251
  def test_can_get_all_features
252
252
  assert @adapter.add(@flipper[:stats])
253
- assert @adapter.enable(@flipper[:stats], @boolean_gate, @flipper.boolean)
253
+ assert @adapter.enable(@flipper[:stats], @boolean_gate, Flipper::Types::Boolean.new)
254
254
  assert @adapter.add(@flipper[:search])
255
255
 
256
256
  result = @adapter.get_all
@@ -273,8 +273,8 @@ module Flipper
273
273
 
274
274
  def test_can_double_enable_an_actor_without_error
275
275
  actor = Flipper::Actor.new('Flipper::Actor;22')
276
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor))
277
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor))
276
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor))
277
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor))
278
278
  assert_equal Set['Flipper::Actor;22'], @adapter.get(@feature).fetch(:actors)
279
279
  end
280
280
 
@@ -285,13 +285,13 @@ module Flipper
285
285
  end
286
286
 
287
287
  def test_can_double_enable_percentage_without_error
288
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25))
289
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25))
288
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25))
289
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25))
290
290
  end
291
291
 
292
292
  def test_can_double_enable_without_error
293
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean)
294
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean)
293
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new)
294
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new)
295
295
  end
296
296
 
297
297
  def test_can_get_all_features_when_there_are_none
@@ -302,11 +302,11 @@ module Flipper
302
302
 
303
303
  def test_clears_other_gate_values_on_enable
304
304
  actor = Flipper::Actor.new('Flipper::Actor;22')
305
- assert_equal true, @adapter.enable(@feature, @actors_gate, @flipper.actors(25))
306
- assert_equal true, @adapter.enable(@feature, @time_gate, @flipper.time(25))
305
+ assert_equal true, @adapter.enable(@feature, @actors_gate, Flipper::Types::PercentageOfActors.new(25))
306
+ assert_equal true, @adapter.enable(@feature, @time_gate, Flipper::Types::PercentageOfTime.new(25))
307
307
  assert_equal true, @adapter.enable(@feature, @group_gate, @flipper.group(:admins))
308
- assert_equal true, @adapter.enable(@feature, @actor_gate, @flipper.actor(actor))
309
- assert_equal true, @adapter.enable(@feature, @boolean_gate, @flipper.boolean(true))
308
+ assert_equal true, @adapter.enable(@feature, @actor_gate, Flipper::Types::Actor.new(actor))
309
+ assert_equal true, @adapter.enable(@feature, @boolean_gate, Flipper::Types::Boolean.new(true))
310
310
  assert_equal @adapter.default_config.merge(boolean: "true"), @adapter.get(@feature)
311
311
  end
312
312