From a8101609202230d4c1bf3afaf9c82511a44d8a97 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Thu, 29 Feb 2024 08:34:07 +0100 Subject: [PATCH] Fix taggable uniqueness in tags admin table We need to check the class for uniqueness check on the admin tags table, otherwise it will be duplicated. (cherry picked from commit ead8ec6b2a78af2905e6f3851c6a21f68fbd8c28) --- app/views/alchemy/admin/tags/_tag.html.erb | 2 +- spec/features/admin/tags_integration_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 spec/features/admin/tags_integration_spec.rb diff --git a/app/views/alchemy/admin/tags/_tag.html.erb b/app/views/alchemy/admin/tags/_tag.html.erb index 15da362c77..1fb82ad296 100644 --- a/app/views/alchemy/admin/tags/_tag.html.erb +++ b/app/views/alchemy/admin/tags/_tag.html.erb @@ -2,7 +2,7 @@ <%= render_icon :tag %> <%= tag.name %> - <% tag.taggings.collect(&:taggable).compact.uniq.each do |taggable| %> + <% tag.taggings.collect(&:taggable).compact.uniq(&:class).each do |taggable| %> <%= taggable.class.model_name.human %> diff --git a/spec/features/admin/tags_integration_spec.rb b/spec/features/admin/tags_integration_spec.rb new file mode 100644 index 0000000000..9156428745 --- /dev/null +++ b/spec/features/admin/tags_integration_spec.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +require "rails_helper" + +RSpec.describe "Tags", type: :system do + let!(:picture) { create(:alchemy_picture, tag_list: "Foo") } + let!(:picture2) { create(:alchemy_picture, tag_list: "Foo") } + let!(:a_page) { create(:alchemy_page, tag_list: "Bar") } + + before { authorize_user(:as_admin) } + + describe "index view" do + it "should list taggable class names" do + visit "/admin/tags" + expect(page).to have_selector(".label", text: "Picture", count: 1) + expect(page).to have_selector(".label", text: "Page", count: 1) + end + end +end