Skip to content

Instantly share code, notes, and snippets.

@snusnu
Created June 12, 2009 14:46
Show Gist options
  • Save snusnu/128669 to your computer and use it in GitHub Desktop.
Save snusnu/128669 to your computer and use it in GitHub Desktop.
require "rubygems"
require "dm-core"
require "spec"
DataMapper.setup(:default, "sqlite3::memory:")
class Person
include DataMapper::Resource
property :id, Serial
has 1, :profile
end
class Profile
include DataMapper::Resource
property :id, Serial
property :person_id, Integer, :nullable => false
belongs_to :person
end
describe "DataMapper::Associations::OneToOne::Relationship" do
before(:each) do
DataMapper.auto_migrate!
end
it "should allow to assign an already created resource" do
person = Person.create
profile = Profile.create(:person => person)
person.profile = profile
person.save
Person.all.size.should == 1
Profile.all.size.should == 0
end
end
# NoMethodError in 'DataMapper::Associations::OneToOne::Relationship should allow to assign an already created resource'
# undefined method `any?' for nil:NilClass
# /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:827:in `child_associations'
# /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:818:in `each_value'
# /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:818:in `child_associations'
# /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:714:in `save_children'
# /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:706:in `_save'
# /opt/local/lib/ruby/gems/1.8/gems/dm-core-0.10.0/lib/dm-core/resource.rb:339:in `save'
# /opt/local/lib/ruby/gems/1.8/gems/dm-validations-0.10.0/lib/dm-validations.rb:56:in `save'
# ./test.rb:28:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment