rolify 3.1.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.travis.yml +44 -11
  4. data/CHANGELOG.rdoc +70 -0
  5. data/CONTRIBUTORS +6 -0
  6. data/Gemfile +21 -2
  7. data/README.md +130 -68
  8. data/Rakefile +29 -4
  9. data/UPGRADE.rdoc +22 -0
  10. data/circle.yml +13 -0
  11. data/gemfiles/Gemfile.rails-3.2 +27 -0
  12. data/gemfiles/Gemfile.rails-4.0 +33 -0
  13. data/gemfiles/Gemfile.rails-4.1 +37 -0
  14. data/lib/generators/active_record/rolify_generator.rb +54 -0
  15. data/lib/generators/active_record/templates/README +8 -0
  16. data/lib/generators/active_record/templates/migration.rb +19 -0
  17. data/lib/generators/mongoid/rolify_generator.rb +55 -0
  18. data/lib/generators/mongoid/templates/README-mongoid +4 -0
  19. data/lib/generators/rolify/rolify_generator.rb +35 -0
  20. data/lib/generators/rolify/{role/templates/README-mongoid → templates/README} +1 -5
  21. data/lib/generators/rolify/templates/initializer.rb +7 -0
  22. data/lib/generators/rolify/templates/role-active_record.rb +11 -0
  23. data/lib/generators/rolify/{role/templates → templates}/role-mongoid.rb +9 -9
  24. data/lib/generators/rolify/user_generator.rb +39 -0
  25. data/lib/rolify/adapters/active_record/resource_adapter.rb +36 -6
  26. data/lib/rolify/adapters/active_record/role_adapter.rb +25 -13
  27. data/lib/rolify/adapters/active_record/scopes.rb +27 -0
  28. data/lib/rolify/adapters/base.rb +9 -0
  29. data/lib/rolify/adapters/mongoid/resource_adapter.rb +27 -6
  30. data/lib/rolify/adapters/mongoid/role_adapter.rb +35 -11
  31. data/lib/rolify/adapters/mongoid/scopes.rb +27 -0
  32. data/lib/rolify/configure.rb +36 -5
  33. data/lib/rolify/finders.rb +40 -0
  34. data/lib/rolify/matchers.rb +31 -0
  35. data/lib/rolify/railtie.rb +1 -1
  36. data/lib/rolify/resource.rb +19 -10
  37. data/lib/rolify/role.rb +33 -13
  38. data/lib/rolify/version.rb +1 -1
  39. data/lib/rolify.rb +46 -20
  40. data/rolify.gemspec +18 -24
  41. data/spec/README.rdoc +24 -0
  42. data/spec/generators/rolify/rolify_activerecord_generator_spec.rb +165 -0
  43. data/spec/generators/rolify/rolify_mongoid_generator_spec.rb +113 -0
  44. data/spec/generators_helper.rb +27 -0
  45. data/spec/rolify/config_spec.rb +20 -21
  46. data/spec/rolify/custom_spec.rb +11 -6
  47. data/spec/rolify/matchers_spec.rb +24 -0
  48. data/spec/rolify/namespace_spec.rb +24 -0
  49. data/spec/rolify/resource_spec.rb +135 -37
  50. data/spec/rolify/resourcifed_and_rolifed_spec.rb +24 -0
  51. data/spec/rolify/role_spec.rb +8 -9
  52. data/spec/rolify/shared_contexts.rb +22 -3
  53. data/spec/rolify/shared_examples/shared_examples_for_add_role.rb +10 -17
  54. data/spec/rolify/shared_examples/shared_examples_for_callbacks.rb +65 -0
  55. data/spec/rolify/shared_examples/shared_examples_for_dynamic.rb +64 -27
  56. data/spec/rolify/shared_examples/shared_examples_for_finders.rb +81 -0
  57. data/spec/rolify/shared_examples/shared_examples_for_has_all_roles.rb +29 -29
  58. data/spec/rolify/shared_examples/shared_examples_for_has_any_role.rb +35 -35
  59. data/spec/rolify/shared_examples/shared_examples_for_has_role.rb +38 -38
  60. data/spec/rolify/shared_examples/shared_examples_for_only_has_role.rb +174 -0
  61. data/spec/rolify/shared_examples/shared_examples_for_remove_role.rb +28 -59
  62. data/spec/rolify/shared_examples/shared_examples_for_roles.rb +58 -32
  63. data/spec/rolify/shared_examples/shared_examples_for_scopes.rb +38 -0
  64. data/spec/spec_helper.rb +39 -3
  65. data/spec/support/adapters/active_record.rb +58 -7
  66. data/spec/support/adapters/mongoid.rb +110 -17
  67. data/spec/support/adapters/mongoid.yml +6 -0
  68. data/spec/support/data.rb +18 -15
  69. data/spec/support/schema.rb +31 -16
  70. data/spec/support/stream_helpers.rb +18 -0
  71. metadata +88 -84
  72. data/lib/generators/rolify/role/role_generator.rb +0 -41
  73. data/lib/generators/rolify/role/templates/README +0 -11
  74. data/lib/generators/rolify/role/templates/README-active_record +0 -21
  75. data/lib/generators/rolify/role/templates/initializer.rb +0 -7
  76. data/lib/generators/rolify/role/templates/migration.rb +0 -19
  77. data/lib/generators/rolify/role/templates/role-active_record.rb +0 -4
  78. data/spec/generators/rolify/role/role_generator_spec.rb +0 -197
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b9f204d757588d80887b2193a4eb9ea1b0fd471
4
+ data.tar.gz: 97030122590f294b06b595af6edc1dec44d13176
5
+ SHA512:
6
+ metadata.gz: 75dc73295700924357b77c4359f43939c3e44d0857015f7f30dc26e4f06c99e1667f7767977e1a9bb332028ee177cab6ba860538a4d1dd640da5175246989a68
7
+ data.tar.gz: 01e0a0874a8ded544155535b4b9cff68f643b20fce6e71e21615ef7c4a5f7ca47b68e4b6ea9de34ec13af5e51bce6fb781f52351483ede4e05e152f21a662c5e
data/.gitignore CHANGED
@@ -1,7 +1,10 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ gemfiles/*.lock
4
5
  pkg/*
5
6
  tmp/*
6
- logs/*
7
+ coverage/*
8
+ log*/*
7
9
  .rbx/*
10
+ .rspec
data/.travis.yml CHANGED
@@ -1,16 +1,49 @@
1
- rvm:
2
- - 1.8.7
3
- - 1.9.3
4
- - ruby-head
5
- - rbx
6
- - jruby
7
- - ree
1
+ language: ruby
8
2
 
9
- env:
10
- - ADAPTER=active_record
11
- - ADAPTER=mongoid
3
+ rvm:
4
+ - 2.1.2
12
5
 
13
6
  before_install:
14
7
  - gem update --system
8
+ - gem install bundler
15
9
  - gem --version
16
- - ruby -v
10
+
11
+ script: bundle exec rake
12
+
13
+ env:
14
+ - ADAPTER=active_record
15
+ - ADAPTER=mongoid
16
+
17
+ services: mongodb
18
+
19
+ addons:
20
+ code_climate:
21
+ repo_token: 6bd8d374b120a5449b9a4b7dfda40cc0609dbade48a1b6655f04a9bc8de3a3ee
22
+ # language: ruby
23
+ #
24
+ # rvm:
25
+ # - 1.9.3
26
+ # - 2.0.0
27
+ # - 2.1.1
28
+ # - 2.1.2
29
+ # - rbx-2
30
+ # - jruby-19mode
31
+ #
32
+ # script: bundle exec rake
33
+ #
34
+ # gemfile:
35
+ # - gemfiles/Gemfile.rails-3.2
36
+ # - gemfiles/Gemfile.rails-4.0
37
+ # - gemfiles/Gemfile.rails-4.1
38
+ #
39
+ # env:
40
+ # - ADAPTER=active_record
41
+ # - ADAPTER=mongoid
42
+ #
43
+ # services: mongodb
44
+ #
45
+ # matrix:
46
+ # fast_finish: true
47
+ # exclude:
48
+ # - rvm: 1.9.3
49
+ # gemfile: gemfiles/Gemfile.rails-4.1
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,73 @@
1
+ = 4.0.0 (Feb 12, 2015)
2
+ * Increasing version number to 4.0.0 for semantic versioning since `has_role` was removed in 3.5.0
3
+ * Fix spec to pass.
4
+ * Fix dynamic shortcuts being set before migration.
5
+
6
+ = 3.5.2 (Jan 14, 2015)
7
+ * Fixed regression in RolifyGenerator
8
+ * Updated dependencies
9
+
10
+ = 3.5.0 (Jan 08, 2015)
11
+ * Removed `has_role` method alias for `add_role`
12
+ * Fixed regression in caching system
13
+ * Fix deprecation warning about timestamp on specs
14
+ * Copy Kernel#capture helper from Rails
15
+ * Add validation on Role.resource_type
16
+
17
+ = 3.4.1 (Sep 08, 2014)
18
+ * Fixed issue with migrations being generated without a file extension.
19
+ * Updated spec tests to work with Travis CI on Ruby up to 2.1.2 and Rails 4.1.x
20
+ * Made it possible for inheritance of resources.
21
+ * Fixed small bugs throughout project.
22
+
23
+ = 3.4 (Jan 28, 2014)
24
+ * fixed an initializer bug preventing the rails app to boot
25
+ * enhanced documentation regarding <tt>with_role</tt> method (thanks to @vicomte)
26
+ * added <tt>select(:id)</tt> in SQL subquery used by <tt>in</tt> method in ActiveRecord adapter (thanks to @ryanaip and @badaboda)
27
+ * improved speed when removing roles using <tt>LIMIT(1)</tt> instead of <tt>COUNT</tt> (thanks to @yankovski)
28
+ * fixed travis builds for rubinius and mongoid
29
+ * fixed sanity check running before <tt>Rolify.config</tt> to ensure roles table exists
30
+ * fixed <tt>has_any_role?</tt> to work with unsaved records (thanks to @mhw)
31
+ * fixed specs for Mongoid
32
+
33
+ = 3.3 (Jan 26, 2014)
34
+ * <b>DEPRECATION NOTICE:</b>Rails 3.1 support dropped: if you use Rails 3.1, please stick to rolify 3.2
35
+ * code cleanup in finders methods
36
+ * generators rewritten entirely. now using ActiveRecord/Mongoid model generator to create Role model
37
+ * added rspec matchers for detailed spec error messages (thanks to @delwyn)
38
+ * clean up specs (thanks to @delwyn), removed subject and let declarations in before(:all) block
39
+ * roles query needs 1 DB hit instead of 1 up to 3 (thanks to @terraplane)
40
+ * remove nil entries from ResourceAdapter#resources_find when using Mongoid adapter (thanks to @daviscabral)
41
+ * fixed a bug regarding redundant index for Mongoid Role model (thanks to @rschultheis)
42
+ * added support for rolify and resourcify methods on the same model class (specs by @amer)
43
+ * added support for namespaced models (thanks to @intrica)
44
+ * fixed compatibility issue with squeel when using symbols as role parameters (hint by @f3ndot)
45
+ * now raises a warning in the initializer if migration has not been run
46
+ * add support for primary key different than 'id' for resource Model (thanks to @rafaeldl)
47
+ * Rails 4 (thanks to @adammathys) and ruby 2.0 compliant
48
+ * configured travis-ci to run the specs on Rails 3.2/4.0 and Rubies 1.9.3/2.0/rbx/jruby
49
+ * added code climate to check for code smell
50
+
51
+ = 3.2 (Aug 7, 2012)
52
+ * <b>DEPRECATION NOTICE:</b> Ruby 1.8 support dropped ! Mongoid 3.0 only supports MRI 1.9.3, and HEAD, and JRuby 1.6.0+ in 1.9 mode
53
+ * removed <tt>dynamic_shortcuts</tt> arguments from the generator
54
+ * to use dynamic shortcuts feature when you're using ActiveRecord, you have to enable it _after_ running rake db:migrate as it relies on the roles table
55
+ * support for Mongoid 3.x (thanks to @Leonas)
56
+ * new class methods on the User class to find users depending on roles they have
57
+ * added scopes to Role class to be able to fetch global, class scoped and instance scoped roles for a specific user
58
+ * deletions of n-n relation are unreliable with Mongoid. Removing ids instead (thanks to @nfo)
59
+ * <tt>has_role?</tt> method now supports new instance (i.e. record not saved in the database yet) (thanks to @demental)
60
+ * added association callbacks <tt>(before|after)_add</tt>, <tt>(before|after)_remove</tt> on <tt>rolify</tt> method (thanks to @shekibobo)
61
+ * added ability to pass an array of roles to <tt>Resource.with_role()</tt>, aliased by <tt>Resource.with_roles()</tt> (thanks to @lukes)
62
+ * added option to have roles be destroyed by default if parent resource is destroyed (thanks to @treydock)
63
+ * added new method <tt>only_has_role?</tt> to check if user has only a specific role (thanks to @jalcine)
64
+ * better edge cases covering in the specs
65
+ * fixed a bug regarding the loading order of the railtie when using Mongoid ORM and other gems using initializer files (thanks to @stigi)
66
+ * fixed double quote syntax when using MySQL
67
+ * fixed a nasty bug regarding class level queries (thanks to @kamrulhassan)
68
+ * fixed uninitialized constant error in scopify method
69
+ * documentation improvement
70
+
1
71
  = 3.1 (Apr 6, 2012)
2
72
  * Mongoid adapter optimization
3
73
  * adapter code refactoring
data/CONTRIBUTORS ADDED
@@ -0,0 +1,6 @@
1
+ Florent Monbillard (@EppO) - Original Author
2
+ Wellington Cordeiro (@wldcordeiro)
3
+ Joel Azemar (@joel)
4
+ Alex Klim (@AlexKlim)
5
+ Mauro George (@MauroGeorge)
6
+ Cheri Allen(@cherimarie)
data/Gemfile CHANGED
@@ -1,4 +1,23 @@
1
- source "http://rubygems.org"
1
+ source "https://rubygems.org"
2
+
3
+ group :test do
4
+ case ENV["ADAPTER"]
5
+ when nil, "active_record"
6
+ gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.rc", :platform => "jruby"
7
+ gem "sqlite3", :platform => "ruby"
8
+ gem "activerecord", ">= 3.2.0", :require => "active_record"
9
+ when "mongoid"
10
+ gem "mongoid", ">= 3.1"
11
+ gem "bson_ext", :platform => "ruby"
12
+ else
13
+ raise "Unknown model adapter: #{ENV["ADAPTER"]}"
14
+ end
15
+
16
+ gem 'coveralls', :require => false
17
+ gem 'its'
18
+ gem 'byebug'
19
+ gem 'pry-byebug'
20
+ gem 'codeclimate-test-reporter', :require => nil
21
+ end
2
22
 
3
- # Specify your gem's dependencies in rolify.gemspec
4
23
  gemspec
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
- # rolify [![build status](https://secure.travis-ci.org/EppO/rolify.png?branch=master)](http://travis-ci.org/EppO/rolify) [![dependency status](https://gemnasium.com/EppO/rolify.png)](https://gemnasium.com/EppO/rolify)
1
+ # rolify [![Gem Version](https://badge.fury.io/rb/rolify.svg)](http://badge.fury.io/rb/rolify) [![build status](https://secure.travis-ci.org/RolifyCommunity/rolify.png)](http://travis-ci.org/RolifyCommunity/rolify) [![Dependency Status](https://gemnasium.com/RolifyCommunity/rolify.svg)](https://gemnasium.com/RolifyCommunity/rolify) [![Code Climate](https://codeclimate.com/github/RolifyCommunity/rolify.png)](https://codeclimate.com/github/RolifyCommunity/rolify) [![Coverage Status](https://img.shields.io/coveralls/RolifyCommunity/rolify.svg)](https://coveralls.io/r/RolifyCommunity/rolify?branch=master)
2
+
2
3
 
3
4
  Very simple Roles library without any authorization enforcement supporting scope on resource object.
4
5
 
@@ -9,26 +10,23 @@ user.has_role?(:moderator, Forum.first)
9
10
  => false # if user is moderator of another Forum
10
11
  ```
11
12
 
12
- This library was intended to be used with [CanCan](https://github.com/ryanb/cancan) and [devise](https://github.com/plataformatec/devise) but should be generic enough to be used by any other authentication/authorization solutions.
13
+ This library can be easily integrated with any authentication gem ([devise](https://github.com/plataformatec/devise), [Authlogic](https://github.com/binarylogic/authlogic), [Clearance](https://github.com/thoughtbot/clearance)) and authorization gem<span style="color: red"><strong>*</strong></span> ([CanCanCan](https://github.com/CanCanCommunity/cancancan), [authority](https://github.com/nathanl/authority))
14
+
15
+ <span style="color: red"><strong>*</strong></span>: authorization gem that doesn't provide a role class
13
16
 
14
17
  ## Requirements
15
18
 
16
- * >= Rails 3.1
17
- * ActiveRecord ORM <b>or</b> Mongoid
18
- * supports ruby 1.8/1.9, REE, JRuby and Rubinius
19
+ * Rails >= 3.2
20
+ * ActiveRecord >= 3.2 <b>or</b> Mongoid >= 3.1
21
+ * supports ruby 2.0/1.9.3, JRuby 1.6.0+ (in 1.9 mode) and Rubinius 2.0.0dev (in 1.9 mode)
22
+ * support of ruby 1.8 has been dropped due to Mongoid >=3.0 that only supports 1.9 new hash syntax
19
23
 
20
24
  ## Installation
21
25
 
22
26
  In <b>Rails 3</b>, add this to your Gemfile and run the +bundle+ command.
23
27
 
24
28
  ```ruby
25
- gem "rolify"
26
- ```
27
-
28
- Alternatively, you can install it as a plugin.
29
-
30
- ```
31
- rails plugin install git://github.com/EppO/rolify.git
29
+ gem "rolify"
32
30
  ```
33
31
 
34
32
  ## Getting Started
@@ -38,129 +36,193 @@ Alternatively, you can install it as a plugin.
38
36
  First, create your Role model and migration file using this generator:
39
37
 
40
38
  ```
41
- rails g rolify:role Role User
39
+ rails g rolify Role User
40
+ ```
41
+
42
+ **NB** for versions of Rolify prior to 3.3, use:
43
+
44
+ ```
45
+ rails g rolify:role Role User
42
46
  ```
43
47
 
44
48
  Role and User classes are the default. You can specify any Role class name you want. This is completly a new file so any name can do the job.
45
49
  For the User class name, you would probably use the one provided by your authentication solution. rolify just adds some class methods in an existing User class.
46
50
 
47
- If you want to use Mongoid instead of ActiveRecord, follow these [instructions](https://github.com/EppO/rolify/wiki/Configuration), and skip to step #3
51
+ If you want to use Mongoid instead of ActiveRecord, just add `--orm=mongoid` argument, and skip to step #3
48
52
 
49
53
  ### 2. Run the migration (only required when using ActiveRecord)
50
54
 
51
55
  Let's migrate !
52
56
 
53
57
  ```
54
- rake db:migrate
58
+ rake db:migrate
55
59
  ```
56
60
 
57
- ### 3. Add a role to a user
61
+ ### 3.1 Configure your user model
62
+
63
+ This gem adds the `rolify` method to your User class. You can also specify optional callbacks on the User class for when roles are added or removed:
64
+
65
+ ```ruby
66
+ class User < ActiveRecord::Base
67
+ rolify :before_add => :before_add_method
68
+
69
+ def before_add_method(role)
70
+ # do something before it gets added
71
+ end
72
+ end
73
+ ```
74
+
75
+ The `rolify` method accepts the following callback options:
76
+
77
+ - `before_add`
78
+ - `after_add`
79
+ - `before_remove`
80
+ - `after_remove`
81
+
82
+ Mongoid callbacks are also supported and works the same way.
83
+
84
+ ### 3.2 Configure your resource models
85
+
86
+ In the resource models you want to apply roles on, just add ``resourcify`` method.
87
+ For example, on this ActiveRecord class:
88
+
89
+ ```ruby
90
+ class Forum < ActiveRecord::Base
91
+ resourcify
92
+ end
93
+ ```
94
+
95
+ ### 4. Add a role to a user
58
96
 
59
97
  To define a global role:
60
98
 
61
99
  ```ruby
62
- user = User.find(1)
63
- user.add_role :admin
100
+ user = User.find(1)
101
+ user.add_role :admin
64
102
  ```
65
103
 
66
104
  To define a role scoped to a resource instance
67
105
 
68
106
  ```ruby
69
- user = User.find(2)
70
- user.add_role :moderator, Forum.first
107
+ user = User.find(2)
108
+ user.add_role :moderator, Forum.first
71
109
  ```
72
110
 
73
111
  To define a role scoped to a resource class
74
112
 
75
113
  ```ruby
76
- user = User.find(3)
77
- user.add_role :moderator, Forum
114
+ user = User.find(3)
115
+ user.add_role :moderator, Forum
78
116
  ```
79
117
 
80
118
  That's it !
81
119
 
82
- ### 4. Check roles
120
+ ### 5. Role queries
83
121
 
84
122
  To check if a user has a global role:
85
123
 
86
124
  ```ruby
87
- user = User.find(1)
88
- user.add_role :admin # sets a global role
89
- user.has_role? :admin
90
- => true
125
+ user = User.find(1)
126
+ user.add_role :admin # sets a global role
127
+ user.has_role? :admin
128
+ => true
91
129
  ```
92
130
 
93
131
  To check if a user has a role scoped to a resource instance:
94
132
 
95
133
  ```ruby
96
- user = User.find(2)
97
- user.add_role :moderator, Forum.first # sets a role scoped to a resource instance
98
- user.has_role? :moderator, Forum.first
99
- => true
100
- user.has_role? :moderator, Forum.last
101
- => false
134
+ user = User.find(2)
135
+ user.add_role :moderator, Forum.first # sets a role scoped to a resource instance
136
+ user.has_role? :moderator, Forum.first
137
+ => true
138
+ user.has_role? :moderator, Forum.last
139
+ => false
102
140
  ```
103
141
 
104
142
  To check if a user has a role scoped to a resource class:
105
143
 
106
144
  ```ruby
107
- user = User.find(3)
108
- user.add_role :moderator, Forum # sets a role scoped to a resource class
109
- user.has_role? :moderator, Forum
110
- => true
111
- user.has_role? :moderator, Forum.first
112
- => true
113
- user.has_role? :moderator, Forum.last
114
- => true
145
+ user = User.find(3)
146
+ user.add_role :moderator, Forum # sets a role scoped to a resource class
147
+ user.has_role? :moderator, Forum
148
+ => true
149
+ user.has_role? :moderator, Forum.first
150
+ => true
151
+ user.has_role? :moderator, Forum.last
152
+ => true
115
153
  ```
116
154
 
117
155
  A global role overrides resource role request:
118
156
 
119
157
  ```ruby
120
- user = User.find(4)
121
- user.add_role :moderator # sets a global role
122
- user.has_role? :moderator, Forum.first
123
- => true
124
- user.has_role? :moderator, Forum.last
125
- => true
158
+ user = User.find(4)
159
+ user.add_role :moderator # sets a global role
160
+ user.has_role? :moderator, Forum.first
161
+ => true
162
+ user.has_role? :moderator, Forum.last
163
+ => true
126
164
  ```
127
165
 
128
- ### 5. Resource roles querying
166
+ ### 6. Resource roles querying
129
167
 
130
168
  Starting from rolify 3.0, you can search roles on instance level or class level resources.
131
169
 
132
170
  #### Instance level
133
171
 
134
172
  ```ruby
135
- forum = Forum.first
136
- forum.roles
137
- # => [ list of roles that are only binded to forum instance ]
138
- forum.applied_roles
139
- # => [ list of roles binded to forum instance and to the Forum class ]
173
+ forum = Forum.first
174
+ forum.roles
175
+ # => [ list of roles that are only binded to forum instance ]
176
+ forum.applied_roles
177
+ # => [ list of roles binded to forum instance and to the Forum class ]
140
178
  ```
141
179
 
142
180
  #### Class level
143
181
 
144
182
  ```ruby
145
- Forum.with_role(:admin)
146
- # => [ list of Forum instances that has role "admin" binded to it ]
147
- Forum.with_role(:admin, current_user)
148
- # => [ list of Forum instances that has role "admin" binded to it and belongs to current_user roles ]
149
-
150
- Forum.find_roles
151
- # => [ list of roles that binded to any Forum instance or to the Forum class ]
152
- Forum.find_roles(:admin)
153
- # => [ list of roles that binded to any Forum instance or to the Forum class with "admin" as a role name ]
154
- Forum.find_roles(:admin, current_user)
155
- # => [ list of roles that binded to any Forum instance or to the Forum class with "admin" as a role name and belongs to current_user roles ]
183
+ Forum.with_role(:admin)
184
+ # => [ list of Forum instances that has role "admin" binded to it ]
185
+ Forum.with_role(:admin, current_user)
186
+ # => [ list of Forum instances that has role "admin" binded to it and belongs to current_user roles ]
187
+ Forum.with_roles([:admin, :user], current_user)
188
+ # => [ list of Forum instances that has role "admin" or "user" binded to it and belongs to current_user roles ]
189
+
190
+ User.with_any_role(:user, :admin)
191
+ # => [ list of User instances that has role "admin" or "user" binded to it ]
192
+ User.with_role(:site_admin, current_site)
193
+ # => [ list of User instances that have a scoped role of "site_admin" to a site instance ]
194
+ User.with_role(:site_admin, :any)
195
+ # => [ list of User instances that have a scoped role of "site_admin" for any site instances ]
196
+
197
+ Forum.find_roles
198
+ # => [ list of roles that binded to any Forum instance or to the Forum class ]
199
+ Forum.find_roles(:admin)
200
+ # => [ list of roles that binded to any Forum instance or to the Forum class with "admin" as a role name ]
201
+ Forum.find_roles(:admin, current_user)
202
+ # => [ list of roles that binded to any Forum instance or to the Forum class with "admin" as a role name and belongs to current_user roles ]
156
203
  ```
157
204
 
158
205
  ## Resources
159
206
 
160
- * [Wiki](https://github.com/EppO/rolify/wiki)
161
- * [Usage](https://github.com/EppO/rolify/wiki/Usage): all the available commands
162
- * [Tutorial](https://github.com/EppO/rolify/wiki/Tutorial): how to use [rolify](http://eppo.github.com/rolify) with [Devise](https://github.com/plataformatec/devise) and [CanCan](https://github.com/ryanb/cancan).
207
+ * [Wiki](https://github.com/RolifyCommunity/rolify/wiki)
208
+ * [Usage](https://github.com/RolifyCommunity/rolify/wiki/Usage): all the available commands
209
+ * [Tutorials](https://github.com/RolifyCommunity/rolify/wiki#wiki-tutorials):
210
+ * [How-To use rolify with Devise and CanCan](https://github.com/RolifyCommunity/rolify/wiki/Tutorial)
211
+ * [Using rolify with Devise and Authority](https://github.com/RolifyCommunity/rolify/wiki/Using-rolify-with-Devise-and-Authority)
212
+ * [Step-by-step tutorial](http://railsapps.github.com/tutorial-rails-bootstrap-devise-cancan.html) provided by [RailsApps](http://railsapps.github.com/)
213
+
214
+ ## Upgrade from previous versions
215
+
216
+ Please read the [upgrade instructions](UPGRADE.rdoc).
217
+
218
+ ## Known issues
219
+
220
+ * If you are using Mongoid and/or less-rails gem, please read [this](https://github.com/RolifyCommunity/rolify/wiki/FAQ#when-i-start-rails-using-server-console-whatever-i-get-this-error)
221
+ * Moped library (ruby driver for Mongodb used by Mongoid) doesn't support rubinius 2.2 yet (see https://github.com/mongoid/moped/issues/231)
222
+ * If you use Rails 4 and Mongoid, use Mongoid ~> 4. rolify is fully tested with Rails 4 and Mongoid 4.
163
223
 
164
224
  ## Questions or Problems?
165
225
 
166
- If you have any issue or feature request with/for rolify, please add an [issue on GitHub](https://github.com/EppO/rolify/issues) or fork the project and send a pull request.
226
+ If you have any issue or feature request with/for rolify, please create an new [issue on GitHub](https://github.com/RolifyCommunity/rolify/issues) **specifying the ruby runtime, rails and rolify versions you're using and the gems listed in your Gemfile**, or fork the project and send a pull request.
227
+
228
+ To get the specs running you should call `bundle` and then `rake`. See the spec/README for more information.
data/Rakefile CHANGED
@@ -1,9 +1,34 @@
1
1
  require 'bundler'
2
+ require 'rspec/core/rake_task'
3
+ require 'coveralls/rake/task'
4
+
2
5
  Bundler::GemHelper.install_tasks
3
6
 
4
- task :default => :spec
7
+ Coveralls::RakeTask.new
8
+
9
+ RSpec::Core::RakeTask.new(:generators) do |task|
10
+ task.pattern = 'spec/generators/**/*_spec.rb'
11
+ end
12
+
13
+ RSpec::Core::RakeTask.new(:rolify) do |task|
14
+ task.pattern = 'spec/rolify/**/*_spec.rb'
15
+ end
16
+
17
+ task :default => [ :spec, 'coveralls:push' ]
18
+
19
+ desc 'Run all specs'
20
+ task 'spec' do
21
+ Rake::Task['generators'].invoke
22
+ return_code1 = $?.exitstatus
23
+ Rake::Task['rolify'].invoke
24
+ return_code2 = $?.exitstatus
25
+ fail if return_code1 != 0 || return_code2 != 0
26
+ end
5
27
 
