cancan-permits 0.2.5 → 0.2.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +2 -0
  2. data/Changelog.txt +12 -0
  3. data/README.markdown +2 -11
  4. data/Rakefile +2 -2
  5. data/VERSION +1 -1
  6. data/cancan-permits.gemspec +38 -9
  7. data/lib/cancan-permits/{permit → license}/base_license.rb +0 -0
  8. data/lib/cancan-permits/main.rb +2 -1
  9. data/lib/cancan-permits/permit/base_permit.rb +6 -2
  10. data/lib/cancan-permits/permit/util.rb +7 -0
  11. data/lib/cancan-permits/permits/ability.rb +6 -2
  12. data/spec/active_record/owner_permits_spec.rb +1 -73
  13. data/spec/active_record/permits_spec.rb +1 -37
  14. data/spec/active_record/spec_helper.rb +2 -0
  15. data/spec/data_mapper/owner_permits_spec.rb +1 -74
  16. data/spec/data_mapper/permits_spec.rb +1 -36
  17. data/spec/data_mapper/spec_helper.rb +2 -0
  18. data/spec/fixtures/permits/any_permit.rb +9 -0
  19. data/spec/fixtures/permits/super_admin_permit.rb +12 -0
  20. data/spec/fixtures/permits/system_permit.rb +9 -0
  21. data/spec/generic/api/basic/config.rb +15 -0
  22. data/spec/generic/api/basic/xgroup.rb +55 -0
  23. data/spec/generic/api/basic/xgroup_orm.rb +20 -0
  24. data/spec/generic/api/owner/config.rb +25 -0
  25. data/spec/generic/api/owner/xgroup.rb +59 -0
  26. data/spec/generic/api/owner/xgroup_orm.rb +23 -0
  27. data/spec/generic/owner_permits_spec.rb +1 -27
  28. data/spec/generic/permits_spec.rb +1 -65
  29. data/spec/generic/spec_helper.rb +15 -1
  30. data/spec/mongo_mapper/owner_permits_spec.rb +1 -74
  31. data/spec/mongo_mapper/permits_spec.rb +1 -35
  32. data/spec/mongo_mapper/spec_helper.rb +5 -4
  33. data/spec/mongoid/owner_permits_spec.rb +1 -73
  34. data/spec/mongoid/permits_spec.rb +1 -65
  35. data/spec/mongoid/spec_helper.rb +4 -3
  36. data/spec/simply_stored/CouchDB.txt +104 -0
  37. data/spec/simply_stored/models/all_models.rb +17 -0
  38. data/spec/simply_stored/owner_permits_spec.rb +2 -0
  39. data/spec/simply_stored/permits_spec.rb +2 -0
  40. data/spec/simply_stored/spec_helper.rb +53 -0
  41. metadata +39 -10
@@ -1,38 +1,4 @@
1
1
  require 'mongo_mapper/spec_helper'
2
+ require 'generic/api/basic/xgroup_orm'
2
3
 
3
- Permits::Ability.orm = :mongo_mapper
4
4
 
5
- describe Permits::Ability do
6
- context "Guest user" do
7
- before :each do
8
- @guest = User.create(:name => "Kristian", :role => "guest")
9
-
10
- @ability = Permits::Ability.new(@guest)
11
-
12
- @comment = Comment.create(:user_id => @guest.id)
13
-
14
- @post = Post.create(:writer => @guest.id)
15
-
16
- @article = Article.create(:author => @guest.id)
17
- end
18
-
19
- it "should be able to :read Comment and Post but NOT Article" do
20
- @ability.can?(:read, Comment).should be_true
21
- @ability.can?(:read, @comment).should be_true
22
-
23
- @ability.can?(:read, Post).should be_true
24
- @ability.can?(:read, @post).should be_true
25
-
26
- @ability.can?(:read, Article).should be_false
27
- @ability.can?(:read, @article).should be_false
28
- end
29
-
30
- it "should be not able to :update only Comment" do
31
- @ability.can?(:update, Comment).should be_true
32
- @ability.can?(:update, @comment).should be_true
33
-
34
- @ability.can?(:update, Post).should be_false
35
- @ability.can?(:update, @post).should be_false
36
- end
37
- end
38
- end
@@ -1,6 +1,10 @@
1
1
  require 'spec_helper'
2
2
  require 'mongo_mapper'
3
3
 
