Sha256: 6b2fb2b5190c2cafe973e4c0aea65fc87f4b008fc3ea376d3241e963fe2239be

Contents?: true

Size: 1.25 KB

Versions: 3

Compression:

Stored size: 1.25 KB

Contents

require 'spec_helper'

describe NQL::Query do

  before :all do
    ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: ":memory:"
    ActiveRecord::Base.connection
    ActiveRecord::Migrator.migrate ActiveRecord::Migrator.migrations_path
  end

  it 'Valid expression' do
    query = NQL::Query.new Country, 'name: Argentina'

    query.text.should eq 'name: Argentina'
    query.expression.should be_a Treetop::Runtime::SyntaxNode
  end

  it 'Valid with empty expression' do
    query = NQL::Query.new Country, ''

    query.text.should eq ''
    query.expression.should be_nil
  end

  it 'Valid with nil expression' do
    query = NQL::Query.new Country, nil

    query.text.should be_nil
    query.expression.should be_nil
  end

  it 'Invalid model type' do
    expect { NQL::Query.new Object, nil }.to raise_error NQL::InvalidModelError
  end

  it 'Invalid expression type' do
    expect { NQL::Query.new Country, Object.new }.to raise_error NQL::DataTypeError
  end

  it 'Invalid expression syntax' do
    expect { NQL::Query.new Country, 'xyz1234' }.to raise_error NQL::SyntaxError
  end

  it 'Invalid fields' do
    expect { NQL::Query.new Country, 'name: Argentina | xyz: 1234 | abc: 0000'}.to raise_error NQL::AttributesNotFoundError
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nql-0.1.2 spec/query_spec.rb
nql-0.1.1 spec/query_spec.rb
nql-0.1.0 spec/query_spec.rb