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 [:create, :destroy, :restore].each do |action|
12 assert ability.cannot? action, ChangesetComment
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 [:destroy, :restore].each do |action|
22 assert ability.cannot? action, ChangesetComment
25 [:create].each do |action|
26 assert ability.can? action, ChangesetComment
30 test "as a moderator without scopes" do
31 user = create(:moderator_user)
33 ability = ApiAbility.new user, scopes
35 [:create, :destroy, :restore].each do |action|
36 assert ability.cannot? action, ChangesetComment
40 test "as a moderator with write_changeset_comments scope" do
41 user = create(:moderator_user)
42 scopes = Set.new %w[write_changeset_comments]
43 ability = ApiAbility.new user, scopes
45 [:create, :destroy, :restore].each do |action|
46 assert ability.can? action, ChangesetComment
51 class NoteApiCapabilityTest < ActiveSupport::TestCase
52 test "as a normal user without scopes" do
55 ability = ApiAbility.new user, scopes
57 [:create, :comment, :close, :reopen, :destroy].each do |action|
58 assert ability.cannot? action, Note
62 test "as a normal user with write_notes scope" do
64 scopes = Set.new %w[write_notes]
65 ability = ApiAbility.new user, scopes
67 [:destroy].each do |action|
68 assert ability.cannot? action, Note
71 [:create, :comment, :close, :reopen].each do |action|
72 assert ability.can? action, Note
76 test "as a moderator without scopes" do
77 user = create(:moderator_user)
79 ability = ApiAbility.new user, scopes
81 [:destroy].each do |action|
82 assert ability.cannot? action, Note
86 test "as a moderator with write_notes scope" do
87 user = create(:moderator_user)
88 scopes = Set.new %w[write_notes]
89 ability = ApiAbility.new user, scopes
91 [:destroy].each do |action|
92 assert ability.can? action, Note
97 class UserApiCapabilityTest < ActiveSupport::TestCase
98 test "user preferences" do
101 ability = ApiAbility.new user, scopes
103 [:index, :show, :update_all, :update, :destroy].each do |act|
104 assert ability.cannot? act, UserPreference
107 scopes = Set.new %w[read_prefs]
108 ability = ApiAbility.new user, scopes
110 [:update_all, :update, :destroy].each do |act|
111 assert ability.cannot? act, UserPreference
114 [:index, :show].each do |act|
115 assert ability.can? act, UserPreference
118 scopes = Set.new %w[write_prefs]
119 ability = ApiAbility.new user, scopes
121 [:index, :show].each do |act|
122 assert ability.cannot? act, UserPreference
125 [:update_all, :update, :destroy].each do |act|
126 assert ability.can? act, UserPreference