X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/b29c173ac75a9de5bf46a5e0779169d076428268..8f70fb21146b1e8b90125e02d54e70bceea1d5fd:/test/abilities/capability_test.rb diff --git a/test/abilities/capability_test.rb b/test/abilities/capability_test.rb index a25c67043..8e77537a4 100644 --- a/test/abilities/capability_test.rb +++ b/test/abilities/capability_test.rb @@ -12,6 +12,48 @@ class CapabilityTest < ActiveSupport::TestCase end end +class ChangesetCommentCapabilityTest < CapabilityTest + test "as a normal user with permissionless token" do + token = create(:access_token) + capability = Capability.new token + + [:create, :destroy, :restore].each do |action| + assert capability.cannot? action, ChangesetComment + end + end + + test "as a normal user with allow_write_api token" do + token = create(:access_token, :allow_write_api => true) + capability = Capability.new token + + [:destroy, :restore].each do |action| + assert capability.cannot? action, ChangesetComment + end + + [:create].each do |action| + assert capability.can? action, ChangesetComment + end + end + + test "as a moderator with permissionless token" do + token = create(:access_token, :user => create(:moderator_user)) + capability = Capability.new token + + [:create, :destroy, :restore].each do |action| + assert capability.cannot? action, ChangesetComment + end + end + + test "as a moderator with allow_write_api token" do + token = create(:access_token, :user => create(:moderator_user), :allow_write_api => true) + capability = Capability.new token + + [:create, :destroy, :restore].each do |action| + assert capability.can? action, ChangesetComment + end + end +end + class UserCapabilityTest < CapabilityTest test "user preferences" do # a user with no tokens