Skip to content

Commit

Permalink
Fix find_by_last when order is given [#2127 state:committed]
Browse files Browse the repository at this point in the history
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
  • Loading branch information
DefV authored and dhh committed Mar 9, 2009
1 parent 9442d84 commit 277c799
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -2174,7 +2174,7 @@ def default_scope(options = {})
# Test whether the given method and optional key are scoped.
def scoped?(method, key = nil) #:nodoc:
if current_scoped_methods && (scope = current_scoped_methods[method])
!key || scope.has_key?(key)
!key || !scope[key].nil?
end
end

Expand Down
Expand Up @@ -70,6 +70,10 @@ def test_find_many_with_merged_options
assert_equal 2, companies(:first_firm).limited_clients.find(:all, :limit => nil).size
end

def test_dynamic_find_last_without_specified_order
assert_equal companies(:second_client), companies(:first_firm).unsorted_clients.find_last_by_type('Client')
end

def test_dynamic_find_should_respect_association_order
assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.find(:first, :conditions => "type = 'Client'")
assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.find_by_type('Client')
Expand Down
4 changes: 2 additions & 2 deletions activerecord/test/cases/reflection_test.rb
Expand Up @@ -170,8 +170,8 @@ def test_association_reflection_in_modules

def test_reflection_of_all_associations
# FIXME these assertions bust a lot
assert_equal 27, Firm.reflect_on_all_associations.size
assert_equal 20, Firm.reflect_on_all_associations(:has_many).size
assert_equal 28, Firm.reflect_on_all_associations.size
assert_equal 21, Firm.reflect_on_all_associations(:has_many).size
assert_equal 7, Firm.reflect_on_all_associations(:has_one).size
assert_equal 0, Firm.reflect_on_all_associations(:belongs_to).size
end
Expand Down
1 change: 1 addition & 0 deletions activerecord/test/models/company.rb
Expand Up @@ -37,6 +37,7 @@ class Firm < Company
has_many :clients, :order => "id", :dependent => :destroy, :counter_sql =>
"SELECT COUNT(*) FROM companies WHERE firm_id = 1 " +
"AND (#{QUOTED_TYPE} = 'Client' OR #{QUOTED_TYPE} = 'SpecialClient' OR #{QUOTED_TYPE} = 'VerySpecialClient' )"
has_many :unsorted_clients, :class_name => "Client"
has_many :clients_sorted_desc, :class_name => "Client", :order => "id DESC"
has_many :clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :order => "id"
has_many :unvalidated_clients_of_firm, :foreign_key => "client_of", :class_name => "Client", :validate => false
Expand Down

0 comments on commit 277c799

Please sign in to comment.