diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2017-07-18 13:42:57 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-18 13:42:57 -0400 |
commit | 36ff7b63ec083924a5b407cf3df7ae90e22183e2 (patch) | |
tree | 8cbdbe138f13a0dc7c3666f036fda685c644d262 /activerecord/test/cases/scoping/default_scoping_test.rb | |
parent | 425ba83c28214ca97c5d3600c16ad7a796cd33e6 (diff) | |
parent | f47bac481949a69a519ea7d833e1a8d435332d52 (diff) | |
download | rails-36ff7b63ec083924a5b407cf3df7ae90e22183e2.tar.gz rails-36ff7b63ec083924a5b407cf3df7ae90e22183e2.tar.bz2 rails-36ff7b63ec083924a5b407cf3df7ae90e22183e2.zip |
Merge branch 'master' into fix_unscope_where_column_with_or
Diffstat (limited to 'activerecord/test/cases/scoping/default_scoping_test.rb')
-rw-r--r-- | activerecord/test/cases/scoping/default_scoping_test.rb | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/activerecord/test/cases/scoping/default_scoping_test.rb b/activerecord/test/cases/scoping/default_scoping_test.rb index 89fb434b27..a8c79628e7 100644 --- a/activerecord/test/cases/scoping/default_scoping_test.rb +++ b/activerecord/test/cases/scoping/default_scoping_test.rb @@ -332,7 +332,7 @@ class DefaultScopingTest < ActiveRecord::TestCase def test_create_with_merge aaron = PoorDeveloperCalledJamis.create_with(name: "foo", salary: 20).merge( - PoorDeveloperCalledJamis.create_with(name: "Aaron")).new + PoorDeveloperCalledJamis.create_with(name: "Aaron")).new assert_equal 20, aaron.salary assert_equal "Aaron", aaron.name @@ -342,6 +342,11 @@ class DefaultScopingTest < ActiveRecord::TestCase assert_equal "Aaron", aaron.name end + def test_create_with_using_both_string_and_symbol + jamis = PoorDeveloperCalledJamis.create_with(name: "foo").create_with("name" => "Aaron").new + assert_equal "Aaron", jamis.name + end + def test_create_with_reset jamis = PoorDeveloperCalledJamis.create_with(name: "Aaron").create_with(nil).new assert_equal "Jamis", jamis.name @@ -372,11 +377,39 @@ class DefaultScopingTest < ActiveRecord::TestCase Comment.joins(:post).count end + def test_joins_not_affected_by_scope_other_than_default_or_unscoped + without_scope_on_post = Comment.joins(:post).to_a + with_scope_on_post = nil + Post.where(id: [1, 5, 6]).scoping do + with_scope_on_post = Comment.joins(:post).to_a + end + + assert_equal with_scope_on_post, without_scope_on_post + end + def test_unscoped_with_joins_should_not_have_default_scope assert_equal SpecialPostWithDefaultScope.unscoped { Comment.joins(:special_post_with_default_scope).to_a }, Comment.joins(:post).to_a end + def test_sti_association_with_unscoped_not_affected_by_default_scope + post = posts(:thinking) + comments = [comments(:does_it_hurt)] + + post.special_comments.update_all(deleted_at: Time.now) + + assert_raises(ActiveRecord::RecordNotFound) { Post.joins(:special_comments).find(post.id) } + assert_equal [], post.special_comments + + SpecialComment.unscoped do + assert_equal post, Post.joins(:special_comments).find(post.id) + assert_equal comments, Post.joins(:special_comments).find(post.id).special_comments + assert_equal comments, Post.eager_load(:special_comments).find(post.id).special_comments + assert_equal comments, Post.includes(:special_comments).find(post.id).special_comments + assert_equal comments, Post.preload(:special_comments).find(post.id).special_comments + end + end + def test_default_scope_select_ignored_by_aggregations assert_equal DeveloperWithSelect.all.to_a.count, DeveloperWithSelect.count end |