flipper-api 0.21.0 → 0.23.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e44a0aba5ffc0b448f66a49335a97100d0d7aa25f69823d65df4a2742ef63171
4
- data.tar.gz: 274e4eb1ba9885b67e7e9dbba8ee8015159d213dc613888e053e6c404b713237
3
+ metadata.gz: c88c8fcf2cad7d28ac9a1c968cb4afa798006f34aef33ee0fbf4c47da64275e8
4
+ data.tar.gz: 5395ef9526ad46564c569d2fdc0f0f58376f5a4956fdb2929c9454b6e3e4d26e
5
5
  SHA512:
6
- metadata.gz: f20d11dc71866738074a3b6465c4082314a4caaf85cced364dba3210cd5ae4d62805ed3f0596a189dbfd41b357b96ed0f3e159527fde2c7618bc2b3825cbcbc3
7
- data.tar.gz: 5c0d32e915b77887ce01e783a84151de21e15ad339b6c27778cc985a6d87a5c4573e05573a40495a553b08ab79062b2a77714edc9ffe5eaba4e0491409241a98
6
+ metadata.gz: d5eb1d1990347809c8383465585ba4926bb622c600870bd382bab3341028202e372311f63fd39f18b506172913e5b3ca7a93f456bfe9438e001da67efe9c5f36
7
+ data.tar.gz: 31316d4c9e04cf706ace8290733102c313053e571c497a4eac5a9bddbb32367dc60ca9a75d6e25245604ce6b7c983b84c9e00bc1fda9219031b1749b7e2561c8
@@ -8,7 +8,7 @@ module Flipper
8
8
  @code = code
9
9
  @message = message
10
10
  @more_info =
11
- 'https://github.com/jnunemaker/flipper/tree/master/docs/api#error-code-reference'
11
+ 'https://flippercloud.io/docs/api#error-code-reference'
12
12
  @http_status = http_status
13
13
  end
14
14
 
@@ -32,10 +32,11 @@ module Flipper
32
32
  def call!(env)
33
33
  request = Rack::Request.new(env)
34
34
  action_class = @action_collection.action_for_request(request)
35
+
35
36
  if action_class.nil?
36
37
  @app.call(env)
37
38
  else
38
- flipper = env.fetch(@env_key)
39
+ flipper = env.fetch(@env_key) { Flipper }
39
40
  action_class.run(flipper, request)
40
41
  end
41
42
  end
data/lib/flipper/api.rb CHANGED
@@ -9,14 +9,11 @@ module Flipper
9
9
 
10
10
  def self.app(flipper = nil, options = {})
11
11
  env_key = options.fetch(:env_key, 'flipper')
12
- memoizer_options = options.fetch(:memoizer_options, {})
13
-
14
12
  app = ->(_) { [404, { 'Content-Type'.freeze => CONTENT_TYPE }, ['{}'.freeze]] }
15
13
  builder = Rack::Builder.new
16
14
  yield builder if block_given?
17
15
  builder.use Flipper::Api::JsonParams
18
16
  builder.use Flipper::Middleware::SetupEnv, flipper, env_key: env_key
19
- builder.use Flipper::Middleware::Memoizer, memoizer_options.merge(env_key: env_key)
20
17
  builder.use Flipper::Api::Middleware, env_key: env_key
21
18
  builder.run app
22
19
  klass = self
@@ -1,3 +1,3 @@
1
1
  module Flipper
2
- VERSION = '0.21.0'.freeze
2
+ VERSION = '0.23.0'.freeze
3
3
  end
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::Action do
4
2
  let(:action_subclass) do
5
3
  Class.new(described_class) do
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::JsonParams do
4
2
  let(:app) do
5
3
  app = lambda do |env|
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::ActorsGate do
4
2
  let(:app) { build_api(flipper) }
5
3
  let(:actor) { Flipper::Actor.new('1') }
@@ -44,7 +42,7 @@ RSpec.describe Flipper::Api::V1::Actions::ActorsGate do
44
42
 
45
43
  describe 'enable feature with slash in name' do
46
44
  before do
47
- flipper[:my_feature].disable_actor(actor)
45
+ flipper["my/feature"].disable_actor(actor)
48
46
  post '/features/my/feature/actors', flipper_id: actor.flipper_id
