dm-core 1.0.0.rc2 → 1.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/Gemfile +1 -1
  2. data/LICENSE +1 -1
  3. data/README.rdoc +1 -1
  4. data/Rakefile +3 -4
  5. data/VERSION +1 -1
  6. data/dm-core.gemspec +7 -5
  7. data/lib/dm-core.rb +44 -0
  8. data/lib/dm-core/adapters.rb +1 -1
  9. data/lib/dm-core/adapters/abstract_adapter.rb +16 -0
  10. data/lib/dm-core/collection.rb +2 -2
  11. data/lib/dm-core/model.rb +64 -53
  12. data/lib/dm-core/model/property.rb +14 -6
  13. data/lib/dm-core/model/relationship.rb +10 -18
  14. data/lib/dm-core/property.rb +10 -10
  15. data/lib/dm-core/query.rb +8 -18
  16. data/lib/dm-core/resource.rb +3 -11
  17. data/lib/dm-core/resource/state.rb +13 -16
  18. data/lib/dm-core/resource/state/dirty.rb +11 -1
  19. data/lib/dm-core/resource/state/transient.rb +9 -1
  20. data/lib/dm-core/spec/lib/adapter_helpers.rb +5 -0
  21. data/lib/dm-core/spec/shared/adapter_spec.rb +2 -0
  22. data/lib/dm-core/spec/shared/resource_spec.rb +0 -31
  23. data/lib/dm-core/version.rb +1 -1
  24. data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +2 -0
  25. data/spec/public/associations/many_to_many_spec.rb +2 -1
  26. data/spec/public/associations/many_to_one_spec.rb +1 -0
  27. data/spec/public/associations/many_to_one_with_boolean_cpk_spec.rb +1 -0
  28. data/spec/public/associations/one_to_many_spec.rb +2 -0
  29. data/spec/public/associations/one_to_one_spec.rb +2 -0
  30. data/spec/public/associations/one_to_one_with_boolean_cpk_spec.rb +1 -0
  31. data/spec/public/collection_spec.rb +2 -0
  32. data/spec/public/finalize_spec.rb +34 -0
  33. data/spec/public/model/hook_spec.rb +1 -0
  34. data/spec/public/model/property_spec.rb +1 -0
  35. data/spec/public/model/relationship_spec.rb +22 -0
  36. data/spec/public/model_spec.rb +138 -3
  37. data/spec/public/property/discriminator_spec.rb +1 -0
  38. data/spec/public/property/object_spec.rb +1 -0
  39. data/spec/public/property_spec.rb +13 -4
  40. data/spec/public/resource_spec.rb +1 -0
  41. data/spec/public/sel_spec.rb +2 -0
  42. data/spec/public/shared/collection_shared_spec.rb +0 -45
  43. data/spec/public/shared/finder_shared_spec.rb +110 -0
  44. data/spec/public/shared/property_shared_spec.rb +1 -1
  45. data/spec/rcov.opts +1 -1
  46. data/spec/semipublic/associations/many_to_many_spec.rb +3 -0
  47. data/spec/semipublic/associations/many_to_one_spec.rb +2 -0
  48. data/spec/semipublic/associations/one_to_many_spec.rb +2 -0
  49. data/spec/semipublic/associations/one_to_one_spec.rb +2 -0
  50. data/spec/semipublic/associations/relationship_spec.rb +6 -0
  51. data/spec/semipublic/query/conditions/comparison_spec.rb +3 -0
  52. data/spec/semipublic/query/conditions/operation_spec.rb +1 -0
  53. data/spec/semipublic/query/path_spec.rb +2 -0
  54. data/spec/semipublic/query_spec.rb +2 -3
  55. data/spec/semipublic/resource/state/clean_spec.rb +2 -1
  56. data/spec/semipublic/resource/state/deleted_spec.rb +2 -1
  57. data/spec/semipublic/resource/state/dirty_spec.rb +42 -20
  58. data/spec/semipublic/resource/state/immutable_spec.rb +7 -1
  59. data/spec/semipublic/resource/state/transient_spec.rb +69 -40
  60. data/spec/semipublic/resource/state_spec.rb +72 -66
  61. data/spec/semipublic/shared/property_shared_spec.rb +1 -0
  62. data/spec/semipublic/shared/resource_shared_spec.rb +1 -0
  63. data/spec/spec_helper.rb +0 -10
  64. data/tasks/spec.rake +3 -0
  65. 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
- @resource = @model.new(:name => 'Dan Kubb', :coding => false)
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.properties[:active].get!(@resource) }.from(nil).to(true)
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(@model.properties[:name] => nil, @model.properties[:coding] => nil).to({})
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
- it 'should be a no-op' do
73
- should equal(@state)
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
- describe 'with a set value' do
82
- before do
83
- @key = @model.properties[:coding]
84
- @key.should be_loaded(@resource)
85
- end
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
- it 'should return value' do
88
- should be(false)
89
- end
115
+ it 'should return value' do
116
+ should be(false)
117
+ end
90
118
 
91
- it 'should be idempotent' do
92
- should equal(subject)
119
+ it 'should be idempotent' do
120
+ should equal(subject)
121
+ end
93
122
  end
94
- end
95
123
 
96
- describe 'with an unset value and no default value' do
97
- before do
98
- @key = @model.properties[:age]
99
- @key.should_not be_loaded(@resource)
100
- @key.should_not be_default
101
- end
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
- it 'should return nil' do
104
- should be_nil
105
- end
131
+ it 'should return nil' do
132
+ should be_nil
133
+ end
106
134
 
