mirror of
https://github.com/discourse/discourse.git
synced 2025-02-25 18:55:32 -06:00
FEATURE: Bookmark pinning (#12431)
Users can now pin bookmarks from their bookmark list. This will anchor the bookmark to the top of the list, and show a pin icon next to it. This also applies in the nav bookmarks panel. If there are multiple pinned bookmarks they sort by last updated order.
This commit is contained in:
@@ -159,7 +159,7 @@ RSpec.describe BookmarkManager do
|
||||
end
|
||||
|
||||
context "if the bookmark no longer exists" do
|
||||
it "raises an invalid access error" do
|
||||
it "raises a not found error" do
|
||||
expect { subject.destroy(9999) }.to raise_error(Discourse::NotFound)
|
||||
end
|
||||
end
|
||||
@@ -220,7 +220,7 @@ RSpec.describe BookmarkManager do
|
||||
before do
|
||||
bookmark.destroy!
|
||||
end
|
||||
it "raises an invalid access error" do
|
||||
it "raises a not found error" do
|
||||
expect { update_bookmark }.to raise_error(Discourse::NotFound)
|
||||
end
|
||||
end
|
||||
@@ -293,4 +293,36 @@ RSpec.describe BookmarkManager do
|
||||
Notification.where(notification_type: Notification.types[:bookmark_reminder], user_id: bookmark.user.id)
|
||||
end
|
||||
end
|
||||
|
||||
describe ".toggle_pin" do
|
||||
let!(:bookmark) { Fabricate(:bookmark, user: user) }
|
||||
|
||||
it "sets pinned to false if it is true" do
|
||||
bookmark.update(pinned: true)
|
||||
subject.toggle_pin(bookmark_id: bookmark.id)
|
||||
expect(bookmark.reload.pinned).to eq(false)
|
||||
end
|
||||
|
||||
it "sets pinned to true if it is false" do
|
||||
bookmark.update(pinned: false)
|
||||
subject.toggle_pin(bookmark_id: bookmark.id)
|
||||
expect(bookmark.reload.pinned).to eq(true)
|
||||
end
|
||||
|
||||
context "if the bookmark is belonging to some other user" do
|
||||
let!(:bookmark) { Fabricate(:bookmark, user: Fabricate(:admin)) }
|
||||
it "raises an invalid access error" do
|
||||
expect { subject.toggle_pin(bookmark_id: bookmark.id) }.to raise_error(Discourse::InvalidAccess)
|
||||
end
|
||||
end
|
||||
|
||||
context "if the bookmark no longer exists" do
|
||||
before do
|
||||
bookmark.destroy!
|
||||
end
|
||||
it "raises a not found error" do
|
||||
expect { subject.toggle_pin(bookmark_id: bookmark.id) }.to raise_error(Discourse::NotFound)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -173,6 +173,7 @@ RSpec.describe BookmarkQuery do
|
||||
let!(:bookmark3) { Fabricate(:bookmark, user: user, updated_at: 6.days.ago) }
|
||||
let!(:bookmark4) { Fabricate(:bookmark, user: user, updated_at: 4.days.ago) }
|
||||
let!(:bookmark5) { Fabricate(:bookmark, user: user, updated_at: 3.days.ago) }
|
||||
|
||||
it "orders by updated_at" do
|
||||
expect(bookmark_query.list_all.map(&:id)).to eq([
|
||||
bookmark1.id,
|
||||
@@ -182,5 +183,17 @@ RSpec.describe BookmarkQuery do
|
||||
bookmark3.id
|
||||
])
|
||||
end
|
||||
|
||||
it "puts pinned bookmarks first, in updated at order, then the rest in updated at order" do
|
||||
bookmark3.update_column(:pinned, true)
|
||||
bookmark4.update_column(:pinned, true)
|
||||
expect(bookmark_query.list_all.map(&:id)).to eq([
|
||||
bookmark4.id,
|
||||
bookmark3.id,
|
||||
bookmark1.id,
|
||||
bookmark2.id,
|
||||
bookmark5.id
|
||||
])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user