mongo_mapper-unstable 2010.3.8 → 2010.06.23

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 (143) hide show
  1. data/README.rdoc +4 -8
  2. data/bin/mmconsole +1 -1
  3. data/examples/keys.rb +37 -0
  4. data/examples/plugins.rb +41 -0
  5. data/examples/querying.rb +35 -0
  6. data/examples/scopes.rb +52 -0
  7. data/lib/mongo_mapper/connection.rb +83 -0
  8. data/lib/mongo_mapper/document.rb +11 -329
  9. data/lib/mongo_mapper/embedded_document.rb +9 -38
  10. data/lib/mongo_mapper/exceptions.rb +30 -0
  11. data/lib/mongo_mapper/extensions/array.rb +19 -0
  12. data/lib/mongo_mapper/extensions/binary.rb +22 -0
  13. data/lib/mongo_mapper/extensions/boolean.rb +44 -0
  14. data/lib/mongo_mapper/extensions/date.rb +25 -0
  15. data/lib/mongo_mapper/extensions/float.rb +14 -0
  16. data/lib/mongo_mapper/extensions/hash.rb +14 -0
  17. data/lib/mongo_mapper/extensions/integer.rb +19 -0
  18. data/lib/mongo_mapper/extensions/kernel.rb +9 -0
  19. data/lib/mongo_mapper/extensions/nil_class.rb +18 -0
  20. data/lib/mongo_mapper/extensions/object.rb +27 -0
  21. data/lib/mongo_mapper/extensions/object_id.rb +30 -0
  22. data/lib/mongo_mapper/extensions/set.rb +20 -0
  23. data/lib/mongo_mapper/extensions/string.rb +18 -0
  24. data/lib/mongo_mapper/extensions/time.rb +29 -0
  25. data/lib/mongo_mapper/plugins/accessible.rb +44 -0
  26. data/lib/mongo_mapper/plugins/associations/base.rb +7 -6
  27. data/lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb +5 -6
  28. data/lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb +5 -6
  29. data/lib/mongo_mapper/plugins/associations/collection.rb +1 -0
  30. data/lib/mongo_mapper/plugins/associations/embedded_collection.rb +2 -1
  31. data/lib/mongo_mapper/plugins/associations/in_array_proxy.rb +25 -39
  32. data/lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb +4 -4
  33. data/lib/mongo_mapper/plugins/associations/many_documents_proxy.rb +36 -46
  34. data/lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb +1 -0
  35. data/lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb +5 -4
  36. data/lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb +1 -0
  37. data/lib/mongo_mapper/plugins/associations/one_embedded_proxy.rb +40 -0
  38. data/lib/mongo_mapper/plugins/associations/one_proxy.rb +7 -7
  39. data/lib/mongo_mapper/plugins/associations/proxy.rb +16 -8
  40. data/lib/mongo_mapper/plugins/associations.rb +14 -22
  41. data/lib/mongo_mapper/plugins/caching.rb +21 -0
  42. data/lib/mongo_mapper/plugins/callbacks.rb +17 -5
  43. data/lib/mongo_mapper/plugins/clone.rb +10 -4
  44. data/lib/mongo_mapper/plugins/descendants.rb +3 -2
  45. data/lib/mongo_mapper/plugins/dirty.rb +1 -0
  46. data/lib/mongo_mapper/plugins/document.rb +41 -0
  47. data/lib/mongo_mapper/{support/find.rb → plugins/dynamic_querying/dynamic_finder.rb} +3 -36
  48. data/lib/mongo_mapper/plugins/dynamic_querying.rb +43 -0
  49. data/lib/mongo_mapper/plugins/embedded_document.rb +49 -0
  50. data/lib/mongo_mapper/plugins/equality.rb +4 -10
  51. data/lib/mongo_mapper/plugins/identity_map.rb +29 -23
  52. data/lib/mongo_mapper/plugins/indexes.rb +12 -0
  53. data/lib/mongo_mapper/plugins/inspect.rb +1 -0
  54. data/lib/mongo_mapper/plugins/keys/key.rb +55 -0
  55. data/lib/mongo_mapper/plugins/keys.rb +85 -110
  56. data/lib/mongo_mapper/plugins/logger.rb +1 -0
  57. data/lib/mongo_mapper/plugins/modifiers.rb +41 -16
  58. data/lib/mongo_mapper/plugins/pagination.rb +5 -15
  59. data/lib/mongo_mapper/plugins/persistence.rb +69 -0
  60. data/lib/mongo_mapper/plugins/protected.rb +9 -1
  61. data/lib/mongo_mapper/plugins/querying/decorator.rb +46 -0
  62. data/lib/mongo_mapper/plugins/querying/plucky_methods.rb +15 -0
  63. data/lib/mongo_mapper/plugins/querying.rb +176 -0
  64. data/lib/mongo_mapper/plugins/rails.rb +6 -1
  65. data/lib/mongo_mapper/plugins/safe.rb +28 -0
  66. data/lib/mongo_mapper/plugins/sci.rb +32 -0
  67. data/lib/mongo_mapper/plugins/scopes.rb +21 -0
  68. data/lib/mongo_mapper/plugins/serialization.rb +5 -4
  69. data/lib/mongo_mapper/plugins/timestamps.rb +2 -1
  70. data/lib/mongo_mapper/plugins/userstamps.rb +1 -0
  71. data/lib/mongo_mapper/plugins/validations.rb +9 -5
  72. data/lib/mongo_mapper/plugins.rb +1 -20
  73. data/lib/mongo_mapper/support/descendant_appends.rb +5 -6
  74. data/lib/mongo_mapper/version.rb +4 -0
  75. data/lib/mongo_mapper.rb +71 -128
  76. data/test/{NOTE_ON_TESTING → _NOTE_ON_TESTING} +0 -0
  77. data/test/functional/associations/test_belongs_to_polymorphic_proxy.rb +5 -5
  78. data/test/functional/associations/test_belongs_to_proxy.rb +13 -21
  79. data/test/functional/associations/test_in_array_proxy.rb +7 -9
  80. data/test/functional/associations/test_many_documents_as_proxy.rb +5 -5
  81. data/test/functional/associations/test_many_documents_proxy.rb +186 -64
  82. data/test/functional/associations/test_many_embedded_polymorphic_proxy.rb +22 -22
  83. data/test/functional/associations/test_many_embedded_proxy.rb +32 -32
  84. data/test/functional/associations/test_many_polymorphic_proxy.rb +47 -47
  85. data/test/functional/associations/test_one_embedded_proxy.rb +67 -0
  86. data/test/functional/associations/test_one_proxy.rb +70 -49
  87. data/test/functional/test_accessible.rb +168 -0
  88. data/test/functional/test_associations.rb +11 -11
  89. data/test/functional/test_binary.rb +5 -5
  90. data/test/functional/test_caching.rb +76 -0
  91. data/test/functional/test_callbacks.rb +104 -34
  92. data/test/functional/test_dirty.rb +16 -16
  93. data/test/functional/test_document.rb +12 -924
  94. data/test/functional/test_dynamic_querying.rb +75 -0
  95. data/test/functional/test_embedded_document.rb +88 -8
  96. data/test/functional/test_identity_map.rb +41 -43
  97. data/test/functional/{test_indexing.rb → test_indexes.rb} +3 -5
  98. data/test/functional/test_logger.rb +1 -1
  99. data/test/functional/test_modifiers.rb +275 -181
  100. data/test/functional/test_pagination.rb +13 -15
  101. data/test/functional/test_protected.rb +25 -11
  102. data/test/functional/test_querying.rb +873 -0
  103. data/test/functional/test_safe.rb +76 -0
  104. data/test/functional/test_sci.rb +230 -0
  105. data/test/functional/test_scopes.rb +171 -0
  106. data/test/functional/test_string_id_compatibility.rb +11 -11
  107. data/test/functional/test_timestamps.rb +0 -2
  108. data/test/functional/test_userstamps.rb +0 -1
  109. data/test/functional/test_validations.rb +44 -31
  110. data/test/models.rb +18 -17
  111. data/test/{active_model_lint_test.rb → test_active_model_lint.rb} +3 -1
  112. data/test/test_helper.rb +59 -16
  113. data/test/unit/associations/test_base.rb +47 -42
  114. data/test/unit/associations/test_proxy.rb +15 -15
  115. data/test/unit/serializers/test_json_serializer.rb +29 -29
  116. data/test/unit/test_clone.rb +69 -0
  117. data/test/unit/test_descendant_appends.rb +3 -3
  118. data/test/unit/test_document.rb +49 -67
  119. data/test/unit/test_dynamic_finder.rb +53 -51
  120. data/test/unit/test_embedded_document.rb +19 -38
  121. data/test/unit/{test_support.rb → test_extensions.rb} +136 -122
  122. data/test/unit/test_key.rb +185 -0
  123. data/test/unit/test_keys.rb +29 -147
  124. data/test/unit/test_mongo_mapper.rb +3 -48
  125. data/test/unit/test_pagination.rb +1 -150
  126. data/test/unit/test_rails.rb +77 -19
  127. data/test/unit/test_rails_compatibility.rb +12 -12
  128. data/test/unit/test_serialization.rb +5 -5
  129. data/test/unit/test_time_zones.rb +9 -9
  130. data/test/unit/test_validations.rb +46 -46
  131. metadata +157 -155
  132. data/.gitignore +0 -10
  133. data/Rakefile +0 -55
  134. data/VERSION +0 -1
  135. data/lib/mongo_mapper/plugins/pagination/proxy.rb +0 -72
  136. data/lib/mongo_mapper/query.rb +0 -130
  137. data/lib/mongo_mapper/support.rb +0 -215
  138. data/mongo_mapper.gemspec +0 -196
  139. data/performance/read_write.rb +0 -52
  140. data/specs.watchr +0 -51
  141. data/test/support/custom_matchers.rb +0 -55
  142. data/test/support/timing.rb +0 -16
  143. data/test/unit/test_query.rb +0 -340
