dm-core 1.1.0 → 1.2.0.rc1

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 (104) hide show
  1. data/Gemfile +13 -11
  2. data/README.rdoc +1 -1
  3. data/Rakefile +1 -2
  4. data/VERSION +1 -1
  5. data/dm-core.gemspec +30 -176
  6. data/lib/dm-core.rb +32 -67
  7. data/lib/dm-core/adapters/abstract_adapter.rb +1 -2
  8. data/lib/dm-core/associations/many_to_many.rb +11 -5
  9. data/lib/dm-core/associations/many_to_one.rb +17 -2
  10. data/lib/dm-core/associations/one_to_many.rb +16 -0
  11. data/lib/dm-core/backwards.rb +13 -0
  12. data/lib/dm-core/collection.rb +1 -1
  13. data/lib/dm-core/model.rb +99 -41
  14. data/lib/dm-core/model/property.rb +24 -27
  15. data/lib/dm-core/model/relationship.rb +22 -28
  16. data/lib/dm-core/property.rb +37 -50
  17. data/lib/dm-core/property/boolean.rb +6 -10
  18. data/lib/dm-core/property/date.rb +0 -2
  19. data/lib/dm-core/property/date_time.rb +0 -2
  20. data/lib/dm-core/property/decimal.rb +5 -1
  21. data/lib/dm-core/property/discriminator.rb +24 -26
  22. data/lib/dm-core/property/float.rb +5 -1
  23. data/lib/dm-core/property/numeric.rb +6 -9
  24. data/lib/dm-core/property/string.rb +2 -1
  25. data/lib/dm-core/property/time.rb +0 -2
  26. data/lib/dm-core/property/typecast/time.rb +7 -2
  27. data/lib/dm-core/property_set.rb +1 -3
  28. data/lib/dm-core/query.rb +3 -10
  29. data/lib/dm-core/query/conditions/comparison.rb +5 -1
  30. data/lib/dm-core/query/conditions/operation.rb +1 -1
  31. data/lib/dm-core/relationship_set.rb +0 -2
  32. data/lib/dm-core/resource.rb +27 -28
  33. data/lib/dm-core/resource/{state.rb → persistence_state.rb} +2 -2
  34. data/lib/dm-core/resource/{state → persistence_state}/clean.rb +4 -4
  35. data/lib/dm-core/resource/{state → persistence_state}/deleted.rb +2 -2
  36. data/lib/dm-core/resource/{state → persistence_state}/dirty.rb +2 -2
  37. data/lib/dm-core/resource/{state → persistence_state}/immutable.rb +3 -3
  38. data/lib/dm-core/resource/{state → persistence_state}/persisted.rb +3 -3
  39. data/lib/dm-core/resource/{state → persistence_state}/transient.rb +3 -3
  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 +1 -1
  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/spec/public/associations/many_to_many_spec.rb +0 -1
  54. data/spec/public/model/property_spec.rb +55 -9
  55. data/spec/public/model/relationship_spec.rb +24 -2
  56. data/spec/public/model_spec.rb +32 -0
  57. data/spec/public/property/binary_spec.rb +14 -6
  58. data/spec/public/property/boolean_spec.rb +14 -6
  59. data/spec/public/property/class_spec.rb +14 -6
  60. data/spec/public/property/date_spec.rb +14 -6
  61. data/spec/public/property/date_time_spec.rb +14 -6
  62. data/spec/public/property/decimal_spec.rb +10 -2
  63. data/spec/public/property/discriminator_spec.rb +15 -1
  64. data/spec/public/property/float_spec.rb +14 -6
  65. data/spec/public/property/integer_spec.rb +14 -6
  66. data/spec/public/property/object_spec.rb +8 -0
  67. data/spec/public/property/serial_spec.rb +14 -6
  68. data/spec/public/property/string_spec.rb +14 -6
  69. data/spec/public/property/text_spec.rb +14 -6
  70. data/spec/public/property/time_spec.rb +14 -6
  71. data/spec/public/resource_spec.rb +58 -0
  72. data/spec/public/shared/finder_shared_spec.rb +8 -4
  73. data/spec/semipublic/associations/many_to_many_spec.rb +2 -0
  74. data/spec/semipublic/associations/many_to_one_spec.rb +2 -0
  75. data/spec/semipublic/associations/one_to_many_spec.rb +2 -0
  76. data/spec/semipublic/associations/one_to_one_spec.rb +2 -0
  77. data/spec/semipublic/property/binary_spec.rb +5 -5
  78. data/spec/semipublic/property/boolean_spec.rb +5 -5
  79. data/spec/semipublic/property/class_spec.rb +5 -5
  80. data/spec/semipublic/property/date_spec.rb +5 -5
  81. data/spec/semipublic/property/date_time_spec.rb +5 -5
  82. data/spec/semipublic/property/decimal_spec.rb +2 -2
  83. data/spec/semipublic/property/discriminator_spec.rb +5 -5
  84. data/spec/semipublic/property/float_spec.rb +5 -5
  85. data/spec/semipublic/property/integer_spec.rb +5 -5
  86. data/spec/semipublic/property/lookup_spec.rb +3 -3
  87. data/spec/semipublic/property/serial_spec.rb +5 -5
  88. data/spec/semipublic/property/string_spec.rb +5 -5
  89. data/spec/semipublic/property/text_spec.rb +5 -5
  90. data/spec/semipublic/property/time_spec.rb +5 -5
  91. data/spec/semipublic/query/conditions/comparison_spec.rb +44 -4
  92. data/spec/semipublic/query_spec.rb +2 -11
  93. data/spec/semipublic/resource/state/clean_spec.rb +6 -6
  94. data/spec/semipublic/resource/state/deleted_spec.rb +4 -4
  95. data/spec/semipublic/resource/state/dirty_spec.rb +8 -8
  96. data/spec/semipublic/resource/state/immutable_spec.rb +6 -6
  97. data/spec/semipublic/resource/state/transient_spec.rb +5 -5
  98. data/spec/semipublic/resource/state_spec.rb +15 -15
  99. data/spec/semipublic/shared/resource_shared_spec.rb +7 -1
  100. data/spec/semipublic/shared/resource_state_shared_spec.rb +8 -8
  101. data/spec/unit/array_spec.rb +0 -14
  102. data/spec/unit/blank_spec.rb +11 -0
  103. metadata +70 -188
  104. data/lib/dm-core/support/inflector.rb +0 -3
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::Boolean do
4
4
  before :all do
