Skip to content

Commit

Permalink
Merge pull request #455 from bobbrodie/rubocop-updates
Browse files Browse the repository at this point in the history
Rubocop updates
  • Loading branch information
bobbrodie authored Oct 16, 2024
2 parents 960e265 + e6f944d commit afef22a
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 40 deletions.
18 changes: 0 additions & 18 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,6 @@ Style/FrozenStringLiteralComment:
#
# We are going to disable these and fix in pull requests
##
Layout/ClosingHeredocIndentation:
Enabled: false

Layout/EmptyLineAfterGuardClause:
Enabled: false

Layout/EmptyLinesAroundMethodBody:
Enabled: false

Layout/HashAlignment:
Enabled: false

Expand Down Expand Up @@ -148,9 +139,6 @@ RSpec/RepeatedSubjectCall:
RSpec/SpecFilePathFormat:
Enabled: false

RSpec/SpecFilePathSuffix:
Enabled: false

RSpec/StubbedMock:
Enabled: false

Expand All @@ -163,9 +151,6 @@ RSpec/VerifiedDoubleReference:
RSpec/VerifiedDoubles:
Enabled: false

Security/Open:
Enabled: false

Style/ArgumentsForwarding:
Enabled: false

Expand All @@ -180,6 +165,3 @@ Style/MissingRespondToMissing:

Style/OptionalBooleanParameter:
Enabled: false

Style/SymbolProc:
Enabled: false
2 changes: 1 addition & 1 deletion lib/jira/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ def save(attrs, path = url)
# not nil or is not a json response.
def set_attrs_from_response(response)
return if response.body.nil? || (response.body.length < 2)

json = self.class.parse_json(response.body)
set_attrs(json)

end

# Set the current attributes from a hash. If clobber is true, any existing
Expand Down
2 changes: 1 addition & 1 deletion lib/jira/http_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ def request_path(url)
def store_cookies(response)
cookies = response.get_fields('set-cookie')
return unless cookies

cookies.each do |cookie|
data = CGI::Cookie.parse(cookie)
data.delete('Path')
@cookies.merge!(data)
end

end

def add_cookies(request)
Expand Down
6 changes: 5 additions & 1 deletion lib/jira/resource/webhook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@ def self.full_url(client)
client.options[:context_path] + REST_BASE_PATH
end

def self.singular_path(client, key, prefix = '/')
"#{full_url(client)}#{prefix}/#{endpoint_name}/#{key}"
end

def self.collection_path(client, prefix = '/')
full_url(client) + prefix + endpoint_name
"#{full_url(client)}#{prefix}/#{endpoint_name}"
end

def self.all(client, options = {})
Expand Down
File renamed without changes.
30 changes: 15 additions & 15 deletions spec/jira/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
end

it 'finds a deadbeef by id' do
response = instance_double('Response', body: '{"self":"http://deadbeef/","id":"98765"}')
response = instance_double(Response, body: '{"self":"http://deadbeef/","id":"98765"}')
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765').and_return(response)
expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
deadbeef = JIRA::Resource::Deadbeef.find(client, '98765')
Expand All @@ -85,7 +85,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:

it 'finds a deadbeef containing changelog by id' do
response = instance_double(
'Response',
Response,
body: '{"self":"http://deadbeef/","id":"98765","changelog":{"histories":[]}}'
)
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765?expand=changelog').and_return(response)
Expand Down Expand Up @@ -172,7 +172,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:

describe 'not cached' do
before do
response = instance_double('Response', body: '{"self":"http://deadbeef/","id":"98765"}')
response = instance_double(Response, body: '{"self":"http://deadbeef/","id":"98765"}')
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765').and_return(response)
expect(JIRA::Resource::Deadbeef).to receive(:collection_path).and_return('/jira/rest/api/2/deadbeef')
end
Expand Down Expand Up @@ -207,7 +207,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
context "with expand parameter 'changelog'" do
it "fetchs changelogs '" do
response = instance_double(
'Response',
Response,
body: '{"self":"http://deadbeef/","id":"98765","changelog":{"histories":[]}}'
)
expect(client).to receive(:get).with('/jira/rest/api/2/deadbeef/98765?expand=changelog').and_return(response)
Expand All @@ -233,7 +233,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
end

it 'POSTs a new record' do
response = instance_double('Response', body: '{"id":"123"}')
response = instance_double(Response, body: '{"id":"123"}')
allow(subject).to receive(:new_record?).and_return(true)
expect(client).to receive(:post).with('/foo/bar', '{"foo":"bar"}').and_return(response)
expect(subject.save('foo' => 'bar')).to be_truthy
Expand All @@ -242,15 +242,15 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
end

it 'PUTs an existing record' do
response = instance_double('Response', body: nil)
response = instance_double(Response, body: nil)
allow(subject).to receive(:new_record?).and_return(false)
expect(client).to receive(:put).with('/foo/bar', '{"foo":"bar"}').and_return(response)
expect(subject.save('foo' => 'bar')).to be_truthy
expect(subject.expanded).to be_falsey
end

it 'merges attrs on save' do
response = instance_double('Response', body: nil)
response = instance_double(Response, body: nil)
expect(client).to receive(:post).with('/foo/bar', '{"foo":{"fum":"dum"}}').and_return(response)
subject.attrs = { 'foo' => { 'bar' => 'baz' } }
subject.save('foo' => { 'fum' => 'dum' })
Expand All @@ -259,7 +259,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:

