Created
February 27, 2021 14:01
-
-
Save boblail/b94c8671d8b537eeb5e2ba298945d042 to your computer and use it in GitHub Desktop.
Active Record Test single file
This file contains 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", branch: "master" | |
gem "mysql2" | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
ActiveRecord::Base.establish_connection(adapter: "mysql2", database: "activerecord_unittest") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :articles, force: true do |t| | |
t.string :title, null: false | |
t.string :slug, null: false | |
t.string :author, null: false | |
t.index :slug, unique: true | |
end | |
end | |
class Article < ActiveRecord::Base; end | |
class BugTest < Minitest::Test | |
def test_upsert_all | |
Article.insert_all( | |
[ | |
{ title: "Article 1", slug: "article", author: "Jane" }, | |
{ title: "Article 2", slug: "article", author: "John" } | |
] | |
) | |
assert_equal 1, Article.count | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment