rolify 5.1.0 → 5.3.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.
- checksums.yaml +5 -5
- data/.hakiri.yml +1 -0
- data/.travis.yml +36 -68
- data/Appraisals +34 -21
- data/CHANGELOG.rdoc +28 -8
- data/CONTRIBUTORS +9 -0
- data/Gemfile +3 -2
- data/LICENSE +1 -1
- data/README.md +44 -12
- data/Rakefile +1 -0
- data/gemfiles/activerecord_4.gemfile +9 -7
- data/gemfiles/activerecord_5.gemfile +16 -15
- data/gemfiles/activerecord_6.gemfile +28 -0
- data/gemfiles/mongoid_5.gemfile +8 -6
- data/gemfiles/mongoid_6.gemfile +20 -0
- data/gemfiles/mongoid_7.gemfile +21 -0
- data/lib/generators/active_record/rolify_generator.rb +13 -15
- data/lib/generators/active_record/templates/migration.rb +2 -3
- data/lib/generators/active_record/templates/model.rb +15 -0
- data/lib/generators/rolify/templates/initializer.rb +4 -1
- data/lib/rolify/adapters/active_record/resource_adapter.rb +3 -3
- data/lib/rolify/adapters/active_record/role_adapter.rb +3 -9
- data/lib/rolify/role.rb +1 -1
- data/lib/rolify/version.rb +1 -1
- data/lib/rolify.rb +3 -3
- data/rolify.gemspec +5 -4
- data/spec/generators/rolify/rolify_activerecord_generator_spec.rb +100 -3
- data/spec/rolify/utils_spec.rb +19 -0
- data/spec/spec_helper.rb +2 -3
- data/spec/support/adapters/{mongoid_3.yml → mongoid_6.yml} +2 -2
- data/spec/support/adapters/{mongoid_4.yml → mongoid_7.yml} +2 -2
- metadata +21 -21
- data/gemfiles/Gemfile.rails-3.2 +0 -27
- data/gemfiles/Gemfile.rails-4.0 +0 -33
- data/gemfiles/Gemfile.rails-4.1 +0 -37
- data/gemfiles/activerecord_3.gemfile +0 -19
- data/gemfiles/mongoid_3.gemfile +0 -19
- data/gemfiles/mongoid_4.gemfile +0 -19
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require 'rails/generators/active_record'
|
|
2
2
|
require 'active_support/core_ext'
|
|
3
|
+
require 'erb'
|
|
3
4
|
|
|
4
5
|
module ActiveRecord
|
|
5
6
|
module Generators
|
|
@@ -34,7 +35,7 @@ module ActiveRecord
|
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
def copy_rolify_migration
|
|
37
|
-
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb"
|
|
38
|
+
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb", migration_version: migration_version
|
|
38
39
|
end
|
|
39
40
|
|
|
40
41
|
private
|
|
@@ -56,20 +57,7 @@ module ActiveRecord
|
|
|
56
57
|
end
|
|
57
58
|
|
|
58
59
|
def model_content
|
|
59
|
-
|
|
60
|
-
has_and_belongs_to_many :%{user_cname}, :join_table => :%{join_table}
|
|
61
|
-
|
|
62
|
-
belongs_to :resource,
|
|
63
|
-
:polymorphic => true,
|
|
64
|
-
:optional => true
|
|
65
|
-
|
|
66
|
-
validates :resource_type,
|
|
67
|
-
:inclusion => { :in => Rolify.resource_types },
|
|
68
|
-
:allow_nil => true
|
|
69
|
-
|
|
70
|
-
scopify
|
|
71
|
-
RUBY
|
|
72
|
-
content % { :user_cname => user_class.table_name, :join_table => "#{user_cname.constantize.table_name}_#{table_name}"}
|
|
60
|
+
ERB.new(File.read(File.join(__dir__, 'templates/model.rb'))).result(binding)
|
|
73
61
|
end
|
|
74
62
|
|
|
75
63
|
def user_class
|
|
@@ -94,6 +82,16 @@ Please ensure that this model exists and is not mis-spelled and re-run the gener
|
|
|
94
82
|
MSG
|
|
95
83
|
end
|
|
96
84
|
|
|
85
|
+
def versioned_migrations?
|
|
86
|
+
Rails::VERSION::MAJOR >= 5
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def migration_version
|
|
90
|
+
if versioned_migrations?
|
|
91
|
+
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
|
|
92
|
+
end
|
|
93
|
+
end
|
|
94
|
+
|
|
97
95
|
end
|
|
98
96
|
end
|
|
99
97
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
1
|
+
class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>
|
|
2
2
|
def change
|
|
3
3
|
create_table(:<%= table_name %>) do |t|
|
|
4
4
|
t.string :name
|
|
@@ -11,8 +11,7 @@ class RolifyCreate<%= table_name.camelize %> < ActiveRecord::Migration
|
|
|
11
11
|
t.references :<%= user_reference %>
|
|
12
12
|
t.references :<%= role_reference %>
|
|
13
13
|
end
|
|
14
|
-
|
|
15
|
-
add_index(:<%= table_name %>, :name)
|
|
14
|
+
<% if ActiveRecord::Base.connection.class.to_s.demodulize != 'PostgreSQLAdapter' %><%= "\n " %>add_index(:<%= table_name %>, :name)<% end %>
|
|
16
15
|
add_index(:<%= table_name %>, [ :name, :resource_type, :resource_id ])
|
|
17
16
|
add_index(:<%= join_table %>, [ :<%= user_reference %>_id, :<%= role_reference %>_id ])
|
|
18
17
|
end
|
|
@@ -0,0 +1,15 @@
|
|
|
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 %>
|
|
10
|
+
|
|
11
|
+
validates :resource_type,
|
|
12
|
+
:inclusion => { :in => Rolify.resource_types },
|
|
13
|
+
:allow_nil => true
|
|
14
|
+
|
|
15
|
+
scopify
|
|
@@ -4,4 +4,7 @@ Rolify.configure<%= "(\"#{class_name.camelize.to_s}\")" if class_name != "Role"
|
|
|
4
4
|
|
|
5
5
|
# Dynamic shortcuts for User class (user.is_admin? like methods). Default is: false
|
|
6
6
|
# config.use_dynamic_shortcuts
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
# Configuration to remove roles from database once the last resource is removed. Default is: true
|
|
9
|
+
# config.remove_role_if_empty = false
|
|
10
|
+
end
|
|
@@ -26,8 +26,8 @@ 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)}")
|
|
30
|
-
relation.where("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)} IN (?) AND ((resource_id = #{quote_table(relation.table_name)}.#{quote_column(relation.primary_key)}) OR (resource_id IS NULL))", roles)
|
|
29
|
+
roles = user.roles.where(:name => role_names).select("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)}").to_a
|
|
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
|
|
|
33
33
|
def applied_roles(relation, children)
|
|
@@ -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 =>
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
data/lib/rolify/role.rb
CHANGED
data/lib/rolify/version.rb
CHANGED
data/lib/rolify.rb
CHANGED
|
@@ -25,9 +25,9 @@ module Rolify
|
|
|
25
25
|
|
|
26
26
|
rolify_options = { :class_name => options[:role_cname].camelize }
|
|
27
27
|
rolify_options.merge!({ :join_table => self.role_join_table_name }) if Rolify.orm == "active_record"
|
|
28
|
-
rolify_options.merge!(options.reject{ |k,v| ![ :before_add, :after_add, :before_remove, :after_remove ].include? k.to_sym })
|
|
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
|
data/rolify.gemspec
CHANGED
|
@@ -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', '~>
|
|
32
|
-
s.add_development_dependency 'rake', '~>
|
|
33
|
-
s.add_development_dependency 'rspec-rails', '~> 3.
|
|
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
|
|
@@ -8,6 +8,7 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
8
8
|
destination File.expand_path("../../../../tmp", __FILE__)
|
|
9
9
|
teardown :cleanup_destination_root
|
|
10
10
|
|
|
11
|
+
let(:adapter) { 'SQLite3Adapter' }
|
|
11
12
|
before {
|
|
12
13
|
prepare_destination
|
|
13
14
|
}
|
|
@@ -20,6 +21,8 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
20
21
|
before(:all) { arguments %w(Role) }
|
|
21
22
|
|
|
22
23
|
before {
|
|
24
|
+
allow(ActiveRecord::Base).to receive_message_chain(
|
|
25
|
+
'connection.class.to_s.demodulize') { adapter }
|
|
23
26
|
capture(:stdout) {
|
|
24
27
|
generator.create_file "app/models/user.rb" do
|
|
25
28
|
<<-RUBY
|
|
@@ -43,8 +46,24 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
43
46
|
describe 'app/models/role.rb' do
|
|
44
47
|
subject { file('app/models/role.rb') }
|
|
45
48
|
it { should exist }
|
|
46
|
-
it
|
|
49
|
+
it do
|
|
50
|
+
if Rails::VERSION::MAJOR < 5
|
|
51
|
+
should contain "class Role < ActiveRecord::Base"
|
|
52
|
+
else
|
|
53
|
+
should contain "class Role < ApplicationRecord"
|
|
54
|
+
end
|
|
55
|
+
end
|
|
47
56
|
it { should contain "has_and_belongs_to_many :users, :join_table => :users_roles" }
|
|
57
|
+
it do
|
|
58
|
+
if Rails::VERSION::MAJOR < 5
|
|
59
|
+
should contain "belongs_to :resource,\n"
|
|
60
|
+
" :polymorphic => true"
|
|
61
|
+
else
|
|
62
|
+
should contain "belongs_to :resource,\n"
|
|
63
|
+
" :polymorphic => true,\n"
|
|
64
|
+
" :optional => true"
|
|
65
|
+
end
|
|
66
|
+
end
|
|
48
67
|
it { should contain "belongs_to :resource,\n"
|
|
49
68
|
" :polymorphic => true,\n"
|
|
50
69
|
" :optional => true"
|
|
@@ -52,6 +71,7 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
52
71
|
it { should contain "validates :resource_type,\n"
|
|
53
72
|
" :inclusion => { :in => Rolify.resource_types },\n"
|
|
54
73
|
" :allow_nil => true" }
|
|
74
|
+
it { should contain "scopify" }
|
|
55
75
|
end
|
|
56
76
|
|
|
57
77
|
describe 'app/models/user.rb' do
|
|
@@ -65,6 +85,24 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
65
85
|
it { should be_a_migration }
|
|
66
86
|
it { should contain "create_table(:roles) do" }
|
|
67
87
|
it { should contain "create_table(:users_roles, :id => false) do" }
|
|
88
|
+
|
|
89
|
+
context 'mysql2' do
|
|
90
|
+
let(:adapter) { 'Mysql2Adapter' }
|
|
91
|
+
|
|
92
|
+
it { expect(subject).to contain('add_index(:roles, :name)') }
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
context 'sqlite3' do
|
|
96
|
+
let(:adapter) { 'SQLite3Adapter' }
|
|
97
|
+
|
|
98
|
+
it { expect(subject).to contain('add_index(:roles, :name)') }
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
context 'pg' do
|
|
102
|
+
let(:adapter) { 'PostgreSQLAdapter' }
|
|
103
|
+
|
|
104
|
+
it { expect(subject).not_to contain('add_index(:roles, :name)') }
|
|
105
|
+
end
|
|
68
106
|
end
|
|
69
107
|
end
|
|
70
108
|
|
|
@@ -72,6 +110,8 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
72
110
|
before(:all) { arguments %w(AdminRole AdminUser) }
|
|
73
111
|
|
|
74
112
|
before {
|
|
113
|
+
allow(ActiveRecord::Base).to receive_message_chain(
|
|
114
|
+
'connection.class.to_s.demodulize') { adapter }
|
|
75
115
|
capture(:stdout) {
|
|
76
116
|
generator.create_file "app/models/admin_user.rb" do
|
|
77
117
|
"class AdminUser < ActiveRecord::Base\nend"
|
|
@@ -94,7 +134,13 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
94
134
|
subject { file('app/models/admin_role.rb') }
|
|
95
135
|
|
|
96
136
|
it { should exist }
|
|
97
|
-
it
|
|
137
|
+
it do
|
|
138
|
+
if Rails::VERSION::MAJOR < 5
|
|
139
|
+
should contain "class AdminRole < ActiveRecord::Base"
|
|
140
|
+
else
|
|
141
|
+
should contain "class AdminRole < ApplicationRecord"
|
|
142
|
+
end
|
|
143
|
+
end
|
|
98
144
|
it { should contain "has_and_belongs_to_many :admin_users, :join_table => :admin_users_admin_roles" }
|
|
99
145
|
it { should contain "belongs_to :resource,\n"
|
|
100
146
|
" :polymorphic => true,\n"
|
|
@@ -114,6 +160,24 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
114
160
|
it { should be_a_migration }
|
|
115
161
|
it { should contain "create_table(:admin_roles)" }
|
|
116
162
|
it { should contain "create_table(:admin_users_admin_roles, :id => false) do" }
|
|
163
|
+
|
|
164
|
+
context 'mysql2' do
|
|
165
|
+
let(:adapter) { 'Mysql2Adapter' }
|
|
166
|
+
|
|
167
|
+
it { expect(subject).to contain('add_index(:admin_roles, :name)') }
|
|
168
|
+
end
|
|
169
|
+
|
|
170
|
+
context 'sqlite3' do
|
|
171
|
+
let(:adapter) { 'SQLite3Adapter' }
|
|
172
|
+
|
|
173
|
+
it { expect(subject).to contain('add_index(:admin_roles, :name)') }
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
context 'pg' do
|
|
177
|
+
let(:adapter) { 'PostgreSQLAdapter' }
|
|
178
|
+
|
|
179
|
+
it { expect(subject).not_to contain('add_index(:admin_roles, :name)') }
|
|
180
|
+
end
|
|
117
181
|
end
|
|
118
182
|
end
|
|
119
183
|
|
|
@@ -121,6 +185,8 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
121
185
|
before(:all) { arguments %w(Admin::Role Admin::User) }
|
|
122
186
|
|
|
123
187
|
before {
|
|
188
|
+
allow(ActiveRecord::Base).to receive_message_chain(
|
|
189
|
+
'connection.class.to_s.demodulize') { adapter }
|
|
124
190
|
capture(:stdout) {
|
|
125
191
|
generator.create_file "app/models/admin/user.rb" do
|
|
126
192
|
<<-RUBY
|
|
@@ -149,7 +215,13 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
149
215
|
subject { file('app/models/admin/role.rb') }
|
|
150
216
|
|
|
151
217
|
it { should exist }
|
|
152
|
-
it
|
|
218
|
+
it do
|
|
219
|
+
if Rails::VERSION::MAJOR < 5
|
|
220
|
+
should contain "class Admin::Role < ActiveRecord::Base"
|
|
221
|
+
else
|
|
222
|
+
should contain "class Admin::Role < ApplicationRecord"
|
|
223
|
+
end
|
|
224
|
+
end
|
|
153
225
|
it { should contain "has_and_belongs_to_many :admin_users, :join_table => :admin_users_admin_roles" }
|
|
154
226
|
it { should contain "belongs_to :resource,\n"
|
|
155
227
|
" :polymorphic => true,\n"
|
|
@@ -169,6 +241,31 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
|
|
|
169
241
|
it { should be_a_migration }
|
|
170
242
|
it { should contain "create_table(:admin_roles)" }
|
|
171
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
|
|
251
|
+
|
|
252
|
+
context 'mysql2' do
|
|
253
|
+
let(:adapter) { 'Mysql2Adapter' }
|
|
254
|
+
|
|
255
|
+
it { expect(subject).to contain('add_index(:admin_roles, :name)') }
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
context 'sqlite3' do
|
|
259
|
+
let(:adapter) { 'SQLite3Adapter' }
|
|
260
|
+
|
|
261
|
+
it { expect(subject).to contain('add_index(:admin_roles, :name)') }
|
|
262
|
+
end
|
|
263
|
+
|
|
264
|
+
context 'pg' do
|
|
265
|
+
let(:adapter) { 'PostgreSQLAdapter' }
|
|
266
|
+
|
|
267
|
+
it { expect(subject).not_to contain('add_index(:admin_roles, :name)') }
|
|
268
|
+
end
|
|
172
269
|
end
|
|
173
270
|
end
|
|
174
271
|
end
|
|
@@ -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
|
data/spec/spec_helper.rb
CHANGED
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.
|
|
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:
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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: '
|
|
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.
|
|
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.
|
|
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,18 +88,16 @@ 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/
|
|
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
|
|
100
|
+
- lib/generators/active_record/templates/model.rb
|
|
102
101
|
- lib/generators/mongoid/rolify_generator.rb
|
|
103
102
|
- lib/generators/mongoid/templates/README-mongoid
|
|
104
103
|
- lib/generators/rolify/rolify_generator.rb
|
|
@@ -152,12 +151,13 @@ files:
|
|
|
152
151
|
- spec/rolify/shared_examples/shared_examples_for_remove_role.rb
|
|
153
152
|
- spec/rolify/shared_examples/shared_examples_for_roles.rb
|
|
154
153
|
- spec/rolify/shared_examples/shared_examples_for_scopes.rb
|
|
154
|
+
- spec/rolify/utils_spec.rb
|
|
155
155
|
- spec/spec_helper.rb
|
|
156
156
|
- spec/support/adapters/active_record.rb
|
|
157
157
|
- spec/support/adapters/mongoid.rb
|
|
158
|
-
- spec/support/adapters/mongoid_3.yml
|
|
159
|
-
- spec/support/adapters/mongoid_4.yml
|
|
160
158
|
- spec/support/adapters/mongoid_5.yml
|
|
159
|
+
- spec/support/adapters/mongoid_6.yml
|
|
160
|
+
- spec/support/adapters/mongoid_7.yml
|
|
161
161
|
- spec/support/adapters/utils/active_record.rb
|
|
162
162
|
- spec/support/adapters/utils/mongoid.rb
|
|
163
163
|
- spec/support/data.rb
|
|
@@ -175,15 +175,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
175
175
|
requirements:
|
|
176
176
|
- - ">="
|
|
177
177
|
- !ruby/object:Gem::Version
|
|
178
|
-
version: '
|
|
178
|
+
version: '2.3'
|
|
179
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
180
180
|
requirements:
|
|
181
181
|
- - ">="
|
|
182
182
|
- !ruby/object:Gem::Version
|
|
183
183
|
version: '0'
|
|
184
184
|
requirements: []
|
|
185
|
-
|
|
186
|
-
rubygems_version: 2.4.5.1
|
|
185
|
+
rubygems_version: 3.1.2
|
|
187
186
|
signing_key:
|
|
188
187
|
specification_version: 4
|
|
189
188
|
summary: Roles library with resource scoping
|
|
@@ -215,12 +214,13 @@ test_files:
|
|
|
215
214
|
- spec/rolify/shared_examples/shared_examples_for_remove_role.rb
|
|
216
215
|
- spec/rolify/shared_examples/shared_examples_for_roles.rb
|
|
217
216
|
- spec/rolify/shared_examples/shared_examples_for_scopes.rb
|
|
217
|
+
- spec/rolify/utils_spec.rb
|
|
218
218
|
- spec/spec_helper.rb
|
|
219
219
|
- spec/support/adapters/active_record.rb
|
|
220
220
|
- spec/support/adapters/mongoid.rb
|
|
221
|
-
- spec/support/adapters/mongoid_3.yml
|
|
222
|
-
- spec/support/adapters/mongoid_4.yml
|
|
223
221
|
- spec/support/adapters/mongoid_5.yml
|
|
222
|
+
- spec/support/adapters/mongoid_6.yml
|
|
223
|
+
- spec/support/adapters/mongoid_7.yml
|
|
224
224
|
- spec/support/adapters/utils/active_record.rb
|
|
225
225
|
- spec/support/adapters/utils/mongoid.rb
|
|
226
226
|
- spec/support/data.rb
|
data/gemfiles/Gemfile.rails-3.2
DELETED
|
@@ -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 => '../'
|
data/gemfiles/Gemfile.rails-4.0
DELETED
|
@@ -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
|