cantango-permits 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +1 -0
- data/Gemfile +39 -0
- data/Gemfile.lock +155 -0
- data/MIT-LICENSE +20 -0
- data/README.mdown +362 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/cantango/executor.rb +5 -0
- data/lib/cantango/executor/base.rb +9 -0
- data/lib/cantango/executor/permit.rb +7 -0
- data/lib/cantango/executor/permit/abstract.rb +27 -0
- data/lib/cantango/executor/permit/base.rb +19 -0
- data/lib/cantango/executor/permit/special.rb +9 -0
- data/lib/cantango/executor/permit_type.rb +50 -0
- data/lib/cantango/license.rb +19 -0
- data/lib/cantango/license/rules.rb +17 -0
- data/lib/cantango/permit.mdown +4 -0
- data/lib/cantango/permit.rb +5 -0
- data/lib/cantango/permit/account_type.rb +44 -0
- data/lib/cantango/permit/attribute.rb +71 -0
- data/lib/cantango/permit/base.rb +94 -0
- data/lib/cantango/permit/class_methods.rb +49 -0
- data/lib/cantango/permit/helper.rb +11 -0
- data/lib/cantango/permit/helper/execution.rb +38 -0
- data/lib/cantango/permit/helper/host.rb +13 -0
- data/lib/cantango/permit/helper/license.rb +34 -0
- data/lib/cantango/permit/helper/naming.rb +38 -0
- data/lib/cantango/permit/helper/state.rb +21 -0
- data/lib/cantango/permit/special.rb +17 -0
- data/lib/cantango/permit/user.rb +36 -0
- data/lib/cantango/permit/user_type.rb +34 -0
- data/lib/cantango/permits.rb +20 -0
- data/lib/cantango/permits_ext.rb +7 -0
- data/lib/cantango/permits_ext/ability.rb +7 -0
- data/lib/cantango/permits_ext/ability/helper.rb +9 -0
- data/lib/cantango/permits_ext/ability/helper/permits.rb +8 -0
- data/lib/cantango/permits_ext/builder.rb +7 -0
- data/lib/cantango/permits_ext/builder/permit.rb +9 -0
- data/lib/cantango/permits_ext/builder/permit/account_type.rb +13 -0
- data/lib/cantango/permits_ext/builder/permit/base.rb +94 -0
- data/lib/cantango/permits_ext/builder/permit/special.rb +13 -0
- data/lib/cantango/permits_ext/builder/permit/user_type.rb +7 -0
- data/lib/cantango/permits_ext/class_methods.rb +28 -0
- data/lib/cantango/permits_ext/config.rb +11 -0
- data/lib/cantango/permits_ext/config/engines.rb +9 -0
- data/lib/cantango/permits_ext/config/engines/permit.rb +20 -0
- data/lib/cantango/permits_ext/config/permits.rb +43 -0
- data/lib/cantango/permits_ext/config/permits/accounts.rb +15 -0
- data/lib/cantango/permits_ext/config/permits/disabling.rb +22 -0
- data/lib/cantango/permits_ext/config/permits/enabling.rb +14 -0
- data/lib/cantango/permits_ext/config/permits/execution.rb +21 -0
- data/lib/cantango/permits_ext/config/permits/key.rb +19 -0
- data/lib/cantango/permits_ext/config/permits/registration.rb +33 -0
- data/lib/cantango/permits_ext/config/permits/tracking.rb +19 -0
- data/lib/cantango/permits_ext/config/permits/types.rb +25 -0
- data/lib/cantango/permits_ext/engine.rb +7 -0
- data/lib/cantango/permits_ext/engine/permits.rb +75 -0
- data/lib/cantango/permits_ext/factory.rb +7 -0
- data/lib/cantango/permits_ext/factory/permits.rb +40 -0
- data/lib/cantango/permits_ext/finder.rb +7 -0
- data/lib/cantango/permits_ext/finder/base.rb +35 -0
- data/lib/cantango/permits_ext/finder/permit.rb +7 -0
- data/lib/cantango/permits_ext/finder/permit/account.rb +47 -0
- data/lib/cantango/permits_ext/finder/permit/base.rb +53 -0
- data/lib/cantango/permits_ext/loader.rb +7 -0
- data/lib/cantango/permits_ext/loader/categories.rb +50 -0
- data/lib/cantango/permits_ext/loader/license.rb +19 -0
- data/lib/cantango/permits_ext/macros.rb +7 -0
- data/lib/cantango/permits_ext/macros/permit.rb +32 -0
- data/lib/cantango/permits_ext/parser.rb +7 -0
- data/lib/cantango/permits_ext/parser/categories.rb +15 -0
- data/lib/cantango/permits_ext/registry.rb +7 -0
- data/lib/cantango/permits_ext/registry/permit.rb +45 -0
- data/lib/generators/cantango/account_permit/account_permit_generator.rb +37 -0
- data/lib/generators/cantango/account_permit/templates/account_permit.erb +23 -0
- data/lib/generators/cantango/base.rb +71 -0
- data/lib/generators/cantango/basic.rb +41 -0
- data/lib/generators/cantango/license/license_generator.rb +29 -0
- data/lib/generators/cantango/license/templates/license.erb +10 -0
- data/lib/generators/cantango/license_base.rb +15 -0
- data/lib/generators/cantango/licenses/licenses_generator.rb +26 -0
- data/lib/generators/cantango/permit_generator.rb +58 -0
- data/lib/generators/cantango/role_permit/role_permit_generator.rb +39 -0
- data/lib/generators/cantango/role_permit/templates/account_permit.erb +4 -0
- data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +24 -0
- data/lib/generators/cantango/role_permit/templates/role_permit.erb +23 -0
- data/lib/generators/cantango/role_permits/role_permits_generator.rb +45 -0
- data/lib/generators/cantango/user_permit/templates/account_permit.erb +5 -0
- data/lib/generators/cantango/user_permit/templates/user_permit.erb +23 -0
- data/lib/generators/cantango/user_permit/user_permit_generator.rb +36 -0
- data/lib/tasks/permits_tasks.rake +4 -0
- data/spec/cantango/ability/helper/permits_spec.rb +14 -0
- data/spec/cantango/builder/permit/account_type_spec.rb +25 -0
- data/spec/cantango/builder/permit/base_spec.rb +30 -0
- data/spec/cantango/builder/permit/special_spec.rb +25 -0
- data/spec/cantango/builder/permit/user_type_spec.rb +27 -0
- data/spec/cantango/config/engines/permit_spec.rb +14 -0
- data/spec/cantango/config/engines_spec.rb +142 -0
- data/spec/cantango/config/permit_registry_ex.rb +9 -0
- data/spec/cantango/config/permit_registry_spec.rb +8 -0
- data/spec/cantango/config/permits/accounts_spec.rb +23 -0
- data/spec/cantango/config/permits/disabling_spec.rb +38 -0
- data/spec/cantango/config/permits/enabling_spec.rb +19 -0
- data/spec/cantango/config/permits/execution_spec.rb +27 -0
- data/spec/cantango/config/permits/registration_spec.rb +15 -0
- data/spec/cantango/config/permits/tracking_spec.rb +19 -0
- data/spec/cantango/config/permits/types_spec.rb +27 -0
- data/spec/cantango/config/permits_spec.rb +76 -0
- data/spec/cantango/engine/permit_cached_spec.rb +52 -0
- data/spec/cantango/engine/permit_spec.rb +58 -0
- data/spec/cantango/engine/permit_static_dynamic_spec.rb +65 -0
- data/spec/cantango/executor/custom_permit_spec.rb +65 -0
- data/spec/cantango/executor/more_permit_spec.rb +45 -0
- data/spec/cantango/executor/permit_base_spec.rb +46 -0
- data/spec/cantango/executor/permit_spec.rb +53 -0
- data/spec/cantango/executor/special_permit_spec.rb +36 -0
- data/spec/cantango/factory/permits_spec.rb +70 -0
- data/spec/cantango/finder/account_permit_spec.rb +30 -0
- data/spec/cantango/finder/permit_spec.rb +23 -0
- data/spec/cantango/license/save_license_spec.rb +24 -0
- data/spec/cantango/license_spec.rb +0 -0
- data/spec/cantango/loader/categories_spec.rb +47 -0
- data/spec/cantango/loader/license_spec.rb +7 -0
- data/spec/cantango/macros/permit_spec.rb +38 -0
- data/spec/cantango/parser/categories_spec.rb +19 -0
- data/spec/cantango/permit/account_type_spec.rb +34 -0
- data/spec/cantango/permit/attribute_permit_spec.rb +65 -0
- data/spec/cantango/permit/base_spec.rb +106 -0
- data/spec/cantango/permit/class_methods_spec.rb +34 -0
- data/spec/cantango/permit/helper/execution_spec.rb +54 -0
- data/spec/cantango/permit/helper/host_spec.rb +29 -0
- data/spec/cantango/permit/helper/license_spec.rb +37 -0
- data/spec/cantango/permit/helper/naming_spec.rb +56 -0
- data/spec/cantango/permit/helper/state_spec.rb +24 -0
- data/spec/cantango/permit/special_default_spec.rb +2 -0
- data/spec/cantango/permit/special_first_spec.rb +2 -0
- data/spec/cantango/permit/user_type_spec.rb +78 -0
- data/spec/cantango/registry/permit_spec.rb +67 -0
- data/spec/fixtures/config/cantango_permissions.yml +49 -0
- data/spec/fixtures/config/categories.yml +6 -0
- data/spec/fixtures/config/evaluator_fixtures.yml +18 -0
- data/spec/fixtures/config/licenses.yml +4 -0
- data/spec/fixtures/config/permissions.yml +60 -0
- data/spec/fixtures/config/role_group.yml +4 -0
- data/spec/fixtures/config/roles.yml +4 -0
- data/spec/fixtures/config/test_permissions.yml +55 -0
- data/spec/fixtures/config/user_permissions.yml +8 -0
- data/spec/fixtures/models.rb +15 -0
- data/spec/fixtures/models/admin.rb +2 -0
- data/spec/fixtures/models/admin_account.rb +22 -0
- data/spec/fixtures/models/items.rb +11 -0
- data/spec/fixtures/models/permission.rb +12 -0
- data/spec/fixtures/models/simple_roles.rb +49 -0
- data/spec/fixtures/models/user.rb +52 -0
- data/spec/fixtures/models/user_account.rb +21 -0
- data/spec/fixtures/tango_fixtures.rb +29 -0
- data/spec/generators/cantango/account_role_permit_generator_spec.rb +35 -0
- data/spec/generators/cantango/account_role_permits_generator_spec.rb +59 -0
- data/spec/generators/cantango/license_generator_spec.rb +33 -0
- data/spec/generators/cantango/licenses_generator_spec.rb +58 -0
- data/spec/generators/cantango/role_permit_generator_spec.rb +35 -0
- data/spec/generators/cantango/role_permits_generator_spec.rb +58 -0
- data/spec/helpers/current_user_accounts.rb +20 -0
- data/spec/helpers/current_users.rb +10 -0
- data/spec/spec_helper.rb +24 -0
- metadata +325 -0
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'cantango'
|
3
|
+
require 'fixtures/models'
|
4
|
+
require 'cantango/rspec'
|
5
|
+
|
6
|
+
def config_folder
|
7
|
+
File.dirname(__FILE__)+ "/../fixtures/config/"
|
8
|
+
end
|
9
|
+
|
10
|
+
CanTango.configure do |config|
|
11
|
+
config.clear!
|
12
|
+
config.ability.mode = :no_cache
|
13
|
+
config.engine(:permit).set :on
|
14
|
+
config.debug!
|
15
|
+
end
|
16
|
+
|
17
|
+
class UserPermit < CanTango::Permit::UserType
|
18
|
+
def initialize ability
|
19
|
+
super
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def calc_rules
|
25
|
+
can :read, Article
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe CanTango::Engine::Permit do
|
30
|
+
context 'cache' do
|
31
|
+
before do
|
32
|
+
@user = User.new 'kris', 'kris@mail.ru', :roles => [:editor]
|
33
|
+
@ability = CanTango::Ability::Base.new @user
|
34
|
+
end
|
35
|
+
|
36
|
+
subject { CanTango::PermitEngine.new ability }
|
37
|
+
|
38
|
+
describe '#execute!' do
|
39
|
+
before do
|
40
|
+
subject.execute!
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'engine should have rules' do
|
44
|
+
subject.send(:rules).should_not be_empty
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'engine cache should have rules' do
|
48
|
+
subject.cache.empty?.should be_false
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'cantango'
|
3
|
+
require 'fixtures/models'
|
4
|
+
require 'cantango/rspec'
|
5
|
+
|
6
|
+
def config_folder
|
7
|
+
File.dirname(__FILE__)+ "/../fixtures/config/"
|
8
|
+
end
|
9
|
+
|
10
|
+
CanTango.configure do |config|
|
11
|
+
config.clear!
|
12
|
+
config.ability.mode = :no_cache
|
13
|
+
config.engine(:permit) do |engine|
|
14
|
+
engine.mode = :no_cache
|
15
|
+
end
|
16
|
+
config.debug!
|
17
|
+
end
|
18
|
+
|
19
|
+
class UserPermit < CanTango::UserPermit
|
20
|
+
def initialize ability
|
21
|
+
super
|
22
|
+
end
|
23
|
+
|
24
|
+
protected
|
25
|
+
|
26
|
+
def calc_rules
|
27
|
+
can :read, Article
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe CanTango::PermitEngine do
|
32
|
+
context 'no-cache' do
|
33
|
+
before do
|
34
|
+
@user = User.new 'kris', 'kris@mail.ru', :roles => [:editor]
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'Permit engine' do
|
38
|
+
let (:ability) do
|
39
|
+
CanTango::Ability.new @user
|
40
|
+
end
|
41
|
+
subject { CanTango::PermitEngine.new ability }
|
42
|
+
|
43
|
+
describe '#execute!' do
|
44
|
+
before do
|
45
|
+
subject.execute!
|
46
|
+
end
|
47
|
+
|
48
|
+
it 'engine should have rules' do
|
49
|
+
subject.send(:rules).should_not be_empty
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'engine cache should be empty' do
|
53
|
+
subject.cache.empty?.should be_true
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class UserRolePermit < CanTango::Permit::Role
|
5
|
+
def initialize ability
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def calc_rules
|
12
|
+
can(:read, Post) if $test == true
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class AdminRolePermit < CanTango::Permit::Role
|
17
|
+
def initialize ability
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
protected
|
22
|
+
|
23
|
+
def calc_rules
|
24
|
+
can(:read, Article) do |article|
|
25
|
+
$test == true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe CanTango::Permits::Permit::Role do
|
31
|
+
before do
|
32
|
+
@user = User.new 'kris', 'kris@mail.ru', :roles => [:editor]
|
33
|
+
@ua = UserAccount.new user, :roles => [:admin, :user], :role_groups => []
|
34
|
+
@user.account = @ua
|
35
|
+
|
36
|
+
@ability = CanTango::Ability::Base.new user_account
|
37
|
+
@permit = AdminRolePermit.new ability
|
38
|
+
end
|
39
|
+
|
40
|
+
before(:each) do
|
41
|
+
CanTango.configure do |config|
|
42
|
+
config.engine(:permit).set :on
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'Having some dynamic conditions based on global things' do
|
47
|
+
it "shoud react if global thing changed" do
|
48
|
+
pending
|
49
|
+
$test = true
|
50
|
+
ability.can?(:read, Article.new).should == true
|
51
|
+
$test = false
|
52
|
+
ability.can?(:read, Article.new).should == false
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe 'Having some dynamic conditions based on global things' do
|
57
|
+
it "shoud react if global thing changed" do
|
58
|
+
pending "Need to reveal CanCan's situation and caching"
|
59
|
+
#$test = true
|
60
|
+
#ability.can?(:read, Post.new).should == true
|
61
|
+
#$test = false
|
62
|
+
#ability.can?(:read, Post.new).should == false
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class MembershipPermit < CanTango::Permit::Attribute
|
5
|
+
class Builder < CanTango::Permit::Attribute::Builder
|
6
|
+
attribute :membership
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.inherited(base_clazz)
|
10
|
+
register base_clazz, :name => attribute_name(base_clazz)
|
11
|
+
end
|
12
|
+
|
13
|
+
# attribute :membership
|
14
|
+
end
|
15
|
+
|
16
|
+
class CanTango::Ability::Base
|
17
|
+
def subject
|
18
|
+
candidate
|
19
|
+
end
|
20
|
+
|
21
|
+
def user
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class AdminMembershipPermit < MembershipPermit
|
27
|
+
protected
|
28
|
+
|
29
|
+
def calc_rules
|
30
|
+
can :read, Article
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Admin
|
35
|
+
def memberships
|
36
|
+
[:admin]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'Custom Permit registration - Membership' do
|
41
|
+
it 'should register :membership as available permit' do
|
42
|
+
CanTango.config.permits.registered_for(:membership, :admin).should == AdminMembershipPermit
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should register :membership as available permit type' do
|
46
|
+
CanTango.config.permits.types.available.should include(:membership)
|
47
|
+
end
|
48
|
+
|
49
|
+
before do
|
50
|
+
@user = Admin.new 'kris', 'kris@mail.ru'
|
51
|
+
@ability = CanTango::Ability::Base.new @user
|
52
|
+
@permit = AdminMembershipPermit.new @ability
|
53
|
+
@executor = CanTango::Executor::Permit::Base.new @permit
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#execute!' do
|
57
|
+
describe 'should define read Article rule' do
|
58
|
+
specify do
|
59
|
+
@executor.execute!
|
60
|
+
@executor.permit.rules.should_not be_empty
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module AdminAccountPermits
|
4
|
+
class AdminRolePermit < CanTango::Permit::Role
|
5
|
+
end
|
6
|
+
end
|
7
|
+
|
8
|
+
class MusicianRolePermit < CanTango::Permit::Role; end
|
9
|
+
class EditorsRoleGroupPermit < CanTango::Permit::RoleGroup; end
|
10
|
+
class AdminAccountPermit < CanTango::Permit::AccountType; end
|
11
|
+
class AdminPermit < CanTango::Permit::UserType; end
|
12
|
+
|
13
|
+
describe CanTango::Permit do
|
14
|
+
|
15
|
+
it "should register RolePermit-based permits" do
|
16
|
+
CanTango.config.permits.admin_account.role[:admin].should == AdminAccountPermits::AdminRolePermit
|
17
|
+
CanTango.config.permits.role[:musician].should == MusicianRolePermit
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should register RoleGroupPermit-based permits" do
|
21
|
+
CanTango.config.permits.role_group[:editors].should == EditorsRoleGroupPermit
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should register UserPermit-based permits" do
|
25
|
+
CanTango.config.permits.user[:admin].should == AdminPermit
|
26
|
+
end
|
27
|
+
it "should register AccountPermit-based permits" do
|
28
|
+
CanTango.config.permits.account[:admin].should == AdminAccountPermit
|
29
|
+
end
|
30
|
+
|
31
|
+
context "registration of double-inherited permits (fx RolePermit ones) - specially for Kris ;)" do
|
32
|
+
before do
|
33
|
+
class GuitaristRolePermit < MusicianRolePermit; end
|
34
|
+
class AdminAccountPermits::AngryAdminRolePermit < AdminAccountPermits::AdminRolePermit; end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should register basic namespaced" do
|
38
|
+
CanTango.config.permits.role[:guitarist].should == GuitaristRolePermit
|
39
|
+
end
|
40
|
+
|
41
|
+
it "should register account-namespaced" do
|
42
|
+
CanTango.config.permits.admin_account.role[:angry_admin].should == AdminAccountPermits::AngryAdminRolePermit
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class AdminPermit < CanTango::Permit::UserType
|
5
|
+
def initialize ability
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def calc_rules
|
12
|
+
can :read, Article
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class CanTango::Ability::Base
|
17
|
+
def subject
|
18
|
+
candidate
|
19
|
+
end
|
20
|
+
|
21
|
+
def user
|
22
|
+
subject
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe CanTango::Executor::Permit::Base do
|
27
|
+
before do
|
28
|
+
@user = Admin.new 'kris', 'kris@mail.ru'
|
29
|
+
@ability = CanTango::Ability::Base.new @user
|
30
|
+
@permit = AdminPermit.new @ability
|
31
|
+
@executor = CanTango::Executor::Permit::Base.new @permit
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#execute!' do
|
35
|
+
describe 'should find permit based on #user_type' do
|
36
|
+
specify { lambda{ @executor.execute! }.should_not raise_error }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'should define read Article rule' do
|
40
|
+
specify do
|
41
|
+
@executor.execute!
|
42
|
+
@executor.permit.rules.should_not be_empty
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class AdminPermit < CanTango::Permit::UserType
|
5
|
+
def initialize ability
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def no_cache_rules
|
12
|
+
can :edit, Article
|
13
|
+
can :delete, Article
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class CanTango::Ability::Base
|
18
|
+
def subject
|
19
|
+
candidate
|
20
|
+
end
|
21
|
+
|
22
|
+
def user
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe CanTango::Executor::Permit::Base do
|
28
|
+
context 'non-cached only' do
|
29
|
+
before do
|
30
|
+
CanTango.configure.ability.modes.execution.register :no_cache
|
31
|
+
|
32
|
+
@admin = Admin.new 'kris', 'kris@mail.ru'
|
33
|
+
@ability = CanTango::Ability::Base.new @admin
|
34
|
+
@permit = AdminPermit.new @ability
|
35
|
+
@executor = CanTango::Executor::Permit::Base.new @permit
|
36
|
+
end
|
37
|
+
|
38
|
+
subject { @executor }
|
39
|
+
|
40
|
+
describe 'config no_cache' do
|
41
|
+
specify { CanTango.configure.ability.modes.execution.registered.should == [:no_cache] }
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'rules contain only non-cached rules' do
|
45
|
+
before do
|
46
|
+
subject.execute!
|
47
|
+
end
|
48
|
+
it 'should have 2 rules' do
|
49
|
+
subject.rules.size.should == @ability.rules.size
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class SystemPermit < CanTango::Permit::Special
|
5
|
+
def initialize ability
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def calc_rules
|
12
|
+
can :read, Article
|
13
|
+
can :write, Post
|
14
|
+
can :create, Comment
|
15
|
+
:break
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe CanTango::Executor::Permit::System do
|
20
|
+
before do
|
21
|
+
@user = User.new 'kris', 'kris@mail.ru'
|
22
|
+
@ua = UserAccount.new @user
|
23
|
+
@user.account = @ua
|
24
|
+
|
25
|
+
@ability = CanTango::Ability::Base.new @user
|
26
|
+
|
27
|
+
@permit = SystemRolePermit.new @ability
|
28
|
+
@executor = CanTango::Executor::Permit::System.new @permit
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#execute!' do
|
32
|
+
describe 'should execute permit' do
|
33
|
+
specify { lambda{ executor.execute! }.should_not raise_error }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
CanTango.config.debug.set :on
|
5
|
+
|
6
|
+
class AdminPermit < CanTango::Permit::UserType
|
7
|
+
def initialize ability
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
protected
|
12
|
+
|
13
|
+
def calc_rules
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class CanTango::Ability::Base
|
18
|
+
def subject
|
19
|
+
candidate
|
20
|
+
end
|
21
|
+
|
22
|
+
def user
|
23
|
+
subject
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe CanTango::Factory::Permits do
|
28
|
+
before do
|
29
|
+
@user = User.new 'kris', 'kris@mail.ru'
|
30
|
+
@admin = Admin.new 'admin', 'admin@mail.ru'
|
31
|
+
@ua = UserAccount.new @user
|
32
|
+
@user.account = @ua
|
33
|
+
|
34
|
+
@ability = CanTango::Ability::Base.new @user
|
35
|
+
@admin_ability = CanTango::Ability::Base.new @admin
|
36
|
+
|
37
|
+
@factory = CanTango::Factory::Permits.new @ability, :user_type
|
38
|
+
@admin_factory = CanTango::Factory::Permits.new @admin_ability, :user_type
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'Admin permits factory' do
|
42
|
+
subject { @factory }
|
43
|
+
|
44
|
+
describe '#create' do
|
45
|
+
it 'should build a list of permits' do
|
46
|
+
subject.create.should be_empty
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'Admin permits factory' do
|
52
|
+
subject { @admin_factory }
|
53
|
+
|
54
|
+
describe 'attributes' do
|
55
|
+
it "should have an ability" do
|
56
|
+
subject.ability.should be_a(CanTango::Ability::Base)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#create' do
|
61
|
+
it 'should build a list of permits' do
|
62
|
+
subject.create.should_not be_empty
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should have the AdminPermit in the list' do
|
66
|
+
subject.create.first.should be_a AdminPermit
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|