Sha256: fef11264ffbe921ebe204c70041fe641818d3c494622f95647c32858895b7cfe

Contents?: true

Size: 1.91 KB

Versions: 7

Compression:

Stored size: 1.91 KB

Contents

require '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_should_behave_like 'A semipublic Subject'
    end
  end
end

Version data entries

7 entries across 7 versions & 3 rubygems

Version Path
ardm-core-1.3.0 spec/semipublic/associations/one_to_many_spec.rb
ardm-core-1.2.1 spec/semipublic/associations/one_to_many_spec.rb
dm-core-1.2.1 spec/semipublic/associations/one_to_many_spec.rb
ghost_dm-core-1.3.0.beta spec/semipublic/associations/one_to_many_spec.rb
dm-core-1.2.0 spec/semipublic/associations/one_to_many_spec.rb
dm-core-1.2.0.rc2 spec/semipublic/associations/one_to_many_spec.rb
dm-core-1.2.0.rc1 spec/semipublic/associations/one_to_many_spec.rb