2017-07-09 13:41:28 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2011-06-06 14:17:44 -04:00
|
|
|
require "cases/helper"
|
2016-08-06 12:26:20 -04:00
|
|
|
require "models/owner"
|
|
|
|
require "models/pet"
|
2008-10-04 10:31:04 -04:00
|
|
|
|
|
|
|
class ReloadModelsTest < ActiveRecord::TestCase
|
2017-04-27 04:10:04 -04:00
|
|
|
include ActiveSupport::Testing::Isolation
|
|
|
|
|
2015-06-19 15:02:12 -04:00
|
|
|
fixtures :pets, :owners
|
2008-12-20 15:05:53 -05:00
|
|
|
|
2008-10-04 10:31:04 -04:00
|
|
|
def test_has_one_with_reload
|
2016-08-06 12:26:20 -04:00
|
|
|
pet = Pet.find_by_name("parrot")
|
|
|
|
pet.owner = Owner.find_by_name("ashley")
|
2008-10-04 10:31:04 -04:00
|
|
|
|
|
|
|
# Reload the class Owner, simulating auto-reloading of model classes in a
|
|
|
|
# development environment. Note that meanwhile the class Pet is not
|
|
|
|
# reloaded, simulating a class that is present in a plugin.
|
|
|
|
Object.class_eval { remove_const :Owner }
|
2017-05-15 10:17:28 -04:00
|
|
|
Kernel.load(File.expand_path("../models/owner.rb", __dir__))
|
2008-10-04 10:31:04 -04:00
|
|
|
|
2016-08-06 12:26:20 -04:00
|
|
|
pet = Pet.find_by_name("parrot")
|
|
|
|
pet.owner = Owner.find_by_name("ashley")
|
|
|
|
assert_equal pet.owner, Owner.find_by_name("ashley")
|
2008-10-04 10:31:04 -04:00
|
|
|
end
|
2017-04-27 04:10:04 -04:00
|
|
|
end unless in_memory_db?
|