Guest User

Untitled

a guest
Feb 21st, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
  2.  
  3. describe DataMapper::Resource, "Transactions" do
  4.  
  5. before do
  6. Object.send(:remove_const, :User) if defined?(User)
  7. class User
  8. include DataMapper::Resource
  9.  
  10. property :name, String, :key => true
  11. property :age, Integer
  12. property :description, Text
  13.  
  14. has n, :comments
  15. end
  16.  
  17. Object.send(:remove_const, :Article) if defined?(Article)
  18. class Article
  19. include DataMapper::Resource
  20.  
  21. property :id, Serial
  22. property :body, Text
  23.  
  24. has n, :paragraphs
  25. end
  26.  
  27. Object.send(:remove_const, :Comment) if defined?(Comment)
  28. class Comment
  29. include DataMapper::Resource
  30.  
  31. property :id, Serial
  32. property :body, Text
  33.  
  34. belongs_to :user
  35. end
  36.  
  37. Object.send(:remove_const, :Paragraph) if defined?(Paragraph)
  38. class Paragraph
  39. include DataMapper::Resource
  40.  
  41. property :id, Integer, :key => true
  42. property :text, String
  43.  
  44. belongs_to :article
  45. end
  46. end
  47.  
  48. supported_by :postgres, :mysql do
  49.  
  50. describe "when the resource is created inside the transaction" do
  51.  
  52. before do
  53. # --- Temporary private api use to get around rspec limitations ---
  54. repository(:default) do
  55. transaction = DataMapper::Transaction.new(repository)
  56. transaction.begin
  57. repository.adapter.push_transaction(transaction)
  58. end
  59.  
  60. @model = User
  61. @child_model = Comment
  62. @user = @model.create(:name => 'dbussink', :age => 25, :description => "Test")
  63. end
  64.  
  65. after do
  66. repository = repository(:default)
  67. while repository.adapter.current_transaction
  68. repository.adapter.current_transaction.rollback
  69. repository.adapter.pop_transaction
  70. end
  71. end
  72.  
  73. it_should_behave_like 'A public Resource'
  74.  
  75. end
  76.  
  77. describe "when the resource is created outside the transaction" do
  78.  
  79. before do
  80. @model = User
  81. @child_model = Comment
  82. @user = @model.create(:name => 'dbussink', :age => 25, :description => "Test")
  83.  
  84. # --- Temporary private api use to get around rspec limitations ---
  85. repository(:default) do
  86. transaction = DataMapper::Transaction.new(repository)
  87. transaction.begin
  88. repository.adapter.push_transaction(transaction)
  89. end
  90. end
  91.  
  92. after do
  93. repository = repository(:default)
  94. while repository.adapter.current_transaction
  95. repository.adapter.current_transaction.rollback
  96. repository.adapter.pop_transaction
  97. end
  98. end
  99.  
  100. it_should_behave_like 'A public Resource'
  101.  
  102. end
  103. end
  104.  
  105. end
Add Comment
Please, Sign In to add comment