rolify 5.3.0 → 6.0.1

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
2
  SHA256:
3
- metadata.gz: 63187a09a4130c5a7f1066f306783ac5c2fba4e54d5f7130e4b60bdc921b7834
4
- data.tar.gz: f66383e7b30ead36d1f2dac277cb473dc41479db4656a4bea0ac85f6c6253f69
3
+ metadata.gz: 548e7372a5619722f724ddf29ced05a3a23f1d13ffc25ee3395121be3b0848f9
4
+ data.tar.gz: 9841e7f855554d8ab8e8027048d338acf36041a3ed96648f3b523a4b99b3ee0a
5
5
  SHA512:
6
- metadata.gz: 6e212c338c8f11662d4bf7f267ae4ecf7e9a4206667cf051053cbaf55b72bd9ba08f7022aed3f85737e29919c3b045129bdec8dfb2922dcb1544232583ce6fcd
7
- data.tar.gz: e0d2c815832045141b1be4ff76a419704785d57e7195b9c18cafa35885267a4cecd3cf9b11ce7952192317d47ae57115d4831860694227aceb072ac56e5ed9ad
6
+ metadata.gz: b6b084f10550cea5c75b07a41cc54ccf37d05b879b6e81a7a1ed979e6ce59198728adb5208ff9ab97c62ddee02692d73707a3a2fc0ad99b48d306500986fdfa4
7
+ data.tar.gz: b99ae9811babb9d719e857704f8491fca157e1fc9949a0be783314938ed0a6e229b4b3f2043060a407ae75251594f0553d9836232459d3d2e0ba2fb70afce6ac
@@ -0,0 +1,6 @@
1
+ version: 2
2
+ updates:
3
+ - package-ecosystem: "github-actions"
4
+ directory: "/"
5
+ schedule:
6
+ interval: "weekly"
@@ -0,0 +1,33 @@
1
+ name: activerecord
2
+ on: [push, pull_request]
3
+ jobs:
4
+ ubuntu:
5
+ runs-on: ubuntu-latest
6
+ continue-on-error: true
7
+ strategy:
8
+ matrix:
9
+ gemfile: [activerecord_4, activerecord_5, activerecord_6]
10
+ ruby: [2.5.9, 2.6.10, 2.7.7]
11
+ include:
12
+ - gemfile: activerecord_7
13
+ ruby: '3.2'
14
+ - gemfile: activerecord_7
15
+ ruby: '3.1'
16
+ - gemfile: activerecord_7
17
+ ruby: '3.0'
18
+ - gemfile: activerecord_6
19
+ ruby: '3.0'
20
+ env:
21
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
22
+ ADAPTER: active_record
23
+ steps:
24
+ - uses: actions/checkout@v3
25
+ - run: sudo apt-get install -y libsqlite3-dev
26
+ - name: Setup ruby
27
+ uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ bundler-cache: true
31
+ - name: Run Tests
32
+ run: |
33
+ bundle exec rake
@@ -0,0 +1,29 @@
1
+ name: mongoid
2
+ on: [push, pull_request]
3
+ jobs:
4
+ ubuntu:
5
+ runs-on: ubuntu-latest
6
+ continue-on-error: true
7
+ services:
8
+ mongodb:
9
+ image: mongo:3.4.23
10
+ ports:
11
+ - 27017:27017
12
+ strategy:
13
+ matrix:
14
+ gemfile: [mongoid_5]
15
+ ruby: [2.5.9, 2.6.10, 2.7.7]
16
+ env:
17
+ BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile
18
+ ADAPTER: mongoid
19
+ steps:
20
+ - uses: actions/checkout@v3
21
+ - run: sudo apt-get install -y libsqlite3-dev
22
+ - name: Setup ruby
23
+ uses: ruby/setup-ruby@v1
24
+ with:
25
+ ruby-version: ${{ matrix.ruby }}
26
+ bundler-cache: true
27
+ - name: Run Tests
28
+ run: |
29
+ bundle exec rake
data/Appraisals CHANGED
@@ -1,5 +1,6 @@
1
1
  appraise 'mongoid-5' do
2
2
  gem "mongoid", "~> 5"
3
+ gem "mongo", "< 2.17"
3
4
  gem "bson_ext", "1.5.1"
4
5
  gem 'bigdecimal', '1.4.2'
5
6
  end
@@ -29,12 +30,6 @@ appraise 'activerecord-5' do
29
30
  gem "actionpack", "~> 5.2.4"
30
31
  gem "activemodel", "~> 5.2.4"
31
32
  gem "railties", "~> 5.2.4"
32
-
33
- gem 'rspec-rails' , github: 'rspec/rspec-rails'
34
- gem 'rspec-core' , github: 'rspec/rspec-core'
35
- gem 'rspec-expectations', github: 'rspec/rspec-expectations'
36
- gem 'rspec-mocks' , github: 'rspec/rspec-mocks'
37
- gem 'rspec-support' , github: 'rspec/rspec-support'
38
33
  end
39
34
 
40
35
  appraise 'activerecord-6' do
@@ -45,10 +40,4 @@ appraise 'activerecord-6' do
45
40
  gem "actionpack", ">= 6.0.0"
46
41
  gem "activemodel", ">= 6.0.0"
47
42
  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'
54
43
  end
data/CHANGELOG.rdoc CHANGED
@@ -1,3 +1,18 @@
1
+ == 6.0.1
2
+
3
+ * Fix with_role with :any resource
4
+
5
+ = 6.0.0 (April 2, 2021)
6
+
7
+ Breaking changes:
8
+
9
+ * Support strict <tt>with_role</tt> queries. Note this changes behaviour of with_role when running in strict mode to behave as previously documented. #543 describes the behaviour change.
10
+ * Dropped support for Ruby 2.3 and 2.4
11
+
12
+ Improvements:
13
+
14
+ * Updated ActiveRecord adapters implementation of <tt>in</tt> to utilise a subquery instead of two queries
15
+
1
16
  = 5.3.0 (June 1, 2020)
2
17
 
3
18
  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.
data/Gemfile CHANGED
@@ -1,15 +1,15 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  group :test do
4
- gem 'appraisal'
5
- gem 'coveralls', :require => false
4
+ gem 'codeclimate-test-reporter', require: nil
5
+ gem 'coveralls', require: false
6
+ gem 'database_cleaner', '~> 1.6.2'
6
7
  gem 'its'
7
- gem 'pry', '< 0.13.0' # pry pins can be removed when we drop Ruby 2.3
8
- gem 'byebug'
9
- gem 'pry-byebug', '< 3.8.0'
10
8
  gem 'test-unit' # Implicitly loaded by ammeter
11
- gem 'database_cleaner', '~> 1.6.2'
12
- gem 'codeclimate-test-reporter', :require => nil
9
+
10
+ gem 'byebug'
11
+ gem 'pry'
12
+ gem 'pry-byebug'
13
13
  end
14
14
 
15
15
  gemspec
data/Rakefile CHANGED
@@ -15,7 +15,7 @@ RSpec::Core::RakeTask.new(:rolify) do |task|
15
15
  task.pattern = 'spec/rolify/**/*_spec.rb'
16
16
  end
17
17
 
18
- if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
18
+ if !ENV["APPRAISAL_INITIALIZED"] && !ENV["CI"]
19
19
  task :default => :appraisal
20
20
  else
21
21
  task :default => [ :spec, 'coveralls:push' ]
@@ -7,15 +7,14 @@ gem "activerecord", "~> 4.2.11", require: "active_record"
7
7
  gem "bigdecimal", "1.4.2"
8
8
 
9
9
  group :test do
10
- gem "appraisal"
10
+ gem "codeclimate-test-reporter", require: nil
11
11
  gem "coveralls", require: false
12
+ gem "database_cleaner", "~> 1.6.2"
12
13
  gem "its"
13
- gem "pry", "< 0.13.0"
14
- gem "byebug"
15
- gem "pry-byebug", "< 3.8.0"
16
14
  gem "test-unit"
17
- gem "database_cleaner", "~> 1.6.2"
18
- gem "codeclimate-test-reporter", require: nil
15
+ gem "byebug"
16
+ gem "pry"
17
+ gem "pry-byebug"
19
18
  end
20
19
 
21
20
  gemspec path: "../"
@@ -7,22 +7,16 @@ gem "activerecord", "~> 5.2.4", require: "active_record"
7
7
  gem "actionpack", "~> 5.2.4"
8
8
  gem "activemodel", "~> 5.2.4"
9
9
  gem "railties", "~> 5.2.4"
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
10
 
16
11
  group :test do
