dm-core 1.1.0 → 1.2.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 (105) hide show
  1. data/Gemfile +22 -13
  2. data/README.rdoc +1 -1
  3. data/Rakefile +1 -2
  4. data/VERSION +1 -1
  5. data/dm-core.gemspec +29 -175
  6. data/lib/dm-core/adapters/abstract_adapter.rb +1 -2
  7. data/lib/dm-core/associations/many_to_many.rb +11 -5
  8. data/lib/dm-core/associations/many_to_one.rb +17 -2
  9. data/lib/dm-core/associations/one_to_many.rb +16 -0
  10. data/lib/dm-core/backwards.rb +13 -0
  11. data/lib/dm-core/collection.rb +1 -1
  12. data/lib/dm-core/model/property.rb +24 -27
  13. data/lib/dm-core/model/relationship.rb +22 -28
  14. data/lib/dm-core/model.rb +99 -41
  15. data/lib/dm-core/property/binary.rb +15 -0
  16. data/lib/dm-core/property/boolean.rb +6 -10
  17. data/lib/dm-core/property/date.rb +0 -2
  18. data/lib/dm-core/property/date_time.rb +0 -2
  19. data/lib/dm-core/property/decimal.rb +7 -3
  20. data/lib/dm-core/property/discriminator.rb +24 -26
  21. data/lib/dm-core/property/float.rb +5 -1
  22. data/lib/dm-core/property/numeric.rb +6 -9
  23. data/lib/dm-core/property/string.rb +2 -1
  24. data/lib/dm-core/property/time.rb +0 -2
  25. data/lib/dm-core/property/typecast/time.rb +7 -2
  26. data/lib/dm-core/property.rb +37 -50
  27. data/lib/dm-core/property_set.rb +1 -3
  28. data/lib/dm-core/query/conditions/comparison.rb +5 -1
  29. data/lib/dm-core/query/conditions/operation.rb +1 -1
  30. data/lib/dm-core/query.rb +3 -10
  31. data/lib/dm-core/relationship_set.rb +0 -2
  32. data/lib/dm-core/resource/{state → persistence_state}/clean.rb +4 -4
  33. data/lib/dm-core/resource/{state → persistence_state}/deleted.rb +2 -2
  34. data/lib/dm-core/resource/{state → persistence_state}/dirty.rb +2 -2
  35. data/lib/dm-core/resource/{state → persistence_state}/immutable.rb +3 -3
  36. data/lib/dm-core/resource/{state → persistence_state}/persisted.rb +3 -3
  37. data/lib/dm-core/resource/{state → persistence_state}/transient.rb +3 -3
  38. data/lib/dm-core/resource/{state.rb → persistence_state.rb} +2 -2
  39. data/lib/dm-core/resource.rb +27 -28
  40. data/lib/dm-core/spec/lib/adapter_helpers.rb +2 -5
  41. data/lib/dm-core/spec/setup.rb +3 -2
  42. data/lib/dm-core/spec/shared/public/property_spec.rb +8 -0
  43. data/lib/dm-core/spec/shared/resource_spec.rb +14 -0
  44. data/lib/dm-core/spec/shared/semipublic/property_spec.rb +5 -11
  45. data/lib/dm-core/support/descendant_set.rb +0 -2
  46. data/lib/dm-core/support/ext/array.rb +0 -19
  47. data/lib/dm-core/support/ext/blank.rb +1 -0
  48. data/lib/dm-core/support/hook.rb +0 -3
  49. data/lib/dm-core/support/naming_conventions.rb +6 -0
  50. data/lib/dm-core/support/ordered_set.rb +0 -2
  51. data/lib/dm-core/support/subject_set.rb +0 -2
  52. data/lib/dm-core/version.rb +1 -1
  53. data/lib/dm-core.rb +32 -67
  54. data/spec/public/associations/many_to_many_spec.rb +0 -1
  55. data/spec/public/model/property_spec.rb +55 -9
  56. data/spec/public/model/relationship_spec.rb +24 -2
  57. data/spec/public/model_spec.rb +32 -0
  58. data/spec/public/property/binary_spec.rb +33 -6
  59. data/spec/public/property/boolean_spec.rb +14 -6
  60. data/spec/public/property/class_spec.rb +14 -6
  61. data/spec/public/property/date_spec.rb +14 -6
  62. data/spec/public/property/date_time_spec.rb +14 -6
  63. data/spec/public/property/decimal_spec.rb +10 -2
  64. data/spec/public/property/discriminator_spec.rb +15 -1
  65. data/spec/public/property/float_spec.rb +14 -6
  66. data/spec/public/property/integer_spec.rb +14 -6
  67. data/spec/public/property/object_spec.rb +8 -0
  68. data/spec/public/property/serial_spec.rb +14 -6
  69. data/spec/public/property/string_spec.rb +14 -6
  70. data/spec/public/property/text_spec.rb +14 -6
  71. data/spec/public/property/time_spec.rb +14 -6
  72. data/spec/public/resource_spec.rb +58 -0
  73. data/spec/public/shared/finder_shared_spec.rb +8 -4
  74. data/spec/semipublic/associations/many_to_many_spec.rb +2 -0
  75. data/spec/semipublic/associations/many_to_one_spec.rb +2 -0
  76. data/spec/semipublic/associations/one_to_many_spec.rb +2 -0
  77. data/spec/semipublic/associations/one_to_one_spec.rb +2 -0
  78. data/spec/semipublic/property/binary_spec.rb +5 -5
  79. data/spec/semipublic/property/boolean_spec.rb +5 -23
  80. data/spec/semipublic/property/class_spec.rb +5 -5
  81. data/spec/semipublic/property/date_spec.rb +5 -5
  82. data/spec/semipublic/property/date_time_spec.rb +5 -5
  83. data/spec/semipublic/property/decimal_spec.rb +2 -2
  84. data/spec/semipublic/property/discriminator_spec.rb +5 -5
  85. data/spec/semipublic/property/float_spec.rb +5 -5
  86. data/spec/semipublic/property/integer_spec.rb +5 -5
  87. data/spec/semipublic/property/lookup_spec.rb +3 -3
  88. data/spec/semipublic/property/serial_spec.rb +5 -5
  89. data/spec/semipublic/property/string_spec.rb +5 -5
  90. data/spec/semipublic/property/text_spec.rb +5 -5
  91. data/spec/semipublic/property/time_spec.rb +5 -5
  92. data/spec/semipublic/query/conditions/comparison_spec.rb +44 -4
  93. data/spec/semipublic/query_spec.rb +2 -11
  94. data/spec/semipublic/resource/state/clean_spec.rb +6 -6
  95. data/spec/semipublic/resource/state/deleted_spec.rb +4 -4
  96. data/spec/semipublic/resource/state/dirty_spec.rb +8 -8
  97. data/spec/semipublic/resource/state/immutable_spec.rb +6 -6
  98. data/spec/semipublic/resource/state/transient_spec.rb +5 -5
  99. data/spec/semipublic/resource/state_spec.rb +15 -15
  100. data/spec/semipublic/shared/resource_shared_spec.rb +7 -1
  101. data/spec/semipublic/shared/resource_state_shared_spec.rb +8 -8
  102. data/spec/unit/array_spec.rb +0 -14
  103. data/spec/unit/blank_spec.rb +11 -0
  104. metadata +52 -174
  105. data/lib/dm-core/support/inflector.rb +0 -3
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::Time do
4
4
  before :all do
