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
@@ -2,6 +2,8 @@ require 'rspec'
|
|
2
2
|
require 'cantango'
|
3
3
|
require 'fixtures/models'
|
4
4
|
|
5
|
+
puts "WARNING - TODO - Full caching spec !!!"
|
6
|
+
|
5
7
|
class CacheStub
|
6
8
|
attr_accessor :user
|
7
9
|
|
@@ -22,8 +24,10 @@ class CacheStub
|
|
22
24
|
def dynamic_rules
|
23
25
|
rules << :rule_d
|
24
26
|
end
|
25
|
-
|
26
|
-
|
27
|
+
|
28
|
+
def cache
|
29
|
+
@cache ||= CanTango::Ability::Cache.new
|
30
|
+
end
|
27
31
|
end
|
28
32
|
|
29
33
|
|
@@ -1,12 +1,10 @@
|
|
1
|
-
|
2
|
-
require 'rspec'
|
3
|
-
require 'cantango'
|
1
|
+
require 'spec_helper'
|
4
2
|
require 'fixtures/models'
|
5
3
|
require 'cantango/rspec'
|
6
4
|
|
7
5
|
CanTango.configure do |config|
|
8
|
-
config.
|
9
|
-
config.
|
6
|
+
config.permission_engine.set :off
|
7
|
+
config.permit_engine.set :on
|
10
8
|
config.categories.register :blog_items => [Article, Post]
|
11
9
|
end
|
12
10
|
|
@@ -37,7 +35,6 @@ class EditorsRoleGroupPermit < CanTango::RoleGroupPermit
|
|
37
35
|
end
|
38
36
|
|
39
37
|
|
40
|
-
|
41
38
|
class UserRolePermit < CanTango::RolePermit
|
42
39
|
def initialize ability
|
43
40
|
super
|
@@ -86,8 +83,6 @@ describe CanTango::Ability do
|
|
86
83
|
end
|
87
84
|
|
88
85
|
subject { @ability }
|
89
|
-
its(:permit_class_names) { should include "AdminRolePermit" }
|
90
|
-
|
91
86
|
specify { @ability.should be_allowed_to(:read, Post)}
|
92
87
|
|
93
88
|
specify { @ability.should_not be_allowed_to(:read, Comment)}
|
@@ -118,9 +113,9 @@ describe CanTango::Ability do
|
|
118
113
|
end
|
119
114
|
|
120
115
|
subject { @ability }
|
121
|
-
its(:permit_class_names) { should include("UserRolePermit", "AdminsRoleGroupPermit") }
|
122
|
-
|
123
116
|
specify { @ability.should be_allowed_to(:read, Comment)}
|
117
|
+
specify { @ability.should be_allowed_to(:write, Article)}
|
118
|
+
|
124
119
|
specify { @ability.should be_allowed_to(:publish, Post)}
|
125
120
|
|
126
121
|
specify { @ability.should_not be_allowed_to(:publish, Article)}
|
@@ -3,7 +3,7 @@ require 'cantango'
|
|
3
3
|
require 'fixtures/models'
|
4
4
|
require 'cantango/rspec'
|
5
5
|
|
6
|
-
def config_folder
|
6
|
+
def config_folder
|
7
7
|
File.dirname(__FILE__)+ "/../fixtures/config/"
|
8
8
|
end
|
9
9
|
|
@@ -12,7 +12,7 @@ CanTango.configure do |config|
|
|
12
12
|
# config.permissions.set :on
|
13
13
|
config.engines.all :on
|
14
14
|
|
15
|
-
config.
|
15
|
+
config.permission_engine.config_path = config_folder
|
16
16
|
config.categories.register :blog_items => [Article, Post]
|
17
17
|
end
|
18
18
|
|
@@ -68,7 +68,6 @@ describe CanTango::Ability do
|
|
68
68
|
its(:user_account) { should be_a(UserAccount) }
|
69
69
|
its(:user) { should be_a(User) }
|
70
70
|
|
71
|
-
its(:permits) { should_not be_empty }
|
72
71
|
its(:roles) { should_not be_empty }
|
73
72
|
its(:role_groups) { should_not be_empty }
|
74
73
|
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
require 'cantango'
|
3
|
+
require 'fixtures/models'
|
4
|
+
require 'cantango/api/current_users'
|
5
|
+
require 'cantango/configuration/engines/store_engine_shared'
|
6
|
+
|
7
|
+
CanTango.config.users.register :user, :admin
|
8
|
+
|
9
|
+
class Context
|
10
|
+
include CanTango::Api::User::Ability
|
11
|
+
|
12
|
+
include CurrentUsers
|
13
|
+
extend ::CurrentUsers
|
14
|
+
end
|
15
|
+
|
16
|
+
describe CanTango::Api::User::Ability do
|
17
|
+
subject { Context.new }
|
18
|
+
|
19
|
+
describe 'user_ability user' do
|
20
|
+
specify { subject.user_ability(subject.current_user).should be_a CanTango::Ability }
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'user_ability admin' do
|
24
|
+
specify { subject.user_ability(subject.current_admin).should be_a CanTango::Ability }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -10,8 +10,8 @@ end
|
|
10
10
|
CanTango.configure do |config|
|
11
11
|
config.users.register :user, :admin
|
12
12
|
config.user_accounts.register :user, :admin
|
13
|
-
config.
|
14
|
-
config.
|
13
|
+
config.cache_engine.set :off
|
14
|
+
config.permit_engine.set :on
|
15
15
|
end
|
16
16
|
|
17
17
|
class UserRolePermit < CanTango::RolePermit
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Configuration::Autoload do
|
4
|
+
subject { CanTango.config.adapters }
|
5
|
+
|
6
|
+
describe 'should run adapter for moneta' do
|
7
|
+
before do
|
8
|
+
subject.adapter :moneta
|
9
|
+
end
|
10
|
+
|
11
|
+
specify { lambda { CanTango::Cache::MonetaCache }.should_not raise_error }
|
12
|
+
specify { lambda { CanTango::Ability::Cache::MonetaCache }.should_not raise_error }
|
13
|
+
specify { lambda { CanTango::PermissionEngine::MonetaStore }.should_not raise_error }
|
14
|
+
end
|
15
|
+
|
16
|
+
specify { lambda { CanTango::Ability::Cache::Kompiler }.should raise_error }
|
17
|
+
|
18
|
+
describe 'should run adapter for sourcify compiler' do
|
19
|
+
|
20
|
+
before do
|
21
|
+
subject.adapter :compiler
|
22
|
+
end
|
23
|
+
|
24
|
+
specify { lambda { CanTango::Ability::Cache::Kompiler }.should_not raise_error }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
@@ -6,11 +6,11 @@ require 'cantango/configuration/engines/store_engine_shared'
|
|
6
6
|
describe CanTango::Configuration::Engines::Cache do
|
7
7
|
|
8
8
|
it_should_behave_like 'Store Engine' do
|
9
|
-
subject { CanTango.config.
|
9
|
+
subject { CanTango.config.cache_engine }
|
10
10
|
end
|
11
11
|
|
12
12
|
it_should_behave_like 'Store' do
|
13
|
-
subject { CanTango.config.
|
13
|
+
subject { CanTango.config.cache_engine.store }
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
@@ -6,14 +6,14 @@ require 'cantango/configuration/engines/store_engine_shared'
|
|
6
6
|
require 'path_helper'
|
7
7
|
|
8
8
|
describe CanTango::Configuration::Engines::Permission do
|
9
|
-
subject { CanTango.config.
|
9
|
+
subject { CanTango.config.permission_engine }
|
10
10
|
|
11
11
|
it_should_behave_like 'Store Engine' do
|
12
|
-
subject { CanTango.config.
|
12
|
+
subject { CanTango.config.permission_engine }
|
13
13
|
end
|
14
14
|
|
15
15
|
it_should_behave_like 'Store' do
|
16
|
-
subject { CanTango.config.
|
16
|
+
subject { CanTango.config.permission_engine.store }
|
17
17
|
end
|
18
18
|
|
19
19
|
describe 'config_path' do
|
@@ -4,7 +4,43 @@ require 'fixtures/models'
|
|
4
4
|
|
5
5
|
require 'cantango/configuration/engines/engine_shared'
|
6
6
|
|
7
|
+
class InvalidPerformanceTool
|
8
|
+
end
|
9
|
+
|
10
|
+
class PerformanceTool
|
11
|
+
attr_reader :ability
|
12
|
+
|
13
|
+
def execute!
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
7
17
|
describe CanTango::Configuration::Engines do
|
18
|
+
subject { CanTango.config.engines }
|
19
|
+
|
20
|
+
describe 'default settings' do
|
21
|
+
describe 'default_available' do
|
22
|
+
its(:default_available) { should include(:permission, :permit, :cache) }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'available' do
|
26
|
+
%w(permit permission).each do |engine|
|
27
|
+
specify { subject.available?(engine).should be_true }
|
28
|
+
specify { subject.available?(engine.to_sym).should be_true }
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
specify { subject.registered.keys.should include(:permit, :permission) }
|
33
|
+
|
34
|
+
# TODO: should it be empty?
|
35
|
+
describe 'active' do
|
36
|
+
its(:active) { should == [] }
|
37
|
+
end
|
38
|
+
|
39
|
+
describe 'execution_order' do
|
40
|
+
its(:execution_order) { should == [:permission, :permit] }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
8
44
|
describe 'Permission engine' do
|
9
45
|
it_should_behave_like 'Engine' do
|
10
46
|
subject { CanTango.config.engine(:permission) }
|
@@ -23,7 +59,7 @@ describe CanTango::Configuration::Engines do
|
|
23
59
|
end
|
24
60
|
end
|
25
61
|
|
26
|
-
|
62
|
+
context 'all on' do
|
27
63
|
subject { CanTango.config.engines }
|
28
64
|
|
29
65
|
before do
|
@@ -31,10 +67,77 @@ describe CanTango::Configuration::Engines do
|
|
31
67
|
end
|
32
68
|
|
33
69
|
specify do
|
34
|
-
[:
|
35
|
-
CanTango.config.send(engine).on?.should be_true
|
70
|
+
[:permit, :permission, :cache].each do |engine|
|
71
|
+
CanTango.config.send("#{engine}_engine").on?.should be_true
|
36
72
|
end
|
37
73
|
end
|
74
|
+
|
75
|
+
describe 'active' do
|
76
|
+
its(:active) { should include(:permit, :permission) }
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'register' do
|
81
|
+
describe 'invalid engine registration' do
|
82
|
+
specify do
|
83
|
+
lambda { subject.register :performance => InvalidPerformanceTool }.should raise_error
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe 'valid engine registration' do
|
88
|
+
before do
|
89
|
+
subject.register :performance => PerformanceTool
|
90
|
+
end
|
91
|
+
|
92
|
+
specify { subject.registered.keys.should include(:performance) }
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe 'execution' do
|
97
|
+
context 'reverse execution order' do
|
98
|
+
before do
|
99
|
+
subject.execution_order = :permit, :permission
|
100
|
+
end
|
101
|
+
|
102
|
+
its(:execution_order) { should == [:permit, :permission] }
|
103
|
+
end
|
104
|
+
|
105
|
+
describe 'execute_before' do
|
106
|
+
before do
|
107
|
+
subject.execute_before :permit, :non_existing
|
108
|
+
end
|
109
|
+
|
110
|
+
its(:execution_order) { should == [:non_existing, :permit, :permission] }
|
111
|
+
end
|
112
|
+
|
113
|
+
describe 'execute_after' do
|
114
|
+
before do
|
115
|
+
subject.execute_after :permit, :performance
|
116
|
+
subject.execute_after :permission, :last
|
117
|
+
end
|
118
|
+
|
119
|
+
its(:execution_order) { should == [:non_existing, :permit, :performance, :permission, :last] }
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'execute_after' do
|
123
|
+
before do
|
124
|
+
subject.execute_last :very_last
|
125
|
+
end
|
126
|
+
|
127
|
+
its(:execution_order) { should == [:non_existing, :permit, :performance, :permission, :last, :very_last] }
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'execute_first' do
|
131
|
+
before do
|
132
|
+
subject.execute_first :very_first
|
133
|
+
end
|
134
|
+
|
135
|
+
after do
|
136
|
+
CanTango.config.engines.clear!
|
137
|
+
end
|
138
|
+
|
139
|
+
its(:execution_order) { should == [:very_first, :non_existing, :permit, :performance, :permission, :last, :very_last] }
|
140
|
+
end
|
38
141
|
end
|
39
142
|
end
|
40
143
|
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Configuration::PermitRegistry do
|
4
|
+
before do
|
5
|
+
@permit_registry = CanTango::Configuration::PermitRegistry.new
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should respond to permits groups methods" do
|
9
|
+
[:user, :account, :role, :role_group].each do |permit_group|
|
10
|
+
@permit_registry.should respond_to(permit_group)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Configuration::Permits do
|
4
|
+
before do
|
5
|
+
@permit_registry = CanTango::Configuration::Permits.instance
|
6
|
+
end
|
7
|
+
|
8
|
+
it "should respond to permits groups methods" do
|
9
|
+
[:user, :account, :role, :role_group].each do |permit_group|
|
10
|
+
@permit_registry.should respond_to(permit_group)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should treat missing methods as account keys" do
|
15
|
+
@permit_registry.any_method.should be_kind_of(CanTango::Configuration::PermitRegistry)
|
16
|
+
end
|
17
|
+
|
18
|
+
context "account keys" do
|
19
|
+
it "should behave like PermitRegistry" do
|
20
|
+
[:user, :account, :role, :role_group].each do |permit_group|
|
21
|
+
@permit_registry.admin_account.should respond_to(permit_group)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -28,15 +28,15 @@ describe CanTango::Configuration do
|
|
28
28
|
describe "configure DSL" do
|
29
29
|
before(:all) {
|
30
30
|
CanTango.configure do |config|
|
31
|
-
CanTango.config.engines.
|
32
|
-
|
31
|
+
CanTango.config.engines.each do |engine|
|
32
|
+
engine.set :off
|
33
33
|
end
|
34
34
|
end
|
35
35
|
}
|
36
36
|
|
37
|
-
CanTango.config.engines.
|
38
|
-
specify {
|
39
|
-
specify {
|
37
|
+
CanTango.config.engines.each do |engine|
|
38
|
+
specify { engine.on?.should be_false}
|
39
|
+
specify { engine.off?.should be_true}
|
40
40
|
end
|
41
41
|
end
|
42
42
|
end
|