Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into sti
Browse files Browse the repository at this point in the history
  • Loading branch information
doits committed Nov 29, 2020
2 parents 98925eb + 7c144ad commit f831526
Show file tree
Hide file tree
Showing 23 changed files with 241 additions and 122 deletions.
1 change: 1 addition & 0 deletions .hakiri.yml
@@ -0,0 +1 @@
dependency_source: gemspec_file
14 changes: 10 additions & 4 deletions .travis.yml
Expand Up @@ -11,18 +11,19 @@ after_success:
- bundle exec codeclimate-test-reporter

rvm:
- 2.7.0
- 2.6.3
- 2.5.5
- 2.4.6
- 2.3.8

gemfile:
- gemfiles/activerecord_4.gemfile
- gemfiles/activerecord_5.gemfile
- gemfiles/activerecord_6.gemfile
- gemfiles/mongoid_5.gemfile
- gemfiles/mongoid_6.gemfile
- gemfiles/mongoid_7.gemfile

env:
env:
- ADAPTER=active_record
- ADAPTER=mongoid

Expand All @@ -32,12 +33,17 @@ matrix:
env: ADAPTER=mongoid
- gemfile: gemfiles/activerecord_5.gemfile
env: ADAPTER=mongoid
- gemfile: gemfiles/activerecord_6.gemfile
env: ADAPTER=mongoid
- gemfile: gemfiles/mongoid_5.gemfile
env: ADAPTER=active_record
- gemfile: gemfiles/mongoid_6.gemfile
env: ADAPTER=active_record
- gemfile: gemfiles/mongoid_7.gemfile
env: ADAPTER=active_record
allow_failures:
- env: ADAPTER=mongoid
- gemfile: gemfiles/mongoid_6.gemfile
- gemfile: gemfiles/mongoid_7.gemfile

services: mongodb

Expand Down
38 changes: 25 additions & 13 deletions Appraisals
@@ -1,30 +1,42 @@
appraise 'mongoid-5' do
gem "mongoid", "~> 5"
gem "bson_ext", "1.5.1"
gem 'bigdecimal', '1.4.2'
end

appraise 'mongoid-6' do
gem "mongoid", "~> 6"
gem "bson_ext", :platform => "ruby"
gem "bson_ext", "1.5.1"
end

appraise 'mongoid-7' do
gem "mongoid", "~> 7"
gem "bson_ext", :platform => "ruby"
gem "bson_ext", "1.5.1"
gem "railties", "5.2.4.1"
end

appraise 'activerecord-4' do
gem "sqlite3", "~> 1.3.6", :platform => "ruby"
gem "sqlite3", "~> 1.3.6"
gem "activerecord", "~> 4.2.11", :require => "active_record"
gem 'bigdecimal', '1.4.2'
end

appraise 'activerecord-5' do
gem "sqlite3", "~> 1.3.6", :platform => "ruby"
gem "activerecord", ">= 5.2.0", :require => "active_record"
gem "sqlite3", "~> 1.3.6"
gem "activerecord", "~> 5.2.4", :require => "active_record"

# Ammeter dependencies:
gem "actionpack", ">= 5.2.0"
gem "activemodel", ">= 5.2.0"
gem "railties", ">= 5.2.0"
gem "actionpack", "~> 5.2.4"
gem "activemodel", "~> 5.2.4"
gem "railties", "~> 5.2.4"
end

gem 'rspec-rails' , github: 'rspec/rspec-rails'
gem 'rspec-core' , github: 'rspec/rspec-core'
gem 'rspec-expectations', github: 'rspec/rspec-expectations'
gem 'rspec-mocks' , github: 'rspec/rspec-mocks'
gem 'rspec-support' , github: 'rspec/rspec-support'
appraise 'activerecord-6' do
gem "sqlite3", "~> 1.4", :platform => "ruby"
gem "activerecord", ">= 6.0.0", :require => "active_record"

# Ammeter dependencies:
gem "actionpack", ">= 6.0.0"
gem "activemodel", ">= 6.0.0"
gem "railties", ">= 6.0.0"
end
26 changes: 18 additions & 8 deletions CHANGELOG.rdoc
@@ -1,3 +1,13 @@
= 5.3.0 (June 1, 2020)

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.

* Fix deprecation warning in Ruby 2.7
* Add Rails 6 support to migration generator
* Significant ActiveRecord performance improvements to <tt>add_role</tt> and <tt>without_role</tt>
* Mongoid fix and performance improvement and to <tt>roles_name</tt>
* Make it safe to call <tt>Thing.with_role(:admin, user)</tt> with new record

= 5.2.0 (Dec 14, 2017)
* Fix regression in generator around belongs_to options compatibility
* Update version of database_cleaner
Expand Down Expand Up @@ -126,7 +136,7 @@
* fixed a backward incompatible change introduced in Rails 3.2 release (<tt>find_or_create_by_* generated methods</tt>)

