Skip to content

Commit

Permalink
Began merging all the pull requests from the main Rolify repo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wellington Cordeiro committed Jun 6, 2014
1 parent befc8db commit 645897f
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 30 deletions.
16 changes: 7 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
rvm:
- 1.9.3
- 2.0.0
- 2.1.0
- rbx
- 2.0.0
- 2.1.1
- rbx-2
- jruby-19mode

gemfile:
- gemfiles/Gemfile.rails-3.2
- gemfiles/Gemfile.rails-4.0
- gemfiles/Gemfile.rails-4.1

env:
- ADAPTER=active_record
Expand All @@ -16,10 +17,7 @@ env:
services: mongodb

matrix:
fast_finish: true
exclude:
- rvm: rbx
gemfile: gemfiles/Gemfile.rails-3.2
env: ADAPTER=mongoid
- rvm: rbx
gemfile: gemfiles/Gemfile.rails-4.0
env: ADAPTER=mongoid
- rvm: 1.9.3
gemfile: gemfiles/Gemfile.rails-4.1
13 changes: 6 additions & 7 deletions gemfiles/Gemfile.rails-3.2
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
source "https://rubygems.org"

platforms :rbx do
gem 'racc'
gem 'rubysl', '~> 2.0'
gem 'psych'
gem 'json'
gem 'rubinius-coverage', '~> 2.0'
gem 'rubysl-test-unit'
end

group :test do
gem 'railties', '~> 3.2', '< 4.0'
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"
#Fix sqlite3 version for rbx until rubinus is updated
#https://github.com/travis-ci/travis-ci/issues/2006
gem "sqlite3", "1.3.8", :platform => "ruby"
gem "activerecord", "~> 3.2.0", :require => "active_record"
when "mongoid"
gem "mongoid", ">= 3.1"
gem "bson_ext", :platform => "ruby"
Expand All @@ -25,4 +24,4 @@ group :test do
gem 'coveralls', :require => false
end

gemspec :path => '../'
gemspec :path => '../'
12 changes: 5 additions & 7 deletions gemfiles/Gemfile.rails-4.0
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
source "https://rubygems.org"

platforms :rbx do
gem 'racc'
gem 'rubysl', '~> 2.0'
gem 'psych'
gem 'json'
gem 'rubinius-coverage', '~> 2.0'
gem 'rubysl-test-unit'
end

group :test do
gem "rails", "~> 4.0.1"
gem "railties", "~> 4.0.1", '< 4.1'
gem "ammeter"
gem "rake"
gem "rspec"
Expand All @@ -24,11 +20,13 @@ group :test do
when nil, "active_record"
gem "activerecord", "~> 4.0.1", :require => "active_record"
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.5", :platform => "jruby"
gem "sqlite3", :platform => "ruby"
#Fix sqlite3 version for rbx until rubinus is updated
#https://github.com/travis-ci/travis-ci/issues/2006
gem "sqlite3", "1.3.8", :platform => "ruby"
when "mongoid"
gem "mongoid", github: 'mongoid/mongoid'
gem "bson_ext", :platform => "ruby"
else
raise "Unknown model adapter: #{ENV["ADAPTER"]}"
end
end
end
36 changes: 36 additions & 0 deletions gemfiles/Gemfile.rails-4.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
source "https://rubygems.org"

platforms :rbx do
gem 'psych'
gem 'rubinius-coverage', '~> 2.0'
end

group :test do
gem 'rails', github: 'rails/rails', branch: '4-1-stable'
# There is currently an active record bug in Rails 4.1.0, this is a workaround until 4.1.1 is released
# See https://github.com/rails/rails/issues/13648
# Without this patch, Resource.with_role(:role, User.first).count throws an SQL syntax exception
#gem "railties", "~> 4.1.0"
gem "ammeter"
gem "rake"
gem "rspec"
gem "rspec-rails"
gem "fuubar"
gem "bundler"

gem 'coveralls', :require => false

case ENV["ADAPTER"]
when nil, "active_record"
gem "activerecord", "~> 4.1.0", :require => "active_record"
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.5", :platform => "jruby"
#Fix sqlite3 version for rbx until rubinus is updated
#https://github.com/travis-ci/travis-ci/issues/2006
gem "sqlite3", "1.3.8", :platform => "ruby"
when "mongoid"
gem "mongoid", github: 'mongoid/mongoid'
gem "bson_ext", :platform => "ruby"
else
raise "Unknown model adapter: #{ENV["ADAPTER"]}"
end
end
4 changes: 2 additions & 2 deletions lib/generators/active_record/rolify_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def inject_role_class
end

def copy_rolify_migration
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}"
migration_template "migration.rb", "db/migrate/rolify_create_#{table_name}.rb"
end

def join_table
Expand Down Expand Up @@ -47,4 +47,4 @@ def model_content
end
end
end
end
end
8 changes: 5 additions & 3 deletions lib/rolify/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ def self.included(base)
end

def add_role(role_name, resource = nil)
role = self.class.adapter.find_or_create_by(role_name.to_s,
(resource.is_a?(Class) ? resource.to_s : resource.class.name if resource),
role = self.class.adapter.find_or_create_by(role_name.to_s,
(resource.is_a?(Class) ? resource.to_s : resource.class.name if resource),
(resource.id if resource && !resource.is_a?(Class)))

if !roles.include?(role)
Expand All @@ -24,7 +24,9 @@ def add_role(role_name, resource = nil)

def has_role?(role_name, resource = nil)
if new_record?
self.roles.detect { |r| r.name == role_name.to_s && (r.resource == resource || resource.nil?) }.present?
self.roles.detect { |r| r.name == role_name.to_s && ((resource == :any) ||
(r.resource.nil? && (r.resource_type.nil? || (r.resource_type == resource.class.to_s))) ||
(r.resource == resource))}.present?
else
self.class.adapter.where(self.roles, :name => role_name, :resource => resource).size > 0
end
Expand Down
9 changes: 7 additions & 2 deletions spec/rolify/shared_examples/shared_examples_for_roles.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@
end

subject { user }

it { should have_role :admin }
it { should have_role :moderator, Forum.first }
it { should have_role :admin, Forum }
it { should have_role :admin, :any }
it { should have_role :moderator, Forum.first }
it { should have_role :moderator, :any }
it { should_not have_role :moderator }
it { should_not have_role :moderator, Forum }
it { subject.has_any_role?(:admin).should be_true }
end

Expand Down

0 comments on commit 645897f

Please sign in to comment.