5
- @name = :deleted_at
6
- @type = DataMapper::Property::Time
7
- @value = Time.now
8
- @other_value = Time.now+15
5
+ @name = :deleted_at
6
+ @type = described_class
7
+ @value = Time.now
8
+ @other_value = Time.now + 15
9
9
  @invalid_value = 1
10
10
  end
11
11
 
12
- it_should_behave_like "A semipublic Property"
12
+ it_should_behave_like 'A semipublic Property'
13
13
 
14
14
  describe '#typecast_to_primitive' do
15
15
  describe 'and value given as a hash with keys like :year, :month, etc' do
@@ -149,7 +149,7 @@ describe DataMapper::Query::Conditions::EqualToComparison do
149
149
  end
150
150
 
151
151
  describe 'with a Relationship subject' do
152
- describe 'with a Relationship subject and a nil value' do
152
+ describe 'with a nil value' do
153
153
  before do
154
154
  @parent = @model.create(:title => 'Parent')
155
155
  @child = @parent.children.create(:title => 'Child')
@@ -182,7 +182,7 @@ describe DataMapper::Query::Conditions::EqualToComparison do
182
182
  end
183
183
  end
184
184
 
185
- describe 'with a Relationship subject and a Hash value' do
185
+ describe 'with a Hash value' do
186
186
  before do