it 'returns false when an invalid field is set' do
# The JIRA REST API apparently ignores fields that you aren't allowed to set manually
response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400)
response = instance_double(Response, body: '{"errorMessages":["blah"]}', status: 400)
allow(subject).to receive(:new_record?).and_return(false)
expect(client).to receive(:put).with('/foo/bar',
'{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response))
Expand All @@ -268,7 +268,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:

it 'returns false with exception details when non json response body (unauthorized)' do
# Unauthorized requests return a non-json body. This makes sure we can handle non-json bodies on HTTPError
response = double('Response', body: 'totally invalid json', code: 401, message: 'Unauthorized')
response = double(Response, body: 'totally invalid json', code: 401, message: 'Unauthorized')
expect(client).to receive(:post).with('/foo/bar', '{"foo":"bar"}').and_raise(JIRA::HTTPError.new(response))
expect(subject.save('foo' => 'bar')).to be_falsey
expect(subject.attrs['exception']['code']).to eq(401)
Expand All @@ -286,7 +286,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
end

it 'POSTs a new record' do
response = instance_double('Response', body: '{"id":"123"}')
response = instance_double(Response, body: '{"id":"123"}')
allow(subject).to receive(:new_record?).and_return(true)
expect(client).to receive(:post).with('/foo/bar', '{"foo":"bar"}').and_return(response)
expect(subject.save!('foo' => 'bar')).to be_truthy
Expand All @@ -295,15 +295,15 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
end

it 'PUTs an existing record' do
response = instance_double('Response', body: nil)
response = instance_double(Response, body: nil)
allow(subject).to receive(:new_record?).and_return(false)
expect(client).to receive(:put).with('/foo/bar', '{"foo":"bar"}').and_return(response)
expect(subject.save!('foo' => 'bar')).to be_truthy
expect(subject.expanded).to be_falsey
end

it 'throws an exception when an invalid field is set' do
response = instance_double('Response', body: '{"errorMessages":["blah"]}', status: 400)
response = instance_double(Response, body: '{"errorMessages":["blah"]}', status: 400)
allow(subject).to receive(:new_record?).and_return(false)
expect(client).to receive(:put).with('/foo/bar',
'{"invalid_field":"foobar"}').and_raise(JIRA::HTTPError.new(response))
Expand Down Expand Up @@ -441,14 +441,14 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
subject { JIRA::Resource::Deadbeef.new(client, attrs: {}) }

it 'sets the attrs from a response' do
response = instance_double('Response', body: '{"foo":"bar"}')
response = instance_double(Response, body: '{"foo":"bar"}')

expect(subject.set_attrs_from_response(response)).to eq('foo' => 'bar')
expect(subject.foo).to eq('bar')
end

it "doesn't clobber existing attrs not in response" do
response = instance_double('Response', body: '{"foo":"bar"}')
response = instance_double(Response, body: '{"foo":"bar"}')

subject.attrs = { 'flum' => 'flar' }
expect(subject.set_attrs_from_response(response)).to eq('foo' => 'bar')
Expand All @@ -457,7 +457,7 @@ class JIRA::Resource::HasManyExample < JIRA::Base # :nodoc:
end

it 'handles nil response body' do
response = instance_double('Response', body: nil)
response = instance_double(Response, body: nil)

subject.attrs = { 'flum' => 'flar' }
expect(subject.set_attrs_from_response(response)).to be_nil
Expand Down
4 changes: 2 additions & 2 deletions spec/jira/resource/board_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
}
]
}
EOS
EOS
allow(response).to receive(:body).and_return(api_json)
allow(board).to receive(:id).and_return(84)
expect(client).to receive(:get).with('/rest/agile/1.0/board/84/sprint?').and_return(response)
Expand Down Expand Up @@ -215,7 +215,7 @@ class JIRAResourceDelegation < SimpleDelegator # :nodoc:
"rankCustomFieldId":10011
}
}
EOS
EOS
allow(response).to receive(:body).and_return(api_json)
allow(board).to receive(:id).and_return(84)
expect(client).to receive(:get).with('/rest/agile/1.0/board/84/configuration').and_return(response)
Expand Down
4 changes: 2 additions & 2 deletions spec/jira/resource/user_factory_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
subject { described_class.new(client) }

let(:client) do
instance_double('Client', options: { rest_base_path: '/jira/rest/api/2' })
instance_double(Client, options: { rest_base_path: '/jira/rest/api/2' })
end

describe '#myself' do
let(:response) do
instance_double(
'Response', body: get_mock_response('user_accountId=1234567890abcdef01234567.json')
Response, body: get_mock_response('user_accountId=1234567890abcdef01234567.json')
)
end

Expand Down
9 changes: 9 additions & 0 deletions spec/support/mock_client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Client
attr_reader :options

def initialize(options = {})
@options = options
end

def get(url) end
end
8 changes: 8 additions & 0 deletions spec/support/mock_response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class Response
attr_reader :body, :status

def initialize(body, status = nil)
@body = body
@status = status
end
end

0 comments on commit afef22a

Please sign in to comment.