Created
October 4, 2009 18:20
-
-
Save djsun/201533 to your computer and use it in GitHub Desktop.
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
require 'test_helper' | |
require 'models' | |
class BelongsToProxyTest < Test::Unit::TestCase | |
def setup | |
clear_all_collections | |
end | |
should "default to nil" do | |
status = Status.new | |
status.project.should be_nil # !!! | |
status.project.should be_true # !!! | |
end | |
should "be able to replace the association" do | |
status = Status.new | |
project = Project.new(:name => "mongomapper") | |
status.project = project | |
status.save.should be_true | |
from_db = Status.find(status.id) | |
from_db.project.should_not be_nil | |
from_db.project.name.should == "mongomapper" | |
end | |
should "unset the association" do | |
status = Status.new | |
project = Project.new(:name => "mongomapper") | |
status.project = project | |
status.save.should be_true | |
from_db = Status.find(status.id) | |
from_db.project = nil | |
from_db.project.should be_nil # !!! | |
from_db.project.should be_true # !!! | |
end | |
context "association id set but document not found" do | |
setup do | |
@status = Status.new(:name => 'Foo', :project_id => '1234') | |
end | |
should "return nil instead of raising error" do | |
@status.project.should be_nil # !!! | |
@status.project.should be_true # !!! | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment