rolify 5.2.0 → 5.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: fd31510680fda8c2bbb43eb49688f9d169d99780
4
- data.tar.gz: bc4fd8fd415cc8c45b333c116f75c83a074c77e0
2
+ SHA256:
3
+ metadata.gz: 63187a09a4130c5a7f1066f306783ac5c2fba4e54d5f7130e4b60bdc921b7834
4
+ data.tar.gz: f66383e7b30ead36d1f2dac277cb473dc41479db4656a4bea0ac85f6c6253f69
5
5
  SHA512:
6
- metadata.gz: ca50a30cd8d60796b6be7d21b26d8bfc6841627623592899f778e56e144c75ff607d7b2263e691452e2613d3fe6f8cf950841fb52b6cf132feb033ad4dce8f71
7
- data.tar.gz: 2d914c23c63900d12eded794a0b1ced812d0815987b42c31c9d83c784f4f7fcfbcb992efad429f533b2b2dc31e2da5d6bb39ba7d8063fc8e5170fd6f759ca6a8
6
+ metadata.gz: 6e212c338c8f11662d4bf7f267ae4ecf7e9a4206667cf051053cbaf55b72bd9ba08f7022aed3f85737e29919c3b045129bdec8dfb2922dcb1544232583ce6fcd
7
+ data.tar.gz: e0d2c815832045141b1be4ff76a419704785d57e7195b9c18cafa35885267a4cecd3cf9b11ce7952192317d47ae57115d4831860694227aceb072ac56e5ed9ad
@@ -0,0 +1 @@
1
+ dependency_source: gemspec_file
@@ -1,5 +1,4 @@
1
1
  language: ruby
2
- sudo: false
3
2
 
4
3
  before_install:
5
4
  - gem update --system
@@ -11,80 +10,46 @@ script: bundle exec rake
11
10
  after_success:
12
11
  - bundle exec codeclimate-test-reporter
13
12
 
14
- matrix:
15
- include:
16
- - rvm: 2.3.0
17
- gemfile: gemfiles/activerecord_3.gemfile
18
- env: ADAPTER=active_record
19
- - rvm: 2.2.4
20
- gemfile: gemfiles/activerecord_3.gemfile
21
- env: ADAPTER=active_record
22
- - rvm: 2.1.8
23
- gemfile: gemfiles/activerecord_3.gemfile
24
- env: ADAPTER=active_record
25
- - rvm: 2.0.0
26
- gemfile: gemfiles/activerecord_3.gemfile
27
- env: ADAPTER=active_record
13
+ rvm:
14
+ - 2.7.0
15
+ - 2.6.3
16
+ - 2.5.5
17
+ - 2.4.6
18
+ - 2.3.8
19
+
20
+ gemfile:
21
+ - gemfiles/activerecord_4.gemfile
22
+ - gemfiles/activerecord_5.gemfile
23
+ - gemfiles/activerecord_6.gemfile
24
+ - gemfiles/mongoid_5.gemfile
25
+ - gemfiles/mongoid_6.gemfile
26
+ - gemfiles/mongoid_7.gemfile
27
+
28
+ env:
29
+ - ADAPTER=active_record
30
+ - ADAPTER=mongoid
28
31
 
29
- - rvm: 2.3.0
30
- gemfile: gemfiles/activerecord_4.gemfile
31
- env: ADAPTER=active_record
32
- - rvm: 2.2.4
33
- gemfile: gemfiles/activerecord_4.gemfile
34
- env: ADAPTER=active_record
35
- - rvm: 2.1.8
36
- gemfile: gemfiles/activerecord_4.gemfile
37
- env: ADAPTER=active_record
38
- - rvm: 2.0.0
39
- gemfile: gemfiles/activerecord_4.gemfile
40
- env: ADAPTER=active_record
41
-
42
- - rvm: 2.3.0
43
- gemfile: gemfiles/activerecord_5.gemfile
44
- env: ADAPTER=active_record
45
- - rvm: 2.2.4
46
- gemfile: gemfiles/activerecord_5.gemfile
47
- env: ADAPTER=active_record
48
-
49
- - rvm: 2.3.0
50
- gemfile: gemfiles/mongoid_3.gemfile
51
- env: ADAPTER=mongoid
52
- - rvm: 2.2.4
53
- gemfile: gemfiles/mongoid_3.gemfile
54
- env: ADAPTER=mongoid
55
- - rvm: 2.1.8
56
- gemfile: gemfiles/mongoid_3.gemfile
57
- env: ADAPTER=mongoid
58
- - rvm: 2.0.0
59
- gemfile: gemfiles/mongoid_3.gemfile
60
- env: ADAPTER=mongoid
61
-
62
- - rvm: 2.3.0
63
- gemfile: gemfiles/mongoid_4.gemfile
64
- env: ADAPTER=mongoid
65
- - rvm: 2.2.4
66
- gemfile: gemfiles/mongoid_4.gemfile
67
- env: ADAPTER=mongoid
68
- - rvm: 2.1.8
69
- gemfile: gemfiles/mongoid_4.gemfile
70
- env: ADAPTER=mongoid
71
- - rvm: 2.0.0
72
- gemfile: gemfiles/mongoid_4.gemfile
73
- env: ADAPTER=mongoid
74
-
75
- - rvm: 2.3.0
76
- gemfile: gemfiles/mongoid_5.gemfile
77
- env: ADAPTER=mongoid
78
- - rvm: 2.2.4
79
- gemfile: gemfiles/mongoid_5.gemfile
32
+ matrix:
33
+ exclude:
34
+ - gemfile: gemfiles/activerecord_4.gemfile
80
35
  env: ADAPTER=mongoid
