From ecfb7c1d50970ef7a861a67619c9225dd1578fab Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 21 Feb 2024 16:35:25 +0100 Subject: [PATCH 1/2] 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 From 5d9023b6d46c6d5fa9cc8b6c3728e96133e74b34 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 21 Feb 2024 16:37:10 +0100 Subject: [PATCH 2/2] Display taggables a labels Looks nicer than the comma separated list. --- app/assets/stylesheets/alchemy/labels.scss | 5 +---- app/views/alchemy/admin/tags/_tag.html.erb | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/alchemy/labels.scss b/app/assets/stylesheets/alchemy/labels.scss index d4c2f1183b..2d109c4726 100644 --- a/app/assets/stylesheets/alchemy/labels.scss +++ b/app/assets/stylesheets/alchemy/labels.scss @@ -1,6 +1,3 @@ .label { - @include label-base( - $margin: $default-margin/2 0, - $padding: $default-padding 2*$default-padding $default-padding - ); + @include label-base($margin: 0, $padding: 0 2 * $default-padding); } diff --git a/app/views/alchemy/admin/tags/_tag.html.erb b/app/views/alchemy/admin/tags/_tag.html.erb index c51fb1a36b..7cfd951f39 100644 --- a/app/views/alchemy/admin/tags/_tag.html.erb +++ b/app/views/alchemy/admin/tags/_tag.html.erb @@ -2,7 +2,11 @@ <%= render_icon(:tag, size: "xl") %> <%= tag.name %> - <%= tag.taggings.collect(&:taggable).compact.map { |t| t.class.model_name.human }.uniq.join(', ') %> + <% tag.taggings.collect(&:taggable).compact.uniq.each do |taggable| %> + + <%= taggable.class.model_name.human %> + + <% end %> <%= tag.taggings.count %>