Sha256: e659662741b4790693b3e9528b238235529b4c5fa885f955bf3b3b70a0ea2fa1

Contents?: true

Size: 1.98 KB

Versions: 4

Compression:

Stored size: 1.98 KB

Contents

require_relative '../../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_behaves_like 'A public Resource'
    it_behaves_like 'A Resource supporting Strategic Eager Loading'
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
sbf-dm-core-1.5.0 spec/public/associations/many_to_one_spec.rb
sbf-dm-core-1.4.0 spec/public/associations/many_to_one_spec.rb
sbf-dm-core-1.3.0 spec/public/associations/many_to_one_spec.rb
sbf-dm-core-1.3.0.beta spec/public/associations/many_to_one_spec.rb