dm-core 0.9.11 → 0.10.0

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 (194) hide show
  1. data/.autotest +17 -14
  2. data/.gitignore +3 -1
  3. data/FAQ +6 -5
  4. data/History.txt +5 -50
  5. data/Manifest.txt +66 -76
  6. data/QUICKLINKS +1 -1
  7. data/README.txt +21 -15
  8. data/Rakefile +6 -7
  9. data/SPECS +2 -29
  10. data/TODO +1 -1
  11. data/deps.rip +2 -0
  12. data/dm-core.gemspec +11 -15
  13. data/lib/dm-core.rb +105 -110
  14. data/lib/dm-core/adapters.rb +135 -16
  15. data/lib/dm-core/adapters/abstract_adapter.rb +251 -181
  16. data/lib/dm-core/adapters/data_objects_adapter.rb +482 -534
  17. data/lib/dm-core/adapters/in_memory_adapter.rb +90 -69
  18. data/lib/dm-core/adapters/mysql_adapter.rb +22 -115
  19. data/lib/dm-core/adapters/oracle_adapter.rb +249 -0
  20. data/lib/dm-core/adapters/postgres_adapter.rb +7 -173
  21. data/lib/dm-core/adapters/sqlite3_adapter.rb +4 -97
  22. data/lib/dm-core/adapters/yaml_adapter.rb +116 -0
  23. data/lib/dm-core/associations/many_to_many.rb +372 -90
  24. data/lib/dm-core/associations/many_to_one.rb +220 -73
  25. data/lib/dm-core/associations/one_to_many.rb +319 -255
  26. data/lib/dm-core/associations/one_to_one.rb +66 -53
  27. data/lib/dm-core/associations/relationship.rb +561 -156
  28. data/lib/dm-core/collection.rb +1101 -379
  29. data/lib/dm-core/core_ext/kernel.rb +12 -0
  30. data/lib/dm-core/core_ext/symbol.rb +10 -0
  31. data/lib/dm-core/identity_map.rb +4 -34
  32. data/lib/dm-core/migrations.rb +1283 -0
  33. data/lib/dm-core/model.rb +570 -369
  34. data/lib/dm-core/model/descendant_set.rb +81 -0
  35. data/lib/dm-core/model/hook.rb +45 -0
  36. data/lib/dm-core/model/is.rb +32 -0
  37. data/lib/dm-core/model/property.rb +247 -0
  38. data/lib/dm-core/model/relationship.rb +335 -0
  39. data/lib/dm-core/model/scope.rb +90 -0
  40. data/lib/dm-core/property.rb +808 -273
  41. data/lib/dm-core/property_set.rb +141 -98
  42. data/lib/dm-core/query.rb +1037 -483
  43. data/lib/dm-core/query/conditions/comparison.rb +872 -0
  44. data/lib/dm-core/query/conditions/operation.rb +221 -0
  45. data/lib/dm-core/query/direction.rb +43 -0
  46. data/lib/dm-core/query/operator.rb +84 -0
  47. data/lib/dm-core/query/path.rb +138 -0
  48. data/lib/dm-core/query/sort.rb +45 -0
  49. data/lib/dm-core/repository.rb +210 -94
  50. data/lib/dm-core/resource.rb +641 -421
  51. data/lib/dm-core/spec/adapter_shared_spec.rb +294 -0
  52. data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +106 -0
  53. data/lib/dm-core/support/chainable.rb +22 -0
  54. data/lib/dm-core/support/deprecate.rb +12 -0
  55. data/lib/dm-core/support/logger.rb +13 -0
  56. data/lib/dm-core/{naming_conventions.rb → support/naming_conventions.rb} +6 -6
  57. data/lib/dm-core/transaction.rb +333 -92
  58. data/lib/dm-core/type.rb +98 -60
  59. data/lib/dm-core/types/boolean.rb +1 -1
  60. data/lib/dm-core/types/discriminator.rb +34 -20
  61. data/lib/dm-core/types/object.rb +7 -4
  62. data/lib/dm-core/types/paranoid_boolean.rb +11 -9
  63. data/lib/dm-core/types/paranoid_datetime.rb +11 -9
  64. data/lib/dm-core/types/serial.rb +3 -3
  65. data/lib/dm-core/types/text.rb +3 -4
  66. data/lib/dm-core/version.rb +1 -1
  67. data/script/performance.rb +102 -109
  68. data/script/profile.rb +169 -38
  69. data/spec/lib/adapter_helpers.rb +105 -0
  70. data/spec/lib/collection_helpers.rb +18 -0
  71. data/spec/lib/counter_adapter.rb +34 -0
  72. data/spec/lib/pending_helpers.rb +27 -0
  73. data/spec/lib/rspec_immediate_feedback_formatter.rb +53 -0
  74. data/spec/public/associations/many_to_many_spec.rb +193 -0
  75. data/spec/public/associations/many_to_one_spec.rb +73 -0
  76. data/spec/public/associations/one_to_many_spec.rb +77 -0
  77. data/spec/public/associations/one_to_one_spec.rb +156 -0
  78. data/spec/public/collection_spec.rb +65 -0
  79. data/spec/public/migrations_spec.rb +359 -0
  80. data/spec/public/model/relationship_spec.rb +924 -0
  81. data/spec/public/model_spec.rb +159 -0
  82. data/spec/public/property_spec.rb +829 -0
  83. data/spec/public/resource_spec.rb +71 -0
  84. data/spec/public/sel_spec.rb +44 -0
  85. data/spec/public/setup_spec.rb +145 -0
  86. data/spec/public/shared/association_collection_shared_spec.rb +317 -0
  87. data/spec/public/shared/collection_shared_spec.rb +1670 -0
  88. data/spec/public/shared/finder_shared_spec.rb +1619 -0
  89. data/spec/public/shared/resource_shared_spec.rb +924 -0
  90. data/spec/public/shared/sel_shared_spec.rb +112 -0
  91. data/spec/public/transaction_spec.rb +129 -0
  92. data/spec/public/types/discriminator_spec.rb +130 -0
  93. data/spec/semipublic/adapters/abstract_adapter_spec.rb +30 -0
  94. data/spec/semipublic/adapters/in_memory_adapter_spec.rb +12 -0
  95. data/spec/semipublic/adapters/mysql_adapter_spec.rb +17 -0
  96. data/spec/semipublic/adapters/oracle_adapter_spec.rb +194 -0
  97. data/spec/semipublic/adapters/postgres_adapter_spec.rb +17 -0
  98. data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +17 -0
  99. data/spec/semipublic/adapters/yaml_adapter_spec.rb +12 -0
  100. data/spec/semipublic/associations/many_to_one_spec.rb +53 -0
  101. data/spec/semipublic/associations/relationship_spec.rb +194 -0
  102. data/spec/semipublic/associations_spec.rb +177 -0
  103. data/spec/semipublic/collection_spec.rb +142 -0
  104. data/spec/semipublic/property_spec.rb +61 -0
  105. data/spec/semipublic/query/conditions_spec.rb +528 -0
  106. data/spec/semipublic/query/path_spec.rb +443 -0
  107. data/spec/semipublic/query_spec.rb +2626 -0
  108. data/spec/semipublic/resource_spec.rb +47 -0
  109. data/spec/semipublic/shared/condition_shared_spec.rb +9 -0
  110. data/spec/semipublic/shared/resource_shared_spec.rb +126 -0
  111. data/spec/spec.opts +3 -1
  112. data/spec/spec_helper.rb +80 -57
  113. data/tasks/ci.rb +19 -31
  114. data/tasks/dm.rb +43 -48
  115. data/tasks/doc.rb +8 -11
  116. data/tasks/gemspec.rb +5 -5
  117. data/tasks/hoe.rb +15 -16
  118. data/tasks/install.rb +8 -10
  119. metadata +74 -111
  120. data/lib/dm-core/associations.rb +0 -207
  121. data/lib/dm-core/associations/relationship_chain.rb +0 -81
  122. data/lib/dm-core/auto_migrations.rb +0 -105
  123. data/lib/dm-core/dependency_queue.rb +0 -32
  124. data/lib/dm-core/hook.rb +0 -11
  125. data/lib/dm-core/is.rb +0 -16
  126. data/lib/dm-core/logger.rb +0 -232
  127. data/lib/dm-core/migrations/destructive_migrations.rb +0 -17
  128. data/lib/dm-core/migrator.rb +0 -29
  129. data/lib/dm-core/scope.rb +0 -58
  130. data/lib/dm-core/support.rb +0 -7
  131. data/lib/dm-core/support/array.rb +0 -13
  132. data/lib/dm-core/support/assertions.rb +0 -8
  133. data/lib/dm-core/support/errors.rb +0 -23
  134. data/lib/dm-core/support/kernel.rb +0 -11
  135. data/lib/dm-core/support/symbol.rb +0 -41
  136. data/lib/dm-core/type_map.rb +0 -80
  137. data/lib/dm-core/types.rb +0 -19
  138. data/script/all +0 -4
  139. data/spec/integration/association_spec.rb +0 -1382
  140. data/spec/integration/association_through_spec.rb +0 -203
  141. data/spec/integration/associations/many_to_many_spec.rb +0 -449
  142. data/spec/integration/associations/many_to_one_spec.rb +0 -163
  143. data/spec/integration/associations/one_to_many_spec.rb +0 -188
  144. data/spec/integration/auto_migrations_spec.rb +0 -413
  145. data/spec/integration/collection_spec.rb +0 -1073
  146. data/spec/integration/data_objects_adapter_spec.rb +0 -32
  147. data/spec/integration/dependency_queue_spec.rb +0 -46
  148. data/spec/integration/model_spec.rb +0 -197
  149. data/spec/integration/mysql_adapter_spec.rb +0 -85
  150. data/spec/integration/postgres_adapter_spec.rb +0 -731
  151. data/spec/integration/property_spec.rb +0 -253
  152. data/spec/integration/query_spec.rb +0 -514
  153. data/spec/integration/repository_spec.rb +0 -61
  154. data/spec/integration/resource_spec.rb +0 -513
  155. data/spec/integration/sqlite3_adapter_spec.rb +0 -352
  156. data/spec/integration/sti_spec.rb +0 -273
  157. data/spec/integration/strategic_eager_loading_spec.rb +0 -156
  158. data/spec/integration/transaction_spec.rb +0 -75
  159. data/spec/integration/type_spec.rb +0 -275
  160. data/spec/lib/logging_helper.rb +0 -18
  161. data/spec/lib/mock_adapter.rb +0 -27
  162. data/spec/lib/model_loader.rb +0 -100
  163. data/spec/lib/publicize_methods.rb +0 -28
  164. data/spec/models/content.rb +0 -16
  165. data/spec/models/vehicles.rb +0 -34
  166. data/spec/models/zoo.rb +0 -48
  167. data/spec/unit/adapters/abstract_adapter_spec.rb +0 -133
  168. data/spec/unit/adapters/adapter_shared_spec.rb +0 -15
  169. data/spec/unit/adapters/data_objects_adapter_spec.rb +0 -632
  170. data/spec/unit/adapters/in_memory_adapter_spec.rb +0 -98
  171. data/spec/unit/adapters/postgres_adapter_spec.rb +0 -133
  172. data/spec/unit/associations/many_to_many_spec.rb +0 -32
  173. data/spec/unit/associations/many_to_one_spec.rb +0 -159
  174. data/spec/unit/associations/one_to_many_spec.rb +0 -393
  175. data/spec/unit/associations/one_to_one_spec.rb +0 -7
  176. data/spec/unit/associations/relationship_spec.rb +0 -71
  177. data/spec/unit/associations_spec.rb +0 -242
  178. data/spec/unit/auto_migrations_spec.rb +0 -111
  179. data/spec/unit/collection_spec.rb +0 -182
  180. data/spec/unit/data_mapper_spec.rb +0 -35
  181. data/spec/unit/identity_map_spec.rb +0 -126
  182. data/spec/unit/is_spec.rb +0 -80
  183. data/spec/unit/migrator_spec.rb +0 -33
  184. data/spec/unit/model_spec.rb +0 -321
  185. data/spec/unit/naming_conventions_spec.rb +0 -36
  186. data/spec/unit/property_set_spec.rb +0 -90
  187. data/spec/unit/property_spec.rb +0 -753
  188. data/spec/unit/query_spec.rb +0 -571
  189. data/spec/unit/repository_spec.rb +0 -93
  190. data/spec/unit/resource_spec.rb +0 -649
  191. data/spec/unit/scope_spec.rb +0 -142
  192. data/spec/unit/transaction_spec.rb +0 -493
  193. data/spec/unit/type_map_spec.rb +0 -114
  194. data/spec/unit/type_spec.rb +0 -119