187
187
  @parent = @model.create(:title => 'Parent')
188
188
  @child = @parent.children.create(:title => 'Child')
@@ -215,7 +215,7 @@ describe DataMapper::Query::Conditions::EqualToComparison do
215
215
  end
216
216
  end
217
217
 
218
- describe 'with a Relationship subject and new Resource value' do
218
+ describe 'with new Resource value' do
219
219
  before do
220
220
  @parent = @model.create(:title => 'Parent')
221
221
  @child = @parent.children.create(:title => 'Child')
@@ -250,7 +250,7 @@ describe DataMapper::Query::Conditions::EqualToComparison do
250
250
  end
251
251
  end
252
252
 
253
- describe 'with a Relationship subject and saved Resource value' do
253
+ describe 'with a saved Resource value' do
254
254
  before do
255
255
  @parent = @model.create(:title => 'Parent')
256
256
  @child = @parent.children.create(:title => 'Child')
@@ -1194,6 +1194,16 @@ describe DataMapper::Query::Conditions::GreaterThanComparison do
1194
1194
 
1195
1195
  it { should be(false) }
1196
1196
  end
1197
+
1198
+ describe 'with an expected value of nil' do
1199
+ subject { @comparison.matches?(@model.new(@property => 2)) }
1200
+
1201
+ before do
1202
+ @comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
1203
+ end
1204
+
1205
+ it { should be(false) }
1206
+ end
1197
1207
  end
1198
1208
  end
1199
1209
 
@@ -1276,6 +1286,16 @@ describe DataMapper::Query::Conditions::LessThanComparison do
1276
1286
 
1277
1287
  it { should be(false) }
1278
1288
  end
1289
+
1290
+ describe 'with an expected value of nil' do
1291
+ subject { @comparison.matches?(@model.new(@property => 0)) }
1292
+
1293
+ before do
1294
+ @comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
1295
+ end
1296
+
1297
+ it { should be(false) }
1298
+ end
1279
1299
  end
1280
1300
  end
1281
1301
 
@@ -1358,6 +1378,16 @@ describe DataMapper::Query::Conditions::GreaterThanOrEqualToComparison do
1358
1378
 
1359
1379
  it { should be(false) }
1360
1380
  end
1381
+
1382
+ describe 'with an expected value of nil' do
1383
+ subject { @comparison.matches?(@model.new(@property => 1)) }
1384
+
1385
+ before do
1386
+ @comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
1387
+ end
1388
+
1389
+ it { should be(false) }
1390
+ end
1361
1391
  end
1362
1392
  end
1363
1393
 
@@ -1440,6 +1470,16 @@ describe DataMapper::Query::Conditions::LessThanOrEqualToComparison do
1440
1470
 
1441
1471
  it { should be(false) }
1442
1472
  end
1473
+
1474
+ describe 'with an expected value of nil' do
1475
+ subject { @comparison.matches?(@model.new(@property => 1)) }
1476
+
1477
+ before do
1478
+ @comparison = DataMapper::Query::Conditions::Comparison.new(@slug, @property, nil)
1479
+ end
1480
+
1481
+ it { should be(false) }
1482
+ end
1443
1483
  end
1444
1484
  end
1445
1485
 
@@ -3472,22 +3472,13 @@ describe DataMapper::Query do
3472
3472
  it { should_not be_unique }
