dm-core 1.0.2 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +28 -94
- data/LICENSE +1 -1
- data/README.rdoc +44 -11
- data/Rakefile +1 -7
- data/VERSION +1 -1
- data/dm-core.gemspec +398 -299
- data/lib/dm-core.rb +23 -13
- data/lib/dm-core/adapters/abstract_adapter.rb +1 -1
- data/lib/dm-core/associations/many_to_many.rb +1 -3
- data/lib/dm-core/associations/many_to_one.rb +54 -36
- data/lib/dm-core/associations/one_to_many.rb +1 -2
- data/lib/dm-core/associations/relationship.rb +11 -2
- data/lib/dm-core/collection.rb +3 -7
- data/lib/dm-core/core_ext/symbol.rb +1 -1
- data/lib/dm-core/identity_map.rb +0 -5
- data/lib/dm-core/model.rb +11 -21
- data/lib/dm-core/model/property.rb +43 -58
- data/lib/dm-core/model/relationship.rb +49 -44
- data/lib/dm-core/property.rb +106 -130
- data/lib/dm-core/property/date_time.rb +1 -3
- data/lib/dm-core/property/decimal.rb +11 -7
- data/lib/dm-core/property/integer.rb +2 -2
- data/lib/dm-core/property/lookup.rb +3 -16
- data/lib/dm-core/property/numeric.rb +3 -3
- data/lib/dm-core/property/object.rb +2 -11
- data/lib/dm-core/property/string.rb +1 -1
- data/lib/dm-core/property_set.rb +34 -54
- data/lib/dm-core/query.rb +85 -56
- data/lib/dm-core/query/conditions/comparison.rb +3 -6
- data/lib/dm-core/query/direction.rb +0 -4
- data/lib/dm-core/query/path.rb +22 -6
- data/lib/dm-core/relationship_set.rb +74 -0
- data/lib/dm-core/resource.rb +21 -32
- data/lib/dm-core/resource/state.rb +3 -4
- data/lib/dm-core/spec/lib/spec_helper.rb +1 -4
- data/lib/dm-core/spec/setup.rb +12 -5
- data/lib/dm-core/spec/shared/public/property_spec.rb +35 -21
- data/lib/dm-core/spec/shared/resource_spec.rb +1 -1
- data/lib/dm-core/spec/shared/semipublic/property_spec.rb +9 -9
- data/lib/dm-core/spec/shared/semipublic/query/conditions/abstract_comparison_spec.rb +261 -0
- data/lib/dm-core/support/deprecate.rb +1 -1
- data/lib/dm-core/support/descendant_set.rb +12 -5
- data/lib/dm-core/support/ordered_set.rb +382 -0
- data/lib/dm-core/support/subject_set.rb +252 -0
- data/lib/dm-core/version.rb +1 -1
- data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +1 -2
- data/spec/public/associations/many_to_many_spec.rb +11 -9
- data/spec/public/associations/many_to_one_spec.rb +1 -1
- data/spec/public/associations/many_to_one_with_boolean_cpk_spec.rb +1 -1
- data/spec/public/associations/many_to_one_with_custom_fk_spec.rb +2 -2
- data/spec/public/associations/one_to_many_spec.rb +6 -5
- data/spec/public/associations/one_to_one_spec.rb +1 -1
- data/spec/public/associations/one_to_one_with_boolean_cpk_spec.rb +1 -1
- data/spec/public/collection_spec.rb +7 -6
- data/spec/public/finalize_spec.rb +1 -1
- data/spec/public/model/hook_spec.rb +4 -3
- data/spec/public/model/property_spec.rb +9 -3
- data/spec/public/model/relationship_spec.rb +2 -4
- data/spec/public/model_spec.rb +1 -1
- data/spec/public/property/binary_spec.rb +1 -1
- data/spec/public/property/boolean_spec.rb +1 -1
- data/spec/public/property/class_spec.rb +1 -1
- data/spec/public/property/date_spec.rb +1 -1
- data/spec/public/property/date_time_spec.rb +1 -1
- data/spec/public/property/decimal_spec.rb +7 -6
- data/spec/public/property/discriminator_spec.rb +1 -1
- data/spec/public/property/float_spec.rb +1 -1
- data/spec/public/property/integer_spec.rb +1 -1
- data/spec/public/property/object_spec.rb +2 -2
- data/spec/public/property/serial_spec.rb +1 -1
- data/spec/public/property/string_spec.rb +1 -1
- data/spec/public/property/text_spec.rb +6 -3
- data/spec/public/property/time_spec.rb +1 -1
- data/spec/public/property_spec.rb +13 -11
- data/spec/public/resource_spec.rb +43 -1
- data/spec/public/sel_spec.rb +1 -1
- data/spec/public/setup_spec.rb +1 -1
- data/spec/public/shared/collection_shared_spec.rb +6 -1
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +1 -1
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +1 -1
- data/spec/semipublic/associations/many_to_many_spec.rb +1 -1
- data/spec/semipublic/associations/many_to_one_spec.rb +1 -1
- data/spec/semipublic/associations/one_to_many_spec.rb +1 -1
- data/spec/semipublic/associations/one_to_one_spec.rb +1 -1
- data/spec/semipublic/associations/relationship_spec.rb +1 -1
- data/spec/semipublic/associations_spec.rb +1 -1
- data/spec/semipublic/collection_spec.rb +1 -1
- data/spec/semipublic/model_spec.rb +1 -1
- data/spec/semipublic/property/binary_spec.rb +1 -1
- data/spec/semipublic/property/boolean_spec.rb +1 -1
- data/spec/semipublic/property/class_spec.rb +1 -1
- data/spec/semipublic/property/date_spec.rb +1 -1
- data/spec/semipublic/property/date_time_spec.rb +1 -1
- data/spec/semipublic/property/decimal_spec.rb +6 -5
- data/spec/semipublic/property/discriminator_spec.rb +1 -1
- data/spec/semipublic/property/float_spec.rb +1 -1
- data/spec/semipublic/property/integer_spec.rb +1 -1
- data/spec/semipublic/property/lookup_spec.rb +8 -5
- data/spec/semipublic/property/serial_spec.rb +1 -1
- data/spec/semipublic/property/string_spec.rb +1 -1
- data/spec/semipublic/property/text_spec.rb +1 -1
- data/spec/semipublic/property/time_spec.rb +1 -1
- data/spec/semipublic/property_spec.rb +32 -7
- data/spec/semipublic/query/conditions/comparison_spec.rb +1 -264
- data/spec/semipublic/query/conditions/operation_spec.rb +1 -2
- data/spec/semipublic/query/path_spec.rb +27 -1
- data/spec/semipublic/query_spec.rb +87 -36
- data/spec/semipublic/resource/state/clean_spec.rb +1 -2
- data/spec/semipublic/resource/state/deleted_spec.rb +1 -2
- data/spec/semipublic/resource/state/dirty_spec.rb +1 -2
- data/spec/semipublic/resource/state/immutable_spec.rb +1 -2
- data/spec/semipublic/resource/state/transient_spec.rb +7 -2
- data/spec/semipublic/resource/state_spec.rb +1 -1
- data/spec/semipublic/resource_spec.rb +1 -1
- data/spec/unit/array_spec.rb +1 -0
- data/spec/unit/data_mapper/ordered_set/append_spec.rb +26 -0
- data/spec/unit/data_mapper/ordered_set/clear_spec.rb +24 -0
- data/spec/unit/data_mapper/ordered_set/delete_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/each_spec.rb +19 -0
- data/spec/unit/data_mapper/ordered_set/empty_spec.rb +20 -0
- data/spec/unit/data_mapper/ordered_set/entries_spec.rb +22 -0
- data/spec/unit/data_mapper/ordered_set/eql_spec.rb +51 -0
- data/spec/unit/data_mapper/ordered_set/equal_value_spec.rb +84 -0
- data/spec/unit/data_mapper/ordered_set/hash_spec.rb +12 -0
- data/spec/unit/data_mapper/ordered_set/include_spec.rb +23 -0
- data/spec/unit/data_mapper/ordered_set/index_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/initialize_spec.rb +32 -0
- data/spec/unit/data_mapper/ordered_set/merge_spec.rb +36 -0
- data/spec/unit/data_mapper/ordered_set/shared/append_spec.rb +24 -0
- data/spec/unit/data_mapper/ordered_set/shared/clear_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/delete_spec.rb +25 -0
- data/spec/unit/data_mapper/ordered_set/shared/each_spec.rb +17 -0
- data/spec/unit/data_mapper/ordered_set/shared/empty_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/entries_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/include_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/index_spec.rb +13 -0
- data/spec/unit/data_mapper/ordered_set/shared/initialize_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/shared/merge_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/shared/size_spec.rb +13 -0
- data/spec/unit/data_mapper/ordered_set/shared/to_ary_spec.rb +11 -0
- data/spec/unit/data_mapper/ordered_set/size_spec.rb +27 -0
- data/spec/unit/data_mapper/ordered_set/to_ary_spec.rb +23 -0
- data/spec/unit/data_mapper/subject_set/append_spec.rb +47 -0
- data/spec/unit/data_mapper/subject_set/clear_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/delete_spec.rb +40 -0
- data/spec/unit/data_mapper/subject_set/each_spec.rb +30 -0
- data/spec/unit/data_mapper/subject_set/empty_spec.rb +31 -0
- data/spec/unit/data_mapper/subject_set/entries_spec.rb +31 -0
- data/spec/unit/data_mapper/subject_set/get_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/include_spec.rb +32 -0
- data/spec/unit/data_mapper/subject_set/named_spec.rb +33 -0
- data/spec/unit/data_mapper/subject_set/shared/append_spec.rb +18 -0
- data/spec/unit/data_mapper/subject_set/shared/clear_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/delete_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/each_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/empty_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/entries_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/get_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/include_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/named_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/size_spec.rb +13 -0
- data/spec/unit/data_mapper/subject_set/shared/to_ary_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/values_at_spec.rb +44 -0
- data/spec/unit/data_mapper/subject_set/size_spec.rb +42 -0
- data/spec/unit/data_mapper/subject_set/to_ary_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/values_at_spec.rb +57 -0
- data/spec/unit/hash_spec.rb +2 -1
- data/spec/unit/hook_spec.rb +1 -0
- data/spec/unit/lazy_array_spec.rb +2 -1
- data/spec/unit/module_spec.rb +2 -1
- data/spec/unit/object_spec.rb +1 -0
- data/spec/unit/try_dup_spec.rb +1 -0
- data/tasks/spec.rake +0 -3
- metadata +149 -52
- data/.gitignore +0 -37
- data/lib/dm-core/type.rb +0 -216
- data/lib/dm-core/types/boolean.rb +0 -9
- data/lib/dm-core/types/decimal.rb +0 -9
- data/lib/dm-core/types/discriminator.rb +0 -50
- data/lib/dm-core/types/object.rb +0 -25
- data/lib/dm-core/types/serial.rb +0 -11
- data/lib/dm-core/types/text.rb +0 -11
- data/tasks/local_gemfile.rake +0 -16
- data/tasks/metrics.rake +0 -37
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
share_examples_for 'it creates a one accessor' do
|
4
4
|
describe 'accessor' do
|
@@ -614,9 +614,7 @@ describe DataMapper::Associations do
|
|
614
614
|
end
|
615
615
|
|
616
616
|
it 'should also change the foreign key' do
|
617
|
-
|
618
|
-
@engine.car.should eql(@car2)
|
619
|
-
end
|
617
|
+
@engine.car.should eql(@car2)
|
620
618
|
end
|
621
619
|
|
622
620
|
it 'should add the engine to the car' do
|
data/spec/public/model_spec.rb
CHANGED
@@ -1,12 +1,13 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Property::Decimal do
|
4
4
|
before :all do
|
5
|
-
@name
|
6
|
-
@type
|
7
|
-
@
|
8
|
-
@
|
9
|
-
@
|
5
|
+
@name = :rate
|
6
|
+
@type = DataMapper::Property::Decimal
|
7
|
+
@options = { :precision => 5, :scale => 2 }
|
8
|
+
@primitive = BigDecimal
|
9
|
+
@value = BigDecimal('1.0')
|
10
|
+
@other_value = BigDecimal('2.0')
|
10
11
|
@invalid_value = true
|
11
12
|
end
|
12
13
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Property, 'Object type' do
|
4
4
|
before :all do
|
@@ -31,7 +31,7 @@ describe DataMapper::Property, 'Object type' do
|
|
31
31
|
it { should equal(@value) }
|
32
32
|
end
|
33
33
|
|
34
|
-
it { should respond_to(:
|
34
|
+
it { should respond_to(:dump) }
|
35
35
|
|
36
36
|
describe '#dump' do
|
37
37
|
describe 'with a value' do
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Property::Text do
|
4
4
|
before :all do
|
@@ -15,7 +15,8 @@ describe DataMapper::Property::Text do
|
|
15
15
|
describe 'migration with an index' do
|
16
16
|
supported_by :all do
|
17
17
|
before do
|
18
|
-
|
18
|
+
Object.send(:remove_const, :Foo) if Object.const_defined?(:Foo)
|
19
|
+
@model = DataMapper::Model.new('Foo') do
|
19
20
|
storage_names[:default] = 'anonymous'
|
20
21
|
|
21
22
|
property :id, DataMapper::Property::Serial
|
@@ -34,7 +35,9 @@ describe DataMapper::Property::Text do
|
|
34
35
|
describe 'migration with a unique index' do
|
35
36
|
supported_by :all do
|
36
37
|
before do
|
37
|
-
|
38
|
+
|
39
|
+
Object.send(:remove_const, :Foo) if Object.const_defined?(:Foo)
|
40
|
+
@model = DataMapper::Model.new('Foo') do
|
38
41
|
storage_names[:default] = 'anonymous'
|
39
42
|
|
40
43
|
property :id, DataMapper::Property::Serial
|
@@ -1,5 +1,5 @@
|
|
1
1
|
# -*- coding: utf-8 -*-
|
2
|
-
require
|
2
|
+
require 'spec_helper'
|
3
3
|
|
4
4
|
# instance methods
|
5
5
|
describe DataMapper::Property do
|
@@ -22,6 +22,8 @@ describe DataMapper::Property do
|
|
22
22
|
property :md5hash, String, :key => true, :length => 32
|
23
23
|
property :title, String, :required => true, :unique => true
|
24
24
|
property :description, Text, :length => 1..1024, :lazy => [ :detail ]
|
25
|
+
property :width, Integer, :lazy => [:dimensions]
|
26
|
+
property :height, Integer, :lazy => [:dimensions]
|
25
27
|
property :format, String, :default => 'jpeg'
|
26
28
|
property :taken_at, Time, :default => proc { Time.now }
|
27
29
|
end
|
@@ -39,12 +41,6 @@ describe DataMapper::Property do
|
|
39
41
|
it 'sets field value using field naming convention on first reference'
|
40
42
|
end
|
41
43
|
|
42
|
-
describe '#custom?' do
|
43
|
-
it 'is true for custom type fields (not provided by dm-core)'
|
44
|
-
|
45
|
-
it 'is false for core type fields (provided by dm-core)'
|
46
|
-
end
|
47
|
-
|
48
44
|
describe '#default_for' do
|
49
45
|
it 'returns default value for non-callables' do
|
50
46
|
Image.properties[:format].default_for(Image.new).should == 'jpeg'
|
@@ -103,10 +99,6 @@ describe DataMapper::Property do
|
|
103
99
|
describe 'when tracking strategy is explicitly given' do
|
104
100
|
it 'uses tracking strategy from options'
|
105
101
|
end
|
106
|
-
|
107
|
-
describe 'when custom type has tracking stragegy' do
|
108
|
-
it 'uses tracking strategy from type'
|
109
|
-
end
|
110
102
|
end
|
111
103
|
|
112
104
|
describe '#inspect' do
|
@@ -150,6 +142,16 @@ describe DataMapper::Property do
|
|
150
142
|
end
|
151
143
|
end
|
152
144
|
|
145
|
+
describe "#lazy_load_properties" do
|
146
|
+
it "returns all lazy properties in the same context" do
|
147
|
+
Image.properties[:width].__send__(:lazy_load_properties).should == Image.properties.values_at(:width, :height)
|
148
|
+
end
|
149
|
+
|
150
|
+
it "returns all properties by default" do
|
151
|
+
Track.properties[:artist].__send__(:lazy_load_properties).should == Track.properties
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
153
155
|
describe '#length' do
|
154
156
|
it 'returns upper bound for Range values' do
|
155
157
|
Image.properties[:description].length.should eql(1024)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Resource do
|
4
4
|
before :all do
|
@@ -180,5 +180,47 @@ describe DataMapper::Resource do
|
|
180
180
|
end
|
181
181
|
end
|
182
182
|
end
|
183
|
+
|
184
|
+
[ :update, :update! ].each do |method|
|
185
|
+
describe 'with attributes where one is a foreign key' do
|
186
|
+
before :all do
|
187
|
+
rescue_if @skip do
|
188
|
+
@dkubb = @user.referrer = @user_model.create(:name => 'dkubb', :age => 33)
|
189
|
+
@user.save
|
190
|
+
@user = @user_model.get(*@user.key)
|
191
|
+
@user.referrer.should == @dkubb
|
192
|
+
|
193
|
+
@solnic = @user_model.create(:name => 'solnic', :age => 28)
|
194
|
+
|
195
|
+
@attributes = {}
|
196
|
+
|
197
|
+
relationship = @user_model.relationships[:referrer]
|
198
|
+
relationship.child_key.to_a.each_with_index do |k, i|
|
199
|
+
@attributes[k.name] = relationship.parent_key.to_a[i].get(@solnic)
|
200
|
+
end
|
201
|
+
|
202
|
+
@return = @user.__send__(method, @attributes)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
it 'should return true' do
|
207
|
+
@return.should be(true)
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should update attributes of Resource' do
|
211
|
+
@attributes.each { |key, value| @user.__send__(key).should == value }
|
212
|
+
end
|
213
|
+
|
214
|
+
it 'should persist the changes' do
|
215
|
+
resource = @user_model.get(*@user.key)
|
216
|
+
@attributes.each { |key, value| resource.__send__(key).should == value }
|
217
|
+
end
|
218
|
+
|
219
|
+
it 'should return correct parent' do
|
220
|
+
resource = @user_model.get(*@user.key)
|
221
|
+
resource.referrer.should == @solnic
|
222
|
+
end
|
223
|
+
end
|
224
|
+
end
|
183
225
|
end
|
184
226
|
end
|
data/spec/public/sel_spec.rb
CHANGED
data/spec/public/setup_spec.rb
CHANGED
@@ -566,7 +566,8 @@ share_examples_for 'A public Collection' do
|
|
566
566
|
describe '#new' do
|
567
567
|
describe 'when scoped to a property' do
|
568
568
|
before :all do
|
569
|
-
@
|
569
|
+
@source = @articles.new(:attachment => "A File")
|
570
|
+
@return = @resource = @articles.new(:original => @source)
|
570
571
|
end
|
571
572
|
|
572
573
|
it 'should return a Resource' do
|
@@ -584,6 +585,10 @@ share_examples_for 'A public Collection' do
|
|
584
585
|
it 'should use the query conditions to set default values' do
|
585
586
|
@resource.title.should == 'Sample Article'
|
586
587
|
end
|
588
|
+
|
589
|
+
it 'should use the query conditions to set default values when accessed through a m:1 relationship' do
|
590
|
+
@resource.original.attachment.should == 'A File'
|
591
|
+
end
|
587
592
|
end
|
588
593
|
|
589
594
|
describe 'when scoped to the key' do
|
@@ -1,11 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe DataMapper::Property::Decimal do
|
4
4
|
before :all do
|
5
|
-
@name
|
6
|
-
@type
|
7
|
-
@
|
8
|
-
@
|
5
|
+
@name = :rate
|
6
|
+
@type = DataMapper::Property::Decimal
|
7
|
+
@options = { :precision => 5, :scale => 2 }
|
8
|
+
@value = BigDecimal('1.0')
|
9
|
+
@other_value = BigDecimal('2.0')
|
9
10
|
@invalid_value = true
|
10
11
|
end
|
11
12
|
|