Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# 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
You can’t perform that action at this time.