1 # frozen_string_literal: true
5 class ChangesetCommentApiCapabilityTest < ActiveSupport::TestCase
6 test "as a normal user without scopes" do
9 ability = ApiAbility.new user, scopes
11 assert ability.cannot? :create, ChangesetComment
12 assert ability.cannot? :create, :changeset_comment_visibility
13 assert ability.cannot? :destroy, :changeset_comment_visibility
16 test "as a normal user with write_changeset_comments scope" do
18 scopes = Set.new %w[write_changeset_comments]
19 ability = ApiAbility.new user, scopes
21 assert ability.can? :create, ChangesetComment
22 assert ability.cannot? :create, :changeset_comment_visibility
23 assert ability.cannot? :destroy, :changeset_comment_visibility
26 test "as a moderator without scopes" do
27 user = create(:moderator_user)
29 ability = ApiAbility.new user, scopes
31 assert ability.cannot? :create, ChangesetComment
32 assert ability.cannot? :create, :changeset_comment_visibility
33 assert ability.cannot? :destroy, :changeset_comment_visibility
36 test "as a moderator with write_changeset_comments scope" do
37 user = create(:moderator_user)
38 scopes = Set.new %w[write_changeset_comments]
39 ability = ApiAbility.new user, scopes
41 assert ability.can? :create, ChangesetComment
42 assert ability.can? :create, :changeset_comment_visibility
43 assert ability.can? :destroy, :changeset_comment_visibility
47 class NoteApiCapabilityTest < ActiveSupport::TestCase
48 test "as a normal user without scopes" do
51 ability = ApiAbility.new user, scopes
53 [:create, :comment, :close, :reopen, :destroy].each do |action|
54 assert ability.cannot? action, Note
58 test "as a normal user with write_notes scope" do
60 scopes = Set.new %w[write_notes]
61 ability = ApiAbility.new user, scopes
63 [:destroy].each do |action|
64 assert ability.cannot? action, Note
67 [:create, :comment, :close, :reopen].each do |action|
68 assert ability.can? action, Note
72 test "as a moderator without scopes" do
73 user = create(:moderator_user)
75 ability = ApiAbility.new user, scopes
77 [:destroy].each do |action|
78 assert ability.cannot? action, Note
82 test "as a moderator with write_notes scope" do
83 user = create(:moderator_user)
84 scopes = Set.new %w[write_notes]
85 ability = ApiAbility.new user, scopes
87 [:destroy].each do |action|
88 assert ability.can? action, Note
93 class UserApiCapabilityTest < ActiveSupport::TestCase
94 test "user preferences" do
97 ability = ApiAbility.new user, scopes
99 [:index, :show, :update_all, :update, :destroy].each do |act|
100 assert ability.cannot? act, UserPreference
103 scopes = Set.new %w[read_prefs]
104 ability = ApiAbility.new user, scopes
106 [:update_all, :update, :destroy].each do |act|
107 assert ability.cannot? act, UserPreference
110 [:index, :show].each do |act|
111 assert ability.can? act, UserPreference
114 scopes = Set.new %w[write_prefs]
115 ability = ApiAbility.new user, scopes
117 [:index, :show].each do |act|
118 assert ability.cannot? act, UserPreference
121 [:update_all, :update, :destroy].each do |act|
122 assert ability.can? act, UserPreference