mirror of
https://github.com/discourse/discourse.git
synced 2025-09-06 10:50:21 +08:00
FEATURE: Polymorphic bookmarks pt. 1 (CRUD) (#16308)
This commit introduces a new use_polymorphic_bookmarks site setting that is default false and hidden, that will be used to help continuous development of polymorphic bookmarks. This setting **should not** be enabled anywhere in production yet, it is purely for local development. This commit uses the setting to enable create/update/delete actions for polymorphic bookmarks on the server and client side. The bookmark interactions on topics/posts are all usable. Listing, searching, sending bookmark reminders, and other edge cases will be handled in subsequent PRs. Comprehensive UI tests will be added in the final PR -- we already have them for regular bookmarks, so it will just be a matter of changing them to be for polymorphic bookmarks.
This commit is contained in:
parent
ff93833fdf
commit
b8828d4a2d
27 changed files with 711 additions and 127 deletions
|
@ -37,6 +37,29 @@ describe Bookmark do
|
|||
|
||||
expect(bookmark_3.valid?).to eq(false)
|
||||
end
|
||||
|
||||
describe "polymorphic bookmarks" do
|
||||
before do
|
||||
SiteSetting.use_polymorphic_bookmarks = true
|
||||
end
|
||||
|
||||
it "does not allow a user to create a bookmark with only one polymorphic column" do
|
||||
user = Fabricate(:user)
|
||||
bm = Bookmark.create(bookmarkable_id: post.id, user: user)
|
||||
expect(bm.errors.full_messages).to include(I18n.t("bookmarks.errors.bookmarkable_id_type_required"))
|
||||
bm = Bookmark.create(bookmarkable_type: "Post", user: user)
|
||||
expect(bm.errors.full_messages).to include(I18n.t("bookmarks.errors.bookmarkable_id_type_required"))
|
||||
bm = Bookmark.create(bookmarkable_type: "Post", bookmarkable_id: post.id, user: user)
|
||||
expect(bm.errors.full_messages).to be_empty
|
||||
end
|
||||
|
||||
it "does not allow a user to create a bookmark for the same record more than once" do
|
||||
user = Fabricate(:user)
|
||||
Bookmark.create(bookmarkable_type: "Post", bookmarkable_id: post.id, user: user)
|
||||
bm = Bookmark.create(bookmarkable_type: "Post", bookmarkable_id: post.id, user: user)
|
||||
expect(bm.errors.full_messages).to include(I18n.t("bookmarks.errors.already_bookmarked", type: "Post"))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "#find_for_topic_by_user" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue