cantango-core 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/Gemfile +7 -1
  2. data/Gemfile.lock +70 -12
  3. data/README.mdown +16 -14
  4. data/VERSION +1 -1
  5. data/cantango-core.gemspec +41 -51
  6. data/lib/cantango/ability/base/callbacks.rb +37 -0
  7. data/lib/cantango/ability/base.rb +21 -8
  8. data/lib/cantango/ability/cache.rb +1 -1
  9. data/lib/cantango/ability/executor/modes.rb +6 -6
  10. data/lib/cantango/ability/executor/no_cache_mode.rb +2 -6
  11. data/lib/cantango/ability/executor.rb +1 -1
  12. data/lib/cantango/ability/helper/account.rb +6 -10
  13. data/lib/cantango/ability/helper/engine.rb +22 -26
  14. data/lib/cantango/ability/helper/user.rb +10 -14
  15. data/lib/cantango/ability/helper.rb +1 -1
  16. data/lib/cantango/ability.rb +7 -2
  17. data/lib/cantango/adaptor/active_record.rb +6 -0
  18. data/lib/cantango/adaptor/data_mapper.rb +5 -0
  19. data/lib/cantango/adaptor/generic.rb +12 -0
  20. data/lib/cantango/adaptor/mongo.rb +13 -0
  21. data/lib/cantango/adaptor/mongo_mapper.rb +5 -0
  22. data/lib/cantango/adaptor/mongoid.rb +5 -0
  23. data/lib/cantango/adaptor/relational.rb +8 -0
  24. data/lib/cantango/{rules/adaptor.rb → adaptor.rb} +4 -4
  25. data/lib/cantango/{rules → cancan}/rule_class.rb +1 -1
  26. data/lib/cantango/cancan.rb +5 -0
  27. data/lib/cantango/core.rb +5 -13
  28. data/lib/cantango/engine.rb +6 -16
  29. data/lib/cantango/filter/base.rb +1 -1
  30. data/lib/cantango/helpers/debug.rb +31 -1
  31. data/lib/cantango/loader/yaml.rb +2 -11
  32. data/lib/cantango/model/guest.rb +3 -1
  33. data/spec/cantango/ability/base_spec.rb +13 -63
  34. data/spec/cantango/ability/cache/simple_key_spec.rb +29 -0
  35. data/spec/cantango/ability/executor/base_spec.rb +12 -52
  36. data/spec/cantango/ability/executor/custom_spec.rb +51 -0
  37. data/spec/cantango/ability/executor/modes_spec.rb +27 -49
  38. data/spec/cantango/ability/executor/no_cache_mode_spec.rb +29 -0
  39. data/spec/cantango/ability/helper/account_spec.rb +37 -0
  40. data/spec/cantango/ability/helper/engine_spec.rb +36 -0
  41. data/spec/cantango/ability/helper/user_spec.rb +38 -0
  42. data/spec/cantango/adaptor/active_record_spec.rb +38 -0
  43. data/spec/cantango/adaptor/data_mapper_spec.rb +39 -0
  44. data/spec/cantango/{rules/adaptor → adaptor}/mongo_mapper_spec.rb +0 -0
  45. data/spec/cantango/{rules/adaptor → adaptor}/mongoid_spec.rb +0 -0
  46. data/spec/cantango/cancan/rule_spec.rb +5 -0
  47. data/spec/cantango/core_spec.rb +0 -2
  48. data/spec/cantango/engine_spec.rb +51 -0
  49. data/spec/cantango/filter/base_spec.rb +25 -0
  50. data/spec/cantango/helpers/debug_spec.rb +29 -0
  51. data/spec/cantango/loader/yaml_spec.rb +5 -0
  52. data/spec/cantango/model/guest_spec.rb +14 -0
  53. data/spec/cantango/rspec/be_allowed_to_spec.rb +5 -0
  54. data/spec/cantango/scope/ability_spec.rb +33 -0
  55. data/spec/fixtures/models/account.rb +7 -0
  56. data/spec/fixtures/models/admin.rb +2 -0
  57. data/spec/fixtures/models/admin_account.rb +8 -0
  58. data/spec/fixtures/models/items.rb +11 -0
  59. data/spec/fixtures/models/user.rb +20 -0
  60. data/spec/fixtures/models.rb +2 -0
  61. data/spec/spec_helper.rb +4 -0
  62. metadata +60 -67
  63. data/lib/cantango/ability/executor/cache_mode.rb +0 -33
  64. data/lib/cantango/ability/helper/role.rb +0 -21
  65. data/lib/cantango/ability/helper/role_group.rb +0 -21
  66. data/lib/cantango/macros/account.rb +0 -14
  67. data/lib/cantango/macros/user.rb +0 -16
  68. data/lib/cantango/macros.rb +0 -11
  69. data/lib/cantango/rules/adaptor/active_record.rb +0 -10
  70. data/lib/cantango/rules/adaptor/data_mapper.rb +0 -11
  71. data/lib/cantango/rules/adaptor/generic.rb +0 -16
  72. data/lib/cantango/rules/adaptor/mongo.rb +0 -19
  73. data/lib/cantango/rules/adaptor/mongo_mapper.rb +0 -10
  74. data/lib/cantango/rules/adaptor/mongoid.rb +0 -9
  75. data/lib/cantango/rules/adaptor/relational.rb +0 -13
  76. data/lib/cantango/rules/dsl.rb +0 -24
  77. data/lib/cantango/rules/relation.rb +0 -67
  78. data/lib/cantango/rules/scope.rb +0 -24
  79. data/lib/cantango/rules.rb +0 -8
  80. data/spec/cantango/ability/cached_spec.rb +0 -0
  81. data/spec/cantango/ability/executor/base2.rb +0 -75
  82. data/spec/cantango/ability/executor/cache_mode_spec.rb +0 -77
  83. data/spec/cantango/macros/account_spec.rb +0 -0
  84. data/spec/cantango/macros/user_spec.rb +0 -0
  85. data/spec/cantango/rules/adaptor/active_record_spec.rb +0 -0
  86. data/spec/cantango/rules/adaptor/data_mapper_spec.rb +0 -0
  87. data/spec/cantango/rules/adaptor_spec.rb +0 -0
  88. data/spec/cantango/rules/dsl_spec.rb +0 -0
  89. data/spec/cantango/rules/relation_spec.rb +0 -0
  90. data/spec/cantango/rules/rule_class_spec.rb +0 -0
  91. data/spec/cantango/rules/scope_spec.rb +0 -0
  92. data/spec/cantango/rules_spec.rb +0 -55
