spec/cantango/api/can/account_spec.rb in cantango-api-0.0.0 vs spec/cantango/api/can/account_spec.rb in cantango-api-0.1.0
- old
+ new
@@ -1,53 +1,61 @@
-require 'spec_helper'
+require 'cantango/config'
+require 'fixtures/models'
-require 'helpers/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, User
+ config.users.register :user, User
config.users.register :admin, Admin
- config.accounts.register :user, UserAccount
+ config.accounts.register :user, UserAccount
config.accounts.register :admin, AdminAccount
-
- #config.cache_engine.set :off
- #config.permit_engine.set :on
+
+ config.modes.register :no_cache, CanTango::Ability::Mode::NoCache
+ config.ability.mode = :no_cache
end
-class UserRolePermit < CanTango::RolePermit
- def permit_rules
- can :edit, Article
- cannot :edit, User
- end
-end
+require 'spec_helper'
+require 'helpers/current_user_accounts'
-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 CanTango::Api::Can::Account
include_and_extend ::CurrentUserAccounts
end
-describe "CanTango::Api::Can::Account" do
+module CanTango::Ability::Mode
+ class NoCache
+ def calculate_rules
+ can :edit, Article
+ cannot :edit, User
+ end
+ end
+end
+
+describe CanTango::Api::Can::Account do
subject { Context.new }
describe 'user_account' do
+ specify do
+ subject.current_account_ability(:user).should be_a CanTango::Ability::Executor::Modal
+ end
+
+ specify do
+ subject.current_account_ability(:user).modes.should == [:no_cache]
+ end
+
+ specify do
+ subject.current_account_ability(:user).should respond_to(:can?)
+ end
+
+ specify do
+ subject.current_account_ability(:user).rules.should_not be_empty
+ end
+
+ specify do
+ subject.current_account_ability(:user).can?(:edit, Article).should be_true
+ end
+
# 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
@@ -55,24 +63,9 @@
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