Skip to content

Commit

Permalink
AO3-5259 Deduplicate and order admin post tags
Browse files Browse the repository at this point in the history
  • Loading branch information
neuroalien committed Nov 10, 2023
1 parent d876523 commit e3b71c0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/admin_posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def index
@admin_posts ||= AdminPost
if params[:language_id].present? && (@language = Language.find_by(short: params[:language_id]))
@admin_posts = @admin_posts.where(language_id: @language.id)
@tags = AdminPostTag.joins(:admin_posts).where(admin_posts: { language_id: @language.id })
@tags = AdminPostTag.distinct.joins(:admin_posts).where(admin_posts: { language_id: @language.id }).order(:name)
else
@admin_posts = @admin_posts.non_translated
@tags = AdminPostTag.order(:name)
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/admin_posts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@
include LoginMacros
include RedirectExpectationHelper

describe "GET #index" do
context "when filtering by language" do
let(:translated_post1) { create(:admin_post, tag_list: "xylophone,aardvark") }
let!(:translation_post1) { create(:admin_post, translated_post_id: translated_post1.id, language: create(:language, short: "fr")) }
let(:translated_post2) { create(:admin_post, tag_list: "xylophone,aardvark") }
let!(:translation_post2) { create(:admin_post, translated_post_id: translated_post2.id, language: translation_post1.language) }
let!(:untranslated_post) { create(:admin_post, tag_list: "uncommon tag")}

it "assigns the admin post tags for the language ordered by name" do
get :index, params: { language_id: "fr" }

expect(assigns[:tags].map(&:name).join(", ")).to eql("aardvark, xylophone")
end
end
end

describe "POST #create" do
before { fake_login_admin(create(:admin, roles: ["communications"])) }

Expand Down

0 comments on commit e3b71c0

Please sign in to comment.