17
- gem "appraisal"
12
+ gem "codeclimate-test-reporter", require: nil
18
13
  gem "coveralls", require: false
14
+ gem "database_cleaner", "~> 1.6.2"
19
15
  gem "its"
20
- gem "pry", "< 0.13.0"
21
- gem "byebug"
22
- gem "pry-byebug", "< 3.8.0"
23
16
  gem "test-unit"
24
- gem "database_cleaner", "~> 1.6.2"
25
- gem "codeclimate-test-reporter", require: nil
17
+ gem "byebug"
18
+ gem "pry"
19
+ gem "pry-byebug"
26
20
  end
27
21
 
28
22
  gemspec path: "../"
@@ -3,26 +3,20 @@
3
3
  source "https://rubygems.org"
4
4
 
5
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"
6
+ gem "activerecord", "~> 6.1.0", require: "active_record"
7
+ gem "actionpack", "~> 6.1.0"
8
+ gem "activemodel", "~> 6.1.0"
9
+ gem "railties", "~> 6.1.0"
15
10
 
16
11
  group :test do
17
- gem "appraisal"
12
+ gem "codeclimate-test-reporter", require: nil
18
13
  gem "coveralls", require: false
14
+ gem "database_cleaner", "~> 1.6.2"
19
15
  gem "its"
20
- gem "pry", "< 0.13.0"
21
- gem "byebug"
22
- gem "pry-byebug", "< 3.8.0"
23
16
  gem "test-unit"
24
- gem "database_cleaner", "~> 1.6.2"
25
- gem "codeclimate-test-reporter", require: nil
17
+ gem "byebug"
18
+ gem "pry"
19
+ gem "pry-byebug"
26
20
  end
27
21
 
28
22
  gemspec path: "../"
@@ -0,0 +1,22 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "sqlite3", "~> 1.4", platform: "ruby"
6
+ gem "activerecord", "~> 7.0.0", require: "active_record"
7
+ gem "actionpack", "~> 7.0.0"
8
+ gem "activemodel", "~> 7.0.0"
9
+ gem "railties", "~> 7.0.0"
10
+
11
+ group :test do
12
+ gem "codeclimate-test-reporter", require: nil
13
+ gem "coveralls", require: false
14
+ gem "database_cleaner", "~> 1.6.2"
15
+ gem "its"
16
+ gem "test-unit"
17
+ gem "byebug"
18
+ gem "pry"
19
+ gem "pry-byebug"
20
+ end
21
+
22
+ gemspec path: "../"
@@ -3,19 +3,19 @@
3
3
  source "https://rubygems.org"
4
4
 
5
5
  gem "mongoid", "~> 5"
6
+ gem "mongo", "< 2.17"
6
7
  gem "bson_ext", "1.5.1"
7
8
  gem "bigdecimal", "1.4.2"
8
9
 
9
10
  group :test do
10
- gem "appraisal"
11
+ gem "codeclimate-test-reporter", require: nil
11
12
  gem "coveralls", require: false
13
+ gem "database_cleaner", "~> 1.6.2"
12
14
  gem "its"
13
- gem "pry", "< 0.13.0"
14
- gem "byebug"
15
- gem "pry-byebug", "< 3.8.0"
16
15
  gem "test-unit"
17
- gem "database_cleaner", "~> 1.6.2"
18
- gem "codeclimate-test-reporter", require: nil
16
+ gem "byebug"
17
+ gem "pry"
18
+ gem "pry-byebug"
19
19
  end
20
20
 
21
21
  gemspec path: "../"
@@ -6,15 +6,14 @@ gem "mongoid", "~> 6"
6
6
  gem "bson_ext", "1.5.1"
7
7
 
8
8
  group :test do
9
- gem "appraisal"
9
+ gem "codeclimate-test-reporter", require: nil
10
10
  gem "coveralls", require: false
11
+ gem "database_cleaner", "~> 1.6.2"
11
12
  gem "its"
12
- gem "pry", "< 0.13.0"
13
- gem "byebug"
14
- gem "pry-byebug", "< 3.8.0"
15
13
  gem "test-unit"
16
- gem "database_cleaner", "~> 1.6.2"
17
- gem "codeclimate-test-reporter", require: nil
14
+ gem "byebug"
15
+ gem "pry"
16
+ gem "pry-byebug"
18
17
  end
19
18
 
20
19
  gemspec path: "../"
