From fae372a2ff1bab23ecdcdb517c6661a46204d9c2 Mon Sep 17 00:00:00 2001 From: marc tobias Date: Fri, 20 Jul 2018 17:32:46 +0200 Subject: [PATCH 1/2] fix rubocop at 0.47, failures (rubocop renamed config values) for newer versions --- Gemfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Gemfile b/Gemfile index eb2d949..5167b8c 100644 --- a/Gemfile +++ b/Gemfile @@ -1,8 +1,8 @@ source 'https://rubygems.org' -# Specify your gem's dependencies in kontena-cli.gemspec +# Specify your gem's dependencies in kong.gemspec gemspec group :development, :test do gem "rspec" - gem "rubocop" + gem "rubocop", "0.47" end From 46b3fd7c9afaff36a536c920f9bb687fee5bcaf7 Mon Sep 17 00:00:00 2001 From: marc tobias Date: Fri, 20 Jul 2018 17:33:37 +0200 Subject: [PATCH 2/2] use application/json content type. Kong 0.14 doesnt seem to handle combining URL params and params from body --- lib/kong/base.rb | 10 +++++----- spec/kong/base_spec.rb | 16 ++++++++-------- spec/kong/plugin_spec.rb | 8 ++++---- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/lib/kong/base.rb b/lib/kong/base.rb index 5f89675..8fa661a 100644 --- a/lib/kong/base.rb +++ b/lib/kong/base.rb @@ -111,8 +111,8 @@ def save # Create resource def create - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } - response = client.post(@api_end_point, nil, attributes, headers) + headers = { 'Content-Type' => 'application/json' } + response = client.post(@api_end_point, attributes, nil, headers) init_attributes(response) self end @@ -121,15 +121,15 @@ def create # Data is sent to Kong in JSON format and HTTP PUT request is used def create_or_update headers = { 'Content-Type' => 'application/json' } - response = client.put("#{@api_end_point}", attributes, nil, headers) + response = client.put(@api_end_point, attributes, nil, headers) init_attributes(response) self end # Update resource def update - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } - response = client.patch("#{@api_end_point}#{self.id}", nil, attributes, headers) + headers = { 'Content-Type' => 'application/json' } + response = client.patch("#{@api_end_point}#{self.id}", attributes, nil, headers) init_attributes(response) self end diff --git a/spec/kong/base_spec.rb b/spec/kong/base_spec.rb index b55abc4..5e72f02 100644 --- a/spec/kong/base_spec.rb +++ b/spec/kong/base_spec.rb @@ -94,18 +94,18 @@ describe '#create' do it 'creates POST /:resource_end_point/ request with resource attributes' do - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + headers = { 'Content-Type' => 'application/json' } attributes = { 'name' => 'test object' } - expect(Kong::Client.instance).to receive(:post).with('/resources/', nil, attributes, headers) + expect(Kong::Client.instance).to receive(:post).with('/resources/', attributes, nil, headers) .and_return(attributes) subject.name = 'test object' subject.create end it 'returns resource instance' do - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + headers = { 'Content-Type' => 'application/json' } attributes = { 'name' => 'test object' } - allow(Kong::Client.instance).to receive(:post).with('/resources/', nil, attributes, headers) + allow(Kong::Client.instance).to receive(:post).with('/resources/', attributes, nil, headers) .and_return(attributes.merge({ 'id' => '12345' })) subject.name = 'test object' expect(subject.create).to eq(subject) @@ -134,19 +134,19 @@ describe '#update' do it 'creates PATCH /:resource_end_point/:resource_id request with resource attributes' do - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + headers = { 'Content-Type' => 'application/json' } subject.id = '12345' subject.name = 'test object' - expect(Kong::Client.instance).to receive(:patch).with('/resources/12345', nil, subject.attributes, headers) + expect(Kong::Client.instance).to receive(:patch).with('/resources/12345', subject.attributes, nil, headers) .and_return(subject.attributes) subject.update end it 'returns resource instance' do - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + headers = { 'Content-Type' => 'application/json' } subject.id = '12345' subject.name = 'test object' - allow(Kong::Client.instance).to receive(:patch).with('/resources/12345', nil, subject.attributes, headers) + allow(Kong::Client.instance).to receive(:patch).with('/resources/12345', subject.attributes, nil, headers) .and_return(subject.attributes) expect(subject.update).to eq(subject) end diff --git a/spec/kong/plugin_spec.rb b/spec/kong/plugin_spec.rb index fe1d268..adbaad4 100644 --- a/spec/kong/plugin_spec.rb +++ b/spec/kong/plugin_spec.rb @@ -26,9 +26,9 @@ describe '#create' do it 'transforms config keys to config.key format' do - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + headers = { 'Content-Type' => 'application/json' } attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' } - expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/', nil, attributes, headers).and_return(attributes) + expect(Kong::Client.instance).to receive(:post).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes) subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } }) subject.create end @@ -36,9 +36,9 @@ describe '#update' do it 'transforms config keys to config.key format' do - headers = { 'Content-Type' => 'application/x-www-form-urlencoded' } + headers = { 'Content-Type' => 'application/json' } attributes = { 'api_id' => ':api_id', 'config.anonymous' => '12345' } - expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/', nil, attributes, headers).and_return(attributes) + expect(Kong::Client.instance).to receive(:patch).with('/apis/:api_id/plugins/', attributes, nil, headers).and_return(attributes) subject = described_class.new({ api_id: ':api_id', config: { 'anonymous' => '12345' } }) subject.update end