aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test')
-rwxr-xr-xactiverecord/test/associations_test.rb48
-rwxr-xr-xactiverecord/test/base_test.rb10
-rw-r--r--activerecord/test/finder_test.rb2
-rwxr-xr-xactiverecord/test/inheritance_test.rb34
-rw-r--r--activerecord/test/migration_mysql.rb12
-rw-r--r--activerecord/test/mixin_nested_set_test.rb2
-rw-r--r--activerecord/test/mixin_test.rb22
-rw-r--r--activerecord/test/modules_test.rb6
8 files changed, 68 insertions, 68 deletions
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