Sha256: 6ae16b7fab644f57166fe1898a7794f9e8120c7b2911cae7b3cd279cfc208321
Contents?: true
Size: 2 KB
Versions: 13
Compression:
Stored size: 2 KB
Contents
require 'rspec' require 'cantango' require 'fixtures/models' require 'cantango/api/current_user_accounts' # require 'cantango/configuration/engines/store_engine_shared' class User include_and_extend SimpleRoles end CanTango.configure do |config| config.users.register :user, :admin config.user_accounts.register :user, :admin config.cache_engine.set :off config.permit_engine.set :on end class UserRolePermit < CanTango::RolePermit def permit_rules can :edit, Article cannot :edit, User end end class AdminRolePermit < CanTango::RolePermit def permit_rules can :edit, Article cannot :edit, User end end class User include CanTango::Users::Masquerade end class Context include CanTango::Api::UserAccount::Can include ::CurrentUserAccounts extend ::CurrentUserAccounts end describe CanTango::Api::UserAccount::Can do subject { Context.new } describe 'user_account' do # user can edit Article, not Admin specify do subject.user_account_can?(:edit, Article).should be_true subject.user_account_can?(:edit, User).should be_false subject.user_account_cannot?(:edit, User).should be_true subject.user_account_cannot?(:edit, Article).should be_false end end describe 'admin_account' do specify do subject.admin_account_can?(:edit, Article).should be_true subject.admin_account_can?(:edit, User).should be_false subject.admin_account_cannot?(:edit, User).should be_true subject.admin_account_cannot?(:edit, Article).should be_false end end describe 'admin masquerades as user' do before do Context.current_admin.masquerade_as Context.current_user end # admin masquerading as user can do same as user specify do subject.admin_account_can?(:edit, Article).should be_true subject.admin_account_can?(:edit, User).should be_false subject.admin_account_cannot?(:edit, User).should be_true subject.admin_account_cannot?(:edit, Article).should be_false end end end
Version data entries
13 entries across 13 versions & 1 rubygems