@@ -1,75 +0,0 @@
1
- require 'rspec'
2
- require 'cantango'
3
- # require 'simple_roles'
4
- require 'fixtures/models'
5
- require 'cantango/rspec'
6
-
7
- def config_folder
8
- File.dirname(__FILE__)+ "/../fixtures/config/"
9
- end
10
-
11
- CanTango.configure do |config|
12
- config.clear!
13
- end
14
- # CanTango.debug!
15
-
16
- class User
17
- tango_user
18
- include_and_extend SimpleRoles
19
- end
20
-
21
- class AdminRolePermit < CanTango::RolePermit
22
- def initialize ability
23
- super
24
- end
25
-
26
- protected
27
-
28
- def static_rules
29
- can :read, Article
30
- end
31
-
32
- module Cached
33
- def permit_rules
34
- can :edit, Article
35
- can :delete, Article
36
- end
37
- end
38
- end
39
-
40
- module CanTango
41
- class Ability
42
- def permit_rules
43
- can :read, Post
44
- end
45
- end
46
- end
47
-
48
- describe CanTango::AbilityExecutor do
49
- context 'non-cached only' do
50
- before do
51
- CanTango.configure.ability.mode = :no_cache
52
-
53
- @user = User.new 'admin', 'admin@mail.ru', :role => 'admin'
54
- @abil = CanTango::AbilityExecutor.new @user
55
- end
56
-
57
- subject { CanTango::AbilityExecutor.new @user }
58
-
59
- describe 'config no_cache' do
60
- specify { CanTango.configure.ability.modes.should == [:no_cache] }
61
- end
62
-
63
- describe 'engines_on?' do
64
- specify { subject.engines_on?.should be_true }
65
- end
66
-
67
- its(:cached_rules) { should be_empty }
68
- its(:non_cached_rules) { should_not be_empty }
69
-
70
- describe 'rules contain only non-cached rules' do
71
- specify { subject.rules.size.should == @abil.non_cached_rules.size }
72
- specify { subject.rules.size.should == 2 }
73
- end
74
- end
75
- end
@@ -1,77 +0,0 @@
1
- require 'rspec'
2
- require 'cantango'
3
- # require 'simple_roles'
4
- require 'fixtures/models'
5
- require 'cantango/rspec'
6
-
7
- def config_folder
8
- File.dirname(__FILE__)+ "/../fixtures/config/"
9
- end
10
-
11
- CanTango.configure do |config|
12
- config.clear!
13
- config.ability.mode = :cache
14
- end
15
- # CanTango.debug!
16
-
17
- class User
18
- tango_user
19
- include_and_extend SimpleRoles
20
- end
21
-
22
- class AdminRolePermit < CanTango::Permit::Role
23
- def initialize ability
24
- super
25
- end
26
-
27
- protected
28
-
29
- def static_rules
30
- can :read, Article
31
- end
32
-
33
- module Cached
34
- def permit_rules
35
- can :edit, Article
36
- can :delete, Article
37
- end
38
- end
39
- end
40
-
41
- module CanTango
42
- class CachedAbility
43
- def permit_rules
44
- can :read, Post
45
- end
46
- end
47
- end
48
-
49
- describe CanTango::Ability::Executor::CacheMode do
50
- context 'cached only' do
51
- before do
52
- CanTango.configure.ability.mode = :cache
53
-
54
- @user = User.new 'admin', 'admin@mail.ru', :role => 'admin'
55
- @abil = CanTango::AbilityExecutor.new @user
56
- end
57
-
58
- subject { CanTango::AbilityExecutor.new @user }
59
-
60
- describe 'config cache' do
61
- specify { CanTango.configure.ability.modes.should == [:cache] }
62
- end
63
-
64
- describe 'engines_on?' do
65
- specify { subject.engines_on?.should be_true }
66
- end
67
-
68
- its(:cached_rules) { should_not be_empty }
69
- its(:non_cached_rules) { should be_empty }
70
-
71
- describe 'rules contain only non-cached rules' do
72
- specify { subject.rules.size.should == @abil.cached_rules.size }
73
- specify { subject.rules.size.should == 4 }
74
- end
75
- end
76
- end
77
-
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -1,55 +0,0 @@
1
- require 'rspec'
2
- require 'cantango'
3
- require 'fixtures/models'
4
-
5
- class SystemRolePermit < CanTango::RolePermit
6
- def initialize ability
7
- super
8
- end
9
-
10
- protected
11
-
12
- def static_rules
13
- end
14
- end
15
-
16
- def setup
17
- let (:user) do
18
- User.new 'kris'
19
- end
20
-
21
- let (:user_account) do
22
- ua = UserAccount.new user
23
- user.account = ua
24
- end
25
-
26
- let (:ability) do
27
- CanTango::Ability.new user_account
28
- end
29
-
30
- let (:permit) do
31
- SystemRolePermit.new ability
32
- end
33
-
34
- let (:executor) do
35
- CanTango::PermitEngine::Executor::System.new permit, user_account
36
- end
37
- end
38
-
39
-
40
- describe CanTango::Rules do
41
- setup
42
-
43
- describe '#can' do
44
- it "should not have any rules" do
45
- permit.rules.should be_empty
46
- end
47
-
48
- it "should have rules after can" do
49
- permit.can :read, Comment
50
- permit.rules.should_not be_empty
51
- end
52
- end
53
- end
54
-
55
-