From f4e0832e8b275829d94d454f468e6124fa37f6e2 Mon Sep 17 00:00:00 2001 From: Marcin Henryk Bartkowiak Date: Mon, 18 Feb 2019 11:54:16 +0100 Subject: [PATCH] Use patched path in Jira::Base#save --- lib/jira/base.rb | 2 +- spec/jira/base_spec.rb | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/jira/base.rb b/lib/jira/base.rb index 8cea4fa5..008d5e4e 100644 --- a/lib/jira/base.rb +++ b/lib/jira/base.rb @@ -356,7 +356,7 @@ def save!(attrs, path = nil) # # Accepts an attributes hash of the values to be saved. Will return false # if the request fails. - def save(attrs, path = url) + def save(attrs, path = nil) begin save_status = save!(attrs, path) rescue JIRA::HTTPError => exception diff --git a/spec/jira/base_spec.rb b/spec/jira/base_spec.rb index 4a0fd202..4876ca67 100644 --- a/spec/jira/base_spec.rb +++ b/spec/jira/base_spec.rb @@ -226,8 +226,10 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: subject { JIRA::Resource::Deadbeef.new(client) } - before(:each) do - expect(subject).to receive(:url).and_return('/foo/bar') + before(:each) do |example| + unless example.metadata[:skip_before] + expect(subject).to receive(:url).and_return('/foo/bar') + end end it 'POSTs a new record' do @@ -269,6 +271,14 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc: expect(subject.attrs['exception']['code']).to eq(401) expect(subject.attrs['exception']['message']).to eq('Unauthorized') end + + it 'creates request with patched path', :skip_before do + expect(subject).to receive(:url).and_return('foo/bar') + response = instance_double('Response', body: nil) + allow(subject).to receive(:new_record?) { false } + expect(client).to receive(:put).with('/foo/bar', '{"foo":"bar"}').and_return(response) + expect(subject.save('foo' => 'bar')).to be_truthy + end end describe 'save!' do