Skip to content

Instantly share code, notes, and snippets.

@djsun
Created October 4, 2009 18:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save djsun/201533 to your computer and use it in GitHub Desktop.
Save djsun/201533 to your computer and use it in GitHub Desktop.
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