Skip to content

Instantly share code, notes, and snippets.

@vishaltelangre
Created March 8, 2019 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vishaltelangre/ba7ad59509f1140631ca45e6d7d48595 to your computer and use it in GitHub Desktop.
Save vishaltelangre/ba7ad59509f1140631ca45e6d7d48595 to your computer and use it in GitHub Desktop.
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails"
gem "pg"
end
require "active_record"
require "minitest/autorun"
require "logger"
ActiveRecord::Base.establish_connection(adapter: "postgresql", database: "upsert_all_issue", username: "postgres", password: "")
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
create_table :books, force: true do |t|
t.string :title, null: false
t.string :author, null: false
t.string :isbn, null: false
t.index :isbn, unique: true
end
end
class Book < ActiveRecord::Base; end
class BugTest < Minitest::Test
def test_upsert_all
Book.upsert_all(
[
{ title: 'Rework', author: 'David', isbn: '1' },
{ title: 'Eloquent Ruby', author: 'Russ', isbn: '1' }
],
unique_by: { columns: %w[ isbn ] }
)
assert_equal("Eloquent Ruby", Book.first.title)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment