Methods
T
Instance Public methods
test_or_identity()
# File activerecord/test/cases/relation/or_test.rb, line 13
def test_or_identity
  expected = Post.where('id = 1').to_a
  assert_equal expected, Post.where('id = 1').or(Post.where('id = 1')).to_a
end
test_or_inside_named_scope()
# File activerecord/test/cases/relation/or_test.rb, line 73
def test_or_inside_named_scope
  expected = Post.where("body LIKE '\%a\%' OR title LIKE ?", "%'%").order('id DESC').to_a
  assert_equal expected, Post.order(id: :desc).typographically_interesting
end
test_or_on_loaded_relation()
# File activerecord/test/cases/relation/or_test.rb, line 78
def test_or_on_loaded_relation
  expected = Post.where('id = 1 or id = 2').to_a
  p = Post.where('id = 1')
  p.load
  assert_equal p.loaded?, true
  assert_equal expected, p.or(Post.where('id = 2')).to_a
end
test_or_preserves_other_querying_methods()
# File activerecord/test/cases/relation/or_test.rb, line 47
def test_or_preserves_other_querying_methods
  expected = Post.where('id = 1 or id = 2 or id = 3').order('body asc').to_a
  partial = Post.order('body asc')
  assert_equal expected, partial.where('id = 1').or(partial.where(:id => [2, 3])).to_a
  assert_equal expected, Post.order('body asc').where('id = 1').or(Post.order('body asc').where(:id => [2, 3])).to_a
end
test_or_when_grouping()
# File activerecord/test/cases/relation/or_test.rb, line 62
def test_or_when_grouping
  groups = Post.where('id < 10').group('body').select('body, COUNT(*) AS c')
  expected = groups.having("COUNT(*) > 1 OR body like 'Such%'").to_a.map {|o| [o.body, o.c] }
  assert_equal expected, groups.having('COUNT(*) > 1').or(groups.having("body like 'Such%'")).to_a.map {|o| [o.body, o.c] }
end
test_or_with_bind_params()
# File activerecord/test/cases/relation/or_test.rb, line 28
def test_or_with_bind_params
  assert_equal Post.find([1, 2]), Post.where(id: 1).or(Post.where(id: 2)).to_a
end
test_or_with_incompatible_relations()
# File activerecord/test/cases/relation/or_test.rb, line 54
def test_or_with_incompatible_relations
  error = assert_raises ArgumentError do
    Post.order('body asc').where('id = 1').or(Post.order('id desc').where(:id => [2, 3])).to_a
  end

  assert_equal "Relation passed to #or must be structurally compatible. Incompatible values: [:order]", error.message
end
test_or_with_named_scope()
# File activerecord/test/cases/relation/or_test.rb, line 68
def test_or_with_named_scope
  expected = Post.where("id = 1 or body LIKE '\%a\%'").to_a
  assert_equal expected, Post.where('id = 1').or(Post.containing_the_letter_a)
end
test_or_with_non_relation_object_raises_error()
# File activerecord/test/cases/relation/or_test.rb, line 86
def test_or_with_non_relation_object_raises_error
  assert_raises ArgumentError do
    Post.where(id: [1, 2, 3]).or(title: 'Rails')
  end
end
test_or_with_null_both()
# File activerecord/test/cases/relation/or_test.rb, line 32
def test_or_with_null_both
  expected = Post.none.to_a
  assert_equal expected, Post.none.or(Post.none).to_a
end
test_or_with_null_left()
# File activerecord/test/cases/relation/or_test.rb, line 18
def test_or_with_null_left
  expected = Post.where('id = 1').to_a
  assert_equal expected, Post.none.or(Post.where('id = 1')).to_a
end
test_or_with_null_right()
# File activerecord/test/cases/relation/or_test.rb, line 23
def test_or_with_null_right
  expected = Post.where('id = 1').to_a
  assert_equal expected, Post.where('id = 1').or(Post.none).to_a
end
test_or_with_relation()
# File activerecord/test/cases/relation/or_test.rb, line 8
def test_or_with_relation
  expected = Post.where('id = 1 or id = 2').to_a
  assert_equal expected, Post.where('id = 1').or(Post.where('id = 2')).to_a
end
test_or_without_left_where()
# File activerecord/test/cases/relation/or_test.rb, line 37
def test_or_without_left_where
  expected = Post.all
  assert_equal expected, Post.or(Post.where('id = 1')).to_a
end
test_or_without_right_where()
# File activerecord/test/cases/relation/or_test.rb, line 42
def test_or_without_right_where
  expected = Post.all
  assert_equal expected, Post.where('id = 1').or(Post.all).to_a
end