Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Try reloading model on class mismatch [#229 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
- Loading branch information
1 parent
b437a7d
commit 7659fb6
Showing
2 changed files
with
21 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
require "cases/helper" | ||
require 'models/owner' | ||
require 'models/pet' | ||
|
||
class ReloadModelsTest < ActiveRecord::TestCase | ||
def test_has_one_with_reload | ||
pet = Pet.find_by_name('parrot') | ||
pet.owner = Owner.find_by_name('ashley') | ||
|
||
# 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 } | ||
Kernel.load(File.expand_path(File.join(File.dirname(__FILE__), "../models/owner.rb"))) | ||
|
||
pet = Pet.find_by_name('parrot') | ||
pet.owner = Owner.find_by_name('ashley') | ||
assert_equal pet.owner, Owner.find_by_name('ashley') | ||
end | ||
end |