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
17 # a user with no tokens
18 capability = Capability.new nil
19 [:read, :read_one, :update, :update_one, :delete_one].each do |act|
20 assert capability.cannot? act, UserPreference
23 # A user with empty tokens
24 capability = Capability.new tokens
26 [:read, :read_one, :update, :update_one, :delete_one].each do |act|
27 assert capability.cannot? act, UserPreference
30 capability = Capability.new tokens(:allow_read_prefs)
32 [:update, :update_one, :delete_one].each do |act|
33 assert capability.cannot? act, UserPreference
36 [:read, :read_one].each do |act|
37 assert capability.can? act, UserPreference
40 capability = Capability.new tokens(:allow_write_prefs)
41 [:read, :read_one].each do |act|
42 assert capability.cannot? act, UserPreference
45 [:update, :update_one, :delete_one].each do |act|
46 assert capability.can? act, UserPreference