6
- desc "Run all specs"
7
- task "spec" do
8
- exec "bundle exec rspec spec"
28
+ desc 'Run specs for all adapters'
29
+ task :spec_all do
30
+ %w[active_record mongoid].each do |model_adapter|
31
+ puts "ADAPTER = #{model_adapter}"
32
+ system "ADAPTER=#{model_adapter} rake"
33
+ end
9
34
  end
data/UPGRADE.rdoc CHANGED
@@ -20,3 +20,25 @@ If you use <i>dynamic methods</i> (<tt>user.is_admin?</tt> like methods), you sh
20
20
  c.use_dynamic_shortcuts
21
21
  end
22
22
  The old fashion way still works though, but won't work anymore if the setter method name is changed in a possible future. You've been warned :-)
23
+
24
+ == From a rolify installation 3.x
25
+
26
+ === Dependencies:
27
+
28
+ Starting from 3.3 release, rolify supports Rails 3.2 and newer.
29
+
30
+ Mongoid callbacks are supported if Mongoid 3.1 and newer is installed.
31
+
32
+ === Rails Generators
33
+
34
+ Role model template when using Mongoid has been changed, you should re-run the generator.
35
+
36
+ Rails generator has been renamed to: <tt>rails g rolify</tt> and arguments have been changed:
37
+ * Role class name is now mandatory, User class name remains optional and its default is still <tt>User</tt>
38
+ * ORM optional argument is now <tt>-o</tt> or <tt>--orm=</tt>
39
+ For instance, here is a new rolify generator command example: <tt>rails g rolify Role</tt>
40
+ You can use <tt>rails g rolify --help</tt> to see all available options.
41
+
42
+ === Testing
43
+
44
+ Starting from rolify 3.3, to run the specs you should run: <tt>rake spec</tt> or simply <tt>rake</tt>.
data/circle.yml ADDED
@@ -0,0 +1,13 @@
1
+ machine:
2
+ ruby:
3
+ version: 2.1.3
4
+ environment:
5
+ CODECLIMATE_REPO_TOKEN: 6bd8d374b120a5449b9a4b7dfda40cc0609dbade48a1b6655f04a9bc8de3a3ee
6
+ ADAPTER: active_record
7
+ ADAPTER: mongoid
8
+ dependencies:
9
+ pre:
10
+ - gem install bundler
11
+ test:
12
+ override:
13
+ - bundle exec rake:spec_all
@@ -0,0 +1,27 @@
1
+ source 'https://rubygems.org'
2
+
3
+ platforms :rbx do
4
+ gem 'psych'
5
+ gem 'rubinius-coverage', '~> 2.0'
6
+ end
7
+
8
+ group :test do
9
+ gem 'railties', '~> 3.2', '< 4.0'
10
+ case ENV['ADAPTER']
11
+ when nil, 'active_record'
12
+ gem 'activerecord-jdbcsqlite3-adapter', '>= 1.3.0.rc', :platform => 'jruby'
13
+ #Fix sqlite3 version for rbx until rubinus is updated
14
+ #https://github.com/travis-ci/travis-ci/issues/2006
15
+ gem 'sqlite3', '1.3.8', :platform => 'ruby'
16
+ gem 'activerecord', '~> 3.2.0', :require => 'active_record'
17
+ when 'mongoid'
18
+ gem 'mongoid', '>= 3.1'
19
+ gem 'bson_ext', :platform => 'ruby'
20
+ else
21
+ raise "Unknown model adapter: #{ENV['ADAPTER']}"
22
+ end
23
+
24
+ gem 'coveralls', :require => false
25
+ end
26
+
27
+ gemspec :path => '../'
@@ -0,0 +1,33 @@
1
+ source 'https://rubygems.org'
2
+
3
+ platforms :rbx do
4
+ gem 'psych'
5
+ gem 'rubinius-coverage', '~> 2.0'
6
+ end
7
+
8
+ group :test do
9
+ gem 'railties', '~> 4.0.1', '< 4.1'
10
+ gem 'ammeter'
11
+ gem 'rake'
12
+ gem 'rspec'
13
+ gem 'its'
14
+ gem 'rspec-rails'
15
+ gem 'fuubar'
16
+ gem 'bundler'
17
+
18
+ gem 'coveralls', :require => false
19
+
20
+ case ENV['ADAPTER']
21
+ when nil, 'active_record'
22
+ gem 'activerecord', '~> 4.0.1', :require => 'active_record'
23
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.5', :platform => 'jruby'
24
+ #Fix sqlite3 version for rbx until rubinus is updated
25
+ #https://github.com/travis-ci/travis-ci/issues/2006
26
+ gem 'sqlite3', '1.3.8', :platform => 'ruby'
27
+ when 'mongoid'
28
+ gem 'mongoid', github: 'mongoid/mongoid'
29
+ gem 'bson_ext', :platform => 'ruby'
30
+ else
31
+ raise "Unknown model adapter: #{ENV['ADAPTER']}"
32
+ end
33
+ end
@@ -0,0 +1,37 @@
1
+ source 'https://rubygems.org'
2
+
3
+ platforms :rbx do
4
+ gem 'psych'
5
+ gem 'rubinius-coverage', '~> 2.0'
6
+ end
7
+
8
+ group :test do
9
+ gem 'rails', github: 'rails/rails', branch: '4-1-stable'
10
+ # There is currently an active record bug in Rails 4.1.0, this is a workaround until 4.1.1 is released
11
+ # See https://github.com/rails/rails/issues/13648
12
+ # Without this patch, Resource.with_role(:role, User.first).count throws an SQL syntax exception
13
+ #gem 'railties', '~> 4.1.0'
14
+ gem 'ammeter'
15
+ gem 'rake'
16
+ gem 'rspec'
17
+ gem 'its'
18
+ gem 'rspec-rails'
19
+ gem 'fuubar'
20
+ gem 'bundler'
21
+
22
+ gem 'coveralls', :require => false
23
+
24
+ case ENV['ADAPTER']
25
+ when nil, 'active_record'
26
+ gem 'activerecord', '~> 4.1.0', :require => 'active_record'
27
+ gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.5', :platform => 'jruby'
28
+ #Fix sqlite3 version for rbx until rubinus is updated
29
+ #https://github.com/travis-ci/travis-ci/issues/2006
30
+ gem 'sqlite3', '1.3.8', :platform => 'ruby'
31
+ when 'mongoid'
32
+ gem 'mongoid', github: 'mongoid/mongoid'
33
+ gem 'bson_ext', :platform => 'ruby'
34
+ else
35
+ raise "Unknown model adapter: #{ENV['ADAPTER']}"
36
+ end
37
+ end