Skip to content

Commit

Permalink
Merge branch 'develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
coorasse committed Nov 22, 2017
2 parents bab2335 + 0826146 commit f4ea6ce
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 716 deletions.
2 changes: 1 addition & 1 deletion Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ appraise 'activerecord_4.2' do
gem 'nokogiri', '~> 1.6.8', require: 'nokogiri' # TODO: fix for ruby 2.0.0

gemfile.platforms :jruby do
gem 'activerecord-jdbcsqlite3-adapter'
gem 'activerecord-jdbcsqlite3-adapter', '~> 1.3.24'
gem 'jdbc-sqlite3'
end

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ Unreleased

* Removed support for dynamic finders (coorasse)

2.1.2 (Nov 22th, 2017)

* Various bugfixes on version 2.1.0

2.1.0 (Nov 10th, 2017)

* Adds support for Rails Api applications (coorasse & ajgon)
Expand Down
2 changes: 1 addition & 1 deletion gemfiles/activerecord_4.2.gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ gem "actionpack", "~> 4.2.0", require: "action_pack"
gem "nokogiri", "~> 1.6.8", require: "nokogiri"

platforms :jruby do
gem "activerecord-jdbcsqlite3-adapter"
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24"
gem "jdbc-sqlite3"
end

Expand Down
15 changes: 10 additions & 5 deletions lib/cancan/controller_resource_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@ def find_resource
end

def find_resource_using_find_by
if resource_base.respond_to? 'find_by'
resource_base.send('find_by', @options[:find_by].to_sym => id_param)
else
resource_base.send(@options[:find_by], id_param)
end
find_by_dynamic_finder || find_by_find_by_finder || resource_base.send(@options[:find_by], id_param)
end

def find_by_dynamic_finder
method_name = "find_by_#{@options[:find_by]}!"
resource_base.send(method_name, id_param) if resource_base.respond_to? method_name
end

def find_by_find_by_finder
resource_base.find_by(@options[:find_by].to_sym => id_param) if resource_base.respond_to? :find_by
end

def id_param
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 = '2.1.1'.freeze
VERSION = '2.1.2'.freeze
end
9 changes: 9 additions & 0 deletions spec/cancan/controller_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ class Model < ::Model; end
expect(controller.instance_variable_get(:@model)).to eq(model)
end

it 'loads resource using dynamic finder method' do
model = Model.new
allow(Model).to receive(:find_by_name!).with('foo') { model }
params.merge!(action: 'show', id: 'foo')
resource = CanCan::ControllerResource.new(controller, find_by: :name)
resource.load_resource
expect(controller.instance_variable_get(:@model)).to eq(model)
end

it 'allows full find method to be passed into find_by option' do
model = Model.new
allow(Model).to receive(:find_by_name).with('foo') { model }
Expand Down
Loading

0 comments on commit f4ea6ce

Please sign in to comment.