Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Raise an exception when invalid options are passed to ActiveRecord::B…

…ase.find. Closes #2363.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@2481 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit e8b427cdefd9ec851e2853d4bf21dd8fd676096d 1 parent bcb50f3
Marcel Molina authored
2  activerecord/CHANGELOG
View
@@ -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]
8 activerecord/lib/active_record/base.rb
View
@@ -975,7 +975,13 @@ def raise_if_bind_arity_mismatch(statement, expected, provided)
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)
3  activerecord/test/conditions_scoping_test.rb
View
@@ -28,7 +28,6 @@ def test_scoped_find_first
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 @@ def test_forwarding_to_dynamic_finders
end
-=end
+=end
5 activerecord/test/finder_test.rb
View
@@ -276,6 +276,11 @@ def test_find_with_bad_sql
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
Please sign in to comment.
Something went wrong with that request. Please try again.