class HasManyScopingTest

Public Instance Methods

setup() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 336
def setup
  @welcome = Post.find(1)
end
test_forwarding_of_static_methods() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 340
def test_forwarding_of_static_methods
  assert_equal "a comment...", Comment.what_are_you
  assert_equal "a comment...", @welcome.comments.what_are_you
end
test_forwarding_to_scoped() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 345
def test_forwarding_to_scoped
  assert_equal 4, Comment.search_by_type("Comment").size
  assert_equal 2, @welcome.comments.search_by_type("Comment").size
end
test_nested_scope_finder() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 350
def test_nested_scope_finder
  Comment.where("1=0").scoping do
    assert_equal 0, @welcome.comments.count
    assert_equal "a comment...", @welcome.comments.what_are_you
  end

  Comment.where("1=1").scoping do
    assert_equal 2, @welcome.comments.count
    assert_equal "a comment...", @welcome.comments.what_are_you
  end
end
test_should_default_scope_on_associations_is_overridden_by_association_conditions() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 367
def test_should_default_scope_on_associations_is_overridden_by_association_conditions
  reference = references(:michael_unicyclist).becomes(BadReference)
  assert_equal [reference], people(:michael).fixed_bad_references
end
test_should_maintain_default_scope_on_associations() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 362
def test_should_maintain_default_scope_on_associations
  magician = BadReference.find(1)
  assert_equal [magician], people(:michael).bad_references
end
test_should_maintain_default_scope_on_eager_loaded_associations() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 372
def test_should_maintain_default_scope_on_eager_loaded_associations
  michael = Person.where(id: people(:michael).id).includes(:bad_references).first
  magician = BadReference.find(1)
  assert_equal [magician], michael.bad_references
end