3473
3473
  end
3474
3474
 
3475
- describe 'when 1..n links are provided, but unique is not specified' do
3476
- before :all do
3477
- @query.should_not be_unique
3478
- @query.update(:links => [ :referrals ])
3479
- end
3480
-
3481
- it { should be_unique }
3482
- end
3483
-
3484
- describe 'when 0..1 links are provided, but unique is not specified' do
3475
+ describe 'when links are provided, but unique is not specified' do
3485
3476
  before :all do
3486
3477
  @query.should_not be_unique
3487
3478
  @query.update(:links => [ :referrer ])
3488
3479
  end
3489
3480
 
3490
- it { should_not be_unique }
3481
+ it { should be_unique }
3491
3482
  end
3492
3483
 
3493
3484
  describe 'when links are provided, but unique is false' do
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- describe DataMapper::Resource::State::Clean do
2
+ describe DataMapper::Resource::PersistenceState::Clean do
3
3
  before :all do
4
4
  class ::Author
5
5
  include DataMapper::Resource
@@ -20,8 +20,8 @@ describe DataMapper::Resource::State::Clean do
20
20
  before do
21
21
  @resource = @model.create(:name => 'Dan Kubb')
22
22
 
23
- @state = @resource.persisted_state
24
- @state.should be_kind_of(DataMapper::Resource::State::Clean)
23
+ @state = @resource.persistence_state
24
+ @state.should be_kind_of(DataMapper::Resource::PersistenceState::Clean)
25
25
  end
26
26
 
27
27
  after do
@@ -45,13 +45,13 @@ describe DataMapper::Resource::State::Clean do
45
45
 
46
46
  supported_by :all do
47
47
  it 'should return a Deleted state' do
48
- should eql(DataMapper::Resource::State::Deleted.new(@resource))
48
+ should eql(DataMapper::Resource::PersistenceState::Deleted.new(@resource))
49
49
  end
50
50
  end
51
51
  end
52
52
 
53
53
  describe '#get' do
54
- it_should_behave_like 'Resource::State::Persisted#get'
54
+ it_should_behave_like 'Resource::PersistenceState::Persisted#get'
55
55
  end
56
56
 
57
57
  describe '#set' do
@@ -67,7 +67,7 @@ describe DataMapper::Resource::State::Clean do
67
67
  it_should_behave_like 'A method that delegates to the superclass #set'
68
68
 
69
69
  it 'should return a Dirty state' do
70
- should eql(DataMapper::Resource::State::Dirty.new(@resource))
70
+ should eql(DataMapper::Resource::PersistenceState::Dirty.new(@resource))
71
71
  end
72
72
  end
73
73
 
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- describe DataMapper::Resource::State::Deleted do
2
+ describe DataMapper::Resource::PersistenceState::Deleted do
3
3
  before :all do
4
4
  class ::Author
5
5
  include DataMapper::Resource
@@ -20,7 +20,7 @@ describe DataMapper::Resource::State::Deleted do
20
20
  before do
21
21
  @resource = @model.create(:name => 'Dan Kubb')
22
22
 
23
- @state = DataMapper::Resource::State::Deleted.new(@resource)
23
+ @state = DataMapper::Resource::PersistenceState::Deleted.new(@resource)
24
24
  end
25
25
 
26
26
  after do
@@ -32,7 +32,7 @@ describe DataMapper::Resource::State::Deleted do
32
32
 
33
33
  supported_by :all do
34
34
  it 'should return an Immutable state' do
35
- should eql(DataMapper::Resource::State::Immutable.new(@resource))
35
+ should eql(DataMapper::Resource::PersistenceState::Immutable.new(@resource))
36
36
  end
37
37
 
38
38
  it 'should delete the resource' do
@@ -58,7 +58,7 @@ describe DataMapper::Resource::State::Deleted do
58
58
  end
59
59
 
60
60
  describe '#get' do
61
- it_should_behave_like 'Resource::State::Persisted#get'
61
+ it_should_behave_like 'Resource::PersistenceState::Persisted#get'
62
62
  end
