class NestedRelationScopingTest

Public Instance Methods

test_merge_inner_scope_has_priority() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 272
def test_merge_inner_scope_has_priority
  Developer.limit(5).scoping do
    Developer.limit(10).scoping do
      assert_equal 10, Developer.all.size
    end
  end
end
test_merge_options() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 261
def test_merge_options
  Developer.where("salary = 80000").scoping do
    Developer.limit(10).scoping do
      devs = Developer.all
      sql = devs.to_sql
      assert_match "(salary = 80000)", sql
      assert_match(/LIMIT 10|ROWNUM <= 10|FETCH FIRST 10 ROWS ONLY/, sql)
    end
  end
end
test_nested_exclusive_scope_for_create() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 320
def test_nested_exclusive_scope_for_create
  comment = Comment.create_with(body: "Hey guys, nested scopes are broken. Please fix!").scoping do
    Comment.unscoped.create_with(post_id: 1).scoping do
      assert Comment.new.body.blank?
      Comment.create body: "Hey guys"
    end
  end

  assert_equal 1, comment.post_id
  assert_equal "Hey guys", comment.body
end
test_nested_scoped_create() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 310
def test_nested_scoped_create
  comment = Comment.create_with(post_id: 1).scoping do
    Comment.create_with(post_id: 2).scoping do
      Comment.create body: "Hey guys, nested scopes are broken. Please fix!"
    end
  end

  assert_equal 2, comment.post_id
end
test_replace_options() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 280
def test_replace_options
  Developer.where(name: "David").scoping do
    Developer.unscoped do
      assert_equal "Jamis", Developer.where(name: "Jamis").first[:name]
    end

    assert_equal "David", Developer.first[:name]
  end
end
test_three_level_nested_exclusive_scoped_find() click to toggle source
# File activerecord/test/cases/scoping/relation_scoping_test.rb, line 290
def test_three_level_nested_exclusive_scoped_find
  Developer.where("name = 'Jamis'").scoping do
    assert_equal "Jamis", Developer.first.name

    Developer.unscoped.where("name = 'David'") do
      assert_equal "David", Developer.first.name

      Developer.unscoped.where("name = 'Maiha'") do
        assert_nil Developer.first
      end

      # ensure that scoping is restored
      assert_equal "David", Developer.first.name
    end

    # ensure that scoping is restored
    assert_equal "Jamis", Developer.first.name
  end
end