mongo_doc 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (122) hide show
  1. data/.document +5 -0
  2. data/.gitignore +7 -0
  3. data/LICENSE +20 -0
  4. data/README.textile +174 -0
  5. data/Rakefile +135 -0
  6. data/TODO +31 -0
  7. data/VERSION +1 -0
  8. data/data/.gitignore +2 -0
  9. data/examples/simple_document.rb +35 -0
  10. data/examples/simple_object.rb +30 -0
  11. data/features/finders.feature +76 -0
  12. data/features/mongodb.yml +7 -0
  13. data/features/mongodoc_base.feature +128 -0
  14. data/features/new_record.feature +36 -0
  15. data/features/partial_updates.feature +105 -0
  16. data/features/removing_documents.feature +68 -0
  17. data/features/saving_an_object.feature +15 -0
  18. data/features/scopes.feature +66 -0
  19. data/features/step_definitions/collection_steps.rb +14 -0
  20. data/features/step_definitions/document_steps.rb +149 -0
  21. data/features/step_definitions/documents.rb +30 -0
  22. data/features/step_definitions/finder_steps.rb +15 -0
  23. data/features/step_definitions/json_steps.rb +9 -0
  24. data/features/step_definitions/object_steps.rb +50 -0
  25. data/features/step_definitions/objects.rb +24 -0
  26. data/features/step_definitions/partial_update_steps.rb +32 -0
  27. data/features/step_definitions/query_steps.rb +54 -0
  28. data/features/step_definitions/removing_documents_steps.rb +14 -0
  29. data/features/step_definitions/scope_steps.rb +18 -0
  30. data/features/step_definitions/util_steps.rb +7 -0
  31. data/features/support/support.rb +10 -0
  32. data/features/using_criteria.feature +128 -0
  33. data/lib/mongo_doc/associations/collection_proxy.rb +105 -0
  34. data/lib/mongo_doc/associations/document_proxy.rb +56 -0
  35. data/lib/mongo_doc/associations/hash_proxy.rb +98 -0
  36. data/lib/mongo_doc/associations/proxy_base.rb +53 -0
  37. data/lib/mongo_doc/attributes.rb +140 -0
  38. data/lib/mongo_doc/bson.rb +45 -0
  39. data/lib/mongo_doc/collection.rb +55 -0
  40. data/lib/mongo_doc/connection.rb +88 -0
  41. data/lib/mongo_doc/contexts/enumerable.rb +128 -0
  42. data/lib/mongo_doc/contexts/ids.rb +41 -0
  43. data/lib/mongo_doc/contexts/mongo.rb +232 -0
  44. data/lib/mongo_doc/contexts.rb +25 -0
  45. data/lib/mongo_doc/criteria.rb +38 -0
  46. data/lib/mongo_doc/cursor.rb +32 -0
  47. data/lib/mongo_doc/document.rb +216 -0
  48. data/lib/mongo_doc/ext/array.rb +5 -0
  49. data/lib/mongo_doc/ext/binary.rb +7 -0
  50. data/lib/mongo_doc/ext/boolean_class.rb +11 -0
  51. data/lib/mongo_doc/ext/date.rb +16 -0
  52. data/lib/mongo_doc/ext/date_time.rb +13 -0
  53. data/lib/mongo_doc/ext/dbref.rb +7 -0
  54. data/lib/mongo_doc/ext/hash.rb +7 -0
  55. data/lib/mongo_doc/ext/nil_class.rb +5 -0
  56. data/lib/mongo_doc/ext/numeric.rb +17 -0
  57. data/lib/mongo_doc/ext/object.rb +17 -0
  58. data/lib/mongo_doc/ext/object_id.rb +7 -0
  59. data/lib/mongo_doc/ext/regexp.rb +5 -0
  60. data/lib/mongo_doc/ext/string.rb +5 -0
  61. data/lib/mongo_doc/ext/symbol.rb +5 -0
  62. data/lib/mongo_doc/ext/time.rb +5 -0
  63. data/lib/mongo_doc/finders.rb +49 -0
  64. data/lib/mongo_doc/matchers.rb +35 -0
  65. data/lib/mongo_doc/query.rb +7 -0
  66. data/lib/mongo_doc/scope.rb +64 -0
  67. data/lib/mongo_doc/validations/macros.rb +11 -0
  68. data/lib/mongo_doc/validations/validates_embedded.rb +13 -0
  69. data/lib/mongo_doc.rb +19 -0
  70. data/lib/mongoid/contexts/paging.rb +42 -0
  71. data/lib/mongoid/criteria.rb +247 -0
  72. data/lib/mongoid/criterion/complex.rb +21 -0
  73. data/lib/mongoid/criterion/exclusion.rb +65 -0
  74. data/lib/mongoid/criterion/inclusion.rb +92 -0
  75. data/lib/mongoid/criterion/optional.rb +136 -0
  76. data/lib/mongoid/extensions/hash/criteria_helpers.rb +20 -0
  77. data/lib/mongoid/extensions/symbol/inflections.rb +36 -0
  78. data/lib/mongoid/matchers/all.rb +11 -0
  79. data/lib/mongoid/matchers/default.rb +26 -0
  80. data/lib/mongoid/matchers/exists.rb +13 -0
  81. data/lib/mongoid/matchers/gt.rb +11 -0
  82. data/lib/mongoid/matchers/gte.rb +11 -0
  83. data/lib/mongoid/matchers/in.rb +11 -0
  84. data/lib/mongoid/matchers/lt.rb +11 -0
  85. data/lib/mongoid/matchers/lte.rb +11 -0
  86. data/lib/mongoid/matchers/ne.rb +11 -0
  87. data/lib/mongoid/matchers/nin.rb +11 -0
  88. data/lib/mongoid/matchers/size.rb +11 -0
  89. data/mongo_doc.gemspec +205 -0
  90. data/mongod.example.yml +2 -0
  91. data/mongodb.example.yml +14 -0
  92. data/perf/mongo_doc_runner.rb +90 -0
  93. data/perf/ruby_driver_runner.rb +64 -0
  94. data/script/console +8 -0
  95. data/spec/associations/collection_proxy_spec.rb +200 -0
  96. data/spec/associations/document_proxy_spec.rb +42 -0
  97. data/spec/associations/hash_proxy_spec.rb +163 -0
  98. data/spec/attributes_spec.rb +273 -0
  99. data/spec/bson_matchers.rb +54 -0
  100. data/spec/bson_spec.rb +196 -0
  101. data/spec/collection_spec.rb +161 -0
  102. data/spec/connection_spec.rb +147 -0
  103. data/spec/contexts/enumerable_spec.rb +274 -0
  104. data/spec/contexts/ids_spec.rb +49 -0
  105. data/spec/contexts/mongo_spec.rb +198 -0
  106. data/spec/contexts_spec.rb +28 -0
  107. data/spec/criteria_spec.rb +33 -0
  108. data/spec/cursor_spec.rb +91 -0
  109. data/spec/document_ext.rb +9 -0
  110. data/spec/document_spec.rb +664 -0
  111. data/spec/embedded_save_spec.rb +109 -0
  112. data/spec/finders_spec.rb +73 -0
  113. data/spec/hash_matchers.rb +27 -0
  114. data/spec/matchers_spec.rb +342 -0
  115. data/spec/mongodb.yml +6 -0
  116. data/spec/mongodb_pairs.yml +8 -0
  117. data/spec/new_record_spec.rb +128 -0
  118. data/spec/query_spec.rb +12 -0
  119. data/spec/scope_spec.rb +79 -0
  120. data/spec/spec.opts +2 -0
  121. data/spec/spec_helper.rb +13 -0
  122. metadata +290 -0