63
63
 
64
64
  describe '#set' do
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- describe DataMapper::Resource::State::Dirty do
2
+ describe DataMapper::Resource::PersistenceState::Dirty do
3
3
  before :all do
4
4
  class ::Author
5
5
  include DataMapper::Resource
@@ -24,8 +24,8 @@ describe DataMapper::Resource::State::Dirty do
24
24
  @resource = @model.create(:id => 2, :name => 'Dan Kubb', :parent => @parent)
25
25
  @resource.attributes = { :name => 'John Doe' }
26
26
 
27
- @state = @resource.persisted_state
28
- @state.should be_kind_of(DataMapper::Resource::State::Dirty)
27
+ @state = @resource.persistence_state
28
+ @state.should be_kind_of(DataMapper::Resource::PersistenceState::Dirty)
29
29
  end
30
30
 
31
31
  after do
@@ -44,7 +44,7 @@ describe DataMapper::Resource::State::Dirty do
44
44
  end
45
45
 
46
46
  it 'should return a Clean state' do
47
- should eql(DataMapper::Resource::State::Clean.new(@resource))
47
+ should eql(DataMapper::Resource::PersistenceState::Clean.new(@resource))
48
48
  end
49
49
 
50
50
  it 'should set the child key if the parent key changes' do
@@ -91,7 +91,7 @@ describe DataMapper::Resource::State::Dirty do
91
91
  it_should_behave_like 'It resets resource state'
92
92
 
93
93
  it 'should return a Deleted state' do
94
- should eql(DataMapper::Resource::State::Deleted.new(@resource))
94
+ should eql(DataMapper::Resource::PersistenceState::Deleted.new(@resource))
95
95
  end
96
96
  end
97
97
  end
@@ -101,7 +101,7 @@ describe DataMapper::Resource::State::Dirty do
101
101
  @loaded_value = 'John Doe'
102
102
  end
103
103
 
104
- it_should_behave_like 'Resource::State::Persisted#get'
104
+ it_should_behave_like 'Resource::PersistenceState::Persisted#get'
105
105
  end
106
106
 
107
107
  describe '#rollback' do
@@ -115,7 +115,7 @@ describe DataMapper::Resource::State::Dirty do
115
115
  it_should_behave_like 'It resets resource state'
116
116
 
117
117
  it 'should return a Clean state' do
118
- should eql(DataMapper::Resource::State::Clean.new(@resource))
118
+ should eql(DataMapper::Resource::PersistenceState::Clean.new(@resource))
119
119
  end
120
120
  end
121
121
  end
@@ -148,7 +148,7 @@ describe DataMapper::Resource::State::Dirty do
148
148
  it_should_behave_like 'A method that delegates to the superclass #set'
149
149
 
150
150
  it 'should return a Clean state' do
151
- should eql(DataMapper::Resource::State::Clean.new(@resource))
151
+ should eql(DataMapper::Resource::PersistenceState::Clean.new(@resource))
152
152
  end
153
153
  end
154
154
  end
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- describe DataMapper::Resource::State::Immutable do
2
+ describe DataMapper::Resource::PersistenceState::Immutable do
3
3
  before :all do
4
4
  class ::Author
5
5
  include DataMapper::Resource
@@ -20,12 +20,12 @@ describe DataMapper::Resource::State::Immutable do
20
20
  before do
21
21
  @parent = @model.create(:name => 'John Doe')
22
22
 
23
- @resource = @model.create(:name => 'Dan Kubb', :parent => @parent)
24
- attributes = DataMapper::Ext::Array.to_hash(@model.key.zip(@resource.key))
25
- @resource = @model.first(attributes.merge(:fields => [ :name, :parent_id ]))
23
+ @resource = @model.create(:name => 'Dan Kubb', :parent => @parent)
24
+ attributes = Hash[ @model.key.zip(@resource.key) ]
25
+ @resource = @model.first(attributes.merge(:fields => [ :name, :parent_id ]))
26
26
 
