dm-core 0.9.2

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 (101) hide show
  1. data/CHANGELOG +144 -0
  2. data/FAQ +74 -0
  3. data/MIT-LICENSE +22 -0
  4. data/QUICKLINKS +12 -0
  5. data/README +143 -0
  6. data/lib/dm-core.rb +213 -0
  7. data/lib/dm-core/adapters.rb +4 -0
  8. data/lib/dm-core/adapters/abstract_adapter.rb +202 -0
  9. data/lib/dm-core/adapters/data_objects_adapter.rb +701 -0
  10. data/lib/dm-core/adapters/mysql_adapter.rb +132 -0
  11. data/lib/dm-core/adapters/postgres_adapter.rb +179 -0
  12. data/lib/dm-core/adapters/sqlite3_adapter.rb +105 -0
  13. data/lib/dm-core/associations.rb +172 -0
  14. data/lib/dm-core/associations/many_to_many.rb +138 -0
  15. data/lib/dm-core/associations/many_to_one.rb +101 -0
  16. data/lib/dm-core/associations/one_to_many.rb +275 -0
  17. data/lib/dm-core/associations/one_to_one.rb +61 -0
  18. data/lib/dm-core/associations/relationship.rb +116 -0
  19. data/lib/dm-core/associations/relationship_chain.rb +74 -0
  20. data/lib/dm-core/auto_migrations.rb +64 -0
  21. data/lib/dm-core/collection.rb +604 -0
  22. data/lib/dm-core/hook.rb +11 -0
  23. data/lib/dm-core/identity_map.rb +45 -0
  24. data/lib/dm-core/is.rb +16 -0
  25. data/lib/dm-core/logger.rb +233 -0
  26. data/lib/dm-core/migrations/destructive_migrations.rb +17 -0
  27. data/lib/dm-core/migrator.rb +29 -0
  28. data/lib/dm-core/model.rb +399 -0
  29. data/lib/dm-core/naming_conventions.rb +52 -0
  30. data/lib/dm-core/property.rb +611 -0
  31. data/lib/dm-core/property_set.rb +158 -0
  32. data/lib/dm-core/query.rb +590 -0
  33. data/lib/dm-core/repository.rb +159 -0
  34. data/lib/dm-core/resource.rb +618 -0
  35. data/lib/dm-core/scope.rb +35 -0
  36. data/lib/dm-core/support.rb +7 -0
  37. data/lib/dm-core/support/array.rb +13 -0
  38. data/lib/dm-core/support/assertions.rb +8 -0
  39. data/lib/dm-core/support/errors.rb +23 -0
  40. data/lib/dm-core/support/kernel.rb +7 -0
  41. data/lib/dm-core/support/symbol.rb +41 -0
  42. data/lib/dm-core/transaction.rb +267 -0
  43. data/lib/dm-core/type.rb +160 -0
  44. data/lib/dm-core/type_map.rb +80 -0
  45. data/lib/dm-core/types.rb +19 -0
  46. data/lib/dm-core/types/boolean.rb +7 -0
  47. data/lib/dm-core/types/discriminator.rb +32 -0
  48. data/lib/dm-core/types/object.rb +20 -0
  49. data/lib/dm-core/types/paranoid_boolean.rb +23 -0
  50. data/lib/dm-core/types/paranoid_datetime.rb +22 -0
  51. data/lib/dm-core/types/serial.rb +9 -0
  52. data/lib/dm-core/types/text.rb +10 -0
  53. data/spec/integration/association_spec.rb +1215 -0
  54. data/spec/integration/association_through_spec.rb +150 -0
  55. data/spec/integration/associations/many_to_many_spec.rb +171 -0
  56. data/spec/integration/associations/many_to_one_spec.rb +123 -0
  57. data/spec/integration/associations/one_to_many_spec.rb +66 -0
  58. data/spec/integration/auto_migrations_spec.rb +398 -0
  59. data/spec/integration/collection_spec.rb +1015 -0
  60. data/spec/integration/data_objects_adapter_spec.rb +32 -0
  61. data/spec/integration/model_spec.rb +68 -0
  62. data/spec/integration/mysql_adapter_spec.rb +85 -0
  63. data/spec/integration/postgres_adapter_spec.rb +732 -0
  64. data/spec/integration/property_spec.rb +224 -0
  65. data/spec/integration/query_spec.rb +376 -0
  66. data/spec/integration/repository_spec.rb +57 -0
  67. data/spec/integration/resource_spec.rb +324 -0
  68. data/spec/integration/sqlite3_adapter_spec.rb +352 -0
  69. data/spec/integration/sti_spec.rb +185 -0
  70. data/spec/integration/transaction_spec.rb +75 -0
  71. data/spec/integration/type_spec.rb +149 -0
  72. data/spec/lib/mock_adapter.rb +27 -0
  73. data/spec/spec_helper.rb +112 -0
  74. data/spec/unit/adapters/abstract_adapter_spec.rb +133 -0
  75. data/spec/unit/adapters/adapter_shared_spec.rb +15 -0
  76. data/spec/unit/adapters/data_objects_adapter_spec.rb +627 -0
  77. data/spec/unit/adapters/postgres_adapter_spec.rb +125 -0
  78. data/spec/unit/associations/many_to_many_spec.rb +14 -0
  79. data/spec/unit/associations/many_to_one_spec.rb +138 -0
  80. data/spec/unit/associations/one_to_many_spec.rb +385 -0
  81. data/spec/unit/associations/one_to_one_spec.rb +7 -0
  82. data/spec/unit/associations/relationship_spec.rb +67 -0
  83. data/spec/unit/associations_spec.rb +205 -0
  84. data/spec/unit/auto_migrations_spec.rb +110 -0
  85. data/spec/unit/collection_spec.rb +174 -0
  86. data/spec/unit/data_mapper_spec.rb +21 -0
  87. data/spec/unit/identity_map_spec.rb +126 -0
  88. data/spec/unit/is_spec.rb +80 -0
  89. data/spec/unit/migrator_spec.rb +33 -0
  90. data/spec/unit/model_spec.rb +339 -0
  91. data/spec/unit/naming_conventions_spec.rb +28 -0
  92. data/spec/unit/property_set_spec.rb +96 -0
  93. data/spec/unit/property_spec.rb +447 -0
  94. data/spec/unit/query_spec.rb +485 -0
  95. data/spec/unit/repository_spec.rb +93 -0
  96. data/spec/unit/resource_spec.rb +557 -0
  97. data/spec/unit/scope_spec.rb +131 -0
  98. data/spec/unit/transaction_spec.rb +493 -0
  99. data/spec/unit/type_map_spec.rb +114 -0
  100. data/spec/unit/type_spec.rb +119 -0
  101. metadata +187 -0
