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 b4e9ab2 commit dab8918
Show file tree
Hide file tree
Showing 6 changed files with 626 additions and 509 deletions.
26 changes: 18 additions & 8 deletions spec/controllers/public_body_change_requests_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@
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 @@ -83,7 +85,8 @@
post :create, params: {
public_body_change_request: @change_request_params
}
expected_text = "Your request to add an authority has been sent. Thank you for getting in touch! We'll get back to you soon."
expected_text = "Your request to add an authority has been sent. " \
"Thank you for getting in touch! We'll get back to you soon."
expect(flash[:notice]).to eq(expected_text)
end

Expand All @@ -96,7 +99,9 @@
end

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

post :create, params: {
public_body_change_request: spam_request_params
Expand Down Expand Up @@ -133,22 +138,27 @@
deliveries = ActionMailer::Base.deliveries
expect(deliveries.size).to eq(1)
mail = deliveries[0]
expect(mail.subject).to match(/Update email address - #{@public_body.name}/)
expect(mail.subject).
to match(/Update email address - #{@public_body.name}/)
expect(mail.header['Reply-To'].to_s).to include(@email)
expect(mail.to).to include('postmaster@localhost')
expect(mail.body).to include('[email protected]')
expect(mail.body).to include(@public_body.name)
expect(mail.body).to include("Please")
expect(mail.body).to include("http://test.host/admin/bodies/#{@public_body.id}/edit?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/" \
"#{@public_body.id}/edit?change_request_id=#{change_request_id}")
expect(mail.body).to include("http://test.host/admin/change_requests/" \
"#{change_request_id}/edit")
end

it 'should show a notice' do
allow(@controller).to receive(:verify_recaptcha).and_return(true)
post :create, params: {
public_body_change_request: @change_request_params
}
expected_text = "Your request to update the address for #{@public_body.name} has been sent. Thank you for getting in touch! We'll get back to you soon."
expected_text = "Your request to update the address for " \
"#{@public_body.name} has been sent. Thank you for getting in " \
"touch! We'll get back to you soon."
expect(flash[:notice]).to eq(expected_text)
end

Expand Down
114 changes: 75 additions & 39 deletions spec/controllers/public_body_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +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 {
|x| x[:model].info_request
}
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 {
|x| x[:model].info_request
}
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 {
|x| x[:model].info_request
}
expect(actual).to match_array(InfoRequest.where(conditions))
end

Expand All @@ -66,12 +72,20 @@

it "should redirect to newest name if you use historic name of public body in URL" do
get :show, params: { url_name: "hdink", view: 'all' }
expect(response).to redirect_to(controller: 'public_body', action: 'show', url_name: "dfh")
expect(response).to redirect_to(
controller: 'public_body',
action: 'show',
url_name: "dfh"
)
end

it "should redirect to lower case name if you use mixed case name in URL" do
get :show, params: { url_name: "dFh", view: 'all' }
expect(response).to redirect_to(controller: 'public_body', action: 'show', url_name: "dfh")
expect(response).to redirect_to(
controller: 'public_body',
action: 'show',
url_name: "dfh"
)
end

it 'keeps the search_params flash' do
Expand Down Expand Up @@ -140,21 +154,24 @@ def make_single_language_example(locale)
end

it "if fallback is requested, should list all bodies from default locale, even when there are no translations for selected locale" do
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).and_return(true)
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).and_return(true)
@english_only = make_single_language_example :en
get :list, params: { locale: 'es' }
expect(assigns[:public_bodies].include?(@english_only)).to eq(true)
end

it 'if fallback is requested, should still list public bodies only with translations in the current locale' do
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).and_return(true)
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).and_return(true)
@spanish_only = make_single_language_example :es
get :list, params: { locale: 'es' }
expect(assigns[:public_bodies].include?(@spanish_only)).to eq(true)
end

it "if fallback is requested, make sure that there are no duplicates listed" do
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).and_return(true)
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).and_return(true)
get :list, params: { locale: 'es' }
pb_ids = assigns[:public_bodies].map(&:id)
unique_pb_ids = pb_ids.uniq
Expand Down Expand Up @@ -184,7 +201,8 @@ def make_single_language_example(locale)
# The names of each public body is in:
# <span class="head"><a>Public Body Name</a></span>
# ... eo extract all of those, and check that they are ordered:
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).and_return(true)
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).and_return(true)
get :list, params: { locale: 'es' }
parsed = Nokogiri::HTML(response.body)
public_body_names = parsed.xpath '//span[@class="head"]/a/text()'
Expand All @@ -205,18 +223,21 @@ 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