27
- @state = @resource.persisted_state
28
- @state.should be_kind_of(DataMapper::Resource::State::Immutable)
27
+ @state = @resource.persistence_state
28
+ @state.should be_kind_of(DataMapper::Resource::PersistenceState::Immutable)
29
29
  end
30
30
 
31
31
  after do
@@ -1,5 +1,5 @@
1
1
  require 'spec_helper'
2
- describe DataMapper::Resource::State::Transient do
2
+ describe DataMapper::Resource::PersistenceState::Transient do
3
3
  before :all do
4
4
  class ::Author
5
5
  include DataMapper::Resource
@@ -26,8 +26,8 @@ describe DataMapper::Resource::State::Transient do
26
26
  @parent = @model.create(:name => 'John Doe')
27
27
  @resource = @model.new(:name => 'Dan Kubb', :coding => false, :parent => @parent)
28
28
 
29
- @state = @resource.persisted_state
30
- @state.should be_kind_of(DataMapper::Resource::State::Transient)
29
+ @state = @resource.persistence_state
30
+ @state.should be_kind_of(DataMapper::Resource::PersistenceState::Transient)
31
31
  end
32
32
 
33
33
  after do
@@ -39,7 +39,7 @@ describe DataMapper::Resource::State::Transient do
39
39
 
40
40
  supported_by :all do
41
41
  it 'should return the expected Clean state' do
42
- should eql(DataMapper::Resource::State::Clean.new(@resource))
42
+ should eql(DataMapper::Resource::PersistenceState::Clean.new(@resource))
43
43
  end
44
44
 
45
45
  it 'should set the serial property' do
@@ -80,7 +80,7 @@ describe DataMapper::Resource::State::Transient do
80
80
  }
81
81
 
82
82
  expect do
83
- @resource.persisted_state = subject
83
+ @resource.persistence_state = subject
84
84
  end.should change { @resource.original_attributes.dup }.from(original_attributes).to({})
85
85
  end
86
86
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe DataMapper::Resource::State do
3
+ describe DataMapper::Resource::PersistenceState do
4
4
  before :all do
5
5
  class ::Author
6
6
  include DataMapper::Resource
@@ -20,13 +20,13 @@ describe DataMapper::Resource::State do
20
20
  before do
21
21
  @resource = @model.new(:name => 'Dan Kubb')
22
22
 
23
- @state = DataMapper::Resource::State.new(@resource)
23
+ @state = DataMapper::Resource::PersistenceState.new(@resource)
24
24
  end
25
25
 
26
26
  describe '.new' do
27
- subject { DataMapper::Resource::State.new(@resource) }
27
+ subject { DataMapper::Resource::PersistenceState.new(@resource) }
28
28
 
29
- it { should be_kind_of(DataMapper::Resource::State) }
29
+ it { should be_kind_of(DataMapper::Resource::PersistenceState) }
30
30
  end
31
31
 
32
32
  describe '#==' do
@@ -35,7 +35,7 @@ describe DataMapper::Resource::State do
35
35
  supported_by :all do
36
36
  describe 'with the same class and resource' do
37
37
  before do
38
- @other = DataMapper::Resource::State.new(@resource)
38
+ @other = DataMapper::Resource::PersistenceState.new(@resource)
39
39
  end
40
40
 
41
41
  it { should be(true) }
@@ -47,7 +47,7 @@ describe DataMapper::Resource::State do
47
47
 
48
48
  describe 'with the same class and different resource' do
49
49
  before do
50
- @other = DataMapper::Resource::State.new(@model.new)
50
+ @other = DataMapper::Resource::PersistenceState.new(@model.new)
51
51
  end
52
52
 
53
53
  it { should be(false) }
@@ -59,7 +59,7 @@ describe DataMapper::Resource::State do
59
59
 
60
60
  describe 'with a different class and the same resource' do
61
61
  before do
62
- @other = DataMapper::Resource::State::Clean.new(@resource)
62
+ @other = DataMapper::Resource::PersistenceState::Clean.new(@resource)
63
63
  end
64
64
 
65
65
  it 'should be true for a subclass' do
