Skip to content

Commit

Permalink
fixup! lint: Layout/LineLength RuboCop - controller specs
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Nov 21, 2023
1 parent 27b5c56 commit f0c93d7
Show file tree
Hide file tree
Showing 15 changed files with 124 additions and 147 deletions.
13 changes: 5 additions & 8 deletions spec/controllers/admin_public_body_categories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,7 @@

it 'builds new translations if the body does not already have a translation in the specified locale' do
get :edit, params: { id: @category.id }
expect(assigns[:public_body_category].
translations.map(&:locale)).
expect(assigns[:public_body_category].translations.map(&:locale)).
to include(:fr)
end

Expand Down Expand Up @@ -685,9 +684,8 @@
id: @category.id,
public_body_category: @params
}
expect(
assigns(:public_body_category).title(:en)
).to eq('Need a description')
expect(assigns(:public_body_category).title(:en)).
to eq('Need a description')
end

it 'is rebuilt with the alternative locale translation' do
Expand All @@ -697,9 +695,8 @@
}

AlaveteliLocalization.with_locale(:es) do
expect(
assigns(:public_body_category).title
).to eq('Mi Nuevo Category')
expect(assigns(:public_body_category).title).
to eq('Mi Nuevo Category')
end
end

Expand Down
28 changes: 11 additions & 17 deletions spec/controllers/admin_public_body_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,8 @@
end

it 'should mark the change request as closed' do
expect(
PublicBodyChangeRequest.find(@change_request.id).is_open
).to be false
expect(PublicBodyChangeRequest.find(@change_request.id).is_open).
to be false
end

end
Expand Down Expand Up @@ -355,8 +354,7 @@
get :edit, params: { id: 3, locale: :en }

# When editing a body, the controller returns all available translations
expect(assigns[:public_body].
find_translation_by_locale("es").name).
expect(assigns[:public_body].find_translation_by_locale("es").name).
to eq('El Department for Humpadinking')
expect(assigns[:public_body].name).to eq('Department for Humpadinking')
expect(response).to render_template('edit')
Expand All @@ -379,18 +377,15 @@
id: change_request.public_body_id,
change_request_id: change_request.id
}
expect(
assigns[:public_body].request_email
).to eq(@change_request.public_body_email)
expect(
assigns[:public_body].last_edit_comment
).to match('Notes: Please')
expect(assigns[:public_body].request_email).
to eq(@change_request.public_body_email)
expect(assigns[:public_body].last_edit_comment).
to match('Notes: Please')
end

it 'should assign a default response text to the view' do
expect(
assigns[:change_request_user_response]
).to match("Thanks for your suggestion to update the email address")
expect(assigns[:change_request_user_response]).
to match("Thanks for your suggestion to update the email address")
end
end

Expand Down Expand Up @@ -657,9 +652,8 @@
end

it 'should mark the change request as closed' do
expect(
PublicBodyChangeRequest.find(@change_request.id).is_open
).to be false
expect(PublicBodyChangeRequest.find(@change_request.id).is_open).
to be false
end

end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@

it 'builds new translations if the body does not already have a translation in the specified locale' do
get :edit, params: { id: @heading.id }
expect(assigns[:public_body_heading].
translations.map(&:locale)).
expect(assigns[:public_body_heading].translations.map(&:locale)).
to include(:fr)
end