4
+ Permits::Ability.orm = :mongo_mapper
5
+
6
+ MongoMapper.database = 'cancan-permits_mongo_mapper'
7
+
4
8
  require_all File.dirname(__FILE__) + '/models/all_models'
5
9
 
6
10
  RSpec.configure do |config|
@@ -27,10 +31,7 @@ class User
27
31
  self.role.to_sym == role.to_sym
28
32
  end
29
33
  end
30
-
31
-
32
- MongoMapper.database = 'cancan-permits_mongo_mapper'
33
-
34
+
34
35
  module Database
35
36
  def self.teardown
36
37
  # MongoMapper.database.collections.each {|collection| collection.drop }
@@ -1,75 +1,3 @@
1
1
  require 'mongoid/spec_helper'
2
+ require 'generic/api/owner/xgroup_orm'
2
3
 
3
- Permits::Ability.orm = :mongoid
4
-
5
- describe Permits::Ability do
6
- context "Editor user" do
7
- context "using default :user_id relation - foreign key to User.id" do
8
- before :each do
9
- @editor = User.create(:name => "Kristian", :role => "editor")
10
- @other_guy = User.create(:name => "Random dude", :role => "admin")
11
-
12
- @ability = Permits::Ability.new(@editor)
13
-
14
- @own_comment = Comment.create(:user_id => @editor.id)
15
- @other_comment = Comment.create(:user_id => @other_guy.id)
16
- # @post = Post.create(:writer => @editor.id)
17
- # @article = Article.create(:author => @editor.id)
18
- end
19
-
20
- it "should be able to :read Comment he owns" do
21
- @ability.should be_able_to(:read, Comment)
22
- @ability.should be_able_to(:read, @own_comment)
23
- end
24
-
25
- it "should be able to :update Comment he owns" do
26
- @ability.should be_able_to(:update, @own_comment)
27
- end
28
-
29
- it "should NOT be able to :update Comment he does NOT own" do
30
- @ability.should_not be_able_to(:update, @other_comment)
31
- end
32
-
33
- it "should be able to :delete Comment he owns" do
34
- @ability.should be_able_to(:delete, @own_comment)
35
- end
36
-
37
- it "should NOT be able to :update Comment he does NOT own" do
38
- @ability.should_not be_able_to(:delete, @other_comment)
39
- end
40
- end
41
-
42
- context "using custom :writer relation - foreign key to User.id" do
43
- before :each do
44
- @editor = User.create(:name => "Kristian", :role => "editor")
45
- @other_guy = User.create(:name => "Random dude", :role => "admin")
46
-
47
- @ability = Permits::Ability.new(@editor)
48
-
49
- @own_post = Post.create(:writer => @editor.id)
50
- @other_post = Post.create(:writer => @other_guy.id)
51
- end
52
-
53
- it "should be able to :read Post he owns" do
54
- @ability.should be_able_to(:read, Post)
55
- @ability.should be_able_to(:read, @own_post)
56
- end
57
-
58
- it "should be able to :update Post he owns" do
59
- @ability.should be_able_to(:update, @own_post)
60
- end
61
-
62
- it "should NOT be able to :update Post he does NOT own" do
63
- @ability.should_not be_able_to(:update, @other_post)
64
- end
65
-
66
- it "should be able to :delete Post he owns" do
67
- @ability.should be_able_to(:delete, @own_post)
68
- end
69
-
70
- it "should NOT be able to :update Post he does NOT own" do
71
- @ability.should_not be_able_to(:delete, @other_post)
72
- end
73
- end
74
- end
75
- end
@@ -1,66 +1,2 @@
1
1
  require 'mongoid/spec_helper'
