class GuestApiAbilityTest < ApiAbilityTest
test "note permissions for a guest" do
- ability = ApiAbility.new nil
+ ability = ApiAbility.new nil, nil
[:index, :create, :feed, :show, :search].each do |action|
assert ability.can?(action, Note), "should be able to #{action} Notes"
class UserApiAbilityTest < ApiAbilityTest
test "Note permissions" do
- token = create(:oauth_access_token, :scopes => %w[write_notes])
- ability = ApiAbility.new token
+ user = create(:user)
+ token = create(:oauth_access_token, :user => user, :scopes => %w[write_notes])
+ ability = ApiAbility.new user, token
[:index, :create, :comment, :feed, :show, :search, :close, :reopen].each do |action|
assert ability.can?(action, Note), "should be able to #{action} Notes"
class ModeratorApiAbilityTest < ApiAbilityTest
test "Note permissions" do
- token = create(:oauth_access_token, :scopes => %w[write_notes], :user => create(:moderator_user))
- ability = ApiAbility.new token
+ user = create(:moderator_user)
+ token = create(:oauth_access_token, :user => user, :scopes => %w[write_notes])
+ ability = ApiAbility.new user, token
[:index, :create, :comment, :feed, :show, :search, :close, :reopen, :destroy].each do |action|
assert ability.can?(action, Note), "should be able to #{action} Notes"
class ChangesetCommentApiCapabilityTest < ActiveSupport::TestCase
test "as a normal user with permissionless token" do
- token = create(:oauth_access_token)
- ability = ApiAbility.new token
+ user = create(:user)
+ token = create(:oauth_access_token, :user => user)
+ ability = ApiAbility.new user, token
[:create, :destroy, :restore].each do |action|
assert ability.cannot? action, ChangesetComment
end
test "as a normal user with write_api token" do
- token = create(:oauth_access_token, :scopes => %w[write_api])
- ability = ApiAbility.new token
+ user = create(:user)
+ token = create(:oauth_access_token, :user => user, :scopes => %w[write_api])
+ ability = ApiAbility.new user, token
[:destroy, :restore].each do |action|
assert ability.cannot? action, ChangesetComment
end
test "as a moderator with permissionless token" do
- token = create(:oauth_access_token, :user => create(:moderator_user))
- ability = ApiAbility.new token
+ user = create(:moderator_user)
+ token = create(:oauth_access_token, :user => user)
+ ability = ApiAbility.new user, token
[:create, :destroy, :restore].each do |action|
assert ability.cannot? action, ChangesetComment
end
test "as a moderator with write_api token" do
- token = create(:oauth_access_token, :user => create(:moderator_user), :scopes => %w[write_api])
- ability = ApiAbility.new token
+ user = create(:moderator_user)
+ token = create(:oauth_access_token, :user => user, :scopes => %w[write_api])
+ ability = ApiAbility.new user, token
[:create, :destroy, :restore].each do |action|
assert ability.can? action, ChangesetComment
class NoteApiCapabilityTest < ActiveSupport::TestCase
test "as a normal user with permissionless token" do
- token = create(:oauth_access_token)
- ability = ApiAbility.new token
+ user = create(:user)
+ token = create(:oauth_access_token, :user => user)
+ ability = ApiAbility.new user, token
[:create, :comment, :close, :reopen, :destroy].each do |action|
assert ability.cannot? action, Note
end
test "as a normal user with write_notes token" do
- token = create(:oauth_access_token, :scopes => %w[write_notes])
- ability = ApiAbility.new token
+ user = create(:user)
+ token = create(:oauth_access_token, :user => user, :scopes => %w[write_notes])
+ ability = ApiAbility.new user, token
[:destroy].each do |action|
assert ability.cannot? action, Note
end
test "as a moderator with permissionless token" do
- token = create(:oauth_access_token, :user => create(:moderator_user))
- ability = ApiAbility.new token
+ user = create(:moderator_user)
+ token = create(:oauth_access_token, :user => user)
+ ability = ApiAbility.new user, token
[:destroy].each do |action|
assert ability.cannot? action, Note
end
test "as a moderator with write_notes token" do
- token = create(:oauth_access_token, :user => create(:moderator_user), :scopes => %w[write_notes])
- ability = ApiAbility.new token
+ user = create(:moderator_user)
+ token = create(:oauth_access_token, :user => user, :scopes => %w[write_notes])
+ ability = ApiAbility.new user, token
[:destroy].each do |action|
assert ability.can? action, Note
class UserApiCapabilityTest < ActiveSupport::TestCase
test "user preferences" do
# A user with empty tokens
- token = create(:oauth_access_token)
- ability = ApiAbility.new token
+ user = create(:user)
+ token = create(:oauth_access_token, :user => user)
+ ability = ApiAbility.new user, token
[:index, :show, :update_all, :update, :destroy].each do |act|
assert ability.cannot? act, UserPreference
end
- token = create(:oauth_access_token, :scopes => %w[read_prefs])
- ability = ApiAbility.new token
+ token = create(:oauth_access_token, :user => user, :scopes => %w[read_prefs])
+ ability = ApiAbility.new user, token
[:update_all, :update, :destroy].each do |act|
assert ability.cannot? act, UserPreference
assert ability.can? act, UserPreference
end
- token = create(:oauth_access_token, :scopes => %w[write_prefs])
- ability = ApiAbility.new token
+ token = create(:oauth_access_token, :user => user, :scopes => %w[write_prefs])
+ ability = ApiAbility.new user, token
[:index, :show].each do |act|
assert ability.cannot? act, UserPreference