Skip to content

Commit

Permalink
Remove references to PublicBodyCategory
Browse files Browse the repository at this point in the history
Replace PublicBodyCategory with Category. Only remaining references are
in the old models and temp rake tasks which migrates to the new Category
model.

Needed to change the expected public bodies returned in some RSpec test
examples due to differences in the fixture data.

Fixes #8179
  • Loading branch information
gbp committed Apr 11, 2024
1 parent 61b02a6 commit 86b3308
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 34 deletions.
10 changes: 5 additions & 5 deletions app/controllers/public_body_controller.rb
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_title}}’',
'Found {{count}} public authorities in the category ' \
'‘{{category_name}}’',
'‘{{category_title}}’',
@public_bodies.total_entries,
count: @public_bodies.total_entries,
category_name: category_name)
category_title: category.title)
end
end

Expand Down
4 changes: 3 additions & 1 deletion app/models/public_body.rb
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
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
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
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

0 comments on commit 86b3308

Please sign in to comment.