Created
March 8, 2019 05:11
-
-
Save vishaltelangre/ba7ad59509f1140631ca45e6d7d48595 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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