dm-core 0.10.2 → 1.0.0.rc1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (183) hide show
  1. data/.gitignore +10 -1
  2. data/Gemfile +143 -0
  3. data/Rakefile +9 -5
  4. data/VERSION +1 -1
  5. data/dm-core.gemspec +160 -57
  6. data/lib/dm-core.rb +131 -56
  7. data/lib/dm-core/adapters.rb +98 -14
  8. data/lib/dm-core/adapters/abstract_adapter.rb +24 -4
  9. data/lib/dm-core/adapters/in_memory_adapter.rb +7 -2
  10. data/lib/dm-core/associations/many_to_many.rb +19 -30
  11. data/lib/dm-core/associations/many_to_one.rb +58 -42
  12. data/lib/dm-core/associations/one_to_many.rb +33 -23
  13. data/lib/dm-core/associations/one_to_one.rb +27 -11
  14. data/lib/dm-core/associations/relationship.rb +4 -4
  15. data/lib/dm-core/collection.rb +23 -16
  16. data/lib/dm-core/core_ext/array.rb +36 -0
  17. data/lib/dm-core/core_ext/hash.rb +30 -0
  18. data/lib/dm-core/core_ext/module.rb +46 -0
  19. data/lib/dm-core/core_ext/object.rb +31 -0
  20. data/lib/dm-core/core_ext/pathname.rb +20 -0
  21. data/lib/dm-core/core_ext/string.rb +22 -0
  22. data/lib/dm-core/core_ext/try_dup.rb +44 -0
  23. data/lib/dm-core/model.rb +88 -27
  24. data/lib/dm-core/model/hook.rb +75 -18
  25. data/lib/dm-core/model/property.rb +50 -9
  26. data/lib/dm-core/model/relationship.rb +31 -31
  27. data/lib/dm-core/model/scope.rb +3 -3
  28. data/lib/dm-core/property.rb +196 -516
  29. data/lib/dm-core/property/binary.rb +7 -0
  30. data/lib/dm-core/property/boolean.rb +35 -0
  31. data/lib/dm-core/property/class.rb +24 -0
  32. data/lib/dm-core/property/date.rb +47 -0
  33. data/lib/dm-core/property/date_time.rb +48 -0
  34. data/lib/dm-core/property/decimal.rb +43 -0
  35. data/lib/dm-core/property/discriminator.rb +48 -0
  36. data/lib/dm-core/property/float.rb +24 -0
  37. data/lib/dm-core/property/integer.rb +32 -0
  38. data/lib/dm-core/property/numeric.rb +43 -0
  39. data/lib/dm-core/property/object.rb +32 -0
  40. data/lib/dm-core/property/serial.rb +8 -0
  41. data/lib/dm-core/property/string.rb +49 -0
  42. data/lib/dm-core/property/text.rb +12 -0
  43. data/lib/dm-core/property/time.rb +48 -0
  44. data/lib/dm-core/property/typecast/numeric.rb +32 -0
  45. data/lib/dm-core/property/typecast/time.rb +28 -0
  46. data/lib/dm-core/property_set.rb +10 -4
  47. data/lib/dm-core/query.rb +14 -37
  48. data/lib/dm-core/query/conditions/comparison.rb +8 -6
  49. data/lib/dm-core/query/conditions/operation.rb +33 -2
  50. data/lib/dm-core/query/operator.rb +2 -5
  51. data/lib/dm-core/query/path.rb +4 -6
  52. data/lib/dm-core/repository.rb +21 -6
  53. data/lib/dm-core/resource.rb +316 -133
  54. data/lib/dm-core/resource/state.rb +79 -0
  55. data/lib/dm-core/resource/state/clean.rb +40 -0
  56. data/lib/dm-core/resource/state/deleted.rb +30 -0
  57. data/lib/dm-core/resource/state/dirty.rb +86 -0
  58. data/lib/dm-core/resource/state/immutable.rb +34 -0
  59. data/lib/dm-core/resource/state/persisted.rb +29 -0
  60. data/lib/dm-core/resource/state/transient.rb +70 -0
  61. data/lib/dm-core/spec/lib/adapter_helpers.rb +52 -0
  62. data/lib/dm-core/spec/lib/collection_helpers.rb +20 -0
  63. data/{spec → lib/dm-core/spec}/lib/counter_adapter.rb +5 -1
  64. data/lib/dm-core/spec/lib/pending_helpers.rb +50 -0
  65. data/lib/dm-core/spec/lib/spec_helper.rb +68 -0
  66. data/lib/dm-core/spec/setup.rb +165 -0
  67. data/lib/dm-core/spec/{adapter_shared_spec.rb → shared/adapter_spec.rb} +21 -7
  68. data/{spec/public/shared/resource_shared_spec.rb → lib/dm-core/spec/shared/resource_spec.rb} +120 -83
  69. data/{spec/public/shared/sel_shared_spec.rb → lib/dm-core/spec/shared/sel_spec.rb} +5 -6
  70. data/lib/dm-core/support/assertions.rb +8 -0
  71. data/lib/dm-core/support/equalizer.rb +1 -0
  72. data/lib/dm-core/support/hook.rb +420 -0
  73. data/lib/dm-core/support/lazy_array.rb +453 -0
  74. data/lib/dm-core/support/local_object_space.rb +12 -0
  75. data/lib/dm-core/support/logger.rb +193 -6
  76. data/lib/dm-core/support/naming_conventions.rb +8 -8
  77. data/lib/dm-core/support/subject.rb +33 -0
  78. data/lib/dm-core/type.rb +4 -0
  79. data/lib/dm-core/types/boolean.rb +2 -0
  80. data/lib/dm-core/types/decimal.rb +9 -0
  81. data/lib/dm-core/types/discriminator.rb +2 -0
  82. data/lib/dm-core/types/object.rb +3 -0
  83. data/lib/dm-core/types/serial.rb +2 -0
  84. data/lib/dm-core/types/text.rb +2 -0
  85. data/lib/dm-core/version.rb +1 -1
  86. data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +67 -0
  87. data/spec/public/model/hook_spec.rb +209 -0
  88. data/spec/public/model/property_spec.rb +35 -0
  89. data/spec/public/model/relationship_spec.rb +33 -20
  90. data/spec/public/model_spec.rb +142 -10
  91. data/spec/public/property/binary_spec.rb +14 -0
  92. data/spec/public/property/boolean_spec.rb +14 -0
  93. data/spec/public/property/class_spec.rb +20 -0
  94. data/spec/public/property/date_spec.rb +14 -0
  95. data/spec/public/property/date_time_spec.rb +14 -0
  96. data/spec/public/property/decimal_spec.rb +14 -0
  97. data/spec/public/{types → property}/discriminator_spec.rb +2 -12
  98. data/spec/public/property/float_spec.rb +14 -0
  99. data/spec/public/property/integer_spec.rb +14 -0
  100. data/spec/public/property/object_spec.rb +9 -17
  101. data/spec/public/property/serial_spec.rb +14 -0
  102. data/spec/public/property/string_spec.rb +14 -0
  103. data/spec/public/property/text_spec.rb +52 -0
  104. data/spec/public/property/time_spec.rb +14 -0
  105. data/spec/public/property_spec.rb +28 -87
  106. data/spec/public/resource_spec.rb +101 -0
  107. data/spec/public/sel_spec.rb +5 -15
  108. data/spec/public/shared/collection_shared_spec.rb +16 -30
  109. data/spec/public/shared/finder_shared_spec.rb +2 -4
  110. data/spec/public/shared/property_shared_spec.rb +176 -0
  111. data/spec/semipublic/adapters/abstract_adapter_spec.rb +1 -1
  112. data/spec/semipublic/adapters/in_memory_adapter_spec.rb +2 -2
  113. data/spec/semipublic/associations/many_to_many_spec.rb +89 -0
  114. data/spec/semipublic/associations/many_to_one_spec.rb +24 -1
  115. data/spec/semipublic/associations/one_to_many_spec.rb +51 -0
  116. data/spec/semipublic/associations/one_to_one_spec.rb +49 -0
  117. data/spec/semipublic/associations/relationship_spec.rb +3 -3
  118. data/spec/semipublic/associations_spec.rb +1 -1
  119. data/spec/semipublic/property/binary_spec.rb +13 -0
  120. data/spec/semipublic/property/boolean_spec.rb +65 -0
  121. data/spec/semipublic/property/class_spec.rb +33 -0
  122. data/spec/semipublic/property/date_spec.rb +43 -0
  123. data/spec/semipublic/property/date_time_spec.rb +46 -0
  124. data/spec/semipublic/property/decimal_spec.rb +82 -0
  125. data/spec/semipublic/property/discriminator_spec.rb +19 -0
  126. data/spec/semipublic/property/float_spec.rb +82 -0
  127. data/spec/semipublic/property/integer_spec.rb +82 -0
  128. data/spec/semipublic/property/serial_spec.rb +13 -0
  129. data/spec/semipublic/property/string_spec.rb +13 -0
  130. data/spec/semipublic/property/text_spec.rb +31 -0
  131. data/spec/semipublic/property/time_spec.rb +50 -0
  132. data/spec/semipublic/property_spec.rb +2 -532
  133. data/spec/semipublic/query/conditions/comparison_spec.rb +171 -169
  134. data/spec/semipublic/query/conditions/operation_spec.rb +53 -51
  135. data/spec/semipublic/query/path_spec.rb +17 -17
  136. data/spec/semipublic/query_spec.rb +47 -78
  137. data/spec/semipublic/resource/state/clean_spec.rb +88 -0
  138. data/spec/semipublic/resource/state/deleted_spec.rb +78 -0
  139. data/spec/semipublic/resource/state/dirty_spec.rb +133 -0
  140. data/spec/semipublic/resource/state/immutable_spec.rb +99 -0
  141. data/spec/semipublic/resource/state/transient_spec.rb +128 -0
  142. data/spec/semipublic/resource/state_spec.rb +226 -0
  143. data/spec/semipublic/shared/property_shared_spec.rb +143 -0
  144. data/spec/semipublic/shared/resource_shared_spec.rb +16 -15
  145. data/spec/semipublic/shared/resource_state_shared_spec.rb +78 -0
  146. data/spec/semipublic/shared/subject_shared_spec.rb +79 -0
  147. data/spec/spec_helper.rb +21 -97
  148. data/spec/support/types/huge_integer.rb +17 -0
  149. data/spec/unit/array_spec.rb +48 -0
  150. data/spec/unit/hash_spec.rb +35 -0
  151. data/spec/unit/hook_spec.rb +1234 -0
  152. data/spec/unit/lazy_array_spec.rb +1959 -0
  153. data/spec/unit/module_spec.rb +70 -0
  154. data/spec/unit/object_spec.rb +37 -0
  155. data/spec/unit/try_dup_spec.rb +45 -0
  156. data/tasks/local_gemfile.rake +18 -0
  157. data/tasks/spec.rake +0 -3
  158. metadata +197 -71
  159. data/deps.rip +0 -2
  160. data/lib/dm-core/adapters/data_objects_adapter.rb +0 -712
  161. data/lib/dm-core/adapters/mysql_adapter.rb +0 -42
  162. data/lib/dm-core/adapters/oracle_adapter.rb +0 -229
  163. data/lib/dm-core/adapters/postgres_adapter.rb +0 -22
  164. data/lib/dm-core/adapters/sqlite3_adapter.rb +0 -17
  165. data/lib/dm-core/adapters/sqlserver_adapter.rb +0 -114
  166. data/lib/dm-core/adapters/yaml_adapter.rb +0 -111
  167. data/lib/dm-core/core_ext/enumerable.rb +0 -28
  168. data/lib/dm-core/migrations.rb +0 -1427
  169. data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +0 -366
  170. data/lib/dm-core/transaction.rb +0 -508
  171. data/lib/dm-core/types/paranoid_boolean.rb +0 -42
  172. data/lib/dm-core/types/paranoid_datetime.rb +0 -41
  173. data/spec/lib/adapter_helpers.rb +0 -105
  174. data/spec/lib/collection_helpers.rb +0 -18
  175. data/spec/lib/pending_helpers.rb +0 -46
  176. data/spec/public/migrations_spec.rb +0 -503
  177. data/spec/public/transaction_spec.rb +0 -153
  178. data/spec/semipublic/adapters/mysql_adapter_spec.rb +0 -17
  179. data/spec/semipublic/adapters/oracle_adapter_spec.rb +0 -194
  180. data/spec/semipublic/adapters/postgres_adapter_spec.rb +0 -17
  181. data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +0 -17
  182. data/spec/semipublic/adapters/sqlserver_adapter_spec.rb +0 -17
  183. data/spec/semipublic/adapters/yaml_adapter_spec.rb +0 -12