107
- it 'should be idempotent' do
108
- should equal(subject)
135
+ it 'should be idempotent' do
136
+ should equal(subject)
137
+ end
109
138
  end
110
- end
111
139
 
112
- describe 'with an unset value and a default value' do
113
- before do
114
- @key = @model.properties[:description]
115
- @key.should_not be_loaded(@resource)
116
- @key.should be_default
117
- end
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
- it 'should return the name' do
120
- should == 'Dan Kubb'
121
- end
147
+ it 'should return the name' do
148
+ should == 'Dan Kubb'
149
+ end
122
150
 
123
- it 'should be idempotent' do
124
- should equal(subject)
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
- describe 'with the same class and resource' do
34
- before do
35
- @other = DataMapper::Resource::State.new(@resource)
36
- end
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
- it { should be(true) }
41
+ it { should be(true) }
39
42
 
40
- it 'should be symmetric' do
41
- should == (@other == @state)
43
+ it 'should be symmetric' do
44
+ should == (@other == @state)
45
+ end
42
46
  end
43
- end
44
47
 
45
- describe 'with the same class and different resource' do
46
- before do
47
- @other = DataMapper::Resource::State.new(@model.new)
48
- end
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
- it { should be(false) }
53
+ it { should be(false) }
51
54
 
52
- it 'should be symmetric' do
53
- should == (@other == @state)
55
+ it 'should be symmetric' do
56
+ should == (@other == @state)
57
+ end
54
58
  end
55
- end
56
59
 
57
- describe 'with a different class and the same resource' do
58
- before do
59
- @other = DataMapper::Resource::State::Clean.new(@resource)
60
- end
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
- it 'should be true for a subclass' do
63
- should be(true)
64
- end
65
+ it 'should be true for a subclass' do
66
+ should be(true)
67
+ end
65
68
 
66
- it 'should be symmetric' do
67
- should == (@other == @state)
69
+ it 'should be symmetric' do
70
+ should == (@other == @state)
71
+ end
68
72
  end
69
- end
70
73
 
71
- describe 'with a different class and different resource' do
72
- before do
73
- @other = DataMapper::Resource::State::Clean.new(@model.new)
74
- end
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
- it { should be(false) }
79
+ it { should be(false) }
77
80
 
78
- it 'should be symmetric' do
79
- should == (@other == @state)
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
- describe 'with the same class and resource' do
98
- before do
99
- @other = DataMapper::Resource::State.new(@resource)
100
- end
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
- it { should be(true) }
107
+ it { should be(true) }
103
108
 
104
- it 'should be symmetric' do
105
- should == @other.eql?(@state)
109
+ it 'should be symmetric' do
110
+ should == @other.eql?(@state)
111
+ end
106
112
  end
107
- end
108
113
 
109
- describe 'with the same class and different resource' do
110
- before do
111
- @other = DataMapper::Resource::State.new(@model.new)
112
- end
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
- it { should be(false) }
119
+ it { should be(false) }
115
120
 
116
- it 'should be symmetric' do
117
- should == @other.eql?(@state)
121
+ it 'should be symmetric' do
122
+ should == @other.eql?(@state)
123
+ end
118
124
  end
119
- end
120
125
 
121
- describe 'with a different class and the same resource' do
122
- before do
123
- @other = DataMapper::Resource::State::Clean.new(@resource)
124
- end
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
- it { should be(false) }
131
+ it { should be(false) }
127
132
 
128
- it 'should be symmetric' do
129
- should == @other.eql?(@state)
133
+ it 'should be symmetric' do
134
+ should == @other.eql?(@state)
135
+ end
130
136
  end
131
- end
132
137
 
133
- describe 'with a different class and different resource' do
134
- before do
135
- @other = DataMapper::Resource::State::Clean.new(@model.new)
136
- end
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
- it { should be(false) }
143
+ it { should be(false) }
139
144
 
140
- it 'should be symmetric' do
141
- should == @other.eql?(@state)
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 object_id hash of the resource' do
179
- should == @resource.object_id.hash
184
+ it 'should be the hash of the resource' do
185
+ should == @resource.hash
180
186
  end
181
187
  end
182
188
 
@@ -13,6 +13,7 @@ share_examples_for 'A semipublic Property' do
13
13
 
14
14
  @model = Blog::Article
15
15
  @property = @type.new(@model, @name)
16
+ DataMapper.finalize
16
17
  end
17
18
 
18
19
  describe '.new' do
@@ -160,6 +160,7 @@ share_examples_for 'A semipublic Resource' do
160
160
  property :name, String
161
161
  property :value, Integer
162
162
  end
163
+ DataMapper.finalize
163
164
  end
164
165
 
165
166
  with_alternate_adapter do
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
@@ -35,4 +35,7 @@ rescue LoadError
35
35
  end
36
36
  end
37
37
 
38
+ task :spec => :check_dependencies
39
+ task :rcov => :check_dependencies
40
+
38
41
  task :default => :spec
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: 977940575
4
+ hash: 977940572
5
5
  prerelease: true
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
9
  - 0
10
- - rc2
11
- version: 1.0.0.rc2
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 00:00:00 -07:00
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: 39
30
+ hash: 37
31
31
  segments:
32
32
  - 0
33
33
  - 9
34
- - 14
35
- version: 0.9.14
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