Last active
December 3, 2019 16:04
-
-
Save alipman88/d499739a466f3e6b6746eeccfa567f9a to your computer and use it in GitHub Desktop.
Association Cache Test
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", "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