houdini/gems/ruby-qx/test/UpsertTest.rb

21 lines
607 B
Ruby
Raw Normal View History

# frozen_string_literal: true
2019-01-09 23:57:35 +00:00
require './lib/qx.rb'
require 'minitest/autorun'
class UpsertTest < Minitest::Test
def setup; end
2019-01-09 23:57:35 +00:00
def test_upsert
table = 'x'
column1 = 'a'
2019-01-09 23:57:35 +00:00
column2 = 'b'
idx = 'idx_something_more'
2019-01-09 23:57:35 +00:00
result = Qx.insert_into(table).values(column1: column1, column2: column2).on_conflict.upsert(idx).parse
2019-01-09 23:57:35 +00:00
expected = %(INSERT INTO "#{table}" ("column1", "column2") VALUES ($Q$#{column1}$Q$, $Q$#{column2}$Q$) ON CONFLICT ON CONSTRAINT #{idx} DO UPDATE SET "column1" = EXCLUDED."column1", "column2" = EXCLUDED."column2")
2019-01-09 23:57:35 +00:00
assert_equal(expected, result)
end
end