@@ -9,8 +9,7 @@ require 'ostruct'
9
9
  # class methods
10
10
  describe DataMapper::Query do
11
11
  before :all do
12
- class ::Password < DataMapper::Type
13
- primitive String
12
+ class ::Password < DataMapper::Property::String
14
13
  length 40
15
14
  end
16
15
 
@@ -19,7 +18,7 @@ describe DataMapper::Query do
19
18
 
20
19
  property :name, String, :key => true
21
20
  property :password, Password
22
- property :balance, BigDecimal
21
+ property :balance, Decimal
23
22
 
24
23
  belongs_to :referrer, self, :required => false
25
24
  has n, :referrals, self, :inverse => :referrer
@@ -171,7 +170,7 @@ describe DataMapper::Query do
171
170
  it 'should raise an exception' do
172
171
  lambda {
173
172
  DataMapper::Query.new(@repository, @model, @options.update(:fields => :name))
174
- }.should raise_error(ArgumentError, '+options[:fields]+ should be Array, but was Symbol')
173
+ }.should raise_error(StandardError)
175
174
  end
176
175
  end
177
176
 
@@ -202,7 +201,7 @@ describe DataMapper::Query do
202
201
  describe 'that is an Array containing an unknown Property' do
203
202
  it 'should raise an exception' do
