cantango 0.8.0 → 0.8.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +32 -19
- data/README.textile +79 -131
- data/VERSION +1 -1
- data/cantango.gemspec +94 -61
- data/lib/cantango.rb +4 -6
- data/lib/cantango/ability.rb +28 -17
- data/lib/cantango/ability/cache.rb +30 -60
- data/lib/cantango/ability/cache/base_cache.rb +1 -1
- data/lib/cantango/ability/cache/key.rb +39 -0
- data/lib/cantango/ability/cache/kompiler.rb +22 -6
- data/lib/cantango/ability/cache/moneta_cache.rb +1 -1
- data/lib/cantango/ability/cache/reader.rb +32 -0
- data/lib/cantango/ability/cache/rules_cache.rb +31 -0
- data/lib/cantango/ability/cache/session_cache.rb +3 -2
- data/lib/cantango/ability/cache/writer.rb +42 -0
- data/lib/cantango/ability/cache_helpers.rb +28 -0
- data/lib/cantango/ability/masquerade_helpers.rb +7 -2
- data/lib/cantango/ability/permission_helpers.rb +0 -8
- data/lib/cantango/ability/permit_helpers.rb +0 -17
- data/lib/cantango/ability/role_helpers.rb +0 -2
- data/lib/cantango/ability/user_helpers.rb +1 -0
- data/lib/cantango/adapter/compiler.rb +9 -0
- data/lib/cantango/adapter/moneta.rb +23 -0
- data/lib/cantango/api.rb +1 -1
- data/lib/cantango/api/aliases.rb +4 -8
- data/lib/cantango/api/attributes.rb +17 -0
- data/lib/cantango/api/common.rb +6 -0
- data/lib/cantango/api/options.rb +9 -5
- data/lib/cantango/cache.rb +1 -1
- data/lib/cantango/cache/hash_cache.rb +34 -0
- data/lib/cantango/configuration.rb +13 -8
- data/lib/cantango/configuration/adapters.rb +25 -0
- data/lib/cantango/configuration/categories.rb +3 -1
- data/lib/cantango/configuration/engines.rb +83 -11
- data/lib/cantango/configuration/engines/cache.rb +12 -1
- data/lib/cantango/configuration/engines/engine.rb +5 -5
- data/lib/cantango/configuration/engines/permission.rb +1 -1
- data/lib/cantango/configuration/permit_registry.rb +17 -0
- data/lib/cantango/configuration/permits.rb +29 -0
- data/lib/cantango/configuration/registry.rb +5 -2
- data/lib/cantango/configuration/role_groups.rb +3 -0
- data/lib/cantango/configuration/role_registry.rb +4 -0
- data/lib/cantango/configuration/roles.rb +2 -0
- data/lib/cantango/configuration/user_accounts.rb +1 -0
- data/lib/cantango/configuration/users.rb +1 -0
- data/lib/cantango/engine.rb +13 -0
- data/lib/cantango/filters.rb +5 -0
- data/lib/cantango/filters/filter.rb +34 -0
- data/lib/cantango/filters/role_filter.rb +29 -0
- data/lib/cantango/filters/role_group_filter.rb +28 -0
- data/lib/cantango/permission_engine.rb +26 -1
- data/lib/cantango/permission_engine/collector.rb +7 -2
- data/lib/cantango/permission_engine/compiler.rb +8 -1
- data/lib/cantango/permission_engine/evaluator.rb +2 -2
- data/lib/cantango/permission_engine/factory.rb +8 -12
- data/lib/cantango/permission_engine/loader.rb +1 -1
- data/lib/cantango/permission_engine/loader/base.rb +1 -1
- data/lib/cantango/permission_engine/loader/categories.rb +3 -3
- data/lib/cantango/permission_engine/loader/permissions.rb +8 -5
- data/lib/cantango/permission_engine/moneta_store.rb +2 -2
- data/lib/cantango/permission_engine/parser.rb +1 -1
- data/lib/cantango/permission_engine/parser/categories.rb +1 -1
- data/lib/cantango/permission_engine/parser/category.rb +1 -1
- data/lib/cantango/permission_engine/parser/default.rb +1 -2
- data/lib/cantango/permission_engine/parser/ownership.rb +1 -1
- data/lib/cantango/permission_engine/parser/permissions.rb +1 -1
- data/lib/cantango/permission_engine/parser/regex.rb +2 -2
- data/lib/cantango/permission_engine/parser/relationship.rb +1 -1
- data/lib/cantango/permission_engine/parser/rule.rb +1 -1
- data/lib/cantango/permission_engine/permission.rb +2 -2
- data/lib/cantango/permission_engine/selector.rb +3 -3
- data/lib/cantango/permission_engine/selector/account_types.rb +24 -0
- data/lib/cantango/permission_engine/selector/base.rb +3 -3
- data/lib/cantango/permission_engine/selector/licenses.rb +2 -2
- data/lib/cantango/permission_engine/selector/role_groups.rb +7 -6
- data/lib/cantango/permission_engine/selector/roles.rb +10 -6
- data/lib/cantango/permission_engine/selector/user_types.rb +23 -0
- data/lib/cantango/permission_engine/selector/users.rb +2 -2
- data/lib/cantango/permission_engine/statement.rb +10 -9
- data/lib/cantango/permission_engine/statements.rb +27 -25
- data/lib/cantango/permission_engine/store.rb +1 -1
- data/lib/cantango/permission_engine/yaml_store.rb +2 -2
- data/lib/cantango/permit_engine.rb +29 -4
- data/lib/cantango/permit_engine/builder.rb +2 -3
- data/lib/cantango/permit_engine/builder/base.rb +9 -1
- data/lib/cantango/permit_engine/builder/special_permits.rb +7 -8
- data/lib/cantango/permit_engine/compatibility.rb +1 -1
- data/lib/cantango/permit_engine/executor.rb +1 -1
- data/lib/cantango/permit_engine/executor/abstract.rb +1 -1
- data/lib/cantango/permit_engine/executor/base.rb +1 -1
- data/lib/cantango/permit_engine/executor/system.rb +1 -1
- data/lib/cantango/permit_engine/factory.rb +2 -7
- data/lib/cantango/permit_engine/finder.rb +43 -9
- data/lib/cantango/permit_engine/role_matcher.rb +1 -1
- data/lib/cantango/permit_engine/util.rb +2 -1
- data/lib/cantango/permits.rb +9 -0
- data/lib/cantango/{permit_engine → permits}/account_permit.rb +15 -4
- data/lib/cantango/{permit_engine → permits}/account_permit/builder.rb +2 -6
- data/lib/cantango/{permit_engine → permits}/account_permit/finder.rb +2 -2
- data/lib/cantango/{permit_engine → permits}/license.rb +1 -1
- data/lib/cantango/{permit_engine → permits}/license/loader.rb +1 -1
- data/lib/cantango/{permit_engine → permits}/license/rules.rb +1 -1
- data/lib/cantango/permits/macros.rb +19 -0
- data/lib/cantango/{permit_engine → permits}/permit.rb +13 -1
- data/lib/cantango/{permit_engine → permits}/role_group_permit.rb +15 -3
- data/lib/cantango/{permit_engine → permits}/role_group_permit/builder.rb +10 -22
- data/lib/cantango/{permit_engine → permits}/role_group_permit/finder.rb +2 -2
- data/lib/cantango/{permit_engine → permits}/role_permit.rb +15 -3
- data/lib/cantango/permits/role_permit/builder.rb +27 -0
- data/lib/cantango/{permit_engine → permits}/role_permit/finder.rb +2 -2
- data/lib/cantango/{permit_engine → permits}/user_permit.rb +15 -3
- data/lib/cantango/{permit_engine → permits}/user_permit/builder.rb +2 -6
- data/lib/cantango/{permit_engine → permits}/user_permit/finder.rb +2 -2
- data/lib/cantango/rails.rb +3 -1
- data/lib/cantango/rails/engine.rb +11 -6
- data/lib/cantango/rails/helpers/base_helper.rb +28 -0
- data/lib/cantango/rails/helpers/controller_helper.rb +17 -0
- data/lib/cantango/rails/helpers/rest_helper.rb +44 -0
- data/lib/cantango/rails/helpers/view_helper.rb +17 -0
- data/lib/cantango/rails/railtie.rb +1 -1
- data/lib/cantango/rspec/config.rb +1 -1
- data/lib/cantango/rspec/matchers/be_allowed_to.rb +5 -3
- data/lib/cantango/rules/user_relation.rb +1 -1
- data/lib/cantango/users/macros.rb +8 -2
- data/lib/cantango/users/user.rb +1 -1
- data/lib/generators/cantango/account_permit/account_permit_generator.rb +37 -0
- data/lib/generators/cantango/account_permit/templates/account_permit.erb +13 -0
- data/lib/generators/cantango/base.rb +15 -18
- data/lib/generators/cantango/basic.rb +41 -0
- data/lib/generators/cantango/install/install_generator.rb +37 -0
- data/lib/generators/cantango/install/templates/cantango.rb +4 -0
- data/{spec/active_record/scenarios/user_accounts/config/account_permits.yml → lib/generators/cantango/install/templates/categories.yml} +0 -0
- data/lib/generators/cantango/install/templates/permissions.yml +4 -0
- data/lib/generators/cantango/license/license_generator.rb +6 -11
- data/lib/generators/cantango/license/templates/license.erb +1 -1
- data/lib/generators/cantango/license_base.rb +2 -2
- data/lib/generators/cantango/licenses/licenses_generator.rb +2 -7
- data/lib/generators/cantango/permit_generator.rb +31 -10
- data/lib/generators/cantango/role_permit/role_permit_generator.rb +11 -14
- data/lib/generators/cantango/role_permit/templates/account_permit.erb +2 -2
- data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +2 -2
- data/lib/generators/cantango/role_permit/templates/role_permit.erb +2 -2
- data/lib/generators/cantango/role_permits/role_permits_generator.rb +16 -98
- data/lib/generators/cantango/user_permit/templates/account_permit.erb +5 -0
- data/lib/generators/cantango/user_permit/templates/user_permit.erb +13 -0
- data/lib/generators/cantango/user_permit/user_permit_generator.rb +36 -0
- data/spec/TODO +1 -6
- data/spec/active_record/helper/permits_config.rb +1 -1
- data/spec/active_record/scenarios/engines/permission_engine/{cantango_permissions.yml → permissions.yml} +2 -1
- data/spec/active_record/scenarios/engines/permission_engine/tango_permission_yml_spec.rb +8 -9
- data/spec/active_record/scenarios/engines/permit_engine/licenses_spec.rb +2 -2
- data/spec/active_record/scenarios/engines/permit_engine/role_groups_permits_spec.rb +2 -2
- data/spec/active_record/scenarios/shared/{can_tango.rb → cantango.rb} +1 -1
- data/spec/active_record/scenarios/shared/models/items.rb +0 -1
- data/spec/active_record/scenarios/shared/models/users.rb +6 -1
- data/spec/active_record/spec_helper.rb +6 -4
- data/spec/cantango/ability/cache/key_spec.rb +64 -0
- data/spec/cantango/ability/cache/{compiler_spec.rb → kompiler_spec.rb} +9 -21
- data/spec/cantango/ability/cache/reader_compile_spec.rb +42 -0
- data/spec/cantango/ability/cache/reader_spec.rb +33 -0
- data/spec/cantango/ability/cache/rules_cache_spec.rb +15 -0
- data/spec/cantango/ability/cache/session_cache_spec.rb +1 -1
- data/spec/cantango/ability/cache/writer_spec.rb +21 -0
- data/spec/cantango/ability/cache_spec.rb +6 -2
- data/spec/cantango/ability_filters_spec.rb +5 -10
- data/spec/cantango/ability_spec.rb +2 -3
- data/spec/cantango/api/attributes_spec.rb +27 -0
- data/spec/cantango/api/user/can_api_spec.rb +2 -2
- data/spec/cantango/api/user_account/can_api_spec.rb +2 -2
- data/spec/cantango/configuration/adapter_spec.rb +28 -0
- data/spec/cantango/configuration/engines/cache_spec.rb +2 -2
- data/spec/cantango/configuration/engines/permission_spec.rb +3 -3
- data/spec/cantango/configuration/engines/permit_spec.rb +1 -1
- data/spec/cantango/configuration/engines/store_shared.rb +3 -1
- data/spec/cantango/configuration/engines_spec.rb +106 -3
- data/spec/cantango/configuration/hash_registry_spec.rb +1 -1
- data/spec/cantango/configuration/permit_registry_spec.rb +14 -0
- data/spec/cantango/configuration/permits_spec.rb +25 -0
- data/spec/cantango/configuration/registry_spec.rb +1 -1
- data/spec/cantango/configuration/shared/registry_ex.rb +2 -1
- data/spec/cantango/configuration_spec.rb +5 -5
- data/spec/cantango/permission_engine/compiler_spec.rb +8 -0
- data/spec/cantango/permission_engine/permission_spec.rb +1 -1
- data/spec/cantango/permission_engine/yaml_store_spec.rb +14 -4
- data/spec/cantango/permission_engine_spec.rb +0 -0
- data/spec/cantango/permit_engine/account_permit_spec.rb +2 -4
- data/spec/cantango/permit_engine/builder/role_group_permits_spec.rb +4 -7
- data/spec/cantango/permit_engine/builder/role_permits_spec.rb +5 -6
- data/spec/cantango/permit_engine/builder/special_permits_spec.rb +3 -4
- data/spec/cantango/permit_engine/executor/system_spec.rb +2 -2
- data/spec/cantango/permit_engine/factory_spec.rb +2 -3
- data/spec/cantango/permit_engine/finder_spec.rb +144 -23
- data/spec/cantango/permit_engine/permit/permit_static_and_dynamic_rules_spec.rb +4 -5
- data/spec/cantango/permit_engine/role_group_permit_spec.rb +1 -1
- data/spec/cantango/permit_engine/role_permit_spec.rb +6 -7
- data/spec/cantango/permit_engine/user_permit_spec.rb +2 -3
- data/spec/cantango/permit_engine_spec.rb +2 -0
- data/spec/cantango/permits/macros_spec.rb +41 -0
- data/spec/cantango/permits/permit_spec.rb +46 -0
- data/spec/cantango_spec.rb +13 -0
- data/spec/devise-dummy/app/helpers/application_helper.rb +7 -0
- data/spec/devise-dummy/app/views/articles/admin.html.haml +1 -1
- data/spec/devise-dummy/app/views/articles/admin_account.html.haml +1 -1
- data/spec/devise-dummy/app/views/articles/guest.html.haml +1 -1
- data/spec/devise-dummy/app/views/articles/index.html.haml +1 -1
- data/spec/devise-dummy/app/views/comments/guest.html.haml +1 -1
- data/spec/devise-dummy/app/views/comments/index.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/admin.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/admin_account.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/guest.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/index.html.haml +1 -1
- data/spec/devise-dummy/app/views/users/index.html.haml +1 -1
- data/spec/devise-dummy/config/initializers/cantango.rb +3 -3
- data/spec/devise-dummy/config/{cantango_permissions.yml → permissions.yml} +2 -1
- data/spec/devise-integration/concerto_spec.rb +1 -1
- data/spec/dummy/app/models/user.rb +1 -0
- data/spec/dummy/app/views/articles/admin.html.haml +1 -1
- data/spec/dummy/app/views/articles/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/articles/guest.html.haml +1 -1
- data/spec/dummy/app/views/articles/index.html.haml +1 -1
- data/spec/dummy/app/views/comments/guest.html.haml +1 -1
- data/spec/dummy/app/views/comments/index.html.haml +1 -1
- data/spec/dummy/app/views/concertos/admin.html.haml +1 -1
- data/spec/dummy/app/views/concertos/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/concertos/guest.html.haml +1 -1
- data/spec/dummy/app/views/concertos/index.html.haml +1 -1
- data/spec/dummy/app/views/posts/admin.html.haml +1 -1
- data/spec/dummy/app/views/posts/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/posts/guest.html.haml +1 -1
- data/spec/dummy/app/views/posts/index.html.haml +1 -1
- data/spec/dummy/app/views/users/admin.html.haml +1 -1
- data/spec/dummy/app/views/users/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/users/guest.html.haml +1 -1
- data/spec/dummy/app/views/users/index.html.haml +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/initializers/cantango.rb +1 -3
- data/spec/dummy/config/{cantango_permissions.yml → permissions.yml} +2 -2
- data/spec/dummy_spec_helper.rb +2 -0
- data/spec/entire_suite_spec.rb +2 -0
- data/spec/factories/user.rb +8 -0
- data/spec/factories/user_account.rb +6 -0
- data/spec/fixtures/config/permissions.yml +60 -19
- data/spec/fixtures/models/admin.rb +2 -0
- data/spec/fixtures/models/admin_account.rb +22 -0
- data/spec/fixtures/models/simple_roles.rb +5 -0
- data/spec/fixtures/models/user.rb +4 -0
- data/spec/helpers/dummy_app_ability.rb +2 -5
- data/spec/integration/cache_using_moneta_spec.rb +3 -1
- data/spec/integration/cache_using_session_spec.rb +2 -2
- data/spec/integration/user/articles_spec.rb +1 -1
- data/spec/integration/user/concerto_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -5
- metadata +120 -95
- data/lib/cantango/ability/class_methods.rb +0 -27
- data/lib/cantango/api/aliases/account_permit.rb +0 -8
- data/lib/cantango/api/aliases/license.rb +0 -7
- data/lib/cantango/api/aliases/permit.rb +0 -9
- data/lib/cantango/api/aliases/role_group_permit.rb +0 -7
- data/lib/cantango/api/aliases/role_permit.rb +0 -7
- data/lib/cantango/api/aliases/user_permit.rb +0 -8
- data/lib/cantango/permission_engine/builder.rb +0 -6
- data/lib/cantango/permit_engine/role_permit/builder.rb +0 -46
- data/lib/cantango/rails/base_helpers.rb +0 -26
- data/lib/cantango/rails/controller_helpers.rb +0 -15
- data/lib/cantango/rails/view_helpers.rb +0 -15
- data/spec/active_record/scenarios/shared/permits/PERMITS README.textile +0 -3
- data/spec/active_record/scenarios/user_accounts/docs/USER_ACCOUNTS_SCENARIO.textile +0 -20
- data/spec/active_record/scenarios/user_accounts/docs/basic_rules_spec_possible_samples.txt +0 -84
- data/spec/factories.rb +0 -8
- data/spec/fixtures/config/cantango_permissions.yml +0 -48
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'rspec'
|
2
2
|
require 'cantango'
|
3
3
|
require 'hashie'
|
4
|
+
require 'spec_helper'
|
4
5
|
def permission_fixture
|
5
6
|
group = 'bloggers'
|
6
7
|
rules = Hashie::Mash.new({"can"=>{"read"=>["Article", "Comment"]}, "cannot"=>{"write"=>["Article", "Post"]}})
|
@@ -17,6 +18,13 @@ describe CanTango::PermissionEngine::Compiler do
|
|
17
18
|
compiler.compile! permission
|
18
19
|
end
|
19
20
|
|
21
|
+
it 'should raise if permission contains not-valid actions' do
|
22
|
+
expect {compiler.can_eval}.not_to raise_error
|
23
|
+
# Replacing static_rules with rule that has not-valid action:
|
24
|
+
permission.static_rules.can = Hashie::Mash.new({'edit' => ["Article"]})
|
25
|
+
expect {compiler.can_eval}.to raise_error
|
26
|
+
end
|
27
|
+
|
20
28
|
it 'should produce cancan statements' do
|
21
29
|
compiler.can_eval do |statements|
|
22
30
|
statements.should == %|can(:read, Article)\ncan(:read, Comment)|
|
@@ -7,7 +7,7 @@ describe CanTango::PermissionEngine::Permission do
|
|
7
7
|
@permission = CanTango::PermissionEngine::Permission.new :bloggers
|
8
8
|
end
|
9
9
|
|
10
|
-
subject do
|
10
|
+
subject do
|
11
11
|
reads = ['Article' , 'Comment']
|
12
12
|
writes = ['Article' , 'Post']
|
13
13
|
@permission.static_rules.can = {:read => reads}
|
@@ -13,12 +13,12 @@ end
|
|
13
13
|
describe CanTango::PermissionEngine::YamlStore do
|
14
14
|
include CanTangoFixtures
|
15
15
|
let (:permissions) { tango_permissions }
|
16
|
-
|
16
|
+
|
17
17
|
context 'Loading permissions' do
|
18
18
|
let (:store) do
|
19
|
-
@store ||= CanTango::PermissionEngine::YamlStore.new '
|
19
|
+
@store ||= CanTango::PermissionEngine::YamlStore.new 'permissions', :path => config_folder
|
20
20
|
end
|
21
|
-
|
21
|
+
|
22
22
|
before(:each) do
|
23
23
|
store.load!
|
24
24
|
end
|
@@ -29,13 +29,23 @@ describe CanTango::PermissionEngine::YamlStore do
|
|
29
29
|
context 'Caching permissions by types' do
|
30
30
|
let (:store) do
|
31
31
|
# filename: 'cantango_permissions.yml',
|
32
|
-
@store ||= CanTango::PermissionEngine::YamlStore.new '
|
32
|
+
@store ||= CanTango::PermissionEngine::YamlStore.new 'permissions', :path => config_folder
|
33
33
|
end
|
34
34
|
|
35
35
|
before(:each) do
|
36
36
|
store.load!
|
37
37
|
end
|
38
38
|
|
39
|
+
context "user_types" do
|
40
|
+
subject{ @store.user_types_rules }
|
41
|
+
it { should == @store.user_types_compiled_permissions }
|
42
|
+
end
|
43
|
+
|
44
|
+
context "account_types" do
|
45
|
+
subject{ @store.account_types_rules }
|
46
|
+
it { should == @store.account_types_compiled_permissions }
|
47
|
+
end
|
48
|
+
|
39
49
|
context "roles" do
|
40
50
|
subject{ @store.roles_rules }
|
41
51
|
it { should == @store.roles_compiled_permissions }
|
File without changes
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
5
4
|
class AdminAccountPermit < CanTango::AccountPermit
|
@@ -14,8 +13,7 @@ class AdminAccountPermit < CanTango::AccountPermit
|
|
14
13
|
end
|
15
14
|
end
|
16
15
|
|
17
|
-
|
18
|
-
describe CanTango::PermitEngine::AccountPermit do
|
16
|
+
describe CanTango::Permits::AccountPermit do
|
19
17
|
let (:user) do
|
20
18
|
User.new 'kris'
|
21
19
|
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
5
|
-
|
6
4
|
class AdminsRoleGroupPermit < CanTango::RoleGroupPermit
|
7
5
|
def initialize ability
|
8
6
|
super
|
@@ -26,10 +24,9 @@ class AdminRolePermit < CanTango::RolePermit
|
|
26
24
|
end
|
27
25
|
|
28
26
|
|
29
|
-
describe CanTango::
|
30
|
-
|
27
|
+
describe CanTango::Permits::RoleGroupPermit::Builder do
|
31
28
|
before do
|
32
|
-
CanTango.config.
|
29
|
+
CanTango.config.cache_engine.set :off
|
33
30
|
end
|
34
31
|
|
35
32
|
let (:user) do
|
@@ -46,7 +43,7 @@ describe CanTango::PermitEngine::RoleGroupPermit::Builder do
|
|
46
43
|
end
|
47
44
|
|
48
45
|
let (:builder) do
|
49
|
-
CanTango::
|
46
|
+
CanTango::Permits::RoleGroupPermit::Builder.new ability
|
50
47
|
end
|
51
48
|
|
52
49
|
describe 'attributes' do
|
@@ -1,8 +1,7 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
5
|
-
CanTango.config.
|
4
|
+
CanTango.config.cache_engine.set :off
|
6
5
|
class AdminsRoleGroupPermit < CanTango::RoleGroupPermit
|
7
6
|
def initialize ability
|
8
7
|
super
|
@@ -26,7 +25,7 @@ class AdminRolePermit < CanTango::RolePermit
|
|
26
25
|
end
|
27
26
|
|
28
27
|
|
29
|
-
describe CanTango::
|
28
|
+
describe CanTango::Permits::RolePermit::Builder do
|
30
29
|
let (:user) do
|
31
30
|
User.new 'kris'
|
32
31
|
end
|
@@ -41,7 +40,7 @@ describe CanTango::PermitEngine::RolePermit::Builder do
|
|
41
40
|
end
|
42
41
|
|
43
42
|
let (:builder) do
|
44
|
-
CanTango::
|
43
|
+
CanTango::Permits::RolePermit::Builder.new ability
|
45
44
|
end
|
46
45
|
|
47
46
|
describe 'attributes' do
|
@@ -54,5 +53,5 @@ describe CanTango::PermitEngine::RolePermit::Builder do
|
|
54
53
|
it 'should build a list of permits' do
|
55
54
|
builder.build.should_not be_empty
|
56
55
|
end
|
57
|
-
end
|
56
|
+
end
|
58
57
|
end
|
@@ -1,14 +1,13 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
5
4
|
class SystemRolePermit < CanTango::RolePermit
|
6
5
|
end
|
7
6
|
|
8
7
|
describe CanTango::PermitEngine::Builder::SpecialPermits do
|
9
|
-
|
8
|
+
|
10
9
|
before do
|
11
|
-
CanTango.config.
|
10
|
+
CanTango.config.cache_engine.set :off
|
12
11
|
end
|
13
12
|
|
14
13
|
let (:user) do
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
5
4
|
class AdminsRoleGroupPermit < CanTango::RoleGroupPermit
|
@@ -16,7 +15,7 @@ end
|
|
16
15
|
describe CanTango::PermitEngine::Factory do
|
17
16
|
|
18
17
|
before do
|
19
|
-
CanTango.config.
|
18
|
+
CanTango.config.cache_engine.set :off
|
20
19
|
end
|
21
20
|
|
22
21
|
let (:user) do
|
@@ -1,7 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
4
|
+
module AdminAccountPermits
|
5
|
+
class EditorRolePermit < CanTango::RolePermit
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
5
9
|
class AdminsRoleGroupPermit < CanTango::RoleGroupPermit
|
6
10
|
def initialize ability
|
7
11
|
super
|
@@ -24,47 +28,164 @@ class AdminRolePermit < CanTango::RolePermit
|
|
24
28
|
end
|
25
29
|
end
|
26
30
|
|
31
|
+
class AdminPermit < CanTango::UserPermit
|
32
|
+
def initialize ability
|
33
|
+
super
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def static_rules
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class AdminAccountPermit < CanTango::AccountPermit
|
43
|
+
def initialize ability
|
44
|
+
super
|
45
|
+
end
|
46
|
+
|
47
|
+
protected
|
48
|
+
|
49
|
+
def static_rules
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
27
53
|
def setup
|
28
54
|
let (:user) do
|
29
55
|
User.new 'kris'
|
30
56
|
end
|
31
57
|
|
58
|
+
let (:admin) do
|
59
|
+
Admin.new 'kris'
|
60
|
+
end
|
61
|
+
|
32
62
|
let (:user_account) do
|
33
63
|
ua = UserAccount.new user, :role_groups => [:admins]
|
34
64
|
user.account = ua
|
35
65
|
end
|
36
|
-
end
|
37
66
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
let (:finder) do
|
42
|
-
CanTango::PermitEngine::RolePermit::Finder.new user_account, :admin
|
67
|
+
let (:admin_account) do
|
68
|
+
ua = AdminAccount.new user, :roles => [:editors], :role_groups => [:admins]
|
69
|
+
admin.account = ua
|
43
70
|
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe CanTango::Permits::RolePermit::Finder do
|
74
|
+
|
75
|
+
setup
|
76
|
+
|
77
|
+
context "Account" do
|
78
|
+
let (:finder) do
|
79
|
+
CanTango::Permits::RolePermit::Finder.new admin_account, :editor
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'attributes' do
|
83
|
+
it "should have an ability" do
|
84
|
+
finder.user_account.should be_a(AdminAccount)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe '#permit_class' do
|
89
|
+
it 'should return the :admin permit class' do
|
90
|
+
finder.permit_class.should == "EditorRolePermit"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#get_permit' do
|
95
|
+
it 'should return the AdminAccount::EditorRolePermit' do
|
96
|
+
finder.get_permit.should == AdminAccountPermits::EditorRolePermit
|
97
|
+
end
|
98
|
+
end
|
44
99
|
|
45
|
-
describe 'attributes' do
|
46
|
-
it "should have an ability" do
|
47
|
-
finder.user_account.should be_a(UserAccount)
|
48
|
-
end
|
49
100
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
101
|
+
|
102
|
+
context "User" do
|
103
|
+
let (:finder) do
|
104
|
+
CanTango::Permits::RolePermit::Finder.new user_account, :admin
|
54
105
|
end
|
55
|
-
|
106
|
+
|
107
|
+
describe 'attributes' do
|
108
|
+
it "should have an ability" do
|
109
|
+
finder.user_account.should be_a(UserAccount)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
describe '#permit_class' do
|
114
|
+
it 'should return the :admin permit class' do
|
115
|
+
finder.permit_class.should == "AdminRolePermit"
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
describe '#get_permit' do
|
120
|
+
it 'should return the AdminRolePermit' do
|
121
|
+
finder.get_permit.should == AdminRolePermit
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
56
126
|
end
|
57
127
|
|
58
|
-
describe CanTango::
|
128
|
+
describe CanTango::Permits::RoleGroupPermit::Finder do
|
59
129
|
setup
|
60
|
-
|
61
|
-
let (:finder) do
|
62
|
-
CanTango::
|
130
|
+
|
131
|
+
let (:finder) do
|
132
|
+
CanTango::Permits::RoleGroupPermit::Finder.new user_account, :admins
|
63
133
|
end
|
64
134
|
|
65
|
-
describe '#permit_class' do
|
135
|
+
describe '#permit_class' do
|
66
136
|
it 'should return the :admins role permit class' do
|
67
137
|
finder.permit_class.should == "AdminsRoleGroupPermit"
|
68
138
|
end
|
69
|
-
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe '#get_permit' do
|
142
|
+
it 'should return the AdminsRoleGroupPermit class' do
|
143
|
+
finder.get_permit.should == AdminsRoleGroupPermit
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
end
|
148
|
+
|
149
|
+
describe CanTango::Permits::UserPermit::Finder do
|
150
|
+
setup
|
151
|
+
|
152
|
+
let (:finder) do
|
153
|
+
CanTango::Permits::UserPermit::Finder.new admin, :admin
|
154
|
+
end
|
155
|
+
|
156
|
+
describe '#permit_class' do
|
157
|
+
it 'should return the :admin user permit class' do
|
158
|
+
finder.permit_class.should == "AdminPermit"
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
describe '#get_permit' do
|
163
|
+
it 'should return AdminPermit class' do
|
164
|
+
finder.get_permit.should == AdminPermit
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
end
|
169
|
+
|
170
|
+
describe CanTango::Permits::AccountPermit::Finder do
|
171
|
+
setup
|
172
|
+
|
173
|
+
let (:finder) do
|
174
|
+
CanTango::Permits::AccountPermit::Finder.new admin_account, :admin
|
175
|
+
end
|
176
|
+
|
177
|
+
# We don't have AdminAccountPermits::AdminAccountPermit so it should fall back to single AdminAccountPermit
|
178
|
+
|
179
|
+
describe '#permit_class' do
|
180
|
+
it 'should return the :admin account permit class' do
|
181
|
+
finder.permit_class.should == "AdminAccountPermit"
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#get_permit' do
|
186
|
+
it 'should return AdminAccountPermit class' do
|
187
|
+
finder.get_permit.should == AdminAccountPermit
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
70
191
|
end
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
5
4
|
class UserRolePermit < CanTango::RolePermit
|
@@ -30,7 +29,7 @@ class AdminRolePermit < CanTango::RolePermit
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
33
|
-
describe CanTango::
|
32
|
+
describe CanTango::Permits::RolePermit do
|
34
33
|
let (:user) do
|
35
34
|
User.new 'kris'
|
36
35
|
end
|
@@ -46,8 +45,8 @@ describe CanTango::PermitEngine::RolePermit do
|
|
46
45
|
end
|
47
46
|
before(:each) do
|
48
47
|
CanTango.configure do |config|
|
49
|
-
config.
|
50
|
-
config.
|
48
|
+
config.permit_engine.set :on
|
49
|
+
config.permission_engine.set :off
|
51
50
|
end
|
52
51
|
end
|
53
52
|
|
@@ -1,5 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
3
2
|
require 'fixtures/models'
|
4
3
|
|
5
4
|
class AdminRolePermit < CanTango::RolePermit
|
@@ -14,7 +13,7 @@ class AdminRolePermit < CanTango::RolePermit
|
|
14
13
|
end
|
15
14
|
|
16
15
|
|
17
|
-
describe CanTango::
|
16
|
+
describe CanTango::Permits::RolePermit do
|
18
17
|
let (:user) do
|
19
18
|
User.new 'kris'
|
20
19
|
end
|
@@ -27,18 +26,18 @@ describe CanTango::PermitEngine::RolePermit do
|
|
27
26
|
let (:ability) do
|
28
27
|
CanTango::Ability.new user_account
|
29
28
|
end
|
30
|
-
|
31
|
-
let (:permit) do
|
29
|
+
|
30
|
+
let (:permit) do
|
32
31
|
AdminRolePermit.new ability
|
33
32
|
end
|
34
33
|
|
35
34
|
describe 'attributes' do
|
36
35
|
it "should be the permit for the :admin role" do
|
37
36
|
permit.role.should == :admin
|
38
|
-
end
|
37
|
+
end
|
39
38
|
|
40
39
|
it "should have an ability" do
|
41
40
|
permit.ability.should be_a(CanTango::Ability)
|
42
|
-
end
|
41
|
+
end
|
43
42
|
end
|
44
43
|
end
|