@@ -73,7 +73,7 @@ describe DataMapper::Resource::State do
73
73
 
74
74
  describe 'with a different class and different resource' do
75
75
  before do
76
- @other = DataMapper::Resource::State::Clean.new(@model.new)
76
+ @other = DataMapper::Resource::PersistenceState::Clean.new(@model.new)
77
77
  end
78
78
 
79
79
  it { should be(false) }
@@ -90,7 +90,7 @@ describe DataMapper::Resource::State do
90
90
  subject { @state.send(method) }
91
91
 
92
92
  it 'should raise an exception' do
93
- method(:subject).should raise_error(NotImplementedError, "DataMapper::Resource::State##{method} should be implemented")
93
+ method(:subject).should raise_error(NotImplementedError, "DataMapper::Resource::PersistenceState##{method} should be implemented")
94
94
  end
95
95
  end
96
96
  end
@@ -101,7 +101,7 @@ describe DataMapper::Resource::State do
101
101
  supported_by :all do
102
102
  describe 'with the same class and resource' do
103
103
  before do
104
- @other = DataMapper::Resource::State.new(@resource)
104
+ @other = DataMapper::Resource::PersistenceState.new(@resource)
105
105
  end
106
106
 
107
107
  it { should be(true) }
@@ -113,7 +113,7 @@ describe DataMapper::Resource::State do
113
113
 
114
114
  describe 'with the same class and different resource' do
115
115
  before do
116
- @other = DataMapper::Resource::State.new(@model.new)
116
+ @other = DataMapper::Resource::PersistenceState.new(@model.new)
117
117
  end
118
118
 
119
119
  it { should be(false) }
@@ -125,7 +125,7 @@ describe DataMapper::Resource::State do
125
125
 
126
126
  describe 'with a different class and the same resource' do
127
127
  before do
128
- @other = DataMapper::Resource::State::Clean.new(@resource)
128
+ @other = DataMapper::Resource::PersistenceState::Clean.new(@resource)
129
129
  end
130
130
 
131
131
  it { should be(false) }
@@ -137,7 +137,7 @@ describe DataMapper::Resource::State do
137
137
 
138
138
  describe 'with a different class and different resource' do
139
139
  before do
140
- @other = DataMapper::Resource::State::Clean.new(@model.new)
140
+ @other = DataMapper::Resource::PersistenceState::Clean.new(@model.new)
141
141
  end
142
142
 
143
143
  it { should be(false) }
@@ -202,7 +202,7 @@ describe DataMapper::Resource::State do
202
202
  end
203
203
 
204
204
  it 'should return a state object' do
205
- should be_kind_of(DataMapper::Resource::State)
205
+ should be_kind_of(DataMapper::Resource::PersistenceState)
206
206
  end
207
207
 
208
208
  it 'should change the object attributes' do
@@ -218,7 +218,7 @@ describe DataMapper::Resource::State do
218
218
  end
219
219
 
220
220
  it 'should return a state object' do
221
- should be_kind_of(DataMapper::Resource::State)
221
+ should be_kind_of(DataMapper::Resource::PersistenceState)
222
222
  end
223
223
 
224
224
  it 'should change the object relationship' do
@@ -160,10 +160,16 @@ share_examples_for 'A semipublic Resource' do
160
160
  property :name, String
161
161
  property :value, Integer
162
162
  end
163
- DataMapper.finalize
164
163
  end
165
164
 
166
165
  with_alternate_adapter do
166
+ before :all do
167
+ if @user_model.respond_to?(:auto_migrate!)
168
+ # force the user model to be available in the alternate repository
169
+ @user_model.auto_migrate!(@adapter.name)
170
+ end
171
+ end
172
+
167
173
  it 'should return the default repository when nothing is specified' do
168
174
  default_repository = DataMapper.repository(:default)
169
175
  @user_model.create(:name => 'carl').repository.should == default_repository
@@ -2,9 +2,9 @@ share_examples_for 'A method that delegates to the superclass #set' do
2
2
  it 'should delegate to the superclass' do
