mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-04 09:16:52 +08:00
1. Make consistent use of `is_me?`, `is_my_own?`, etc. since these are more robust and don't use the `user` accessor method (soon to be deprecated) directly. 2. Add missing test coverage for `BookmarkGuardian` methods.
27 lines
819 B
Ruby
27 lines
819 B
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe BookmarkGuardian do
|
|
fab!(:user)
|
|
fab!(:moderator)
|
|
fab!(:bookmark) { Fabricate(:bookmark, user:) }
|
|
|
|
describe "#can_delete_bookmark?" do
|
|
it "returns true when user owns the bookmark" do
|
|
expect(Guardian.new(user).can_delete_bookmark?(bookmark)).to eq(true)
|
|
end
|
|
|
|
it "returns false when user doesn't own the bookmark" do
|
|
expect(Guardian.new(moderator).can_delete_bookmark?(bookmark)).to eq(false)
|
|
end
|
|
end
|
|
|
|
describe "#can_edit_bookmark?" do
|
|
it "returns true when user owns the bookmark" do
|
|
expect(Guardian.new(user).can_delete_bookmark?(bookmark)).to eq(true)
|
|
end
|
|
|
|
it "returns false when user doesn't own the bookmark" do
|
|
expect(Guardian.new(moderator).can_delete_bookmark?(bookmark)).to eq(false)
|
|
end
|
|
end
|
|
end
|