Sha256: 0c5318f8bdebf94d3edba636874d582f691289e915ea2c6ca7beed1c1d807235

Contents?: true

Size: 1.26 KB

Versions: 1

Compression:

Stored size: 1.26 KB

Contents

require 'test_helper'

describe 'Ensure that we don\'t stomp on Active Record\'s queries' do
  describe '.where' do
    it 'generates IN clauses for non array columns' do
      query = Person.where(:id => [1,2,3]).to_sql

      query.must_match /IN \(1, 2, 3\)/
    end

    it 'generates IN clauses for non array columns' do
      query = Person.where(:id => []).to_sql

      query.must_match /WHERE 1=0/
    end
  end

  describe '.where(joins: { column: [] })' do
    it 'generates IN clause for non array columns' do
      query = Person.joins(:hm_tags).where(tags: { id: ['working'] }).to_sql
      query.must_match /WHERE "tags"\."id" IN \('working'\)/
    end
  end

  describe '#habtm_association_ids=' do
    it 'properly deletes records through HABTM association method' do
      person = Person.create(habtm_tag_ids: [Tag.create.id])
      person.update_attributes(habtm_tag_ids: [])
      person.habtm_tag_ids.must_be_empty
    end
  end

  describe 'Associated record array query' do
    it 'correctly identifies the column on associations with different class names' do
      person = Person.create(:habtm_tag_ids => [Tag.create(categories: ['wicked', 'awesome']).id])
      wicked_people = Person.wicked_people
      wicked_people.must_include(person)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
postgres_ext-2.3.0 test/queries/sanity_test.rb