dm-core 1.0.2 → 1.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +28 -94
- data/LICENSE +1 -1
- data/README.rdoc +44 -11
- data/Rakefile +1 -7
- data/VERSION +1 -1
- data/dm-core.gemspec +398 -299
- data/lib/dm-core.rb +23 -13
- data/lib/dm-core/adapters/abstract_adapter.rb +1 -1
- data/lib/dm-core/associations/many_to_many.rb +1 -3
- data/lib/dm-core/associations/many_to_one.rb +54 -36
- data/lib/dm-core/associations/one_to_many.rb +1 -2
- data/lib/dm-core/associations/relationship.rb +11 -2
- data/lib/dm-core/collection.rb +3 -7
- data/lib/dm-core/core_ext/symbol.rb +1 -1
- data/lib/dm-core/identity_map.rb +0 -5
- data/lib/dm-core/model.rb +11 -21
- data/lib/dm-core/model/property.rb +43 -58
- data/lib/dm-core/model/relationship.rb +49 -44
- data/lib/dm-core/property.rb +106 -130
- data/lib/dm-core/property/date_time.rb +1 -3
- data/lib/dm-core/property/decimal.rb +11 -7
- data/lib/dm-core/property/integer.rb +2 -2
- data/lib/dm-core/property/lookup.rb +3 -16
- data/lib/dm-core/property/numeric.rb +3 -3
- data/lib/dm-core/property/object.rb +2 -11
- data/lib/dm-core/property/string.rb +1 -1
- data/lib/dm-core/property_set.rb +34 -54
- data/lib/dm-core/query.rb +85 -56
- data/lib/dm-core/query/conditions/comparison.rb +3 -6
- data/lib/dm-core/query/direction.rb +0 -4
- data/lib/dm-core/query/path.rb +22 -6
- data/lib/dm-core/relationship_set.rb +74 -0
- data/lib/dm-core/resource.rb +21 -32
- data/lib/dm-core/resource/state.rb +3 -4
- data/lib/dm-core/spec/lib/spec_helper.rb +1 -4
- data/lib/dm-core/spec/setup.rb +12 -5
- data/lib/dm-core/spec/shared/public/property_spec.rb +35 -21
- data/lib/dm-core/spec/shared/resource_spec.rb +1 -1
- data/lib/dm-core/spec/shared/semipublic/property_spec.rb +9 -9
- data/lib/dm-core/spec/shared/semipublic/query/conditions/abstract_comparison_spec.rb +261 -0
- data/lib/dm-core/support/deprecate.rb +1 -1
- data/lib/dm-core/support/descendant_set.rb +12 -5
- data/lib/dm-core/support/ordered_set.rb +382 -0
- data/lib/dm-core/support/subject_set.rb +252 -0
- data/lib/dm-core/version.rb +1 -1
- data/spec/public/associations/many_to_many/read_multiple_join_spec.rb +1 -2
- data/spec/public/associations/many_to_many_spec.rb +11 -9
- data/spec/public/associations/many_to_one_spec.rb +1 -1
- data/spec/public/associations/many_to_one_with_boolean_cpk_spec.rb +1 -1
- data/spec/public/associations/many_to_one_with_custom_fk_spec.rb +2 -2
- data/spec/public/associations/one_to_many_spec.rb +6 -5
- data/spec/public/associations/one_to_one_spec.rb +1 -1
- data/spec/public/associations/one_to_one_with_boolean_cpk_spec.rb +1 -1
- data/spec/public/collection_spec.rb +7 -6
- data/spec/public/finalize_spec.rb +1 -1
- data/spec/public/model/hook_spec.rb +4 -3
- data/spec/public/model/property_spec.rb +9 -3
- data/spec/public/model/relationship_spec.rb +2 -4
- data/spec/public/model_spec.rb +1 -1
- data/spec/public/property/binary_spec.rb +1 -1
- data/spec/public/property/boolean_spec.rb +1 -1
- data/spec/public/property/class_spec.rb +1 -1
- data/spec/public/property/date_spec.rb +1 -1
- data/spec/public/property/date_time_spec.rb +1 -1
- data/spec/public/property/decimal_spec.rb +7 -6
- data/spec/public/property/discriminator_spec.rb +1 -1
- data/spec/public/property/float_spec.rb +1 -1
- data/spec/public/property/integer_spec.rb +1 -1
- data/spec/public/property/object_spec.rb +2 -2
- data/spec/public/property/serial_spec.rb +1 -1
- data/spec/public/property/string_spec.rb +1 -1
- data/spec/public/property/text_spec.rb +6 -3
- data/spec/public/property/time_spec.rb +1 -1
- data/spec/public/property_spec.rb +13 -11
- data/spec/public/resource_spec.rb +43 -1
- data/spec/public/sel_spec.rb +1 -1
- data/spec/public/setup_spec.rb +1 -1
- data/spec/public/shared/collection_shared_spec.rb +6 -1
- data/spec/semipublic/adapters/abstract_adapter_spec.rb +1 -1
- data/spec/semipublic/adapters/in_memory_adapter_spec.rb +1 -1
- data/spec/semipublic/associations/many_to_many_spec.rb +1 -1
- data/spec/semipublic/associations/many_to_one_spec.rb +1 -1
- data/spec/semipublic/associations/one_to_many_spec.rb +1 -1
- data/spec/semipublic/associations/one_to_one_spec.rb +1 -1
- data/spec/semipublic/associations/relationship_spec.rb +1 -1
- data/spec/semipublic/associations_spec.rb +1 -1
- data/spec/semipublic/collection_spec.rb +1 -1
- data/spec/semipublic/model_spec.rb +1 -1
- data/spec/semipublic/property/binary_spec.rb +1 -1
- data/spec/semipublic/property/boolean_spec.rb +1 -1
- data/spec/semipublic/property/class_spec.rb +1 -1
- data/spec/semipublic/property/date_spec.rb +1 -1
- data/spec/semipublic/property/date_time_spec.rb +1 -1
- data/spec/semipublic/property/decimal_spec.rb +6 -5
- data/spec/semipublic/property/discriminator_spec.rb +1 -1
- data/spec/semipublic/property/float_spec.rb +1 -1
- data/spec/semipublic/property/integer_spec.rb +1 -1
- data/spec/semipublic/property/lookup_spec.rb +8 -5
- data/spec/semipublic/property/serial_spec.rb +1 -1
- data/spec/semipublic/property/string_spec.rb +1 -1
- data/spec/semipublic/property/text_spec.rb +1 -1
- data/spec/semipublic/property/time_spec.rb +1 -1
- data/spec/semipublic/property_spec.rb +32 -7
- data/spec/semipublic/query/conditions/comparison_spec.rb +1 -264
- data/spec/semipublic/query/conditions/operation_spec.rb +1 -2
- data/spec/semipublic/query/path_spec.rb +27 -1
- data/spec/semipublic/query_spec.rb +87 -36
- data/spec/semipublic/resource/state/clean_spec.rb +1 -2
- data/spec/semipublic/resource/state/deleted_spec.rb +1 -2
- data/spec/semipublic/resource/state/dirty_spec.rb +1 -2
- data/spec/semipublic/resource/state/immutable_spec.rb +1 -2
- data/spec/semipublic/resource/state/transient_spec.rb +7 -2
- data/spec/semipublic/resource/state_spec.rb +1 -1
- data/spec/semipublic/resource_spec.rb +1 -1
- data/spec/unit/array_spec.rb +1 -0
- data/spec/unit/data_mapper/ordered_set/append_spec.rb +26 -0
- data/spec/unit/data_mapper/ordered_set/clear_spec.rb +24 -0
- data/spec/unit/data_mapper/ordered_set/delete_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/each_spec.rb +19 -0
- data/spec/unit/data_mapper/ordered_set/empty_spec.rb +20 -0
- data/spec/unit/data_mapper/ordered_set/entries_spec.rb +22 -0
- data/spec/unit/data_mapper/ordered_set/eql_spec.rb +51 -0
- data/spec/unit/data_mapper/ordered_set/equal_value_spec.rb +84 -0
- data/spec/unit/data_mapper/ordered_set/hash_spec.rb +12 -0
- data/spec/unit/data_mapper/ordered_set/include_spec.rb +23 -0
- data/spec/unit/data_mapper/ordered_set/index_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/initialize_spec.rb +32 -0
- data/spec/unit/data_mapper/ordered_set/merge_spec.rb +36 -0
- data/spec/unit/data_mapper/ordered_set/shared/append_spec.rb +24 -0
- data/spec/unit/data_mapper/ordered_set/shared/clear_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/delete_spec.rb +25 -0
- data/spec/unit/data_mapper/ordered_set/shared/each_spec.rb +17 -0
- data/spec/unit/data_mapper/ordered_set/shared/empty_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/entries_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/include_spec.rb +9 -0
- data/spec/unit/data_mapper/ordered_set/shared/index_spec.rb +13 -0
- data/spec/unit/data_mapper/ordered_set/shared/initialize_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/shared/merge_spec.rb +28 -0
- data/spec/unit/data_mapper/ordered_set/shared/size_spec.rb +13 -0
- data/spec/unit/data_mapper/ordered_set/shared/to_ary_spec.rb +11 -0
- data/spec/unit/data_mapper/ordered_set/size_spec.rb +27 -0
- data/spec/unit/data_mapper/ordered_set/to_ary_spec.rb +23 -0
- data/spec/unit/data_mapper/subject_set/append_spec.rb +47 -0
- data/spec/unit/data_mapper/subject_set/clear_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/delete_spec.rb +40 -0
- data/spec/unit/data_mapper/subject_set/each_spec.rb +30 -0
- data/spec/unit/data_mapper/subject_set/empty_spec.rb +31 -0
- data/spec/unit/data_mapper/subject_set/entries_spec.rb +31 -0
- data/spec/unit/data_mapper/subject_set/get_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/include_spec.rb +32 -0
- data/spec/unit/data_mapper/subject_set/named_spec.rb +33 -0
- data/spec/unit/data_mapper/subject_set/shared/append_spec.rb +18 -0
- data/spec/unit/data_mapper/subject_set/shared/clear_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/delete_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/each_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/empty_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/entries_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/get_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/include_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/named_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/size_spec.rb +13 -0
- data/spec/unit/data_mapper/subject_set/shared/to_ary_spec.rb +9 -0
- data/spec/unit/data_mapper/subject_set/shared/values_at_spec.rb +44 -0
- data/spec/unit/data_mapper/subject_set/size_spec.rb +42 -0
- data/spec/unit/data_mapper/subject_set/to_ary_spec.rb +34 -0
- data/spec/unit/data_mapper/subject_set/values_at_spec.rb +57 -0
- data/spec/unit/hash_spec.rb +2 -1
- data/spec/unit/hook_spec.rb +1 -0
- data/spec/unit/lazy_array_spec.rb +2 -1
- data/spec/unit/module_spec.rb +2 -1
- data/spec/unit/object_spec.rb +1 -0
- data/spec/unit/try_dup_spec.rb +1 -0
- data/tasks/spec.rake +0 -3
- metadata +149 -52
- data/.gitignore +0 -37
- data/lib/dm-core/type.rb +0 -216
- data/lib/dm-core/types/boolean.rb +0 -9
- data/lib/dm-core/types/decimal.rb +0 -9
- data/lib/dm-core/types/discriminator.rb +0 -50
- data/lib/dm-core/types/object.rb +0 -25
- data/lib/dm-core/types/serial.rb +0 -11
- data/lib/dm-core/types/text.rb +0 -11
- data/tasks/local_gemfile.rake +0 -16
- data/tasks/metrics.rake +0 -37
@@ -100,11 +100,8 @@ module DataMapper
|
|
100
100
|
|
101
101
|
# A base class for the various comparison classes.
|
102
102
|
class AbstractComparison
|
103
|
-
extend Deprecate
|
104
103
|
extend Equalizer
|
105
104
|
|
106
|
-
deprecate :property, :subject
|
107
|
-
|
108
105
|
equalize :slug, :subject, :value
|
109
106
|
|
110
107
|
# @api semipublic
|
@@ -123,8 +120,8 @@ module DataMapper
|
|
123
120
|
# filtering collections, or the value in the repository when
|
124
121
|
# performing queries.
|
125
122
|
#
|
126
|
-
# In the case of
|
127
|
-
# the repository.
|
123
|
+
# In the case of primitive property, this is the value as it
|
124
|
+
# is stored in the repository.
|
128
125
|
#
|
129
126
|
# @return [Object]
|
130
127
|
#
|
@@ -136,7 +133,7 @@ module DataMapper
|
|
136
133
|
# The loaded/typecast value
|
137
134
|
#
|
138
135
|
# In the case of primitive types, this will be the same as +value+,
|
139
|
-
# however when using
|
136
|
+
# however when using primitive property this stores the loaded value.
|
140
137
|
#
|
141
138
|
# If writing an adapter, you should use +value+, while plugin authors
|
142
139
|
# should refer to +loaded_value+.
|
data/lib/dm-core/query/path.rb
CHANGED
@@ -10,7 +10,7 @@ module DataMapper
|
|
10
10
|
# TODO: replace this with BasicObject
|
11
11
|
instance_methods.each do |method|
|
12
12
|
next if method =~ /\A__/ ||
|
13
|
-
%w[ send class dup object_id kind_of? instance_of? respond_to? respond_to_missing? equal? freeze frozen? should should_not instance_variables instance_variable_set instance_variable_get instance_variable_defined? remove_instance_variable extend hash inspect copy_object initialize_dup ].include?(method.to_s)
|
13
|
+
%w[ send class dup object_id kind_of? instance_of? respond_to? respond_to_missing? equal? freeze frozen? should should_not instance_variables instance_variable_set instance_variable_get instance_variable_defined? remove_instance_variable extend hash inspect to_s copy_object initialize_dup ].include?(method.to_s)
|
14
14
|
undef_method method
|
15
15
|
end
|
16
16
|
|
@@ -33,10 +33,10 @@ module DataMapper
|
|
33
33
|
|
34
34
|
(Conditions::Comparison.slugs | [ :not ]).each do |slug|
|
35
35
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
36
|
-
def #{slug}
|
37
|
-
#{"
|
38
|
-
Operator.new(self, #{slug.inspect})
|
39
|
-
end
|
36
|
+
def #{slug} # def eql
|
37
|
+
#{"raise \"explicit use of '#{slug}' operator is deprecated (#{caller.first})\"" if slug == :eql || slug == :in} # raise "explicit use of 'eql' operator is deprecated (#{caller.first})"
|
38
|
+
Operator.new(self, #{slug.inspect}) # Operator.new(self, :eql)
|
39
|
+
end # end
|
40
40
|
RUBY
|
41
41
|
end
|
42
42
|
|
@@ -50,11 +50,27 @@ module DataMapper
|
|
50
50
|
super || (defined?(@property) ? @property.instance_of?(klass) : false)
|
51
51
|
end
|
52
52
|
|
53
|
+
# Used for creating :order options. This technique may be deprecated,
|
54
|
+
# so marking as semipublic until the issue is resolved.
|
55
|
+
#
|
56
|
+
# @api semipublic
|
57
|
+
def asc
|
58
|
+
Operator.new(property, :asc)
|
59
|
+
end
|
60
|
+
|
61
|
+
# Used for creating :order options. This technique may be deprecated,
|
62
|
+
# so marking as semipublic until the issue is resolved.
|
63
|
+
#
|
64
|
+
# @api semipublic
|
65
|
+
def desc
|
66
|
+
Operator.new(property, :desc)
|
67
|
+
end
|
68
|
+
|
53
69
|
# @api semipublic
|
54
70
|
def respond_to?(method, include_private = false)
|
55
71
|
super ||
|
56
72
|
(defined?(@property) && @property.respond_to?(method, include_private)) ||
|
57
|
-
@model.relationships(@repository_name).
|
73
|
+
@model.relationships(@repository_name).named?(method) ||
|
58
74
|
@model.properties(@repository_name).named?(method)
|
59
75
|
end
|
60
76
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'dm-core/support/subject_set'
|
2
|
+
|
3
|
+
module DataMapper
|
4
|
+
|
5
|
+
# A {SubjectSet} that keeps track of relationships defined in a {Model}
|
6
|
+
#
|
7
|
+
class RelationshipSet < SubjectSet
|
8
|
+
|
9
|
+
# A list of all relationships in this set
|
10
|
+
#
|
11
|
+
# @deprecated use DataMapper::RelationshipSet#each or DataMapper::RelationshipSet#to_a instead
|
12
|
+
#
|
13
|
+
# @return [Array]
|
14
|
+
# a list of all relationships in the set
|
15
|
+
#
|
16
|
+
# @api semipublic
|
17
|
+
def values
|
18
|
+
warn "#{self.class}#values is deprecated. Use #{self.class}#each or #{self.class}#to_a instead: #{caller.first}"
|
19
|
+
to_a
|
20
|
+
end
|
21
|
+
|
22
|
+
# A list of all relationships in this set
|
23
|
+
#
|
24
|
+
# @deprecated use DataMapper::RelationshipSet#each instead
|
25
|
+
#
|
26
|
+
# @yield [DataMapper::Associations::Relationship]
|
27
|
+
# all relationships in the set
|
28
|
+
#
|
29
|
+
# @yieldparam [DataMapper::Associations::Relationship] relationship
|
30
|
+
# a relationship in the set
|
31
|
+
#
|
32
|
+
# @return [RelationshipSet] self
|
33
|
+
#
|
34
|
+
# @api semipublic
|
35
|
+
def each_value
|
36
|
+
warn "#{self.class}#each_value is deprecated. Use #{self.class}#each instead: #{caller.first}"
|
37
|
+
each { |relationship| yield(relationship) }
|
38
|
+
self
|
39
|
+
end
|
40
|
+
|
41
|
+
# Check wether this RelationshipSet includes an entry with the given name
|
42
|
+
#
|
43
|
+
# @deprecated use DataMapper::RelationshipSet#named? instead
|
44
|
+
#
|
45
|
+
# @param [#to_s] name
|
46
|
+
# the name of the entry to look for
|
47
|
+
#
|
48
|
+
# @return [Boolean]
|
49
|
+
# true if the set contains a relationship with the given name
|
50
|
+
#
|
51
|
+
# @api semipublic
|
52
|
+
def key?(name)
|
53
|
+
warn "#{self.class}#key? is deprecated. Use #{self.class}#named? instead: #{caller.first}"
|
54
|
+
named?(name)
|
55
|
+
end
|
56
|
+
|
57
|
+
# Check wether this RelationshipSet includes an entry with the given name
|
58
|
+
#
|
59
|
+
# @deprecated use DataMapper::RelationshipSet#named? instead
|
60
|
+
#
|
61
|
+
# @param [#to_s] name
|
62
|
+
# the name of the entry to look for
|
63
|
+
#
|
64
|
+
# @return [Boolean]
|
65
|
+
# true if the set contains a relationship with the given name
|
66
|
+
#
|
67
|
+
# @api semipublic
|
68
|
+
def has_key?(name)
|
69
|
+
warn "#{self.class}#has_key? is deprecated. Use #{self.class}#named? instead: #{caller.first}"
|
70
|
+
named?(name)
|
71
|
+
end
|
72
|
+
|
73
|
+
end # class RelationshipSet
|
74
|
+
end # module DataMapper
|
data/lib/dm-core/resource.rb
CHANGED
@@ -5,26 +5,20 @@ module DataMapper
|
|
5
5
|
module Resource
|
6
6
|
include DataMapper::Assertions
|
7
7
|
extend Chainable
|
8
|
-
extend Deprecate
|
9
|
-
|
10
|
-
deprecate :new_record?, :new?
|
11
8
|
|
12
9
|
# @deprecated
|
13
10
|
def self.append_inclusions(*inclusions)
|
14
|
-
|
15
|
-
Model.append_inclusions(*inclusions)
|
11
|
+
raise "DataMapper::Resource.append_inclusions is deprecated, use DataMapper::Model.append_inclusions instead (#{caller.first})"
|
16
12
|
end
|
17
13
|
|
18
14
|
# @deprecated
|
19
15
|
def self.extra_inclusions
|
20
|
-
|
21
|
-
Model.extra_inclusions
|
16
|
+
raise "DataMapper::Resource.extra_inclusions is deprecated, use DataMapper::Model.extra_inclusions instead (#{caller.first})"
|
22
17
|
end
|
23
18
|
|
24
19
|
# @deprecated
|
25
20
|
def self.descendants
|
26
|
-
|
27
|
-
Model.descendants
|
21
|
+
raise "DataMapper::Resource.descendants is deprecated, use DataMapper::Model.descendants instead (#{caller.first})"
|
28
22
|
end
|
29
23
|
|
30
24
|
# Return if Resource#save should raise an exception on save failures (per-resource)
|
@@ -64,23 +58,18 @@ module DataMapper
|
|
64
58
|
#
|
65
59
|
# @deprecated
|
66
60
|
def update_attributes(attributes = {}, *allowed)
|
67
|
-
model
|
68
|
-
call_stack = caller[0]
|
69
|
-
|
70
|
-
warn "#{model}#update_attributes is deprecated, use #{model}#update instead (#{call_stack})"
|
71
|
-
|
72
|
-
if allowed.any?
|
73
|
-
warn "specifying allowed in #{model}#update_attributes is deprecated, " \
|
74
|
-
"use Hash#only to filter the attributes in the caller (#{call_stack})"
|
75
|
-
attributes = attributes.only(*allowed)
|
76
|
-
end
|
77
|
-
|
78
|
-
assert_update_clean_only(:update_attributes)
|
79
|
-
update(attributes)
|
61
|
+
raise "#{model}#update_attributes is deprecated, use #{model}#update instead (#{caller.first})"
|
80
62
|
end
|
81
63
|
|
82
64
|
# Makes sure a class gets all the methods when it includes Resource
|
83
65
|
#
|
66
|
+
# Note that including this module into an anonymous class will leave
|
67
|
+
# the model descendant tracking mechanism with no possibility to reliably
|
68
|
+
# track the anonymous model across code reloads. This means that
|
69
|
+
# {DataMapper::DescendantSet} will currently leak memory in scenarios where
|
70
|
+
# anonymous models are reloaded multiple times (as is the case in dm-rails
|
71
|
+
# development mode for example).
|
72
|
+
#
|
84
73
|
# @api private
|
85
74
|
def self.included(model)
|
86
75
|
model.extend Model
|
@@ -358,7 +347,7 @@ module DataMapper
|
|
358
347
|
# original value, and then removing all the ivars for properties
|
359
348
|
# and relationships. On the next access of those ivars, the
|
360
349
|
# resource will eager load what it needs. While this is more of
|
361
|
-
# a lazy reload, it should result
|
350
|
+
# a lazy reload, it should result in more consistent behavior
|
362
351
|
# since no cached results will remain from the initial load.
|
363
352
|
#
|
364
353
|
# @return [Resource]
|
@@ -616,7 +605,7 @@ module DataMapper
|
|
616
605
|
dirty_attributes = {}
|
617
606
|
|
618
607
|
original_attributes.each_key do |property|
|
619
|
-
next unless property.respond_to?(:
|
608
|
+
next unless property.respond_to?(:dump)
|
620
609
|
dirty_attributes[property] = property.dump(property.get!(self))
|
621
610
|
end
|
622
611
|
|
@@ -632,7 +621,7 @@ module DataMapper
|
|
632
621
|
#
|
633
622
|
# @api private
|
634
623
|
def collection
|
635
|
-
return @_collection if
|
624
|
+
return @_collection if @_collection || new? || readonly?
|
636
625
|
collection_for_self
|
637
626
|
end
|
638
627
|
|
@@ -782,7 +771,7 @@ module DataMapper
|
|
782
771
|
|
783
772
|
# Gets this instance's Model's properties
|
784
773
|
#
|
785
|
-
# @return [
|
774
|
+
# @return [PropertySet]
|
786
775
|
# List of this Resource's Model's properties
|
787
776
|
#
|
788
777
|
# @api private
|
@@ -792,7 +781,7 @@ module DataMapper
|
|
792
781
|
|
793
782
|
# Gets this instance's Model's relationships
|
794
783
|
#
|
795
|
-
# @return [
|
784
|
+
# @return [RelationshipSet]
|
796
785
|
# List of this instance's Model's Relationships
|
797
786
|
#
|
798
787
|
# @api private
|
@@ -852,7 +841,7 @@ module DataMapper
|
|
852
841
|
def clear_subjects
|
853
842
|
model_properties = properties
|
854
843
|
|
855
|
-
(model_properties - model_properties.key | relationships
|
844
|
+
(model_properties - model_properties.key | relationships).each do |subject|
|
856
845
|
next unless subject.loaded?(self)
|
857
846
|
remove_instance_variable(subject.instance_variable_name)
|
858
847
|
end
|
@@ -914,7 +903,7 @@ module DataMapper
|
|
914
903
|
def parent_relationships
|
915
904
|
parent_relationships = []
|
916
905
|
|
917
|
-
relationships.
|
906
|
+
relationships.each do |relationship|
|
918
907
|
next unless relationship.respond_to?(:resource_for)
|
919
908
|
set_default_value(relationship)
|
920
909
|
next unless relationship.loaded?(self) && relationship.get!(self)
|
@@ -934,7 +923,7 @@ module DataMapper
|
|
934
923
|
def child_relationships
|
935
924
|
child_relationships = []
|
936
925
|
|
937
|
-
relationships.
|
926
|
+
relationships.each do |relationship|
|
938
927
|
next unless relationship.respond_to?(:collection_for)
|
939
928
|
set_default_value(relationship)
|
940
929
|
next unless relationship.loaded?(self)
|
@@ -1046,7 +1035,7 @@ module DataMapper
|
|
1046
1035
|
def save_parents(execute_hooks)
|
1047
1036
|
run_once(true) do
|
1048
1037
|
parent_relationships.map do |relationship|
|
1049
|
-
parent = relationship.get
|
1038
|
+
parent = relationship.get(self)
|
1050
1039
|
|
1051
1040
|
if parent.__send__(:save_parents, execute_hooks) && parent.__send__(:save_self, execute_hooks)
|
1052
1041
|
relationship.set(self, parent) # set the FK values
|
@@ -1070,7 +1059,7 @@ module DataMapper
|
|
1070
1059
|
# Checks if the resource has unsaved changes
|
1071
1060
|
#
|
1072
1061
|
# @return [Boolean]
|
1073
|
-
# true if the resource has
|
1062
|
+
# true if the resource has unsaved changes
|
1074
1063
|
#
|
1075
1064
|
# @api semipublic
|
1076
1065
|
def dirty_self?
|
@@ -11,6 +11,7 @@ module DataMapper
|
|
11
11
|
|
12
12
|
def initialize(resource)
|
13
13
|
@resource = resource
|
14
|
+
@model = resource.model
|
14
15
|
end
|
15
16
|
|
16
17
|
def get(subject, *args)
|
@@ -36,16 +37,14 @@ module DataMapper
|
|
36
37
|
|
37
38
|
private
|
38
39
|
|
39
|
-
|
40
|
-
@model ||= resource.model
|
41
|
-
end
|
40
|
+
attr_reader :model
|
42
41
|
|
43
42
|
def properties
|
44
43
|
@properties ||= model.properties(repository.name)
|
45
44
|
end
|
46
45
|
|
47
46
|
def relationships
|
48
|
-
@relationships ||= model.relationships(repository.name)
|
47
|
+
@relationships ||= model.relationships(repository.name)
|
49
48
|
end
|
50
49
|
|
51
50
|
def identity_map
|
@@ -29,12 +29,9 @@ module DataMapper
|
|
29
29
|
remove_ivars(model)
|
30
30
|
model.instance_methods(false).each { |method| model.send(:undef_method, method) }
|
31
31
|
|
32
|
-
DataMapper::Model.descendants.delete(model)
|
33
32
|
end
|
34
33
|
|
35
|
-
|
36
|
-
raise 'DataMapper::Model.descendants is not empty'
|
37
|
-
end
|
34
|
+
DataMapper::Model.descendants.clear
|
38
35
|
end
|
39
36
|
|
40
37
|
def self.remove_ivars(object, instance_variables = object.instance_variables)
|
data/lib/dm-core/spec/setup.rb
CHANGED
@@ -52,8 +52,11 @@ module DataMapper
|
|
52
52
|
|
53
53
|
def require_plugins
|
54
54
|
plugins = ENV['PLUGINS'] || ENV['PLUGIN']
|
55
|
-
plugins = plugins.to_s.split(/[,\s]+/)
|
56
|
-
|
55
|
+
plugins = plugins.to_s.split(/[,\s]+/)
|
56
|
+
unless ENV['ADAPTER'] == 'in_memory'
|
57
|
+
plugins.push('dm-migrations')
|
58
|
+
end
|
59
|
+
plugins.uniq.each { |plugin| require plugin }
|
57
60
|
end
|
58
61
|
|
59
62
|
def spec_adapters
|
@@ -111,7 +114,7 @@ module DataMapper
|
|
111
114
|
end
|
112
115
|
|
113
116
|
def connection_uri
|
114
|
-
"#{adapter_name}://#{username}:#{password}
|
117
|
+
"#{adapter_name}://#{username}:#{password}@#{host}/#{storage_name}"
|
115
118
|
end
|
116
119
|
|
117
120
|
def storage_name
|
@@ -127,11 +130,15 @@ module DataMapper
|
|
127
130
|
end
|
128
131
|
|
129
132
|
def username
|
130
|
-
'datamapper'
|
133
|
+
ENV.fetch('DM_DB_USER', 'datamapper')
|
131
134
|
end
|
132
135
|
|
133
136
|
def password
|
134
|
-
'datamapper'
|
137
|
+
ENV.fetch('DM_DB_PASSWORD', 'datamapper')
|
138
|
+
end
|
139
|
+
|
140
|
+
def host
|
141
|
+
ENV.fetch('DM_DB_HOST', 'localhost')
|
135
142
|
end
|
136
143
|
|
137
144
|
# Test the connection
|
@@ -11,7 +11,8 @@ share_examples_for 'A public Property' do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
@model
|
14
|
+
@model = Blog::Article
|
15
|
+
@options ||= {}
|
15
16
|
end
|
16
17
|
|
17
18
|
describe "with a sub-type" do
|
@@ -21,7 +22,32 @@ share_examples_for 'A public Property' do
|
|
21
22
|
@type.accept_options :foo, :bar
|
22
23
|
end
|
23
24
|
|
25
|
+
describe "predefined options" do
|
26
|
+
before :all do
|
27
|
+
class ::ChildSubType < @subtype
|
28
|
+
default nil
|
29
|
+
end
|
30
|
+
@child_subtype = ChildSubType
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "when parent type overrides a default" do
|
34
|
+
before do
|
35
|
+
@subtype.default "foo"
|
36
|
+
end
|
37
|
+
|
38
|
+
after do
|
39
|
+
DataMapper::Property.descendants.delete(ChildSubType)
|
40
|
+
Object.send(:remove_const, :ChildSubType)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should not override the child's type setting" do
|
44
|
+
@child_subtype.default.should eql(nil)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
24
49
|
after :all do
|
50
|
+
DataMapper::Property.descendants.delete(SubType)
|
25
51
|
Object.send(:remove_const, :SubType)
|
26
52
|
end
|
27
53
|
|
@@ -45,7 +71,7 @@ share_examples_for 'A public Property' do
|
|
45
71
|
before :all do
|
46
72
|
@type.foo true
|
47
73
|
@type.bar 1
|
48
|
-
@property = @type.new(@model, @name)
|
74
|
+
@property = @type.new(@model, @name, @options)
|
49
75
|
end
|
50
76
|
|
51
77
|
it "should set the pre-defined option values" do
|
@@ -86,7 +112,7 @@ share_examples_for 'A public Property' do
|
|
86
112
|
[true, false].each do |value|
|
87
113
|
describe "when created with :#{opt} => #{value}" do
|
88
114
|
before :all do
|
89
|
-
@property = @type.new(@model, @name, opt => value)
|
115
|
+
@property = @type.new(@model, @name, @options.merge(opt => value))
|
90
116
|
end
|
91
117
|
|
92
118
|
it "should return #{value}" do
|
@@ -98,7 +124,7 @@ share_examples_for 'A public Property' do
|
|
98
124
|
describe "when created with :#{opt} => true and :required => true" do
|
99
125
|
it "should fail with ArgumentError" do
|
100
126
|
lambda {
|
101
|
-
@property = @type.new(@model, @name, opt => true, :required => true)
|
127
|
+
@property = @type.new(@model, @name, @options.merge(opt => true, :required => true))
|
102
128
|
}.should raise_error(ArgumentError,
|
103
129
|
"options[:required] cannot be mixed with :allow_nil or :allow_blank")
|
104
130
|
end
|
@@ -112,7 +138,7 @@ share_examples_for 'A public Property' do
|
|
112
138
|
describe "when created with :#{method} => #{value}" do
|
113
139
|
before :all do
|
114
140
|
opt = method.to_s.chomp('?').to_sym
|
115
|
-
@property = @type.new(@model, @name, opt => value)
|
141
|
+
@property = @type.new(@model, @name, @options.merge(opt => value))
|
116
142
|
end
|
117
143
|
|
118
144
|
it "should return #{value}" do
|
@@ -126,7 +152,7 @@ share_examples_for 'A public Property' do
|
|
126
152
|
describe "#lazy?" do
|
127
153
|
describe "when created with :lazy => true, :key => false" do
|
128
154
|
before :all do
|
129
|
-
@property = @type.new(@model, @name, :lazy => true, :key => false)
|
155
|
+
@property = @type.new(@model, @name, @options.merge(:lazy => true, :key => false))
|
130
156
|
end
|
131
157
|
|
132
158
|
it "should return true" do
|
@@ -136,7 +162,7 @@ share_examples_for 'A public Property' do
|
|
136
162
|
|
137
163
|
describe "when created with :lazy => true, :key => true" do
|
138
164
|
before :all do
|
139
|
-
@property = @type.new(@model, @name, :lazy => true, :key => true)
|
165
|
+
@property = @type.new(@model, @name, @options.merge(:lazy => true, :key => true))
|
140
166
|
end
|
141
167
|
|
142
168
|
it "should return false" do
|
@@ -145,22 +171,10 @@ share_examples_for 'A public Property' do
|
|
145
171
|
end
|
146
172
|
end
|
147
173
|
|
148
|
-
describe "#custom?" do
|
149
|
-
describe "when DM::Type is not provided" do
|
150
|
-
before :all do
|
151
|
-
@property = @type.new(@model, @name)
|
152
|
-
end
|
153
|
-
|
154
|
-
it "should be false" do
|
155
|
-
@property.custom?.should be(false)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
174
|
describe '#instance_of?' do
|
161
175
|
subject { property.instance_of?(klass) }
|
162
176
|
|
163
|
-
let(:property) { @type.new(@model, @name) }
|
177
|
+
let(:property) { @type.new(@model, @name, @options) }
|
164
178
|
|
165
179
|
context 'when provided the property class' do
|
166
180
|
let(:klass) { @type }
|
@@ -184,7 +198,7 @@ share_examples_for 'A public Property' do
|
|
184
198
|
describe '#kind_of?' do
|
185
199
|
subject { property.kind_of?(klass) }
|
186
200
|
|
187
|
-
let(:property) { @type.new(@model, @name) }
|
201
|
+
let(:property) { @type.new(@model, @name, @options) }
|
188
202
|
|
189
203
|
context 'when provided the property class' do
|
190
204
|
let(:klass) { @type }
|