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,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
CanTango.config.permits.types.register :user_type
|
4
|
+
CanTango.config.debug.set :on
|
5
|
+
|
6
|
+
module AdminAccountPermits
|
7
|
+
class PublisherPermit < CanTango::Permit::UserType
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
describe CanTango::Finder::Permit::Account do
|
12
|
+
subject do
|
13
|
+
CanTango::Finder::Permit::Account.new :publisher, :type => :user_type, :account => :admin
|
14
|
+
end
|
15
|
+
|
16
|
+
describe '#account_registry' do
|
17
|
+
it 'should return the permits registry for the given ccount' do
|
18
|
+
subject.account_registry.should be_a CanTango::Registry::Permit::Base
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '#permits' do
|
23
|
+
it 'should return the account permits for a given type' do
|
24
|
+
subject.permits.should be_a CanTango::Registry::Hash
|
25
|
+
subject.permits.registered.should be_a Hashie::Mash
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
specify { subject.find_permit.should == AdminAccountPermits::PublisherPermit }
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
CanTango.config.permits.types.register :user_type
|
4
|
+
CanTango.config.debug.set :on
|
5
|
+
|
6
|
+
class EditorPermit < CanTango::Permit::UserType
|
7
|
+
end
|
8
|
+
|
9
|
+
describe CanTango::Finder::Permit::Base do
|
10
|
+
before do
|
11
|
+
@finder = CanTango::Finder::Permit::Base.new :editor, :type => :user_type
|
12
|
+
end
|
13
|
+
subject { @finder }
|
14
|
+
|
15
|
+
its(:type) { should == :user_type }
|
16
|
+
its(:name) { should == :editor }
|
17
|
+
|
18
|
+
it 'should have registered the permit' do
|
19
|
+
CanTango.config.permits.registered_for(:user_type, :editor).should_not be_nil
|
20
|
+
end
|
21
|
+
|
22
|
+
specify { subject.find_permit.should == EditorPermit }
|
23
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'cantango'
|
3
|
+
require 'rails'
|
4
|
+
require 'require_all'
|
5
|
+
|
6
|
+
DIR = File.dirname(__FILE__)
|
7
|
+
|
8
|
+
#require_all DIR + '/../../../app/models'
|
9
|
+
|
10
|
+
describe 'Save License to yaml' do
|
11
|
+
pending 'not done'
|
12
|
+
|
13
|
+
before :each do
|
14
|
+
# @license = LicenseConfig.new :name => 'blogging'
|
15
|
+
# @license.can = PermissionSet.new :read => ['Article', 'Post']
|
16
|
+
end
|
17
|
+
|
18
|
+
# it "should save license to license.yml file" do
|
19
|
+
# pending
|
20
|
+
# puts @license
|
21
|
+
# puts @license.to_yaml
|
22
|
+
# end
|
23
|
+
end
|
24
|
+
|
File without changes
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Loader::Categories do
|
4
|
+
before do
|
5
|
+
@file = File.join(config_path, 'categories.yml')
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { CanTango::Loader::Categories.new }
|
9
|
+
|
10
|
+
context 'categories loaded via default setting' do
|
11
|
+
describe 'categories' do
|
12
|
+
specify do
|
13
|
+
subject.categories.default.should_not be_empty
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'category name' do
|
18
|
+
specify do
|
19
|
+
subject.category(:grains).should == []
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
subject { CanTango::Loader::Categories.new @file }
|
25
|
+
|
26
|
+
describe 'parser' do
|
27
|
+
specify { subject.parser.should be_a CanTango::Parser::Categories }
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'categories registered in config' do
|
31
|
+
before do
|
32
|
+
CanTango.config.categories.register :genders => ['male', 'female']
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'categories' do
|
36
|
+
specify do
|
37
|
+
subject.categories.default.genders.should == ['male', 'female']
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
describe 'category name' do
|
42
|
+
specify do
|
43
|
+
subject.category(:genders).should == ['male', 'female']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class NoTypePermit
|
4
|
+
end
|
5
|
+
|
6
|
+
class NoName
|
7
|
+
end
|
8
|
+
|
9
|
+
class GoodPermit
|
10
|
+
end
|
11
|
+
|
12
|
+
CanTango.config.permits.types.register :user_type, CanTango::Permit::UserType
|
13
|
+
|
14
|
+
describe CanTango::Macros::Permit do
|
15
|
+
describe '#tango_permit' do
|
16
|
+
it 'should not register permit without type' do
|
17
|
+
lambda { NoTypePermit.tango_permit }.should raise_error(CanTango::Permit::MissingTypeError)
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should not register permit without name' do
|
21
|
+
lambda { NoName.tango_permit :type =>:user_type }.should raise_error(CanTango::Permit::MissingNameError)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe 'should register permit with type set explicitly and valid name' do
|
25
|
+
specify do
|
26
|
+
lambda { GoodPermit.tango_permit(:type => :user_type) }.should_not raise_error
|
27
|
+
end
|
28
|
+
|
29
|
+
describe 'registration' do
|
30
|
+
before do
|
31
|
+
@options = GoodPermit.tango_permit(:type => :user_type)
|
32
|
+
end
|
33
|
+
specify { CanTango.config.permits.registered_for(:user_type).registered.should include(:good) }
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Parser::Categories do
|
4
|
+
before do
|
5
|
+
@categories = {}
|
6
|
+
@key = :grains
|
7
|
+
@models = ['Wheat', 'Barley']
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { CanTango::Parser::Categories.new }
|
11
|
+
|
12
|
+
describe 'parse categories, key, obj, &blk' do
|
13
|
+
specify do
|
14
|
+
subject.parse @categories, @key, @models do |categories|
|
15
|
+
categories[@key].should == @models
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class AdminAccountPermit < CanTango::Permit::AccountType
|
5
|
+
def initialize ability
|
6
|
+
super
|
7
|
+
end
|
8
|
+
|
9
|
+
protected
|
10
|
+
|
11
|
+
def static_rules
|
12
|
+
can :read, Article
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe CanTango::Permit::AccountType do
|
17
|
+
before do
|
18
|
+
@user = SimpleUser.new
|
19
|
+
@ability = CanTango::Ability::Base.new @user
|
20
|
+
@permit = AdminAccountPermit.new @ability
|
21
|
+
end
|
22
|
+
|
23
|
+
subject { @permit }
|
24
|
+
|
25
|
+
describe 'attributes' do
|
26
|
+
it "should be the permit for the :admin account" do
|
27
|
+
subject.account_type.should == :admin
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should have an ability" do
|
31
|
+
subject.ability.should be_a CanTango::Ability::Base
|
32
|
+
end
|
33
|
+
end
|
34
|
+
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,106 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
CanTango.config.categories do |cat|
|
5
|
+
cat.register :grains => ['Wheat', 'Barley']
|
6
|
+
end
|
7
|
+
|
8
|
+
class MyPermit < CanTango::Permit::Base
|
9
|
+
def initialize ability
|
10
|
+
super
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
|
15
|
+
def calc_rules
|
16
|
+
can :read, Article
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
class AdminPermit < CanTango::Permit::UserType
|
21
|
+
def initialize ability
|
22
|
+
super
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def static_rules
|
28
|
+
can :read, Article
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe CanTango::Permit::Base do
|
33
|
+
before do
|
34
|
+
@user = User.new 'kris', 'kris@mail.ru', :roles => [:editor]
|
35
|
+
@ability = CanTango::Ability::Base.new @user
|
36
|
+
@permit = AdminPermit.new @ability
|
37
|
+
end
|
38
|
+
|
39
|
+
subject { @permit }
|
40
|
+
|
41
|
+
describe '#permit_type' do
|
42
|
+
it "should be disabled" do
|
43
|
+
subject.permit_type.should == :user_type
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
describe '#disable!' do
|
48
|
+
before do
|
49
|
+
subject.disable!
|
50
|
+
end
|
51
|
+
it "should be disabled" do
|
52
|
+
subject.disabled?.should be_true
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#disabled?' do
|
57
|
+
it "should not be disabled" do
|
58
|
+
subject.disabled?.should be_false
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe '#valid?' do
|
63
|
+
it "should return exception NotImplemented" do
|
64
|
+
lambda { subject.valid? }.should raise_error
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe '#category label' do
|
69
|
+
it "should return models of that category" do
|
70
|
+
subject.category('grains').should include('Wheat', 'Barley')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#any reg_exp' do
|
75
|
+
it "should return matching models of ORM" do
|
76
|
+
subject.any(/Item/).should be_empty #include('Item', 'ProductItem')
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe '#build_permit' do
|
81
|
+
it "should build a permit" do
|
82
|
+
pending
|
83
|
+
# subject.build_permit(:mine).should be_a CanTango::Permit::Mine
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#builder' do
|
88
|
+
it "should have a builder" do
|
89
|
+
subject.builder.should be_a CanTango::Builder::Permit::Base
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#finder' do
|
94
|
+
it "should have a finder" do
|
95
|
+
subject.finder.should be_a CanTango::Finder::Permit::Base
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#account_type' do
|
100
|
+
it "should be the permit for the :admin account" do
|
101
|
+
subject.account_type.should == :admin
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
specify { subject.ability.should be_a(CanTango::Ability) }
|
106
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class MyOwnPermit < 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
|
+
describe CanTango::Permit::ClassMethods do
|
17
|
+
subject { MyOwnPermit }
|
18
|
+
|
19
|
+
it "should be the permit for the :admin account" do
|
20
|
+
subject.permit_type.should == :user_type
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should not be an account permit" do
|
24
|
+
subject.account_name.should == nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should not be an account permit" do
|
28
|
+
subject.permit_name.should == :my_own
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should have a finder" do
|
32
|
+
subject.finder.should be_a CanTango::Finder::Permit::Base
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'fixtures/models'
|
3
|
+
|
4
|
+
class ExecPermit < CanTango::Ability::Base
|
5
|
+
include CanTango::Permit::Helper::Execution
|
6
|
+
|
7
|
+
attr_reader :subject
|
8
|
+
|
9
|
+
def initialize subject
|
10
|
+
@subject = subject
|
11
|
+
end
|
12
|
+
|
13
|
+
def execute!
|
14
|
+
calc_rules
|
15
|
+
end
|
16
|
+
|
17
|
+
def calc_rules
|
18
|
+
can :edit, Project
|
19
|
+
end
|
20
|
+
|
21
|
+
def valid?
|
22
|
+
true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe CanTango::Permit::Helper::Execution do
|
27
|
+
before do
|
28
|
+
@user = User.new 'kris', 'kris@mail.ru', :roles => [:editor]
|
29
|
+
end
|
30
|
+
subject { ExecPermit.new @user }
|
31
|
+
|
32
|
+
# Should be an Permit executor!
|
33
|
+
describe 'executor' do
|
34
|
+
specify { subject.executor.should be_a CanTango::Executor::Permit::Base }
|
35
|
+
end
|
36
|
+
|
37
|
+
describe 'execute' do
|
38
|
+
context 'disabled' do
|
39
|
+
before do
|
40
|
+
subject.disable!
|
41
|
+
subject.execute
|
42
|
+
end
|
43
|
+
specify { subject.rules.should be_empty }
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'enabled' do
|
47
|
+
before do
|
48
|
+
subject.enable!
|
49
|
+
subject.execute
|
50
|
+
end
|
51
|
+
specify { subject.rules.should_not be_empty }
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|