1 # frozen_string_literal: true
5 class CapabilityTest < ActiveSupport::TestCase
7 AccessToken.new do |token|
9 token.public_send("#{t}=", true)
15 class UserCapabilityTest < CapabilityTest
16 test "user preferences" do
19 # a user with no tokens
20 capability = Capability.new create(:user), nil
21 [:read, :read_one, :update, :update_one, :delete_one].each do |act|
22 assert capability.can? act, UserPreference
25 # A user with empty tokens
26 capability = Capability.new create(:user), tokens
28 [:read, :read_one, :update, :update_one, :delete_one].each do |act|
29 assert capability.cannot? act, UserPreference
32 capability = Capability.new user, tokens(:allow_read_prefs)
34 [:update, :update_one, :delete_one].each do |act|
35 assert capability.cannot? act, UserPreference
38 [:read, :read_one].each do |act|
39 assert capability.can? act, UserPreference
42 capability = Capability.new user, tokens(:allow_write_prefs)
43 [:read, :read_one].each do |act|
44 assert capability.cannot? act, UserPreference
47 [:update, :update_one, :delete_one].each do |act|
48 assert capability.can? act, UserPreference