From 3dfa56ccfbdcaeba74273ace80cb752e6b716f87 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sun, 26 Jun 2005 11:25:32 +0000 Subject: Updated all references to the old find_first and find_all to use the new style #1511 [Marcel Molina] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1520 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- activerecord/lib/active_record/acts/list.rb | 9 ++--- activerecord/lib/active_record/acts/nested_set.rb | 8 ++-- activerecord/lib/active_record/associations.rb | 2 +- activerecord/lib/active_record/base.rb | 14 +++---- activerecord/lib/active_record/callbacks.rb | 2 +- activerecord/lib/active_record/fixtures.rb | 6 +-- activerecord/lib/active_record/validations.rb | 4 +- activerecord/test/associations_test.rb | 48 +++++++++++------------ activerecord/test/base_test.rb | 10 ++--- activerecord/test/finder_test.rb | 2 +- activerecord/test/inheritance_test.rb | 34 ++++++++-------- activerecord/test/migration_mysql.rb | 12 +++--- activerecord/test/mixin_nested_set_test.rb | 2 +- activerecord/test/mixin_test.rb | 22 +++++------ activerecord/test/modules_test.rb | 6 +-- 15 files changed, 89 insertions(+), 92 deletions(-) diff --git a/activerecord/lib/active_record/acts/list.rb b/activerecord/lib/active_record/acts/list.rb index eb3993a92b..6c908c88a4 100644 --- a/activerecord/lib/active_record/acts/list.rb +++ b/activerecord/lib/active_record/acts/list.rb @@ -135,14 +135,14 @@ module ActiveRecord def higher_item return nil unless in_list? - self.class.find_first( + self.class.find(:first, :conditions => "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i - 1).to_s}" ) end def lower_item return nil unless in_list? - self.class.find_first( + self.class.find(:first, :conditions => "#{scope_condition} AND #{position_column} = #{(send(position_column).to_i + 1).to_s}" ) end @@ -169,10 +169,7 @@ module ActiveRecord end def bottom_item - self.class.find_first( - "#{scope_condition} ", - "#{position_column} DESC" - ) + self.class.find(:first, :conditions => scope_condition, :order => "#{position_column} DESC") end def assume_bottom_position diff --git a/activerecord/lib/active_record/acts/nested_set.rb b/activerecord/lib/active_record/acts/nested_set.rb index 0202ac65b4..cc120cad4b 100644 --- a/activerecord/lib/active_record/acts/nested_set.rb +++ b/activerecord/lib/active_record/acts/nested_set.rb @@ -181,17 +181,17 @@ module ActiveRecord # Returns a set of itself and all of it's nested children def full_set - self.class.find_all( "#{scope_condition} AND (#{left_col_name} BETWEEN #{self[left_col_name]} and #{self[right_col_name]})" ) + self.class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} BETWEEN #{self[left_col_name]} and #{self[right_col_name]})" ) end # Returns a set of all of it's children and nested children def all_children - self.class.find_all( "#{scope_condition} AND (#{left_col_name} > #{self[left_col_name]}) and (#{right_col_name} < #{self[right_col_name]})" ) + self.class.find(:all, :conditions => "#{scope_condition} AND (#{left_col_name} > #{self[left_col_name]}) and (#{right_col_name} < #{self[right_col_name]})" ) end # Returns a set of only this entries immediate children def direct_children - self.class.find_all( "#{scope_condition} and #{parent_column} = #{self.id}") + self.class.find(:all, :conditions => "#{scope_condition} and #{parent_column} = #{self.id}") end # Prunes a branch off of the tree, shifting all of the elements on the right @@ -209,4 +209,4 @@ module ActiveRecord end end end -end \ No newline at end of file +end diff --git a/activerecord/lib/active_record/associations.rb b/activerecord/lib/active_record/associations.rb index 9dba33dfd9..d82d58b94c 100755 --- a/activerecord/lib/active_record/associations.rb +++ b/activerecord/lib/active_record/associations.rb @@ -304,7 +304,7 @@ module ActiveRecord # with +attributes+ and linked to this object through a foreign key and that has already been saved (if it passed the validation). # # Example: An Account class declares has_one :beneficiary, which will add: - # * Account#beneficiary (similar to Beneficiary.find_first "account_id = #{id}") + # * Account#beneficiary (similar to Beneficiary.find(:first, :conditions => "account_id = #{id}")) # * Account#beneficiary=(beneficiary) (similar to beneficiary.account_id = account.id; beneficiary.save) # * Account#beneficiary.nil? # * Account#build_beneficiary (similar to Beneficiary.new("account_id" => id)) diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 5535f224c8..7e2acb5acf 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -79,11 +79,11 @@ module ActiveRecord #:nodoc: # # User < ActiveRecord::Base # def self.authenticate_unsafely(user_name, password) - # find_first("user_name = '#{user_name}' AND password = '#{password}'") + # find(:first, :conditions => "user_name = '#{user_name}' AND password = '#{password}'") # end # # def self.authenticate_safely(user_name, password) - # find_first([ "user_name = ? AND password = ?", user_name, password ]) + # find(:first, :conditions => [ "user_name = ? AND password = ?", user_name, password ]) # end # end # @@ -362,7 +362,7 @@ module ActiveRecord #:nodoc: end end - # Works like find_all, but requires a complete SQL string. Examples: + # Works like find(:all), but requires a complete SQL string. Examples: # Post.find_by_sql "SELECT p.*, c.author FROM posts p, comments c WHERE p.id = c.post_id" # Post.find_by_sql ["SELECT * FROM posts WHERE author = ? AND created > ?", author_id, start_date] def find_by_sql(sql) @@ -426,7 +426,7 @@ module ActiveRecord #:nodoc: # the destroy method. Example: # Person.destroy_all "last_login < '2004-04-04'" def destroy_all(conditions = nil) - find_all(conditions).each { |object| object.destroy } + find(:all, :conditions => conditions).each { |object| object.destroy } end # Deletes all the records that matches the +condition+ without instantiating the objects first (and hence not @@ -679,7 +679,7 @@ module ActiveRecord #:nodoc: # Project.benchmark("Creating project") do # project = Project.create("name" => "stuff") # project.create_manager("name" => "David") - # project.milestones << Milestone.find_all + # project.milestones << Milestone.find(:all) # end def benchmark(title) result = nil @@ -777,8 +777,8 @@ module ActiveRecord #:nodoc: end # Enables dynamic finders like find_by_user_name(user_name) and find_by_user_name_and_password(user_name, password) that are turned into - # find_first(["user_name = ?", user_name]) and find_first(["user_name = ? AND password = ?", user_name, password]) respectively. Also works - # for find_all, but using find_all_by_amount(50) that are turned into find_all(["amount = ?", 50]). + # find(:first, :conditions => ["user_name = ?", user_name]) and find(:first, :conditions => ["user_name = ? AND password = ?", user_name, password]) + # respectively. Also works for find(:all), but using find_all_by_amount(50) that are turned into find(:all, :conditions => ["amount = ?", 50]). # # It's even possible to use all the additional parameters to find. For example, the full interface for find_all_by_amount # is actually find_all_by_amount(amount, options). diff --git a/activerecord/lib/active_record/callbacks.rb b/activerecord/lib/active_record/callbacks.rb index 57745b344e..8e95502e56 100755 --- a/activerecord/lib/active_record/callbacks.rb +++ b/activerecord/lib/active_record/callbacks.rb @@ -153,7 +153,7 @@ module ActiveRecord # # == The after_find and after_initialize exceptions # - # Because after_find and after_initialize is called for each object instantiated found by a finder, such as Base.find_all, we've had + # Because after_find and after_initialize is called for each object instantiated found by a finder, such as Base.find(:all), we've had # to implement a simple performance constraint (50% more speed on a simple test case). Unlike all the other callbacks, after_find and # after_initialize will only be run if an explicit implementation is defined (def after_find). In that case, all of the # callback types will be called. diff --git a/activerecord/lib/active_record/fixtures.rb b/activerecord/lib/active_record/fixtures.rb index 3c43ab7636..47928201c7 100755 --- a/activerecord/lib/active_record/fixtures.rb +++ b/activerecord/lib/active_record/fixtures.rb @@ -169,13 +169,13 @@ require 'csv' # fixtures :foos # # def test_godzilla -# assert !Foo.find_all.emtpy? +# assert !Foo.find(:all).empty? # Foo.destroy_all -# assert Foo.find_all.emtpy? +# assert Foo.find(:all).empty? # end # # def test_godzilla_aftermath -# assert !Foo.find_all.emtpy? +# assert !Foo.find(:all).empty? # end # end # diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index e42b306e10..f455b97e0a 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -465,11 +465,11 @@ module ActiveRecord if scope = configuration[:scope] validates_each(attr_names,configuration) do |record, attr_name, value| - record.errors.add(attr_name, configuration[:message]) if record.class.find_first(record.new_record? ? ["#{attr_name} = ? AND #{scope} = ?", record.send(attr_name), record.send(scope)] : ["#{attr_name} = ? AND #{record.class.primary_key} <> ? AND #{scope} = ?", record.send(attr_name), record.send(:id), record.send(scope)]) + record.errors.add(attr_name, configuration[:message]) if record.class.find(:first, :conditions => (record.new_record? ? ["#{attr_name} = ? AND #{scope} = ?", record.send(attr_name), record.send(scope)] : ["#{attr_name} = ? AND #{record.class.primary_key} <> ? AND #{scope} = ?", record.send(attr_name), record.send(:id), record.send(scope)])) end else validates_each(attr_names,configuration) do |record, attr_name, value| - record.errors.add(attr_name, configuration[:message]) if record.class.find_first(record.new_record? ? ["#{attr_name} = ?", record.send(attr_name)] : ["#{attr_name} = ? AND #{record.class.primary_key} <> ?", record.send(attr_name), record.send(:id) ] ) + record.errors.add(attr_name, configuration[:message]) if record.class.find(:first, :conditions => (record.new_record? ? ["#{attr_name} = ?", record.send(attr_name)] : ["#{attr_name} = ? AND #{record.class.primary_key} <> ?", record.send(attr_name), record.send(:id) ] )) end end end diff --git a/activerecord/test/associations_test.rb b/activerecord/test/associations_test.rb index 52dc1a7359..0218f7e6c7 100755 --- a/activerecord/test/associations_test.rb +++ b/activerecord/test/associations_test.rb @@ -126,7 +126,7 @@ class HasOneAssociationsTest < Test::Unit::TestCase firm = Firm.find(1) assert !firm.account.nil? firm.destroy - assert_equal 1, Account.find_all.length + assert_equal 1, Account.count end def test_succesful_build_association @@ -259,45 +259,45 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_counting - assert_equal 2, Firm.find_first.clients.count + assert_equal 2, Firm.find(:first).clients.count end def test_finding - assert_equal 2, Firm.find_first.clients.length + assert_equal 2, Firm.find(:first).clients.length end def test_finding_default_orders - assert_equal "Summit", Firm.find_first.clients.first.name + assert_equal "Summit", Firm.find(:first).clients.first.name end def test_finding_with_different_class_name_and_order - assert_equal "Microsoft", Firm.find_first.clients_sorted_desc.first.name + assert_equal "Microsoft", Firm.find(:first).clients_sorted_desc.first.name end def test_finding_with_foreign_key - assert_equal "Microsoft", Firm.find_first.clients_of_firm.first.name + assert_equal "Microsoft", Firm.find(:first).clients_of_firm.first.name end def test_finding_with_condition - assert_equal "Microsoft", Firm.find_first.clients_like_ms.first.name + assert_equal "Microsoft", Firm.find(:first).clients_like_ms.first.name end def test_finding_using_sql - firm = Firm.find_first + firm = Firm.find(:first) first_client = firm.clients_using_sql.first assert_not_nil first_client assert_equal "Microsoft", first_client.name assert_equal 1, firm.clients_using_sql.size - assert_equal 1, Firm.find_first.clients_using_sql.size + assert_equal 1, Firm.find(:first).clients_using_sql.size end def test_counting_using_sql - assert_equal 1, Firm.find_first.clients_using_counter_sql.size - assert_equal 0, Firm.find_first.clients_using_zero_counter_sql.size + assert_equal 1, Firm.find(:first).clients_using_counter_sql.size + assert_equal 0, Firm.find(:first).clients_using_zero_counter_sql.size end def test_counting_non_existant_items_using_sql - assert_equal 0, Firm.find_first.no_clients_using_counter_sql.size + assert_equal 0, Firm.find(:first).no_clients_using_counter_sql.size end def test_belongs_to_sanity @@ -547,7 +547,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_destroy_dependent_when_deleted_from_association - firm = Firm.find_first + firm = Firm.find(:first) assert_equal 2, firm.clients.size client = firm.clients.first @@ -579,9 +579,9 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_dependence_on_account - assert_equal 2, Account.find_all.length + assert_equal 2, Account.count companies(:first_firm).destroy - assert_equal 1, Account.find_all.length + assert_equal 1, Account.count end def test_included_in_collection @@ -589,7 +589,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_adding_array_and_collection - assert_nothing_raised { Firm.find_first.clients + Firm.find_all.last.clients } + assert_nothing_raised { Firm.find(:first).clients + Firm.find(:all).last.clients } end def test_find_all_without_conditions @@ -598,7 +598,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_replace_with_less - firm = Firm.find_first + firm = Firm.find(:first) firm.clients = [companies(:first_client)] assert firm.save, "Could not save firm" firm.reload @@ -606,7 +606,7 @@ class HasManyAssociationsTest < Test::Unit::TestCase end def test_replace_with_new - firm = Firm.find_first + firm = Firm.find(:first) new_client = Client.new("name" => "New Client") firm.clients = [companies(:second_client),new_client] firm.save @@ -699,7 +699,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase end def test_assignment_before_parent_saved - client = Client.find_first + client = Client.find(:first) apple = Firm.new("name" => "Apple") client.firm = apple assert_equal apple, client.firm @@ -738,7 +738,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase def test_new_record_with_foreign_key_but_no_object c = Client.new("firm_id" => 1) - assert_equal Firm.find_first, c.firm_with_basic_id + assert_equal Firm.find(:first), c.firm_with_basic_id end def test_forgetting_the_load_when_foreign_key_enters_late @@ -746,7 +746,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase assert_nil c.firm_with_basic_id c.firm_id = 1 - assert_equal Firm.find_first, c.firm_with_basic_id + assert_equal Firm.find(:first), c.firm_with_basic_id end def test_field_name_same_as_foreign_key @@ -764,7 +764,7 @@ class BelongsToAssociationsTest < Test::Unit::TestCase apple.companies_count = 2 apple.save - apple = Firm.find_first("name = 'Apple'") + apple = Firm.find(:first, :conditions => "name = 'Apple'") assert_equal 2, apple.clients.size, "Should use the new cached number" apple.clients.to_s @@ -966,7 +966,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase def test_deleting_array david = Developer.find(1) david.projects.reload - david.projects.delete(Project.find_all) + david.projects.delete(Project.find(:all)) assert_equal 0, david.projects.size assert_equal 0, david.projects(true).size end @@ -986,7 +986,7 @@ class HasAndBelongsToManyAssociationsTest < Test::Unit::TestCase active_record.developers.reload assert_equal 2, active_record.developers_by_sql.size - active_record.developers_by_sql.delete(Developer.find_all) + active_record.developers_by_sql.delete(Developer.find(:all)) assert_equal 0, active_record.developers_by_sql(true).size end diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index fa1d621950..b2df346dec 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -110,7 +110,7 @@ class BasicsTest < Test::Unit::TestCase end def test_attributes_hash - assert_equal @loaded_fixtures['projects']['active_record'].to_hash, Project.find_first.attributes + assert_equal @loaded_fixtures['projects']['active_record'].to_hash, Project.find(:first).attributes end def test_create @@ -227,13 +227,13 @@ class BasicsTest < Test::Unit::TestCase end def test_load - topics = Topic.find_all nil, "id" + topics = Topic.find(:all, :order => 'id') assert_equal(2, topics.size) assert_equal(topics(:first).title, topics.first.title) end def test_load_with_condition - topics = Topic.find_all "author_name = 'Mary'" + topics = Topic.find(:all, :conditions => "author_name = 'Mary'") assert_equal(1, topics.size) assert_equal(topics(:second).title, topics.first.title) @@ -276,10 +276,10 @@ class BasicsTest < Test::Unit::TestCase end def test_destroy_all - assert_equal 2, Topic.find_all.size + assert_equal 2, Topic.count Topic.destroy_all "author_name = 'Mary'" - assert_equal 1, Topic.find_all.size + assert_equal 1, Topic.count end def test_destroy_many diff --git a/activerecord/test/finder_test.rb b/activerecord/test/finder_test.rb index 1ac97271eb..12330b6f7c 100644 --- a/activerecord/test/finder_test.rb +++ b/activerecord/test/finder_test.rb @@ -48,7 +48,7 @@ class FinderTest < Test::Unit::TestCase def test_find_all_with_prepared_limit_and_offset if ActiveRecord::ConnectionAdapters.const_defined? :OracleAdapter if ActiveRecord::Base.connection.instance_of?(ActiveRecord::ConnectionAdapters::OracleAdapter) - assert_raises(ArgumentError) { Entrant.find_all nil, "id ASC", [2, 1] } + assert_raises(ArgumentError) { Entrant.find(:all, :order => 'id ASC', :limit => 2, :offset => 1) } end else entrants = Entrant.find(:all, :order => "id ASC", :limit => 2, :offset => 1) diff --git a/activerecord/test/inheritance_test.rb b/activerecord/test/inheritance_test.rb index d46d0d406b..3ac29b73c8 100755 --- a/activerecord/test/inheritance_test.rb +++ b/activerecord/test/inheritance_test.rb @@ -23,7 +23,7 @@ class InheritanceTest < Test::Unit::TestCase end def test_inheritance_find_all - companies = Company.find_all(nil, "id") + companies = Company.find(:all, :order => 'id') assert companies[0].kind_of?(Firm), "37signals should be a firm" assert companies[1].kind_of?(Client), "Summit should be a client" end @@ -48,9 +48,9 @@ class InheritanceTest < Test::Unit::TestCase end def test_inheritance_condition - assert_equal 5, Company.find_all.length - assert_equal 2, Firm.find_all.length - assert_equal 3, Client.find_all.length + assert_equal 5, Company.count + assert_equal 2, Firm.count + assert_equal 3, Client.count end def test_alt_inheritance_condition @@ -70,8 +70,8 @@ class InheritanceTest < Test::Unit::TestCase def test_update_all_within_inheritance Client.update_all "name = 'I am a client'" - assert_equal "I am a client", Client.find_all.first.name - assert_equal "37signals", Firm.find_all.first.name + assert_equal "I am a client", Client.find(:all).first.name + assert_equal "37signals", Firm.find(:all).first.name end def test_alt_update_all_within_inheritance @@ -81,8 +81,8 @@ class InheritanceTest < Test::Unit::TestCase def test_destroy_all_within_inheritance Client.destroy_all - assert_equal 0, Client.find_all.length - assert_equal 2, Firm.find_all.length + assert_equal 0, Client.count + assert_equal 2, Firm.count end def test_alt_destroy_all_within_inheritance @@ -91,9 +91,9 @@ class InheritanceTest < Test::Unit::TestCase end def test_find_first_within_inheritance - assert_kind_of Firm, Company.find_first("name = '37signals'") - assert_kind_of Firm, Firm.find_first("name = '37signals'") - assert_nil Client.find_first("name = '37signals'") + assert_kind_of Firm, Company.find(:first, :conditions => "name = '37signals'") + assert_kind_of Firm, Firm.find(:first, :conditions => "name = '37signals'") + assert_nil Client.find(:first, :conditions => "name = '37signals'") end def test_alt_find_first_within_inheritance @@ -103,11 +103,11 @@ class InheritanceTest < Test::Unit::TestCase def test_complex_inheritance very_special_client = VerySpecialClient.create("name" => "veryspecial") - assert_equal very_special_client, VerySpecialClient.find_first("name = 'veryspecial'") - assert_equal very_special_client, SpecialClient.find_first("name = 'veryspecial'") - assert_equal very_special_client, Company.find_first("name = 'veryspecial'") - assert_equal very_special_client, Client.find_first("name = 'veryspecial'") - assert_equal 1, Client.find_all("name = 'Summit'").size + assert_equal very_special_client, VerySpecialClient.find(:first, :conditions => "name = 'veryspecial'") + assert_equal very_special_client, SpecialClient.find(:first, :conditions => "name = 'veryspecial'") + assert_equal very_special_client, Company.find(:first, :conditions => "name = 'veryspecial'") + assert_equal very_special_client, Client.find(:first, :conditions => "name = 'veryspecial'") + assert_equal 1, Client.find(:all, :conditions => "name = 'Summit'").size assert_equal very_special_client, Client.find(very_special_client.id) end @@ -125,7 +125,7 @@ class InheritanceTest < Test::Unit::TestCase private def switch_to_alt_inheritance_column # we don't want misleading test results, so get rid of the values in the type column - Company.find_all(nil, "id").each do |c| + Company.find(:all, :order => 'id').each do |c| c['type'] = nil c.save end diff --git a/activerecord/test/migration_mysql.rb b/activerecord/test/migration_mysql.rb index 7777bb2c03..6761d76ca1 100644 --- a/activerecord/test/migration_mysql.rb +++ b/activerecord/test/migration_mysql.rb @@ -40,10 +40,10 @@ class MigrationTest < Test::Unit::TestCase WeNeedReminders.up assert Reminder.create("content" => "hello world", "remind_at" => Time.now) - assert "hello world", Reminder.find_first + assert "hello world", Reminder.find(:first) WeNeedReminders.down - assert_raises(ActiveRecord::StatementInvalid) { Reminder.find_first } + assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) } end def test_migrator @@ -56,7 +56,7 @@ class MigrationTest < Test::Unit::TestCase Person.reset_column_information assert Person.column_methods_hash.include?(:last_name) assert Reminder.create("content" => "hello world", "remind_at" => Time.now) - assert "hello world", Reminder.find_first + assert "hello world", Reminder.find(:first) ActiveRecord::Migrator.down(File.dirname(__FILE__) + '/fixtures/migrations/') @@ -64,7 +64,7 @@ class MigrationTest < Test::Unit::TestCase assert_equal 0, ActiveRecord::Migrator.current_version Person.reset_column_information assert !Person.column_methods_hash.include?(:last_name) - assert_raises(ActiveRecord::StatementInvalid) { Reminder.find_first } + assert_raises(ActiveRecord::StatementInvalid) { Reminder.find(:first) } end def test_migrator_one_up @@ -81,7 +81,7 @@ class MigrationTest < Test::Unit::TestCase ActiveRecord::Migrator.up(File.dirname(__FILE__) + '/fixtures/migrations/', 2) assert Reminder.create("content" => "hello world", "remind_at" => Time.now) - assert "hello world", Reminder.find_first + assert "hello world", Reminder.find(:first) end def test_migrator_one_down @@ -101,4 +101,4 @@ class MigrationTest < Test::Unit::TestCase assert !Person.column_methods_hash.include?(:last_name) assert_raises(ActiveRecord::StatementInvalid) { Reminder.column_methods_hash } end -end \ No newline at end of file +end diff --git a/activerecord/test/mixin_nested_set_test.rb b/activerecord/test/mixin_nested_set_test.rb index f51926afbc..c52dabd6b9 100644 --- a/activerecord/test/mixin_nested_set_test.rb +++ b/activerecord/test/mixin_nested_set_test.rb @@ -143,7 +143,7 @@ class MixinNestedSetTest < Test::Unit::TestCase def test_deleting_root NestedSetWithStringScope.find(4001).destroy - assert( NestedSetWithStringScope.find_all.length == 0 ) + assert( NestedSetWithStringScope.count == 0 ) end def test_common_usage diff --git a/activerecord/test/mixin_test.rb b/activerecord/test/mixin_test.rb index bb6f9912a7..96e6f7442f 100644 --- a/activerecord/test/mixin_test.rb +++ b/activerecord/test/mixin_test.rb @@ -13,7 +13,7 @@ class ListTest < Test::Unit::TestCase mixins(:list_2), mixins(:list_3), mixins(:list_4)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') mixins(:list_2).move_lower @@ -21,7 +21,7 @@ class ListTest < Test::Unit::TestCase mixins(:list_3), mixins(:list_2), mixins(:list_4)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') mixins(:list_2).move_higher @@ -29,7 +29,7 @@ class ListTest < Test::Unit::TestCase mixins(:list_2), mixins(:list_3), mixins(:list_4)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') mixins(:list_1).move_to_bottom @@ -37,7 +37,7 @@ class ListTest < Test::Unit::TestCase mixins(:list_3), mixins(:list_4), mixins(:list_1)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') mixins(:list_1).move_to_top @@ -45,7 +45,7 @@ class ListTest < Test::Unit::TestCase mixins(:list_2), mixins(:list_3), mixins(:list_4)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') mixins(:list_2).move_to_bottom @@ -54,7 +54,7 @@ class ListTest < Test::Unit::TestCase mixins(:list_3), mixins(:list_4), mixins(:list_2)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') mixins(:list_4).move_to_top @@ -62,7 +62,7 @@ class ListTest < Test::Unit::TestCase mixins(:list_1), mixins(:list_3), mixins(:list_2)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') end @@ -134,14 +134,14 @@ class ListTest < Test::Unit::TestCase mixins(:list_2), mixins(:list_3), mixins(:list_4)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') mixins(:list_2).destroy assert_equal [mixins(:list_1, :reload), mixins(:list_3, :reload), mixins(:list_4, :reload)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') assert_equal 1, mixins(:list_1).pos assert_equal 2, mixins(:list_3).pos @@ -151,7 +151,7 @@ class ListTest < Test::Unit::TestCase assert_equal [mixins(:list_3, :reload), mixins(:list_4, :reload)], - ListMixin.find_all("parent_id=5", "pos") + ListMixin.find(:all, :conditions => 'parent_id = 5', :order => 'pos') assert_equal 1, mixins(:list_3).pos assert_equal 2, mixins(:list_4).pos @@ -168,7 +168,7 @@ class ListTest < Test::Unit::TestCase def test_nil_scope new1, new2, new3 = ListMixin.create, ListMixin.create, ListMixin.create new2.move_higher - assert_equal [new2, new1, new3], ListMixin.find_all("parent_id IS NULL", "pos") + assert_equal [new2, new1, new3], ListMixin.find(:all, :conditions => 'parent_id IS NULL', :order => 'pos') end end diff --git a/activerecord/test/modules_test.rb b/activerecord/test/modules_test.rb index f13d140b6d..d34afbb8f8 100644 --- a/activerecord/test/modules_test.rb +++ b/activerecord/test/modules_test.rb @@ -5,14 +5,14 @@ class ModulesTest < Test::Unit::TestCase fixtures :accounts, :companies, :projects, :developers def test_module_spanning_associations - assert MyApplication::Business::Firm.find_first.has_clients?, "Firm should have clients" - firm = MyApplication::Business::Firm.find_first + assert MyApplication::Business::Firm.find(:first).has_clients?, "Firm should have clients" + firm = MyApplication::Business::Firm.find(:first) assert_nil firm.class.table_name.match('::'), "Firm shouldn't have the module appear in its table name" assert_equal 2, firm.clients_count, "Firm should have two clients" end def test_module_spanning_has_and_belongs_to_many_associations - project = MyApplication::Business::Project.find_first + project = MyApplication::Business::Project.find(:first) project.developers << MyApplication::Business::Developer.create("name" => "John") assert "John", project.developers.last.name end -- cgit v1.2.3