5
- @name = :active
6
- @type = DataMapper::Property::Boolean
7
- @value = true
8
- @other_value = false
5
+ @name = :active
6
+ @type = described_class
7
+ @value = true
8
+ @other_value = false
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 '#load' do
15
15
  before :all do
@@ -8,14 +8,14 @@ describe DataMapper::Property::Class do
8
8
  class ::Foo; end
9
9
  class ::Bar; end
10
10
 
11
- @name = :type
12
- @type = DataMapper::Property::Class
13
- @value = Foo
14
- @other_value = Bar
11
+ @name = :type
12
+ @type = described_class
13
+ @value = Foo
14
+ @other_value = Bar
15
15
  @invalid_value = 1
16
16
  end
17
17
 
18
- it_should_behave_like "A semipublic Property"
18
+ it_should_behave_like 'A semipublic Property'
19
19
 
20
20
  describe '#typecast_to_primitive' do
21
21
  it 'returns same value if a class' do
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::Date do
4
4
  before :all do
5
- @name = :created_on
6
- @type = DataMapper::Property::Date
7
- @value = Date.today
8
- @other_value = Date.today+1
5
+ @name = :created_on
6
+ @type = described_class
7
+ @value = Date.today
8
+ @other_value = Date.today + 1
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
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::DateTime do
4
4
  before :all do
5
- @name = :created_at
6
- @type = DataMapper::Property::DateTime
7
- @value = DateTime.now
8
- @other_value = DateTime.now+15
5
+ @name = :created_at
6
+ @type = described_class
7
+ @value = DateTime.now
8
+ @other_value = DateTime.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
@@ -3,14 +3,14 @@ require 'spec_helper'
3
3
  describe DataMapper::Property::Decimal do
