Skip to content

Commit

Permalink
Merge pull request RolifyCommunity#388 from lorefnon/compat/385
Browse files Browse the repository at this point in the history
Support Rails 5
  • Loading branch information
wldcordeiro committed Feb 29, 2016
2 parents d44ec21 + 38ae565 commit a86d81a
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 35 deletions.
85 changes: 74 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,24 +1,87 @@
language: ruby
sudo: false

rvm:
- 2.2.3
- 2.2.2
- 2.1.2
- 2.0.0

before_install:
- gem update --system
- gem install bundler
- gem --version

script: bundle exec rake

env:
- ADAPTER=active_record
- ADAPTER=mongoid MONGOID_VERSION=3
- ADAPTER=mongoid MONGOID_VERSION=4
- ADAPTER=mongoid MONGOID_VERSION=5
matrix:
include:
- rvm: 2.3.0
gemfile: gemfiles/activerecord_3.gemfile
env: ADAPTER=active_record
- rvm: 2.2.4
gemfile: gemfiles/activerecord_3.gemfile
env: ADAPTER=active_record
- rvm: 2.1.8
gemfile: gemfiles/activerecord_3.gemfile
env: ADAPTER=active_record
- rvm: 2.0.0
gemfile: gemfiles/activerecord_3.gemfile
env: ADAPTER=active_record

- rvm: 2.3.0
gemfile: gemfiles/activerecord_4.gemfile
env: ADAPTER=active_record
- rvm: 2.2.4
gemfile: gemfiles/activerecord_4.gemfile
env: ADAPTER=active_record
- rvm: 2.1.8
gemfile: gemfiles/activerecord_4.gemfile
env: ADAPTER=active_record
- rvm: 2.0.0
gemfile: gemfiles/activerecord_4.gemfile
env: ADAPTER=active_record

- rvm: 2.3.0
gemfile: gemfiles/activerecord_5.gemfile
env: ADAPTER=active_record
- rvm: 2.2.4
gemfile: gemfiles/activerecord_5.gemfile
env: ADAPTER=active_record

- rvm: 2.3.0
gemfile: gemfiles/mongoid_3.gemfile
env: ADAPTER=mongoid
- rvm: 2.2.4
gemfile: gemfiles/mongoid_3.gemfile
env: ADAPTER=mongoid
- rvm: 2.1.8
gemfile: gemfiles/mongoid_3.gemfile
env: ADAPTER=mongoid
- rvm: 2.0.0
gemfile: gemfiles/mongoid_3.gemfile
env: ADAPTER=mongoid

- rvm: 2.3.0
gemfile: gemfiles/mongoid_4.gemfile
env: ADAPTER=mongoid
- rvm: 2.2.4
gemfile: gemfiles/mongoid_4.gemfile
env: ADAPTER=mongoid
- rvm: 2.1.8
gemfile: gemfiles/mongoid_4.gemfile
env: ADAPTER=mongoid
- rvm: 2.0.0
gemfile: gemfiles/mongoid_4.gemfile
env: ADAPTER=mongoid

- rvm: 2.3.0
gemfile: gemfiles/mongoid_5.gemfile
env: ADAPTER=mongoid
- rvm: 2.2.4
gemfile: gemfiles/mongoid_5.gemfile
env: ADAPTER=mongoid
- rvm: 2.1.8
gemfile: gemfiles/mongoid_5.gemfile
env: ADAPTER=mongoid
- rvm: 2.0.0
gemfile: gemfiles/mongoid_5.gemfile
env: ADAPTER=mongoid


services: mongodb

Expand Down
41 changes: 41 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
appraise 'mongoid-3' do
gem "mongoid", "~> 3"
gem "bson_ext", :platform => "ruby"
end

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

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

appraise 'activerecord-3' do
gem "sqlite3", :platform => "ruby"
gem "activerecord", ">= 3.2.0", :require => "active_record"
end

appraise 'activerecord-4' do
gem "sqlite3", :platform => "ruby"
gem "activerecord", ">= 4.2.5", :require => "active_record"
end

appraise 'activerecord-5' do
gem "sqlite3", :platform => "ruby"
gem "activerecord", ">= 5.0.0.beta", :require => "active_record"

# Ammeter dependencies:
gem "actionpack", ">= 5.0.0.beta2"
gem "activemodel", ">= 5.0.0.beta2"
gem "railties", ">= 5.0.0.beta2"

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'

end
20 changes: 1 addition & 19 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,25 +1,7 @@
source "https://rubygems.org"

