Skip to content

Instantly share code, notes, and snippets.

@alipman88
Last active December 3, 2019 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save alipman88/d499739a466f3e6b6746eeccfa567f9a to your computer and use it in GitHub Desktop.
Save alipman88/d499739a466f3e6b6746eeccfa567f9a to your computer and use it in GitHub Desktop.
Association Cache Test
# 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", "6.0.2.rc1"
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 :customers, force: true do |t|
end
create_table :appointments, force: true do |t|
t.references :customer
end
end
class Customer < ActiveRecord::Base
has_many :appointments
end
class Appointment < ActiveRecord::Base
belongs_to :customer
end
class BugTest < Minitest::Test
def test_association_cache
@customer = Customer.create
a = Appointment.new(customer_id: @customer.id)
assert_instance_of Customer, a.association(:customer).reader
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment