diff options
Diffstat (limited to 'activerecord/test/cases/scoping')
-rw-r--r-- | activerecord/test/cases/scoping/default_scoping_test.rb | 21 | ||||
-rw-r--r-- | activerecord/test/cases/scoping/named_scoping_test.rb | 7 |
2 files changed, 25 insertions, 3 deletions
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb index 9a4d8c6740..a5c4404175 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -1,9 +1,10 @@ require 'cases/helper' require 'models/post' +require 'models/comment' require 'models/developer' class DefaultScopingTest < ActiveRecord::TestCase - fixtures :developers, :posts + fixtures :developers, :posts, :comments def test_default_scope expected = Developer.all.merge!(:order => 'salary DESC').to_a.collect { |dev| dev.salary } @@ -378,6 +379,24 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal 1, DeveloperWithIncludes.where(:audit_logs => { :message => 'foo' }).count end + def test_default_scope_with_references_works_through_collection_association + post = PostWithCommentWithDefaultScopeReferencesAssociation.create!(title: "Hello World", body: "Here we go.") + comment = post.comment_with_default_scope_references_associations.create!(body: "Great post.", developer_id: Developer.first.id) + assert_equal comment, post.comment_with_default_scope_references_associations.to_a.first + end + + def test_default_scope_with_references_works_through_association + post = PostWithCommentWithDefaultScopeReferencesAssociation.create!(title: "Hello World", body: "Here we go.") + comment = post.comment_with_default_scope_references_associations.create!(body: "Great post.", developer_id: Developer.first.id) + assert_equal comment, post.first_comment + end + + def test_default_scope_with_references_works_with_find_by + post = PostWithCommentWithDefaultScopeReferencesAssociation.create!(title: "Hello World", body: "Here we go.") + comment = post.comment_with_default_scope_references_associations.create!(body: "Great post.", developer_id: Developer.first.id) + assert_equal comment, CommentWithDefaultScopeReferencesAssociation.find_by(id: comment.id) + end + unless in_memory_db? def test_default_scope_is_threadsafe threads = [] diff --git a/activerecord/test/cases/scoping/named_scoping_test.rb b/activerecord/test/cases/scoping/named_scoping_test.rb index 59ec2dd6a4..d3546bd471 100644 --- a/activerecord/test/cases/scoping/named_scoping_test.rb +++ b/activerecord/test/cases/scoping/named_scoping_test.rb @@ -291,9 +291,12 @@ class NamedScopingTest < ActiveRecord::TestCase :relation, # private class method on AR::Base :new, # redefined class method on AR::Base :all, # a default scope - :public, + :public, # some imporant methods on Module and Class :protected, - :private + :private, + :name, + :parent, + :superclass ] non_conflicts = [ |