Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

remove calls to find(:first), find(:last) and find(:all)

  • Loading branch information...
commit 75f03eca753f1e835409a80db1f54f716ef48d18 1 parent b309963
@jonleighton jonleighton authored
Showing with 114 additions and 119 deletions.
  1. +1 −1  activerecord/test/cases/adapters/mysql/schema_test.rb
  2. +1 −1  activerecord/test/cases/adapters/mysql2/schema_test.rb
  3. +1 −1  activerecord/test/cases/associations/belongs_to_associations_test.rb
  4. +2 −2 activerecord/test/cases/associations/eager_test.rb
  5. +8 −8 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
  6. +6 −11 activerecord/test/cases/associations/has_many_associations_test.rb
  7. +3 −3 activerecord/test/cases/associations/has_many_through_associations_test.rb
  8. +2 −2 activerecord/test/cases/associations/has_one_associations_test.rb
  9. +18 −18 activerecord/test/cases/associations/inverse_associations_test.rb
  10. +7 −7 activerecord/test/cases/associations/join_model_test.rb
  11. +1 −1  activerecord/test/cases/attribute_methods_test.rb
  12. +12 −12 activerecord/test/cases/autosave_association_test.rb
  13. +5 −5 activerecord/test/cases/base_test.rb
  14. +1 −1  activerecord/test/cases/finder_test.rb
  15. +1 −1  activerecord/test/cases/fixtures_test.rb
  16. +4 −4 activerecord/test/cases/inheritance_test.rb
  17. +1 −1  activerecord/test/cases/locking_test.rb
  18. +3 −3 activerecord/test/cases/migration/column_attributes_test.rb
  19. +3 −3 activerecord/test/cases/migration/rename_column_test.rb
  20. +8 −8 activerecord/test/cases/migration_test.rb
  21. +4 −4 activerecord/test/cases/modules_test.rb
  22. +11 −11 activerecord/test/cases/named_scope_test.rb
  23. +3 −3 activerecord/test/cases/query_cache_test.rb
  24. +2 −2 activerecord/test/cases/readonly_test.rb
  25. +1 −1  activerecord/test/cases/reflection_test.rb
  26. +4 −4 activerecord/test/cases/relation_scoping_test.rb
  27. +1 −1  activerecord/test/cases/validations/association_validation_test.rb
