Skip to content

Commit

Permalink
Update type of authority helper
Browse files Browse the repository at this point in the history
Updated to use new category system introduced in #8023 over the older
`PublicBodyCategory` model which isn't being updated anymore.

Fixes #8081
  • Loading branch information
gbp committed Jan 9, 2024
1 parent 6c9bb58 commit ed989c4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
2 changes: 1 addition & 1 deletion app/helpers/public_body_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def public_body_not_requestable_reasons(public_body)
#
# Returns a String
def type_of_authority(public_body)
categories = PublicBodyCategory.
categories = PublicBody.categories.
where(category_tag: public_body.tag_string.split).order(:id)

types = categories.each_with_index.map do |category, index|
Expand Down
4 changes: 4 additions & 0 deletions spec/factories/categories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,9 @@
title { 'Popular authorities' }
description { 'The most popular authorities' }
category_tag { 'popular_agency' }

trait :public_body do
parents { [PublicBody.category_root] }
end
end
end
40 changes: 16 additions & 24 deletions spec/helpers/public_body_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,24 @@
end

it 'handles Unicode' do
category = FactoryBot.create(:public_body_category, category_tag: 'spec',
description: 'ünicode category')
heading = FactoryBot.create(:public_body_heading)
heading.add_category(category)
FactoryBot.create(
:category, :public_body,
category_tag: 'spec',
description: 'ünicode category'
)
public_body = FactoryBot.create(:public_body, tag_string: 'spec')

expect(type_of_authority(public_body)).
to eq('<a href="/body/list/spec">Ünicode category</a>')
end

it 'constructs the correct string if there are tags which are not categories' do
heading = FactoryBot.create(:public_body_heading)
3.times do |i|
category = FactoryBot.
create(
:public_body_category,
category_tag: "spec_#{i}",
description: "spec category #{i}"
)
heading.add_category(category)
FactoryBot.create(
:category, :public_body,
category_tag: "spec_#{i}",
description: "spec category #{i}"
)
end
public_body = FactoryBot.create(
:public_body,
Expand All @@ -86,13 +84,11 @@

context 'when associated with one category' do
it 'returns the description wrapped in an anchor tag' do
category = FactoryBot.create(
:public_body_category,
FactoryBot.create(
:category, :public_body,
category_tag: 'spec',
description: 'spec category'
)
heading = FactoryBot.create(:public_body_heading)
heading.add_category(category)
public_body = FactoryBot.create(:public_body, tag_string: 'spec')

anchor = %Q(<a href="/body/list/spec">Spec category</a>)
Expand All @@ -102,14 +98,12 @@

context 'when associated with several categories' do
it 'joins the category descriptions and capitalizes the first letter' do
heading = FactoryBot.create(:public_body_heading)
3.times do |i|
category = FactoryBot.create(
:public_body_category,
FactoryBot.create(
:category, :public_body,
category_tag: "spec_#{i}",
description: "spec category #{i}"
)
heading.add_category(category)
end
public_body = FactoryBot.create(
:public_body,
Expand All @@ -132,13 +126,11 @@
it 'creates the anchor href in the correct locale' do
# Activate the routing filter, normally turned off for helper tests
RoutingFilter.active = true
category = FactoryBot.create(
:public_body_category,
FactoryBot.create(
:category, :public_body,
category_tag: 'spec',
description: 'spec category'
)
heading = FactoryBot.create(:public_body_heading)
heading.add_category(category)
public_body = FactoryBot.create(:public_body, tag_string: 'spec')

anchor = %Q(<a href="/es/body/list/spec">Spec category</a>)
Expand Down

0 comments on commit ed989c4

Please sign in to comment.