Skip to content

Commit

Permalink
Fix call to method on nil value for failing unfriendly finds.
Browse files Browse the repository at this point in the history
  • Loading branch information
norman committed Jul 30, 2010
1 parent 81d29e7 commit abb49e1
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ suggestions, ideas and improvements to FriendlyId.
* Table of Contents
{:toc}

## 3.1.1 (2010-07-30)

* Fixed call to method on nil value for failing unfriendly finds (thanks [jlippiner](http://github.com/jlippiner))

## 3.1.0 (2010-07-29)

* Refactored/simplified Active Record 2 and 3 query code.
Expand Down
5 changes: 2 additions & 3 deletions lib/friendly_id/active_record_adapter/finders.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module ActiveRecordAdapter
module Finders

class Find

extend Forwardable
def_delegators :@klass, :scoped, :friendly_id_config, :quoted_table_name, :table_name, :primary_key,
:connection, :name, :sanitize_sql
Expand Down Expand Up @@ -147,15 +146,15 @@ def find_one(id, options)
finder = Find.new(self, id, options)
finder.find_one or super
rescue ActiveRecord::RecordNotFound => error
finder.raise_error(error)
finder ? finder.raise_error(error) : raise(error)
end

def find_some(ids, options)
return super if ids.empty?
finder = Find.new(self, ids, options)
finder.find_some
rescue ActiveRecord::RecordNotFound => error
finder.raise_error(error)
finder ? finder.raise_error(error) : raise(error)
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/friendly_id/test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,12 @@ def assert_validation_error
assert_equal instance, klass.send(find_method, "206")
end

test "failing finds with unfriendly_id should raise errors normally" do
assert_raise ActiveRecord::RecordNotFound do
klass.send(find_method, 0)
end
end

test "creation should raise an error if the friendly_id text is reserved" do
assert_validation_error do
klass.send(create_method, :name => "new")
Expand Down
2 changes: 1 addition & 1 deletion lib/friendly_id/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module FriendlyId
module Version
MAJOR = 3
MINOR = 1
TINY = 0
TINY = 1
BUILD = nil
STRING = [MAJOR, MINOR, TINY, BUILD].compact.join('.')
end
Expand Down
6 changes: 6 additions & 0 deletions test/active_record_adapter/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def validation_exceptions
assert_equal 2, klass.find([instance.friendly_id, second.friendly_id]).size
end

test "failing finds with array of unfriendly_id should raise errors normally" do
assert_raise ActiveRecord::RecordNotFound do
klass.find([0, -1])
end
end

test "instances should be findable by an array of numeric ids" do
second = klass.create!(:name => "second_instance")
third = klass.create!(:name => "third_instance")
Expand Down

0 comments on commit abb49e1

Please sign in to comment.