@@ -7,15 +7,14 @@ gem "bson_ext", "1.5.1"
7
7
  gem "railties", "5.2.4.1"
8
8
 
9
9
  group :test do
10
- gem "appraisal"
10
+ gem "codeclimate-test-reporter", require: nil
11
11
  gem "coveralls", require: false
12
+ gem "database_cleaner", "~> 1.6.2"
12
13
  gem "its"
13
- gem "pry", "< 0.13.0"
14
- gem "byebug"
15
- gem "pry-byebug", "< 3.8.0"
16
14
  gem "test-unit"
17
- gem "database_cleaner", "~> 1.6.2"
18
- gem "codeclimate-test-reporter", require: nil
15
+ gem "byebug"
16
+ gem "pry"
17
+ gem "pry-byebug"
19
18
  end
20
19
 
21
20
  gemspec path: "../"
@@ -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)}").to_a
29
+ roles = user.roles.where(:name => role_names).select("#{quote_table(role_class.table_name)}.#{quote_column(role_class.primary_key)}")
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
 
@@ -9,14 +9,20 @@ module Rolify
9
9
  end
10
10
 
11
11
  def where_strict(relation, args)
12
- return relation.where(:name => args[:name]) if args[:resource].blank?
13
- resource = if args[:resource].is_a?(Class)
14
- {class: args[:resource].to_s, id: nil}
15
- else
16
- {class: args[:resource].class.name, id: args[:resource].id}
17
- end
18
-
19
- relation.where(:name => args[:name], :resource_type => resource[:class], :resource_id => resource[:id])
12
+ wrap_conditions = relation.name != role_class.name
13
+
14
+ conditions = if args[:resource].is_a?(Class)
15
+ {:resource_type => args[:resource].to_s, :resource_id => nil }
16
+ elsif args[:resource].present?
17
+ {:resource_type => args[:resource].class.name, :resource_id => args[:resource].id}
18
+ else
19
+ {}
20
+ end
21
+
22
+ conditions.merge!(:name => args[:name])
23
+ conditions = wrap_conditions ? { role_table => conditions } : conditions
24
+
25
+ relation.where(conditions)
20
26
  end
21
27
 
22
28
  def find_cached(relation, args)
@@ -67,9 +73,9 @@ module Rolify
67
73
  relation.where("#{column} IS NOT NULL")
68
74
  end
69
75
 
70
- def scope(relation, conditions)
76
+ def scope(relation, conditions, strict)
71
77
  query = relation.joins(:roles)
72
- query = where(query, conditions)
78
+ query = strict ? where_strict(query, conditions) : where(query, conditions)
73
79
  query
74
80
  end
75
81
 
@@ -9,14 +9,20 @@ module Rolify
9
9
  end
10
10
 
11
11
  def where_strict(relation, args)
12
- return relation.where(:name => args[:name]) if args[:resource].blank?
13
- resource = if args[:resource].is_a?(Class)
14
- {class: args[:resource].to_s, id: nil}
15
- else
16
- {class: args[:resource].class.name, id: args[:resource].id}
17
- end
18
-
19
- relation.where(:name => args[:name], :resource_type => resource[:class], :resource_id => resource[:id])
12
+ wrap_conditions = relation.name != role_class.name
13
+
14
+ conditions = if args[:resource].is_a?(Class)
15
+ {:resource_type => args[:resource].to_s, :resource_id => nil }
16
+ elsif args[:resource].present?
17
+ {:resource_type => args[:resource].class.name, :resource_id => args[:resource].id}
18
+ else
19
+ {}
20
+ end
21
+
22
+ conditions.merge!(:name => args[:name])
23
+ conditions = wrap_conditions ? { role_table => conditions } : conditions
24
+
25
+ relation.where(conditions)
20
26
  end
21
27
 
22
28
  def find_cached(relation, args)
@@ -84,8 +90,9 @@ module Rolify
84
90
  relation.where(column.to_sym.ne => nil)
85
91
  end
86
92
 
87
- def scope(relation, conditions)
88
- roles = where(role_class, conditions).map { |role| role.id }
93
+ def scope(relation, conditions, strict)
94
+ query = strict ? where_strict(role_class, conditions) : where(role_class, conditions)
95
+ roles = query.map { |role| role.id }
89
96
  return [] if roles.size.zero?
90
97
  query = relation.any_in(:role_ids => roles)
