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
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= user.to_s.camelize %>Permit < CanTango::UserPermit
|
2
|
+
def initialize ability
|
3
|
+
super
|
4
|
+
end
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def permit_rules
|
9
|
+
# insert your can, cannot and any other rule statements here
|
10
|
+
<%= permit_logic.strip %>
|
11
|
+
<%= license_logic %>
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'generators/cantango/base'
|
2
|
+
require 'generators/cantango/license_base'
|
3
|
+
require 'generators/cantango/permit_generator'
|
4
|
+
|
5
|
+
module Cantango
|
6
|
+
module Generators
|
7
|
+
class UserPermitGenerator < Cantango::Generators::Base
|
8
|
+
desc "Creates a Permit for a user in 'app/permits' with specific permissions and/or licenses"
|
9
|
+
|
10
|
+
argument :user, :type => :string, :desc => "User class to create permit for"
|
11
|
+
|
12
|
+
class_option :licenses, :type => :array, :default => [], :desc => "Licenses to use in Permit"
|
13
|
+
|
14
|
+
class_option :account, :type => :string,
|
15
|
+
:desc => "Generate permits for a specific user account"
|
16
|
+
|
17
|
+
class_option :group, :type => :boolean, :default => false, :desc => "Generate permit for a role group"
|
18
|
+
|
19
|
+
source_root File.dirname(__FILE__) + '/templates'
|
20
|
+
|
21
|
+
def main_flow
|
22
|
+
template_permit user, account
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def is_user?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
include Cantango::Generators::LicenseBase
|
32
|
+
include Cantango::Generators::PermitGenerator
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
data/spec/TODO
CHANGED
@@ -1,7 +1,2 @@
|
|
1
|
-
|
1
|
+
1) Sweetloader into Gemfile!
|
2
2
|
|
3
|
-
To provide configuration options (global engines) and options on configuration macros tango_user and tango_user_account.
|
4
|
-
|
5
|
-
Don't know for now what are the options should be except turning off permission and permit engines!
|
6
|
-
|
7
|
-
Fx present CanTango.permission_engine = false -- it is only a stub - don't know if it is enough for real configuration needs.
|
@@ -1,25 +1,24 @@
|
|
1
1
|
require 'active_record/spec_helper'
|
2
2
|
require_all File.dirname(__FILE__) + "/../../shared/"
|
3
3
|
|
4
|
-
describe 'Cantango config:
|
4
|
+
describe 'Cantango config: permissions.yml' do
|
5
5
|
|
6
6
|
before(:each) {
|
7
7
|
CanTango.configure do |config|
|
8
|
-
config.
|
9
|
-
config.
|
10
|
-
config.
|
8
|
+
config.permit_engine.set :off
|
9
|
+
config.permission_engine.config_path = File.dirname(__FILE__)
|
10
|
+
config.permission_engine.set :on
|
11
11
|
end
|
12
12
|
@user ||= User.create!(:email => "kris@gmail.com", :role => 'musician')
|
13
13
|
@own_todo = Todo.create!
|
14
14
|
@own_todo.authors << @user
|
15
15
|
@own_todo.save!
|
16
|
-
|
17
16
|
}
|
18
17
|
|
19
18
|
after(:each) {
|
20
19
|
CanTango.configure do |config|
|
21
|
-
config.
|
22
|
-
config.
|
20
|
+
config.permit_engine.set :on
|
21
|
+
config.permission_engine.set :off
|
23
22
|
end
|
24
23
|
}
|
25
24
|
|
@@ -73,5 +72,5 @@ describe 'Cantango config: tango_permissions.yml' do
|
|
73
72
|
|
74
73
|
end
|
75
74
|
|
76
|
-
CanTango.config.
|
77
|
-
CanTango.config.
|
75
|
+
CanTango.config.permission_engine.set :off
|
76
|
+
CanTango.config.permit_engine.set :on
|
@@ -1,2 +1,2 @@
|
|
1
1
|
# Doing this because all AR suite for now is based on permit_engine
|
2
|
-
CanTango.config.
|
2
|
+
CanTango.config.permission_engine.set :off
|
@@ -13,7 +13,8 @@ class User < ActiveRecord::Base
|
|
13
13
|
end
|
14
14
|
|
15
15
|
class Admin < User
|
16
|
-
tango_user # see macros
|
16
|
+
tango_user # see macros
|
17
|
+
masquerader
|
17
18
|
end
|
18
19
|
|
19
20
|
# should not inherit from AR, since no need to persist Guest
|
@@ -21,6 +22,10 @@ class Guest
|
|
21
22
|
|
22
23
|
tango_user # see macros
|
23
24
|
|
25
|
+
def email
|
26
|
+
'guest@gmail.com'
|
27
|
+
end
|
28
|
+
|
24
29
|
def role_groups_list
|
25
30
|
[]
|
26
31
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
-
require 'spec_helper'
|
2
1
|
require 'rails'
|
2
|
+
require 'cantango'
|
3
|
+
require 'cantango/rspec/matchers'
|
4
|
+
|
3
5
|
require 'active_record'
|
4
|
-
|
5
|
-
require '
|
6
|
+
|
7
|
+
require 'cutter'
|
6
8
|
require 'yaml'
|
7
9
|
require 'logger'
|
8
10
|
require 'database_cleaner'
|
@@ -15,5 +17,5 @@ require 'active_record/helper/rails_config'
|
|
15
17
|
Cutter::Inspection.loud!
|
16
18
|
|
17
19
|
CanTango.configure do |config|
|
18
|
-
config.
|
20
|
+
config.permit_engine.set :on
|
19
21
|
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Ability::Cache::Key do
|
4
|
+
let (:session) do
|
5
|
+
{}
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:user) { User.new 'kris', 'kris@gmail.com' }
|
9
|
+
let(:subj) { user }
|
10
|
+
|
11
|
+
def set_valid_unique_field
|
12
|
+
CanTango.config.user.unique_key_field = :email
|
13
|
+
end
|
14
|
+
|
15
|
+
def set_invalid_unique_field
|
16
|
+
# unique_key_field not configured
|
17
|
+
CanTango.config.user.unique_key_field = :blip
|
18
|
+
end
|
19
|
+
|
20
|
+
subject do
|
21
|
+
CanTango::Ability::Cache::Key.new user, subj
|
22
|
+
end
|
23
|
+
|
24
|
+
specify { subject.should be_a CanTango::Ability::Cache::Key }
|
25
|
+
|
26
|
+
context 'using invalid user' do
|
27
|
+
before do
|
28
|
+
set_invalid_unique_field
|
29
|
+
end
|
30
|
+
|
31
|
+
specify { lambda { subject.value }.should raise_error }
|
32
|
+
end
|
33
|
+
|
34
|
+
context 'valid user' do
|
35
|
+
before do
|
36
|
+
set_valid_unique_field
|
37
|
+
end
|
38
|
+
|
39
|
+
specify { lambda { subject.value }.should_not raise_error }
|
40
|
+
specify { subject.value.should be_a Fixnum } # hash
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '#same?' do
|
44
|
+
context 'set to same' do
|
45
|
+
|
46
|
+
before do
|
47
|
+
pending
|
48
|
+
session[:cache_key] = subject.value
|
49
|
+
end
|
50
|
+
|
51
|
+
specify { subject.same?(session).should be_true }
|
52
|
+
end
|
53
|
+
|
54
|
+
context 'set to random' do
|
55
|
+
before do
|
56
|
+
pending
|
57
|
+
session[:cache_key] = 25676923
|
58
|
+
end
|
59
|
+
|
60
|
+
specify { subject.same?(session).should be_false }
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
@@ -2,32 +2,21 @@ require 'rspec'
|
|
2
2
|
require 'cantango'
|
3
3
|
require 'sourcify'
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
module Cachestub
|
8
|
-
|
9
|
-
class << self
|
10
|
-
include CanTango::Ability::Cache::Kompiler
|
5
|
+
CanTango.config.adapters.use :compiler, :moneta
|
11
6
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
def decompile_rules rules
|
17
|
-
decompile_rules! rules
|
7
|
+
describe CanTango::Ability::Cache::Kompiler do
|
8
|
+
subject do
|
9
|
+
CanTango::Ability::Cache::Kompiler.new
|
18
10
|
end
|
19
11
|
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
before(:each) {
|
12
|
+
before(:each) do
|
24
13
|
$b = [:a,:b,:c]
|
25
14
|
@condition_block = Proc.new { |arg| $b = [1, 2, 3, arg] }
|
26
15
|
@rules = [CanCan::Rule.new(true, :read, :all, nil, @condition_block) ]
|
27
|
-
|
16
|
+
end
|
28
17
|
|
29
18
|
it "should compile! rules" do
|
30
|
-
|
19
|
+
subject.compile!(@rules).first.block.should == "proc { |arg| $b = [1, 2, 3, arg] }"
|
31
20
|
end
|
32
21
|
|
33
22
|
# Direct testing doesn't work here because raw_rules.first.eval.to_source raises exception.
|
@@ -36,10 +25,9 @@ end
|
|
36
25
|
# I.e. things like eval( (Proc.new{}).to_source ).to_source do not work.
|
37
26
|
# But for our needs basic two operations flow like Proc -> String -> (evaled)Proc is pretty enough
|
38
27
|
it "should decompile! rules" do
|
39
|
-
compiled_rules =
|
40
|
-
raw_rules =
|
28
|
+
compiled_rules = subject.compile!(@rules)
|
29
|
+
raw_rules = subject.decompile! compiled_rules
|
41
30
|
raw_rules.first.block.call(4)
|
42
31
|
$b.should == [1,2,3,4]
|
43
32
|
end
|
44
|
-
|
45
33
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
CanTango.config.adapters.use :compiler
|
4
|
+
|
5
|
+
describe CanTango::Ability::Cache::Reader do
|
6
|
+
let (:session) do
|
7
|
+
{}
|
8
|
+
end
|
9
|
+
|
10
|
+
let(:user) { User.new 'kris', 'kris@gmail.com' }
|
11
|
+
|
12
|
+
let(:ability) { CanTango::Ability.new user, :session => session }
|
13
|
+
|
14
|
+
let(:cache) { CanTango::Ability::Cache.new ability }
|
15
|
+
|
16
|
+
subject do
|
17
|
+
CanTango::Ability::Cache::Reader.new cache
|
18
|
+
end
|
19
|
+
|
20
|
+
specify { subject.should be_a CanTango::Ability::Cache::Reader }
|
21
|
+
|
22
|
+
describe 'prepared rules' do
|
23
|
+
before do
|
24
|
+
$b = [:a,:b,:c]
|
25
|
+
@condition_block = Proc.new { |arg| $b = [1, 2, 3, arg] }
|
26
|
+
@rules = [CanCan::Rule.new(true, :read, :all, nil, @condition_block) ]
|
27
|
+
|
28
|
+
subject.expects(:loaded_rules).returns(@rules)
|
29
|
+
end
|
30
|
+
|
31
|
+
specify do
|
32
|
+
subject.prepared_rules.should == @rules
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should have proc condition block' do
|
36
|
+
$b = nil
|
37
|
+
@rules.first.block.call(4)
|
38
|
+
$b.should == [1,2,3,4]
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Ability::Cache::Reader do
|
4
|
+
let (:session) do
|
5
|
+
{}
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:user) { User.new 'kris', 'kris@gmail.com' }
|
9
|
+
|
10
|
+
let(:ability) { CanTango::Ability.new user, :session => session }
|
11
|
+
|
12
|
+
let(:cache) { CanTango::Ability::Cache.new ability }
|
13
|
+
|
14
|
+
subject do
|
15
|
+
CanTango::Ability::Cache::Reader.new cache
|
16
|
+
end
|
17
|
+
|
18
|
+
specify { subject.should be_a CanTango::Ability::Cache::Reader }
|
19
|
+
|
20
|
+
describe 'prepared rules' do
|
21
|
+
before do
|
22
|
+
$b = [:a,:b,:c]
|
23
|
+
@rules = [ CanCan::Rule.new(true, :read, :all, nil, {}) ]
|
24
|
+
|
25
|
+
subject.expects(:loaded_rules).returns(@rules)
|
26
|
+
end
|
27
|
+
|
28
|
+
specify do
|
29
|
+
subject.prepared_rules.should == @rules
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Ability::Cache::RulesCache do
|
4
|
+
let (:session) do
|
5
|
+
{}
|
6
|
+
end
|
7
|
+
|
8
|
+
subject do
|
9
|
+
CanTango::Ability::Cache::RulesCache.new session
|
10
|
+
end
|
11
|
+
|
12
|
+
specify { subject.should be_a CanTango::Ability::Cache::RulesCache }
|
13
|
+
end
|
14
|
+
|
15
|
+
|
@@ -5,7 +5,7 @@ describe CanTango::Ability::Cache::SessionCache do
|
|
5
5
|
subject { CanTango::Ability::Cache::SessionCache.new :roles, :session => {} }
|
6
6
|
its(:name) { should == :roles}
|
7
7
|
its(:store) { should_not be_nil}
|
8
|
-
its(:store) { should be_a CanTango::Cache::
|
8
|
+
its(:store) { should be_a CanTango::Cache::HashCache }
|
9
9
|
|
10
10
|
end
|
11
11
|
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CanTango::Ability::Cache::Writer do
|
4
|
+
let (:session) do
|
5
|
+
{}
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:user) { User.new 'kris', 'kris@gmail.com' }
|
9
|
+
|
10
|
+
let(:ability) { CanTango::Ability.new user, :session => session }
|
11
|
+
|
12
|
+
let(:cache) { CanTango::Ability::Cache.new ability }
|
13
|
+
|
14
|
+
subject do
|
15
|
+
CanTango::Ability::Cache::Writer.new cache
|
16
|
+
end
|
17
|
+
|
18
|
+
specify { subject.should be_a CanTango::Ability::Cache::Writer }
|
19
|
+
end
|
20
|
+
|
21
|
+
|