Skip to content

Commit

Permalink
lint: Layout/LineLength RuboCop
Browse files Browse the repository at this point in the history
Mostly manual adjustment rather than autocorrect function due to
inconsistency in autocorrect
  • Loading branch information
alexander-griffen committed Jun 23, 2023
1 parent a9d7d0f commit 964d9c1
Show file tree
Hide file tree
Showing 10 changed files with 301 additions and 123 deletions.
120 changes: 93 additions & 27 deletions spec/controllers/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
@number_of_requests = InfoRequest.count
@request_data = {
'title' => 'Tell me about your chickens',
'body' => "Dear Sir,\n\nI should like to know about your chickens.\n\nYours in faith,\nBob\n",
'body' => "Dear Sir,\n\n" \
"I should like to know about your chickens.\n\n" \
"Yours in faith,\nBob\n",
'external_url' => 'http://www.example.gov.uk/foi/chickens_23',
'external_user_name' => 'Bob Smith'
}
Expand Down Expand Up @@ -57,7 +59,9 @@ def _create_request

request_data = {
'title' => 'Tell me about your chickens',
'body' => "Dear Sir,\n\nI should like to know about your chickens.\n\nYours in faith,\nBob\n",
'body' => "Dear Sir,\n\n" \
"I should like to know about your chickens.\n\n" \
"Yours in faith,\nBob\n",
'external_url' => 'http://www.example.gov.uk/foi/chickens_23',
'external_user_name' => 'Bob Smith'
}
Expand All @@ -82,16 +86,24 @@ def _create_request

new_request = InfoRequest.find(response_body['id'])
expect(new_request.user_id).to be_nil
expect(new_request.external_user_name).to eq(request_data['external_user_name'])
expect(
new_request.external_user_name
).to eq(request_data['external_user_name'])
expect(new_request.external_url).to eq(request_data['external_url'])

expect(new_request.title).to eq(request_data['title'])
expect(new_request.last_event_forming_initial_request.outgoing_message.body).to eq(request_data['body'].strip)
expect(
new_request.last_event_forming_initial_request.outgoing_message.body
).to eq(request_data['body'].strip)

expect(new_request.public_body_id).to eq(public_bodies(:geraldine_public_body).id)
expect(
new_request.public_body_id
).to eq(public_bodies(:geraldine_public_body).id)
expect(new_request.info_request_events.size).to eq(1)
expect(new_request.info_request_events[0].event_type).to eq('sent')
expect(new_request.info_request_events[0].calculated_state).to eq('waiting_response')
expect(
new_request.info_request_events[0].calculated_state
).to eq('waiting_response')
end
end

Expand All @@ -108,7 +120,11 @@ def _create_request

