Skip to content

Commit

Permalink
lint: Layout/LineLength RuboCop - controller specs
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 authored and gbp committed Nov 21, 2023
1 parent 5af969f commit f2906ad
Show file tree
Hide file tree
Showing 33 changed files with 1,147 additions and 730 deletions.
3 changes: 2 additions & 1 deletion spec/controllers/admin_comment_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@
body: 'updated text')
sign_in admin_user
put :update, params: { id: comment.id, comment: atts }
expect(response).to redirect_to(admin_request_path(comment.info_request))
expect(response).
to redirect_to(admin_request_path(comment.info_request))
end
end

Expand Down
10 changes: 7 additions & 3 deletions spec/controllers/admin_general_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
end

it 'assigns requests flagged for admin attention to the view' do
attention_requested_request = FactoryBot.create(:attention_requested_request)
attention_requested_request = FactoryBot.create(
:attention_requested_request
)
sign_in admin_user
get :index
expect(assigns[:attention_requests]).to eq([attention_requested_request])
Expand All @@ -65,7 +67,7 @@
it 'assigns public_request_tasks to true' do
undeliverable = FactoryBot.
create(:incoming_message,
info_request: InfoRequest.holding_pen_request)
info_request: InfoRequest.holding_pen_request)
sign_in admin_user
get :index
expect(assigns[:public_request_tasks]).to be true
Expand Down Expand Up @@ -208,7 +210,9 @@

it 'does not assign embargoed requests flagged for admin attention to the view' do
with_feature_enabled(:alaveteli_pro) do
attention_requested_request = FactoryBot.create(:attention_requested_request)
attention_requested_request = FactoryBot.create(
:attention_requested_request
)
attention_requested_request.create_embargo
sign_in admin_user
get :index
Expand Down
3 changes: 2 additions & 1 deletion spec/controllers/admin_holidays_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@
end

it 'updates the holiday' do
holiday = expect(Holiday.find(@holiday.id).description).to eq('New Test Holiday')
holiday = expect(Holiday.find(@holiday.id).description).
to eq('New Test Holiday')
end

it 'shows the admin a success message' do
Expand Down
27 changes: 20 additions & 7 deletions spec/controllers/admin_incoming_message_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
info_request = FactoryBot.create(:info_request)
allow(@im).to receive(:info_request).and_return(info_request)
allow(IncomingMessage).to receive(:find).and_return(@im)
expect(@im.info_request).to receive(:expire).with(preserve_database_cache: true)
expect(@im.info_request).
to receive(:expire).
with(preserve_database_cache: true)
post :destroy, params: { id: @im.id }
end

Expand Down Expand Up @@ -104,8 +106,12 @@
# It shouldn't delete this message
assert_equal IncomingMessage.exists?(incoming_message.id), true
# Should show an error to the user
assert_equal flash[:error], "You must supply at least one request to redeliver the message to."
expect(response).to redirect_to admin_request_url(incoming_message.info_request)
assert_equal(
flash[:error],
"You must supply at least one request to redeliver the message to."
)
expect(response).
to redirect_to admin_request_url(incoming_message.info_request)
end

context 'when redelivering to multiple requests' do
Expand Down Expand Up @@ -241,9 +247,13 @@ def make_request(params=@default_params)
end

it 'should log an "edit_incoming" event on the info_request' do
allow(@controller).to receive(:admin_current_user).and_return("Admin user")
allow(@controller).
to receive(:admin_current_user).
and_return("Admin user")

expect(NotifyCacheJob).to receive(:perform_later).
with(@incoming.info_request)

make_request
@incoming.reload
last_event = @incoming.info_request_events.last
Expand Down Expand Up @@ -272,7 +282,8 @@ def make_request(params=@default_params)

it 'should redirect to the admin info request view' do
make_request
expect(response).to redirect_to admin_request_url(@incoming.info_request)
expect(response).
to redirect_to admin_request_url(@incoming.info_request)
end

it 'should show a message that the incoming message has been updated' do
Expand Down Expand Up @@ -372,7 +383,8 @@ def make_request(params=@default_params)
}

expect(response).to redirect_to(admin_request_url(request))
expect(flash[:notice]).to eq("Incoming messages successfully destroyed.")
expect(flash[:notice]).
to eq("Incoming messages successfully destroyed.")
end

it "only destroys selected messages" do
Expand Down Expand Up @@ -413,7 +425,8 @@ def make_request(params=@default_params)
commit: "No"
}

expect(IncomingMessage.where(id: spam_ids)).to match_array([spam1, spam2])
expect(IncomingMessage.where(id: spam_ids)).
to match_array([spam1, spam2])
end

it "redirects back to the admin page for the request" do
Expand Down
4 changes: 3 additions & 1 deletion spec/controllers/admin_info_request_event_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
it 'shows a success notice' do
put :update, params: { id: info_request_event }
expect(flash[:notice]).
to eq('Old response marked as having been a request for clarification')
to eq(
'Old response marked as having been a request for clarification'
)
end

it 'redirects to the request admin page' do
Expand Down
7 changes: 5 additions & 2 deletions spec/controllers/admin_outgoing_message_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def make_request(params = default_params)
end

it 'should log an "edit_outgoing" event on the info_request' do
allow(@controller).to receive(:admin_current_user).and_return("Admin user")
allow(@controller).
to receive(:admin_current_user).
and_return("Admin user")
make_request
info_request.reload
last_event = info_request.info_request_events.last
Expand All @@ -252,7 +254,8 @@ def make_request(params = default_params)

it 'should expire the file cache for the info request' do
info_request = FactoryBot.create(:info_request)
allow_any_instance_of(OutgoingMessage).to receive(:info_request) { info_request }
allow_any_instance_of(OutgoingMessage).
to receive(:info_request) { info_request }

outgoing = FactoryBot.create(:initial_request, info_request: info_request)

Expand Down
23 changes: 16 additions & 7 deletions spec/controllers/admin_public_body_categories_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@
headings: { "heading_#{ heading.id }" => heading.id }
}

category = PublicBodyCategory.where(title: @params[:translations_attributes]['en'][:title]).first
category = PublicBodyCategory.
where(title: @params[:translations_attributes]['en'][:title]).first
expect(category.public_body_headings).to eq([heading])
end

Expand Down Expand Up @@ -232,7 +233,8 @@
post :create, params: { public_body_category: @params }

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 Expand Up @@ -263,7 +265,8 @@

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)).to include(:fr)
expect(assigns[:public_body_category].translations.map(&:locale)).
to include(:fr)
end

it 'finds the public bodies tagged with the category tag' do
Expand Down Expand Up @@ -337,7 +340,9 @@

post :update, params: {
id: category.id,
public_body_category: category.serializable_hash.except(:title, :description)
public_body_category: category.
serializable_hash.
except(:title, :description)
}

expect(assigns(:tagged_public_bodies)).to match_array(expected_bodies)
Expand Down Expand Up @@ -437,7 +442,9 @@
end

it 'saves edits to category_tag if the category has no associated bodies' do
category = FactoryBot.create(:public_body_category, category_tag: 'empty')
category = FactoryBot.create(
:public_body_category, category_tag: 'empty'
)

post :update, params: {
id: category.id,
Expand Down Expand Up @@ -677,7 +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 @@ -687,7 +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
Loading

0 comments on commit f2906ad

Please sign in to comment.