aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/associations
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord/test/cases/associations')
-rw-r--r--activerecord/test/cases/associations/belongs_to_associations_test.rb4
-rw-r--r--activerecord/test/cases/associations/eager_load_includes_full_sti_class_test.rb2
-rw-r--r--activerecord/test/cases/associations/eager_test.rb2
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb13
-rw-r--r--activerecord/test/cases/associations/has_many_through_associations_test.rb4
-rw-r--r--activerecord/test/cases/associations/has_one_associations_test.rb8
-rw-r--r--activerecord/test/cases/associations/inverse_associations_test.rb18
-rw-r--r--activerecord/test/cases/associations/join_model_test.rb4
8 files changed, 24 insertions, 31 deletions
diff --git a/activerecord/test/cases/associations/belongs_to_associations_test.rb b/activerecord/test/cases/associations/belongs_to_associations_test.rb
index be77ee4bf3..9258c987ef 100644
--- a/activerecord/test/cases/associations/belongs_to_associations_test.rb
+++ b/activerecord/test/cases/associations/belongs_to_associations_test.rb
@@ -403,7 +403,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal saved_member.id, sponsor.sponsorable_id
sponsor.sponsorable = new_member
- assert_equal nil, sponsor.sponsorable_id
+ assert_nil sponsor.sponsorable_id
end
def test_polymorphic_assignment_with_primary_key_updates_foreign_id_field_for_new_and_saved_records
@@ -415,7 +415,7 @@ class BelongsToAssociationsTest < ActiveRecord::TestCase
assert_equal saved_writer.name, essay.writer_id
essay.writer = new_writer
- assert_equal nil, essay.writer_id
+ assert_nil essay.writer_id
end
def test_belongs_to_proxy_should_not_respond_to_private_methods
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 7c470616a5..b124a2bfc3 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
@@ -29,7 +29,7 @@ class EagerLoadIncludeFullStiClassNamesTest < ActiveRecord::TestCase
ActiveRecord::Base.store_full_sti_class = true
post = Namespaced::Post.find_by_title( 'Great stuff', :include => :tagging )
- assert_equal 'Tagging', post.tagging.class.name
+ assert_instance_of Tagging, post.tagging
ensure
ActiveRecord::Base.store_full_sti_class = old
end
diff --git a/activerecord/test/cases/associations/eager_test.rb b/activerecord/test/cases/associations/eager_test.rb
index 79e5ecf4ce..445e6889c0 100644
--- a/activerecord/test/cases/associations/eager_test.rb
+++ b/activerecord/test/cases/associations/eager_test.rb
@@ -110,7 +110,7 @@ class EagerAssociationTest < ActiveRecord::TestCase
author = assert_queries(3) { Author.find(author_id, :include => {:posts_with_comments => :comments}) } # find the author, then find the posts, then find the comments
author.posts_with_comments.each do |post_with_comments|
assert_equal post_with_comments.comments.length, post_with_comments.comments.count
- assert_equal nil, post_with_comments.comments.uniq!
+ assert_nil post_with_comments.comments.uniq!
end
end
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 6e47967696..8e5bc56008 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -175,14 +175,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
c = Client.new
assert_nil c.firm
- if c.firm
- assert false, "belongs_to failed if check"
- end
-
- unless c.firm
- else
- assert false, "belongs_to failed unless check"
- end
+ flunk "belongs_to failed if check" if c.firm
end
def test_find_ids
@@ -620,7 +613,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal [], Client.destroyed_client_ids[firm.id]
# Should be destroyed since the association is exclusively dependent.
- assert Client.find_by_id(client_id).nil?
+ assert_nil Client.find_by_id(client_id)
end
def test_dependent_association_respects_optional_conditions_on_delete
@@ -669,7 +662,7 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
old_record = firm.clients_using_primary_key_with_delete_all.first
firm = Firm.find(:first)
firm.destroy
- assert Client.find_by_id(old_record.id).nil?
+ assert_nil Client.find_by_id(old_record.id)
end
def test_creation_respects_hash_condition
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 ff799191c2..e4dd810732 100644
--- a/activerecord/test/cases/associations/has_many_through_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -63,8 +63,8 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase
assert_queries(1) { posts(:thinking) }
assert_queries(0) do
- posts(:thinking).people.build(:first_name=>"Bob")
- posts(:thinking).people.new(:first_name=>"Ted")
+ posts(:thinking).people.build(:first_name => "Bob")
+ posts(:thinking).people.new(:first_name => "Ted")
end
# Should only need to load the association once
diff --git a/activerecord/test/cases/associations/has_one_associations_test.rb b/activerecord/test/cases/associations/has_one_associations_test.rb
index 8f5540950e..469a21b9bf 100644
--- a/activerecord/test/cases/associations/has_one_associations_test.rb
+++ b/activerecord/test/cases/associations/has_one_associations_test.rb
@@ -149,7 +149,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
num_accounts = Account.count
firm = Firm.find(1)
- assert !firm.account.nil?
+ assert_not_nil firm.account
account_id = firm.account.id
assert_equal [], Account.destroyed_account_ids[firm.id]
@@ -162,7 +162,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
num_accounts = Account.count
firm = ExclusivelyDependentFirm.find(9)
- assert !firm.account.nil?
+ assert_not_nil firm.account
account_id = firm.account.id
assert_equal [], Account.destroyed_account_ids[firm.id]
@@ -181,7 +181,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
firm = RestrictedFirm.new(:name => 'restrict')
firm.save!
account = firm.create_account(:credit_limit => 10)
- assert !firm.account.nil?
+ assert_not_nil firm.account
assert_raise(ActiveRecord::DeleteRestrictionError) { firm.destroy }
end
@@ -246,7 +246,7 @@ class HasOneAssociationsTest < ActiveRecord::TestCase
def test_dependence_with_missing_association
Account.destroy_all
firm = Firm.find(1)
- assert firm.account.nil?
+ assert_nil firm.account
firm.destroy
end
diff --git a/activerecord/test/cases/associations/inverse_associations_test.rb b/activerecord/test/cases/associations/inverse_associations_test.rb
index 1d7604f52b..34d24a2948 100644
--- a/activerecord/test/cases/associations/inverse_associations_test.rb
+++ b/activerecord/test/cases/associations/inverse_associations_test.rb
@@ -23,39 +23,39 @@ class InverseAssociationTests < ActiveRecord::TestCase
def test_should_be_able_to_ask_a_reflection_if_it_has_an_inverse
has_one_with_inverse_ref = Man.reflect_on_association(:face)
- assert has_one_with_inverse_ref.respond_to?(:has_inverse?)
+ assert_respond_to has_one_with_inverse_ref, :has_inverse?
assert has_one_with_inverse_ref.has_inverse?
has_many_with_inverse_ref = Man.reflect_on_association(:interests)
- assert has_many_with_inverse_ref.respond_to?(:has_inverse?)
+ assert_respond_to has_many_with_inverse_ref, :has_inverse?
assert has_many_with_inverse_ref.has_inverse?
belongs_to_with_inverse_ref = Face.reflect_on_association(:man)
- assert belongs_to_with_inverse_ref.respond_to?(:has_inverse?)
+ assert_respond_to belongs_to_with_inverse_ref, :has_inverse?
assert belongs_to_with_inverse_ref.has_inverse?
has_one_without_inverse_ref = Club.reflect_on_association(:sponsor)
- assert has_one_without_inverse_ref.respond_to?(:has_inverse?)
+ assert_respond_to has_one_without_inverse_ref, :has_inverse?
assert !has_one_without_inverse_ref.has_inverse?
has_many_without_inverse_ref = Club.reflect_on_association(:memberships)
- assert has_many_without_inverse_ref.respond_to?(:has_inverse?)
+ assert_respond_to has_many_without_inverse_ref, :has_inverse?
assert !has_many_without_inverse_ref.has_inverse?
belongs_to_without_inverse_ref = Sponsor.reflect_on_association(:sponsor_club)
- assert belongs_to_without_inverse_ref.respond_to?(:has_inverse?)
+ assert_respond_to belongs_to_without_inverse_ref, :has_inverse?
assert !belongs_to_without_inverse_ref.has_inverse?
end
def test_should_be_able_to_ask_a_reflection_what_it_is_the_inverse_of
has_one_ref = Man.reflect_on_association(:face)
- assert has_one_ref.respond_to?(:inverse_of)
+ assert_respond_to has_one_ref, :inverse_of
has_many_ref = Man.reflect_on_association(:interests)
- assert has_many_ref.respond_to?(:inverse_of)
+ assert_respond_to has_many_ref, :inverse_of
belongs_to_ref = Face.reflect_on_association(:man)
- assert belongs_to_ref.respond_to?(:inverse_of)
+ assert_respond_to belongs_to_ref, :inverse_of
end
def test_inverse_of_method_should_supply_the_actual_reflection_instance_it_is_the_inverse_of
diff --git a/activerecord/test/cases/associations/join_model_test.rb b/activerecord/test/cases/associations/join_model_test.rb
index dca72be4fd..447fe4d275 100644
--- a/activerecord/test/cases/associations/join_model_test.rb
+++ b/activerecord/test/cases/associations/join_model_test.rb
@@ -280,12 +280,12 @@ class AssociationsJoinModelTest < ActiveRecord::TestCase
def test_has_many_find_conditions
assert_equal categories(:general), authors(:david).categories.find(:first, :conditions => "categories.name = 'General'")
- assert_equal nil, authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'")
+ assert_nil authors(:david).categories.find(:first, :conditions => "categories.name = 'Technology'")
end
def test_has_many_class_methods_called_by_method_missing
assert_equal categories(:general), authors(:david).categories.find_all_by_name('General').first
- assert_equal nil, authors(:david).categories.find_by_name('Technology')
+ assert_nil authors(:david).categories.find_by_name('Technology')
end
def test_has_many_array_methods_called_by_method_missing