Sha256: 1c418c04fa6b83831f620e8f4ce47effc725e5cb5a49513323855b9dcd5f8a32

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require "#{File.dirname(__FILE__)}/../spec_helper"

describe SQLTree::Node::InsertQuery do
  
  it "should parse an insert query without field list correctly" do
    insert = SQLTree::Node::InsertQuery["INSERT INTO table VALUES (1, 'two', 3+4, MD5('$ecret'))"]
    insert.table.should == 'table'
    insert.fields.should be_nil
    insert.values.should have(4).items
    insert.values[0].should == SQLTree::Node::Value.new(1)
    insert.values[1].should == SQLTree::Node::Value.new('two')
    insert.values[2].should be_kind_of(SQLTree::Node::ArithmeticExpression)
    insert.values[3].should be_kind_of(SQLTree::Node::FunctionExpression)
  end
  
  it "should parse an insert query with field list" do
    insert = SQLTree::Node::InsertQuery['INSERT INTO table ("field1", "field2") VALUES (1, 2)']
    insert.table.should == 'table'
    insert.fields.should have(2).items
    insert.fields[0].should == SQLTree::Node::Variable.new('field1')
    insert.fields[1].should == SQLTree::Node::Variable.new('field2')
    insert.values.should have(2).items
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sql_tree-0.1.0 spec/unit/insert_query_spec.rb