Last active
December 25, 2015 21:49
-
-
Save groeneman/7045339 to your computer and use it in GitHub Desktop.
Staleness in long-lived instantiations of the same object
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
it "guards against stale objects by checking a fresh instance before creating a duplciate account" do | |
@d = Dummy.create | |
# Hey, I somehow have an extra instance of this object! | |
@d2 = Dummy.find(@d.id) | |
# And I set up an account by calling from my original instance | |
d1s_account = @d.account(AC_AR) | |
# My original instance got the account back and stored it just fine | |
d1s_account.id.should_not be_nil | |
@d.account_id(AC_AR).should eq(d1s_account) | |
# If I create a new instance now, it'll have the account ID as we expect | |
Dummy.find(@d.id).account_id(AC_AR).should eq(d1s_account) | |
# But the stale old object from the beginning doesn't have the ID | |
@d2.account_id(AC_AR).should be_nil | |
# Good thing we do an extra check before we create a duplicate account | |
@d2.account(AC_AR).should eq(d1s_account) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment