mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Raise an exception when invalid options are passed to ActiveRecord::Base.find. Closes #2363.
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2481 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* Raise errors when invalid hash keys are passed to ActiveRecord::Base.find. #2363 [Chad Fowler <chad@chadfowler.com>, Nicholas Seckar]
|
||||
|
||||
* Added :force option to create_table that'll try to drop the table if it already exists before creating
|
||||
|
||||
* Fix transactions so that calling return while inside a transaction will not leave an open transaction on the connection. [Nicholas Seckar]
|
||||
|
||||
@@ -975,7 +975,13 @@ module ActiveRecord #:nodoc:
|
||||
end
|
||||
|
||||
def extract_options_from_args!(args)
|
||||
if args.last.is_a?(Hash) then args.pop else {} end
|
||||
options = args.last.is_a?(Hash) ? args.pop : {}
|
||||
validate_find_options(options)
|
||||
options
|
||||
end
|
||||
|
||||
def validate_find_options(options)
|
||||
options.assert_valid_keys [:conditions, :include, :joins, :limit, :offset, :order, :select]
|
||||
end
|
||||
|
||||
def encode_quoted_value(value)
|
||||
|
||||
@@ -28,7 +28,6 @@ class ConditionsScopingTest < Test::Unit::TestCase
|
||||
def test_scoped_find_all
|
||||
Developer.constrain(:conditions => "name = 'David'") do
|
||||
assert_equal [Developer.find(1)], Developer.find(:all)
|
||||
assert_equal [Developer.find(1)], Developer.find(:all, :condtions => '1 = 2')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -134,4 +133,4 @@ class HasOneScopingTest< Test::Unit::TestCase
|
||||
|
||||
end
|
||||
|
||||
=end
|
||||
=end
|
||||
|
||||
@@ -276,6 +276,11 @@ class FinderTest < Test::Unit::TestCase
|
||||
assert_raises(ActiveRecord::StatementInvalid) { Topic.find_by_sql "select 1 from badtable" }
|
||||
end
|
||||
|
||||
def test_find_with_invalid_params
|
||||
assert_raises(ArgumentError) { Topic.find :first, :join => "It should be `joins'" }
|
||||
assert_raises(ArgumentError) { Topic.find :first, :conditions => '1 = 1', :join => "It should be `joins'" }
|
||||
end
|
||||
|
||||
def test_find_all_with_limit
|
||||
first_five_developers = Developer.find :all, :order => 'id ASC', :limit => 5
|
||||
assert_equal 5, first_five_developers.length
|
||||
|
||||
Reference in New Issue
Block a user