Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#8179] Replace public body categories #8196

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/controllers/public_body_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,8 @@ def list
count: @public_bodies.total_entries,
first_letter: @tag)
else
category_name = PublicBodyCategory.get.by_tag[@tag]
if category_name.nil?
category = PublicBody.category_list.find_by(category_tag: @tag)
if category.nil?
n_('Found {{count}} public authority matching the tag ' \
'‘{{tag_name}}’',
'Found {{count}} public authorities matching the tag ' \
Expand All @@ -155,12 +155,12 @@ def list
tag_name: @tag)
else
n_('Found {{count}} public authority in the category ' \
'‘{{category_name}}’',
'‘{{category}}’',
'Found {{count}} public authorities in the category ' \
'‘{{category_name}}’',
'‘{{category}}’',
@public_bodies.total_entries,
count: @public_bodies.total_entries,
category_name: category_name)
category: category.title)
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/models/public_body.rb
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,9 @@ def self.with_tag(tag)
return all if tag.size == 1 || tag.nil? || tag == 'all'

if tag == 'other'
tags = PublicBodyCategory.get.tags - ['other']
tags = PublicBody.category_list.distinct.
where.not(category_tag: [nil, '', 'other']).
pluck(:category_tag)
where.not("EXISTS(#{tag_search_sql(tags)})")
else
original_with_tag(tag)
Expand Down
19 changes: 5 additions & 14 deletions lib/tasks/export.rake
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@ namespace :export do
default_scope -> { order(:info_request_batch_id, :public_body_id) }
end

class PublicBodyCategoryTranslation < ActiveRecord::Base
self.table_name = "public_body_category_translations"
belongs_to :public_body_category
end

class PublicBodyHeadingTranslation < ActiveRecord::Base
self.table_name = "public_body_heading_translations"
belongs_to :public_body_heading
end

class HasTagStringTag < ActiveRecord::Base
self.table_name = "has_tag_string_tags"
Expand Down Expand Up @@ -48,11 +39,11 @@ namespace :export do

to_run = to_run.split(",") if to_run

DataExport.csv_export(PublicBodyCategory, to_run)
DataExport.csv_export(PublicBodyHeading, to_run)
DataExport.csv_export(PublicBodyCategoryLink, to_run)
DataExport.csv_export(PublicBodyCategoryTranslation, to_run)
DataExport.csv_export(PublicBodyHeadingTranslation, to_run)
DataExport.csv_export(
Category, to_run, Category,
%w[id title description category_tag created_at updated_at]
)
DataExport.csv_export(CategoryRelationship, to_run)
DataExport.csv_export(InfoRequestBatchPublicBody, to_run)
DataExport.csv_export(HasTagStringTag,
to_run,
Expand Down
12 changes: 1 addition & 11 deletions spec/controllers/public_body_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -328,14 +328,7 @@ def make_single_language_example(locale)
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
PublicBodyCategory.destroy_all
PublicBodyHeading.destroy_all
PublicBodyCategoryLink.destroy_all

category = FactoryBot.create(:public_body_category)
heading = FactoryBot.create(:public_body_heading)
PublicBodyCategoryLink.create(public_body_heading_id: heading.id,
public_body_category_id: category.id)
category = FactoryBot.create(:category, :public_body, category_tag: 'dink')
public_bodies(:humpadink_public_body).tag_string = category.category_tag

get :list, params: { tag: category.category_tag }
Expand All @@ -351,10 +344,7 @@ def make_single_language_example(locale)
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)
]
)

Expand Down
3 changes: 0 additions & 3 deletions spec/models/public_body_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,6 @@
it 'should returns authorities without categories' do
pbs = PublicBody.with_tag('other')
expect(pbs).to match_array([
public_bodies(:geraldine_public_body),
public_bodies(:humpadink_public_body),
public_bodies(:silly_walks_public_body),
public_bodies(:sensible_walks_public_body),
public_bodies(:other_public_body)
])
Expand Down
Loading