Sha256: 05365e036a2f1e36790ca3570606ba4c53c9a112ca59014b5ee3dfc9135bd702

Contents?: true

Size: 1.23 KB

Versions: 1

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'

describe ThinkingSphinx::ActiveRecord::ColumnSQLPresenter do
  describe '#with_table' do
    let(:model)        { double 'Model' }
    let(:column)       { double 'Column', :__name => 'column_name',
      :__stack => [], :string? => false }
    let(:adapter)      { double 'Adapter' }
    let(:associations) { double 'Associations' }
    let(:path)         { double 'Path',
      :model => double(:column_names => ['column_name']) }
    let(:presenter) { ThinkingSphinx::ActiveRecord::ColumnSQLPresenter.new(
      model, column, adapter, associations
    ) }

    before do
      stub_const 'Joiner::Path', double(:new => path)
      adapter.stub(:quote) { |arg| "`#{arg}`" }
    end

    context "when there's no explicit db name" do
      before { associations.stub(:alias_for => 'table_name') }

      it 'returns quoted table and column names' do
        presenter.with_table.should == '`table_name`.`column_name`'
      end
    end

    context 'when an eplicit db name is provided' do
      before { associations.stub(:alias_for => 'db_name.table_name') }

      it 'returns properly quoted table name with column name' do
        presenter.with_table.should == '`db_name`.`table_name`.`column_name`'
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thinking-sphinx-3.2.0 spec/thinking_sphinx/active_record/column_sql_presenter_spec.rb