2
-
3
- Permits::Ability.orm = :mongoid
4
-
5
- describe Permits::Ability do
6
- context "Guest user" do
7
- before :each do
8
- @guest = User.create(:name => "Kristian", :role => "guest")
9
-
10
- @ability = Permits::Ability.new(@guest, :strategy => :string)
11
-
12
- @comment = Comment.create(:user_id => @guest.id)
13
-
14
- @post = Post.create(:writer => @guest.id)
15
-
16
- @article = Article.create(:author => @guest.id)
17
- end
18
-
19
- it "should be able to :read Comment and Post but NOT Article" do
20
- @ability.can?(:read, Comment).should be_true
21
- @ability.can?(:read, @comment).should be_true
22
-
23
- @ability.can?(:read, Post).should be_true
24
- @ability.can?(:read, @post).should be_true
25
-
26
- @ability.can?(:read, Article).should be_false
27
- @ability.can?(:read, @article).should be_false
28
- end
29
-
30
- it "should be not able to :update only Comment" do
31
- @ability.can?(:update, Comment).should be_true
32
- @ability.can?(:update, @comment).should be_true
33
-
34
- @ability.can?(:update, Post).should be_false
35
- @ability.can?(:update, @post).should be_false
36
- end
37
- end
38
-
39
- context "Admin user" do
40
- before do
41
- @admin = User.create(:role => 'admin')
42
- @ability = Permits::Ability.new(@admin, :strategy => :string)
43
- end
44
-
45
- it "should be able to :read anything" do
46
- @ability.can?(:read, Comment).should be_true
47
- @ability.can?(:read, Post).should be_true
48
- end
49
-
50
- it "should be not able to :update everything" do
51
- @ability.can?(:update, Comment).should be_true
52
- @ability.can?(:update, Post).should be_true
53
- end
54
-
55
- it "should be not able to :create everything" do
56
- @ability.can?(:create, Comment).should be_true
57
- @ability.can?(:create, Post).should be_true
58
- end
59
-
60
- it "should be not able to :update everything" do
61
- @ability.can?(:destroy, Comment).should be_true
62
- @ability.can?(:destroy, Post).should be_true
63
- end
64
- end
65
-
66
- end
2
+ require 'generic/api/basic/xgroup_orm'
@@ -3,6 +3,10 @@ require 'mongoid'
3
3
 
4
4
  require_all File.dirname(__FILE__) + '/models/all_models'
5
5
 
6
+ Mongoid.configure.master = Mongo::Connection.new.db('cancan_permits')
7
+
8
+ Permits::Ability.orm = :mongoid
9
+
6
10
  RSpec.configure do |config|
7
11
  config.mock_with :mocha
8
12
  end
@@ -27,10 +31,7 @@ class User
27
31
  self.role.to_sym == role.to_sym
28
32
  end
29
33
  end
30
-
31
34
 
32
- Mongoid.configure.master = Mongo::Connection.new.db('cancan_permits')
33
-
34
35
  module Database
35
36
  def self.teardown
36
37
  Mongoid.database.collections.each do |coll|
