diff options
Diffstat (limited to 'activerecord/test/cases/associations')
6 files changed, 21 insertions, 21 deletions
diff --git a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb index 75a6295350..b0a6e0a550 100644 --- a/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb +++ b/activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb @@ -24,11 +24,11 @@ class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase old = ActiveRecord::Base.store_full_sti_class ActiveRecord::Base.store_full_sti_class = false - post = Namespaced::Post.includes(:tagging).find_by_title('Great stuff') + post = Namespaced::Post.includes(:tagging).find_by(title: 'Great stuff') assert_nil post.tagging ActiveRecord::Base.store_full_sti_class = true - post = Namespaced::Post.includes(:tagging).find_by_title('Great stuff') + post = Namespaced::Post.includes(:tagging).find_by(title: 'Great stuff') assert_instance_of Tagging, post.tagging ensure ActiveRecord::Base.store_full_sti_class = old diff --git a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb index 1b1b479f1a..3c3355b0f8 100644 --- a/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb @@ -33,7 +33,7 @@ class ProjectWithAfterCreateHook < ActiveRecord::Base after_create :add_david def add_david - david = DeveloperForProjectWithAfterCreateHook.find_by_name('David') + david = DeveloperForProjectWithAfterCreateHook.find_by(name: 'David') david.projects << self end end @@ -268,7 +268,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert devel.persisted? assert proj2.persisted? assert_equal devel.projects.last, proj2 - assert_equal Developer.find_by_name("Marcel").projects.last, proj2 # prove join table is updated + assert_equal Developer.find_by(name: "Marcel").projects.last, proj2 # prove join table is updated end def test_create @@ -293,7 +293,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase assert devel.persisted? assert proj2.persisted? assert_equal devel.projects.last, proj2 - assert_equal Developer.find_by_name("Marcel").projects.last, proj2 # prove join table is updated + assert_equal Developer.find_by(name: "Marcel").projects.last, proj2 # prove join table is updated end def test_creation_respects_hash_condition @@ -567,7 +567,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase high_id_jamis = projects(:active_record).developers.create(:name => 'Jamis') assert_equal high_id_jamis, projects(:active_record).developers.merge(:where => "name = 'Jamis'").first - assert_equal high_id_jamis, projects(:active_record).developers.find_by_name('Jamis') + assert_equal high_id_jamis, projects(:active_record).developers.find_by(name: 'Jamis') end def test_find_should_prepend_to_association_order @@ -581,8 +581,8 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase end def test_new_with_values_in_collection - jamis = DeveloperForProjectWithAfterCreateHook.find_by_name('Jamis') - david = DeveloperForProjectWithAfterCreateHook.find_by_name('David') + jamis = DeveloperForProjectWithAfterCreateHook.find_by(name: 'Jamis') + david = DeveloperForProjectWithAfterCreateHook.find_by(name: 'David') project = ProjectWithAfterCreateHook.new(:name => "Cooking with Bertie") project.developers << jamis project.save! @@ -751,7 +751,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase end def test_scoped_find_on_through_association_doesnt_return_read_only_records - tag = Post.find(1).tags.find_by_name("General") + tag = Post.find(1).tags.find_by(name: "General") assert_nothing_raised do tag.save! @@ -783,7 +783,7 @@ class HasAndBelongsToManyAssociationsTest < ActiveRecord::TestCase def test_dynamic_find_should_respect_association_include # SQL error in sort clause if :include is not included # due to Unknown column 'authors.id' - assert Category.find(1).posts_with_authors_sorted_by_author_id.find_by_title('Welcome to the weblog') + assert Category.find(1).posts_with_authors_sorted_by_author_id.find_by(title: 'Welcome to the weblog') end def test_count diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index 7e6c7d5862..3f9667fa94 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -253,7 +253,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase post = Post.first assert_equal [], person.readers - assert_nil person.readers.find_by_post_id(post.id) + assert_nil person.readers.find_by(post_id: post.id) person.readers.create(:post_id => post.id) @@ -311,7 +311,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_dynamic_find_should_respect_association_order assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.where("type = 'Client'").first - assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.find_by_type('Client') + assert_equal companies(:second_client), companies(:first_firm).clients_sorted_desc.find_by(type: 'Client') end def test_cant_save_has_many_readonly_association @@ -878,7 +878,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [client_id], Client.destroyed_client_ids[firm.id] # Should be destroyed since the association is dependent. - assert_nil Client.find_by_id(client_id) + assert_nil Client.find_by(id: client_id) end def test_clearing_an_exclusively_dependent_association_collection @@ -898,7 +898,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase assert_equal [], Client.destroyed_client_ids[firm.id] # Should be destroyed since the association is exclusively dependent. - assert_nil Client.find_by_id(client_id) + assert_nil Client.find_by(id: client_id) end def test_dependent_association_respects_optional_conditions_on_delete @@ -947,7 +947,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase old_record = firm.clients_using_primary_key_with_delete_all.first firm = Firm.first firm.destroy - assert_nil Client.find_by_id(old_record.id) + assert_nil Client.find_by(id: old_record.id) end def test_creation_respects_hash_condition @@ -973,7 +973,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_deleting_a_item_which_is_not_in_the_collection force_signal37_to_load_all_clients_of_firm - summit = Client.find_by_name('Summit') + summit = Client.find_by(name: 'Summit') companies(:first_firm).clients_of_firm.delete(summit) assert_equal 1, companies(:first_firm).clients_of_firm.size assert_equal 1, companies(:first_firm).clients_of_firm(true).size @@ -1299,7 +1299,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase def test_dynamic_find_should_respect_association_order_for_through assert_equal Comment.find(10), authors(:david).comments_desc.where("comments.type = 'SpecialComment'").first - assert_equal Comment.find(10), authors(:david).comments_desc.find_by_type('SpecialComment') + assert_equal Comment.find(10), authors(:david).comments_desc.find_by(type: 'SpecialComment') end def test_has_many_through_respects_hash_conditions diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index af91fb2920..0e9af3acec 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -524,7 +524,7 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase def test_dynamic_find_should_respect_association_include # SQL error in sort clause if :include is not included # due to Unknown column 'comments.id' - assert Person.find(1).posts_with_comments_sorted_by_comment_id.find_by_title('Welcome to the weblog') + assert Person.find(1).posts_with_comments_sorted_by_comment_id.find_by(title: 'Welcome to the weblog') end def test_count_with_include_should_alias_join_table diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb index 4ed09a3bf7..65562709a2 100644 --- a/activerecord/test/cases/associations/has_one_associations_test.rb +++ b/activerecord/test/cases/associations/has_one_associations_test.rb @@ -38,7 +38,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase def test_finding_using_primary_key firm = companies(:first_firm) - assert_equal Account.find_by_firm_id(firm.id), firm.account + assert_equal Account.find_by(firm_id: firm.id), firm.account firm.firm_id = companies(:rails_core).id assert_equal accounts(:rails_core_account), firm.account_using_primary_key end @@ -46,7 +46,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase def test_update_with_foreign_and_primary_keys firm = companies(:first_firm) account = firm.account_using_foreign_and_primary_keys - assert_equal Account.find_by_firm_name(firm.name), account + assert_equal Account.find_by(firm_name: firm.name), account firm.save firm.reload assert_equal account, firm.account_using_foreign_and_primary_keys diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb index 10ec33be75..368d862f4e 100644 --- a/activerecord/test/cases/associations/join_model_test.rb +++ b/activerecord/test/cases/associations/join_model_test.rb @@ -448,7 +448,7 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase end def test_has_many_through_uses_correct_attributes - assert_nil posts(:thinking).tags.find_by_name("General").attributes["tag_id"] + assert_nil posts(:thinking).tags.find_by(name: "General").attributes["tag_id"] end def test_associating_unsaved_records_with_has_many_through |