Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'pathname'
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
- if HAS_SQLITE3
- describe DataMapper::AutoMigrations, '.auto_migrate! on STI models with sqlite3' do
- before :all do
- @adapter = repository(:sqlite3).adapter
- @property_class = Struct.new(:type, :serial)
- class Comment
- include DataMapper::Resource
- property :id, Integer, :serial => true
- property :user_id, Integer
- property :content, DM::Text
- property :type, Discriminator
- belongs_to :article
- belongs_to :user
- end
- class ArticleComment < Comment
- property :article_id, Integer
- end
- class User
- include DataMapper::Resource
- property :id, Integer, :serial => true
- property :username, String
- has n, :articles
- has n, :comments
- end
- class Article
- include DataMapper::Resource
- property :id, Integer, :serial => true
- property :user_id, Integer
- has n, :comments
- belongs_to :user
- end
- end
- describe "inheritence" do
- before :all do
- Comment.auto_migrate!(:sqlite3)
- User.auto_migrate!(:sqlite3)
- Article.auto_migrate!(:sqlite3)
- repository(:sqlite3) do
- Article.create(:user_id => 1)
- User.create(:username => "user")
- ArticleComment.create(:article_id => 1, :user_id => 1, :content => "test")
- ArticleComment.create(:article_id => 1, :user_id => 1, :content => "test")
- end
- end
- it "should be able to name all of the parameters" do
- repository(:sqlite3) do
- a = Article.first
- a.comments.each do |c|
- c.user.username.should == User.first.username
- c.content.should == "test"
- end
- end
- end
- end
- end
- end
Add Comment
Please, Sign In to add comment