File: insert_spec.rb

package info (click to toggle)
ruby-riddle 2.3.1-2~deb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 10,752 kB
  • sloc: sql: 25,022; php: 5,992; ruby: 4,757; sh: 59; makefile: 5
file content (27 lines) | stat: -rw-r--r-- 959 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# frozen_string_literal: true

require 'spec_helper'

describe Riddle::Query::Insert do
  it 'handles inserts' do
    query = Riddle::Query::Insert.new('foo_core', [:id, :deleted], [4, false])
    query.to_sql.should == 'INSERT INTO foo_core (id, `deleted`) VALUES (4, 0)'
  end

  it 'handles replaces' do
    query = Riddle::Query::Insert.new('foo_core', [:id, :deleted], [4, false])
    query.replace!
    query.to_sql.should == 'REPLACE INTO foo_core (id, `deleted`) VALUES (4, 0)'
  end

  it 'encloses strings in single quotes' do
    query = Riddle::Query::Insert.new('foo_core', [:id, :name], [4, 'bar'])
    query.to_sql.should == "INSERT INTO foo_core (id, `name`) VALUES (4, 'bar')"
  end

  it 'handles inserts with more than one set of values' do
    query = Riddle::Query::Insert.new 'foo_core', [:id, :name], [[4, 'bar'], [5, 'baz']]
    query.to_sql.
      should == "INSERT INTO foo_core (id, `name`) VALUES (4, 'bar'), (5, 'baz')"
  end
end