Sha256: e704d2c1ab033e270fbed52372e4ed17daccdee3bbb57724402216795e2ff1dd
Contents?: true
Size: 1.92 KB
Versions: 2
Compression:
Stored size: 1.92 KB
Contents
require_relative '../../spec_helper' describe 'One to Many 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 n = @article_model.n @default_value = [ @author_model.new(:name => 'Dan Kubb') ] @default_value_callable = [ @author_model.new(:name => 'John Doe') ] @subject_without_default = @article_model.has(n, :without_default, @author_model, :child_key => [ :without_default_id ]) @subject_with_default = @article_model.has(n, :with_default, @author_model, :child_key => [ :with_default_id ], :default => @default_value) @subject_with_default_callable = @article_model.has(n, :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.each { |resource| resource.save } @default_value_callable.each { |resource| resource.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_many_spec.rb |
sbf-dm-core-1.3.0.beta | spec/semipublic/associations/one_to_many_spec.rb |