81
- - rvm: 2.1.8
82
- gemfile: gemfiles/mongoid_5.gemfile
36
+ - gemfile: gemfiles/activerecord_5.gemfile
83
37
  env: ADAPTER=mongoid
84
- - rvm: 2.0.0
85
- gemfile: gemfiles/mongoid_5.gemfile
38
+ - gemfile: gemfiles/activerecord_6.gemfile
86
39
  env: ADAPTER=mongoid
87
-
40
+ - gemfile: gemfiles/activerecord_6.gemfile
41
+ rvm: 2.4.6
42
+ - gemfile: gemfiles/activerecord_6.gemfile
43
+ rvm: 2.3.8
44
+ - gemfile: gemfiles/mongoid_5.gemfile
45
+ env: ADAPTER=active_record
46
+ - gemfile: gemfiles/mongoid_6.gemfile
47
+ env: ADAPTER=active_record
48
+ - gemfile: gemfiles/mongoid_7.gemfile
49
+ env: ADAPTER=active_record
50
+ allow_failures:
51
+ - gemfile: gemfiles/mongoid_6.gemfile
52
+ - gemfile: gemfiles/mongoid_7.gemfile
88
53
 
89
54
  services: mongodb
90
55
 
data/Appraisals CHANGED
@@ -1,41 +1,54 @@
1
- appraise 'mongoid-3' do
2
- gem "mongoid", "~> 3"
3
- gem "bson_ext", :platform => "ruby"
4
- end
5
-
6
- appraise 'mongoid-4' do
7
- gem "mongoid", "~> 4"
8
- gem "bson_ext", :platform => "ruby"
9
- end
10
-
11
1
  appraise 'mongoid-5' do
12
2
  gem "mongoid", "~> 5"
13
- gem "bson_ext", :platform => "ruby"
3
+ gem "bson_ext", "1.5.1"
4
+ gem 'bigdecimal', '1.4.2'
14
5
  end
15
6
 
16
- appraise 'activerecord-3' do
17
- gem "sqlite3", :platform => "ruby"
18
- gem "activerecord", "~> 3.2.0", :require => "active_record"
7
+ appraise 'mongoid-6' do
8
+ gem "mongoid", "~> 6"
9
+ gem "bson_ext", "1.5.1"
10
+ end
11
+
12
+ appraise 'mongoid-7' do
13
+ gem "mongoid", "~> 7"
14
+ gem "bson_ext", "1.5.1"
15
+ gem "railties", "5.2.4.1"
19
16
  end
20
17
 
21
18
  appraise 'activerecord-4' do
22
- gem "sqlite3", :platform => "ruby"
23
- gem "activerecord", "~> 4.2.5", :require => "active_record"
19
+ gem "sqlite3", "~> 1.3.6"
20
+ gem "activerecord", "~> 4.2.11", :require => "active_record"
21
+ gem 'bigdecimal', '1.4.2'
24
22
  end
25
23
 
26
24
  appraise 'activerecord-5' do
27
- gem "sqlite3", :platform => "ruby"
28
- gem "activerecord", ">= 5.0.0.beta", :require => "active_record"
25
+ gem "sqlite3", "~> 1.3.6"
26
+ gem "activerecord", "~> 5.2.4", :require => "active_record"
29
27
 
30
28
  # Ammeter dependencies:
31
- gem "actionpack", ">= 5.0.0.beta2"
32
- gem "activemodel", ">= 5.0.0.beta2"
33
- gem "railties", ">= 5.0.0.beta2"
29
+ gem "actionpack", "~> 5.2.4"
30
+ gem "activemodel", "~> 5.2.4"
31
+ gem "railties", "~> 5.2.4"
34
32
 
35
33
  gem 'rspec-rails' , github: 'rspec/rspec-rails'
36
34
  gem 'rspec-core' , github: 'rspec/rspec-core'
37
35
  gem 'rspec-expectations', github: 'rspec/rspec-expectations'
38
36
  gem 'rspec-mocks' , github: 'rspec/rspec-mocks'
39
37
  gem 'rspec-support' , github: 'rspec/rspec-support'