91
98
  query
@@ -1,7 +1,12 @@
1
1
  module Rolify
2
2
  module Finders
3
3
  def with_role(role_name, resource = nil)
4
- self.adapter.scope(self, :name => role_name, :resource => resource)
4
+ strict = self.strict_rolify && resource && resource != :any
5
+ self.adapter.scope(
6
+ self,
7
+ { :name => role_name, :resource => resource },
8
+ strict
9
+ )
5
10
  end
6
11
 
7
12
  def without_role(role_name, resource = nil)
@@ -41,4 +46,4 @@ module Rolify
41
46
  block.call(users_to_add)
42
47
  end
43
48
  end
44
- end
49
+ end
@@ -11,7 +11,7 @@ module Rolify
11
11
 
12
12
  def with_role(role_name, user = nil)
13
13
  if role_name.is_a? Array
14
- role_name.map!(&:to_s)
14
+ role_name = role_name.map(&:to_s)
15
15
  else
16
16
  role_name = role_name.to_s
17
17
  end
@@ -1,3 +1,3 @@
1
1
  module Rolify
2
- VERSION = "5.3.0"
2
+ VERSION = "6.0.1"
3
3
  end
data/rolify.gemspec CHANGED
@@ -26,9 +26,10 @@ Gem::Specification.new do |s|
26
26
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
27
  s.require_paths = ['lib']
28
28
 
29
- s.required_ruby_version = '>= 2.3'
29
+ s.required_ruby_version = '>= 2.5'
30
30
 
31
31
  s.add_development_dependency 'ammeter', '~> 1.1' # Spec generator
32
+ s.add_development_dependency 'appraisal', '~> 2.0'
32
33
  s.add_development_dependency 'bundler', '~> 2.0' # packaging feature
33
34
  s.add_development_dependency 'rake', '~> 12.3' # Tasks manager
34
35
  s.add_development_dependency 'rspec-rails', '~> 3.8'
@@ -32,7 +32,11 @@ describe Rolify::Generators::RolifyGenerator, :if => ENV['ADAPTER'] == 'active_r
32
32
  end
33
33
  }
34
34
  require File.join(destination_root, "app/models/user.rb")
35
- run_generator
35
+ if Rails::VERSION::MAJOR >= 7
36
+ run_generator %w(--skip-collision-check)
37
+ else
38
+ run_generator
39
+ end
36
40
  }
37
41
 
38
42
  describe 'config/initializers/rolify.rb' do
@@ -4,47 +4,70 @@ shared_examples_for :finders do |param_name, param_method|
4
4
  it { should respond_to(:with_role).with(1).argument }
5
5
  it { should respond_to(:with_role).with(2).arguments }
6
6
 
7
- context "with a global role" do
8
- it { subject.with_role("admin".send(param_method)).should eq([ root ]) }
9
- it { subject.with_role("moderator".send(param_method)).should be_empty }
10
- it { subject.with_role("visitor".send(param_method)).should be_empty }
11
- end
7
+ context "when resource setting: strict is set to false" do
8
+ context "with a global role" do
9
+ it { subject.with_role("admin".send(param_method)).should eq([ root ]) }
10
+ it { subject.with_role("moderator".send(param_method)).should be_empty }
11
+ it { subject.with_role("visitor".send(param_method)).should be_empty }
12
+ end
12
13
 
13
- context "with a class scoped role" do
14
- context "on Forum class" do
15
- it { subject.with_role("admin".send(param_method), Forum).should eq([ root ]) }
16
- it { subject.with_role("moderator".send(param_method), Forum).should eq([ modo ]) }
17
- it { subject.with_role("visitor".send(param_method), Forum).should be_empty }
14
+ context "with a class scoped role" do
15
+ context "on Forum class" do
16
+ it { subject.with_role("admin".send(param_method), Forum).should eq([ root ]) }
17
+ it { subject.with_role("moderator".send(param_method), Forum).should eq([ modo ]) }
18
+ it { subject.with_role("visitor".send(param_method), Forum).should be_empty }
19
+ end
20
+
21
+ context "on Group class" do
22
+ it { subject.with_role("admin".send(param_method), Group).should eq([ root ]) }
23
+ it { subject.with_role("moderator".send(param_method), Group).should eq([ root ]) }
24
+ it { subject.with_role("visitor".send(param_method), Group).should be_empty }
25
+ end
18
26
  end