@@ -0,0 +1,104 @@
1
+ INSTALL GUIDE
2
+
3
+ $ brew install couchdb
4
+
5
+ or download tar at http://www.apache.org/dyn/closer.cgi?path=/couchdb/1.0.1/apache-couchdb-1.0.1.tar.gz
6
+
7
+ Then follow instructions in the appropriate INSTALL file
8
+
9
+ user = User.new(:login => 'Bert', :age => 12, :accepted_terms_of_service => true, :last_login = Time.now)
10
+ user.save
11
+
12
+ User.find_by_age(12).login
13
+ # => 'Bert'
14
+
15
+ User.all
16
+ # => [user]
17
+
18
+ class Post
19
+ include SimplyStored::Couch
20
+
21
+ property :title
22
+ property :body
23
+
24
+ belongs_to :user
25
+ end
26
+
27
+ class User
28
+ has_many :posts
29
+ end
30
+
31
+ post = Post.create(:title => 'My first post', :body => 'SimplyStored is so nice!', :user => user)
32
+
33
+ user.posts
34
+ # => [post]
35
+
36
+ Post.find_all_by_title_and_user_id('My first post', user.id).first.body
37
+ # => 'SimplyStored is so nice!'
38
+
39
+ post.destroy
40
+
41
+ user.posts(:force_reload => true)
42
+ # => []
43
+
44
+ CouchDB - Associations
45
+
46
+ The supported associations are: belongs_to, has_one, has_many, and has_many :through
47
+
48
+ class Post
49
+ include SimplyStored::Couch
50
+
51
+ property :title
52
+ property :body
53
+
54
+ has_many :posts, :dependent => :destroy
55
+ has_many :users, :through => :posts
56
+ belongs_to :user
57
+ end
58
+
59
+ class Comment
60
+ include SimplyStored::Couch
61
+
62
+ property :body
63
+
64
+ belongs_to :post
65
+ belongs_to :user
66
+ end
67
+
68
+ post = Post.create(:title => 'Look ma!', :body => 'I can have comments')
69
+
70
+ mike = User.create(:login => 'mike')
71
+ mikes_comment = Comment.create(:user => mike, :post => post, :body => 'Wow, comments are nice')
72
+
73
+ john = User.create(:login => 'john')
74
+ johns_comment = Comment.create(:user => john, :post => post, :body => 'They are indeed')
75
+
76
+ post.comments
77
+ # => [mikes_comment, johns_comment]
78
+
79
+ post.comments(:order => :desc)
80
+ # => [johns_comment, mikes_comment]
81
+
82
+ post.comments(:limit => 1)
83
+ # => [mikes_comment]
84
+
85
+ post.comment_count
86
+ # => 2
87
+
88
+ post.users
89
+ # => [mike, john]
90
+
91
+ post.user_count
92
+ # => 2
93
+
94
+ CouchDB - Custom Associations
95
+
96
+ class Document
97
+ include SimplyStored::Couch
98
+
99
+ belongs_to :creator, :class_name => "User"
100
+ belongs_to :updater, :class_name => "User"
101
+ end
102
+
103
+ d = Document.new
104
+ d.creator = User.first
@@ -0,0 +1,17 @@
1
+ class Comment
2
+ include SimplyStored::Couch
3
+
4
+ property :user_id, :type => String
5
+ end
6
+
7
+ class Post
8
+ include SimplyStored::Couch
9
+
10
+ property :writer, :type => String
11
+ end
12
+
13
+ class Article
14
+ include SimplyStored::Couch
15
+
16
+ property :author, :type => String
17
+ end
@@ -0,0 +1,2 @@
1
+ require 'simply_stored/spec_helper'
2
+ require 'generic/api/owner/xgroup_orm'
@@ -0,0 +1,2 @@
1
+ require 'simply_stored/spec_helper'
2
+ require 'generic/api/basic/xgroup_orm'
@@ -0,0 +1,53 @@
1
+ require 'spec_helper'
2
+ require 'rails'
3
+ require 'simply_stored/couch'
4
+
5
+ CouchPotato::Config.database_name = "http://localhost:5984/cancan-permits"
6
+
7
+ Permits::Ability.orm = :simply_stored
8
+
9
+ require_all File.dirname(__FILE__) + '/models/all_models'
10
+
11
+ RSpec.configure do |config|
12
+ config.mock_with :mocha
13
+ end
14
+
15
+ module Permits::Roles
16
+ def self.available
17
+ User.roles
18
+ end
19
+ end
20
+
21
+ class Guest
22
+ class << self
23
+ attr_accessor :id_counter
24
+
25
+ def next_id
26
+ @id_counter += 1
27
+ end
28
+
29
+ def create
30
+ User.create(next_id, :guest, 'Guest')
31
+ end
32
+ end
33
+ end
34
+
35
+
36
+ class User
37
+ include SimplyStored::Couch
38
+
39
+ property :role, :type => String
40
+ property :name, :type => String
41
+
42
+ def self.roles
43
+ [:guest, :admin, :editor]
44
+ end
45
+
46
+ def has_role? role
47
+ self.role.to_sym == role.to_sym
48
+ end
49
+ end
50
+
51
+
52
+
53
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 5
9
- version: 0.2.5
8
+ - 7
9
+ version: 0.2.7
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-10-17 00:00:00 +02:00
17
+ date: 2010-10-23 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -57,9 +57,9 @@ dependencies:
57
57
  - !ruby/object:Gem::Version
58
58
  segments:
59
59
  - 0
60
- - 2
61
- - 14
62
- version: 0.2.14
60
+ - 3
61
+ - 0
62
+ version: 0.3.0
63
63
  type: :development
64
64
  version_requirements: *id003
65
65
  - !ruby/object:Gem::Dependency
@@ -102,9 +102,9 @@ dependencies:
102
102
  - !ruby/object:Gem::Version
103
103
  segments:
104
104
  - 0
105
- - 2
106
- - 10
107
- version: 0.2.10
105
+ - 3
106
+ - 0
107
+ version: 0.3.0
108
108
  type: :runtime
109
109
  version_requirements: *id006
110
110
  description: Role specific Permits for use with CanCan permission system
@@ -120,6 +120,7 @@ files:
120
120
  - .document
121
121
  - .gitignore
122
122
  - .rspec