38
+ end
39
+
40
+ appraise 'activerecord-6' do
41
+ gem "sqlite3", "~> 1.4", :platform => "ruby"
42
+ gem "activerecord", ">= 6.0.0", :require => "active_record"
40
43
 
44
+ # Ammeter dependencies:
45
+ gem "actionpack", ">= 6.0.0"
46
+ gem "activemodel", ">= 6.0.0"
47
+ gem "railties", ">= 6.0.0"
48
+
49
+ gem 'rspec-rails' , github: 'rspec/rspec-rails'
50
+ gem 'rspec-core' , github: 'rspec/rspec-core'
51
+ gem 'rspec-expectations', github: 'rspec/rspec-expectations'
52
+ gem 'rspec-mocks' , github: 'rspec/rspec-mocks'
53
+ gem 'rspec-support' , github: 'rspec/rspec-support'
41
54
  end
@@ -1,3 +1,13 @@
1
+ = 5.3.0 (June 1, 2020)
2
+
3
+ 5.3.0 will be the last version to support Ruby < 2.5 and Rails < 5.2. Support for these will be dropped in the next major release.
4
+
5
+ * Fix deprecation warning in Ruby 2.7
6
+ * Add Rails 6 support to migration generator
7
+ * Significant ActiveRecord performance improvements to <tt>add_role</tt> and <tt>without_role</tt>
8
+ * Mongoid fix and performance improvement and to <tt>roles_name</tt>
9
+ * Make it safe to call <tt>Thing.with_role(:admin, user)</tt> with new record
10
+
1
11
  = 5.2.0 (Dec 14, 2017)
2
12
  * Fix regression in generator around belongs_to options compatibility
3
13
  * Update version of database_cleaner
@@ -126,7 +136,7 @@
126
136
  * fixed a backward incompatible change introduced in Rails 3.2 release (<tt>find_or_create_by_* generated methods</tt>)
127
137
 
128
138
  = 2.2 (Jan 18, 2012)
129
- * fixed a bug in the initializer file regarding dynamic shortcuts
139
+ * fixed a bug in the initializer file regarding dynamic shortcuts
130
140
 
131
141
  = 2.1 (Nov 30, 2011)
132
142
  * added syntactic sugar: <tt>grant</tt> and <tt>revoke</tt> are aliases for <tt>has_role</tt> and <tt>has_no_role</tt>
@@ -167,8 +177,8 @@
167
177
 
168
178
  = 1.0 (Aug 25, 2011)
169
179
  * added a new parameter to disable dynamic shortcut methods due to potential incompatibility with other gems using method_missing with the same pattern
170
- * add <tt>Rolify.dynamic_shortcuts = false</tt> in the initializer file or
171
- * use the generator command with a third parameter:
180
+ * add <tt>Rolify.dynamic_shortcuts = false</tt> in the initializer file or
181
+ * use the generator command with a third parameter:
172
182
  * <tt>rails g rolify:role Role User false</tt>
173
183
  * removed the railtie as it created more problems than it solved
174
184
  * code refactoring to do some speed improvements and code clean up
@@ -177,16 +187,16 @@
177
187
  * rolify is now on travis-ci to monitor build status
178
188
 
179
189
  = 0.7 (June 20, 2011)
180
- * added a method_missing to catch newly created role outside the current ruby process (i.e. dynamic shortcut methods are not defined within this process)
181
- * dynamic shortcut is created on the fly in the method_missing to avoid extra method_missing for the same dynamic shortcut
182
- * check if the role actually exists in the database before defining the new method
190
+ * added a method_missing to catch newly created role outside the current ruby process (i.e. dynamic shortcut methods are not defined within this process)
191
+ * dynamic shortcut is created on the fly in the method_missing to avoid extra method_missing for the same dynamic shortcut
192
+ * check if the role actually exists in the database before defining the new method
183
193
  * first call is slower due to method_missing but next calls are fast
184
194
  * avoid strange bugs when spawning many ruby processes as the dynamic shortcut methods were only defined in the process that used the <tt>has_role</tt> command
185
195
 
186
196
  = 0.6 (June 19, 2011)
187
197
  * custom User and Role class names support
188
198
  * can now use other class names for Role and User classes
189
- * fixed generators and templates
199
+ * fixed generators and templates
190
200
  * join table is explicitly set to avoid alphabetical order issue
191
201
  * created a new railtie to load the dynamic shortcuts at startup
192
202
 
@@ -208,7 +218,7 @@
208
218
  * Trying to remove a role scoped to a resource whereas the user has a global role won't remove it
209
219
 
210
220
  = v0.3 (June 06, 2011)
211
- * multiple roles check:
221
+ * multiple roles check:
212
222
  * <tt>has_all_roles?</tt> returns true if the user has ALL the roles in arguments
213
223
  * <tt>has_any_role?</tt> returns true if the user has ANY the roles in arguments
