Sha256: da4fc11ed76e801abffec40a733332b9ba3c2edd918aff278b5533c923e76054

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 KB

Contents

require 'test_helper'

class ActiverecordAnyOfTest < ActiveSupport::TestCase
  fixtures :authors, :posts

  test 'finding with alternate conditions' do
    assert_equal ['David', 'Mary'], Author.any_of({name: 'David'}, {name: 'Mary'}).map(&:name)
    assert_equal ['David', 'Mary'], Author.any_of({name: 'David'}, ['name = ?', 'Mary']).map(&:name)

    davids = Author.where(name: 'David')
    assert_equal ['David', 'Mary', 'Bob'], Author.any_of(davids, ['name = ?', 'Mary'], {name: 'Bob'}).map(&:name)
    assert_equal ['David', 'Mary', 'Bob'], Author.any_of(davids, "name = 'Mary'", {name: 'Bob', id: 3}).map(&:name)

    if Rails.version >= '4'
      assert_equal ['David'], Author.where.not(name: 'Mary').any_of(davids, ['name = ?', 'Mary']).map(&:name)
    else
      assert_equal ['David'], Author.where("name IS NOT 'Mary'").any_of(davids, ['name = ?', 'Mary']).map(&:name)
    end
  end

  test 'finding with alternate conditions on association' do
    david = Author.where(name: 'David').first
    welcome = david.posts.where(body: 'Such a lovely day')
    expected = ['Welcome to the weblog', 'So I was thinking']
    assert_equal expected, david.posts.any_of(welcome, {type: 'SpecialPost'}).map(&:title)
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
activerecord_any_of-0.0.1 test/activerecord_any_of_test.rb