Sha256: 64187b71d452bfe74fa7e26a0976f48e0004a06b1fe7c4fe8547e2b52946162e

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe SQL::Generator::Relation, '#to_s' do
  subject { object.to_s }

  let(:described_class) { Class.new(SQL::Generator::Relation)              }
  let(:id)              { Attribute::Integer.new(:id)                      }
  let(:name)            { Attribute::String.new(:name)                     }
  let(:age)             { Attribute::Integer.new(:age, :required => false) }
  let(:header)          { [ id, name, age ]                                }
  let(:body)            { [ [ 1, 'Dan Kubb', 35 ] ].each                   }
  let(:base_relation)   { Relation::Base.new('users', header, body)        }
  let(:object)          { described_class.new                              }

  context 'when no object visited' do
    it_should_behave_like 'an idempotent method'

    it { should respond_to(:to_s) }

    it { should be_frozen }

    its(:to_s) { should == '' }
  end

  context 'when an object is visited' do
    let(:visitable) { mock('Visitable') }

    before do
      described_class.class_eval do
        def visit_spec_mocks_mock(mock)
          @name     = mock.instance_variable_get(:@name)
          @distinct = 'DISTINCT'
          @scope    = Set.new
        end

        def generate_sql(columns)
          "SELECT #{columns} FROM #{@name}"
        end
      end

      object.visit(visitable)
    end

    it_should_behave_like 'a generated SQL expression'

    its(:to_s) { should eql('SELECT DISTINCT FROM Visitable') }
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
veritas-sql-generator-0.0.7 spec/unit/veritas/sql/generator/relation/to_s_spec.rb
veritas-sql-generator-0.0.6 spec/unit/veritas/sql/generator/relation/to_s_spec.rb
veritas-sql-generator-0.0.5 spec/unit/veritas/sql/generator/relation/to_s_spec.rb
veritas-sql-generator-0.0.4 spec/unit/veritas/sql/generator/relation/to_s_spec.rb