Skip to content

Instantly share code, notes, and snippets.

@spaghetticode
Created January 11, 2021 15:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save spaghetticode/c25e286cf2b2fe769925d4e82520120e to your computer and use it in GitHub Desktop.
Save spaghetticode/c25e286cf2b2fe769925d4e82520120e to your computer and use it in GitHub Desktop.
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