canard 0.3.4 → 0.3.5

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -147,12 +147,15 @@ to accept pull requests for tested Rails 2.x updates if anybody is game.
147
147
 
148
148
  == Contributors
149
149
 
150
+ git log | grep Author | sort | uniq
151
+
150
152
  * James McCarthy
151
153
  * Joey Geiger
154
+ * Morton Jonuschat
152
155
 
153
156
  == Credits
154
157
 
155
- Thanks to Ryan Bates for creating the awesome CanCan (http://wiki.github.com/ryanb/cancan/role-based-authorization)
158
+ Thanks to Ryan Bates for creating the awesome CanCan (http://wiki.github.com/ryanb/cancan)
156
159
  and Martin Rehfeld for implementing Role Based Authorization in the form of RoleModel (http://github.com/martinrehfeld/role_model).
157
160
 
158
161
  == Copyright
data/TODO CHANGED
@@ -1,9 +1,13 @@
1
+ 0.4.0
2
+ * Make the roles_attribute_name configureable in UserModel.
3
+ * Make the Ability user referece configureable in Ability.
1
4
  * Test the generators.
2
- * Test the railtie
3
- * Expand the tests to produce all the standard abilities: index,show,read,new,create,edit,update,destroy.
5
+ * Test the railtie (currently implicity tested in dummy app).
6
+ * Add upgrade generator to move the now deprecated definitions to the new syntax.
7
+ * Remove old definition syntax and therefore deprecations.
8
+ * Remove ActiveSupport runtime dependency (which is just used for deprecation warnings).
9
+ 0.5.0
10
+ * Abstract out the ActiveRecord extensions into a model adapter to become framework independent.
11
+ * Expand the generated tests to produce all the standard abilities: index,show,read,new,create,edit,update,destroy.
4
12
  * Add test unit generator.
5
13
  * Add install generator to allow overriding of the default tests.
6
- * Make the Ability user referece configureable in Ability.
7
- * Abstract out the ActiveRecord extensions into a model adapter.
8
- * Make the roles_attribute_name configureable in UserModel.
9
- * Remove ActiveSupport runtime dependency.
data/lib/ability.rb CHANGED
@@ -54,11 +54,8 @@ class Ability
54
54
 
55
55
  private
56
56
 
57
- def ability_definitions
58
- Canard.ability_definitions
59
- end
60
-
61
57
  def append_abilities(role)
58
+ ability_definitions = Canard.ability_definitions
62
59
  instance_eval(&ability_definitions[role]) if ability_definitions.has_key?(role)
63
60
  end
64
61
 
@@ -21,6 +21,11 @@ module Canard
21
21
 
22
22
  end
23
23
 
24
+ def self.load_paths
25
+ Abilities.definition_paths.map { |path| File.join(Rails.root, path) }
26
+ end
27
+
28
+ # TODO remove at version 0.4.0
24
29
  def self.find_abilities #:nodoc:
25
30
  absolute_abilities_path = File.expand_path(abilities_path)
26
31
 
@@ -30,13 +35,12 @@ module Canard
30
35
  end
31
36
  end
32
37
 
33
- Abilities.definition_paths.each do |path|
34
- Dir[File.join(Rails.root, path, '**', '*.rb')].sort.each do |file|
38
+ load_paths.each do |path|
39
+ Dir[File.join(path, '**', '*.rb')].sort.each do |file|
35
40
  load file
36
41
  end
37
42
  end
38
43
 
39
44
  end
40
45
 
41
-
42
46
  end
@@ -4,6 +4,14 @@ require 'rails'
4
4
  module Canard
5
5
  class Railtie < Rails::Railtie
6
6
 
7
+ initializer "carard.no_eager_loading", :before => 'before_eager_loading' do |app|
8
+ ActiveSupport::Dependencies.autoload_paths.reject!{ |path| Canard.load_paths.include?(path) }
9
+ # Don't eagerload our configs, we'll deal with them ourselves
10
+ app.config.eager_load_paths = app.config.eager_load_paths.reject do |path|
11
+ Canard.load_paths.include?(path)
12
+ end
13
+ end
14
+
7
15
  initializer "canard.active_record" do |app|
8
16
  ActiveSupport.on_load :active_record do
9
17
  extend Canard::UserModel
@@ -59,7 +59,7 @@ module Canard
59
59
 
60
60
  roles options[:roles] if options.has_key?(:roles) && has_roles_mask_attribute? || has_roles_mask_accessors?
61
61
 
62
- if respond_to?(:table_exists?) && table_exists?
62
+ if active_record_table?
63
63
  valid_roles.each do |role|
64
64
  define_scopes_for_role role
65
65
  end
@@ -76,6 +76,10 @@ module Canard
76
76
 
77
77
  private
78
78
 
79
+ def active_record_table?
80
+ respond_to?(:table_exists?) && table_exists?
81
+ end
82
+
79
83
  def has_roles_mask_accessors?
80
84
  instance_method_names = instance_methods.map { |method_name| method_name.to_s }
81
85
  [roles_attribute_name.to_s, "#{roles_attribute_name}="].all? do |accessor|
@@ -84,7 +88,7 @@ module Canard
84
88
  end
85
89
 
86
90
  def has_roles_mask_attribute?
87
- respond_to?(:column_names) && column_names.include?(roles_attribute_name.to_s)
91
+ active_record_table? && column_names.include?(roles_attribute_name.to_s)
88
92
  end
89
93
 
90
94
  def define_scopes_for_role(role)
@@ -1,3 +1,3 @@
1
1
  module Canard
2
- VERSION = "0.3.4"
2
+ VERSION = "0.3.5"
3
3
  end
@@ -19,40 +19,61 @@ describe Canard::UserModel do
19
19
 
20
20
  describe 'acts_as_user' do
21
21
 
22
- it 'should add role_model to this model' do
22
+ it 'adds role_model to the class' do
23
23
  User.included_modules.must_include RoleModel
24
24
  User.must_respond_to :roles
25
25
  end
26
26
 
27
- describe 'on a model with a role mask' do
27
+ describe "on an ActiveRecord model" do
28
28
 
29
- describe 'and :roles => [] specified' do
29
+ describe 'with a role_mask' do
30
30
 
31
- it 'sets the valid_roles for the class' do
32
- User.valid_roles.must_equal [:viewer, :author, :admin]
31
+ describe 'and :roles => [] specified' do
32
+
33
+ it 'sets the valid_roles for the class' do
34
+ User.valid_roles.must_equal [:viewer, :author, :admin]
35
+ end
36
+
37
+ end
38
+
39
+ describe 'and no :roles => [] specified' do
40
+
41
+ it 'sets no roles' do
42
+ UserWithoutRole.valid_roles.must_equal []
43
+ end
33
44
  end
34
45
 
35
46
  end
36
47
 
37
- describe 'with no :roles => [] specified' do
48
+ describe 'with no roles_mask' do
38
49
 
39
50
  it 'sets no roles' do
40
51
  UserWithoutRole.valid_roles.must_equal []
41
52
  end
42
53
  end
43
54
 
44
- end
55
+ describe "with no table" do
56
+
57
+ subject { Class.new(ActiveRecord::Base) }
45
58
 
46
- describe 'on a model with no roles_mask' do
47
-
48
- it 'sets no roles' do
49
- UserWithoutRole.valid_roles.must_equal []
59
+ it "sets no roles" do
60
+ subject.class_eval { acts_as_user :roles => [:admin] }
61
+ subject.valid_roles.must_equal []
62
+ end
63
+
64
+ it "does not raise any errors" do
65
+ proc { subject.class_eval { acts_as_user :roles => [:admin] } }.must_be_silent
66
+ end
67
+
68
+ it "returns nil" do
69
+ subject.class_eval { acts_as_user :roles => [:admin] }.must_be_nil
70
+ end
50
71
  end
51
72
  end
73
+
74
+ describe "on a regular Ruby class" do
52
75
 
53
- describe "on a non ActiveRecord User class" do
54
-
55
- describe "with a roles_mask attribute" do
76
+ describe "with a roles_mask" do
56
77
 
57
78
  it "assigns the roles" do
58
79
  PlainRubyUser.valid_roles.must_equal [:viewer, :author, :admin]
@@ -65,26 +86,25 @@ describe Canard::UserModel do
65
86
  PlainRubyNonUser.valid_roles.must_equal []
66
87
  end
67
88
  end
68
-
69
89
  end
70
90
  end
71
91
 
72
92
  describe "scopes" do
73
93
 
74
- before do
75
- @no_role = User.create
76
- @admin_author_viewer = User.create(:roles => [:admin, :author, :viewer])
77
- @author_viewer = User.create(:roles => [:author, :viewer])
78
- @viewer = User.create(:roles => [:viewer])
79
- @admin_only = User.create(:roles => [:admin])
80
- @author_only = User.create(:roles => [:author])
81
- end
94
+ describe "on an ActiveRecord model with roles" do
82
95
 
83
- after do
84
- User.delete_all
85
- end
96
+ before do
97
+ @no_role = User.create
98
+ @admin_author_viewer = User.create(:roles => [:admin, :author, :viewer])
99
+ @author_viewer = User.create(:roles => [:author, :viewer])
100
+ @viewer = User.create(:roles => [:viewer])
101
+ @admin_only = User.create(:roles => [:admin])
102
+ @author_only = User.create(:roles => [:author])
103
+ end
86
104
 
87
- describe "on models with roles" do
105
+ after do
106
+ User.delete_all
107
+ end
88
108
 
89
109
  subject { User }
90
110
 
@@ -442,7 +462,7 @@ describe Canard::UserModel do
442
462
 
443
463
  end
444
464
 
445
- describe "on a non ActiveRecord class" do
465
+ describe "on a plain Ruby class" do
446
466
 
447
467
  subject { PlainRubyUser }
448
468
 
metadata CHANGED
@@ -1,118 +1,90 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: canard
3
- version: !ruby/object:Gem::Version
4
- hash: 27
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.5
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 3
9
- - 4
10
- version: 0.3.4
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - James McCarthy
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-05-12 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-05-25 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: minitest
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &2152467160 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 2
31
- version: "2"
20
+ - !ruby/object:Gem::Version
21
+ version: '2'
32
22
  type: :development
33
- version_requirements: *id001
34
- - !ruby/object:Gem::Dependency
35
- name: sqlite3
36
23
  prerelease: false
37
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *2152467160
25
+ - !ruby/object:Gem::Dependency
26
+ name: sqlite3
27
+ requirement: &2152466380 !ruby/object:Gem::Requirement
38
28
  none: false
39
- requirements:
40
- - - ">="
41
- - !ruby/object:Gem::Version
42
- hash: 3
43
- segments:
44
- - 0
45
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
46
33
  type: :development
47
- version_requirements: *id002
48
- - !ruby/object:Gem::Dependency
49
- name: rails
50
34
  prerelease: false
51
- requirement: &id003 !ruby/object:Gem::Requirement
35
+ version_requirements: *2152466380
36
+ - !ruby/object:Gem::Dependency
37
+ name: rails
38
+ requirement: &2152464940 !ruby/object:Gem::Requirement
52
39
  none: false
53
- requirements:
40
+ requirements:
54
41
  - - ~>
55
- - !ruby/object:Gem::Version
56
- hash: 9
57
- segments:
58
- - 3
59
- - 2
60
- - 3
42
+ - !ruby/object:Gem::Version
61
43
  version: 3.2.3
62
44
  type: :development
63
- version_requirements: *id003
64
- - !ruby/object:Gem::Dependency
65
- name: activesupport
66
45
  prerelease: false
67
- requirement: &id004 !ruby/object:Gem::Requirement
46
+ version_requirements: *2152464940
47
+ - !ruby/object:Gem::Dependency
48
+ name: activesupport
49
+ requirement: &2152463940 !ruby/object:Gem::Requirement
68
50
  none: false
69
- requirements:
70
- - - ">="
71
- - !ruby/object:Gem::Version
72
- hash: 3
73
- segments:
74
- - 0
75
- version: "0"
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
76
55
  type: :runtime
77
- version_requirements: *id004
78
- - !ruby/object:Gem::Dependency
79
- name: cancan
80
56
  prerelease: false
81
- requirement: &id005 !ruby/object:Gem::Requirement
57
+ version_requirements: *2152463940
58
+ - !ruby/object:Gem::Dependency
59
+ name: cancan
60
+ requirement: &2152463060 !ruby/object:Gem::Requirement
82
61
  none: false
83
- requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- hash: 3
87
- segments:
88
- - 0
89
- version: "0"
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
90
66
  type: :runtime
91
- version_requirements: *id005
92
- - !ruby/object:Gem::Dependency
93
- name: role_model
94
67
  prerelease: false
95
- requirement: &id006 !ruby/object:Gem::Requirement
68
+ version_requirements: *2152463060
69
+ - !ruby/object:Gem::Dependency
70
+ name: role_model
71
+ requirement: &2152462240 !ruby/object:Gem::Requirement
96
72
  none: false
97
- requirements:
98
- - - ">="
99
- - !ruby/object:Gem::Version
100
- hash: 3
101
- segments:
102
- - 0
103
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
104
77
  type: :runtime
105
- version_requirements: *id006
106
- description: Wraps CanCan and RoleModel up to make role based authorisation really easy in Rails 3.x.
107
- email:
78
+ prerelease: false
79
+ version_requirements: *2152462240
80
+ description: Wraps CanCan and RoleModel up to make role based authorisation really
81
+ easy in Rails 3.x.
82
+ email:
108
83
  - james2mccarthy@gmail.com
109
84
  executables: []
110
-
111
85
  extensions: []
112
-
113
86
  extra_rdoc_files: []
114
-
115
- files:
87
+ files:
116
88
  - .gitignore
117
89
  - Gemfile
118
90
  - MIT-LICENSE
@@ -173,38 +145,29 @@ files:
173
145
  - test/user_model_test.rb
174
146
  homepage: https://github.com/james2m/canard
175
147
  licenses: []
176
-
177
148
  post_install_message:
178
149
  rdoc_options: []
179
-
180
- require_paths:
150
+ require_paths:
181
151
  - lib
182
- required_ruby_version: !ruby/object:Gem::Requirement
152
+ required_ruby_version: !ruby/object:Gem::Requirement
183
153
  none: false
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- hash: 3
188
- segments:
189
- - 0
190
- version: "0"
191
- required_rubygems_version: !ruby/object:Gem::Requirement
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
159
  none: false
193
- requirements:
194
- - - ">="
195
- - !ruby/object:Gem::Version
196
- hash: 3
197
- segments:
198
- - 0
199
- version: "0"
160
+ requirements:
161
+ - - ! '>='
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
200
164
  requirements: []
201
-
202
165
  rubyforge_project: canard
203
- rubygems_version: 1.8.21
166
+ rubygems_version: 1.8.12
204
167
  signing_key:
205
168
  specification_version: 3
206
169
  summary: Adds role based authorisation to Rails by combining RoleModel and CanCan.
207
- test_files:
170
+ test_files:
208
171
  - test/abilities/admins.rb
209
172
  - test/abilities_test.rb
210
173
  - test/ability_test.rb