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 20, 2023
1 parent f14cebd commit f021aa1
Show file tree
Hide file tree
Showing 10 changed files with 126 additions and 112 deletions.
36 changes: 19 additions & 17 deletions spec/controllers/admin_public_body_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@

it "searches for 'humpa'" do
get :index, params: { query: "humpa" }
expect(assigns[:public_bodies])
.to eq([public_bodies(:humpadink_public_body)])
expect(assigns[:public_bodies]).
to eq([public_bodies(:humpadink_public_body)])
end

it "searches for 'humpa' in another locale" do
get :index, params: { query: "humpa", locale: "es" }
expect(assigns[:public_bodies])
.to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:public_bodies]).
to eq([public_bodies(:humpadink_public_body)])
end

end
Expand Down Expand Up @@ -599,13 +599,19 @@
context 'on failure for multiple locales' do

before(:each) do
@params = { id: @body.id,
public_body: { name: '',
translations_attributes: {
'es' => { id: @body.translation_for(:es).id,
locale: 'es',
name: 'Mi Nuevo Body' }
} } }
@params = {
id: @body.id,
public_body: {
name: '',
translations_attributes: {
'es' => {
id: @body.translation_for(:es).id,
locale: 'es',
name: 'Mi Nuevo Body'
}
}
}
}
end

it 'is rebuilt with the default locale translation' do
Expand Down Expand Up @@ -910,12 +916,8 @@ def setup_emergency_credentials(username, password)
sign_in users(:admin_user)
@request.env["HTTP_AUTHORIZATION"] = ""
post :show, params: { id: public_bodies(:humpadink_public_body).id }
expect(
controller.
send(:admin_current_user)).
to eq(users(:admin_user).
url_name
)
expect(controller.send(:admin_current_user)).
to eq(users(:admin_user).url_name)
end

it 'returns the REMOTE_USER value from the request environment when skipping admin auth' do
Expand Down
18 changes: 9 additions & 9 deletions spec/controllers/api_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -580,9 +580,9 @@ def _create_request
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 do |x|
%w[sent followup_sent resent followup_resent].include?(x)
end
end
end

Expand All @@ -600,16 +600,16 @@ def _create_request
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 do |x|
%w[sent followup_sent resent followup_resent].include?(x)
end
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 do |x|
%w[sent followup_sent resent followup_resent].include?(x)
end
end
end

Expand Down
14 changes: 7 additions & 7 deletions spec/controllers/concerns/translatable_params_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
status: 'good',
id: 40,
translations_attributes: {
en: {
locale: 'en',
name: 'Other name',
bad: "value"
en: {
locale: 'en',
name: 'Other name',
bad: "value"
}
}
}
}
expected = {
name: 'Some name',
status: 'good',
Expand Down Expand Up @@ -76,9 +76,9 @@
id: 40,
locale: 'en',
name: 'Other name'
}
}
}
}
expected = ActionController::Parameters.new(params).permit!