214
224
 
data/Gemfile CHANGED
@@ -4,8 +4,9 @@ group :test do
4
4
  gem 'appraisal'
5
5
  gem 'coveralls', :require => false
6
6
  gem 'its'
7
+ gem 'pry', '< 0.13.0' # pry pins can be removed when we drop Ruby 2.3
7
8
  gem 'byebug'
8
- gem 'pry-byebug'
9
+ gem 'pry-byebug', '< 3.8.0'
9
10
  gem 'test-unit' # Implicitly loaded by ammeter
10
11
  gem 'database_cleaner', '~> 1.6.2'
11
12
  gem 'codeclimate-test-reporter', :require => nil
data/README.md CHANGED
@@ -1,4 +1,4 @@
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://coveralls.io/repos/RolifyCommunity/rolify/badge.svg?branch=master&service=github)](https://coveralls.io/github/RolifyCommunity/rolify?branch=master)
1
+ # rolify [![Gem Version](https://badge.fury.io/rb/rolify.svg)](http://badge.fury.io/rb/rolify) [![build status](https://travis-ci.org/RolifyCommunity/rolify.svg)](http://travis-ci.org/RolifyCommunity/rolify) [![Code Climate](https://codeclimate.com/github/RolifyCommunity/rolify.svg)](https://codeclimate.com/github/RolifyCommunity/rolify) [![Coverage Status](https://coveralls.io/repos/RolifyCommunity/rolify/badge.svg?branch=master&service=github)](https://coveralls.io/github/RolifyCommunity/rolify?branch=master)
2
2
 
3
3
  Very simple Roles library without any authorization enforcement supporting scope on resource object.
4
4
 
