Sha256: 10e6f329b464d8a3d094a0a39fc75799ba2c9572e47b5a1158eefe46c0292e54
Contents?: true
Size: 1.83 KB
Versions: 2
Compression:
Stored size: 1.83 KB
Contents
require_relative '../../spec_helper' describe 'One to One Associations' do before :all do module ::Blog class Article include DataMapper::Resource property :title, String, :key => true property :body, Text, :required => true end class Author include DataMapper::Resource property :name, String, :key => true belongs_to :without_default, 'Article', :child_key => [ :without_default_id ], :required => false belongs_to :with_default, 'Article', :child_key => [ :with_default_id ], :required => false belongs_to :with_default_callable, 'Article', :child_key => [ :with_default_callable_id ], :required => false end end @article_model = Blog::Article @author_model = Blog::Author DataMapper.finalize @default_value = @author_model.new(:name => 'Dan Kubb') @default_value_callable = @author_model.new(:name => 'John Doe') @subject_without_default = @article_model.has(1, :without_default, @author_model, :child_key => [ :without_default_id ]) @subject_with_default = @article_model.has(1, :with_default, @author_model, :child_key => [ :with_default_id ], :default => @default_value) @subject_with_default_callable = @article_model.has(1, :with_default_callable, @author_model, :child_key => [ :with_default_callable_id ], :default => lambda { |resource, relationship| @default_value_callable }) DataMapper.finalize end supported_by :all do before :all do @default_value.save @default_value_callable.save end describe 'acts like a subject' do before do @resource = @article_model.new(:title => 'DataMapper Rocks!', :body => 'TSIA') end it_behaves_like 'A semipublic Subject' end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
sbf-dm-core-1.3.0 | spec/semipublic/associations/one_to_one_spec.rb |
sbf-dm-core-1.3.0.beta | spec/semipublic/associations/one_to_one_spec.rb |