dm-core 1.0.0.rc2 → 1.0.0.rc3
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.
- data/Gemfile +1 -1
- data/LICENSE +1 -1
- data/README.rdoc +1 -1
- data/Rakefile +3 -4
- data/VERSION +1 -1
- data/dm-core.gemspec +7 -5
- data/lib/dm-core.rb +44 -0
- data/lib/dm-core/adapters.rb +1 -1
- data/lib/dm-core/adapters/abstract_adapter.rb +16 -0
- data/lib/dm-core/collection.rb +2 -2
- data/lib/dm-core/model.rb +64 -53
- data/lib/dm-core/model/property.rb +14 -6
- data/lib/dm-core/model/relationship.rb +10 -18
- data/lib/dm-core/property.rb +10 -10
- data/lib/dm-core/query.rb +8 -18
- data/lib/dm-core/resource.rb +3 -11
- data/lib/dm-core/resource/state.rb +13 -16
- data/lib/dm-core/resource/state/dirty.rb +11 -1
- data/lib/dm-core/resource/state/transient.rb +9 -1
- data/lib/dm-core/spec/lib/adapter_helpers.rb +5 -0
- data/lib/dm-core/spec/shared/adapter_spec.rb +2 -0
- data/lib/dm-core/spec/shared/resource_spec.rb +0 -31
- data/lib/dm-core/version.rb +1 -1
- data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +2 -0
- data/spec/public/associations/many_to_many_spec.rb +2 -1
- data/spec/public/associations/many_to_one_spec.rb +1 -0
- data/spec/public/associations/many_to_one_with_boolean_cpk_spec.rb +1 -0
- data/spec/public/associations/one_to_many_spec.rb +2 -0
- data/spec/public/associations/one_to_one_spec.rb +2 -0
- data/spec/public/associations/one_to_one_with_boolean_cpk_spec.rb +1 -0
- data/spec/public/collection_spec.rb +2 -0
- data/spec/public/finalize_spec.rb +34 -0
- data/spec/public/model/hook_spec.rb +1 -0
- data/spec/public/model/property_spec.rb +1 -0
- data/spec/public/model/relationship_spec.rb +22 -0
- data/spec/public/model_spec.rb +138 -3
- data/spec/public/property/discriminator_spec.rb +1 -0
- data/spec/public/property/object_spec.rb +1 -0
- data/spec/public/property_spec.rb +13 -4
- data/spec/public/resource_spec.rb +1 -0
- data/spec/public/sel_spec.rb +2 -0
- data/spec/public/shared/collection_shared_spec.rb +0 -45
- data/spec/public/shared/finder_shared_spec.rb +110 -0
- data/spec/public/shared/property_shared_spec.rb +1 -1
- data/spec/rcov.opts +1 -1
- data/spec/semipublic/associations/many_to_many_spec.rb +3 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +2 -0
- data/spec/semipublic/associations/one_to_many_spec.rb +2 -0
- data/spec/semipublic/associations/one_to_one_spec.rb +2 -0
- data/spec/semipublic/associations/relationship_spec.rb +6 -0
- data/spec/semipublic/query/conditions/comparison_spec.rb +3 -0
- data/spec/semipublic/query/conditions/operation_spec.rb +1 -0
- data/spec/semipublic/query/path_spec.rb +2 -0
- data/spec/semipublic/query_spec.rb +2 -3
- data/spec/semipublic/resource/state/clean_spec.rb +2 -1
- data/spec/semipublic/resource/state/deleted_spec.rb +2 -1
- data/spec/semipublic/resource/state/dirty_spec.rb +42 -20
- data/spec/semipublic/resource/state/immutable_spec.rb +7 -1
- data/spec/semipublic/resource/state/transient_spec.rb +69 -40
- data/spec/semipublic/resource/state_spec.rb +72 -66
- data/spec/semipublic/shared/property_shared_spec.rb +1 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +1 -0
- data/spec/spec_helper.rb +0 -10
- data/tasks/spec.rake +3 -0
- metadata +9 -7
@@ -11,18 +11,30 @@ describe DataMapper::Resource::State::Transient do
|
|
11
11
|
property :description, Text, :default => lambda { |resource, property| resource.name }
|
12
12
|
property :active, Boolean, :default => true
|
13
13
|
property :coding, Boolean, :default => true
|
14
|
+
|
15
|
+
belongs_to :parent, self, :required => false
|
16
|
+
has n, :children, self, :inverse => :parent
|
17
|
+
|
18
|
+
belongs_to :with_default, self, :required => false, :default => proc { first(:name => 'John Doe') }
|
14
19
|
end
|
15
20
|
|
21
|
+
DataMapper.finalize
|
22
|
+
|
16
23
|
@model = Author
|
17
24
|
end
|
18
25
|
|
19
26
|
before do
|
20
|
-
@
|
27
|
+
@parent = @model.create(:name => 'John Doe')
|
28
|
+
@resource = @model.new(:name => 'Dan Kubb', :coding => false, :parent => @parent)
|
21
29
|
|
22
30
|
@state = @resource.persisted_state
|
23
31
|
@state.should be_kind_of(DataMapper::Resource::State::Transient)
|
24
32
|
end
|
25
33
|
|
34
|
+
after do
|
35
|
+
@model.destroy!
|
36
|
+
end
|
37
|
+
|
26
38
|
describe '#commit' do
|
27
39
|
subject { @state.commit }
|
28
40
|
|
@@ -35,8 +47,14 @@ describe DataMapper::Resource::State::Transient do
|
|
35
47
|
method(:subject).should change(@resource, :id).from(nil)
|
36
48
|
end
|
37
49
|
|
50
|
+
it 'should set the child key if the parent key changes' do
|
51
|
+
original_id = @parent.id
|
52
|
+
@parent.update(:id => 42).should be(true)
|
53
|
+
method(:subject).should change(@resource, :parent_id).from(original_id).to(42)
|
54
|
+
end
|
55
|
+
|
38
56
|
it 'should set default values' do
|
39
|
-
method(:subject).should change { @model.
|
57
|
+
method(:subject).should change { @model.relationships[:with_default].get!(@resource) }.from(nil).to(@parent)
|
40
58
|
end
|
41
59
|
|
42
60
|
it 'should not set default values when they are already set' do
|
@@ -49,9 +67,16 @@ describe DataMapper::Resource::State::Transient do
|
|
49
67
|
end
|
50
68
|
|
51
69
|
it 'should reset original attributes' do
|
70
|
+
original_attributes = {
|
71
|
+
@model.properties[:name] => nil,
|
72
|
+
@model.properties[:coding] => nil,
|
73
|
+
@model.properties[:parent_id] => nil,
|
74
|
+
@model.relationships[:parent] => nil,
|
75
|
+
}
|
76
|
+
|
52
77
|
expect do
|
53
78
|
@resource.persisted_state = subject
|
54
|
-
end.should change { @resource.original_attributes.dup }.from(
|
79
|
+
end.should change { @resource.original_attributes.dup }.from(original_attributes).to({})
|
55
80
|
end
|
56
81
|
|
57
82
|
it 'should add the resource to the identity map' do
|
@@ -59,7 +84,7 @@ describe DataMapper::Resource::State::Transient do
|
|
59
84
|
identity_map = repository.identity_map(@model)
|
60
85
|
identity_map.should be_empty
|
61
86
|
subject
|
62
|
-
identity_map.should == { @resource.key => @resource }
|
87
|
+
identity_map.should == { @parent.key => @parent, @resource.key => @resource }
|
63
88
|
end
|
64
89
|
end
|
65
90
|
end
|
@@ -69,8 +94,10 @@ describe DataMapper::Resource::State::Transient do
|
|
69
94
|
describe "##{method}" do
|
70
95
|
subject { @state.send(method) }
|
71
96
|
|
72
|
-
|
73
|
-
should
|
97
|
+
supported_by :all do
|
98
|
+
it 'should be a no-op' do
|
99
|
+
should equal(@state)
|
100
|
+
end
|
74
101
|
end
|
75
102
|
end
|
76
103
|
end
|
@@ -78,50 +105,52 @@ describe DataMapper::Resource::State::Transient do
|
|
78
105
|
describe '#get' do
|
79
106
|
subject { @state.get(@key) }
|
80
107
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
108
|
+
supported_by :all do
|
109
|
+
describe 'with a set value' do
|
110
|
+
before do
|
111
|
+
@key = @model.properties[:coding]
|
112
|
+
@key.should be_loaded(@resource)
|
113
|
+
end
|
86
114
|
|
87
|
-
|
88
|
-
|
89
|
-
|
115
|
+
it 'should return value' do
|
116
|
+
should be(false)
|
117
|
+
end
|
90
118
|
|
91
|
-
|
92
|
-
|
119
|
+
it 'should be idempotent' do
|
120
|
+
should equal(subject)
|
121
|
+
end
|
93
122
|
end
|
94
|
-
end
|
95
123
|
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
124
|
+
describe 'with an unset value and no default value' do
|
125
|
+
before do
|
126
|
+
@key = @model.properties[:age]
|
127
|
+
@key.should_not be_loaded(@resource)
|
128
|
+
@key.should_not be_default
|
129
|
+
end
|
102
130
|
|
103
|
-
|
104
|
-
|
105
|
-
|
131
|
+
it 'should return nil' do
|
132
|
+
should be_nil
|
133
|
+
end
|
106
134
|
|
107
|
-
|
108
|
-
|
135
|
+
it 'should be idempotent' do
|
136
|
+
should equal(subject)
|
137
|
+
end
|
109
138
|
end
|
110
|
-
end
|
111
139
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
140
|
+
describe 'with an unset value and a default value' do
|
141
|
+
before do
|
142
|
+
@key = @model.properties[:description]
|
143
|
+
@key.should_not be_loaded(@resource)
|
144
|
+
@key.should be_default
|
145
|
+
end
|
118
146
|
|
119
|
-
|
120
|
-
|
121
|
-
|
147
|
+
it 'should return the name' do
|
148
|
+
should == 'Dan Kubb'
|
149
|
+
end
|
122
150
|
|
123
|
-
|
124
|
-
|
151
|
+
it 'should be idempotent' do
|
152
|
+
should equal(subject)
|
153
|
+
end
|
125
154
|
end
|
126
155
|
end
|
127
156
|
end
|
@@ -12,6 +12,8 @@ describe DataMapper::Resource::State do
|
|
12
12
|
belongs_to :parent, self, :required => false
|
13
13
|
end
|
14
14
|
|
15
|
+
DataMapper.finalize
|
16
|
+
|
15
17
|
@model = Author
|
16
18
|
end
|
17
19
|
|
@@ -30,53 +32,55 @@ describe DataMapper::Resource::State do
|
|
30
32
|
describe '#==' do
|
31
33
|
subject { @state == @other }
|
32
34
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
supported_by :all do
|
36
|
+
describe 'with the same class and resource' do
|
37
|
+
before do
|
38
|
+
@other = DataMapper::Resource::State.new(@resource)
|
39
|
+
end
|
37
40
|
|
38
|
-
|
41
|
+
it { should be(true) }
|
39
42
|
|
40
|
-
|
41
|
-
|
43
|
+
it 'should be symmetric' do
|
44
|
+
should == (@other == @state)
|
45
|
+
end
|
42
46
|
end
|
43
|
-
end
|
44
47
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
48
|
+
describe 'with the same class and different resource' do
|
49
|
+
before do
|
50
|
+
@other = DataMapper::Resource::State.new(@model.new)
|
51
|
+
end
|
49
52
|
|
50
|
-
|
53
|
+
it { should be(false) }
|
51
54
|
|
52
|
-
|
53
|
-
|
55
|
+
it 'should be symmetric' do
|
56
|
+
should == (@other == @state)
|
57
|
+
end
|
54
58
|
end
|
55
|
-
end
|
56
59
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
60
|
+
describe 'with a different class and the same resource' do
|
61
|
+
before do
|
62
|
+
@other = DataMapper::Resource::State::Clean.new(@resource)
|
63
|
+
end
|
61
64
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
+
it 'should be true for a subclass' do
|
66
|
+
should be(true)
|
67
|
+
end
|
65
68
|
|
66
|
-
|
67
|
-
|
69
|
+
it 'should be symmetric' do
|
70
|
+
should == (@other == @state)
|
71
|
+
end
|
68
72
|
end
|
69
|
-
end
|
70
73
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
74
|
+
describe 'with a different class and different resource' do
|
75
|
+
before do
|
76
|
+
@other = DataMapper::Resource::State::Clean.new(@model.new)
|
77
|
+
end
|
75
78
|
|
76
|
-
|
79
|
+
it { should be(false) }
|
77
80
|
|
78
|
-
|
79
|
-
|
81
|
+
it 'should be symmetric' do
|
82
|
+
should == (@other == @state)
|
83
|
+
end
|
80
84
|
end
|
81
85
|
end
|
82
86
|
end
|
@@ -94,51 +98,53 @@ describe DataMapper::Resource::State do
|
|
94
98
|
describe '#eql?' do
|
95
99
|
subject { @state.eql?(@other) }
|
96
100
|
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
+
supported_by :all do
|
102
|
+
describe 'with the same class and resource' do
|
103
|
+
before do
|
104
|
+
@other = DataMapper::Resource::State.new(@resource)
|
105
|
+
end
|
101
106
|
|
102
|
-
|
107
|
+
it { should be(true) }
|
103
108
|
|
104
|
-
|
105
|
-
|
109
|
+
it 'should be symmetric' do
|
110
|
+
should == @other.eql?(@state)
|
111
|
+
end
|
106
112
|
end
|
107
|
-
end
|
108
113
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
114
|
+
describe 'with the same class and different resource' do
|
115
|
+
before do
|
116
|
+
@other = DataMapper::Resource::State.new(@model.new)
|
117
|
+
end
|
113
118
|
|
114
|
-
|
119
|
+
it { should be(false) }
|
115
120
|
|
116
|
-
|
117
|
-
|
121
|
+
it 'should be symmetric' do
|
122
|
+
should == @other.eql?(@state)
|
123
|
+
end
|
118
124
|
end
|
119
|
-
end
|
120
125
|
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
126
|
+
describe 'with a different class and the same resource' do
|
127
|
+
before do
|
128
|
+
@other = DataMapper::Resource::State::Clean.new(@resource)
|
129
|
+
end
|
125
130
|
|
126
|
-
|
131
|
+
it { should be(false) }
|
127
132
|
|
128
|
-
|
129
|
-
|
133
|
+
it 'should be symmetric' do
|
134
|
+
should == @other.eql?(@state)
|
135
|
+
end
|
130
136
|
end
|
131
|
-
end
|
132
137
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
138
|
+
describe 'with a different class and different resource' do
|
139
|
+
before do
|
140
|
+
@other = DataMapper::Resource::State::Clean.new(@model.new)
|
141
|
+
end
|
137
142
|
|
138
|
-
|
143
|
+
it { should be(false) }
|
139
144
|
|
140
|
-
|
141
|
-
|
145
|
+
it 'should be symmetric' do
|
146
|
+
should == @other.eql?(@state)
|
147
|
+
end
|
142
148
|
end
|
143
149
|
end
|
144
150
|
end
|
@@ -175,8 +181,8 @@ describe DataMapper::Resource::State do
|
|
175
181
|
describe '#hash' do
|
176
182
|
subject { @state.hash }
|
177
183
|
|
178
|
-
it 'should be the
|
179
|
-
should == @resource.
|
184
|
+
it 'should be the hash of the resource' do
|
185
|
+
should == @resource.hash
|
180
186
|
end
|
181
187
|
end
|
182
188
|
|
data/spec/spec_helper.rb
CHANGED
@@ -35,13 +35,3 @@ Spec::Runner.configure do |config|
|
|
35
35
|
end
|
36
36
|
|
37
37
|
end
|
38
|
-
|
39
|
-
# remove the Resource#send method to ensure specs/internals do no rely on it
|
40
|
-
module RemoveSend
|
41
|
-
def self.included(model)
|
42
|
-
model.send(:undef_method, :send)
|
43
|
-
model.send(:undef_method, :freeze)
|
44
|
-
end
|
45
|
-
|
46
|
-
DataMapper::Model.append_inclusions self
|
47
|
-
end
|
data/tasks/spec.rake
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dm-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 977940572
|
5
5
|
prerelease: true
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 0
|
9
9
|
- 0
|
10
|
-
-
|
11
|
-
version: 1.0.0.
|
10
|
+
- rc3
|
11
|
+
version: 1.0.0.rc3
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Dan Kubb
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-05-
|
19
|
+
date: 2010-05-27 00:00:00 -07:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
@@ -27,12 +27,12 @@ dependencies:
|
|
27
27
|
requirements:
|
28
28
|
- - ~>
|
29
29
|
- !ruby/object:Gem::Version
|
30
|
-
hash:
|
30
|
+
hash: 37
|
31
31
|
segments:
|
32
32
|
- 0
|
33
33
|
- 9
|
34
|
-
-
|
35
|
-
version: 0.9.
|
34
|
+
- 15
|
35
|
+
version: 0.9.15
|
36
36
|
type: :runtime
|
37
37
|
version_requirements: *id001
|
38
38
|
- !ruby/object:Gem::Dependency
|
@@ -199,6 +199,7 @@ files:
|
|
199
199
|
- spec/public/associations/one_to_one_spec.rb
|
200
200
|
- spec/public/associations/one_to_one_with_boolean_cpk_spec.rb
|
201
201
|
- spec/public/collection_spec.rb
|
202
|
+
- spec/public/finalize_spec.rb
|
202
203
|
- spec/public/model/hook_spec.rb
|
203
204
|
- spec/public/model/property_spec.rb
|
204
205
|
- spec/public/model/relationship_spec.rb
|
@@ -329,6 +330,7 @@ test_files:
|
|
329
330
|
- spec/public/associations/one_to_one_spec.rb
|
330
331
|
- spec/public/associations/one_to_one_with_boolean_cpk_spec.rb
|
331
332
|
- spec/public/collection_spec.rb
|
333
|
+
- spec/public/finalize_spec.rb
|
332
334
|
- spec/public/model/hook_spec.rb
|
333
335
|
- spec/public/model/property_spec.rb
|
334
336
|
- spec/public/model/relationship_spec.rb
|