@@ -0,0 +1,79 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), "spec_helper.rb"))
2
+
3
+ describe MongoDoc::Scope do
4
+
5
+ module Extension
6
+ def extension_module_method
7
+ "extension module method"
8
+ end
9
+ end
10
+
11
+ class ScopeTest
12
+ include MongoDoc::Document
13
+
14
+ key :active
15
+ key :count
16
+
17
+ scope :active, where(:active => true)
18
+ scope :count_lte_one, where(:count.lte => 1) do
19
+ def extension_method
20
+ "extension method"
21
+ end
22
+ end
23
+ scope :count_gt_one, where(:count.gt => 1), :extend => Extension
24
+ scope :at_least_count, lambda {|count| where(:count.gt => count)}
25
+ end
26
+
27
+ context ".scope" do
28
+ it "adds the named scope to the hash of scopes" do
29
+ ScopeTest.scopes.should have_key(:active)
30
+ end
31
+
32
+ it "creates a class method for the named scope" do
33
+ ScopeTest.should respond_to(:active)
34
+ end
35
+ end
36
+
37
+ context "accessing a named scope" do
38
+ it "is a criteria proxy" do
39
+ MongoDoc::Scope::CriteriaProxy.should === ScopeTest.active
40
+ end
41
+
42
+ it "responds like a criteria" do
43
+ ScopeTest.active.should respond_to(:selector)
44
+ end
45
+
46
+ it "has set the conditions on the criteria" do
47
+ ScopeTest.active.selector.should has_entry(:active => true)
48
+ end
49
+
50
+ it "sets the association extension by block" do
51
+ ScopeTest.count_lte_one.extension_method.should == "extension method"
52
+ end
53
+
54
+ it "sets the association extension by :extend" do
55
+ ScopeTest.count_gt_one.extension_module_method.should == "extension module method"
56
+ end
57
+
58
+ context "when using a lambda" do
59
+ it "accepts parameters to the criteria" do
60
+ ScopeTest.at_least_count(3).selector.should has_entry(:count => {'$gt' => 3})
61
+ end
62
+ end
63
+ end
64
+
65
+ context "chained scopes" do
66
+ it "is a criteria proxy" do
67
+ MongoDoc::Scope::CriteriaProxy.should === ScopeTest.active.count_gt_one
68
+ end
69
+
70
+ it "responds like a criteria" do
71
+ ScopeTest.active.count_gt_one.should respond_to(:selector)
72
+ end
73
+
74
+ it "merges the criteria" do
75
+ ScopeTest.active.count_gt_one.selector.should has_entry(:count => {'$gt' => 1}, :active => true)
76
+ end
77
+ end
78
+ end
79
+
data/spec/spec.opts ADDED
@@ -0,0 +1,2 @@
1
+ --colour
2
+ --format nested
@@ -0,0 +1,13 @@
1
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
3
+ require 'mongo_doc'
4
+ require 'spec'
5
+ require 'spec/autorun'
6
+ require 'bson_matchers'
7
+ require 'hash_matchers'
8
+ require 'document_ext'
9
+
10
+ Spec::Runner.configure do |config|
11
+ config.include(BsonMatchers)
12
+ config.include(HashMatchers)
13
+ end
metadata ADDED
@@ -0,0 +1,290 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo_doc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 3
8
+ - 0
9
+ version: 0.3.0
10
+ platform: ruby
11
+ authors:
12
+ - Les Hill
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-03-02 00:00:00 -05:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: mongo
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 19
30
+ version: "0.19"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: mongo_ext
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "="
39
+ - !ruby/object:Gem::Version
40
+ segments:
41
+ - 0
42
+ - 19
43
+ version: "0.19"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: durran-validatable
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "="
52
+ - !ruby/object:Gem::Version
53
+ segments:
54
+ - 2
55
+ - 0
56
+ - 1
57
+ version: 2.0.1
58
+ type: :runtime
59
+ version_requirements: *id003
60
+ - !ruby/object:Gem::Dependency
61
+ name: leshill-will_paginate
62
+ prerelease: false
63
+ requirement: &id004 !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "="
66
+ - !ruby/object:Gem::Version
67
+ segments:
68
+ - 2
69
+ - 3
70
+ - 11
71
+ version: 2.3.11
72
+ type: :runtime
73
+ version_requirements: *id004
74
+ - !ruby/object:Gem::Dependency
75
+ name: rspec
76
+ prerelease: false
77
+ requirement: &id005 !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 1
83
+ - 3
84
+ - 0
85
+ version: 1.3.0
86
+ type: :development
87
+ version_requirements: *id005
88
+ - !ruby/object:Gem::Dependency
89
+ name: cucumber
90
+ prerelease: false
91
+ requirement: &id006 !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "="
94
+ - !ruby/object:Gem::Version
95
+ segments:
96
+ - 0
97
+ - 6
98
+ - 2
99
+ version: 0.6.2
100
+ type: :development
101
+ version_requirements: *id006
102
+ description: ODM for MongoDB
103
+ email: leshill@gmail.com
104
+ executables: []
105
+
106
+ extensions: []
107
+
108
+ extra_rdoc_files:
109
+ - LICENSE
110
+ - README.textile
111
+ - TODO
112
+ files:
113
+ - .document
114
+ - .gitignore
115
+ - LICENSE
116
+ - README.textile
117
+ - Rakefile
118
+ - TODO
119
+ - VERSION
120
+ - data/.gitignore
121
+ - examples/simple_document.rb
122
+ - examples/simple_object.rb
123
+ - features/finders.feature
124
+ - features/mongodb.yml
125
+ - features/mongodoc_base.feature
126
+ - features/new_record.feature
127
+ - features/partial_updates.feature
128
+ - features/removing_documents.feature
129
+ - features/saving_an_object.feature
130
+ - features/scopes.feature
131
+ - features/step_definitions/collection_steps.rb
132
+ - features/step_definitions/document_steps.rb
133
+ - features/step_definitions/documents.rb
134
+ - features/step_definitions/finder_steps.rb
135
+ - features/step_definitions/json_steps.rb
136
+ - features/step_definitions/object_steps.rb
137
+ - features/step_definitions/objects.rb
138
+ - features/step_definitions/partial_update_steps.rb
139
+ - features/step_definitions/query_steps.rb
140
+ - features/step_definitions/removing_documents_steps.rb
141
+ - features/step_definitions/scope_steps.rb
142
+ - features/step_definitions/util_steps.rb
143
+ - features/support/support.rb
144
+ - features/using_criteria.feature
145
+ - lib/mongo_doc.rb
146
+ - lib/mongo_doc/associations/collection_proxy.rb
147
+ - lib/mongo_doc/associations/document_proxy.rb
148
+ - lib/mongo_doc/associations/hash_proxy.rb
149
+ - lib/mongo_doc/associations/proxy_base.rb
150
+ - lib/mongo_doc/attributes.rb
151
+ - lib/mongo_doc/bson.rb
152
+ - lib/mongo_doc/collection.rb
153
+ - lib/mongo_doc/connection.rb
154
+ - lib/mongo_doc/contexts.rb
155
+ - lib/mongo_doc/contexts/enumerable.rb
156
+ - lib/mongo_doc/contexts/ids.rb
157
+ - lib/mongo_doc/contexts/mongo.rb
158
+ - lib/mongo_doc/criteria.rb
159
+ - lib/mongo_doc/cursor.rb
160
+ - lib/mongo_doc/document.rb
161
+ - lib/mongo_doc/ext/array.rb
162
+ - lib/mongo_doc/ext/binary.rb
163
+ - lib/mongo_doc/ext/boolean_class.rb
164
+ - lib/mongo_doc/ext/date.rb
165
+ - lib/mongo_doc/ext/date_time.rb
166
+ - lib/mongo_doc/ext/dbref.rb
167
+ - lib/mongo_doc/ext/hash.rb
168
+ - lib/mongo_doc/ext/nil_class.rb
169
+ - lib/mongo_doc/ext/numeric.rb
170
+ - lib/mongo_doc/ext/object.rb
171
+ - lib/mongo_doc/ext/object_id.rb
172
+ - lib/mongo_doc/ext/regexp.rb
173
+ - lib/mongo_doc/ext/string.rb
174
+ - lib/mongo_doc/ext/symbol.rb
175
+ - lib/mongo_doc/ext/time.rb
176
+ - lib/mongo_doc/finders.rb
177
+ - lib/mongo_doc/matchers.rb
178
+ - lib/mongo_doc/query.rb
179
+ - lib/mongo_doc/scope.rb
180
+ - lib/mongo_doc/validations/macros.rb
181
+ - lib/mongo_doc/validations/validates_embedded.rb
182
+ - lib/mongoid/contexts/paging.rb
183
+ - lib/mongoid/criteria.rb
184
+ - lib/mongoid/criterion/complex.rb
185
+ - lib/mongoid/criterion/exclusion.rb
186
+ - lib/mongoid/criterion/inclusion.rb
187
+ - lib/mongoid/criterion/optional.rb
188
+ - lib/mongoid/extensions/hash/criteria_helpers.rb
189
+ - lib/mongoid/extensions/symbol/inflections.rb
190
+ - lib/mongoid/matchers/all.rb
191
+ - lib/mongoid/matchers/default.rb
192
+ - lib/mongoid/matchers/exists.rb
193
+ - lib/mongoid/matchers/gt.rb
194
+ - lib/mongoid/matchers/gte.rb
195
+ - lib/mongoid/matchers/in.rb
196
+ - lib/mongoid/matchers/lt.rb
197
+ - lib/mongoid/matchers/lte.rb
198
+ - lib/mongoid/matchers/ne.rb
199
+ - lib/mongoid/matchers/nin.rb
200
+ - lib/mongoid/matchers/size.rb
201
+ - mongo_doc.gemspec
202
+ - mongod.example.yml
203
+ - mongodb.example.yml
204
+ - perf/mongo_doc_runner.rb
205
+ - perf/ruby_driver_runner.rb
206
+ - script/console
207
+ - spec/associations/collection_proxy_spec.rb
208
+ - spec/associations/document_proxy_spec.rb
209
+ - spec/associations/hash_proxy_spec.rb
210
+ - spec/attributes_spec.rb
211
+ - spec/bson_matchers.rb
212
+ - spec/bson_spec.rb
213
+ - spec/collection_spec.rb
214
+ - spec/connection_spec.rb
215
+ - spec/contexts/enumerable_spec.rb
216
+ - spec/contexts/ids_spec.rb
217
+ - spec/contexts/mongo_spec.rb
218
+ - spec/contexts_spec.rb
219
+ - spec/criteria_spec.rb
220
+ - spec/cursor_spec.rb
221
+ - spec/document_ext.rb
222
+ - spec/document_spec.rb
223
+ - spec/embedded_save_spec.rb
224
+ - spec/finders_spec.rb
225
+ - spec/hash_matchers.rb
226
+ - spec/matchers_spec.rb
227
+ - spec/mongodb.yml
228
+ - spec/mongodb_pairs.yml
229
+ - spec/new_record_spec.rb
230
+ - spec/query_spec.rb
231
+ - spec/scope_spec.rb
232
+ - spec/spec.opts
233
+ - spec/spec_helper.rb
234
+ has_rdoc: true
235
+ homepage: http://github.com/leshill/mongodoc
236
+ licenses: []
237
+
238
+ post_install_message:
239
+ rdoc_options:
240
+ - --charset=UTF-8
241
+ require_paths:
242
+ - lib
243
+ required_ruby_version: !ruby/object:Gem::Requirement
244
+ requirements:
245
+ - - ">="
246
+ - !ruby/object:Gem::Version
247
+ segments:
248
+ - 0
249
+ version: "0"
250
+ required_rubygems_version: !ruby/object:Gem::Requirement
251
+ requirements:
252
+ - - ">="
253
+ - !ruby/object:Gem::Version
254
+ segments:
255
+ - 0
256
+ version: "0"
257
+ requirements: []
258
+
259
+ rubyforge_project:
260
+ rubygems_version: 1.3.6
261
+ signing_key:
262
+ specification_version: 3
263
+ summary: ODM for MongoDB
264
+ test_files:
265
+ - spec/associations/collection_proxy_spec.rb
266
+ - spec/associations/document_proxy_spec.rb
267
+ - spec/associations/hash_proxy_spec.rb
268
+ - spec/attributes_spec.rb
269
+ - spec/bson_matchers.rb
270
+ - spec/bson_spec.rb
271
+ - spec/collection_spec.rb
272
+ - spec/connection_spec.rb
273
+ - spec/contexts/enumerable_spec.rb
274
+ - spec/contexts/ids_spec.rb
275
+ - spec/contexts/mongo_spec.rb
276
+ - spec/contexts_spec.rb
277
+ - spec/criteria_spec.rb
278
+ - spec/cursor_spec.rb
279
+ - spec/document_ext.rb
280
+ - spec/document_spec.rb
281
+ - spec/embedded_save_spec.rb
282
+ - spec/finders_spec.rb
283
+ - spec/hash_matchers.rb
284
+ - spec/matchers_spec.rb
285
+ - spec/new_record_spec.rb
286
+ - spec/query_spec.rb
287
+ - spec/scope_spec.rb
288
+ - spec/spec_helper.rb
289
+ - examples/simple_document.rb
290
+ - examples/simple_object.rb