Skip to content

Commit 6ce0bb1

Browse files
authored
AO3-6946 Fix manage collection items page sometimes showing unrelated works instead of bookmarks (#5114)
* AO3-6946 Add failing test for incorrect preload by includes * AO3-6946 Fix incorrect preload by include_for_works * Rubocop
1 parent 4e7b35f commit 6ce0bb1

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

app/models/collection_item.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def collection_is_open
3232
end
3333
end
3434

35-
scope :include_for_works, -> { includes(work: :pseuds)}
35+
scope :include_for_works, -> { includes(item: :pseuds) }
3636
scope :unrevealed, -> { where(unrevealed: true) }
3737
scope :anonymous, -> { where(anonymous: true) }
3838

spec/models/collection_item_spec.rb

+15
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,19 @@
7777
end
7878
end
7979
end
80+
81+
describe "include_for_works scope" do
82+
let(:collection) { create(:collection) }
83+
let(:work) { create(:work, id: 63) }
84+
let(:bookmark) { create(:bookmark, id: 63) }
85+
86+
before { bookmark.collections << collection }
87+
88+
it "returns the correct type item for bookmarks" do
89+
expect(work.id).to eq(bookmark.id)
90+
expect(collection.collection_items).not_to be_empty
91+
expect(collection.collection_items.first.item_type).to eq("Bookmark")
92+
expect(collection.collection_items.include_for_works.first.item_type).to eq("Bookmark")
93+
end
94+
end
8095
end

0 commit comments

Comments
 (0)