204
203
  lambda {
205
- DataMapper::Query.new(@repository, @model, @options.update(:fields => [ DataMapper::Property.new(@model, :unknown, String) ]))
204
+ DataMapper::Query.new(@repository, @model, @options.update(:fields => [ DataMapper::Property::String.new(@model, :unknown) ]))
206
205
  }.should raise_error(ArgumentError, "+options[:field]+ entry :unknown does not map to a property in #{@model}")
207
206
  end
208
207
  end
@@ -265,7 +264,7 @@ describe DataMapper::Query do
265
264
  it 'should raise an exception' do
266
265
  lambda {
267
266
  DataMapper::Query.new(@repository, @model, @options.update(:links => :referral))
268
- }.should raise_error(ArgumentError, '+options[:links]+ should be Array, but was Symbol')
267
+ }.should raise_error(StandardError)
269
268
  end
270
269
  end
271
270
 
@@ -521,16 +520,10 @@ describe DataMapper::Query do
521
520
 
522
521
  it { @return.should be_kind_of(DataMapper::Query) }
523
522
 
524
- it 'should set the conditions' do
525
- @return.conditions.should ==
526
- DataMapper::Query::Conditions::Operation.new(
527
- :and,
528
- DataMapper::Query::Conditions::Comparison.new(
529
- :eql,
530
- @model.referrer.name,
531
- 'Dan Kubb'
532
- )
533
- )
523
+ it 'should not set the conditions' do
524
+ pending do
525
+ @return.conditions.should be_nil
526
+ end
534
527
  end
