]> git.openstreetmap.org Git - rails.git/blob - test/abilities/user_api_capability_test.rb
Merge remote-tracking branch 'upstream/pull/6787'
[rails.git] / test / abilities / user_api_capability_test.rb
1 # frozen_string_literal: true
2
3 require "test_helper"
4
5 class UserApiCapabilityTest < ActiveSupport::TestCase
6   test "user preferences" do
7     user = create(:user)
8     scopes = Set.new
9     ability = ApiAbility.new user, scopes
10
11     [:index, :show, :update_all, :update, :destroy].each do |act|
12       assert ability.cannot? act, UserPreference
13     end
14
15     scopes = Set.new %w[read_prefs]
16     ability = ApiAbility.new user, scopes
17
18     [:update_all, :update, :destroy].each do |act|
19       assert ability.cannot? act, UserPreference
20     end
21
22     [:index, :show].each do |act|
23       assert ability.can? act, UserPreference
24     end
25
26     scopes = Set.new %w[write_prefs]
27     ability = ApiAbility.new user, scopes
28
29     [:index, :show].each do |act|
30       assert ability.cannot? act, UserPreference
31     end
32
33     [:update_all, :update, :destroy].each do |act|
34       assert ability.can? act, UserPreference
35     end
36   end
37 end