19
27
 
20
- context "on Group class" do
21
- it { subject.with_role("admin".send(param_method), Group).should eq([ root ]) }
22
- it { subject.with_role("moderator".send(param_method), Group).should eq([ root ]) }
23
- it { subject.with_role("visitor".send(param_method), Group).should be_empty }
28
+ context "with an instance scoped role" do
29
+ context "on Forum.first instance" do
30
+ it { subject.with_role("admin".send(param_method), Forum.first).should eq([ root ]) }
31
+ it { subject.with_role("moderator".send(param_method), Forum.first).should eq([ modo ]) }
32
+ it { subject.with_role("visitor".send(param_method), Forum.first).should be_empty }
33
+ end
34
+
35
+ context "on Forum.last instance" do
36
+ it { subject.with_role("admin".send(param_method), Forum.last).should eq([ root ]) }
37
+ it { subject.with_role("moderator".send(param_method), Forum.last).should eq([ modo ]) }
38
+ it { subject.with_role("visitor".send(param_method), Forum.last).should include(root, visitor) } # =~ doesn't pass using mongoid, don't know why...
39
+ end
40
+
41
+ context "on Group.first instance" do
42
+ it { subject.with_role("admin".send(param_method), Group.first).should eq([ root ]) }
43
+ it { subject.with_role("moderator".send(param_method), Group.first).should eq([ root ]) }
44
+ it { subject.with_role("visitor".send(param_method), Group.first).should eq([ modo ]) }
45
+ end
46
+
47
+ context "on Company.first_instance" do
48
+ it { subject.with_role("owner".send(param_method), Company.first).should eq([ owner ]) }
49
+ end
24
50
  end
25
51
  end
26
52
 
27
- context "with an instance scoped role" do
28
- context "on Forum.first instance" do
29
- it { subject.with_role("admin".send(param_method), Forum.first).should eq([ root ]) }
30
- it { subject.with_role("moderator".send(param_method), Forum.first).should eq([ modo ]) }
31
- it { subject.with_role("visitor".send(param_method), Forum.first).should be_empty }
53
+ context "when resource setting: strict is set to true" do
54
+ before(:context) do
55
+ user_class.strict_rolify = true
32
56
  end
33
-
34
- context "on Forum.last instance" do
35
- it { subject.with_role("admin".send(param_method), Forum.last).should eq([ root ]) }
36
- it { subject.with_role("moderator".send(param_method), Forum.last).should eq([ modo ]) }
37
- it { subject.with_role("visitor".send(param_method), Forum.last).should include(root, visitor) } # =~ doesn't pass using mongoid, don't know why...
57
+ after(:context) do
58
+ user_class.strict_rolify = false
38
59
  end
39
60
 
40
- context "on Group.first instance" do
41
- it { subject.with_role("admin".send(param_method), Group.first).should eq([ root ]) }
42
- it { subject.with_role("moderator".send(param_method), Group.first).should eq([ root ]) }
43
- it { subject.with_role("visitor".send(param_method), Group.first).should eq([ modo ]) }
44
- end
61
+ context "with an instance scoped role" do
62
+ context "on Forum.first instance" do
63
+ it { subject.with_role("admin".send(param_method), Forum.first).should be_empty }
64
+ it { subject.with_role("moderator".send(param_method), Forum.first).should be_empty }
65
+ end
45
66
 
46
- context "on Company.first_instance" do
47
- it { subject.with_role("owner".send(param_method), Company.first).should eq([ owner ]) }
67
+ context "on any resource" do
68
+ it { subject.with_role("admin".send(param_method), :any).should_not be_empty }
69
+ it { subject.with_role("moderator".send(param_method), :any).should_not be_empty }
70
+ end
48
71
  end
49
72
  end
50
73
  end
@@ -97,7 +120,7 @@ shared_examples_for :finders do |param_name, param_method|
97
120
  end
98
121
  end
99
122
  end
100
-
123
+
101
124
 
102
125
  describe ".with_all_roles" do
103
126
  it { should respond_to(:with_all_roles) }
@@ -128,4 +151,4 @@ shared_examples_for :finders do |param_name, param_method|
128
151
  it { subject.with_any_role({ :name => "visitor".send(param_method), :resource => :any }, { :name => "moderator".send(param_method), :resource => :any }).should =~ [ root, modo, visitor ] }