535
528
 
536
529
  it 'should set the links' do
@@ -550,16 +543,10 @@ describe DataMapper::Query do
550
543
 
551
544
  it { @return.should be_kind_of(DataMapper::Query) }
552
545
 
553
- it 'should set the conditions' do
554
- @return.conditions.should ==
555
- DataMapper::Query::Conditions::Operation.new(
556
- :and,
557
- DataMapper::Query::Conditions::Comparison.new(
558
- :eql,
559
- @model.referrer.name,
560
- 'Dan Kubb'
561
- )
562
- )
546
+ it 'should not set the conditions' do
547
+ pending do
548
+ @return.conditions.should be_nil
549
+ end
563
550
  end
564
551
 
565
552
  it 'should set the links' do
@@ -700,7 +687,7 @@ describe DataMapper::Query do
700
687
  end
701
688
  end
702
689
 
703
- describe 'with a Float for a BigDecimal property' do
690
+ describe 'with a Float for a Decimal property' do
704
691
  before :all do
705
692
  @options[:conditions] = { :balance => 50.5 }
706
693
  @return = DataMapper::Query.new(@repository, @model, @options.freeze)
@@ -846,7 +833,7 @@ describe DataMapper::Query do
846
833
  it 'should raise an exception' do
847
834
  lambda {
848
835
  DataMapper::Query.new(@repository, @model, @options.update(:offset => '0'))
849
- }.should raise_error(ArgumentError, '+options[:offset]+ should be Integer, but was String')
836
+ }.should raise_error(StandardError)
850
837
  end