3
3
  # this is the only way I could think of to test if the
4
4
  # superclass method is being called
5
- DataMapper::Resource::State.class_eval { alias_method :original_set, :set; undef_method(:set) }
5
+ DataMapper::Resource::PersistenceState.class_eval { alias_method :original_set, :set; undef_method(:set) }
6
6
  method(:subject).should raise_error(NoMethodError)
7
- DataMapper::Resource::State.class_eval { alias_method :set, :original_set; undef_method(:original_set) }
7
+ DataMapper::Resource::PersistenceState.class_eval { alias_method :set, :original_set; undef_method(:original_set) }
8
8
  end
9
9
  end
10
10
 
@@ -12,9 +12,9 @@ share_examples_for 'A method that does not delegate to the superclass #set' do
12
12
  it 'should delegate to the superclass' do
13
13
  # this is the only way I could think of to test if the
14
14
  # superclass method is not being called
15
- DataMapper::Resource::State.class_eval { alias_method :original_set, :set; undef_method(:set) }
15
+ DataMapper::Resource::PersistenceState.class_eval { alias_method :original_set, :set; undef_method(:set) }
16
16
  method(:subject).should_not raise_error(NoMethodError)
17
- DataMapper::Resource::State.class_eval { alias_method :set, :original_set; undef_method(:original_set) }
17
+ DataMapper::Resource::PersistenceState.class_eval { alias_method :set, :original_set; undef_method(:original_set) }
18
18
  end
19
19
  end
20
20
 
@@ -36,7 +36,7 @@ share_examples_for 'It resets resource state' do
36
36
  end
37
37
  end
38
38
 
39
- share_examples_for 'Resource::State::Persisted#get' do
39
+ share_examples_for 'Resource::PersistenceState::Persisted#get' do
40
40
  subject { @state.get(@key) }
41
41
 
42
42
  supported_by :all do
@@ -49,9 +49,9 @@ share_examples_for 'Resource::State::Persisted#get' do
49
49
  @resource.should be_dirty
50
50
  @resource.save.should be(true)
51
51
 
52
- attributes = DataMapper::Ext::Array.to_hash(@model.key.zip(@resource.key))
53
- @resource = @model.first(attributes.merge(:fields => @model.key))
54
- @state = @state.class.new(@resource)
52
+ attributes = Hash[ @model.key.zip(@resource.key) ]
53
+ @resource = @model.first(attributes.merge(:fields => @model.key))
54
+ @state = @state.class.new(@resource)
55
55
 
56
56
  # make sure the subject is not loaded
57
57
  @key.should_not be_loaded(@resource)
@@ -7,20 +7,6 @@ describe DataMapper::Ext::Array do
7
7
  @array = [ [ :a, [ 1 ] ], [ :b, [ 2 ] ], [ :c, [ 3 ] ] ].freeze
8
8
  end
9
9
 
10
- describe '.to_hash' do
11
- before :all do
12
- @return = DataMapper::Ext::Array.to_hash(@array)
13
- end
14
-
15
- it 'should return a Hash' do
16
- @return.should be_kind_of(Hash)
17
- end
18
-
19
- it 'should return expected value' do
20
- @return.should == { :a => [ 1 ], :b => [ 2 ], :c => [ 3 ] }
21
- end
22
- end
23
-
24
10
  describe '.to_mash' do
25
11
  before :all do
26
12
  @return = DataMapper::Ext::Array.to_mash(@array)
@@ -60,3 +60,14 @@ describe 'DataMapper::Ext.blank?', String do
60
60
  DataMapper::Ext.blank?(' a ').should == false
61
61
  end
62
62
  end
63
+
64
+ describe 'DataMapper::Ext.blank?', 'object with #blank?' do
65
+ subject { DataMapper::Ext.blank?(object) }
66
+
67
+ let(:return_value) { mock('Return Value') }
68
+ let(:object) { mock('Object', :blank? => return_value) }
69
+
70
+ it 'returns the object#blank? result if supported' do
71
+ should equal(return_value)
72
+ end
73
+ end