it 'list bodies in collate order according to the locale with the fallback set' do
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).
and_return(true)

allow(DatabaseCollation).to receive(:supports?).
Expand All @@ -228,7 +249,8 @@ def make_single_language_example(locale)
end

it 'list bodies in default order according to the locale with the fallback set' do
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).
and_return(true)

allow(DatabaseCollation).to receive(:supports?).
Expand All @@ -241,7 +263,8 @@ def make_single_language_example(locale)
end

it 'list bodies in collate order according to the locale' do
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).
and_return(false)

allow(DatabaseCollation).to receive(:supports?).
Expand All @@ -254,7 +277,8 @@ def make_single_language_example(locale)
end

it 'list bodies in alphabetical order according to the locale' do
allow(AlaveteliConfiguration).to receive(:public_body_list_fallback_to_default_locale).
allow(AlaveteliConfiguration).
to receive(:public_body_list_fallback_to_default_locale).
and_return(false)

allow(DatabaseCollation).to receive(:supports?).
Expand All @@ -268,31 +292,36 @@ def make_single_language_example(locale)

it "should support simple searching of bodies by title" do
get :list, params: { public_body_query: 'quango' }
expect(assigns[:public_bodies]).to eq([ public_bodies(:geraldine_public_body) ])
expect(assigns[:public_bodies]).
to eq([ public_bodies(:geraldine_public_body) ])
end

it "should support simple searching of bodies by short_name" do
get :list, params: { public_body_query: 'DfH' }
expect(assigns[:public_bodies]).to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:public_bodies]).
to eq([ public_bodies(:humpadink_public_body) ])
end

xit "should support simple searching of bodies by notes" do
get :list, params: { public_body_query: 'Albatross' }
expect(assigns[:public_bodies]).to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:public_bodies]).
to eq([ public_bodies(:humpadink_public_body) ])
end

it "should list bodies in alphabetical order with different locale" do
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
end

it "should list a tagged thing on the appropriate list page, and others on the other page,
and all still on the all page" do
it "should list a tagged thing on the appropriate list page, and others on the other page, and all still on the all page" do
PublicBodyCategory.destroy_all
PublicBodyHeading.destroy_all
PublicBodyCategoryLink.destroy_all
Expand All @@ -305,35 +334,41 @@ def make_single_language_example(locale)

get :list, params: { tag: category.category_tag }
expect(response).to render_template('list')
expect(assigns[:public_bodies]).to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:public_bodies]).
to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:tag]).to eq(category.category_tag)
expect(assigns[:description]).
to eq("Found 1 public authority in the category ‘#{category.title}’")

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
public_bodies(:humpadink_public_body).tag_string = "eats_cheese:stilton"

get :list, params: { tag: "eats_cheese" }
expect(response).to render_template('list')
expect(assigns[:public_bodies]).to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:public_bodies]).
to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:tag]).to eq("eats_cheese")

get :list, params: { tag: "eats_cheese:jarlsberg" }
Expand All @@ -343,7 +378,8 @@ def make_single_language_example(locale)

get :list, params: { tag: "eats_cheese:stilton" }
expect(response).to render_template('list')
expect(assigns[:public_bodies]).to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:public_bodies]).
to eq([ public_bodies(:humpadink_public_body) ])
expect(assigns[:tag]).to eq("eats_cheese:stilton")
end

Expand Down
10 changes: 5 additions & 5 deletions spec/controllers/reports_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}
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)
.to redirect_to show_request_path(url_title: info_request.url_title)
end
end

Expand Down Expand Up @@ -97,7 +97,7 @@
reason: "my reason"
}
expect(response)
.to redirect_to show_request_path(url_title: info_request.url_title)
.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 @@ -122,14 +122,14 @@
reason: "my reason"
}
expect(response)
.to redirect_to show_request_url(url_title: info_request.url_title)
.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)
.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 @@ -292,7 +292,7 @@
}

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

end
Expand Down
Loading

0 comments on commit dab8918

Please sign in to comment.