851
838
  end
852
839
 
@@ -896,7 +883,7 @@ describe DataMapper::Query do
896
883
  it 'should raise an exception' do
897
884
  lambda {
898
885
  DataMapper::Query.new(@repository, @model, @options.update(:limit => '1'))
899
- }.should raise_error(ArgumentError, '+options[:limit]+ should be Integer, but was String')
886
+ }.should raise_error(StandardError)
900
887
  end
901
888
  end
902
889
 
@@ -1094,7 +1081,7 @@ describe DataMapper::Query do
1094
1081
 
1095
1082
  describe 'that contains a Query::Direction with a property that is not part of the model' do
1096
1083
  before :all do
1097
- @property = DataMapper::Property.new(@model, :unknown, String)
1084
+ @property = DataMapper::Property::String.new(@model, :unknown)
1098
1085
  @direction = DataMapper::Query::Direction.new(@property, :desc)
1099
1086
  end
1100
1087
 
@@ -1123,7 +1110,7 @@ describe DataMapper::Query do
1123
1110
 
1124
1111
  describe 'that contains a Property that is not part of the model' do
1125
1112
  before :all do
1126
- @property = DataMapper::Property.new(@model, :unknown, String)
1113
+ @property = DataMapper::Property::String.new(@model, :unknown)
1127
1114
  end
1128
1115
 
1129
1116
  it 'should raise an exception' do
@@ -1280,7 +1267,7 @@ describe DataMapper::Query do
1280
1267
  it 'should raise an exception' do
1281
1268
  lambda {
1282
1269
  DataMapper::Query.new(@repository, @model, 'invalid')
1283
- }.should raise_error(ArgumentError, '+options+ should be Hash, but was String')
1270
+ }.should raise_error(StandardError)
1284
1271
  end
1285
1272
  end
1286
1273
  end
@@ -1354,7 +1341,7 @@ describe DataMapper::Query do
1354
1341
  @return = @query == @query
1355
1342
  end
1356
1343
 
1357
- it { @return.should be_true }
1344
+ it { @return.should be(true) }
1358
1345
  end
1359
1346
 
1360
1347
  describe 'when other is equivalent' do
@@ -1362,7 +1349,7 @@ describe DataMapper::Query do
1362
1349
  @return = @query == @query.dup
1363
1350
  end
1364
1351
 
1365
- it { @return.should be_true }
1352
+ it { @return.should be(true) }
1366
1353
  end
1367
1354
 
1368
1355
  DataMapper::Query::OPTIONS.each do |name|
@@ -1371,7 +1358,7 @@ describe DataMapper::Query do
1371
1358
  @return = @query == @query.merge(name => @other_options[name])
1372
1359
  end
1373
1360
 
1374
- it { @return.should be_false }
1361
+ it { @return.should be(false) }
1375
1362
  end
1376
1363
  end
1377
1364
 
@@ -1394,7 +1381,7 @@ describe DataMapper::Query do
1394
1381
  @return = @query == @other
1395
1382
  end
1396
1383
 
1397
- it { @return.should be_true }
1384
+ it { @return.should be(false) }
1398
1385
  end
1399
1386
 
1400
1387
  describe 'when other is a different type of object that can be compared, and is not equivalent' do
@@ -1416,7 +1403,7 @@ describe DataMapper::Query do
1416
1403
  @return = @query == @other
1417
1404
  end
1418
1405
 
1419
- it { @return.should be_false }
1406
+ it { @return.should be(false) }
1420
1407
  end
1421
1408
 
1422
1409
  describe 'when other is a different type of object that cannot be compared' do