View
2  activerecord/test/cases/adapters/mysql/schema_test.rb
@@ -20,7 +20,7 @@ def self.name; 'Post'; end
end
def test_schema
- assert @omgpost.find(:first)
+ assert @omgpost.first
end
def test_primary_key
View
2  activerecord/test/cases/adapters/mysql2/schema_test.rb
@@ -20,7 +20,7 @@ def self.name; 'Post'; end
end
def test_schema
- assert @omgpost.find(:first)
+ assert @omgpost.first
end
def test_primary_key
View
2  activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -394,7 +394,7 @@ def test_custom_counter_cache
end
def test_association_assignment_sticks
- post = Post.find(:first)
+ post = Post.first
author1, author2 = Author.find(:all, :limit => 2)
assert_not_nil author1
View
4 activerecord/test/cases/associations/eager_test.rb
@@ -585,7 +585,7 @@ def test_count_eager_with_has_many_and_limit_and_high_offset
end
def test_eager_with_has_many_and_limit_with_no_results
- posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "posts.title = 'magic forest'").find(:all)
+ posts = Post.scoped(:includes => [ :author, :comments ], :limit => 2, :where => "posts.title = 'magic forest'").all
assert_equal 0, posts.size
end
@@ -1036,7 +1036,7 @@ def test_preload_has_many_uses_exclusive_scope
end
def test_preload_has_many_using_primary_key
- expected = Firm.find(:first).clients_using_primary_key.to_a
+ expected = Firm.first.clients_using_primary_key.to_a
firm = Firm.find :first, :include => :clients_using_primary_key
assert_no_queries do
assert_equal expected, firm.clients_using_primary_key
View
16 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -355,7 +355,7 @@ def test_deleting
def test_deleting_array
david = Developer.find(1)
david.projects.reload
- david.projects.delete(Project.find(:all))
+ david.projects.delete(Project.all)
assert_equal 0, david.projects.size
assert_equal 0, david.projects(true).size
end
@@ -375,7 +375,7 @@ def test_deleting_array_with_sql
active_record.developers.reload
assert_equal 3, active_record.developers_by_sql.size
- active_record.developers_by_sql.delete(Developer.find(:all))
+ active_record.developers_by_sql.delete(Developer.all)
assert_equal 0, active_record.developers_by_sql(true).size
end
@@ -548,7 +548,7 @@ def test_find_in_association_with_custom_finder_sql_and_string_id
def test_find_with_merged_options
assert_equal 1, projects(:active_record).limited_developers.size
- assert_equal 1, projects(:active_record).limited_developers.find(:all).size
+ assert_equal 1, projects(:active_record).limited_developers.all.size
assert_equal 3, projects(:active_record).limited_developers.find(:all, :limit => nil).size
end
@@ -632,7 +632,7 @@ def test_replace_on_new_object
end
def test_consider_type
- developer = Developer.find(:first)
+ developer = Developer.first
special_project = SpecialProject.create("name" => "Special Project")
other_project = developer.projects.first
@@ -667,7 +667,7 @@ def test_habtm_respects_select
categories(:technology).select_testing_posts(true).each do |o|
assert_respond_to o, :correctness_marker
end
- assert_respond_to categories(:technology).select_testing_posts.find(:first), :correctness_marker
+ assert_respond_to categories(:technology).select_testing_posts.first, :correctness_marker
end
def test_habtm_selects_all_columns_by_default
@@ -780,8 +780,8 @@ def test_symbols_as_keys
assert_equal 1, project.developers.size
assert_equal 1, developer.projects.size
- assert_equal developer, project.developers.find(:first)
- assert_equal project, developer.projects.find(:first)
+ assert_equal developer, project.developers.first
+ assert_equal project, developer.projects.first
end
def test_self_referential_habtm_without_foreign_key_set_should_raise_exception
@@ -820,7 +820,7 @@ def test_count_with_finder_sql
def test_association_proxy_transaction_method_starts_transaction_in_association_class
Post.expects(:transaction)
- Category.find(:first).posts.transaction do
+ Category.first.posts.transaction do
# nothing
end
end
View
17 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -279,7 +279,7 @@ def test_find_with_blank_conditions
def test_find_many_with_merged_options
assert_equal 1, companies(:first_firm).limited_clients.size
- assert_equal 1, companies(:first_firm).limited_clients.find(:all).size
+ assert_equal 1, companies(:first_firm).limited_clients.all.size
assert_equal 2, companies(:first_firm).limited_clients.find(:all, :limit => nil).size
end
@@ -312,11 +312,6 @@ def test_dynamic_find_all_limit_should_override_association_limit
assert_equal 2, companies(:first_firm).limited_clients.find_all_by_type('Client', :limit => 9_000).length
end
- def test_dynamic_find_all_should_respect_readonly_access
- companies(:first_firm).readonly_clients.find(:all).each { |c| assert_raise(ActiveRecord::ReadOnlyRecord) { c.save! } }
- companies(:first_firm).readonly_clients.find(:all).each { |c| assert c.readonly? }
- end
-
def test_dynamic_find_or_create_from_two_attributes_using_an_association
author = authors(:david)
number_of_posts = Post.count
@@ -1000,14 +995,14 @@ def test_dependent_association_respects_optional_hash_conditions_on_delete
end
def test_delete_all_association_with_primary_key_deletes_correct_records
- firm = Firm.find(:first)
+ firm = Firm.first
# break the vanilla firm_id foreign key
assert_equal 2, firm.clients.count
firm.clients.first.update_column(:firm_id, nil)
assert_equal 1, firm.clients(true).count
assert_equal 1, firm.clients_using_primary_key_with_delete_all.count
old_record = firm.clients_using_primary_key_with_delete_all.first
- firm = Firm.find(:first)
+ firm = Firm.first
firm.destroy
assert_nil Client.find_by_id(old_record.id)
end
@@ -1216,12 +1211,12 @@ def test_included_in_collection
end
def test_adding_array_and_collection
- assert_nothing_raised { Firm.find(:first).clients + Firm.find(:all).last.clients }
+ assert_nothing_raised { Firm.first.clients + Firm.all.last.clients }
end
def test_find_all_without_conditions
firm = companies(:first_firm)
- assert_equal 2, firm.clients.find(:all).length
+ assert_equal 2, firm.clients.all.length
end
def test_replace_with_less
@@ -1561,7 +1556,7 @@ def test_joins_with_namespaced_model_should_use_correct_type
def test_association_proxy_transaction_method_starts_transaction_in_association_class
Comment.expects(:transaction)
- Post.find(:first).comments.transaction do
+ Post.first.comments.transaction do
# nothing
end
end
View
6 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -568,7 +568,7 @@ def test_get_ids_for_unloaded_associations_does_not_load_them
def test_association_proxy_transaction_method_starts_transaction_in_association_class
Tag.expects(:transaction)
- Post.find(:first).tags.transaction do
+ Post.first.tags.transaction do
# nothing
end
end
@@ -651,7 +651,7 @@ def test_collection_singular_ids_getter_with_string_primary_keys
def test_collection_singular_ids_setter
company = companies(:rails_core)
- dev = Developer.find(:first)
+ dev = Developer.first
company.developer_ids = [dev.id]
assert_equal [dev], company.developers
@@ -671,7 +671,7 @@ def test_collection_singular_ids_setter_with_string_primary_keys
def test_collection_singular_ids_setter_raises_exception_when_invalid_ids_set
company = companies(:rails_core)
- ids = [Developer.find(:first).id, -9999]
+ ids = [Developer.first.id, -9999]
assert_raises(ActiveRecord::RecordNotFound) {company.developer_ids= ids}
end
View
4 activerecord/test/cases/associations/has_one_associations_test.rb
@@ -294,13 +294,13 @@ def test_dependence_with_missing_association
def test_dependence_with_missing_association_and_nullify
Account.destroy_all
- firm = DependentFirm.find(:first)
+ firm = DependentFirm.first
assert_nil firm.account
firm.destroy
end
def test_finding_with_interpolated_condition
- firm = Firm.find(:first)
+ firm = Firm.first
superior = firm.clients.create(:name => 'SuperiorCo')
superior.rating = 10
superior.save
View
36 activerecord/test/cases/associations/inverse_associations_test.rb
@@ -114,7 +114,7 @@ def test_parent_instance_should_be_shared_with_eager_loaded_child_on_find
end
def test_parent_instance_should_be_shared_with_newly_built_child
- m = Man.find(:first)
+ m = Man.first
f = m.build_face(:description => 'haunted')
assert_not_nil f.man
assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance"
@@ -125,7 +125,7 @@ def test_parent_instance_should_be_shared_with_newly_built_child
end
def test_parent_instance_should_be_shared_with_newly_created_child
- m = Man.find(:first)
+ m = Man.first
f = m.create_face(:description => 'haunted')
assert_not_nil f.man
assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance"
@@ -136,7 +136,7 @@ def test_parent_instance_should_be_shared_with_newly_created_child
end
def test_parent_instance_should_be_shared_with_newly_created_child_via_bang_method
- m = Man.find(:first)
+ m = Man.first
f = m.create_face!(:description => 'haunted')
assert_not_nil f.man
assert_equal m.name, f.man.name, "Name of man should be the same before changes to parent instance"
@@ -147,7 +147,7 @@ def test_parent_instance_should_be_shared_with_newly_created_child_via_bang_meth
end
def test_parent_instance_should_be_shared_with_replaced_via_accessor_child
- m = Man.find(:first)
+ m = Man.first
f = Face.new(:description => 'haunted')
m.face = f
assert_not_nil f.man
@@ -159,7 +159,7 @@ def test_parent_instance_should_be_shared_with_replaced_via_accessor_child
end
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
- assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).dirty_face }
+ assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.first.dirty_face }
end
end
@@ -201,7 +201,7 @@ def test_parent_instance_should_be_shared_with_eager_loaded_children
end
def test_parent_instance_should_be_shared_with_newly_block_style_built_child
- m = Man.find(:first)
+ m = Man.first
i = m.interests.build {|ii| ii.topic = 'Industrial Revolution Re-enactment'}
assert_not_nil i.topic, "Child attributes supplied to build via blocks should be populated"
assert_not_nil i.man
@@ -213,7 +213,7 @@ def test_parent_instance_should_be_shared_with_newly_block_style_built_child
end
def test_parent_instance_should_be_shared_with_newly_created_via_bang_method_child
- m = Man.find(:first)
+ m = Man.first
i = m.interests.create!(:topic => 'Industrial Revolution Re-enactment')
assert_not_nil i.man
assert_equal m.name, i.man.name, "Name of man should be the same before changes to parent instance"
@@ -224,7 +224,7 @@ def test_parent_instance_should_be_shared_with_newly_created_via_bang_method_chi
end
def test_parent_instance_should_be_shared_with_newly_block_style_created_child
- m = Man.find(:first)
+ m = Man.first
i = m.interests.create {|ii| ii.topic = 'Industrial Revolution Re-enactment'}
assert_not_nil i.topic, "Child attributes supplied to create via blocks should be populated"
assert_not_nil i.man
@@ -248,7 +248,7 @@ def test_parent_instance_should_be_shared_with_poked_in_child
end
def test_parent_instance_should_be_shared_with_replaced_via_accessor_children
- m = Man.find(:first)
+ m = Man.first
i = Interest.new(:topic => 'Industrial Revolution Re-enactment')
m.interests = [i]
assert_not_nil i.man
@@ -260,7 +260,7 @@ def test_parent_instance_should_be_shared_with_replaced_via_accessor_children
end
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
- assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.find(:first).secret_interests }
+ assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Man.first.secret_interests }
end
end
@@ -331,7 +331,7 @@ def test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
end
def test_child_instance_should_be_shared_with_replaced_via_accessor_parent
- f = Face.find(:first)
+ f = Face.first
m = Man.new(:name => 'Charles')
f.man = m
assert_not_nil m.face
@@ -343,7 +343,7 @@ def test_child_instance_should_be_shared_with_replaced_via_accessor_parent
end
def test_trying_to_use_inverses_that_dont_exist_should_raise_an_error
- assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.find(:first).horrible_man }
+ assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.horrible_man }
end
end
@@ -421,19 +421,19 @@ def test_should_not_try_to_set_inverse_instances_when_the_inverse_is_a_has_many
def test_trying_to_access_inverses_that_dont_exist_shouldnt_raise_an_error
# Ideally this would, if only for symmetry's sake with other association types
- assert_nothing_raised(ActiveRecord::InverseOfAssociationNotFoundError) { Face.find(:first).horrible_polymorphic_man }
+ assert_nothing_raised(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.horrible_polymorphic_man }
end
def test_trying_to_set_polymorphic_inverses_that_dont_exist_at_all_should_raise_an_error
# fails because no class has the correct inverse_of for horrible_polymorphic_man
- assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.find(:first).horrible_polymorphic_man = Man.first }
+ assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.horrible_polymorphic_man = Man.first }
end
def test_trying_to_set_polymorphic_inverses_that_dont_exist_on_the_instance_being_set_should_raise_an_error
# passes because Man does have the correct inverse_of
- assert_nothing_raised(ActiveRecord::InverseOfAssociationNotFoundError) { Face.find(:first).polymorphic_man = Man.first }
+ assert_nothing_raised(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.polymorphic_man = Man.first }
# fails because Interest does have the correct inverse_of
- assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.find(:first).polymorphic_man = Interest.first }
+ assert_raise(ActiveRecord::InverseOfAssociationNotFoundError) { Face.first.polymorphic_man = Interest.first }
end
end
@@ -444,7 +444,7 @@ class InverseMultipleHasManyInversesForSameModel < ActiveRecord::TestCase
def test_that_we_can_load_associations_that_have_the_same_reciprocal_name_from_different_models
assert_nothing_raised(ActiveRecord::AssociationTypeMismatch) do
- i = Interest.find(:first)
+ i = Interest.first
i.zine
i.man
end
@@ -452,7 +452,7 @@ def test_that_we_can_load_associations_that_have_the_same_reciprocal_name_from_d
def test_that_we_can_create_associations_that_have_the_same_reciprocal_name_from_different_models
assert_nothing_raised(ActiveRecord::AssociationTypeMismatch) do
- i = Interest.find(:first)
+ i = Interest.first
i.build_zine(:title => 'Get Some in Winter! 2008')
i.build_man(:name => 'Gordon')
i.save!
View
14 activerecord/test/cases/associations/join_model_test.rb
@@ -51,7 +51,7 @@ def test_has_many_uniq_through_count
end
def test_has_many_uniq_through_find
- assert_equal 1, authors(:mary).unique_categorized_posts.find(:all).size
+ assert_equal 1, authors(:mary).unique_categorized_posts.all.size
end
def test_has_many_uniq_through_dynamic_find
@@ -71,7 +71,7 @@ def test_count_polymorphic_has_many
end
def test_polymorphic_has_many_going_through_join_model_with_find
- assert_equal tags(:general), tag = posts(:welcome).tags.find(:first)
+ assert_equal tags(:general), tag = posts(:welcome).tags.first
assert_no_queries do
tag.tagging
end
@@ -85,7 +85,7 @@ def test_polymorphic_has_many_going_through_join_model_with_include_on_source_re
end
def test_polymorphic_has_many_going_through_join_model_with_include_on_source_reflection_with_find
- assert_equal tags(:general), tag = posts(:welcome).funky_tags.find(:first)
+ assert_equal tags(:general), tag = posts(:welcome).funky_tags.first
assert_no_queries do
tag.tagging
end
@@ -280,15 +280,15 @@ def test_include_polymorphic_has_many
end
def test_has_many_find_all
- assert_equal [categories(:general)], authors(:david).categories.find(:all)
+ assert_equal [categories(:general)], authors(:david).categories.all
end
def test_has_many_find_first
- assert_equal categories(:general), authors(:david).categories.find(:first)
+ assert_equal categories(:general), authors(:david).categories.first
end
def test_has_many_with_hash_conditions
- assert_equal categories(:general), authors(:david).categories_like_general.find(:first)
+ assert_equal categories(:general), authors(:david).categories_like_general.first
end
def test_has_many_find_conditions
@@ -444,7 +444,7 @@ def test_add_to_self_referential_has_many_through
end
def test_has_many_through_uses_conditions_specified_on_the_has_many_association
- author = Author.find(:first)
+ author = Author.first
assert_present author.comments
assert_blank author.nonexistant_comments
end
View
2  activerecord/test/cases/attribute_methods_test.rb
@@ -244,7 +244,7 @@ def test_case_sensitive_attributes_hash
# DB2 is not case-sensitive
return true if current_adapter?(:DB2Adapter)
- assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.find(:first).attributes
+ assert_equal @loaded_fixtures['computers']['workstation'].to_hash, Computer.first.attributes
end
def test_hashes_not_mangled
View
24 activerecord/test/cases/autosave_association_test.rb
@@ -87,7 +87,7 @@ def test_should_save_parent_but_not_invalid_child
end
def test_save_fails_for_invalid_has_one
- firm = Firm.find(:first)
+ firm = Firm.first
assert firm.valid?
firm.build_account
@@ -99,7 +99,7 @@ def test_save_fails_for_invalid_has_one
end
def test_save_succeeds_for_invalid_has_one_with_validate_false
- firm = Firm.find(:first)
+ firm = Firm.first
assert firm.valid?
firm.build_unvalidated_account
@@ -159,16 +159,16 @@ def test_not_resaved_when_unchanged
firm.name += '-changed'
assert_queries(1) { firm.save! }
- firm = Firm.find(:first)
- firm.account = Account.find(:first)
+ firm = Firm.first
+ firm.account = Account.first
assert_queries(Firm.partial_updates? ? 0 : 1) { firm.save! }
- firm = Firm.find(:first).dup
- firm.account = Account.find(:first)
+ firm = Firm.first.dup
+ firm.account = Account.first
assert_queries(2) { firm.save! }
- firm = Firm.find(:first).dup
- firm.account = Account.find(:first).dup
+ firm = Firm.first.dup
+ firm.account = Account.first.dup
assert_queries(2) { firm.save! }
end
@@ -228,7 +228,7 @@ def test_save_succeeds_for_invalid_belongs_to_with_validate_false
end
def test_assignment_before_parent_saved
- client = Client.find(:first)
+ client = Client.first
apple = Firm.new("name" => "Apple")
client.firm = apple
assert_equal apple, client.firm
@@ -342,7 +342,7 @@ def test_store_association_with_a_polymorphic_relationship
end
def test_build_and_then_save_parent_should_not_reload_target
- client = Client.find(:first)
+ client = Client.first
apple = client.build_firm(:name => "Apple")
client.save!
assert_no_queries { assert_equal apple, client.firm }
@@ -384,7 +384,7 @@ def test_invalid_adding_before_save
end
def test_invalid_adding_with_validate_false
- firm = Firm.find(:first)
+ firm = Firm.first
client = Client.new
firm.unvalidated_clients_of_firm << client
@@ -397,7 +397,7 @@ def test_invalid_adding_with_validate_false
def test_valid_adding_with_validate_false
no_of_clients = Client.count
- firm = Firm.find(:first)
+ firm = Firm.first
client = Client.new("name" => "Apple")
assert firm.valid?
View
10 activerecord/test/cases/base_test.rb
@@ -192,7 +192,7 @@ def test_preserving_date_objects
end
def test_previously_changed
- topic = Topic.find :first
+ topic = Topic.first
topic.title = '<3<3<3'
assert_equal({}, topic.previous_changes)
@@ -202,7 +202,7 @@ def test_previously_changed
end
def test_previously_changed_dup
- topic = Topic.find :first
+ topic = Topic.first
topic.title = '<3<3<3'
topic.save!
@@ -1600,7 +1600,7 @@ def test_no_limit_offset
end
def test_find_last
- last = Developer.find :last
+ last = Developer.last
assert_equal last, Developer.find(:first, :order => 'id desc')
end
@@ -1611,7 +1611,7 @@ def test_last
def test_all
developers = Developer.all
assert_kind_of Array, developers
- assert_equal Developer.find(:all), developers
+ assert_equal Developer.all, developers
end
def test_all_with_conditions
@@ -1720,7 +1720,7 @@ def test_assert_queries
end
def test_to_param_should_return_string
- assert_kind_of String, Client.find(:first).to_param
+ assert_kind_of String, Client.first.to_param
end
def test_inspect_class
View
2  activerecord/test/cases/finder_test.rb
@@ -104,7 +104,7 @@ def test_find_by_ids_with_limit_and_offset
# Also test an edge case: If you have 11 results, and you set a
# limit of 3 and offset of 9, then you should find that there
# will be only 2 results, regardless of the limit.
- devs = Developer.find :all
+ devs = Developer.all
last_devs = Developer.find devs.map(&:id), :limit => 3, :offset => 9
assert_equal 2, last_devs.size
end
View
2  activerecord/test/cases/fixtures_test.rb
@@ -716,7 +716,7 @@ def test_supports_polymorphic_belongs_to
end
def test_only_generates_a_pk_if_necessary
- m = Matey.find(:first)
+ m = Matey.first
m.pirate = pirates(:blackbeard)
m.target = pirates(:redbeard)
end
View
8 activerecord/test/cases/inheritance_test.rb
@@ -15,7 +15,7 @@ def test_class_with_store_full_sti_class_returns_full_name
end
def test_class_with_blank_sti_name
- company = Company.find(:first)
+ company = Company.first
company = company.dup
company.extend(Module.new {
def read_attribute(name)
@@ -24,7 +24,7 @@ def read_attribute(name)
end
})
company.save!
- company = Company.find(:all).find { |x| x.id == company.id }
+ company = Company.all.find { |x| x.id == company.id }
assert_equal ' ', company.type
end
@@ -149,7 +149,7 @@ def test_alt_finding_incorrect_type_data
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 "I am a client", Client.all.first.name
# Order by added as otherwise Oracle tests were failing because of different order of results
assert_equal "37signals", Firm.find(:all, :order => "id").first.name
end
@@ -259,7 +259,7 @@ def teardown
def test_instantiation_doesnt_try_to_require_corresponding_file
ActiveRecord::Base.store_full_sti_class = false
- foo = Firm.find(:first).clone
+ foo = Firm.first.clone
foo.ruby_type = foo.type = 'FirmOnTheFly'
foo.save!
View
2  activerecord/test/cases/locking_test.rb
@@ -323,7 +323,7 @@ def remove_counter_column_from(model, col = :test_count)
def counter_test(model, expected_count)
add_counter_column_to(model)
- object = model.find(:first)
+ object = model.first
assert_equal 0, object.test_count
assert_equal 0, object.send(model.locking_column)
yield object.id
View
6 activerecord/test/cases/migration/column_attributes_test.rb
@@ -64,7 +64,7 @@ def test_native_decimal_insert_manual_vs_automatic
end
# SELECT
- row = TestModel.find(:first)
+ row = TestModel.first
assert_kind_of BigDecimal, row.wealth
# If this assert fails, that means the SELECT is broken!
@@ -79,7 +79,7 @@ def test_native_decimal_insert_manual_vs_automatic
TestModel.create :wealth => BigDecimal.new("12345678901234567890.0123456789")
# SELECT
- row = TestModel.find(:first)
+ row = TestModel.first
assert_kind_of BigDecimal, row.wealth
# If these asserts fail, that means the INSERT (create function, or cast to SQL) is broken!
@@ -132,7 +132,7 @@ def test_native_types
:birthday => 18.years.ago, :favorite_day => 10.days.ago,
:moment_of_truth => "1782-10-10 21:40:18", :male => true
- bob = TestModel.find(:first)
+ bob = TestModel.first
assert_equal 'bob', bob.first_name
assert_equal 'bobsen', bob.last_name
assert_equal "I was born ....", bob.bio
View
6 activerecord/test/cases/migration/rename_column_test.rb
@@ -18,7 +18,7 @@ def test_add_rename
rename_column "test_models", "girlfriend", "exgirlfriend"
TestModel.reset_column_information
- bob = TestModel.find(:first)
+ bob = TestModel.first
assert_equal "bobette", bob.exgirlfriend
end
@@ -33,7 +33,7 @@ def test_rename_column_using_symbol_arguments
rename_column :test_models, :first_name, :nick_name
TestModel.reset_column_information
assert TestModel.column_names.include?("nick_name")
- assert_equal ['foo'], TestModel.find(:all).map(&:nick_name)
+ assert_equal ['foo'], TestModel.all.map(&:nick_name)
end
# FIXME: another integration test. We should decouple this from the
@@ -46,7 +46,7 @@ def test_rename_column
rename_column "test_models", "first_name", "nick_name"
TestModel.reset_column_information
assert TestModel.column_names.include?("nick_name")
- assert_equal ['foo'], TestModel.find(:all).map(&:nick_name)
+ assert_equal ['foo'], TestModel.all.map(&:nick_name)
end
def test_rename_column_preserves_default_value_not_null
View
16 activerecord/test/cases/migration_test.rb
@@ -109,7 +109,7 @@ def test_add_table_with_decimals
:value_of_e => BigDecimal("2.7182818284590452353602875")
)
- b = BigNumber.find(:first)
+ b = BigNumber.first
assert_not_nil b
assert_not_nil b.bank_balance
@@ -153,7 +153,7 @@ def test_add_table_with_decimals
end
GiveMeBigNumbers.down
- assert_raise(ActiveRecord::StatementInvalid) { BigNumber.find(:first) }
+ assert_raise(ActiveRecord::StatementInvalid) { BigNumber.first }
end
def test_filtering_migrations
@@ -165,13 +165,13 @@ def test_filtering_migrations
Person.reset_column_information
assert Person.column_methods_hash.include?(:last_name)
- assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
ActiveRecord::Migrator.down(MIGRATIONS_ROOT + "/valid", &name_filter)
Person.reset_column_information
assert !Person.column_methods_hash.include?(:last_name)
- assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
end
class MockMigration < ActiveRecord::Migration
@@ -285,12 +285,12 @@ def test_rename_table_with_prefix_and_suffix
WeNeedThings.up
assert Thing.create("content" => "hello world")
- assert_equal "hello world", Thing.find(:first).content
+ assert_equal "hello world", Thing.first.content
RenameThings.up
Thing.table_name = "p_awesome_things_s"
- assert_equal "hello world", Thing.find(:first).content
+ assert_equal "hello world", Thing.first.content
ensure
ActiveRecord::Base.table_name_prefix = ''
ActiveRecord::Base.table_name_suffix = ''
@@ -306,10 +306,10 @@ def test_add_drop_table_with_prefix_and_suffix
Reminder.reset_sequence_name
WeNeedReminders.up
assert Reminder.create("content" => "hello world", "remind_at" => Time.now)
- assert_equal "hello world", Reminder.find(:first).content
+ assert_equal "hello world", Reminder.first.content
WeNeedReminders.down
- assert_raise(ActiveRecord::StatementInvalid) { Reminder.find(:first) }
+ assert_raise(ActiveRecord::StatementInvalid) { Reminder.first }
ensure
ActiveRecord::Base.table_name_prefix = ''
ActiveRecord::Base.table_name_suffix = ''
View
8 activerecord/test/cases/modules_test.rb
@@ -27,13 +27,13 @@ def teardown
end
def test_module_spanning_associations
- firm = MyApplication::Business::Firm.find(:first)
+ firm = MyApplication::Business::Firm.first
assert !firm.clients.empty?, "Firm should have clients"
assert_nil firm.class.table_name.match('::'), "Firm shouldn't have the module appear in its table name"
end
def test_module_spanning_has_and_belongs_to_many_associations
- project = MyApplication::Business::Project.find(:first)
+ project = MyApplication::Business::Project.first
project.developers << MyApplication::Business::Developer.create("name" => "John")
assert_equal "John", project.developers.last.name
end
@@ -123,7 +123,7 @@ def test_nested_models_should_not_raise_exception_when_using_delete_all_dependen
old = ActiveRecord::Base.store_full_sti_class
ActiveRecord::Base.store_full_sti_class = true
- collection = Shop::Collection.find(:first)
+ collection = Shop::Collection.first
assert !collection.products.empty?, "Collection should have products"
assert_nothing_raised { collection.destroy }
ensure
@@ -134,7 +134,7 @@ def test_nested_models_should_not_raise_exception_when_using_nullify_dependency_
old = ActiveRecord::Base.store_full_sti_class
ActiveRecord::Base.store_full_sti_class = true
- product = Shop::Product.find(:first)
+ product = Shop::Product.first
assert !product.variants.empty?, "Product should have variants"
assert_nothing_raised { product.destroy }
ensure
View
22 activerecord/test/cases/named_scope_test.rb
@@ -10,12 +10,12 @@ class NamedScopeTest < ActiveRecord::TestCase
fixtures :posts, :authors, :topics, :comments, :author_addresses
def test_implements_enumerable
- assert !Topic.find(:all).empty?
+ assert !Topic.all.empty?
- assert_equal Topic.find(:all), Topic.base
- assert_equal Topic.find(:all), Topic.base.to_a
- assert_equal Topic.find(:first), Topic.base.first
- assert_equal Topic.find(:all), Topic.base.map { |i| i }
+ assert_equal Topic.all, Topic.base
+ assert_equal Topic.all, Topic.base.to_a
+ assert_equal Topic.first, Topic.base.first
+ assert_equal Topic.all, Topic.base.map { |i| i }
end
def test_found_items_are_cached
@@ -38,10 +38,10 @@ def test_reload_expires_cache_of_found_items
end
def test_delegates_finds_and_calculations_to_the_base_class
- assert !Topic.find(:all).empty?
+ assert !Topic.all.empty?
- assert_equal Topic.find(:all), Topic.base.find(:all)
- assert_equal Topic.find(:first), Topic.base.find(:first)
+ assert_equal Topic.all, Topic.base.all
+ assert_equal Topic.first, Topic.base.first
assert_equal Topic.count, Topic.base.count
assert_equal Topic.average(:replies_count), Topic.base.average(:replies_count)
end
@@ -93,7 +93,7 @@ def test_procedural_scopes
end
def test_procedural_scopes_returning_nil
- all_topics = Topic.find(:all)
+ all_topics = Topic.all
assert_equal all_topics, Topic.written_before(nil)
end
@@ -134,9 +134,9 @@ def test_scopes_honor_current_scopes_from_when_defined
end
def test_active_records_have_scope_named__all__
- assert !Topic.find(:all).empty?
+ assert !Topic.all.empty?
- assert_equal Topic.find(:all), Topic.base
+ assert_equal Topic.all, Topic.base
end
def test_active_records_have_scope_named__scoped__
View
6 activerecord/test/cases/query_cache_test.rb
@@ -96,7 +96,7 @@ def test_cache_off_after_close
def test_cache_clear_after_close
mw = ActiveRecord::QueryCache.new lambda { |env|
- Post.find(:first)
+ Post.first
[200, {}, nil]
}
body = mw.call({}).last
@@ -233,8 +233,8 @@ def test_insert
def test_cache_is_expired_by_habtm_update
ActiveRecord::Base.connection.expects(:clear_query_cache).times(2)
ActiveRecord::Base.cache do
- c = Category.find(:first)
- p = Post.find(:first)
+ c = Category.first
+ p = Post.first
p.categories << c
end
end
View
4 activerecord/test/cases/readonly_test.rb
@@ -27,7 +27,7 @@ def test_cant_save_readonly_record
def test_find_with_readonly_option
- Developer.find(:all).each { |d| assert !d.readonly? }
+ Developer.all.each { |d| assert !d.readonly? }
Developer.readonly(false).each { |d| assert !d.readonly? }
Developer.readonly(true).each { |d| assert d.readonly? }
Developer.readonly.each { |d| assert d.readonly? }
@@ -48,7 +48,7 @@ def test_has_many_find_readonly
post = Post.find(1)
assert !post.comments.empty?
assert !post.comments.any?(&:readonly?)
- assert !post.comments.find(:all).any?(&:readonly?)
+ assert !post.comments.all.any?(&:readonly?)
assert post.comments.readonly(true).all?(&:readonly?)
end
View
2  activerecord/test/cases/reflection_test.rb
@@ -63,7 +63,7 @@ def test_column_string_type_and_limit
end
def test_column_null_not_null
- subscriber = Subscriber.find(:first)
+ subscriber = Subscriber.first
assert subscriber.column_for_attribute("name").null
assert !subscriber.column_for_attribute("nick").null
end
View
8 activerecord/test/cases/relation_scoping_test.rb
@@ -324,7 +324,7 @@ class DefaultScopingTest < ActiveRecord::TestCase
def test_default_scope
expected = Developer.find(:all, :order => 'salary DESC').collect { |dev| dev.salary }
- received = DeveloperOrderedBySalary.find(:all).collect { |dev| dev.salary }
+ received = DeveloperOrderedBySalary.all.collect { |dev| dev.salary }
assert_equal expected, received
end
@@ -362,12 +362,12 @@ def test_default_scope_is_unscoped_on_create
end
def test_default_scope_with_conditions_string
- assert_equal Developer.find_all_by_name('David').map(&:id).sort, DeveloperCalledDavid.find(:all).map(&:id).sort
+ assert_equal Developer.find_all_by_name('David').map(&:id).sort, DeveloperCalledDavid.all.map(&:id).sort
assert_equal nil, DeveloperCalledDavid.create!.name
end
def test_default_scope_with_conditions_hash
- assert_equal Developer.find_all_by_name('Jamis').map(&:id).sort, DeveloperCalledJamis.find(:all).map(&:id).sort
+ assert_equal Developer.find_all_by_name('Jamis').map(&:id).sort, DeveloperCalledJamis.all.map(&:id).sort
assert_equal 'Jamis', DeveloperCalledJamis.create!.name
end
@@ -397,7 +397,7 @@ def test_default_scope_with_multiple_calls
def test_scope_overwrites_default
expected = Developer.find(:all, :order => 'salary DESC, name DESC').collect { |dev| dev.name }
- received = DeveloperOrderedBySalary.by_name.find(:all).collect { |dev| dev.name }
+ received = DeveloperOrderedBySalary.by_name.all.collect { |dev| dev.name }
assert_equal expected, received
end
View
2  activerecord/test/cases/validations/association_validation_test.rb
@@ -86,7 +86,7 @@ def test_validates_associated_missing
assert !r.valid?
assert r.errors[:topic].any?
- r.topic = Topic.find :first
+ r.topic = Topic.first
assert r.valid?
end
Please sign in to comment.
Something went wrong with that request. Please try again.