Sha256: ef370aa9ea8d45d0b8536c04f12c6bd4030c82decd9a83acba22331d433ccd94

Contents?: true

Size: 1.79 KB

Versions: 13

Compression:

Stored size: 1.79 KB

Contents

require File.join(File.dirname(__FILE__), 'spec_helper')

describe 'with custom selects for cases where DISTINCT is required' do
  before do
    TestModel.extended_models.each { |model| model.last_find = {} }
  end 

  describe 'on a standard filter' do
    it 'should put nothing in the select' do
      Post.filter do
        having(:comments).with(:offensive, true)
      end.inspect
      Post.last_find[:select].should be_nil
    end
  end

  describe 'with join types that require distinct' do
    it 'should put the distinct clause in the select' do
      [:left, :right].each do |join_type|
        Post.filter do
          having(join_type, :comments).with(:offensive, true)
        end.inspect rescue nil # required because sqlite doesn't support right joins
        Post.last_find[:select].should == %q(DISTINCT "posts".*)
      end
    end
  end

  describe 'with join types that do not require distinct' do
    it 'should not put the distinct clause in the select' do
      [:inner].each do |join_type|
        Post.filter do
          having(join_type, :comments).with(:offensive, true)
        end.inspect
        Post.last_find[:select].should be_nil
      end
    end
  end

  describe 'on a filter with nested joins that require distinct' do
    it 'should put the distinct clause in the select' do
      Blog.filter do
        having(:posts) do
          having(:left, :comments).with(:offensive, true)
        end
      end.inspect
      Blog.last_find[:select].should == %q(DISTINCT "blogs".*)
    end
  end

  describe 'on a filter that requires distinct with a count call' do
    it 'should put the distinct clause in the select' do
      Post.filter do
        having(:left, :comments).with(:offensive, true)
      end.count
      Post.last_find[:select].should == %q(DISTINCT "posts".id)
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
aub-record_filter-0.6.0 spec/select_spec.rb
aub-record_filter-0.8.0 spec/select_spec.rb
aub-record_filter-0.9.0 spec/select_spec.rb
aub-record_filter-0.9.1 spec/select_spec.rb
aub-record_filter-0.9.2 spec/select_spec.rb
aub-record_filter-0.9.3 spec/select_spec.rb
aub-record_filter-0.9.4 spec/select_spec.rb
aub-record_filter-0.9.5 spec/select_spec.rb
aub-record_filter-0.9.6 spec/select_spec.rb
aub-record_filter-0.9.7 spec/select_spec.rb
outoftime-record_filter-0.2.0 spec/select_spec.rb
outoftime-record_filter-0.6.0 spec/select_spec.rb
outoftime-record_filter-0.8.0 spec/select_spec.rb