@@ -1424,7 +1411,7 @@ describe DataMapper::Query do
1424
1411
  @return = @query == 'invalid'
1425
1412
  end
1426
1413
 
1427
- it { @return.should be_false }
1414
+ it { @return.should be(false) }
1428
1415
  end
1429
1416
  end
1430
1417
 
@@ -1467,8 +1454,8 @@ describe DataMapper::Query do
1467
1454
  {
1468
1455
  :child_key => @key.map { |p| p.name },
1469
1456
  :parent_key => @key.map { |p| p.name },
1470
- :child_repository_name => @repository,
1471
- :parent_repository_name => @repository,
1457
+ :child_repository_name => @repository.name,
1458
+ :parent_repository_name => @repository.name,
1472
1459
  }
1473
1460
  )
1474
1461
 
@@ -1629,9 +1616,7 @@ describe DataMapper::Query do
1629
1616
  it { should_not equal(@other) }
1630
1617
 
1631
1618
  it 'should put each query into a subquery and AND them together, and negate the other query' do
1632
- pending_if 'TODO: Fix once table aliasing works', @do_adapter do
1633
- subject.conditions.should == @expected
1634
- end
1619
+ subject.conditions.should == @expected
1635
1620
  end
1636
1621
  end
1637
1622
 
@@ -1657,9 +1642,7 @@ describe DataMapper::Query do
1657
1642
  it { should_not equal(@other) }
1658
1643
 
1659
1644
  it 'should put each query into a subquery and AND them together, and negate the other query' do
1660
- pending_if 'TODO: Fix once table aliasing works', @do_adapter do
1661
- subject.conditions.should == @expected
1662
- end
1645
+ subject.conditions.should == @expected
1663
1646
  end
1664
1647
  end
1665
1648
 
@@ -1841,7 +1824,7 @@ describe DataMapper::Query do
1841
1824
  @return = @query.eql?(@query)
1842
1825
  end
1843
1826
 
1844
- it { @return.should be_true }
1827
+ it { @return.should be(true) }
1845
1828
  end
1846
1829
 
1847
1830
  describe 'when other is eql' do
@@ -1849,7 +1832,7 @@ describe DataMapper::Query do
1849
1832
  @return = @query.eql?(@query.dup)
1850
1833
  end
1851
1834
 
1852
- it { @return.should be_true }
1835
+ it { @return.should be(true) }
1853
1836
  end
1854
1837
 
1855
1838
  DataMapper::Query::OPTIONS.each do |name|
@@ -1858,7 +1841,7 @@ describe DataMapper::Query do
1858
1841
  @return = @query.eql?(@query.merge(name => @other_options[name]))
1859
1842
  end
1860
1843
 
1861
- it { @return.should be_false }
1844
+ it { @return.should be(false) }
1862
1845
  end
1863
1846
  end
1864
1847
 
@@ -1881,7 +1864,7 @@ describe DataMapper::Query do
1881
1864
  @return = @query.eql?(@other)
1882
1865
  end
1883
1866
 
1884
- it { @return.should be_false }
1867
+ it { @return.should be(false) }
1885
1868
  end
1886
1869
  end
1887
1870
 
@@ -1941,10 +1924,10 @@ describe DataMapper::Query do
1941
1924
  #<DataMapper::Query
1942
1925
  @repository=:default
1943
1926
  @model=User