# Now add one
sent_at = '2012-05-28T12:35:39+01:00'
response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
response_body = "Thank you for your request for information, which we " \
"are handling in accordance with the Freedom of Information Act " \
"2000. You will receive a response within 20 working days or before " \
"the next full moon, whichever is sooner.\n\nYours sincerely," \
"\nJohn Gandermulch,\nExample Council FOI Officer\n"
post :add_correspondence,
params: {
k: public_bodies(:geraldine_public_body).api_key,
Expand All @@ -128,7 +144,9 @@ def _create_request
incoming_message = incoming_messages[0]

expect(incoming_message.sent_at).to eq(Time.iso8601(sent_at))
expect(incoming_message.get_main_body_text_folded).to be_equal_modulo_whitespace_to(response_body)
expect(
incoming_message.get_main_body_text_folded
).to be_equal_modulo_whitespace_to(response_body)
end

it 'should add a followup to a request' do
Expand Down Expand Up @@ -178,7 +196,11 @@ def _create_request

# Now add one
sent_at = '2012-05-28T12:35:39+01:00'
response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
response_body = "Thank you for your request for information, which we" \
" are handling in accordance with the Freedom of Information Act " \
"2000. You will receive a response within 20 working days or before " \
"the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \
"Gandermulch,\nExample Council FOI Officer\n"
post :add_correspondence,
params: {
k: public_bodies(:geraldine_public_body).api_key,
Expand Down Expand Up @@ -212,7 +234,11 @@ def _create_request

# Now add one
sent_at = '2012-05-28T12:35:39+01:00'
response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
response_body = "Thank you for your request for information, which we " \
"are handling in accordance with the Freedom of Information Act " \
"2000. You will receive a response within 20 working days or before " \
"the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \
"Gandermulch,\nExample Council FOI Officer\n"
post :add_correspondence,
params: {
k: public_bodies(:geraldine_public_body).api_key,
Expand Down Expand Up @@ -290,9 +316,16 @@ def _create_request

it 'should return a JSON 404 error for non-existent requests' do
request_id = '123459876'
allow(InfoRequest).to receive(:find_by_id).with(request_id).and_return(nil)
allow(InfoRequest).
to receive(:find_by_id).
with(request_id).
and_return(nil)
sent_at = '2012-05-28T12:35:39+01:00'
response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
response_body = "Thank you for your request for information, which we " \
"are handling in accordance with the Freedom of Information Act " \
"2000. You will receive a response within 20 working days or before " \
"the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \
"Gandermulch,\nExample Council FOI Officer\n"
post :add_correspondence,
params: {
k: public_bodies(:geraldine_public_body).api_key,
Expand All @@ -304,13 +337,19 @@ def _create_request
}.to_json
}
expect(response.status).to eq(404)
expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(['Could not find request 123459876'])
expect(
ActiveSupport::JSON.decode(response.body)['errors']
).to eq(['Could not find request 123459876'])
end

it 'should return a JSON 403 error if we try to add correspondence to a request we don\'t own' do
request_id = info_requests(:naughty_chicken_request).id
sent_at = '2012-05-28T12:35:39+01:00'
response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
response_body = "Thank you for your request for information, which we " \
"are handling in accordance with the Freedom of Information Act " \
"2000. You will receive a response within 20 working days or before " \
"the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \
"Gandermulch,\nExample Council FOI Officer\n"
post :add_correspondence,
params: {
k: public_bodies(:geraldine_public_body).api_key,
Expand All @@ -322,7 +361,9 @@ def _create_request
}.to_json
}
expect(response.status).to eq(403)
expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(["Request #{request_id} cannot be updated using the API"])
expect(
ActiveSupport::JSON.decode(response.body)['errors']
).to eq(["Request #{request_id} cannot be updated using the API"])
end

it 'should not allow files to be attached to a followup' do
Expand All @@ -343,7 +384,9 @@ def _create_request
# Make sure it worked
expect(response.status).to eq(500)
errors = ActiveSupport::JSON.decode(response.body)['errors']
expect(errors).to eq(["You cannot attach files to messages in the 'request' direction"])
expect(errors).to eq(
["You cannot attach files to messages in the 'request' direction"]
)
end

it 'should allow files to be attached to a response' do
Expand All @@ -356,7 +399,11 @@ def _create_request

# Now add one
sent_at = '2012-05-28T12:35:39+01:00'
response_body = "Thank you for your request for information, which we are handling in accordance with the Freedom of Information Act 2000. You will receive a response within 20 working days or before the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn Gandermulch,\nExample Council FOI Officer\n"
response_body = "Thank you for your request for information, which we " \
"are handling in accordance with the Freedom of Information Act " \
"2000. You will receive a response within 20 working days or before " \
"the next full moon, whichever is sooner.\n\nYours sincerely,\nJohn " \
"Gandermulch,\nExample Council FOI Officer\n"
post :add_correspondence,
params: {
k: public_bodies(:geraldine_public_body).api_key,
Expand All @@ -379,7 +426,9 @@ def _create_request

incoming_message = incoming_messages[0]
expect(incoming_message.sent_at).to eq(Time.iso8601(sent_at))
expect(incoming_message.get_main_body_text_folded).to be_equal_modulo_whitespace_to(response_body)
expect(
incoming_message.get_main_body_text_folded
).to be_equal_modulo_whitespace_to(response_body)

# Get the attachment
attachments = incoming_message.get_attachments_for_display
Expand Down Expand Up @@ -437,7 +486,9 @@ def _create_request

# Check that the error has been raised...
expect(response.status).to eq(500)
expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(["'random_string' is not a valid request state"])
expect(
ActiveSupport::JSON.decode(response.body)['errors']
).to eq(["'random_string' is not a valid request state"])

# ..and that the status hasn't been updated
request = InfoRequest.find_by_id(request_id)
Expand All @@ -446,15 +497,20 @@ def _create_request

it 'should return a JSON 404 error for non-existent requests' do
request_id = '123459876'
allow(InfoRequest).to receive(:find_by_id).with(request_id).and_return(nil)
allow(InfoRequest).
to receive(:find_by_id).
with(request_id).
and_return(nil)

post :update_state, params: {
k: public_bodies(:geraldine_public_body).api_key,
id: request_id, state: "successful"
}

expect(response.status).to eq(404)
expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(['Could not find request 123459876'])
expect(
ActiveSupport::JSON.decode(response.body)['errors']
).to eq(['Could not find request 123459876'])
end

it 'should return a JSON 403 error if we try to add correspondence to a request we don\'t own' do
Expand All @@ -466,7 +522,9 @@ def _create_request
}

expect(response.status).to eq(403)
expect(ActiveSupport::JSON.decode(response.body)['errors']).to eq(["Request #{request_id} cannot be updated using the API"])
expect(
ActiveSupport::JSON.decode(response.body)['errors']
).to eq(["Request #{request_id} cannot be updated using the API"])
end
end

Expand Down Expand Up @@ -519,9 +577,12 @@ def _create_request
expect(response).to render_template('api/request_events')
expect(assigns[:events].size).to be > 0
assigns[:events].each do |event|
expect(event.info_request.public_body).to eq(public_bodies(:geraldine_public_body))
expect(event.info_request.public_body).
to eq(public_bodies(:geraldine_public_body))
expect(event.outgoing_message).not_to be_nil
expect(event.event_type).to satisfy { |x| %w[sent followup_sent resent followup_resent].include?(x) }
expect(event.event_type).to satisfy {
|x| %w[sent followup_sent resent followup_resent].include?(x)
}
end
end

Expand All @@ -536,14 +597,19 @@ def _create_request
expect(response).to be_successful
expect(assigns[:events].size).to be > 0
assigns[:events].each do |event|
expect(event.info_request.public_body).to eq(public_bodies(:geraldine_public_body))
expect(event.info_request.public_body).
to eq(public_bodies(:geraldine_public_body))
expect(event.outgoing_message).not_to be_nil
expect(event.event_type).to satisfy { |x| %w[sent followup_sent resent followup_resent].include?(x) }
expect(event.event_type).to satisfy {
|x| %w[sent followup_sent resent followup_resent].include?(x)
}
end

expect(assigns[:event_data].size).to eq(assigns[:events].size)
assigns[:event_data].each do |event_record|
expect(event_record[:event_type]).to satisfy { |x| %w[sent followup_sent resent followup_resent].include?(x) }
expect(event_record[:event_type]).to satisfy {
|x| %w[sent followup_sent resent followup_resent].include?(x)
}
end
end

Expand Down
29 changes: 17 additions & 12 deletions spec/controllers/attachments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,15 @@ def show(params = {})
File.delete(key_path)
end

# This is a regression test for a bug where URLs of this form were causing 500 errors
# instead of 404s.
# This is a regression test for a bug where URLs of this form were causing
# 500 errors nstead of 404s.
#
# (Note that in fact only the integer-prefix of the URL part is used, so there are
# *some* “ugly URLs containing a request id that isn't an integer” that actually return
# a 200 response. The point is that IDs of this sort were triggering an error in the
# error-handling path, causing the wrong sort of error response to be returned in the
# case where the integer prefix referred to the wrong request.)
# (Note that in fact only the integer-prefix of the URL part is used, so
# there are *some* “ugly URLs containing a request id that isn't an integer”
# that actually return a 200 response. The point is that IDs of this sort
# were triggering an error in the error-handling path, causing the wrong
# sort of error response to be returned in the case where the integer prefix
# referred to the wrong request.)
#
# https://github.com/mysociety/alaveteli/issues/351
it "should return 404 for ugly URLs containing a request id that isn't an integer" do
Expand Down Expand Up @@ -268,13 +269,17 @@ def show(params = {})
end

describe 'GET show_as_html' do
let(:info_request) { FactoryBot.create(:info_request_with_incoming_attachments) }
let(:info_request) {
FactoryBot.create(:info_request_with_incoming_attachments)
}

def get_html_attachment(params = {})
default_params = { incoming_message_id: info_request.incoming_messages.first.id,
id: info_request.id,
part: 2,
file_name: 'interesting.pdf.html' }
default_params = {
incoming_message_id: info_request.incoming_messages.first.id,
id: info_request.id,
part: 2,
file_name: 'interesting.pdf.html'
}
get :show_as_html, params: default_params.merge(params)
end

Expand Down
8 changes: 5 additions & 3 deletions spec/controllers/classifications_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,11 @@ def post_status(status, message: nil)
end

it 'should log a status update event' do
expected_params = { user: { gid: info_request.user.to_global_id.to_s },
old_described_state: 'waiting_response',
described_state: 'rejected' }
expected_params = {
user: { gid: info_request.user.to_global_id.to_s },
old_described_state: 'waiting_response',
described_state: 'rejected'
}
post_status('rejected')
last_event = info_request.reload.info_request_events.last
expect(last_event.params).to eq expected_params
Expand Down
Loading

0 comments on commit 964d9c1

Please sign in to comment.