Sha256: 7e8a1e1942daf2c58ca52ef123379b679d3d9a675573465e2261536929695013

Contents?: true

Size: 1.97 KB

Versions: 9

Compression:

Stored size: 1.97 KB

Contents

require 'spec_helper'

describe 'Many to One Associations' do
  before :all do
    module ::Blog
      class User
        include DataMapper::Resource

        property :name,        String, :key => true
        property :age,         Integer
        property :summary,     Text
        property :description, Text
        property :admin,       Boolean, :accessor => :private

        belongs_to :parent, self, :required => false
        has n, :children, self, :inverse => :parent

        belongs_to :referrer, self, :required => false
        has n, :comments

        # FIXME: figure out a different approach than stubbing things out
        def comment=(*)
          # do nothing with comment
        end
      end

      class Author < User; end

      class Comment
        include DataMapper::Resource

        property :id,   Serial
        property :body, Text

        belongs_to :user
      end

      class Article
        include DataMapper::Resource

        property :id,   Serial
        property :body, Text

        has n, :paragraphs
      end

      class Paragraph
        include DataMapper::Resource

        property :id,   Serial
        property :text, String

        belongs_to :article
      end
    end

    class ::Default
      include DataMapper::Resource

      property :name, String, :key => true, :default => 'a default value'
    end
    DataMapper.finalize

    @user_model      = Blog::User
    @author_model    = Blog::Author
    @comment_model   = Blog::Comment
    @article_model   = Blog::Article
    @paragraph_model = Blog::Paragraph
  end

  supported_by :all do
    before :all do
      user    = @user_model.create(:name => 'dbussink', :age => 25, :description => 'Test')
      comment = @comment_model.create(:body => 'Cool spec', :user => user)

      @comment = @comment_model.get(*comment.key)
      @user    = @comment.user
    end

    it_should_behave_like 'A public Resource'
    it_should_behave_like 'A Resource supporting Strategic Eager Loading'
  end
end

Version data entries

9 entries across 9 versions & 3 rubygems

Version Path
ardm-core-1.2.1 spec/public/associations/many_to_one_spec.rb
ghost_dm-core-1.3.0.beta spec/public/associations/many_to_one_spec.rb
dm-core-1.2.0 spec/public/associations/many_to_one_spec.rb
dm-core-1.2.0.rc2 spec/public/associations/many_to_one_spec.rb
dm-core-1.2.0.rc1 spec/public/associations/many_to_one_spec.rb
dm-core-1.1.0 spec/public/associations/many_to_one_spec.rb
dm-core-1.1.0.rc3 spec/public/associations/many_to_one_spec.rb
dm-core-1.1.0.rc2 spec/public/associations/many_to_one_spec.rb
dm-core-1.1.0.rc1 spec/public/associations/many_to_one_spec.rb