123
+ - Changelog.txt
123
124
  - LICENSE
124
125
  - README.markdown
125
126
  - Rakefile
@@ -127,10 +128,11 @@ files:
127
128
  - cancan-permits.gemspec
128
129
  - development.sqlite3
129
130
  - lib/cancan-permits.rb
131
+ - lib/cancan-permits/license/base_license.rb
130
132
  - lib/cancan-permits/main.rb
131
133
  - lib/cancan-permits/namespaces.rb
132
- - lib/cancan-permits/permit/base_license.rb
133
134
  - lib/cancan-permits/permit/base_permit.rb
135
+ - lib/cancan-permits/permit/util.rb
134
136
  - lib/cancan-permits/permits/ability.rb
135
137
  - lib/cancan-permits/permits/configuration.rb
136
138
  - lib/cancan-permits/permits/roles.rb
@@ -156,9 +158,18 @@ files:
156
158
  - spec/data_mapper/permits_spec.rb
157
159
  - spec/data_mapper/spec_helper.rb
158
160
  - spec/fixtures/permits/admin_permit.rb
161
+ - spec/fixtures/permits/any_permit.rb
159
162
  - spec/fixtures/permits/editor_permit.rb
160
163
  - spec/fixtures/permits/guest_permit.rb
164
+ - spec/fixtures/permits/super_admin_permit.rb
165
+ - spec/fixtures/permits/system_permit.rb
161
166
  - spec/generators/permit_generator_spec.rb
167
+ - spec/generic/api/basic/config.rb
168
+ - spec/generic/api/basic/xgroup.rb
169
+ - spec/generic/api/basic/xgroup_orm.rb
170
+ - spec/generic/api/owner/config.rb
171
+ - spec/generic/api/owner/xgroup.rb
172
+ - spec/generic/api/owner/xgroup_orm.rb
162
173
  - spec/generic/models/all_models.rb
163
174
  - spec/generic/owner_permits_spec.rb
164
175
  - spec/generic/permits_spec.rb
@@ -171,6 +182,11 @@ files:
171
182
  - spec/mongoid/owner_permits_spec.rb
172
183
  - spec/mongoid/permits_spec.rb
173
184
  - spec/mongoid/spec_helper.rb
185
+ - spec/simply_stored/CouchDB.txt
186
+ - spec/simply_stored/models/all_models.rb
187
+ - spec/simply_stored/owner_permits_spec.rb
188
+ - spec/simply_stored/permits_spec.rb
189
+ - spec/simply_stored/spec_helper.rb
174
190
  - spec/spec_helper.rb
175
191
  has_rdoc: true
176
192
  homepage: http://github.com/kristianmandrup/cancan-permits
@@ -218,9 +234,18 @@ test_files:
218
234
  - spec/data_mapper/permits_spec.rb
219
235
  - spec/data_mapper/spec_helper.rb
220
236
  - spec/fixtures/permits/admin_permit.rb
237
+ - spec/fixtures/permits/any_permit.rb
221
238
  - spec/fixtures/permits/editor_permit.rb
222
239
  - spec/fixtures/permits/guest_permit.rb
240
+ - spec/fixtures/permits/super_admin_permit.rb
241
+ - spec/fixtures/permits/system_permit.rb
223
242
  - spec/generators/permit_generator_spec.rb
243
+ - spec/generic/api/basic/config.rb
244
+ - spec/generic/api/basic/xgroup.rb
245
+ - spec/generic/api/basic/xgroup_orm.rb
246
+ - spec/generic/api/owner/config.rb
247
+ - spec/generic/api/owner/xgroup.rb
248
+ - spec/generic/api/owner/xgroup_orm.rb
224
249
  - spec/generic/models/all_models.rb
225
250
  - spec/generic/owner_permits_spec.rb
226
251
  - spec/generic/permits_spec.rb
@@ -233,4 +258,8 @@ test_files:
233
258
  - spec/mongoid/owner_permits_spec.rb
234
259
  - spec/mongoid/permits_spec.rb
235
260
  - spec/mongoid/spec_helper.rb
261
+ - spec/simply_stored/models/all_models.rb
262
+ - spec/simply_stored/owner_permits_spec.rb
263
+ - spec/simply_stored/permits_spec.rb
264
+ - spec/simply_stored/spec_helper.rb
236
265
  - spec/spec_helper.rb