@@ -0,0 +1,114 @@
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
@@ -0,0 +1,119 @@
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
metadata ADDED
@@ -0,0 +1,187 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: dm-core
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ platform: ruby
6
+ authors:
7
+ - Sam Smoot
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-06-25 00:00:00 -05:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: data_objects
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - "="
21
+ - !ruby/object:Gem::Version
22
+ version: 0.9.2
23
+ version:
24
+ - !ruby/object:Gem::Dependency
25
+ name: extlib
26
+ version_requirement:
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - - "="
30
+ - !ruby/object:Gem::Version
31
+ version: 0.9.2
32
+ version:
33
+ - !ruby/object:Gem::Dependency
34
+ name: rspec
35
+ version_requirement:
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.1.3
41
+ version:
42
+ - !ruby/object:Gem::Dependency
43
+ name: addressable
44
+ version_requirement:
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: 1.0.4
50
+ version:
51
+ description: Faster, Better, Simpler.
52
+ email: ssmoot@gmail.com
53
+ executables: []
54
+
55
+ extensions: []
56
+
57
+ extra_rdoc_files: []
58
+
59
+ files:
60
+ - README
61
+ - FAQ
62
+ - QUICKLINKS
63
+ - CHANGELOG
64
+ - MIT-LICENSE
65
+ - lib/dm-core/adapters/abstract_adapter.rb
66
+ - lib/dm-core/adapters/data_objects_adapter.rb
67
+ - lib/dm-core/adapters/mysql_adapter.rb
68
+ - lib/dm-core/adapters/postgres_adapter.rb
69
+ - lib/dm-core/adapters/sqlite3_adapter.rb
70
+ - lib/dm-core/adapters.rb
71
+ - lib/dm-core/associations/many_to_many.rb
72
+ - lib/dm-core/associations/many_to_one.rb
73
+ - lib/dm-core/associations/one_to_many.rb
74
+ - lib/dm-core/associations/one_to_one.rb
75
+ - lib/dm-core/associations/relationship.rb
76
+ - lib/dm-core/associations/relationship_chain.rb
77
+ - lib/dm-core/associations.rb
78
+ - lib/dm-core/auto_migrations.rb
79
+ - lib/dm-core/collection.rb
80
+ - lib/dm-core/hook.rb
81
+ - lib/dm-core/identity_map.rb
82
+ - lib/dm-core/is.rb
83
+ - lib/dm-core/logger.rb
84
+ - lib/dm-core/migrations/destructive_migrations.rb
85
+ - lib/dm-core/migrator.rb
86
+ - lib/dm-core/model.rb
87
+ - lib/dm-core/naming_conventions.rb
88
+ - lib/dm-core/property.rb
89
+ - lib/dm-core/property_set.rb
90
+ - lib/dm-core/query.rb
91
+ - lib/dm-core/repository.rb
92
+ - lib/dm-core/resource.rb
93
+ - lib/dm-core/scope.rb
94
+ - lib/dm-core/support/array.rb
95
+ - lib/dm-core/support/assertions.rb
96
+ - lib/dm-core/support/errors.rb
97
+ - lib/dm-core/support/kernel.rb
98
+ - lib/dm-core/support/symbol.rb
99
+ - lib/dm-core/support.rb
100
+ - lib/dm-core/transaction.rb
101
+ - lib/dm-core/type.rb
102
+ - lib/dm-core/type_map.rb
103
+ - lib/dm-core/types/boolean.rb
104
+ - lib/dm-core/types/discriminator.rb
105
+ - lib/dm-core/types/object.rb
106
+ - lib/dm-core/types/paranoid_boolean.rb
107
+ - lib/dm-core/types/paranoid_datetime.rb
108
+ - lib/dm-core/types/serial.rb
109
+ - lib/dm-core/types/text.rb
110
+ - lib/dm-core/types.rb
111
+ - lib/dm-core.rb
112
+ - spec/integration/association_spec.rb
113
+ - spec/integration/association_through_spec.rb
114
+ - spec/integration/associations/many_to_many_spec.rb
115
+ - spec/integration/associations/many_to_one_spec.rb
116
+ - spec/integration/associations/one_to_many_spec.rb
117
+ - spec/integration/auto_migrations_spec.rb
118
+ - spec/integration/collection_spec.rb
119
+ - spec/integration/data_objects_adapter_spec.rb
120
+ - spec/integration/model_spec.rb
121
+ - spec/integration/mysql_adapter_spec.rb
122
+ - spec/integration/postgres_adapter_spec.rb
123
+ - spec/integration/property_spec.rb
124
+ - spec/integration/query_spec.rb
125
+ - spec/integration/repository_spec.rb
126
+ - spec/integration/resource_spec.rb
127
+ - spec/integration/sqlite3_adapter_spec.rb
128
+ - spec/integration/sti_spec.rb
129
+ - spec/integration/transaction_spec.rb
130
+ - spec/integration/type_spec.rb
131
+ - spec/lib/mock_adapter.rb
132
+ - spec/spec_helper.rb
133
+ - spec/unit/adapters/abstract_adapter_spec.rb
134
+ - spec/unit/adapters/adapter_shared_spec.rb
135
+ - spec/unit/adapters/data_objects_adapter_spec.rb
136
+ - spec/unit/adapters/postgres_adapter_spec.rb
137
+ - spec/unit/associations/many_to_many_spec.rb
138
+ - spec/unit/associations/many_to_one_spec.rb
139
+ - spec/unit/associations/one_to_many_spec.rb
140
+ - spec/unit/associations/one_to_one_spec.rb
141
+ - spec/unit/associations/relationship_spec.rb
142
+ - spec/unit/associations_spec.rb
143
+ - spec/unit/auto_migrations_spec.rb
144
+ - spec/unit/collection_spec.rb
145
+ - spec/unit/data_mapper_spec.rb
146
+ - spec/unit/identity_map_spec.rb
147
+ - spec/unit/is_spec.rb
148
+ - spec/unit/migrator_spec.rb
149
+ - spec/unit/model_spec.rb
150
+ - spec/unit/naming_conventions_spec.rb
151
+ - spec/unit/property_set_spec.rb
152
+ - spec/unit/property_spec.rb
153
+ - spec/unit/query_spec.rb
154
+ - spec/unit/repository_spec.rb
155
+ - spec/unit/resource_spec.rb
156
+ - spec/unit/scope_spec.rb
157
+ - spec/unit/transaction_spec.rb
158
+ - spec/unit/type_map_spec.rb
159
+ - spec/unit/type_spec.rb
160
+ has_rdoc: false
161
+ homepage: http://datamapper.org
162
+ post_install_message:
163
+ rdoc_options: []
164
+
165
+ require_paths:
166
+ - lib
167
+ required_ruby_version: !ruby/object:Gem::Requirement
168
+ requirements:
169
+ - - ">="
170
+ - !ruby/object:Gem::Version
171
+ version: "0"
172
+ version:
173
+ required_rubygems_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - ">="
176
+ - !ruby/object:Gem::Version
177
+ version: "0"
178
+ version:
179
+ requirements:
180
+ - none
181
+ rubyforge_project: dm-core
182
+ rubygems_version: 1.0.1
183
+ signing_key:
184
+ specification_version: 2
185
+ summary: An Object/Relational Mapper for Ruby
186
+ test_files: []
187
+