diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index 3479cc9d81..ad085641fb 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Raise errors when invalid hash keys are passed to ActiveRecord::Base.find. #2363 [Chad Fowler , 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] diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 1c063c003d..8d7a49e46b 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -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) diff --git a/activerecord/test/conditions_scoping_test.rb b/activerecord/test/conditions_scoping_test.rb index 8ff708658c..2f5b28f30f 100644 --- a/activerecord/test/conditions_scoping_test.rb +++ b/activerecord/test/conditions_scoping_test.rb @@ -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 \ No newline at end of file +=end diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index c87fc7f2f2..d40c1272f1 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -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