@@ -1,130 +0,0 @@
1
- module MongoMapper
2
- # IMPORTANT
3
- # This class is private to MongoMapper and should not be considered part of MongoMapper's public API.
4
- #
5
- class Query
6
- OptionKeys = [:fields, :select, :skip, :offset, :limit, :sort, :order]
7
-
8
- attr_reader :model
9
-
10
- def initialize(model, options)
11
- raise ArgumentError, "Options must be a hash" unless options.is_a?(Hash)
12
- @model, @options, @conditions, @original_options = model, {}, {}, options
13
- separate_options_and_conditions
14
- add_sci_condition
15
- end
16
-
17
- def criteria
18
- to_criteria(@conditions)
19
- end
20
-
21
- def options
22
- fields = @options[:fields] || @options[:select]
23
- skip = @options[:skip] || @options[:offset] || 0
24
- limit = @options[:limit] || 0
25
- sort = @options[:sort] || normalized_sort(@options[:order])
26
-
27
- {:fields => to_fields(fields), :skip => skip.to_i, :limit => limit.to_i, :sort => sort}
28
- end
29
-
30
- def to_a
31
- [criteria, options]
32
- end
33
-
34
- private
35
- def separate_options_and_conditions
36
- @original_options.each_pair do |key, value|
37
- key = key.respond_to?(:to_sym) ? key.to_sym : key
38
-
39
- if OptionKeys.include?(key)
40
- @options[key] = value
41
- elsif key == :conditions
42
- @conditions.update(value)
43
- else
44
- @conditions[key] = value
45
- end
46
- end
47
- end
48
-
49
- # adds _type single collection inheritance scope for models that need it
50
- def add_sci_condition
51
- @conditions[:_type] = model.to_s if model.single_collection_inherited?
52
- end
53
-
54
- def modifier?(field)
55
- field.to_s =~ /^\$/
56
- end
57
-
58
- def symbol_operator?(object)
59
- object.respond_to?(:field, :operator)
60
- end
61
-
62
- def to_criteria(conditions, parent_key=nil)
63
- criteria = {}
64
-
65
- conditions.each_pair do |key, value|
66
- key = normalized_key(key)
67
-
68
- if model.object_id_key?(key) && value.is_a?(String)
69
- value = Mongo::ObjectID.from_string(value)
70
- end
71
-
72
- if symbol_operator?(key)
73
- value = {"$#{key.operator}" => value}
74
- key = normalized_key(key.field)
75
- end
76
-
77
- criteria[key] = normalized_value(key, value)
78
- end
79
-
80
- criteria
81
- end
82
-
83
- def to_fields(fields)
84
- return if fields.blank?
85
-
86
- if fields.respond_to?(:flatten, :compact)
87
- fields.flatten.compact
88
- else
89
- fields.split(',').map { |field| field.strip }
90
- end
91
- end
92
-
93
- def to_order(field, direction=nil)
94
- direction ||= 'ASC'
95
- direction = direction.upcase == 'ASC' ? 1 : -1
96
- [normalized_key(field).to_s, direction]
97
- end
98
-
99
- def normalized_key(field)
100
- field.to_s == 'id' ? :_id : field
101
- end
102
-
103
- def normalized_value(field, value)
104
- case value
105
- when Array
106
- modifier?(field) ? value : {'$in' => value}
107
- when Hash
108
- to_criteria(value, field)
109
- when Time
110
- value.utc
111
- else
112
- value
113
- end
114
- end
115
-
116
- def normalized_sort(sort)
117
- return if sort.blank?
118
-
119
- if sort.respond_to?(:all?) && sort.all? { |s| symbol_operator?(s) }
120
- sort.map { |s| to_order(s.field, s.operator) }
121
- elsif symbol_operator?(sort)
122
- [to_order(sort.field, sort.operator)]
123
- else
124
- sort.split(',').map do |str|
125
- to_order(*str.strip.split(' '))
126
- end
127
- end
128
- end
129
- end
130
- end
@@ -1,215 +0,0 @@
1
- class Array
2
- def self.to_mongo(value)
3
- value = value.respond_to?(:lines) ? value.lines : value
4
- value.to_a
5
- end
6
-
7
- def self.from_mongo(value)
8
- value || []
9
- end
10
- end
11
-
12
- class Binary
13
- def self.to_mongo(value)
14
- if value.is_a?(ByteBuffer)
15
- value
16
- else
17
- value.nil? ? nil : ByteBuffer.new(value)
18
- end
19
- end
20
-
21
- def self.from_mongo(value)
22
- value
23
- end
24
- end
25
-
26
- class Boolean
27
- BOOLEAN_MAPPING = {
28
- true => true, 'true' => true, 'TRUE' => true, 'True' => true, 't' => true, 'T' => true, '1' => true, 1 => true, 1.0 => true,
29
- false => false, 'false' => false, 'FALSE' => false, 'False' => false, 'f' => false, 'F' => false, '0' => false, 0 => false, 0.0 => false, nil => false
30
- }
31
-
32
- def self.to_mongo(value)
33
- if value.is_a?(Boolean)
34
- value
35
- else
36
- v = BOOLEAN_MAPPING[value]
37
- v = value.to_s.downcase == 'true' if v.nil? # Check all mixed case spellings for true
38
- v
39
- end
40
- end
41
-
42
- def self.from_mongo(value)
43
- !!value
44
- end
45
- end
46
-
47
- class Date
48
- def self.to_mongo(value)
49
- if value.nil? || value == ''
50
- nil
51
- else
52
- date = value.is_a?(Date) || value.is_a?(Time) ? value : Date.parse(value.to_s)
53
- Time.utc(date.year, date.month, date.day)
54
- end
55
- rescue
56
- nil
57
- end
58
-
59
- def self.from_mongo(value)
60
- value.to_date if value.present?
61
- end
62
- end
63
-
64
- class Float
65
- def self.to_mongo(value)
66
- value.to_f
67
- end
68
- end
69
-
70
- class Hash
71
- def self.from_mongo(value)
72
- HashWithIndifferentAccess.new(value || {})
73
- end
74
-
75
- def to_mongo
76
- self
77
- end
78
- end
79
-
80
- class Integer
81
- def self.to_mongo(value)
82
- value_to_i = value.to_i
83
- if value_to_i == 0 && value != value_to_i
84
- value.to_s =~ /^(0x|0b)?0+/ ? 0 : nil
85
- else
86
- value_to_i
87
- end
88
- end
89
- end
90
-
91
- class NilClass
92
- def to_mongo(value)
93
- value
94
- end
95
-
96
- def from_mongo(value)
97
- value
98
- end
99
- end
100
-
101
- class Object
102
- # The hidden singleton lurks behind everyone
103
- def metaclass
104
- class << self; self end
105
- end
106
-
107
- def meta_eval(&blk)
108
- metaclass.instance_eval(&blk)
109
- end
110
-
111
- # Adds methods to a metaclass
112
- def meta_def(name, &blk)
113
- meta_eval { define_method(name, &blk) }
114
- end
115
-
116
- # Defines an instance method within a class
117
- def class_def(name, &blk)
118
- class_eval { define_method(name, &blk) }
119
- end
120
-
121
- def self.to_mongo(value)
122
- value
123
- end
124
-
125
- def self.from_mongo(value)
126
- value
127
- end
128
- end
129
-
130
- class ObjectId
131
- def self.to_mongo(value)
132
- if value.blank?
133
- nil
134
- elsif value.is_a?(Mongo::ObjectID)
135
- value
136
- else
137
- Mongo::ObjectID.from_string(value.to_s)
138
- end
139
- end
140
-
141
- def self.from_mongo(value)
142
- value
143
- end
144
- end
145
-
146
- class Set
147
- def self.to_mongo(value)
148
- value.to_a
149
- end
150
-
151
- def self.from_mongo(value)
152
- Set.new(value || [])
153
- end
154
- end
155
-
156
- class String
157
- def self.to_mongo(value)
158
- value.nil? ? nil : value.to_s
159
- end
160
-
161
- def self.from_mongo(value)
162
- value.nil? ? nil : value.to_s
163
- end
164
- end
165
-
166
- class SymbolOperator
167
- attr_reader :field, :operator
168
-
169
- def initialize(field, operator, options={})
170
- @field, @operator = field, operator
171
- end unless method_defined?(:initialize)
172
- end
173
-
174
- class Symbol
175
- %w(gt lt gte lte ne in nin mod all size where exists asc desc).each do |operator|
176
- define_method(operator) do
177
- SymbolOperator.new(self, operator)
178
- end unless method_defined?(operator)
179
- end
180
- end
181
-
182
- class Time
183
- def self.to_mongo(value)
184
- if value.nil? || value == ''
185
- nil
186
- else
187
- time = value.is_a?(Time) ? value : MongoMapper.time_class.parse(value.to_s)
188
- # Convert time to milliseconds since BSON stores dates with that accurracy, but Ruby uses microseconds
189
- Time.at((time.to_f * 1000).round / 1000.0).utc if time
190
- end
191
- end
192
-
193
- def self.from_mongo(value)
194
- if MongoMapper.use_time_zone? && value.present?
195
- value.in_time_zone(Time.zone)
196
- else
197
- value
198
- end
199
- end
200
- end
201
-
202
- class Mongo::ObjectID
203
- alias_method :original_to_json, :to_json
204
-
205
- def to_json(options = nil)
206
- %Q("#{to_s}")
207
- end
208
- end
209
-
210
- module MongoMapper
211
- module Support
212
- autoload :DescendantAppends, 'mongo_mapper/support/descendant_appends'
213
- autoload :Find, 'mongo_mapper/support/find'
214
- end
215
- end
data/mongo_mapper.gemspec DELETED
@@ -1,196 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = %q{mongo_mapper}
8
- s.version = "0.7.0"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["John Nunemaker"]
12
- s.date = %q{2010-02-10}
13
- s.default_executable = %q{mmconsole}
14
- s.email = %q{nunemaker@gmail.com}
15
- s.executables = ["mmconsole"]
16
- s.extra_rdoc_files = [
17
- "LICENSE",
18
- "README.rdoc"
19
- ]
20
- s.files = [
21
- ".gitignore",
22
- "LICENSE",
23
- "README.rdoc",
24
- "Rakefile",
25
- "VERSION",
26
- "bin/mmconsole",
27
- "lib/mongo_mapper.rb",
28
- "lib/mongo_mapper/document.rb",
29
- "lib/mongo_mapper/embedded_document.rb",
30
- "lib/mongo_mapper/plugins.rb",
31
- "lib/mongo_mapper/plugins/associations.rb",
32
- "lib/mongo_mapper/plugins/associations/base.rb",
33
- "lib/mongo_mapper/plugins/associations/belongs_to_polymorphic_proxy.rb",
34
- "lib/mongo_mapper/plugins/associations/belongs_to_proxy.rb",
35
- "lib/mongo_mapper/plugins/associations/collection.rb",
36
- "lib/mongo_mapper/plugins/associations/embedded_collection.rb",
37
- "lib/mongo_mapper/plugins/associations/in_array_proxy.rb",
38
- "lib/mongo_mapper/plugins/associations/many_documents_as_proxy.rb",
39
- "lib/mongo_mapper/plugins/associations/many_documents_proxy.rb",
40
- "lib/mongo_mapper/plugins/associations/many_embedded_polymorphic_proxy.rb",
41
- "lib/mongo_mapper/plugins/associations/many_embedded_proxy.rb",
42
- "lib/mongo_mapper/plugins/associations/many_polymorphic_proxy.rb",
43
- "lib/mongo_mapper/plugins/associations/one_proxy.rb",
44
- "lib/mongo_mapper/plugins/associations/proxy.rb",
45
- "lib/mongo_mapper/plugins/callbacks.rb",
46
- "lib/mongo_mapper/plugins/clone.rb",
47
- "lib/mongo_mapper/plugins/descendants.rb",
48
- "lib/mongo_mapper/plugins/dirty.rb",
49
- "lib/mongo_mapper/plugins/equality.rb",
50
- "lib/mongo_mapper/plugins/identity_map.rb",
51
- "lib/mongo_mapper/plugins/inspect.rb",
52
- "lib/mongo_mapper/plugins/keys.rb",
53
- "lib/mongo_mapper/plugins/logger.rb",
54
- "lib/mongo_mapper/plugins/pagination.rb",
55
- "lib/mongo_mapper/plugins/pagination/proxy.rb",
56
- "lib/mongo_mapper/plugins/protected.rb",
57
- "lib/mongo_mapper/plugins/rails.rb",
58
- "lib/mongo_mapper/plugins/serialization.rb",
59
- "lib/mongo_mapper/plugins/validations.rb",
60
- "lib/mongo_mapper/query.rb",
61
- "lib/mongo_mapper/support.rb",
62
- "lib/mongo_mapper/support/descendant_appends.rb",
63
- "lib/mongo_mapper/support/find.rb",
64
- "mongo_mapper.gemspec",
65
- "performance/read_write.rb",
66
- "specs.watchr",
67
- "test/NOTE_ON_TESTING",
68
- "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
69
- "test/functional/associations/test_belongs_to_proxy.rb",
70
- "test/functional/associations/test_in_array_proxy.rb",
71
- "test/functional/associations/test_many_documents_as_proxy.rb",
72
- "test/functional/associations/test_many_documents_proxy.rb",
73
- "test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
74
- "test/functional/associations/test_many_embedded_proxy.rb",
75
- "test/functional/associations/test_many_polymorphic_proxy.rb",
76
- "test/functional/associations/test_one_proxy.rb",
77
- "test/functional/test_associations.rb",
78
- "test/functional/test_binary.rb",
79
- "test/functional/test_callbacks.rb",
80
- "test/functional/test_dirty.rb",
81
- "test/functional/test_document.rb",
82
- "test/functional/test_embedded_document.rb",
83
- "test/functional/test_identity_map.rb",
84
- "test/functional/test_logger.rb",
85
- "test/functional/test_modifiers.rb",
86
- "test/functional/test_pagination.rb",
87
- "test/functional/test_protected.rb",
88
- "test/functional/test_string_id_compatibility.rb",
89
- "test/functional/test_validations.rb",
90
- "test/models.rb",
91
- "test/support/custom_matchers.rb",
92
- "test/support/timing.rb",
93
- "test/test_helper.rb",
94
- "test/unit/associations/test_base.rb",
95
- "test/unit/associations/test_proxy.rb",
96
- "test/unit/serializers/test_json_serializer.rb",
97
- "test/unit/test_descendant_appends.rb",
98
- "test/unit/test_document.rb",
99
- "test/unit/test_dynamic_finder.rb",
100
- "test/unit/test_embedded_document.rb",
101
- "test/unit/test_keys.rb",
102
- "test/unit/test_mongo_mapper.rb",
103
- "test/unit/test_pagination.rb",
104
- "test/unit/test_plugins.rb",
105
- "test/unit/test_query.rb",
106
- "test/unit/test_rails.rb",
107
- "test/unit/test_rails_compatibility.rb",
108
- "test/unit/test_serialization.rb",
109
- "test/unit/test_support.rb",
110
- "test/unit/test_time_zones.rb",
111
- "test/unit/test_validations.rb"
112
- ]
113
- s.homepage = %q{http://github.com/jnunemaker/mongomapper}
114
- s.rdoc_options = ["--charset=UTF-8"]
115
- s.require_paths = ["lib"]
116
- s.rubygems_version = %q{1.3.5}
117
- s.summary = %q{Awesome gem for modeling your domain and storing it in mongo}
118
- s.test_files = [
119
- "test/functional/associations/test_belongs_to_polymorphic_proxy.rb",
120
- "test/functional/associations/test_belongs_to_proxy.rb",
121
- "test/functional/associations/test_in_array_proxy.rb",
122
- "test/functional/associations/test_many_documents_as_proxy.rb",
123
- "test/functional/associations/test_many_documents_proxy.rb",
124
- "test/functional/associations/test_many_embedded_polymorphic_proxy.rb",
125
- "test/functional/associations/test_many_embedded_proxy.rb",
126
- "test/functional/associations/test_many_polymorphic_proxy.rb",
127
- "test/functional/associations/test_one_proxy.rb",
128
- "test/functional/test_associations.rb",
129
- "test/functional/test_binary.rb",
130
- "test/functional/test_callbacks.rb",
131
- "test/functional/test_dirty.rb",
132
- "test/functional/test_document.rb",
133
- "test/functional/test_embedded_document.rb",
134
- "test/functional/test_identity_map.rb",
135
- "test/functional/test_logger.rb",
136
- "test/functional/test_modifiers.rb",
137
- "test/functional/test_pagination.rb",
138
- "test/functional/test_protected.rb",
139
- "test/functional/test_string_id_compatibility.rb",
140
- "test/functional/test_validations.rb",
141
- "test/models.rb",
142
- "test/support/custom_matchers.rb",
143
- "test/support/timing.rb",
144
- "test/test_helper.rb",
145
- "test/unit/associations/test_base.rb",
146
- "test/unit/associations/test_proxy.rb",
147
- "test/unit/serializers/test_json_serializer.rb",
148
- "test/unit/test_descendant_appends.rb",
149
- "test/unit/test_document.rb",
150
- "test/unit/test_dynamic_finder.rb",
151
- "test/unit/test_embedded_document.rb",
152
- "test/unit/test_keys.rb",
153
- "test/unit/test_mongo_mapper.rb",
154
- "test/unit/test_pagination.rb",
155
- "test/unit/test_plugins.rb",
156
- "test/unit/test_query.rb",
157
- "test/unit/test_rails.rb",
158
- "test/unit/test_rails_compatibility.rb",
159
- "test/unit/test_serialization.rb",
160
- "test/unit/test_support.rb",
161
- "test/unit/test_time_zones.rb",
162
- "test/unit/test_validations.rb"
163
- ]
164
-
165
- if s.respond_to? :specification_version then
166
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
167
- s.specification_version = 3
168
-
169
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
170
- s.add_runtime_dependency(%q<activesupport>, [">= 2.3"])
171
- s.add_runtime_dependency(%q<mongo>, ["= 0.18.3"])
172
- s.add_runtime_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
173
- s.add_development_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
174
- s.add_development_dependency(%q<shoulda>, ["= 2.10.2"])
175
- s.add_development_dependency(%q<timecop>, ["= 0.3.1"])
176
- s.add_development_dependency(%q<mocha>, ["= 0.9.8"])
177
- else
178
- s.add_dependency(%q<activesupport>, [">= 2.3"])
179
- s.add_dependency(%q<mongo>, ["= 0.18.3"])
180
- s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
181
- s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
182
- s.add_dependency(%q<shoulda>, ["= 2.10.2"])
183
- s.add_dependency(%q<timecop>, ["= 0.3.1"])
184
- s.add_dependency(%q<mocha>, ["= 0.9.8"])
185
- end
186
- else
187
- s.add_dependency(%q<activesupport>, [">= 2.3"])
188
- s.add_dependency(%q<mongo>, ["= 0.18.3"])
189
- s.add_dependency(%q<jnunemaker-validatable>, ["= 1.8.1"])
190
- s.add_dependency(%q<jnunemaker-matchy>, ["= 0.4.0"])
191
- s.add_dependency(%q<shoulda>, ["= 2.10.2"])
192
- s.add_dependency(%q<timecop>, ["= 0.3.1"])
193
- s.add_dependency(%q<mocha>, ["= 0.9.8"])
194
- end
195
- end
196
-
@@ -1,52 +0,0 @@
1
- # The purpose of this is to check finding, initializing,
2
- # and creating objects (typecasting times/dates and booleans).
3
-
4
- require 'pp'
5
- require 'benchmark'
6
- require 'rubygems'
7
-
8
- # to test with slow version just do this:
9
- # gem 'mongo_mapper', '0.6.10'
10
- # and comment out this:
11
- $:.unshift File.expand_path(File.dirname(__FILE__) + '/../lib')
12
-
13
- require 'mongo_mapper'
14
-
15
- MongoMapper.database = 'testing'
16
-
17
- class Foo
18
- include MongoMapper::Document
19
- key :approved, Boolean
20
- key :count, Integer
21
- key :approved_at, Time
22
- key :expire_on, Date
23
- timestamps!
24
- end
25
- Foo.collection.remove
26
-
27
- Benchmark.bm(5) do |x|
28
- ids = []
29
- x.report("write") do
30
- 1000.times { |i| ids << Foo.create(:count => 0, :approved => true, :approved_at => Time.now, :expire_on => Date.today).id }
31
- end
32
-
33
- x.report("read ") do
34
- ids.each { |id| Foo.first(:id => id) }
35
- end
36
- end
37
-
38
- # I was get something like this on my puny macbook air:
39
- # user system total real
40
- # write 4.810000 0.090000 4.900000 ( 5.039949)
41
- # read 2.730000 0.070000 2.800000 ( 2.990749)
42
- #
43
- #
44
- # After these commits:
45
- #
46
- # * http://github.com/jnunemaker/mongomapper/commit/e5091fa140d5fae2721017b53027092233694ee5
47
- # * http://github.com/jnunemaker/mongomapper/commit/c22bbde4fa1cfbc310d79cb0e50203310ffb03d1
48
- #
49
- # I'm now getting something like this:
50
- # user system total real
51
- # write 1.660000 0.050000 1.710000 ( 1.752676)
52
- # read 1.060000 0.050000 1.110000 ( 1.263429)
data/specs.watchr DELETED
@@ -1,51 +0,0 @@
1
- def growl(title, msg, img)
2
- %x{growlnotify -m #{ msg.inspect} -t #{title.inspect} --image ~/.watchr/#{img}.png}
3
- end
4
-
5
- def form_growl_message(str)
6
- results = str.split("\n").last
7
- if results =~ /[1-9]\s(failure|error)s?/
8
- growl "Test Results", "#{results}", "fail"
9
- elsif results != ""
10
- growl "Test Results", "#{results}", "pass"
11
- end
12
- end
13
-
14
- def run(cmd)
15
- puts(cmd)
16
- output = ""
17
- IO.popen(cmd) do |com|
18
- com.each_char do |c|
19
- print c
20
- output << c
21
- $stdout.flush
22
- end
23
- end
24
- form_growl_message output
25
- end
26
-
27
- def run_test_file(file)
28
- run %Q(ruby -I"lib:test" -rubygems #{file})
29
- end
30
-
31
- def run_all_tests
32
- run "rake test"
33
- end
34
-
35
- def related_test_files(path)
36
- Dir['test/**/*.rb'].select { |file| file =~ /test_#{File.basename(path)}/ }
37
- end
38
-
39
- watch('test/test_helper\.rb') { system('clear'); run_all_tests }
40
- watch('test/.*/test_.*\.rb') { |m| system('clear'); run_test_file(m[0]) }
41
- watch('lib/.*') { |m| related_test_files(m[0]).each { |file| run_test_file(file) } }
42
-
43
- # Ctrl-\
44
- Signal.trap('QUIT') do
45
- puts " --- Running all tests ---\n\n"
46
- run_all_tests
47
- end
48
-
49
- # Ctrl-C
50
- Signal.trap('INT') { abort("\n") }
51
-
@@ -1,55 +0,0 @@
1
- module CustomMatchers
2
- custom_matcher :be_nil do |receiver, matcher, args|
3
- matcher.positive_failure_message = "Expected #{receiver} to be nil but it wasn't"
4
- matcher.negative_failure_message = "Expected #{receiver} not to be nil but it was"
5
- receiver.nil?
6
- end
7
-
8
- custom_matcher :be_blank do |receiver, matcher, args|
9
- matcher.positive_failure_message = "Expected #{receiver} to be blank but it wasn't"
10
- matcher.negative_failure_message = "Expected #{receiver} not to be blank but it was"
11
- receiver.blank?
12
- end
13
-
14
- custom_matcher :be_true do |receiver, matcher, args|
15
- matcher.positive_failure_message = "Expected #{receiver} to be true but it wasn't"
16
- matcher.negative_failure_message = "Expected #{receiver} not to be true but it was"
17
- receiver.eql?(true)
18
- end
19
-
20
- custom_matcher :be_false do |receiver, matcher, args|
21
- matcher.positive_failure_message = "Expected #{receiver} to be false but it wasn't"
22
- matcher.negative_failure_message = "Expected #{receiver} not to be false but it was"
23
- receiver.eql?(false)
24
- end
25
-
26
- custom_matcher :be_valid do |receiver, matcher, args|
27
- matcher.positive_failure_message = "Expected to be valid but it was invalid #{receiver.errors.inspect}"
28
- matcher.negative_failure_message = "Expected to be invalid but it was valid #{receiver.errors.inspect}"
29
- receiver.valid?
30
- end
31
-
32
- custom_matcher :have_error_on do |receiver, matcher, args|
33
- receiver.valid?
34
- attribute = args[0]
35
- expected_message = args[1]
36
-
37
- if expected_message.nil?
38
- matcher.positive_failure_message = "#{receiver} had no errors on #{attribute}"
39
- matcher.negative_failure_message = "#{receiver} had errors on #{attribute} #{receiver.errors.inspect}"
40
- !receiver.errors.on(attribute).blank?
41
- else
42
- actual = receiver.errors.on(attribute)
43
- matcher.positive_failure_message = %Q(Expected error on #{attribute} to be "#{expected_message}" but was "#{actual}")
44
- matcher.negative_failure_message = %Q(Expected error on #{attribute} not to be "#{expected_message}" but was "#{actual}")
45
- actual == expected_message
46
- end
47
- end
48
-
49
- custom_matcher :have_index do |receiver, matcher, args|
50
- index_name = args[0]
51
- matcher.positive_failure_message = "#{receiver} does not have index named #{index_name}, but should"
52
- matcher.negative_failure_message = "#{receiver} does have index named #{index_name}, but should not"
53
- !receiver.collection.index_information.detect { |index| index[0] == index_name }.nil?
54
- end
55
- end