1944
- @fields=[#<DataMapper::Property @model=User @name=:name>, #<DataMapper::Property @model=User @name=:citizenship>, #<DataMapper::Property @model=User @name=:referrer_name>]
1927
+ @fields=[#<DataMapper::Property::String @model=User @name=:name>, #<DataMapper::Property::String @model=User @name=:citizenship>, #<DataMapper::Property::String @model=User @name=:referrer_name>]
1945
1928
  @links=[]
1946
1929
  @conditions=nil
1947
- @order=[#<DataMapper::Query::Direction @target=#<DataMapper::Property @model=User @name=:name> @operator=:asc>]
1930
+ @order=[#<DataMapper::Query::Direction @target=#<DataMapper::Property::String @model=User @name=:name> @operator=:asc>]
1948
1931
  @limit=3
1949
1932
  @offset=0
1950
1933
  @reload=false
@@ -1968,8 +1951,8 @@ describe DataMapper::Query do
1968
1951
  {
1969
1952
  :child_key => @key.map { |p| p.name },
1970
1953
  :parent_key => @key.map { |p| p.name },
1971
- :child_repository_name => @repository,
1972
- :parent_repository_name => @repository,
1954
+ :child_repository_name => @repository.name,
1955
+ :parent_repository_name => @repository.name,
1973
1956
  }
1974
1957
  )
1975
1958
 
@@ -2130,9 +2113,7 @@ describe DataMapper::Query do
2130
2113
  it { should_not equal(@other) }
2131
2114
 
2132
2115
  it 'should put each query into a subquery and AND them together' do
2133
- pending_if 'TODO: Fix once table aliasing works', @do_adapter do
2134
- subject.conditions.should == @expected
2135
- end
2116
+ subject.conditions.should == @expected
2136
2117
  end
2137
2118
  end
2138
2119
 
@@ -2156,9 +2137,7 @@ describe DataMapper::Query do
2156
2137
  it { should_not equal(@other) }
2157
2138
 
2158
2139
  it 'should put each query into a subquery and AND them together' do
2159
- pending_if 'TODO: Fix once table aliasing works', @do_adapter do
2160
- subject.conditions.should == @expected
2161
- end
2140
+ subject.conditions.should == @expected
2162
2141
  end
2163
2142
  end
2164
2143
 
@@ -3107,8 +3086,8 @@ describe DataMapper::Query do
3107
3086
  {
3108
3087
  :child_key => @key.map { |p| p.name },
3109
3088
  :parent_key => @key.map { |p| p.name },
3110
- :child_repository_name => @repository,
3111
- :parent_repository_name => @repository,
3089
+ :child_repository_name => @repository.name,
3090
+ :parent_repository_name => @repository.name,
3112
3091
  }
3113
3092
  )
3114
3093
 
@@ -3265,9 +3244,7 @@ describe DataMapper::Query do
3265
3244
  it { should_not equal(@other) }
3266
3245
 
3267
3246
  it 'should put each query into a subquery and OR them together' do
3268
- pending_if 'TODO: Fix once table aliasing works', @do_adapter do
3269
- subject.conditions.should == @expected
3270
- end
3247
+ subject.conditions.should == @expected
3271
3248
  end
3272
3249
  end
3273
3250
 
@@ -3291,9 +3268,7 @@ describe DataMapper::Query do
3291
3268
  it { should_not equal(@other) }
3292
3269
 
3293
3270
  it 'should put each query into a subquery and OR them together' do
3294
- pending_if 'TODO: Fix once table aliasing works', @do_adapter do
3295
- subject.conditions.should == @expected
3296
- end
3271
+ subject.conditions.should == @expected
3297
3272
  end
3298
3273
  end
3299
3274
 
@@ -3742,16 +3717,10 @@ describe DataMapper::Query do
3742
3717
 
3743
3718
  it { @return.should be_kind_of(DataMapper::Query) }
3744
3719
 
3745
- it 'should set the conditions' do
3746
- @return.conditions.should ==
3747
- DataMapper::Query::Conditions::Operation.new(
3748
- :and,
3749
- DataMapper::Query::Conditions::Comparison.new(
3750
- :eql,
3751
- @model.grandparents.name,
3752
- 'Dan Kubb'
3753
- )
3754
- )
3720
+ it 'should not set the conditions' do
3721
+ pending do
3722
+ @return.conditions.should be_nil
3723
+ end
3755
3724
  end
3756
3725
 
3757
3726
  it 'should set the links' do
@@ -0,0 +1,88 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper'))
2
+
3
+ describe DataMapper::Resource::State::Clean do
4
+ before :all do
5
+ class ::Author
6
+ include DataMapper::Resource
7
+
8
+ property :id, HugeInteger, :key => true, :default => 1
9
+ property :name, String
10
+ property :active, Boolean, :default => true
11
+ property :coding, Boolean, :default => true
12
+
13
+ belongs_to :parent, self, :required => false
14
+ has n, :children, self, :inverse => :parent
15
+ end
16
+
17
+ @model = Author
18
+ end
19
+
20
+ before do
21
+ @resource = @model.create(:name => 'Dan Kubb')
22
+
23
+ @state = @resource.persisted_state
24
+ @state.should be_kind_of(DataMapper::Resource::State::Clean)
25
+ end
26
+
27
+ after do
28
+ @resource.destroy
29
+ end
30
+
31
+ [ :commit, :rollback ].each do |method|
32
+ describe "##{method}" do
33
+ subject { @state.send(method) }
34
+
35
+ supported_by :all do
36
+ it 'should be a no-op' do
37
+ should equal(@state)
38
+ end
39
+ end
40
+ end
41
+ end
42
+
43
+ describe '#delete' do
44
+ subject { @state.delete }
45
+
46
+ supported_by :all do
47
+ it 'should return a Deleted state' do
48
+ should eql(DataMapper::Resource::State::Deleted.new(@resource))
49
+ end
50
+ end
51
+ end
52
+
53
+ describe '#get' do
54
+ it_should_behave_like 'Resource::State::Persisted#get'
55
+ end
56
+
57
+ describe '#set' do
58
+ subject { @state.set(@key, @value) }
59
+
60
+ supported_by :all do
61
+ describe 'with attributes that make the resource dirty' do
62
+ before do
63
+ @key = @model.properties[:name]
64
+ @value = nil
65
+ end
66
+
67
+ it_should_behave_like 'A method that delegates to the superclass #set'
68
+
69
+ it 'should return a Dirty state' do
70
+ should eql(DataMapper::Resource::State::Dirty.new(@resource))
71
+ end
72
+ end
73
+
74
+ describe 'with attributes that keep the resource clean' do
75
+ before do
76
+ @key = @model.properties[:name]
77
+ @value = 'Dan Kubb'
78
+ end
79
+
80
+ it_should_behave_like 'A method that does not delegate to the superclass #set'
81
+
82
+ it 'should return a Clean state' do
83
+ should equal(@state)
84
+ end
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,78 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', '..', 'spec_helper'))
2
+
3
+ describe DataMapper::Resource::State::Deleted do
4
+ before :all do
5
+ class ::Author
6
+ include DataMapper::Resource
7
+
8
+ property :id, HugeInteger, :key => true, :default => 1
9
+ property :name, String
10
+ property :active, Boolean, :default => true
11
+ property :coding, Boolean, :default => true
12
+
13
+ belongs_to :parent, self, :required => false
14
+ has n, :children, self, :inverse => :parent
15
+ end
16
+
17
+ @model = Author
18
+ end
19
+
20
+ before do
21
+ @resource = @model.create(:name => 'Dan Kubb')
22
+
23
+ @state = DataMapper::Resource::State::Deleted.new(@resource)
24
+ end
25
+
26
+ after do
27
+ @resource.destroy
28
+ end
29
+
30
+ describe '#commit' do
31
+ subject { @state.commit }
32
+
33
+ supported_by :all do
34
+ it 'should return an Immutable state' do
35
+ should eql(DataMapper::Resource::State::Immutable.new(@resource))
36
+ end
37
+
38
+ it 'should delete the resource' do
39
+ subject
40
+ @model.get(*@resource.key).should be_nil
41
+ end
42
+
43
+ it 'should remove the resource from the identity map' do
44
+ identity_map = @resource.repository.identity_map(@model)
45
+ method(:subject).should change { identity_map.dup }.from(@resource.key => @resource).to({})
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#delete' do
51
+ subject { @state.delete }
52
+
53
+ supported_by :all do
54
+ it 'should be a no-op' do
55
+ should equal(@state)
56
+ end
57
+ end
58
+ end
59
+
60
+ describe '#get' do
61
+ it_should_behave_like 'Resource::State::Persisted#get'
62
+ end
63
+
64
+ describe '#set' do
65
+ subject { @state.set(@key, @value) }
66
+
67
+ supported_by :all do
68
+ before do
69
+ @key = @model.properties[:name]
70
+ @value = @key.get!(@resource)
71
+ end
72
+
73
+ it 'should raise an exception' do
74
+ method(:subject).should raise_error(DataMapper::ImmutableDeletedError, 'Deleted resource cannot be modified')
75
+ end
76
+ end
77
+ end
78
+ end