= 2.2 (Jan 18, 2012)
* fixed a bug in the initializer file regarding dynamic shortcuts
* fixed a bug in the initializer file regarding dynamic shortcuts

= 2.1 (Nov 30, 2011)
* added syntactic sugar: <tt>grant</tt> and <tt>revoke</tt> are aliases for <tt>has_role</tt> and <tt>has_no_role</tt>
Expand Down Expand Up @@ -167,8 +177,8 @@

= 1.0 (Aug 25, 2011)
* added a new parameter to disable dynamic shortcut methods due to potential incompatibility with other gems using method_missing with the same pattern
* add <tt>Rolify.dynamic_shortcuts = false</tt> in the initializer file or
* use the generator command with a third parameter:
* add <tt>Rolify.dynamic_shortcuts = false</tt> in the initializer file or
* use the generator command with a third parameter:
* <tt>rails g rolify:role Role User false</tt>
* removed the railtie as it created more problems than it solved
* code refactoring to do some speed improvements and code clean up
Expand All @@ -177,16 +187,16 @@
* rolify is now on travis-ci to monitor build status

= 0.7 (June 20, 2011)
* 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)
* dynamic shortcut is created on the fly in the method_missing to avoid extra method_missing for the same dynamic shortcut
* check if the role actually exists in the database before defining the new method
* 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)
* dynamic shortcut is created on the fly in the method_missing to avoid extra method_missing for the same dynamic shortcut
* check if the role actually exists in the database before defining the new method
* first call is slower due to method_missing but next calls are fast
* 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

= 0.6 (June 19, 2011)
* custom User and Role class names support
* can now use other class names for Role and User classes
* fixed generators and templates
* fixed generators and templates
* join table is explicitly set to avoid alphabetical order issue
* created a new railtie to load the dynamic shortcuts at startup

Expand All @@ -208,7 +218,7 @@
* Trying to remove a role scoped to a resource whereas the user has a global role won't remove it

= v0.3 (June 06, 2011)
* multiple roles check:
* multiple roles check:
* <tt>has_all_roles?</tt> returns true if the user has ALL the roles in arguments
* <tt>has_any_role?</tt> returns true if the user has ANY the roles in arguments

Expand Down
11 changes: 6 additions & 5 deletions Gemfile
@@ -1,14 +1,15 @@
source "https://rubygems.org"

group :test do
gem 'appraisal'
gem 'coveralls', :require => false
gem 'codeclimate-test-reporter', require: nil
gem 'coveralls', require: false
gem 'database_cleaner', '~> 1.6.2'
gem 'its'
gem 'test-unit' # Implicitly loaded by ammeter

gem 'byebug'
gem 'pry'
gem 'pry-byebug'
gem 'test-unit' # Implicitly loaded by ammeter
gem 'database_cleaner', '~> 1.6.2'
gem 'codeclimate-test-reporter', :require => nil
end

gemspec
4 changes: 2 additions & 2 deletions README.md
@@ -1,4 +1,4 @@
# 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) [![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)
# 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)

Very simple Roles library without any authorization enforcement supporting scope on resource object.