129
152
  end
130
153
  end
131
- end
154
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,5 +1,5 @@
1
- require "simplecov"
2
- SimpleCov.start
1
+ require 'coveralls'
2
+ Coveralls.wear_merged!
3
3
 
4
4
  require 'rubygems'
5
5
  require "bundler/setup"
@@ -13,9 +13,6 @@ rescue LoadError
13
13
  end
14
14
  require 'database_cleaner'
15
15
 
16
- require 'coveralls'
17
- Coveralls.wear_merged!
18
-
19
16
  ENV['ADAPTER'] ||= 'active_record'
20
17
 
21
18
  load File.dirname(__FILE__) + "/support/adapters/#{ENV['ADAPTER']}.rb"
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rolify
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.3.0
4
+ version: 6.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florent Monbillard
8
8
  - Wellington Cordeiro
9
- autorequire:
9
+ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2020-06-01 00:00:00.000000000 Z
12
+ date: 2023-02-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ammeter
@@ -25,6 +25,20 @@ dependencies:
25
25
  - - "~>"
26
26
  - !ruby/object:Gem::Version
27
27
  version: '1.1'
28
+ - !ruby/object:Gem::Dependency
29
+ name: appraisal
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: '2.0'
35
+ type: :development
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: '2.0'
28
42
  - !ruby/object:Gem::Dependency
29
43
  name: bundler
30
44
  requirement: !ruby/object:Gem::Requirement
@@ -77,9 +91,11 @@ executables: []
77
91
  extensions: []
78
92
  extra_rdoc_files: []
79
93
  files:
94
+ - ".github/dependabot.yml"
95
+ - ".github/workflows/activerecord.yml"
96
+ - ".github/workflows/mongoid.yml"
80
97
  - ".gitignore"
81
98
  - ".hakiri.yml"
82
- - ".travis.yml"
83
99
  - Appraisals
84
100
  - CHANGELOG.rdoc
85
101
  - CONTRIBUTORS
@@ -91,6 +107,7 @@ files:
91
107
  - gemfiles/activerecord_4.gemfile
92
108
  - gemfiles/activerecord_5.gemfile
93
109
  - gemfiles/activerecord_6.gemfile
110
+ - gemfiles/activerecord_7.gemfile
94
111
  - gemfiles/mongoid_5.gemfile
95
112
  - gemfiles/mongoid_6.gemfile
96
113
  - gemfiles/mongoid_7.gemfile
@@ -167,7 +184,7 @@ homepage: https://github.com/RolifyCommunity/rolify
167
184
  licenses:
168
185
  - MIT
169
186
  metadata: {}
170
- post_install_message:
187
+ post_install_message:
171
188
  rdoc_options: []
172
189
  require_paths:
173
190
  - lib
@@ -175,15 +192,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
175
192
  requirements:
176
193
  - - ">="
177
194
  - !ruby/object:Gem::Version
178
- version: '2.3'
195
+ version: '2.5'
179
196
  required_rubygems_version: !ruby/object:Gem::Requirement
180
197
  requirements:
181
198
  - - ">="
182
199
  - !ruby/object:Gem::Version
183
200
  version: '0'
184
201
  requirements: []
185
- rubygems_version: 3.1.2
186
- signing_key:
202
+ rubygems_version: 3.4.1
203
+ signing_key:
187
204
  specification_version: 4
188
205
  summary: Roles library with resource scoping
189
206
  test_files:
data/.travis.yml DELETED
@@ -1,58 +0,0 @@
1
- language: ruby
2
-
3
- before_install:
4
- - gem update --system
5
- - gem install bundler
6
- - gem --version
7
-
8
- script: bundle exec rake
9
-
10
- after_success:
11
- - bundle exec codeclimate-test-reporter
12
-
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
31
-
32
- matrix:
33
- exclude:
34
- - gemfile: gemfiles/activerecord_4.gemfile
35
- env: ADAPTER=mongoid
36
- - gemfile: gemfiles/activerecord_5.gemfile
37
- env: ADAPTER=mongoid
38
- - gemfile: gemfiles/activerecord_6.gemfile
39
- env: ADAPTER=mongoid
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
53
-
54
- services: mongodb
55
-
56
- addons:
57
- code_climate:
58
- repo_token: 6bd8d374b120a5449b9a4b7dfda40cc0609dbade48a1b6655f04a9bc8de3a3ee