Last active
June 2, 2022 18:19
-
-
Save Thomascountz/ab087279672656cb3d23785aad7b8684 to your computer and use it in GitHub Desktop.
activerecord test script for PR#45036 experimentation
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 do | |
source "https://rubygems.org" | |
# gem "activerecord", github: "thomascountz/rails", ref: "5942211feba53c8deec8884bcee109a759c5e60d" | |
gem "activerecord", path: "/worspaces/rails" | |
gem "sqlite3" | |
gem "pry" # <-- ADD THIS!! | |
end | |
require "active_record" | |
require "minitest/autorun" | |
require "logger" | |
ActiveRecord::Base.establish_connection(adapter: "sqlite3", database: ":memory:") | |
ActiveRecord::Base.logger = Logger.new(STDOUT) | |
ActiveRecord::Schema.define do | |
create_table :books, force: true do |t| | |
t.string :name | |
end | |
end | |
class Book < ActiveRecord::Base | |
alias_attribute :title, :name | |
end | |
class BugTest < Minitest::Test | |
def test_insert_all | |
assert_raises(ActiveModel::UnknownAttributeError, "unknown attribute 'title' for Book.") do | |
Book.insert_all [{ title: "Hello, Bug!" }] | |
end | |
end | |
end |
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
From: /workspaces/rails/activerecord/lib/active_record/insert_all.rb:261 ActiveRecord::InsertAll::Builder#extract_types_from_columns_on: | |
260: def extract_types_from_columns_on(table_name, keys:) | |
=> 261: require 'pry'; binding.pry | |
262: columns = connection.schema_cache.columns_hash(table_name) | |
263: | |
264: unknown_column = (keys - columns.keys).first | |
265: raise UnknownAttributeError.new(model.new, unknown_column) if unknown_column | |
266: | |
267: keys.index_with { |key| model.type_for_attribute(key) } | |
268: end | |
[1] pry(#<ActiveRecord::InsertAll::Builder>)> |
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
module ActiveRecord | |
class InsertAll | |
# ...snip... | |
def extract_types_from_columns_on(table_name, keys:) | |
require 'pry'; binding.pry # <-- THIS IS A BREAKPOINT | |
columns = connection.schema_cache.columns_hash(table_name) | |
unknown_column = (keys - columns.keys).first | |
raise UnknownAttributeError.new(model.new, unknown_column) if unknown_column | |
keys.index_with { |key| model.type_for_attribute(key) } | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment