Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync with Master repository #1

Merged
merged 47 commits into from
Apr 13, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
d2a14e5
Add link to mailing list.
bryanrite Feb 23, 2014
5a9a7fd
Update Travis build image.
bryanrite Feb 24, 2014
83aa5db
Update Travis as Rubinius now builds successfully.
bryanrite Feb 25, 2014
ee9f036
Ignore Mac's .DS_Store files and config folder, which Rubymine genera…
Loremaster Feb 25, 2014
1323a5c
Merge pull request #6 from Loremaster/gitignore
bryanrite Feb 25, 2014
ac9b668
.ruby-version should not be included in the gem.
bryanrite Feb 25, 2014
59e0443
Ignore ruby version settings and gemsets.
bryanrite Feb 25, 2014
5a3684a
Sigh... RBX is failing to build on Travis again.
bryanrite Feb 25, 2014
2712a64
Add docs badge to README
rrrene Feb 28, 2014
ec36005
Fix deprecation `I18n.enforce_available_locales will default to true …
Loremaster Feb 28, 2014
ac57de9
supermodel and rails bumped.
Loremaster Feb 28, 2014
6037fbc
Merge pull request #9 from Loremaster/gems-bumps
bryanrite Feb 28, 2014
bad36e6
Merge pull request #8 from rrrene/patch-1
bryanrite Feb 28, 2014
876cce7
Merge pull request #7 from Loremaster/fix-i18n-deprecation
bryanrite Mar 3, 2014
9e87457
Update README.rdoc
macarthy Mar 6, 2014
a91c525
Merge pull request #12 from macarthy/patch-1
bryanrite Mar 6, 2014
eed52bc
Add guard for local development.
bryanrite Mar 6, 2014
f3b4ec3
Setup Appraisals to test against different gems.
bryanrite Mar 6, 2014
0a9d8cd
Rename appraisal gemfiles.
bryanrite Mar 6, 2014
8eb298f
Proper homepage.
bryanrite Mar 7, 2014
2fb16a6
These are handled by appraisals file.
bryanrite Mar 7, 2014
9938da7
Setup Appraisals file with proper gem requirements.
bryanrite Mar 7, 2014
3d81a3a
Don't use MODEL_ADAPTER, conditionally check if adapter is defined.
bryanrite Mar 7, 2014
85bf23b
Update gem spec with more modern configs.
bryanrite Mar 7, 2014
0ca3c4a
Fix whitespace.
bryanrite Mar 7, 2014
9d43556
Remove guard as it doesn't play nice with Appraisal or ruby < 1.9.3
bryanrite Mar 7, 2014
c929181
Move supermodel requirement to gem spec.
bryanrite Mar 7, 2014
e379873
A require is needed here.
bryanrite Mar 7, 2014
c25e004
Remove old rake task.
bryanrite Mar 7, 2014
853dde9
Conditionally include bson_ext for mongoid build.
bryanrite Mar 7, 2014
16f13a9
Guard adapter specific logic until it can be extracted.
bryanrite Mar 7, 2014
110d868
Update READMEs with new testing info.
bryanrite Mar 9, 2014
d3527ab
Grammar fix.
bryanrite Mar 9, 2014
32d6de4
Make sure all links to the documentation in the README have been upda…
kevintuhumury Mar 14, 2014
b30b125
Fix #951
hitendrasingh Oct 25, 2013
11867bf
Rails 4 fix for #951
thejchap Feb 8, 2014
bed84f7
Add a change log entry for fix.
bryanrite Mar 14, 2014
ae35c2a
Fixed a couple of gem name references.
Mar 14, 2014
24975fc
Merge pull request #22 from maxshelley/develop
bryanrite Mar 15, 2014
f28ddcc
Merge commit '32d6de4af1914d7ba179e69903c33df2dc3aa830' into develop
bryanrite Mar 15, 2014
504dc62
Require RSpec Expectations
bryanrite Mar 15, 2014
afe32a2
Include core as well, just in case.
bryanrite Mar 15, 2014
c8ac15e
Update documentation.
bryanrite Mar 15, 2014
418cf1d
Require files, test_files, and executes in a more modern way.
bryanrite Mar 15, 2014
0ada2b4
Merge pull request #23 from CanCanCommunity/feature/fix_rspec
bryanrite Mar 19, 2014
517f9de
Bump version to 1.7.1
bryanrite Mar 19, 2014
c9afa64
Merge branch 'release/1.7.1'
bryanrite Mar 19, 2014
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
.DS_Store
.idea/*
*.swp
**/*.swp
*.gem
Gemfile.lock
.bundle

gemfiles/*.lock
Gemfile.lock

.rvmrc
.rbenv-version
.ruby-version
.ruby-gemset
/tmp
1 change: 0 additions & 1 deletion .ruby-version

This file was deleted.

7 changes: 6 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ rvm:
- ree
- jruby
- rbx
gemfile:
- gemfiles/rails_3.0.gemfile
- gemfiles/rails_3.0_datamapper.gemfile
- gemfiles/rails_3.0_mongoid.gemfile
services:
- mongodb
matrix:
allow_failures:
- rvm: rbx
notifications:
recipients:
- bryan@bryanrite.com
- ryan@railscasts.com
28 changes: 28 additions & 0 deletions Appraisals
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
appraise "rails_3.0" do
gem "activerecord", "~> 3.0.20", :require => "active_record"
gem "with_model", "~> 0.2.5"
gem "meta_where"

gemfile.platforms :jruby do
gem "activerecord-jdbcsqlite3-adapter"
gem "jdbc-sqlite3"
end

gemfile.platforms :ruby, :mswin, :mingw do
gem "sqlite3"
end
end

appraise "rails_3.0_datamapper" do
gem "dm-core", "~> 1.0.2"
gem "dm-sqlite-adapter", "~> 1.0.2"
gem "dm-migrations", "~> 1.0.2"
end

appraise "rails_3.0_mongoid" do
gem "mongoid", "~> 2.0.0"

gemfile.platforms :ruby, :mswin, :mingw do
gem "bson_ext", "~> 1.1"
end
end
7 changes: 7 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Master


1.7.1 (March 19th, 2014)

* Fix ryanb/cancan#992 - Remove Rails 4 deprecations for scoped (thejchap & hitendrasingh)

* Fix cancancan#16 - RSpec expectations are not explicitly required in RSpec > 2.13 (justinaiken & bryanrite)


1.7.0 (February 19th, 2014)

* Feature #988 Adds support for strong_parameters (bryanrite)
Expand Down
22 changes: 17 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,23 @@
### Please read before contributing
## Contributing to CanCanCan

1) If you have any questions about CanCan, search the [Wiki](https://github.com/bryanrite/cancancan/wiki) or use [Stack Overflow](http://stackoverflow.com/questions/tagged/cancancan). Do not post questions here.
### Reporting an Issue

2) If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [bryan@bryanrite.com](mailto:bryan@bryanrite.com) instead.
1. If you have any questions about CanCanCan, search the [Wiki](https://github.com/bryanrite/cancancan/wiki), use [Stack Overflow](http://stackoverflow.com/questions/tagged/cancancan), or [our mailing list](https://groups.google.com/forum/#!forum/cancancan). Do not post questions here.

3) Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed. In case it was not, create your report including Rails and CanCan versions. If you are getting exceptions, please include the full backtrace.
1. If you find a security bug, **DO NOT** submit an issue here. Please send an e-mail to [bryan@bryanrite.com](mailto:bryan@bryanrite.com) instead.

That's it! The more information you give, the more easy it becomes for us to track it down and fix it. Ideal scenario would be adding the issue to CanCan test suite or to a sample application.
1. Do a small search on the issues tracker before submitting your issue to see if it was already reported / fixed.

1. Create your report including Rails and CanCanCan versions. If you are getting exceptions, please include the full backtrace.

That's it! The more information you give, the more easy it becomes for us to track it down and fix it. Ideal scenario would be adding the issue to CanCanCan test suite or to a sample application.

### Adding new Features or Bugfixes

CanCanCan uses a [git-flow](http://nvie.com/posts/a-successful-git-branching-model/) development model. The latest "released" version of CanCanCan, the latest gem version, can always be found on `master`, while the next version or nightly is on `develop`.

Please make sure you have test coverage for anything you add or fix!

Please add a CHANGELOG entry with any relevant tags for issues, pull-requests, and authors.

Thanks!
20 changes: 0 additions & 20 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,3 @@
source "https://rubygems.org"

case ENV["MODEL_ADAPTER"]
when nil, "active_record"
# Sqlite for CRuby, Rubinius, including Windows and RubyInstaller
gem "sqlite3", :platform => [:ruby, :mswin, :mingw]
# Sqlite for JRuby
gem 'activerecord-jdbcsqlite3-adapter', :platform => :jruby
gem "activerecord", '~> 3.0.9', :require => "active_record"
gem "with_model", "~> 0.2.5"
gem "meta_where"
when "data_mapper"
gem "dm-core", "~> 1.0.2"
gem "dm-sqlite-adapter", "~> 1.0.2"
gem "dm-migrations", "~> 1.0.2"
when "mongoid"
gem "bson_ext", "~> 1.1"
gem "mongoid", "~> 2.0.0.beta.20"
else
raise "Unknown model adapter: #{ENV["MODEL_ADAPTER"]}"
end

gemspec
22 changes: 16 additions & 6 deletions README.rdoc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
= CanCanCan
{<img src="https://badge.fury.io/rb/cancancan.png" alt="Gem Version" />}[http://badge.fury.io/rb/cancancan]
{<img src="https://travis-ci.org/bryanrite/cancancan.png" alt="Build Status" />}[https://travis-ci.org/bryanrite/cancancan]
{<img src="https://travis-ci.org/CanCanCommunity/cancancan.png?branch=master" alt="Build Status" />}[https://travis-ci.org/CanCanCommunity/cancancan]
{<img src="https://codeclimate.com/github/bryanrite/cancancan.png?" alt="Code Climate" />}[https://codeclimate.com/github/bryanrite/cancancan]
{<img src="http://inch-pages.github.io/github/CanCanCommunity/cancancan.png" alt="Inline docs" />}[http://inch-pages.github.io/github/CanCanCommunity/cancancan]

Wiki[https://github.com/bryanrite/cancancan/wiki] | RDocs[http://rdoc.info/projects/ryanb/cancan] | Screencast[http://railscasts.com/episodes/192-authorization-with-cancan]

Expand Down Expand Up @@ -34,7 +35,7 @@ Alternatively, you can install it as a plugin.

== Getting Started

CanCan expects a +current_user+ method to exist in the controller. First, set up some authentication (such as Authlogic[https://github.com/binarylogic/authlogic] or Devise[https://github.com/plataformatec/devise]). See {Changing Defaults}[https://github.com/bryanrite/cancan/wiki/changing-defaults] if you need different behavior.
CanCanCan expects a +current_user+ method to exist in the controller. First, set up some authentication (such as Authlogic[https://github.com/binarylogic/authlogic] or Devise[https://github.com/plataformatec/devise]). See {Changing Defaults}[https://github.com/bryanrite/cancancan/wiki/changing-defaults] if you need different behavior.


=== 1. Define Abilities
Expand All @@ -52,7 +53,7 @@ In Rails 2.3, just add a new class in <tt>app/models/ability.rb</tt> with the fo
end
end

See {Defining Abilities}[https://github.com/bryanrite/cancan/wiki/defining-abilities] for details.
See {Defining Abilities}[https://github.com/bryanrite/cancancan/wiki/defining-abilities] for details.


=== 2. Check Abilities & Authorization
Expand Down Expand Up @@ -114,7 +115,7 @@ Additionally, <tt>load_and_authorize_resource</tt> can now take a <tt>param_meth
params.require(:article).permit(:name)
end
end

See {Strong Parameters}[https://github.com/bryanrite/cancancan/wiki/Strong-Parameters] for more information.

=== 3. Handle Unauthorized Access
Expand Down Expand Up @@ -153,9 +154,18 @@ This will raise an exception if authorization is not performed in an action. If

== Questions or Problems?

If you have any issues with CanCan which you cannot find the solution to in the documentation[https://github.com/bryanrite/cancancan/wiki], please add an {issue on GitHub}[https://github.com/bryanrite/cancancan/issues] or fork the project and send a pull request.
If you have any issues with CanCan which you cannot find the solution to in the documentation[https://github.com/bryanrite/cancancan/wiki] or our mailing list: http://groups.google.com/group/cancancan, please add an {issue on GitHub}[https://github.com/bryanrite/cancancan/issues] or fork the project and send a pull request.


== Development

Cancancan uses {appraisals}[https://github.com/thoughtbot/appraisal] to test the code base against multiple versions of rails, as well as the different model adapters.

When first developing, you may need to run <tt>bundle install</tt> and then <tt>appraisal install</tt>, to install the different sets.

You can then run all appraisal files (like CI does), with <tt>appraisal rake</tt> or just run a specific set <tt>appraisal rails_3.0 rake</tt>.

To get the specs running you should call +bundle+ and then +rake+. See the {spec/README}[https://github.com/bryanrite/cancancan/blob/master/spec/README.rdoc] for more information.
See the {CONTRIBUTING}[https://github.com/CanCanCommunity/cancancan/blob/develop/CONTRIBUTING.md] and {spec/README}[https://github.com/bryanrite/cancancan/blob/master/spec/README.rdoc] for more information.


== Special Thanks
Expand Down
8 changes: 0 additions & 8 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,4 @@ RSpec::Core::RakeTask.new do |t|
t.verbose = false
end

desc "Run specs for all adapters"
task :spec_all do
%w[active_record data_mapper mongoid].each do |model_adapter|
puts "MODEL_ADAPTER = #{model_adapter}"
system "rake spec MODEL_ADAPTER=#{model_adapter}"
end
end

task :default => :spec
16 changes: 10 additions & 6 deletions cancancan.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ Gem::Specification.new do |s|
s.version = CanCan::VERSION
s.authors = ["Bryan Rite", "Ryan Bates"]
s.email = "bryan@bryanrite.com"
s.homepage = "http://github.com/bryanrite/cancancan"
s.homepage = "https://github.com/CanCanCommunity/cancancan"
s.summary = "Simple authorization solution for Rails."
s.description = "Continuation of the simple authorization solution for Rails which is decoupled from user roles. All permissions are stored in a single location."
s.platform = Gem::Platform::RUBY
s.license = "MIT"

s.files = Dir["{lib,spec}/**/*", "[A-Z]*", "init.rb"] - ["Gemfile.lock"]
s.require_path = "lib"
s.files = `git ls-files`.split($/)
s.test_files = `git ls-files -- Appraisals {spec,features,gemfiles}/*`.split($/)
s.executables = `git ls-files -- bin/*`.split($/).map{ |f| File.basename(f) }
s.require_paths = ["lib"]

s.required_ruby_version = Gem::Requirement.new(">= 1.8.7")
s.required_rubygems_version = ">= 1.3.4"

s.add_development_dependency 'rspec', '~> 2.14'
s.add_development_dependency 'rails', '~> 3.0.9'
s.add_development_dependency 'supermodel', '~> 0.1.4'
s.add_development_dependency 'supermodel', '~> 0.1.6'
s.add_development_dependency 'appraisal', '>= 1.0.0.beta3'

s.rubyforge_project = s.name
s.required_rubygems_version = ">= 1.3.4"
end
18 changes: 18 additions & 0 deletions gemfiles/rails_3.0.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "activerecord", "~> 3.0.20", :require=>"active_record"
gem "with_model", "~> 0.2.5"
gem "meta_where"

platforms :jruby do
gem "activerecord-jdbcsqlite3-adapter"
gem "jdbc-sqlite3"
end

platforms :ruby, :mswin, :mingw do
gem "sqlite3"
end

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

source "https://rubygems.org"

gem "dm-core", "~> 1.0.2"
gem "dm-sqlite-adapter", "~> 1.0.2"
gem "dm-migrations", "~> 1.0.2"

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

source "https://rubygems.org"

gem "mongoid", "~> 2.0.0"

platforms :ruby, :mswin, :mingw do
gem "bson_ext", "~> 1.1"
end

gemspec :path=>".././"
8 changes: 8 additions & 0 deletions lib/cancan/matchers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
rspec_module = defined?(RSpec::Core) ? 'RSpec' : 'Spec' # for RSpec 1 compatability

if rspec_module == 'RSpec'
require 'rspec/core'
require 'rspec/expectations'
else
ActiveSupport::Deprecation.warn("RSpec v1 will not be supported in the CanCanCan >= 2.0.0")
end

Kernel.const_get(rspec_module)::Matchers.define :be_able_to do |*args|
match do |ability|
ability.can?(*args)
Expand Down
4 changes: 2 additions & 2 deletions lib/cancan/model_adapters/active_record_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def joins

def database_records
if override_scope
@model_class.scoped.merge(override_scope)
@model_class.where(nil).merge(override_scope)
elsif @model_class.respond_to?(:where) && @model_class.respond_to?(:joins)
mergeable_conditions = @rules.select {|rule| rule.unmergeable? }.blank?
if mergeable_conditions
Expand All @@ -106,7 +106,7 @@ def database_records
@model_class.where(*(@rules.map(&:conditions))).includes(joins)
end
else
@model_class.scoped(:conditions => conditions, :joins => joins)
@model_class.all(:conditions => conditions, :joins => joins)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/cancan/rule.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def matches_conditions_hash?(subject, conditions = @conditions)
else
attribute = subject.send(name)
if value.kind_of?(Hash)
if attribute.kind_of?(Array) || attribute.kind_of?(ActiveRecord::Relation)
if attribute.kind_of?(Array) || (defined?(ActiveRecord) && attribute.kind_of?(ActiveRecord::Relation))
attribute.any? { |element| matches_conditions_hash? element, value }
else
!attribute.nil? && matches_conditions_hash?(attribute, value)
Expand Down
2 changes: 1 addition & 1 deletion lib/cancan/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CanCan
VERSION = "1.7.0"
VERSION = "1.7.1"
end
23 changes: 11 additions & 12 deletions spec/README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,23 @@
To run the specs first run the +bundle+ command to install the necessary gems and the +rake+ command to run the specs.

bundle
rake

The specs currently require Ruby 1.8.7. Ruby 1.9.2 support will be coming soon.
Then run the appraisal command to install all the necssary test sets:

appraisal install

== Model Adapters
You can then run all test sets:

appraisal rake

CanCan offers separate specs for different model adapters (such as Mongoid and Data Mapper). By default it will use Active Record but you can change this by setting the +MODEL_ADAPTER+ environment variable before running. You can run the +bundle+ command with this as well to ensure you have the installed gems.
Or individual ones:

MODEL_ADAPTER=data_mapper bundle
MODEL_ADAPTER=data_mapper rake
appraisal rails_3.0 rake

The different model adapters you can specify are:
A list of the tests is in the +Appraisal+ file.

* active_record (default)
* data_mapper
* mongoid
The specs support Ruby 1.8.7+

You can also run the +spec_all+ rake task to run specs for each adapter.
== Model Adapters

rake spec_all
The model adapter ENV setting has been removed and replaced with the +Appraisal+ file.
9 changes: 7 additions & 2 deletions spec/cancan/model_adapters/active_record_adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
if ENV["MODEL_ADAPTER"].nil? || ENV["MODEL_ADAPTER"] == "active_record"
require "spec_helper"
require "spec_helper"

if defined? CanCan::ModelAdapters::ActiveRecordAdapter

RSpec.configure do |config|
config.extend WithModel
end

ActiveRecord::Base.establish_connection(:adapter => "sqlite3", :database => ":memory:")

Expand Down
5 changes: 3 additions & 2 deletions spec/cancan/model_adapters/data_mapper_adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if ENV["MODEL_ADAPTER"] == "data_mapper"
require "spec_helper"
require "spec_helper"

if defined? CanCan::ModelAdapters::DataMapperAdapter

DataMapper.setup(:default, 'sqlite::memory:')

Expand Down
5 changes: 3 additions & 2 deletions spec/cancan/model_adapters/mongoid_adapter_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
if ENV["MODEL_ADAPTER"] == "mongoid"
require "spec_helper"
require "spec_helper"

if defined? CanCan::ModelAdapters::MongoidAdapter

class MongoidCategory
include Mongoid::Document
Expand Down
Loading