Created
January 11, 2021 15:03
-
-
Save spaghetticode/c25e286cf2b2fe769925d4e82520120e 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
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: "6-0-stable" | |
gem "sqlite3" | |
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 :users, force: true do |t| | |
t.string :name | |
t.timestamps | |
end | |
create_table :addresses, force: true do |t| | |
t.references :user | |
t.string :country | |
t.string :city | |
t.timestamps | |
end | |
end | |
class User < ActiveRecord::Base | |
has_many :addresses, inverse_of: :user | |
end | |
class Address < ActiveRecord::Base | |
belongs_to :user | |
scope :us, -> { where(country: "US") } | |
end | |
ActiveSupport::Deprecation.behavior = :raise | |
class BugTest < Minitest::Test | |
def test_doesnt_raise_deprecation_when_building_single_record | |
user = User.create!(name: 'David') | |
%w[Chicago Miami].each do |city| | |
assert user.addresses.us.build(city: city) | |
end | |
end | |
def test_raises_deprecation_when_building_multiple_records | |
user = User.create!(name: 'David') | |
assert user.addresses.us.build([{city: "Chicago"}, {city: "Miami"}]) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment