Sha256: f5260f49367eaa36a2f20f3f249e98a40839a860f563c16dec6ccf3206f1cc71

Contents?: true

Size: 1.36 KB

Versions: 4

Compression:

Stored size: 1.36 KB

Contents

require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))

describe 'SEL', 'with STI subclasses' do
  before :all do
    module ::Blog
      class Author
        include DataMapper::Resource

        property :id,   Serial
        property :name, String

        has n, :messages
      end

      class Message
        include DataMapper::Resource

        property :id,    Serial
        property :type,  Discriminator
        property :title, String, :required => true

        belongs_to :author
      end

      class Article < Message; end
      class Comment < Message; end
    end

    DataMapper.finalize

    @author_model  = Blog::Author
    @message_model = Blog::Message
    @article_model = Blog::Article
    @comment_model = Blog::Comment
  end

  supported_by :all do
    before :all do
      author1 = @author_model.create(:name => 'Dan Kubb')
      author2 = @author_model.create(:name => 'Sindre Aarsaether')

      @article_model.create(:title => 'SEL',               :author => author1)
      @article_model.create(:title => 'STI',               :author => author1)
      @comment_model.create(:title => 'SEL and STI error', :author => author2)
    end

    it 'should allow STI loading of mixed relationships' do
      lambda {
        @message_model.all.each { |message| message.author }
      }.should_not raise_error(ArgumentError)
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
dm-core-1.0.2 spec/public/sel_spec.rb
dm-core-1.0.1 spec/public/sel_spec.rb
dm-core-1.0.0 spec/public/sel_spec.rb
dm-core-1.0.0.rc3 spec/public/sel_spec.rb