mirror of
https://github.com/discourse/discourse.git
synced 2024-11-29 20:24:05 -06:00
fcc2e7ebbf
This commit migrates all bookmarks to be polymorphic (using the bookmarkable_id and bookmarkable_type) columns. It also deletes all the old code guarded behind the use_polymorphic_bookmarks setting and changes that setting to true for all sites and by default for the sake of plugins. No data is deleted in the migrations, the old post_id and for_topic columns for bookmarks will be dropped later on.
53 lines
1.9 KiB
Ruby
53 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe Jobs::SyncTopicUserBookmarked do
|
|
fab!(:topic) { Fabricate(:topic) }
|
|
fab!(:post1) { Fabricate(:post, topic: topic) }
|
|
fab!(:post2) { Fabricate(:post, topic: topic) }
|
|
fab!(:post3) { Fabricate(:post, topic: topic) }
|
|
|
|
fab!(:tu1) { Fabricate(:topic_user, topic: topic, bookmarked: false) }
|
|
fab!(:tu2) { Fabricate(:topic_user, topic: topic, bookmarked: false) }
|
|
fab!(:tu3) { Fabricate(:topic_user, topic: topic, bookmarked: true) }
|
|
fab!(:tu4) { Fabricate(:topic_user, topic: topic, bookmarked: true) }
|
|
fab!(:tu5) { Fabricate(:topic_user, topic: topic, bookmarked: true) }
|
|
|
|
it "corrects all topic_users.bookmarked records for the topic" do
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: topic.posts.sample)
|
|
Fabricate(:bookmark, user: tu4.user, bookmarkable: topic.posts.sample)
|
|
|
|
subject.execute(topic_id: topic.id)
|
|
|
|
expect(tu1.reload.bookmarked).to eq(true)
|
|
expect(tu2.reload.bookmarked).to eq(false)
|
|
expect(tu3.reload.bookmarked).to eq(false)
|
|
expect(tu4.reload.bookmarked).to eq(true)
|
|
expect(tu5.reload.bookmarked).to eq(false)
|
|
end
|
|
|
|
it "does not consider topic as bookmarked if the bookmarked post is deleted" do
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: post1)
|
|
Fabricate(:bookmark, user: tu2.user, bookmarkable: post1)
|
|
|
|
post1.trash!
|
|
|
|
subject.execute(topic_id: topic.id)
|
|
|
|
expect(tu1.reload.bookmarked).to eq(false)
|
|
expect(tu2.reload.bookmarked).to eq(false)
|
|
end
|
|
|
|
it "works when no topic id is provided (runs for all topics)" do
|
|
Fabricate(:bookmark, user: tu1.user, bookmarkable: topic.posts.sample)
|
|
Fabricate(:bookmark, user: tu4.user, bookmarkable: topic.posts.sample)
|
|
|
|
subject.execute
|
|
|
|
expect(tu1.reload.bookmarked).to eq(true)
|
|
expect(tu2.reload.bookmarked).to eq(false)
|
|
expect(tu3.reload.bookmarked).to eq(false)
|
|
expect(tu4.reload.bookmarked).to eq(true)
|
|
expect(tu5.reload.bookmarked).to eq(false)
|
|
end
|
|
end
|