@@ -1,114 +0,0 @@
1
- require 'pathname'
2
- require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
3
-
4
- describe DataMapper::TypeMap do
5
-
6
- before(:each) do
7
- @tm = DataMapper::TypeMap.new
8
- end
9
-
10
- describe "#map" do
11
- it "should return a type map chain" do
12
- @tm.map(String).should be_instance_of(DataMapper::TypeMap::TypeChain)
13
- end
14
-
15
- it "should return the original chain if the type has already been mapped" do
16
- tc = @tm.map(String)
17
- @tm.map(String).should == tc
18
- end
19
- end
20
-
21
- describe "#lookup" do
22
- it "should the primitive's mapping the class has a primitive type" do
23
- @tm.map(String).to(:varchar)
24
-
25
- lambda { @tm.lookup(DM::Text) }.should_not raise_error
26
- end
27
-
28
- it "should merge in the parent type map's translated match" do
29
-
30
- end
31
-
32
- describe "#lookup_from_map" do
33
- it "should merge the translated type match into the parent match" do
34
- @tm.map(String).to(:varchar)
35
-
36
- child = DataMapper::TypeMap.new(@tm)
37
- child.map(String).with(:size => 100)
38
-
39
- child.lookup_from_map(String).should == {:primitive => :varchar, :size => 100}
40
- end
41
- end
42
-
43
- describe "#lookup_by_type" do
44
- it "should raise an exception if the type is not mapped and does not have a primitive" do
45
- klass = Class.new
46
- lambda { @tm.lookup(klass) }.should raise_error("Type #{klass} must have a default primitive or type map entry")
47
- end
48
- end
49
- end
50
-
51
- describe "#map" do
52
- it "should create a new TypeChain if there is no match" do
53
- @tm.chains.should_not have_key(String)
54
-
55
- DataMapper::TypeMap::TypeChain.should_receive(:new)
56
-
57
- @tm.map(String)
58
- end
59
-
60
- it "should not create a new TypeChain if there is a match" do
61
- @tm.map(String)
62
-
63
- DataMapper::TypeMap::TypeChain.should_not_receive(:new)
64
-
65
- @tm.map(String)
66
- end
67
- end
68
-
69
- describe DataMapper::TypeMap::TypeChain do
70
- describe "#to" do
71
- it "should be a setter for @primitive" do
72
- tc = DataMapper::TypeMap::TypeChain.new
73
-
74
- lambda { tc.to(:primitive) }.should change { tc.primitive }.to(:primitive)
75
- end
76
-
77
- it "should return itself" do
78
- tc = DataMapper::TypeMap::TypeChain.new
79
-
80
- tc.to(:primitive).should == tc
81
- end
82
- end
83
-
84
- describe "#with" do
85
- it "should return itself" do
86
- tc = DataMapper::TypeMap::TypeChain.new
87
-
88
- tc.with(:key => :value).should == tc
89
- end
90
-
91
- it "should raise an error if the argument is not a hash" do
92
- tc = DataMapper::TypeMap::TypeChain.new
93
-
94
- lambda { tc.with(:key) }.should raise_error("method 'with' expects a hash")
95
- end
96
-
97
- it "should merge the argument hash into the attributes hash" do
98
- tc = DataMapper::TypeMap::TypeChain.new
99
-
100
- tc.with(:key => :value).with(:size => 10).attributes.should == {:key => :value, :size => 10}
101
- end
102
- end
103
-
104
- describe "#translate" do
105
- it "should merge the attributes hash with the primitive value" do
106
- DataMapper::TypeMap::TypeChain.new.to(:int).with(:size => 10).translate.should == {:primitive => :int, :size => 10}
107
- end
108
-
109
- it "should overwrite any :primitive entry set using the 'with' method" do
110
- DataMapper::TypeMap::TypeChain.new.to(:int).with(:primitive => :varchar).translate.should == {:primitive => :int}
111
- end
112
- end
113
- end
114
- end
@@ -1,119 +0,0 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
2
-
3
- describe DataMapper::Type do
4
-
5
- before(:each) do
6
- class TestType < DataMapper::Type
7
- primitive String
8
- size 10
9
- end
10
-
11
- class TestType2 < DataMapper::Type
12
- primitive String
13
- size 10
14
-
15
- def self.load(value, property)
16
- value.reverse
17
- end
18
-
19
- def self.dump(value, property)
20
- value.reverse
21
- end
22
- end
23
-
24
- class TestResource
25
- include DataMapper::Resource
26
- end
27
-
28
- class TestType3 < DataMapper::Type
29
- primitive String
30
- size 10
31
- attr_accessor :property, :value
32
-
33
- def self.load(value, property)
34
- type = self.new
35
- type.property = property
36
- type.value = value
37
- type
38
- end
39
-
40
- def self.dump(value, property)
41
- value.value
42
- end
43
- end
44
- end
45
-
46
- it "should have the same PROPERTY_OPTIONS array as DataMapper::Property" do
47
- DataMapper::Type::PROPERTY_OPTIONS.should == DataMapper::Property::PROPERTY_OPTIONS
48
- end
49
-
50
- it "should create a new type based on String primitive" do
51
- TestType.primitive.should == String
52
- end
53
-
54
- it "should have size of 10" do
55
- TestType.size.should == 10
56
- end
57
-
58
- it "should have options hash exactly equal to options specified in custom type" do
59
- #ie. it should not include null elements
60
- TestType.options.should == { :size => 10, :length => 10 }
61
- end
62
-
63
- it "should have length aliased to size" do
64
- TestType.length.should == TestType.size
65
- end
66
-
67
- it "should pass through the value if load wasn't overridden" do
68
- TestType.load("test", nil).should == "test"
69
- end
70
-
71
- it "should pass through the value if dump wasn't overridden" do
72
- TestType.dump("test", nil).should == "test"
73
- end
74
-
75
- it "should not raise NotImplementedException if load was overridden" do
76
- TestType2.dump("helo", nil).should == "oleh"
77
- end
78
-
79
- it "should not raise NotImplementedException if dump was overridden" do
80
- TestType2.load("oleh", nil).should == "helo"
81
- end
82
-
83
- describe "using a custom type" do
84
- before do
85
- @property = DataMapper::Property.new TestResource, :name, TestType3, {}
86
- end
87
-
88
- it "should return a object of the same type" do
89
- TestType3.load("helo", @property).class.should == TestType3
90
- end
91
-
92
- it "should contain the property" do
93
- TestType3.load("helo", @property).property.should == @property
94
- end
95
-
96
- it "should contain the value" do
97
- TestType3.load("helo", @property).value.should == "helo"
98
- end
99
-
100
- it "should return the value" do
101
- obj = TestType3.load("helo", @property)
102
- TestType3.dump(obj, @property).should == "helo"
103
- end
104
- end
105
-
106
- describe "using def Type" do
107
- before do
108
- @class = Class.new(DataMapper::Type(String, :size => 20))
109
- end
110
-
111
- it "should be of the specified type" do
112
- @class.primitive.should == String
113
- end
114
-
115
- it "should have the right options set" do
116
- @class.size.should == 20
117
- end
118
- end
119
- end