Skip to content

Instantly share code, notes, and snippets.

@kuldeepaggarwal
Last active December 31, 2015 18:29
Show Gist options
  • Save kuldeepaggarwal/8026843 to your computer and use it in GitHub Desktop.
Save kuldeepaggarwal/8026843 to your computer and use it in GitHub Desktop.
Rails Issue#13378
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'pg'
GEMFILE
system 'bundle'
end
require 'bundler'
Bundler.setup(:default)
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
ActiveRecord::Base.establish_connection(
adapter: 'postgresql',
encoding: 'utf8',
database: 'kd_test',
username: 'postgres',
password: '',
host: 'localhost'
)
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :articles, force: true do |t|
t.integer :number
end
end
class Article < ActiveRecord::Base
end
class BugTest < Minitest::Test
def test_multiline_insert_sql
connection = ActiveRecord::Base.connection
id = connection.insert_sql(<<-SQL)
insert into articles(
number)
values(
5152
)
SQL
expect = connection.query('select max(id) from articles').first.first
assert_equal expect, id
end
end
Output:
-- create_table(:articles, {:force=>true})
D, [2013-12-19T00:45:25.744734 #81931] DEBUG -- : (9.3ms) DROP TABLE "articles"
D, [2013-12-19T00:45:25.749148 #81931] DEBUG -- : (4.1ms) CREATE TABLE "articles" ("id" serial primary key, "number" integer)
-> 0.0487s
Run options: --seed 19220
# Running:
D, [2013-12-19T00:45:25.767565 #81931] DEBUG -- : (1.2ms) insert into articles(
number)
values(
5152
)
D, [2013-12-19T00:45:25.768431 #81931] DEBUG -- : (0.7ms) select max(id) from articles
F
Finished in 0.008476s, 117.9802 runs/s, 117.9802 assertions/s.
1) Failure:
BugTest#test_multiline_insert_sql [has_one_and_has_many.rb:50]:
Expected: "1"
Actual: nil
1 runs, 1 assertions, 1 failures, 0 errors, 0 skips
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment