Skip to content
Browse files

Merge and add tests related to 5215

  • Loading branch information...
1 parent 2f3d81c commit 5359ad9ed1458a010c814639e824d3ce2bde1628 @vipulnsward vipulnsward committed
View
17 activerecord/test/cases/associations/has_and_belongs_to_many_associations_test.rb
@@ -799,12 +799,6 @@ def test_count_with_counter_sql
assert_equal 1, developer.projects.count
end
- def test_counting_should_not_fire_sql_if_parent_is_unsaved
- assert_no_queries do
- assert_equal 0, Developer.new.projects.count
- end
- end
-
unless current_adapter?(:PostgreSQLAdapter)
def test_count_with_finder_sql
assert_equal 3, projects(:active_record).developers_with_finder_sql.count
@@ -862,4 +856,15 @@ def klass.name; 'Foo'; end
def klass.name; 'Foo'; end
assert_deprecated { klass.has_and_belongs_to_many :posts, :delete_sql => 'lol' }
end
+
+ test "has and belongs to many associations on new records use null relations" do
+ projects = Developer.new.projects
+ assert_no_queries do
+ assert_equal [], projects
+ assert_equal [], projects.where(title: 'omg')
+ assert_equal [], projects.pluck(:title)
+ assert_equal 0, projects.count
+ end
+ end
+
end
View
7 activerecord/test/cases/associations/has_many_associations_test.rb
@@ -262,12 +262,6 @@ def test_counting_with_association_limit
assert_equal firm.limited_clients.length, firm.limited_clients.count
end
- def test_counting_should_not_fire_sql_if_parent_is_unsaved
- assert_no_queries do
- assert_equal 0, Person.new.readers.count
- end
- end
-
def test_finding
assert_equal 2, Firm.all.merge!(:order => "id").first.clients.length
end
@@ -1665,6 +1659,7 @@ def test_collection_association_with_private_kernel_method
assert_equal [], post.comments.where(body: 'omg')
assert_equal [], post.comments.pluck(:body)
assert_equal 0, post.comments.sum(:id)
+ assert_equal 0, post.comments.count
end
end
end
View
19 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -766,12 +766,6 @@ def test_count_has_many_through_with_named_scope
assert_equal 1, authors(:mary).categories.general.count
end
- def test_counting_should_not_fire_sql_if_parent_is_unsaved
- assert_no_queries do
- assert_equal 0, Person.new.posts.count
- end
- end
-
def test_has_many_through_belongs_to_should_update_when_the_through_foreign_key_changes
post = posts(:eager_other)
@@ -876,4 +870,17 @@ def test_has_many_through_with_polymorphic_source
post = tags(:general).tagged_posts.create! :title => "foo", :body => "bar"
assert_equal [tags(:general)], post.reload.tags
end
+
+ test "has many through associations on new records use null relations" do
+ person = Person.new
+
+ assert_no_queries do
+ assert_equal [], person.posts
+ assert_equal [], person.posts.where(body: 'omg')
+ assert_equal [], person.posts.pluck(:body)
+ assert_equal 0, person.posts.sum(:tags_count)
+ assert_equal 0, person.posts.count
+ end
+ end
+
end

0 comments on commit 5359ad9

Please sign in to comment.
Something went wrong with that request. Please try again.