Expand Down Expand Up @@ -46,7 +46,7 @@ rails g rolify Role User
rails g rolify:role Role User
```

The generator will create your Role model, add a migration file, and update your User class with new class methods.
The generator will create your Role model, add a migration file, and update your User class with new class methods.

### 2. Run the migration (only required when using ActiveRecord)

Expand Down
11 changes: 6 additions & 5 deletions gemfiles/activerecord_4.gemfile
Expand Up @@ -2,18 +2,19 @@

source "https://rubygems.org"

gem "sqlite3", "~> 1.3.6", platform: "ruby"
gem "sqlite3", "~> 1.3.6"
gem "activerecord", "~> 4.2.11", require: "active_record"
gem "bigdecimal", "1.4.2"

group :test do
gem "appraisal"
gem "codeclimate-test-reporter", require: nil
gem "coveralls", require: false
gem "database_cleaner", "~> 1.6.2"
gem "its"
gem "test-unit"
gem "byebug"
gem "pry"
gem "pry-byebug"
gem "test-unit"
gem "database_cleaner", "~> 1.6.2"
gem "codeclimate-test-reporter", require: nil
end

gemspec path: "../"
23 changes: 9 additions & 14 deletions gemfiles/activerecord_5.gemfile
Expand Up @@ -2,26 +2,21 @@

source "https://rubygems.org"

gem "sqlite3", "~> 1.3.6", platform: "ruby"
gem "activerecord", ">= 5.2.0", require: "active_record"
gem "actionpack", ">= 5.2.0"
gem "activemodel", ">= 5.2.0"
gem "railties", ">= 5.2.0"
gem "rspec-rails", github: "rspec/rspec-rails"
gem "rspec-core", github: "rspec/rspec-core"
gem "rspec-expectations", github: "rspec/rspec-expectations"
gem "rspec-mocks", github: "rspec/rspec-mocks"
gem "rspec-support", github: "rspec/rspec-support"
gem "sqlite3", "~> 1.3.6"
gem "activerecord", "~> 5.2.4", require: "active_record"
gem "actionpack", "~> 5.2.4"
gem "activemodel", "~> 5.2.4"
gem "railties", "~> 5.2.4"

group :test do
gem "appraisal"
gem "codeclimate-test-reporter", require: nil
gem "coveralls", require: false
gem "database_cleaner", "~> 1.6.2"
gem "its"
gem "test-unit"
gem "byebug"
gem "pry"
gem "pry-byebug"
gem "test-unit"
gem "database_cleaner", "~> 1.6.2"
gem "codeclimate-test-reporter", require: nil
end

gemspec path: "../"
22 changes: 22 additions & 0 deletions gemfiles/activerecord_6.gemfile
@@ -0,0 +1,22 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sqlite3", "~> 1.4", platform: "ruby"
gem "activerecord", ">= 6.0.0", require: "active_record"
gem "actionpack", ">= 6.0.0"
gem "activemodel", ">= 6.0.0"
gem "railties", ">= 6.0.0"

group :test do
gem "codeclimate-test-reporter", require: nil
gem "coveralls", require: false
gem "database_cleaner", "~> 1.6.2"
gem "its"
gem "test-unit"
gem "byebug"
gem "pry"
gem "pry-byebug"
end

gemspec path: "../"
20 changes: 20 additions & 0 deletions gemfiles/mongoid_5.gemfile
@@ -0,0 +1,20 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "mongoid", "~> 5"
gem "bson_ext", "1.5.1"
gem "bigdecimal", "1.4.2"

group :test do
gem "codeclimate-test-reporter", require: nil
gem "coveralls", require: false
gem "database_cleaner", "~> 1.6.2"
gem "its"
gem "test-unit"
gem "byebug"
gem "pry"
gem "pry-byebug"
end

gemspec path: "../"
10 changes: 5 additions & 5 deletions gemfiles/mongoid_6.gemfile
Expand Up @@ -3,17 +3,17 @@
source "https://rubygems.org"

gem "mongoid", "~> 6"
gem "bson_ext", platform: "ruby"
gem "bson_ext", "1.5.1"

group :test do
gem "appraisal"
gem "codeclimate-test-reporter", require: nil
gem "coveralls", require: false
gem "database_cleaner", "~> 1.6.2"
gem "its"
gem "test-unit"
gem "byebug"
gem "pry"
gem "pry-byebug"
gem "test-unit"
gem "database_cleaner", "~> 1.6.2"
gem "codeclimate-test-reporter", require: nil
end

gemspec path: "../"
11 changes: 6 additions & 5 deletions gemfiles/mongoid_7.gemfile
Expand Up @@ -3,17 +3,18 @@
source "https://rubygems.org"

gem "mongoid", "~> 7"
gem "bson_ext", platform: "ruby"
gem "bson_ext", "1.5.1"
gem "railties", "5.2.4.1"

group :test do
gem "appraisal"
gem "codeclimate-test-reporter", require: nil
gem "coveralls", require: false
gem "database_cleaner", "~> 1.6.2"
gem "its"
gem "test-unit"
gem "byebug"
gem "pry"
gem "pry-byebug"
gem "test-unit"
gem "database_cleaner", "~> 1.6.2"
gem "codeclimate-test-reporter", require: nil
end

gemspec path: "../"
6 changes: 3 additions & 3 deletions lib/generators/active_record/rolify_generator.rb
Expand Up @@ -82,12 +82,12 @@ def prompt_missing_user
MSG
end

def rails5?
Rails.version.start_with? '5'
def versioned_migrations?
Rails::VERSION::MAJOR >= 5
end

def migration_version
if rails5?
if versioned_migrations?
"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/rolify.rb
Expand Up @@ -27,7 +27,7 @@ def rolify(options = {})
rolify_options.merge!({ :join_table => self.role_join_table_name }) if Rolify.orm == "active_record"
rolify_options.merge!(options.reject{ |k,v| ![ :before_add, :after_add, :before_remove, :after_remove, :inverse_of ].include? k.to_sym })

has_and_belongs_to_many :roles, rolify_options
has_and_belongs_to_many :roles, **rolify_options

self.adapter = Rolify::Adapter::Base.create("role_adapter", self.role_cname, self.name)

Expand All @@ -48,7 +48,7 @@ def resourcify(association_name = :roles, options = {})
self.role_cname = options[:role_cname]
self.role_table_name = self.role_cname.tableize.gsub(/\//, "_")

has_many association_name, resourcify_options
has_many association_name, **resourcify_options

self.resource_adapter = Rolify::Adapter::Base.create("resource_adapter", self.role_cname, self.name)
@@resource_types << self.name
Expand Down

0 comments on commit f831526

Please sign in to comment.