dm-core 0.10.2 → 1.0.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -1
- data/Gemfile +143 -0
- data/Rakefile +9 -5
- data/VERSION +1 -1
- data/dm-core.gemspec +160 -57
- data/lib/dm-core.rb +131 -56
- data/lib/dm-core/adapters.rb +98 -14
- data/lib/dm-core/adapters/abstract_adapter.rb +24 -4
- data/lib/dm-core/adapters/in_memory_adapter.rb +7 -2
- data/lib/dm-core/associations/many_to_many.rb +19 -30
- data/lib/dm-core/associations/many_to_one.rb +58 -42
- data/lib/dm-core/associations/one_to_many.rb +33 -23
- data/lib/dm-core/associations/one_to_one.rb +27 -11
- data/lib/dm-core/associations/relationship.rb +4 -4
- data/lib/dm-core/collection.rb +23 -16
- data/lib/dm-core/core_ext/array.rb +36 -0
- data/lib/dm-core/core_ext/hash.rb +30 -0
- data/lib/dm-core/core_ext/module.rb +46 -0
- data/lib/dm-core/core_ext/object.rb +31 -0
- data/lib/dm-core/core_ext/pathname.rb +20 -0
- data/lib/dm-core/core_ext/string.rb +22 -0
- data/lib/dm-core/core_ext/try_dup.rb +44 -0
- data/lib/dm-core/model.rb +88 -27
- data/lib/dm-core/model/hook.rb +75 -18
- data/lib/dm-core/model/property.rb +50 -9
- data/lib/dm-core/model/relationship.rb +31 -31
- data/lib/dm-core/model/scope.rb +3 -3
- data/lib/dm-core/property.rb +196 -516
- data/lib/dm-core/property/binary.rb +7 -0
- data/lib/dm-core/property/boolean.rb +35 -0
- data/lib/dm-core/property/class.rb +24 -0
- data/lib/dm-core/property/date.rb +47 -0
- data/lib/dm-core/property/date_time.rb +48 -0
- data/lib/dm-core/property/decimal.rb +43 -0
- data/lib/dm-core/property/discriminator.rb +48 -0
- data/lib/dm-core/property/float.rb +24 -0
- data/lib/dm-core/property/integer.rb +32 -0
- data/lib/dm-core/property/numeric.rb +43 -0
- data/lib/dm-core/property/object.rb +32 -0
- data/lib/dm-core/property/serial.rb +8 -0
- data/lib/dm-core/property/string.rb +49 -0
- data/lib/dm-core/property/text.rb +12 -0
- data/lib/dm-core/property/time.rb +48 -0
- data/lib/dm-core/property/typecast/numeric.rb +32 -0
- data/lib/dm-core/property/typecast/time.rb +28 -0
- data/lib/dm-core/property_set.rb +10 -4
- data/lib/dm-core/query.rb +14 -37
- data/lib/dm-core/query/conditions/comparison.rb +8 -6
- data/lib/dm-core/query/conditions/operation.rb +33 -2
- data/lib/dm-core/query/operator.rb +2 -5
- data/lib/dm-core/query/path.rb +4 -6
- data/lib/dm-core/repository.rb +21 -6
- data/lib/dm-core/resource.rb +316 -133
- data/lib/dm-core/resource/state.rb +79 -0
- data/lib/dm-core/resource/state/clean.rb +40 -0
- data/lib/dm-core/resource/state/deleted.rb +30 -0
- data/lib/dm-core/resource/state/dirty.rb +86 -0
- data/lib/dm-core/resource/state/immutable.rb +34 -0
- data/lib/dm-core/resource/state/persisted.rb +29 -0
- data/lib/dm-core/resource/state/transient.rb +70 -0
- data/lib/dm-core/spec/lib/adapter_helpers.rb +52 -0
- data/lib/dm-core/spec/lib/collection_helpers.rb +20 -0
- data/{spec → lib/dm-core/spec}/lib/counter_adapter.rb +5 -1
- data/lib/dm-core/spec/lib/pending_helpers.rb +50 -0
- data/lib/dm-core/spec/lib/spec_helper.rb +68 -0
- data/lib/dm-core/spec/setup.rb +165 -0
- data/lib/dm-core/spec/{adapter_shared_spec.rb → shared/adapter_spec.rb} +21 -7
- data/{spec/public/shared/resource_shared_spec.rb → lib/dm-core/spec/shared/resource_spec.rb} +120 -83
- data/{spec/public/shared/sel_shared_spec.rb → lib/dm-core/spec/shared/sel_spec.rb} +5 -6
- data/lib/dm-core/support/assertions.rb +8 -0
- data/lib/dm-core/support/equalizer.rb +1 -0
- data/lib/dm-core/support/hook.rb +420 -0
- data/lib/dm-core/support/lazy_array.rb +453 -0
- data/lib/dm-core/support/local_object_space.rb +12 -0
- data/lib/dm-core/support/logger.rb +193 -6
- data/lib/dm-core/support/naming_conventions.rb +8 -8
- data/lib/dm-core/support/subject.rb +33 -0
- data/lib/dm-core/type.rb +4 -0
- data/lib/dm-core/types/boolean.rb +2 -0
- data/lib/dm-core/types/decimal.rb +9 -0
- data/lib/dm-core/types/discriminator.rb +2 -0
- data/lib/dm-core/types/object.rb +3 -0
- data/lib/dm-core/types/serial.rb +2 -0
- data/lib/dm-core/types/text.rb +2 -0
- data/lib/dm-core/version.rb +1 -1
- data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +67 -0
- data/spec/public/model/hook_spec.rb +209 -0
- data/spec/public/model/property_spec.rb +35 -0
- data/spec/public/model/relationship_spec.rb +33 -20
- data/spec/public/model_spec.rb +142 -10
- data/spec/public/property/binary_spec.rb +14 -0
- data/spec/public/property/boolean_spec.rb +14 -0
- data/spec/public/property/class_spec.rb +20 -0
- data/spec/public/property/date_spec.rb +14 -0
- data/spec/public/property/date_time_spec.rb +14 -0
- data/spec/public/property/decimal_spec.rb +14 -0
- data/spec/public/{types → property}/discriminator_spec.rb +2 -12
- data/spec/public/property/float_spec.rb +14 -0
- data/spec/public/property/integer_spec.rb +14 -0
- data/spec/public/property/object_spec.rb +9 -17
- data/spec/public/property/serial_spec.rb +14 -0
- data/spec/public/property/string_spec.rb +14 -0
- data/spec/public/property/text_spec.rb +52 -0
- data/spec/public/property/time_spec.rb +14 -0
- data/spec/public/property_spec.rb +28 -87
- data/spec/public/resource_spec.rb +101 -0
- data/spec/public/sel_spec.rb +5 -15
- data/spec/public/shared/collection_shared_spec.rb +16 -30
- data/spec/public/shared/finder_shared_spec.rb +2 -4
- data/spec/public/shared/property_shared_spec.rb +176 -0
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +1 -1
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +2 -2
- data/spec/semipublic/associations/many_to_many_spec.rb +89 -0
- data/spec/semipublic/associations/many_to_one_spec.rb +24 -1
- data/spec/semipublic/associations/one_to_many_spec.rb +51 -0
- data/spec/semipublic/associations/one_to_one_spec.rb +49 -0
- data/spec/semipublic/associations/relationship_spec.rb +3 -3
- data/spec/semipublic/associations_spec.rb +1 -1
- data/spec/semipublic/property/binary_spec.rb +13 -0
- data/spec/semipublic/property/boolean_spec.rb +65 -0
- data/spec/semipublic/property/class_spec.rb +33 -0
- data/spec/semipublic/property/date_spec.rb +43 -0
- data/spec/semipublic/property/date_time_spec.rb +46 -0
- data/spec/semipublic/property/decimal_spec.rb +82 -0
- data/spec/semipublic/property/discriminator_spec.rb +19 -0
- data/spec/semipublic/property/float_spec.rb +82 -0
- data/spec/semipublic/property/integer_spec.rb +82 -0
- data/spec/semipublic/property/serial_spec.rb +13 -0
- data/spec/semipublic/property/string_spec.rb +13 -0
- data/spec/semipublic/property/text_spec.rb +31 -0
- data/spec/semipublic/property/time_spec.rb +50 -0
- data/spec/semipublic/property_spec.rb +2 -532
- data/spec/semipublic/query/conditions/comparison_spec.rb +171 -169
- data/spec/semipublic/query/conditions/operation_spec.rb +53 -51
- data/spec/semipublic/query/path_spec.rb +17 -17
- data/spec/semipublic/query_spec.rb +47 -78
- data/spec/semipublic/resource/state/clean_spec.rb +88 -0
- data/spec/semipublic/resource/state/deleted_spec.rb +78 -0
- data/spec/semipublic/resource/state/dirty_spec.rb +133 -0
- data/spec/semipublic/resource/state/immutable_spec.rb +99 -0
- data/spec/semipublic/resource/state/transient_spec.rb +128 -0
- data/spec/semipublic/resource/state_spec.rb +226 -0
- data/spec/semipublic/shared/property_shared_spec.rb +143 -0
- data/spec/semipublic/shared/resource_shared_spec.rb +16 -15
- data/spec/semipublic/shared/resource_state_shared_spec.rb +78 -0
- data/spec/semipublic/shared/subject_shared_spec.rb +79 -0
- data/spec/spec_helper.rb +21 -97
- data/spec/support/types/huge_integer.rb +17 -0
- data/spec/unit/array_spec.rb +48 -0
- data/spec/unit/hash_spec.rb +35 -0
- data/spec/unit/hook_spec.rb +1234 -0
- data/spec/unit/lazy_array_spec.rb +1959 -0
- data/spec/unit/module_spec.rb +70 -0
- data/spec/unit/object_spec.rb +37 -0
- data/spec/unit/try_dup_spec.rb +45 -0
- data/tasks/local_gemfile.rake +18 -0
- data/tasks/spec.rake +0 -3
- metadata +197 -71
- data/deps.rip +0 -2
- data/lib/dm-core/adapters/data_objects_adapter.rb +0 -712
- data/lib/dm-core/adapters/mysql_adapter.rb +0 -42
- data/lib/dm-core/adapters/oracle_adapter.rb +0 -229
- data/lib/dm-core/adapters/postgres_adapter.rb +0 -22
- data/lib/dm-core/adapters/sqlite3_adapter.rb +0 -17
- data/lib/dm-core/adapters/sqlserver_adapter.rb +0 -114
- data/lib/dm-core/adapters/yaml_adapter.rb +0 -111
- data/lib/dm-core/core_ext/enumerable.rb +0 -28
- data/lib/dm-core/migrations.rb +0 -1427
- data/lib/dm-core/spec/data_objects_adapter_shared_spec.rb +0 -366
- data/lib/dm-core/transaction.rb +0 -508
- data/lib/dm-core/types/paranoid_boolean.rb +0 -42
- data/lib/dm-core/types/paranoid_datetime.rb +0 -41
- data/spec/lib/adapter_helpers.rb +0 -105
- data/spec/lib/collection_helpers.rb +0 -18
- data/spec/lib/pending_helpers.rb +0 -46
- data/spec/public/migrations_spec.rb +0 -503
- data/spec/public/transaction_spec.rb +0 -153
- data/spec/semipublic/adapters/mysql_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/oracle_adapter_spec.rb +0 -194
- data/spec/semipublic/adapters/postgres_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/sqlite3_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/sqlserver_adapter_spec.rb +0 -17
- data/spec/semipublic/adapters/yaml_adapter_spec.rb +0 -12
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Binary do
|
4
|
+
before :all do
|
5
|
+
@name = :title
|
6
|
+
@type = DataMapper::Property::Binary
|
7
|
+
@primitive = String
|
8
|
+
@value = 'value'
|
9
|
+
@other_value = 'return value'
|
10
|
+
@invalid_value = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Boolean do
|
4
|
+
before :all do
|
5
|
+
@name = :active
|
6
|
+
@type = DataMapper::Property::Boolean
|
7
|
+
@primitive = TrueClass
|
8
|
+
@value = true
|
9
|
+
@other_value = false
|
10
|
+
@invalid_value = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Class do
|
4
|
+
before :all do
|
5
|
+
Object.send(:remove_const, :Foo) if defined?(Foo)
|
6
|
+
Object.send(:remove_const, :Bar) if defined?(Bar)
|
7
|
+
|
8
|
+
class ::Foo; end
|
9
|
+
class ::Bar; end
|
10
|
+
|
11
|
+
@name = :type
|
12
|
+
@type = DataMapper::Property::Class
|
13
|
+
@primitive = Class
|
14
|
+
@value = Foo
|
15
|
+
@other_value = Bar
|
16
|
+
@invalid_value = 1
|
17
|
+
end
|
18
|
+
|
19
|
+
it_should_behave_like "A public Property"
|
20
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Date do
|
4
|
+
before :all do
|
5
|
+
@name = :created_on
|
6
|
+
@type = DataMapper::Property::Date
|
7
|
+
@primitive = Date
|
8
|
+
@value = Date.today
|
9
|
+
@other_value = Date.today+1
|
10
|
+
@invalid_value = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::DateTime do
|
4
|
+
before :all do
|
5
|
+
@name = :created_at
|
6
|
+
@type = DataMapper::Property::DateTime
|
7
|
+
@primitive = DateTime
|
8
|
+
@value = DateTime.now
|
9
|
+
@other_value = DateTime.now+15
|
10
|
+
@invalid_value = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Decimal do
|
4
|
+
before :all do
|
5
|
+
@name = :rate
|
6
|
+
@type = DataMapper::Property::Decimal
|
7
|
+
@primitive = BigDecimal
|
8
|
+
@value = BigDecimal('1.0')
|
9
|
+
@other_value = BigDecimal('2.0')
|
10
|
+
@invalid_value = true
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
2
|
|
3
|
-
describe DataMapper::
|
3
|
+
describe DataMapper::Property::Discriminator do
|
4
4
|
before :all do
|
5
5
|
module ::Blog
|
6
6
|
class Article
|
@@ -98,17 +98,7 @@ describe DataMapper::Types::Discriminator do
|
|
98
98
|
|
99
99
|
supported_by :all do
|
100
100
|
before :all do
|
101
|
-
@
|
102
|
-
end
|
103
|
-
|
104
|
-
before do
|
105
|
-
pending if @skip
|
106
|
-
end
|
107
|
-
|
108
|
-
before :all do
|
109
|
-
rescue_if 'TODO: fix YAML serialization/deserialization', @skip do
|
110
|
-
@announcement = @announcement_model.create(:title => 'Announcement')
|
111
|
-
end
|
101
|
+
@announcement = @announcement_model.create(:title => 'Announcement')
|
112
102
|
end
|
113
103
|
|
114
104
|
it 'should persist the type' do
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Float do
|
4
|
+
before :all do
|
5
|
+
@name = :rating
|
6
|
+
@type = DataMapper::Property::Float
|
7
|
+
@primitive = Float
|
8
|
+
@value = 0.1
|
9
|
+
@other_value = 0.2
|
10
|
+
@invalid_value = '1'
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Integer do
|
4
|
+
before :all do
|
5
|
+
@name = :age
|
6
|
+
@type = DataMapper::Property::Integer
|
7
|
+
@primitive = Integer
|
8
|
+
@value = 1
|
9
|
+
@other_value = 2
|
10
|
+
@invalid_value = '1'
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -32,19 +32,19 @@ describe DataMapper::Property, 'Object type' do
|
|
32
32
|
|
33
33
|
it { should respond_to(:value) }
|
34
34
|
|
35
|
-
describe '#
|
35
|
+
describe '#dump' do
|
36
36
|
describe 'with a value' do
|
37
37
|
before do
|
38
38
|
@value = { 'lang' => 'en_CA' }
|
39
39
|
end
|
40
40
|
|
41
|
-
subject { @property.
|
41
|
+
subject { @property.dump(@value) }
|
42
42
|
|
43
|
-
it { @property.
|
43
|
+
it { @property.load(subject).should == @value }
|
44
44
|
end
|
45
45
|
|
46
46
|
describe 'with nil' do
|
47
|
-
subject { @property.
|
47
|
+
subject { @property.dump(nil) }
|
48
48
|
|
49
49
|
it { should be_nil }
|
50
50
|
end
|
@@ -56,7 +56,7 @@ describe DataMapper::Property, 'Object type' do
|
|
56
56
|
describe 'with a valid primitive' do
|
57
57
|
subject { @property.valid?('lang' => 'en_CA') }
|
58
58
|
|
59
|
-
it { should
|
59
|
+
it { should be(true) }
|
60
60
|
end
|
61
61
|
|
62
62
|
describe 'with nil and property is not required' do
|
@@ -66,28 +66,24 @@ describe DataMapper::Property, 'Object type' do
|
|
66
66
|
|
67
67
|
subject { @property.valid?(nil) }
|
68
68
|
|
69
|
-
it { should
|
69
|
+
it { should be(true) }
|
70
70
|
end
|
71
71
|
|
72
72
|
describe 'with nil and property is required' do
|
73
73
|
subject { @property.valid?(nil) }
|
74
74
|
|
75
|
-
it { should
|
75
|
+
it { should be(false) }
|
76
76
|
end
|
77
77
|
|
78
78
|
describe 'with nil and property is required, but validity is negated' do
|
79
79
|
subject { @property.valid?(nil, true) }
|
80
80
|
|
81
|
-
it { should
|
81
|
+
it { should be(true) }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
85
|
describe 'persistable' do
|
86
86
|
supported_by :all do
|
87
|
-
before :all do
|
88
|
-
@do_adapter = defined?(DataMapper::Adapters::DataObjectsAdapter) && @adapter.kind_of?(DataMapper::Adapters::DataObjectsAdapter)
|
89
|
-
end
|
90
|
-
|
91
87
|
before :all do
|
92
88
|
@resource = @model.create(:title => 'Test', :meta => { 'lang' => 'en_CA' })
|
93
89
|
end
|
@@ -95,11 +91,7 @@ describe DataMapper::Property, 'Object type' do
|
|
95
91
|
subject { @resource.reload.meta }
|
96
92
|
|
97
93
|
it 'should load the correct value' do
|
98
|
-
|
99
|
-
pending_if 'Fix DO adapter to send String for Text primitive', !!(RUBY_PLATFORM =~ /java/) do
|
100
|
-
should == { 'lang' => 'en_CA' }
|
101
|
-
end
|
102
|
-
end
|
94
|
+
should == { 'lang' => 'en_CA' }
|
103
95
|
end
|
104
96
|
end
|
105
97
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Serial do
|
4
|
+
before :all do
|
5
|
+
@name = :id
|
6
|
+
@type = DataMapper::Property::Serial
|
7
|
+
@primitive = Integer
|
8
|
+
@value = 1
|
9
|
+
@other_value = 2
|
10
|
+
@invalid_value = 'foo'
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::String do
|
4
|
+
before :all do
|
5
|
+
@name = :name
|
6
|
+
@type = DataMapper::Property::String
|
7
|
+
@primitive = String
|
8
|
+
@value = 'value'
|
9
|
+
@other_value = 'return value'
|
10
|
+
@invalid_value = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Text do
|
4
|
+
before :all do
|
5
|
+
@name = :title
|
6
|
+
@type = DataMapper::Property::Text
|
7
|
+
@primitive = String
|
8
|
+
@value = 'value'
|
9
|
+
@other_value = 'return value'
|
10
|
+
@invalid_value = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
|
15
|
+
describe 'migration with an index' do
|
16
|
+
supported_by :all do
|
17
|
+
before do
|
18
|
+
@model = DataMapper::Model.new do
|
19
|
+
storage_names[:default] = 'anonymous'
|
20
|
+
|
21
|
+
property :id, DataMapper::Property::Serial
|
22
|
+
property :body, DataMapper::Property::Text, :index => true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should allow a migration' do
|
27
|
+
lambda {
|
28
|
+
@model.auto_migrate!
|
29
|
+
}.should_not raise_error(DataObjects::SyntaxError)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end if defined?(DataObjects::SyntaxError)
|
33
|
+
|
34
|
+
describe 'migration with a unique index' do
|
35
|
+
supported_by :all do
|
36
|
+
before do
|
37
|
+
@model = DataMapper::Model.new do
|
38
|
+
storage_names[:default] = 'anonymous'
|
39
|
+
|
40
|
+
property :id, DataMapper::Property::Serial
|
41
|
+
property :body, DataMapper::Property::Text, :unique_index => true
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should allow a migration' do
|
46
|
+
lambda {
|
47
|
+
@model.auto_migrate!
|
48
|
+
}.should_not raise_error(DataObjects::SyntaxError)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end if defined?(DataObjects::SyntaxError)
|
52
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../..', 'spec_helper'))
|
2
|
+
|
3
|
+
describe DataMapper::Property::Time do
|
4
|
+
before :all do
|
5
|
+
@name = :deleted_at
|
6
|
+
@type = DataMapper::Property::Time
|
7
|
+
@primitive = Time
|
8
|
+
@value = Time.now
|
9
|
+
@other_value = Time.now+15
|
10
|
+
@invalid_value = 1
|
11
|
+
end
|
12
|
+
|
13
|
+
it_should_behave_like "A public Property"
|
14
|
+
end
|
@@ -69,36 +69,6 @@ describe DataMapper::Property do
|
|
69
69
|
end
|
70
70
|
end
|
71
71
|
|
72
|
-
describe '#get' do
|
73
|
-
before :all do
|
74
|
-
@image = Image.create(:md5hash => '5268f0f3f452844c79843e820f998869',
|
75
|
-
:title => 'Rome at the sunset',
|
76
|
-
:description => 'Just wow')
|
77
|
-
|
78
|
-
@image.should be_saved
|
79
|
-
|
80
|
-
@image = Image.first(:fields => [ :md5hash, :title ], :md5hash => @image.md5hash)
|
81
|
-
end
|
82
|
-
|
83
|
-
it 'triggers loading for lazy loaded properties' do
|
84
|
-
Image.properties[:description].get(@image)
|
85
|
-
Image.properties[:description].loaded?(@image).should be(true)
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'assigns loaded value to @ivar' do
|
89
|
-
Image.properties[:description].get(@image)
|
90
|
-
@image.instance_variable_get(:@description).should == 'Just wow'
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'sets default value for new records with nil value' do
|
94
|
-
Image.properties[:format].get(@image).should == 'jpeg'
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'returns property value' do
|
98
|
-
Image.properties[:description].get(@image).should == 'Just wow'
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
72
|
describe '#get!' do
|
103
73
|
before :all do
|
104
74
|
@image = Image.new
|
@@ -116,7 +86,7 @@ describe DataMapper::Property do
|
|
116
86
|
|
117
87
|
describe '#index' do
|
118
88
|
it 'returns true when property has an index' do
|
119
|
-
Track.properties[:title].index.should
|
89
|
+
Track.properties[:title].index.should be(true)
|
120
90
|
end
|
121
91
|
|
122
92
|
it 'returns index name when property has a named index' do
|
@@ -155,27 +125,27 @@ describe DataMapper::Property do
|
|
155
125
|
describe '#key?' do
|
156
126
|
describe 'returns true when property is a ' do
|
157
127
|
it 'serial key' do
|
158
|
-
Track.properties[:id].key?.should
|
128
|
+
Track.properties[:id].key?.should be(true)
|
159
129
|
end
|
160
130
|
it 'natural key' do
|
161
|
-
Image.properties[:md5hash].key?.should
|
131
|
+
Image.properties[:md5hash].key?.should be(true)
|
162
132
|
end
|
163
133
|
end
|
164
134
|
|
165
135
|
it 'returns true when property is a part of composite key'
|
166
136
|
|
167
137
|
it 'returns false when property does not relate to a key' do
|
168
|
-
Track.properties[:title].key?.should
|
138
|
+
Track.properties[:title].key?.should be(false)
|
169
139
|
end
|
170
140
|
end
|
171
141
|
|
172
142
|
describe '#lazy?' do
|
173
143
|
it 'returns true when property is lazy loaded' do
|
174
|
-
Image.properties[:description].lazy?.should
|
144
|
+
Image.properties[:description].lazy?.should be(true)
|
175
145
|
end
|
176
146
|
|
177
147
|
it 'returns false when property is not lazy loaded' do
|
178
|
-
Track.properties[:artist].lazy?.should
|
148
|
+
Track.properties[:artist].lazy?.should be(false)
|
179
149
|
end
|
180
150
|
end
|
181
151
|
|
@@ -257,59 +227,21 @@ describe DataMapper::Property do
|
|
257
227
|
|
258
228
|
describe '#allow_nil?' do
|
259
229
|
it 'returns true when property can accept nil as its value' do
|
260
|
-
Track.properties[:artist].allow_nil?.should
|
230
|
+
Track.properties[:artist].allow_nil?.should be(true)
|
261
231
|
end
|
262
232
|
|
263
233
|
it 'returns false when property nil value is prohibited for this property' do
|
264
|
-
Image.properties[:title].allow_nil?.should
|
234
|
+
Image.properties[:title].allow_nil?.should be(false)
|
265
235
|
end
|
266
236
|
end
|
267
237
|
|
268
238
|
describe '#serial?' do
|
269
239
|
it 'returns true when property is serial (auto incrementing)' do
|
270
|
-
Track.properties[:id].serial?.should
|
240
|
+
Track.properties[:id].serial?.should be(true)
|
271
241
|
end
|
272
242
|
|
273
243
|
it 'returns false when property is NOT serial (auto incrementing)' do
|
274
|
-
Image.properties[:md5hash].serial?.should
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
# What's going on here:
|
279
|
-
#
|
280
|
-
# we first set original value and make an assertion on it
|
281
|
-
# then we try to set it again, which clears original value
|
282
|
-
# (since original value is set, property is no longer dirty)
|
283
|
-
describe '#set_original_value' do
|
284
|
-
before :all do
|
285
|
-
@image = Image.create(
|
286
|
-
:md5hash => '5268f0f3f452844c79843e820f998869',
|
287
|
-
:title => 'Rome at the sunset',
|
288
|
-
:description => 'Just wow'
|
289
|
-
)
|
290
|
-
|
291
|
-
@property = Image.properties[:title]
|
292
|
-
end
|
293
|
-
|
294
|
-
describe 'when value changes' do
|
295
|
-
before :all do
|
296
|
-
@property.set_original_value(@image, 'New title')
|
297
|
-
end
|
298
|
-
|
299
|
-
it 'sets original value of the property' do
|
300
|
-
@image.original_attributes[@property].should == 'Rome at the sunset'
|
301
|
-
end
|
302
|
-
end
|
303
|
-
|
304
|
-
describe 'when value stays the same' do
|
305
|
-
before :all do
|
306
|
-
@property.set_original_value(@image, 'Rome at the sunset')
|
307
|
-
end
|
308
|
-
|
309
|
-
it 'only sets original value when it has changed' do
|
310
|
-
@property.set_original_value(@image, 'Rome at the sunset')
|
311
|
-
@image.original_attributes.should_not have_key(@property)
|
312
|
-
end
|
244
|
+
Image.properties[:md5hash].serial?.should be(false)
|
313
245
|
end
|
314
246
|
end
|
315
247
|
|
@@ -334,11 +266,6 @@ describe DataMapper::Property do
|
|
334
266
|
@image.title.should == 'http://test.example/'
|
335
267
|
end
|
336
268
|
|
337
|
-
it 'stores original value' do
|
338
|
-
@property.set(@image, 'Updated value')
|
339
|
-
@image.original_attributes[@property].should == 'Rome at the sunset'
|
340
|
-
end
|
341
|
-
|
342
269
|
it 'sets new property value' do
|
343
270
|
@property.set(@image, 'Updated value')
|
344
271
|
@image.title.should == 'Updated value'
|
@@ -362,28 +289,42 @@ describe DataMapper::Property do
|
|
362
289
|
|
363
290
|
describe '#unique?' do
|
364
291
|
it 'is true for fields that explicitly given uniq index' do
|
365
|
-
Track.properties[:musicbrainz_hash].unique?.should
|
292
|
+
Track.properties[:musicbrainz_hash].unique?.should be(true)
|
366
293
|
end
|
367
294
|
|
368
295
|
it 'is true for serial fields' do
|
369
296
|
pending do
|
370
|
-
Track.properties[:title].unique?.should
|
297
|
+
Track.properties[:title].unique?.should be(true)
|
371
298
|
end
|
372
299
|
end
|
373
300
|
|
374
301
|
it 'is true for keys' do
|
375
|
-
Image.properties[:md5hash].unique?.should
|
302
|
+
Image.properties[:md5hash].unique?.should be(true)
|
376
303
|
end
|
377
304
|
end
|
378
305
|
|
379
306
|
describe '#unique_index' do
|
380
307
|
it 'returns true when property has unique index' do
|
381
|
-
Track.properties[:musicbrainz_hash].unique_index.should
|
308
|
+
Track.properties[:musicbrainz_hash].unique_index.should be(true)
|
382
309
|
end
|
383
310
|
|
384
311
|
it 'returns nil when property has no unique index' do
|
385
312
|
Image.properties[:title].unique_index.should be_nil
|
386
313
|
end
|
387
314
|
end
|
315
|
+
|
316
|
+
describe "exception on bad property names" do
|
317
|
+
it "is raised for 'model'" do
|
318
|
+
lambda {
|
319
|
+
Track.property :model, String
|
320
|
+
}.should raise_error(ArgumentError)
|
321
|
+
end
|
322
|
+
|
323
|
+
it "is raised for 'repository_name'" do
|
324
|
+
lambda {
|
325
|
+
Track.property :repository_name, String
|
326
|
+
}.should raise_error(ArgumentError)
|
327
|
+
end
|
328
|
+
end
|
388
329
|
end
|
389
330
|
end # DataMapper::Property
|