group :test do
case ENV["ADAPTER"]
when nil, "active_record"
gem "activerecord-jdbcsqlite3-adapter", ">= 1.3.0.rc", :platform => "jruby"
gem "sqlite3", :platform => "ruby"
gem "activerecord", ">= 3.2.0", :require => "active_record"
when "mongoid"
case ENV["MONGOID_VERSION"]
when nil, '5'
gem "mongoid", "~> 5"
when '4'
gem "mongoid", "~> 4"
when '3'
gem "mongoid", "~> 3"
end
gem "bson_ext", :platform => "ruby"
else
raise "Unknown model adapter: #{ENV["ADAPTER"]}"
end

gem 'appraisal'
gem 'coveralls', :require => false
gem 'its'
gem 'byebug'
Expand Down
6 changes: 5 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@ RSpec::Core::RakeTask.new(:rolify) do |task|
task.pattern = 'spec/rolify/**/*_spec.rb'
end

task :default => [ :spec, 'coveralls:push' ]
if !ENV["APPRAISAL_INITIALIZED"] && !ENV["TRAVIS"]
task :default => :appraisal
else
task :default => [ :spec, 'coveralls:push' ]
end

desc 'Run all specs'
task 'spec' do
Expand Down
19 changes: 19 additions & 0 deletions gemfiles/activerecord_3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sqlite3", :platform => "ruby"
gem "activerecord", ">= 3.2.0", :require => "active_record"

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

gemspec :path => "../"
19 changes: 19 additions & 0 deletions gemfiles/activerecord_4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sqlite3", :platform => "ruby"
gem "activerecord", ">= 4.2.5", :require => "active_record"

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

gemspec :path => "../"
27 changes: 27 additions & 0 deletions gemfiles/activerecord_5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "sqlite3", :platform => "ruby"
gem "activerecord", ">= 5.0.0.beta", :require => "active_record"
gem "actionpack", ">= 5.0.0.beta2"
gem "activemodel", ">= 5.0.0.beta2"
gem "railties", ">= 5.0.0.beta2"
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"

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

gemspec :path => "../"
19 changes: 19 additions & 0 deletions gemfiles/mongoid_3.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "mongoid", "~> 3"
gem "bson_ext", :platform => "ruby"

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

gemspec :path => "../"
19 changes: 19 additions & 0 deletions gemfiles/mongoid_4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "mongoid", "~> 4"
gem "bson_ext", :platform => "ruby"

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

gemspec :path => "../"
19 changes: 19 additions & 0 deletions gemfiles/mongoid_5.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "mongoid", "~> 5"
gem "bson_ext", :platform => "ruby"

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

gemspec :path => "../"
7 changes: 6 additions & 1 deletion lib/generators/active_record/rolify_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def copy_rolify_migration
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb"
end

private

def join_table
user_class.table_name + "_" + table_name
end
Expand All @@ -56,7 +58,10 @@ def model_path
def model_content
content = <<RUBY
has_and_belongs_to_many :%{user_cname}, :join_table => :%{join_table}
belongs_to :resource, :polymorphic => true
belongs_to :resource,
:polymorphic => true,
:optional => true
validates :resource_type,
:inclusion => { :in => Rolify.resource_types },
Expand Down
15 changes: 12 additions & 3 deletions spec/generators/rolify/rolify_activerecord_generator_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ class User < ActiveRecord::Base
it { should exist }
it { should contain "class Role < ActiveRecord::Base" }
it { should contain "has_and_belongs_to_many :users, :join_table => :users_roles" }
it { should contain "belongs_to :resource, :polymorphic => true" }
it { should contain "belongs_to :resource,\n"
" :polymorphic => true,\n"
" :optional => true"
}
it { should contain "validates :resource_type,\n"
" :inclusion => { :in => Rolify.resource_types },\n"
" :allow_nil => true" }
Expand Down Expand Up @@ -93,7 +96,10 @@ class User < ActiveRecord::Base
it { should exist }
it { should contain "class AdminRole < ActiveRecord::Base" }
it { should contain "has_and_belongs_to_many :admin_users, :join_table => :admin_users_admin_roles" }
it { should contain "belongs_to :resource, :polymorphic => true" }
it { should contain "belongs_to :resource,\n"
" :polymorphic => true,\n"
" :optional => true"
}
end

describe 'app/models/admin_user.rb' do
Expand Down Expand Up @@ -145,7 +151,10 @@ class User < ActiveRecord::Base
it { should exist }
it { should contain "class Admin::Role < ActiveRecord::Base" }
it { should contain "has_and_belongs_to_many :admin_users, :join_table => :admin_users_admin_roles" }
it { should contain "belongs_to :resource, :polymorphic => true" }
it { should contain "belongs_to :resource,\n"
" :polymorphic => true,\n"
" :optional => true"
}
end

describe 'app/models/admin/user.rb' do
Expand Down

0 comments on commit a86d81a

Please sign in to comment.