discourse/spec/lib/guardian/bookmark_guardian_spec.rb
Ted Johansson a93b6a2214
DEV: Consistently use Guardian helper methods (#34024)
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.
2025-08-14 15:23:42 +08:00

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