Sha256: 99fbd33644a3e0435e97af23c58ead7bbbc29992c650e65af5cb092e8a9022c0

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

# encoding: utf-8

require 'spec_helper'

describe SQL::Generator::Relation, '.visit' do
  subject { object.visit(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                                  }

  context 'when the relation is a set operation' do
    let(:relation) { base_relation.union(base_relation) }

    it { should be_kind_of(SQL::Generator::Relation::Set) }

    its(:name) { should == 'users' }

    it { should be_frozen }
  end

  context 'when the relation is a binary operation' do
    let(:relation) { base_relation.join(base_relation.project([ :id ])) }

    it { should be_kind_of(SQL::Generator::Relation::Binary) }

    its(:name) { should == 'users' }

    it { should be_frozen }
  end

  context 'when the relation is a unary operation' do
    let(:relation) { base_relation.project([ :id ]) }

    it { should be_kind_of(SQL::Generator::Relation::Unary) }

    its(:name) { should == 'users' }

    it { should be_frozen }
  end

  context 'when the relation is a base relation' do
    let(:relation) { base_relation }

    it { should be_kind_of(SQL::Generator::Relation::Base) }

    its(:name) { should == 'users' }

    it { should be_frozen }
  end

  context 'when the relation is invalid' do
    let(:relation) { mock('Invalid Relation') }

    specify { expect { subject }.to raise_error(SQL::Generator::InvalidRelationError, "#{relation.class} is not a visitable relation") }
  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/class_methods/visit_spec.rb
veritas-sql-generator-0.0.6 spec/unit/veritas/sql/generator/relation/class_methods/visit_spec.rb
veritas-sql-generator-0.0.5 spec/unit/veritas/sql/generator/relation/class_methods/visit_spec.rb
veritas-sql-generator-0.0.4 spec/unit/veritas/sql/generator/relation/class_methods/visit_spec.rb