params = params = ActionController::Parameters.new(params)
Expand All @@ -94,9 +94,9 @@
locale: 'en',
name: 'Other name',
bad: "value"
}
}
}
}
expected = {
translations_attributes: {
en: {
Expand Down
7 changes: 3 additions & 4 deletions spec/controllers/followups_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
render_views

let(:request_user) { FactoryBot.create(:user) }
let(:request) { FactoryBot.create(
:info_request_with_incoming,
user: request_user
) }
let(:request) do
FactoryBot.create(:info_request_with_incoming, user: request_user)
end
let(:message_id) { request.incoming_messages[0].id }
let(:pro_user) { FactoryBot.create(:pro_user) }

Expand Down
32 changes: 18 additions & 14 deletions spec/controllers/general_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
described_at: Time.zone.now,
search_text_main: 'example text')
xapian_result = double(
'xapian result', results: [{model: info_request_event}]
'xapian result', results: [{ model: info_request_event }]
)
allow(controller).to receive(:perform_search).and_return(xapian_result)
end
Expand Down Expand Up @@ -253,12 +253,14 @@
it "should filter results based on end of URL being 'all'" do
get :search, params: { combined: "bob/all" }
expect(assigns[:xapian_requests].results.map { |x| x[:model] }).
to match_array([
info_request_events(:useless_outgoing_message_event),
info_request_events(:silly_outgoing_message_event),
info_request_events(:useful_incoming_message_event),
info_request_events(:another_useful_incoming_message_event)
])
to match_array(
[
info_request_events(:useless_outgoing_message_event),
info_request_events(:silly_outgoing_message_event),
info_request_events(:useful_incoming_message_event),
info_request_events(:another_useful_incoming_message_event)
]
)
expect(assigns[:xapian_users].results.map { |x| x[:model] }).
to eq([users(:bob_smith_user)])
expect(assigns[:xapian_bodies].results).to eq([])
Expand All @@ -285,13 +287,15 @@

it "should filter results based on end of URL being 'requests'" do
get :search, params: { combined: "bob/requests" }
expect(assigns[:xapian_requests].results.map { |x|x[:model] }).
to match_array([
info_request_events(:useless_outgoing_message_event),
info_request_events(:silly_outgoing_message_event),
info_request_events(:useful_incoming_message_event),
info_request_events(:another_useful_incoming_message_event)
])
expect(assigns[:xapian_requests].results.map { |x| x[:model] }).
to match_array(
[
info_request_events(:useless_outgoing_message_event),
info_request_events(:silly_outgoing_message_event),
info_request_events(:useful_incoming_message_event),
info_request_events(:another_useful_incoming_message_event)
]
)
expect(assigns[:xapian_users]).to eq(nil)
expect(assigns[:xapian_bodies]).to eq(nil)
end
Expand Down
7 changes: 4 additions & 3 deletions spec/controllers/info_request_batch_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,14 @@
it 'should assign all info_requests to the view' do
with_feature_enabled(:alaveteli_pro) do
action
expect(assigns[:info_requests].sort).
to eq([
expect(assigns[:info_requests].sort).to eq(
[
first_request,
second_request,
hidden_request,
backpage_request
])
]
)
end
end
end
Expand Down
80 changes: 44 additions & 36 deletions spec/controllers/public_body_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,28 @@
it "should assign the requests (1)" do
get :show, params: { url_name: "tgq", view: 'all' }
conditions = { public_body_id: public_bodies(:geraldine_public_body).id }
actual = assigns[:xapian_requests].results.map {
|x| x[:model].info_request
}
actual = assigns[:xapian_requests].results.map do |x|
x[:model].info_request
end
expect(actual).to match_array(InfoRequest.where(conditions))
end

it "should assign the requests (2)" do
get :show, params: { url_name: "tgq", view: 'successful' }
conditions = { described_state: 'successful',
public_body_id: public_bodies(:geraldine_public_body).id }
actual = assigns[:xapian_requests].results.map {
|x| x[:model].info_request
}
actual = assigns[:xapian_requests].results.map do |x|
x[:model].info_request
end
expect(actual).to match_array(InfoRequest.where(conditions))
end

it "should assign the requests (3)" do
get :show, params: { url_name: "dfh", view: 'all' }
conditions = { public_body_id: public_bodies(:humpadink_public_body).id }
actual = assigns[:xapian_requests].results.map {
|x| x[:model].info_request
}
actual = assigns[:xapian_requests].results.map do |x|
x[:model].info_request
end
expect(actual).to match_array(InfoRequest.where(conditions))
end

Expand Down Expand Up @@ -223,14 +223,16 @@ def make_single_language_example(locale)

expect(response).to render_template('list')

expect(assigns[:public_bodies]).to eq([
public_bodies(:other_public_body),
public_bodies(:humpadink_public_body),
public_bodies(:forlorn_public_body),
public_bodies(:geraldine_public_body),
public_bodies(:sensible_walks_public_body),
public_bodies(:silly_walks_public_body)
])
expect(assigns[:public_bodies]).to eq(
[
public_bodies(:other_public_body),
public_bodies(:humpadink_public_body),
public_bodies(:forlorn_public_body),
public_bodies(:geraldine_public_body),
public_bodies(:sensible_walks_public_body),
public_bodies(:silly_walks_public_body)
]
)
expect(assigns[:tag]).to eq("all")
expect(assigns[:description]).to eq("Found 6 public authorities")
end
Expand Down Expand Up @@ -312,10 +314,12 @@ def make_single_language_example(locale)
with_default_locale(:es) do
get :list
expect(response).to render_template('list')
expect(assigns[:public_bodies]).to eq([
public_bodies(:geraldine_public_body),
public_bodies(:humpadink_public_body)
])
expect(assigns[:public_bodies]).to eq(
[
public_bodies(:geraldine_public_body),
public_bodies(:humpadink_public_body)
]
)
expect(assigns[:tag]).to eq("all")
expect(assigns[:description]).to eq("Found 2 public authorities")
end
Expand All @@ -342,24 +346,28 @@ def make_single_language_example(locale)

get :list, params: { tag: "other" }
expect(response).to render_template('list')
expect(assigns[:public_bodies]).to eq([
public_bodies(:other_public_body),
public_bodies(:forlorn_public_body),
public_bodies(:geraldine_public_body),
public_bodies(:sensible_walks_public_body),
public_bodies(:silly_walks_public_body)
])
expect(assigns[:public_bodies]).to eq(
[
public_bodies(:other_public_body),
public_bodies(:forlorn_public_body),
public_bodies(:geraldine_public_body),
public_bodies(:sensible_walks_public_body),
public_bodies(:silly_walks_public_body)
]
)

get :list
expect(response).to render_template('list')
expect(assigns[:public_bodies]).to eq([
public_bodies(:other_public_body),
public_bodies(:humpadink_public_body),
public_bodies(:forlorn_public_body),
public_bodies(:geraldine_public_body),
public_bodies(:sensible_walks_public_body),
public_bodies(:silly_walks_public_body)
])
expect(assigns[:public_bodies]).to eq(
[
public_bodies(:other_public_body),
public_bodies(:humpadink_public_body),
public_bodies(:forlorn_public_body),
public_bodies(:geraldine_public_body),
public_bodies(:sensible_walks_public_body),
public_bodies(:silly_walks_public_body)
]
)
end

it "should list a machine tagged thing, should get it in both ways" do
Expand Down
20 changes: 10 additions & 10 deletions spec/controllers/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
reason: "my reason"
}
expect(flash[:notice]).to match(/You need to be logged in/)
expect(response)
.to redirect_to show_request_path(url_title: info_request.url_title)
expect(response).
to redirect_to show_request_path(url_title: info_request.url_title)
end
end

Expand Down Expand Up @@ -96,8 +96,8 @@
request_id: info_request.url_title,
reason: "my reason"
}
expect(response)
.to redirect_to show_request_path(url_title: info_request.url_title)
expect(response).
to redirect_to show_request_path(url_title: info_request.url_title)

info_request.reload
expect(info_request.attention_requested).to eq(true)
Expand All @@ -121,15 +121,15 @@
request_id: info_request.url_title,
reason: "my reason"
}
expect(response)
.to redirect_to show_request_url(url_title: info_request.url_title)
expect(response).
to redirect_to show_request_url(url_title: info_request.url_title)

post :create, params: {
request_id: info_request.url_title,
reason: "my reason"
}
expect(response)
.to redirect_to show_request_url(url_title: info_request.url_title)
expect(response).
to redirect_to show_request_url(url_title: info_request.url_title)
expect(flash[:notice]).to match(/has already been reported/)
end

Expand Down Expand Up @@ -291,8 +291,8 @@
message: "It's just not"
}

expect(response)
.to redirect_to show_request_path(url_title: info_request.url_title)
expect(response).
to redirect_to show_request_path(url_title: info_request.url_title)
end

end
Expand Down
Loading

0 comments on commit f021aa1

Please sign in to comment.