Guest User

Untitled

a guest
Feb 20th, 2018
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.97 KB | None | 0 0
  1. require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
  2.  
  3. def with_adapters(*adapters)
  4. adapters = if !adapters.empty?
  5. ADAPTERS.only(*adapters)
  6. elsif ENV['ADAPTERS'] == 'all'
  7. ADAPTERS
  8. else
  9. ADAPTERS.only(*ENV['ADAPTERS'].strip.downcase.split(/\s+/))
  10. end
  11.  
  12. adapters.each do |adapter, connection_uri|
  13. if adapters.length > 1
  14. describe "with #{adapter}" do
  15.  
  16. before(:each) do
  17. DataMapper.setup(:default, connection_uri)
  18. DataMapper.auto_migrate!
  19. end
  20.  
  21. yield adapter
  22. end
  23. else
  24. before(:each) do
  25. DataMapper.setup(:default, connection_uri)
  26. DataMapper.auto_migrate!
  27. end
  28.  
  29. yield adapter
  30. end
  31. end
  32. end
  33.  
  34. def with_alternate
  35. # This would actually loop through all the alternate
  36. # adapters, but I'm too tired to finish it up
  37. if @adapter == 'mysql'
  38. DataMapper.setup(:alternate, ALTERNATE['postgres'])
  39. else
  40. DataMapper.setup(:alternate, ALTERNATE['mysql'])
  41. end
  42. end
  43.  
  44. describe DataMapper::Resource do
  45.  
  46. before(:each) do
  47. Object.send(:remove_const, :User) if defined?(User)
  48. class User
  49. include DataMapper::Resource
  50.  
  51. property :id, Integer, :key => true
  52. property :name, String
  53. end
  54.  
  55. # This is a special class that needs to be an exact copy of User
  56. Object.send(:remove_const, :Clone) if defined?(Clone)
  57. class Clone
  58. include DataMapper::Resource
  59.  
  60. property :id, Integer, :key => true
  61. property :name, String
  62. end
  63. end
  64.  
  65. with_adapters do |adapter|
  66.  
  67. describe "#eql?" do
  68.  
  69. it "should be true when they are the same objects" do
  70. user = User.new
  71. user.should be_eql(user)
  72. end
  73.  
  74. it "should be false when they are instances of different classes" do
  75. User.new(:name => "John").should_not be_eql(Clone.new(:name => "John"))
  76. User.create(:name => "John").should_not be_eql(Clone.create(:name => "John"))
  77. end
  78.  
  79. it "should be true when they are instances from the same repository, the keys are the same, and properties are the same" do
  80. user = User.create(:name => "Bill", :id => 1)
  81. user.should be_eql(User.get(1))
  82. end
  83.  
  84. it "should be true when they are instances from the same repository, the keys are the same, but the attributes differ" do
  85. user = User.create(:name => "Bill", :id => 1)
  86. user.name = "John"
  87. user.should be_eql(User.get(1))
  88. end
  89.  
  90. with_alternate do
  91. it "should be true when they are instances from different repositories, but the keys and attributes are the same" do
  92. pending
  93. user = User.create(:name => "Bill", :id => 5)
  94. other = repository(:alternate) { User.create(:name => "Bill", :id => 5) }
  95. user.should be_eql(other)
  96. end
  97. end
  98.  
  99. it "should be true when they are different " do
  100.  
  101. end
  102.  
  103. end
  104. end
  105. end
Add Comment
Please, Sign In to add comment