4
4
  before :all do
5
5
  @name = :rate
6
- @type = DataMapper::Property::Decimal
6
+ @type = described_class
7
7
  @options = { :precision => 5, :scale => 2 }
8
8
  @value = BigDecimal('1.0')
9
9
  @other_value = BigDecimal('2.0')
10
10
  @invalid_value = true
11
11
  end
12
12
 
13
- it_should_behave_like "A semipublic Property"
13
+ it_should_behave_like 'A semipublic Property'
14
14
 
15
15
  describe '#typecast_to_primitive' do
16
16
  it 'returns same value if a decimal' do
@@ -8,12 +8,12 @@ describe DataMapper::Property::Discriminator do
8
8
  class ::Foo; end
9
9
  class ::Bar; end
10
10
 
11
- @name = :type
12
- @type = DataMapper::Property::Discriminator
13
- @value = Foo
14
- @other_value = Bar
11
+ @name = :type
12
+ @type = described_class
13
+ @value = Foo
14
+ @other_value = Bar
15
15
  @invalid_value = 1
16
16
  end
17
17
 
18
- it_should_behave_like "A semipublic Property"
18
+ it_should_behave_like 'A semipublic Property'
19
19
  end
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::Float do
4
4
  before :all do
5
- @name = :rating
6
- @type = DataMapper::Property::Float
7
- @value = 0.1
8
- @other_value = 0.2
5
+ @name = :rating
6
+ @type = described_class
7
+ @value = 0.1
8
+ @other_value = 0.2
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
  it 'returns same value if a float' do
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::Integer do
4
4
  before :all do
5
- @name = :age
6
- @type = DataMapper::Property::Integer
7
- @value = 1
8
- @other_value = 2
5
+ @name = :age
6
+ @type = described_class
7
+ @value = 1
8
+ @other_value = 2
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
  it 'returns same value if an integer' do
@@ -12,15 +12,15 @@ describe DataMapper::Property::Lookup do
12
12
  end
13
13
  end
14
14
 
15
- it "should provide access to Property classes" do
15
+ it 'should provide access to Property classes' do
16
16
  @klass::Serial.should == DataMapper::Property::Serial
17
17
  end
18
18
 
19
- it "should provide access to Property classes from outside of the Property namespace" do
19
+ it 'should provide access to Property classes from outside of the Property namespace' do
20
20
  @klass::OtherProperty.should be(Foo::OtherProperty)
21
21
  end
22
22
 
23
- it "should not provide access to unknown Property classes" do
23
+ it 'should not provide access to unknown Property classes' do
24
24
  lambda {
25
25
  @klass::Bla
26
26
  }.should raise_error(NameError)
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::Serial do
4
4
  before :all do
5
- @name = :id
6
- @type = DataMapper::Property::Serial
7
- @value = 1
8
- @other_value = 2
5
+ @name = :id
6
+ @type = described_class
7
+ @value = 1
8
+ @other_value = 2
9
9
  @invalid_value = 'foo'
10
10
  end
11
11
 
12
- it_should_behave_like "A semipublic Property"
12
+ it_should_behave_like 'A semipublic Property'
13
13
  end
@@ -2,12 +2,12 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::String do
4
4
  before :all do
5
- @name = :name
6
- @type = DataMapper::Property::String
7
- @value = 'value'
8
- @other_value = 'return value'
5
+ @name = :name
6
+ @type = described_class
7
+ @value = 'value'
8
+ @other_value = 'return value'
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
  end
@@ -2,14 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe DataMapper::Property::Text do
4
4
  before :all do
5
- @name = :title
6
- @type = DataMapper::Property::Text
7
- @value = 'value'
8
- @other_value = 'return value'
5
+ @name = :title
6
+ @type = described_class
7
+ @value = 'value'
8
+ @other_value = 'return value'
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 '#load' do
15
15
  before :all do
@@ -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