@@ -15,9 +15,9 @@ This library can be easily integrated with any authentication gem ([devise](http
15
15
 
16
16
  ## Requirements
17
17
 
18
- * Rails >= 3.2
19
- * ActiveRecord >= 3.2 <b>or</b> Mongoid >= 3.1
20
- * supports ruby 2.0/1.9.3, JRuby 1.6.0+ (in 1.9 mode) and Rubinius 2.0.0dev (in 1.9 mode)
18
+ * Rails >= 4.2
19
+ * ActiveRecord >= 4.2 <b>or</b> Mongoid >= 4.0
20
+ * supports ruby 2.2+, JRuby 1.6.0+ (in 1.9 mode) and Rubinius 2.0.0dev (in 1.9 mode)
21
21
  * support of ruby 1.8 has been dropped due to Mongoid >=3.0 that only supports 1.9 new hash syntax
22
22
 
23
23
  ## Installation
@@ -46,7 +46,7 @@ rails g rolify Role User
46
46
  rails g rolify:role Role User
47
47
  ```
48
48
 
49
- The generator will create your Role model, add a migration file, and update your User class with new class methods.
49
+ The generator will create your Role model, add a migration file, and update your User class with new class methods.
50
50
 
51
51
  ### 2. Run the migration (only required when using ActiveRecord)
52
52
 
@@ -181,6 +181,17 @@ user.has_role? :moderator, Forum.last
181
181
  => true
182
182
  ```
183
183
 
184
+ To check if a user has the exact role scoped to a resource class:
185
+
186
+ ```ruby
187
+ user = User.find(5)
188
+ user.add_role :moderator # sets a global role
189
+ user.has_role? :moderator, Forum.first
190
+ => true
191
+ user.has_strict_role? :moderator, Forum.last
192
+ => false
193
+ ```
194
+
184
195
  ### 6. Resource roles querying
185
196
 
186
197
  Starting from rolify 3.0, you can search roles on instance level or class level resources.
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'bundler'
2
2
  require 'rspec/core/rake_task'
3
3
  require 'coveralls/rake/task'
4
+ require 'appraisal'
4
5
 
5
6
  Bundler::GemHelper.install_tasks
6
7
 
@@ -2,15 +2,17 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sqlite3", platform: "ruby"
6
- gem "activerecord", "~> 4.2.5", require: "active_record"
5
+ gem "sqlite3", "~> 1.3.6"
6
+ gem "activerecord", "~> 4.2.11", require: "active_record"
7
+ gem "bigdecimal", "1.4.2"
7
8
 
8
9
  group :test do
9
10
  gem "appraisal"
10
11
  gem "coveralls", require: false
11
12
  gem "its"
13
+ gem "pry", "< 0.13.0"
12
14
  gem "byebug"
13
- gem "pry-byebug"
15
+ gem "pry-byebug", "< 3.8.0"
14
16
  gem "test-unit"
15
17
  gem "database_cleaner", "~> 1.6.2"
16
18
  gem "codeclimate-test-reporter", require: nil
@@ -2,11 +2,11 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "sqlite3", platform: "ruby"
6
- gem "activerecord", ">= 5.0.0.beta", require: "active_record"
7
- gem "actionpack", ">= 5.0.0.beta2"
8
- gem "activemodel", ">= 5.0.0.beta2"
9
- gem "railties", ">= 5.0.0.beta2"
5
+ gem "sqlite3", "~> 1.3.6"
6
+ gem "activerecord", "~> 5.2.4", require: "active_record"
7
+ gem "actionpack", "~> 5.2.4"
8
+ gem "activemodel", "~> 5.2.4"
9
+ gem "railties", "~> 5.2.4"
10
10
  gem "rspec-rails", github: "rspec/rspec-rails"
11
11
  gem "rspec-core", github: "rspec/rspec-core"
12
12
  gem "rspec-expectations", github: "rspec/rspec-expectations"
@@ -17,8 +17,9 @@ group :test do
17
17
  gem "appraisal"
18
18
  gem "coveralls", require: false
19
19
  gem "its"
20
+ gem "pry", "< 0.13.0"
20
21
  gem "byebug"
21
- gem "pry-byebug"
22
+ gem "pry-byebug", "< 3.8.0"
22
23
  gem "test-unit"
23
24
  gem "database_cleaner", "~> 1.6.2"
24
25
  gem "codeclimate-test-reporter", require: nil
@@ -0,0 +1,28 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.4", platform: "ruby"
6
+ gem "activerecord", ">= 6.0.0", require: "active_record"
7
+ gem "actionpack", ">= 6.0.0"
8
+ gem "activemodel", ">= 6.0.0"
9
+ gem "railties", ">= 6.0.0"
10
+ gem "rspec-rails", github: "rspec/rspec-rails"
11
+ gem "rspec-core", github: "rspec/rspec-core"
12
+ gem "rspec-expectations", github: "rspec/rspec-expectations"
13
+ gem "rspec-mocks", github: "rspec/rspec-mocks"
14
+ gem "rspec-support", github: "rspec/rspec-support"
15
+
16
+ group :test do
17
+ gem "appraisal"
18
+ gem "coveralls", require: false
19
+ gem "its"
20
+ gem "pry", "< 0.13.0"
21
+ gem "byebug"
22
+ gem "pry-byebug", "< 3.8.0"
23
+ gem "test-unit"
24
+ gem "database_cleaner", "~> 1.6.2"
25
+ gem "codeclimate-test-reporter", require: nil
26
+ end
27
+
28
+ gemspec path: "../"
@@ -3,14 +3,16 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mongoid", "~> 5"
6
- gem "bson_ext", platform: "ruby"
6
+ gem "bson_ext", "1.5.1"
7
+ gem "bigdecimal", "1.4.2"
7
8
 
8
9
  group :test do
9
10
  gem "appraisal"
10
11
  gem "coveralls", require: false
11
12
  gem "its"
13
+ gem "pry", "< 0.13.0"
12
14
  gem "byebug"
13
- gem "pry-byebug"
15
+ gem "pry-byebug", "< 3.8.0"
14
16
  gem "test-unit"
15
17
  gem "database_cleaner", "~> 1.6.2"
16
18
  gem "codeclimate-test-reporter", require: nil
@@ -2,15 +2,16 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "mongoid", "~> 3"
6
- gem "bson_ext", platform: "ruby"
5
+ gem "mongoid", "~> 6"
6
+ gem "bson_ext", "1.5.1"
7
7
 
8
8
  group :test do
9
9
  gem "appraisal"
10
10
  gem "coveralls", require: false
11
11
  gem "its"
12
+ gem "pry", "< 0.13.0"
12
13
  gem "byebug"
13
- gem "pry-byebug"
14
+ gem "pry-byebug", "< 3.8.0"
14
15
  gem "test-unit"
15
16
  gem "database_cleaner", "~> 1.6.2"
16
17
  gem "codeclimate-test-reporter", require: nil
@@ -2,15 +2,17 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "mongoid", "~> 4"
6
- gem "bson_ext", platform: "ruby"
5
+ gem "mongoid", "~> 7"
6
+ gem "bson_ext", "1.5.1"
7
+ gem "railties", "5.2.4.1"
7
8
 
8
9
  group :test do
9
10
  gem "appraisal"
10
11
  gem "coveralls", require: false
11
12
  gem "its"
13
+ gem "pry", "< 0.13.0"
12
14
  gem "byebug"
13
- gem "pry-byebug"
15
+ gem "pry-byebug", "< 3.8.0"
14
16
  gem "test-unit"
15
17
  gem "database_cleaner", "~> 1.6.2"
16
18
  gem "codeclimate-test-reporter", require: nil
@@ -82,12 +82,12 @@ Please ensure that this model exists and is not mis-spelled and re-run the gener
82
82
  MSG
83
83
  end
84
84
 
85
- def rails5?
86
- Rails.version.start_with? '5'
85
+ def versioned_migrations?
86
+ Rails::VERSION::MAJOR >= 5
87
87
  end
88
88
 
89
89
  def migration_version
90
- if rails5?
90
+ if versioned_migrations?
91
91
  "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
92
92
  end
93
93
  end
@@ -1,16 +1,15 @@
1
- has_and_belongs_to_many :<%= user_class.table_name %>, :join_table => :<%= join_table %>
1
+ has_and_belongs_to_many :<%= user_class.table_name %>, :join_table => :<%= join_table %>
2
+ <% if Rails::VERSION::MAJOR < 5 %>
3
+ belongs_to :resource,
4
+ :polymorphic => true
5
+ <% else %>
6
+ belongs_to :resource,
7
+ :polymorphic => true,
8
+ :optional => true
9
+ <% end %>
2
10
 
3
- <% if Rails::VERSION::MAJOR < 5 %>
4
- belongs_to :resource,
5
- :polymorphic => true
6
- <% else %>
7
- belongs_to :resource,
8
- :polymorphic => true,
9
- :optional => true
10
- <% end %>
11
+ validates :resource_type,
12
+ :inclusion => { :in => Rolify.resource_types },
13
+ :allow_nil => true
11
14
 
12
- validates :resource_type,
13
- :inclusion => { :in => Rolify.resource_types },
14
- :allow_nil => true
15
-
16
- scopify
15
+ scopify
@@ -27,7 +27,7 @@ module Rolify
27
27
  rolify_options.merge!({ :join_table => self.role_join_table_name }) if Rolify.orm == "active_record"
28
28
  rolify_options.merge!(options.reject{ |k,v| ![ :before_add, :after_add, :before_remove, :after_remove, :inverse_of ].include? k.to_sym })
29
29
 
30
- has_and_belongs_to_many :roles, rolify_options
30
+ has_and_belongs_to_many :roles, **rolify_options
31
31
 
32
32
  self.adapter = Rolify::Adapter::Base.create("role_adapter", self.role_cname, self.name)
33
33
 
@@ -48,7 +48,7 @@ module Rolify
48
48
  self.role_cname = options[:role_cname]
49
49
  self.role_table_name = self.role_cname.tableize.gsub(/\//, "_")
50
50
 
51
- has_many association_name, resourcify_options
51
+ has_many association_name, **resourcify_options
52
52
 
53
53
  self.resource_adapter = Rolify::Adapter::Base.create("resource_adapter", self.role_cname, self.name)
54
54
  @@resource_types << self.name
@@ -26,7 +26,7 @@ module Rolify
26
26
  end
27
27
 
28
28
  def in(relation, user, role_names)
29
- roles = user.roles.where(:name => role_names).select("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)}")
29
+ roles = user.roles.where(:name => role_names).select("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)}").to_a
30
30
  relation.where("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)} IN (?) AND ((#{quote_table(role_class.table_name)}.resource_id = #{quote_table(relation.table_name)}.#{quote_column(relation.primary_key)}) OR (#{quote_table(role_class.table_name)}.resource_id IS NULL))", roles)
31
31
  end
32
32
 
@@ -40,7 +40,7 @@ module Rolify
40
40
 
41
41
  def all_except(resource, excluded_obj)
42
42
  prime_key = resource.primary_key.to_sym
43
- resource.where(prime_key => (resource.all - excluded_obj).map(&prime_key))
43
+ resource.where.not(prime_key => excluded_obj.pluck(prime_key))
44
44
  end
45
45
 
46
46
  private
@@ -46,7 +46,7 @@ module Rolify
46
46
  end
47
47
 
48
48
  def add(relation, role)
49
- relation.role_ids |= [role.id]
49
+ relation.roles << role unless relation.roles.include?(role)
50
50
  end
51
51
 
52
52
  def remove(relation, role_name, resource = nil)
@@ -68,19 +68,13 @@ module Rolify
68
68
  end
69
69
 
70
70
  def scope(relation, conditions)
71
- if Rails.version < "4.0"
72
- query = relation.scoped
73
- else
74
- query = relation.all
75
- end
76
- query = query.joins(:roles)
71
+ query = relation.joins(:roles)
77
72
  query = where(query, conditions)
78
73
  query
79
74
  end
80
75
 
81
76
  def all_except(user, excluded_obj)
82
- prime_key = user.primary_key.to_sym
83
- user.where(prime_key => (user.all - excluded_obj).map(&prime_key))
77
+ user.where.not(user.primary_key => excluded_obj)
84
78
  end
85
79
 
86
80
  private
@@ -86,7 +86,7 @@ module Rolify
86
86
  deprecate :has_no_role, :remove_role
87
87
 
88
88
  def roles_name
89
- self.roles.select(:name).map { |r| r.name }
89
+ self.roles.pluck(:name)
90
90
  end
91
91
 
92
92
  def method_missing(method, *args, &block)
@@ -1,3 +1,3 @@
1
1
  module Rolify
2
- VERSION = "5.2.0"
2
+ VERSION = "5.3.0"
3
3
  end
@@ -9,7 +9,6 @@ Gem::Specification.new do |s|
9
9
  s.version = Rolify::VERSION
10
10
  s.platform = Gem::Platform::RUBY
11
11
  s.homepage = 'https://github.com/RolifyCommunity/rolify'
12
- s.rubyforge_project = s.name
13
12
 
14
13
  s.license = 'MIT'
15
14
 
@@ -27,8 +26,10 @@ Gem::Specification.new do |s|
27
26
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
28
27
  s.require_paths = ['lib']
29
28
 
29
+ s.required_ruby_version = '>= 2.3'
30
+
30
31
  s.add_development_dependency 'ammeter', '~> 1.1' # Spec generator
31
- s.add_development_dependency 'bundler', '~> 1.10' # packaging feature
32
- s.add_development_dependency 'rake', '~> 10.4' # Tasks manager
33
- s.add_development_dependency 'rspec-rails', '~> 3.4'
32
+ s.add_development_dependency 'bundler', '~> 2.0' # packaging feature
33
+ s.add_development_dependency 'rake', '~> 12.3' # Tasks manager
34
+ s.add_development_dependency 'rspec-rails', '~> 3.8'
34
35
  end
@@ -71,6 +71,7 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
71
71
  it { should contain "validates :resource_type,\n"
72
72
  " :inclusion => { :in => Rolify.resource_types },\n"
73
73
  " :allow_nil => true" }
74
+ it { should contain "scopify" }
74
75
  end
75
76
 
76
77
  describe 'app/models/user.rb' do
@@ -240,6 +241,13 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
240
241
  it { should be_a_migration }
241
242
  it { should contain "create_table(:admin_roles)" }
242
243
  it { should contain "create_table(:admin_users_admin_roles, :id => false) do" }
244
+ it do
245
+ if Rails::VERSION::MAJOR < 5
246
+ should contain "< ActiveRecord::Migration"
247
+ else
248
+ should contain "< ActiveRecord::Migration[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
249
+ end
250
+ end
243
251
 
244
252
  context 'mysql2' do
245
253
  let(:adapter) { 'Mysql2Adapter' }
@@ -0,0 +1,19 @@
1
+ require "spec_helper"
2
+
3
+ describe Rolify::Utils do
4
+ class Harness
5
+ extend Rolify::Utils
6
+ define_method(:new_method) { |*_args| true }
7
+ deprecate :old_method, :new_method
8
+ end
9
+
10
+ let(:harness) { Harness.new }
11
+
12
+ context '#deprecate' do
13
+ it 'calls new method with same arguments' do
14
+ expect(harness).to receive(:warn).once
15
+ expect(harness).to receive(:new_method).once.with(1, 2, 3)
16
+ harness.old_method(1, 2, 3)
17
+ end
18
+ end
19
+ end
@@ -1,6 +1,6 @@
1
1
  test:
2
- sessions:
2
+ clients:
3
3
  default:
4
4
  database: godfather
5
5
  hosts:
6
- - localhost:27017
6
+ - localhost:27017
@@ -1,6 +1,6 @@
1
1
  test:
2
- sessions:
2
+ clients:
3
3
  default:
4
4
  database: godfather
5
5
  hosts:
6
- - localhost:27017
6
+ - localhost:27017
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rolify
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florent Monbillard
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2017-12-19 00:00:00.000000000 Z
12
+ date: 2020-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ammeter
@@ -31,42 +31,42 @@ dependencies:
31
31
  requirements:
32
32
  - - "~>"
33
33
  - !ruby/object:Gem::Version
34
- version: '1.10'
34
+ version: '2.0'
35
35
  type: :development
36
36
  prerelease: false
37
37
  version_requirements: !ruby/object:Gem::Requirement
38
38
  requirements:
39
39
  - - "~>"
40
40
  - !ruby/object:Gem::Version
41
- version: '1.10'
41
+ version: '2.0'
42
42
  - !ruby/object:Gem::Dependency
43
43
  name: rake
44
44
  requirement: !ruby/object:Gem::Requirement
45
45
  requirements:
46
46
  - - "~>"
47
47
  - !ruby/object:Gem::Version
48
- version: '10.4'
48
+ version: '12.3'
49
49
  type: :development
50
50
  prerelease: false
51
51
  version_requirements: !ruby/object:Gem::Requirement
52
52
  requirements:
53
53
  - - "~>"
54
54
  - !ruby/object:Gem::Version
55
- version: '10.4'
55
+ version: '12.3'
56
56
  - !ruby/object:Gem::Dependency
57
57
  name: rspec-rails
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
60
  - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '3.4'
62
+ version: '3.8'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
67
  - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '3.4'
69
+ version: '3.8'
70
70
  description: Very simple Roles library without any authorization enforcement supporting
71
71
  scope on resource objects (instance or class). Supports ActiveRecord and Mongoid
72
72
  ORMs.
@@ -78,6 +78,7 @@ extensions: []
78
78
  extra_rdoc_files: []
79
79
  files:
80
80
  - ".gitignore"
81
+ - ".hakiri.yml"
81
82
  - ".travis.yml"
82
83
  - Appraisals
83
84
  - CHANGELOG.rdoc
@@ -87,15 +88,12 @@ files:
87
88
  - README.md
88
89
  - Rakefile
89
90
  - UPGRADE.rdoc
90
- - gemfiles/Gemfile.rails-3.2
91
- - gemfiles/Gemfile.rails-4.0
92
- - gemfiles/Gemfile.rails-4.1
93
- - gemfiles/activerecord_3.gemfile
94
91
  - gemfiles/activerecord_4.gemfile
95
92
  - gemfiles/activerecord_5.gemfile
96
- - gemfiles/mongoid_3.gemfile
97
- - gemfiles/mongoid_4.gemfile
93
+ - gemfiles/activerecord_6.gemfile
98
94
  - gemfiles/mongoid_5.gemfile
95
+ - gemfiles/mongoid_6.gemfile
96
+ - gemfiles/mongoid_7.gemfile
99
97
  - lib/generators/active_record/rolify_generator.rb
100
98
  - lib/generators/active_record/templates/README
101
99
  - lib/generators/active_record/templates/migration.rb
@@ -153,12 +151,13 @@ files:
153
151
  - spec/rolify/shared_examples/shared_examples_for_remove_role.rb
154
152
  - spec/rolify/shared_examples/shared_examples_for_roles.rb
155
153
  - spec/rolify/shared_examples/shared_examples_for_scopes.rb
154
+ - spec/rolify/utils_spec.rb
156
155
  - spec/spec_helper.rb
157
156
  - spec/support/adapters/active_record.rb
158
157
  - spec/support/adapters/mongoid.rb
159
- - spec/support/adapters/mongoid_3.yml
160
- - spec/support/adapters/mongoid_4.yml
161
158
  - spec/support/adapters/mongoid_5.yml
159
+ - spec/support/adapters/mongoid_6.yml
160
+ - spec/support/adapters/mongoid_7.yml
162
161
  - spec/support/adapters/utils/active_record.rb
163
162
  - spec/support/adapters/utils/mongoid.rb
164
163
  - spec/support/data.rb
@@ -176,15 +175,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
175
  requirements:
177
176
  - - ">="
178
177
  - !ruby/object:Gem::Version
179
- version: '0'
178
+ version: '2.3'
180
179
  required_rubygems_version: !ruby/object:Gem::Requirement
181
180
  requirements:
182
181
  - - ">="
183
182
  - !ruby/object:Gem::Version
184
183
  version: '0'
185
184
  requirements: []
186
- rubyforge_project: rolify
187
- rubygems_version: 2.6.14
185
+ rubygems_version: 3.1.2
188
186
  signing_key:
189
187
  specification_version: 4
190
188
  summary: Roles library with resource scoping
@@ -216,12 +214,13 @@ test_files:
216
214
  - spec/rolify/shared_examples/shared_examples_for_remove_role.rb
217
215
  - spec/rolify/shared_examples/shared_examples_for_roles.rb
218
216
  - spec/rolify/shared_examples/shared_examples_for_scopes.rb
217
+ - spec/rolify/utils_spec.rb
219
218
  - spec/spec_helper.rb
220
219
  - spec/support/adapters/active_record.rb
221
220
  - spec/support/adapters/mongoid.rb
222
- - spec/support/adapters/mongoid_3.yml
223
- - spec/support/adapters/mongoid_4.yml
224
221
  - spec/support/adapters/mongoid_5.yml
222
+ - spec/support/adapters/mongoid_6.yml
223
+ - spec/support/adapters/mongoid_7.yml
225
224
  - spec/support/adapters/utils/active_record.rb
226
225
  - spec/support/adapters/utils/mongoid.rb
227
226
  - spec/support/data.rb
@@ -1,27 +0,0 @@
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 => '../'
@@ -1,33 +0,0 @@
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
@@ -1,37 +0,0 @@
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
@@ -1,19 +0,0 @@
1
- # This file was generated by Appraisal
2
-
3
- source "https://rubygems.org"
4
-
5
- gem "sqlite3", platform: "ruby"
6
- gem "activerecord", "~> 3.2.0", require: "active_record"
7
-
8
- group :test do
9
- gem "appraisal"
10
- gem "coveralls", require: false
11
- gem "its"
12
- gem "byebug"
13
- gem "pry-byebug"
14
- gem "test-unit"
15
- gem "database_cleaner", "~> 1.6.2"
16
- gem "codeclimate-test-reporter", require: nil
17
- end
18
-
19
- gemspec path: "../"