49
47
  end
50
48
 
@@ -60,6 +58,24 @@ RSpec.describe Flipper::Api::V1::Actions::ActorsGate do
60
58
  end
61
59
  end
62
60
 
61
+ describe 'enable feature with space in name' do
62
+ before do
63
+ flipper["sp ace"].disable_actor(actor)
64
+ post '/features/sp%20ace/actors', flipper_id: actor.flipper_id
65
+ end
66
+
67
+ it 'enables feature for actor' do
68
+ expect(last_response.status).to eq(200)
69
+ expect(flipper["sp ace"].enabled?(actor)).to be_truthy
70
+ expect(flipper["sp ace"].enabled_gate_names).to eq([:actor])
71
+ end
72
+
73
+ it 'returns decorated feature with actor enabled' do
74
+ gate = json_response['gates'].find { |gate| gate['key'] == 'actors' }
75
+ expect(gate['value']).to eq(['1'])
76
+ end
77
+ end
78
+
63
79
  describe 'enable missing flipper_id parameter' do
64
80
  before do
65
81
  flipper[:my_feature].enable
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::Actors do
4
2
  let(:app) { build_api(flipper) }
5
3
  let(:actor) { Flipper::Actor.new('User123') }
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::BooleanGate do
4
2
  let(:app) { build_api(flipper) }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::ClearFeature do
4
2
  let(:app) { build_api(flipper) }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::Feature do
4
2
  let(:app) { build_api(flipper) }
5
3
  let(:feature) { build_feature }
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::Features do
4
2
  let(:app) { build_api(flipper) }
5
3
  let(:feature) { build_feature }
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::GroupsGate do
4
2
  let(:app) { build_api(flipper) }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::PercentageOfActorsGate do
4
2
  let(:app) { build_api(flipper) }
5
3
 
@@ -1,5 +1,3 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api::V1::Actions::PercentageOfTimeGate do
4
2
  let(:app) { build_api(flipper) }
5
3
 
@@ -1,6 +1,34 @@
1
- require 'helper'
2
-
3
1
  RSpec.describe Flipper::Api do
2
+ describe 'Initializing middleware with flipper instance' do
3
+ let(:app) { build_api(flipper) }
4
+
5
+ it 'works' do
6
+ flipper.enable :a
7
+ flipper.disable :b
8
+
9
+ get '/features'
10
+
11
+ expect(last_response.status).to be(200)
12
+ feature_names = json_response.fetch('features').map { |feature| feature.fetch('key') }
13
+ expect(feature_names).to eq(%w(a b))
14
+ end
15
+ end
16
+
17
+ describe 'Initializing middleware lazily with a block' do
18
+ let(:app) { build_api(-> { flipper }) }
19
+
20
+ it 'works' do
21
+ flipper.enable :a
22
+ flipper.disable :b
23
+
24
+ get '/features'
25
+
26
+ expect(last_response.status).to be(200)
27
+ feature_names = json_response.fetch('features').map { |feature| feature.fetch('key') }
28
+ expect(feature_names).to eq(%w(a b))
29
+ end
30
+ end
31
+
4
32
  context 'when initialized with flipper instance and flipper instance in env' do
5
33
  let(:app) { build_api(flipper) }
6
34
 
@@ -76,4 +104,10 @@ RSpec.describe Flipper::Api do
76
104
  expect(json_response).to eq({})
77
105
  end
78
106
  end
107
+
108
+ describe 'Inspecting the built Rack app' do
109
+ it 'returns a String' do
110
+ expect(build_api(flipper).inspect).to be_a(String)
111
+ end
112
+ end
79
113
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flipper-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.21.0
4
+ version: 0.23.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-05-09 00:00:00.000000000 Z
11
+ date: 2021-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 0.21.0
39
+ version: 0.23.0
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: 0.21.0
46
+ version: 0.23.0
47
47
  description:
48
48
  email:
49
49
  - nunemaker@gmail.com
@@ -105,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
105
105
  - !ruby/object:Gem::Version
106
106
  version: '0'
107
107
  requirements: []
108
- rubygems_version: 3.0.3
108
+ rubygems_version: 3.1.2
109
109
  signing_key:
110
110
  specification_version: 4
111
111
  summary: API for the Flipper gem