Guest User

Untitled

a guest
May 24th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. require 'pathname'
  2. require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
  3.  
  4. if HAS_SQLITE3
  5. describe DataMapper::AutoMigrations, '.auto_migrate! on STI models with sqlite3' do
  6. before :all do
  7. @adapter = repository(:sqlite3).adapter
  8. @property_class = Struct.new(:type, :serial)
  9. class Comment
  10. include DataMapper::Resource
  11.  
  12. property :id, Integer, :serial => true
  13. property :user_id, Integer
  14. property :content, DM::Text
  15. property :type, Discriminator
  16.  
  17. belongs_to :article
  18. belongs_to :user
  19.  
  20. end
  21.  
  22. class ArticleComment < Comment
  23.  
  24. property :article_id, Integer
  25.  
  26.  
  27. end
  28.  
  29. class User
  30. include DataMapper::Resource
  31.  
  32. property :id, Integer, :serial => true
  33. property :username, String
  34.  
  35. has n, :articles
  36. has n, :comments
  37.  
  38. end
  39.  
  40. class Article
  41. include DataMapper::Resource
  42.  
  43. property :id, Integer, :serial => true
  44. property :user_id, Integer
  45.  
  46. has n, :comments
  47. belongs_to :user
  48. end
  49. end
  50.  
  51. describe "inheritence" do
  52. before :all do
  53. Comment.auto_migrate!(:sqlite3)
  54. User.auto_migrate!(:sqlite3)
  55. Article.auto_migrate!(:sqlite3)
  56. repository(:sqlite3) do
  57. Article.create(:user_id => 1)
  58. User.create(:username => "user")
  59. ArticleComment.create(:article_id => 1, :user_id => 1, :content => "test")
  60. ArticleComment.create(:article_id => 1, :user_id => 1, :content => "test")
  61. end
  62. end
  63.  
  64. it "should be able to name all of the parameters" do
  65. repository(:sqlite3) do
  66. a = Article.first
  67. a.comments.each do |c|
  68. c.user.username.should == User.first.username
  69. c.content.should == "test"
  70. end
  71. end
  72. end
  73. end
  74. end
  75. end
Add Comment
Please, Sign In to add comment