Skip to content

Commit

Permalink
Fix tags view for missing taggables
Browse files Browse the repository at this point in the history
When the taggable has been deleted it is nil in this collection
and model_name is not available on NilClass
  • Loading branch information
tvdeyen committed Feb 21, 2024
1 parent b679b86 commit ecfb7c1
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/views/alchemy/admin/tags/_tag.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<td class="icon"><%= render_icon(:tag, size: "xl") %></td>
<td class="name"><%= tag.name %></td>
<td>
<%= 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(', ') %>
</td>
<td class="count"><%= tag.taggings.count %></td>
<td class="tools">
Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/alchemy/admin/tags_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ecfb7c1

Please sign in to comment.