From ecfb7c1d50970ef7a861a67619c9225dd1578fab Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 21 Feb 2024 16:35:25 +0100 Subject: [PATCH] Fix tags view for missing taggables When the taggable has been deleted it is nil in this collection and model_name is not available on NilClass --- app/views/alchemy/admin/tags/_tag.html.erb | 2 +- .../alchemy/admin/tags_controller_spec.rb | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/app/views/alchemy/admin/tags/_tag.html.erb b/app/views/alchemy/admin/tags/_tag.html.erb index 66f60f322d..c51fb1a36b 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, size: "xl") %> <%= tag.name %> - <%= tag.taggings.collect(&:taggable).collect { |t| t.class.model_name.human }.uniq.join(', ') %> + <%= tag.taggings.collect(&:taggable).compact.map { |t| t.class.model_name.human }.uniq.join(', ') %> <%= tag.taggings.count %> diff --git a/spec/controllers/alchemy/admin/tags_controller_spec.rb b/spec/controllers/alchemy/admin/tags_controller_spec.rb index 77f101d8d7..4fd7ebc25a 100644 --- a/spec/controllers/alchemy/admin/tags_controller_spec.rb +++ b/spec/controllers/alchemy/admin/tags_controller_spec.rb @@ -10,10 +10,26 @@ module Admin before { authorize_user(:as_admin) } describe "#index" do + render_views + + let!(:picture) { create(:alchemy_picture, tag_list: "Foo,Bar") } + it "renders index template" do get :index expect(response).to be_successful end + + context "with taggable missing" do + before do + picture.thumbs.destroy_all + picture.delete + end + + it "does not raise error" do + get :index + expect(response).to be_successful + end + end end describe "#create" do