Skip to content

Commit

Permalink
Merge pull request #781 from flippercloud/simplify-http-adapter
Browse files Browse the repository at this point in the history
simplify http adapter
  • Loading branch information
jnunemaker authored Dec 6, 2023
2 parents ed08bbb + 6ccf408 commit a268fe6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/flipper/adapters/http/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def build_request(http_method, uri, headers, options)
end

def client_frameworks
CLIENT_FRAMEWORKS.transform_values { |detect| detect.call rescue nil }.select { |_, version| version }
CLIENT_FRAMEWORKS.transform_values { |detect| detect.call rescue nil }.compact
end
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/flipper/adapters/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
}
stub_request(:get, "http://app.com/flipper/features/feature_panel")
.with(headers: headers)
.to_return(status: 404, body: "", headers: {})
.to_return(status: 404)

adapter = described_class.new(url: 'http://app.com/flipper')
adapter.get(flipper[:feature_panel])
end

it "sends framework versions" do
stub_const("Rails", Struct.new(:version).new("7.1.0"))
stub_const("Rails", double(version: "7.1.0"))
stub_const("Sinatra::VERSION", "3.1.0")
stub_const("Hanami::VERSION", "0.7.2")

Expand All @@ -101,14 +101,14 @@

stub_request(:get, "http://app.com/flipper/features/feature_panel")
.with(headers: headers)
.to_return(status: 404, body: "", headers: {})
.to_return(status: 404)

adapter = described_class.new(url: 'http://app.com/flipper')
adapter.get(flipper[:feature_panel])
end

it "does not send undefined framework versions" do
stub_const("Rails", Struct.new(:version).new("7.1.0"))
stub_const("Rails", double(version: "7.1.0"))
stub_const("Sinatra::VERSION", "3.1.0")

headers = {
Expand All @@ -117,7 +117,7 @@

stub_request(:get, "http://app.com/flipper/features/feature_panel")
.with(headers: headers)
.to_return(status: 404, body: "", headers: {})
.to_return(status: 404)

adapter = described_class.new(url: 'http://app.com/flipper')
adapter.get(flipper[:feature_panel])
Expand All @@ -127,7 +127,7 @@
describe "#get" do
it "raises error when not successful response" do
stub_request(:get, "http://app.com/flipper/features/feature_panel")
.to_return(status: 503, body: "", headers: {})
.to_return(status: 503)

adapter = described_class.new(url: 'http://app.com/flipper')
expect {
Expand All @@ -139,7 +139,7 @@
describe "#get_multi" do
it "raises error when not successful response" do
stub_request(:get, "http://app.com/flipper/features?keys=feature_panel&exclude_gate_names=true")
.to_return(status: 503, body: "", headers: {})
.to_return(status: 503)

adapter = described_class.new(url: 'http://app.com/flipper')
expect {
Expand All @@ -151,7 +151,7 @@
describe "#get_all" do
it "raises error when not successful response" do
stub_request(:get, "http://app.com/flipper/features?exclude_gate_names=true")
.to_return(status: 503, body: "", headers: {})
.to_return(status: 503)

adapter = described_class.new(url: 'http://app.com/flipper')
expect {
Expand All @@ -163,7 +163,7 @@
describe "#features" do
it "raises error when not successful response" do
stub_request(:get, "http://app.com/flipper/features?exclude_gate_names=true")
.to_return(status: 503, body: "", headers: {})
.to_return(status: 503)

adapter = described_class.new(url: 'http://app.com/flipper')
expect {
Expand Down

0 comments on commit a268fe6

Please sign in to comment.