Expand Down
5 changes: 2 additions & 3 deletions spec/controllers/alaveteli_pro/base_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ def index
context "when the user is not logged in" do
it "redirects to the signin path" do
get :index
expect(
@response.redirect_url
).to match(/http:\/\/test\.host\/profile\/sign_in/)
expect(@response.redirect_url).
to match(/http:\/\/test\.host\/profile\/sign_in/)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
it "raises ActiveRecord::RecordNotFound" do
with_feature_enabled(:alaveteli_pro) do
params[:draft_id] = AlaveteliPro::DraftInfoRequestBatch.
maximum(:id).
next
maximum(:id).next
expect { action }.to raise_error(ActiveRecord::RecordNotFound)
end
end
Expand Down Expand Up @@ -183,9 +182,8 @@
with_feature_enabled(:alaveteli_pro) do
action
expect(assigns[:info_request_batch].errors).to be_empty
expect(
assigns[:example_info_request].errors[:outgoing_messages]
).to be_empty
expect(assigns[:example_info_request].errors[:outgoing_messages]).
to be_empty
expect(assigns[:example_info_request].errors[:title]).not_to be_empty
expect(assigns[:outgoing_message].errors[:body]).not_to be_empty
end
Expand Down Expand Up @@ -220,9 +218,9 @@
it "destroys the draft" do
with_feature_enabled(:alaveteli_pro) do
title = draft.title
expect { action }.to change {
AlaveteliPro::DraftInfoRequestBatch.count
}.by(-1)
expect { action }.
to change { AlaveteliPro::DraftInfoRequestBatch.count }.
by(-1)
expect(AlaveteliPro::DraftInfoRequestBatch.where(title: title))
end
end
Expand All @@ -231,9 +229,8 @@
with_feature_enabled(:alaveteli_pro) do
action
new_batch = InfoRequestBatch.order(created_at: :desc).first
expect(response).to redirect_to(
show_alaveteli_pro_batch_request_path(new_batch.id)
)
expect(response).
to redirect_to(show_alaveteli_pro_batch_request_path(new_batch.id))
end
end
end
Expand Down Expand Up @@ -300,9 +297,8 @@
with_feature_enabled(:alaveteli_pro) do
action
expect(assigns[:info_request_batch].errors).to be_empty
expect(
assigns[:example_info_request].errors[:outgoing_messages]
).to be_empty
expect(assigns[:example_info_request].errors[:outgoing_messages]).
to be_empty
expect(assigns[:example_info_request].errors[:title]).not_to be_empty
expect(assigns[:outgoing_message].errors[:body]).not_to be_empty
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@
it "assigns the user's request summaries" do
get :index
expect(assigns[:request_summaries].size).to eq 2
expect(assigns[:request_summaries]).
to match_array [
info_request.request_summary, foo_request.request_summary
]
expect(assigns[:request_summaries]).to match_array [
info_request.request_summary, foo_request.request_summary
]
end
end

Expand Down
55 changes: 22 additions & 33 deletions spec/controllers/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,24 +86,20 @@ 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)
last_event = new_request.last_event_forming_initial_request
expect(last_event.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 Down Expand Up @@ -144,9 +140,8 @@ 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 @@ -337,9 +332,8 @@ 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
Expand All @@ -361,9 +355,8 @@ 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 Down Expand Up @@ -426,9 +419,8 @@ 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 @@ -486,9 +478,8 @@ 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 @@ -508,9 +499,8 @@ def _create_request
}

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 @@ -522,9 +512,8 @@ 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
5 changes: 2 additions & 3 deletions spec/controllers/followups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -542,9 +542,8 @@ def send_request
request_id: request.id,
incoming_message_id: message_id
}
expect(flash[:notice]).to eq(
'Your follow up message has been sent on its way.'
)
expect(flash[:notice]).
to eq('Your follow up message has been sent on its way.')
end

it "displays an error if the request has been closed to new responses" do
Expand Down
5 changes: 2 additions & 3 deletions spec/controllers/general_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -304,9 +304,8 @@
get :search, params: { combined: "quango/bodies" }
expect(assigns[:xapian_requests]).to eq(nil)
expect(assigns[:xapian_users]).to eq(nil)
expect(assigns[:xapian_bodies].results.map { |x| x[:model] }).to eq(
[public_bodies(:geraldine_public_body)]
)
expect(assigns[:xapian_bodies].results.map(&:model)).
to eq([public_bodies(:geraldine_public_body)])
end

it 'should prioritise direct matches of public body names' do
Expand Down
3 changes: 1 addition & 2 deletions spec/controllers/help_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,7 @@

before do
# Prepend our fixture templates
fixture_theme_path = File.join(
Rails.root,
fixture_theme_path = Rails.root.join(
'spec',
'fixtures',
'theme_views',
Expand Down
13 changes: 8 additions & 5 deletions spec/controllers/public_body_change_requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,13 @@
expect(mail.body).to include('[email protected]')
expect(mail.body).to include('New Body')
expect(mail.body).to include("Please")
expect(mail.body).to include("http://test.host/admin/bodies/" \
"new?change_request_id=#{change_request_id}")
expect(mail.body).to include("http://test.host/admin/change_requests/" \
"#{change_request_id}/edit")
expect(mail.body).to include(
"http://test.host/admin/bodies/new?change_request_id=" \
"#{change_request_id}"
)
expect(mail.body).to include(
"http://test.host/admin/change_requests/#{change_request_id}/edit"
)
end

it 'sets render_recaptcha to true if there is no logged in user' do
Expand Down Expand Up @@ -100,7 +103,7 @@

it 'has rudimentary spam protection' do
spam_request_params = @change_request_params.merge(
{ comment: 'I AM A SPAMBOT' }
comment: 'I AM A SPAMBOT'
)

post :create, params: {
Expand Down
Loading

0 comments on commit f0c93d7

Please sign in to comment.