mongo_doc 0.6.11 → 0.6.12
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -11
- data/Gemfile.lock +69 -0
- data/README.textile +11 -1
- data/Rakefile +5 -5
- data/VERSION +1 -1
- data/features/polymorphic_collections.feature +16 -0
- data/features/step_definitions/documents.rb +4 -0
- data/features/step_definitions/finder_steps.rb +1 -1
- data/lib/mongo_doc/contexts/ids.rb +2 -21
- data/lib/mongo_doc/contexts.rb +1 -0
- data/lib/mongo_doc/document.rb +2 -4
- data/lib/mongo_doc/polymorphic_collection.rb +32 -0
- data/lib/mongo_doc.rb +1 -1
- data/lib/mongoid/contexts/id_conversion.rb +26 -0
- data/lib/mongoid/criterion/optional.rb +7 -1
- data/mongo_doc.gemspec +25 -11
- data/spec/criteria/optional_spec.rb +26 -0
- data/spec/polymorphic_collection_spec.rb +47 -0
- metadata +58 -18
data/Gemfile
CHANGED
@@ -1,12 +1,3 @@
|
|
1
|
-
source
|
2
|
-
|
3
|
-
gem "activesupport", ">= 3.0.0.beta4"
|
4
|
-
gem "activemodel", ">= 3.0.0.beta4"
|
5
|
-
gem "bson", ">= 1.0.0"
|
6
|
-
gem "bson_ext", ">= 1.0.0"
|
7
|
-
gem "cucumber", ">= 0.8.3"
|
8
|
-
gem "jeweler", ">= 1.4.0"
|
9
|
-
gem "mongo", ">= 1.0.0"
|
10
|
-
gem "rspec", ">= 2.0.0.beta.12"
|
11
|
-
gem "tzinfo", ">= 0.3.22"
|
1
|
+
source :rubygems
|
12
2
|
|
3
|
+
gemspec
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
mongo_doc (0.6.11)
|
5
|
+
activemodel (>= 3.0.0.beta.4)
|
6
|
+
activesupport (>= 3.0.0.beta.4)
|
7
|
+
bson (>= 1.0.0)
|
8
|
+
bson_ext (>= 1.0.0)
|
9
|
+
mongo (>= 1.0.0)
|
10
|
+
tzinfo (>= 0.3.22)
|
11
|
+
|
12
|
+
GEM
|
13
|
+
remote: http://rubygems.org/
|
14
|
+
specs:
|
15
|
+
activemodel (3.0.0.beta4)
|
16
|
+
activesupport (= 3.0.0.beta4)
|
17
|
+
builder (~> 2.1.2)
|
18
|
+
i18n (~> 0.4.1)
|
19
|
+
activesupport (3.0.0.beta4)
|
20
|
+
bson (1.0.4)
|
21
|
+
bson_ext (1.0.4)
|
22
|
+
builder (2.1.2)
|
23
|
+
cucumber (0.8.5)
|
24
|
+
builder (~> 2.1.2)
|
25
|
+
diff-lcs (~> 1.1.2)
|
26
|
+
gherkin (~> 2.1.4)
|
27
|
+
json_pure (~> 1.4.3)
|
28
|
+
term-ansicolor (~> 1.0.4)
|
29
|
+
diff-lcs (1.1.2)
|
30
|
+
gemcutter (0.6.1)
|
31
|
+
gherkin (2.1.5)
|
32
|
+
trollop (~> 1.16.2)
|
33
|
+
git (1.2.5)
|
34
|
+
i18n (0.4.1)
|
35
|
+
jeweler (1.4.0)
|
36
|
+
gemcutter (>= 0.1.0)
|
37
|
+
git (>= 1.2.5)
|
38
|
+
rubyforge (>= 2.0.0)
|
39
|
+
json_pure (1.4.3)
|
40
|
+
mongo (1.0.5)
|
41
|
+
bson (>= 1.0.4)
|
42
|
+
rspec (2.0.0.beta.18)
|
43
|
+
rspec-core (= 2.0.0.beta.18)
|
44
|
+
rspec-expectations (= 2.0.0.beta.18)
|
45
|
+
rspec-mocks (= 2.0.0.beta.18)
|
46
|
+
rspec-core (2.0.0.beta.18)
|
47
|
+
rspec-expectations (2.0.0.beta.18)
|
48
|
+
diff-lcs (>= 1.1.2)
|
49
|
+
rspec-mocks (2.0.0.beta.18)
|
50
|
+
rubyforge (2.0.4)
|
51
|
+
json_pure (>= 1.1.7)
|
52
|
+
term-ansicolor (1.0.5)
|
53
|
+
trollop (1.16.2)
|
54
|
+
tzinfo (0.3.22)
|
55
|
+
|
56
|
+
PLATFORMS
|
57
|
+
ruby
|
58
|
+
|
59
|
+
DEPENDENCIES
|
60
|
+
activemodel (>= 3.0.0.beta.4)
|
61
|
+
activesupport (>= 3.0.0.beta.4)
|
62
|
+
bson (>= 1.0.0)
|
63
|
+
bson_ext (>= 1.0.0)
|
64
|
+
cucumber (>= 0.8.5)
|
65
|
+
jeweler (>= 1.4.0)
|
66
|
+
mongo (>= 1.0.0)
|
67
|
+
mongo_doc!
|
68
|
+
rspec (>= 2.0.0.beta.18)
|
69
|
+
tzinfo (>= 0.3.22)
|
data/README.textile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
h1. MongoDoc
|
2
2
|
|
3
|
-
Version: Hurricane (0.6.
|
3
|
+
Version: Hurricane (0.6.12) 2010/07/23
|
4
4
|
|
5
5
|
h2. Notes
|
6
6
|
|
@@ -177,6 +177,16 @@ Thanks to Sandro and Durran for some great conversations and some lovely code.
|
|
177
177
|
|
178
178
|
Thanks to Elliot for pushing me to get Rails 3 support
|
179
179
|
|
180
|
+
|
181
|
+
h2. Hacking on MongoDoc
|
182
|
+
|
183
|
+
* Clone the project locally.
|
184
|
+
* Use RVM, you will be happier.
|
185
|
+
* Run: @gem install bundler --pre@
|
186
|
+
* Run: @bundle install@
|
187
|
+
* Make sure MongoDB is running.
|
188
|
+
* Run the specs and features (they should all pass!): @rake spec && rake features@
|
189
|
+
|
180
190
|
h2. Note on Patches/Pull Requests
|
181
191
|
|
182
192
|
* Fork the project.
|
data/Rakefile
CHANGED
@@ -12,11 +12,13 @@ begin
|
|
12
12
|
gem.files.include('lib/**/*.task')
|
13
13
|
gem.add_dependency "activesupport", ">= 3.0.0.beta.4"
|
14
14
|
gem.add_dependency "activemodel", ">=3.0.0.beta.4"
|
15
|
-
gem.add_dependency "mongo", ">= 1.0.0"
|
16
15
|
gem.add_dependency "bson", ">= 1.0.0"
|
17
16
|
gem.add_dependency "bson_ext", ">= 1.0.0"
|
18
|
-
gem.
|
19
|
-
gem.
|
17
|
+
gem.add_dependency "mongo", ">= 1.0.0"
|
18
|
+
gem.add_dependency "tzinfo", ">= 0.3.22"
|
19
|
+
gem.add_development_dependency "cucumber", ">= 0.8.5"
|
20
|
+
gem.add_development_dependency "jeweler", ">= 1.4.0"
|
21
|
+
gem.add_development_dependency "rspec", ">= 2.0.0.beta.18"
|
20
22
|
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
21
23
|
end
|
22
24
|
Jeweler::GemcutterTasks.new
|
@@ -37,12 +39,10 @@ end
|
|
37
39
|
|
38
40
|
require 'rspec/core/rake_task'
|
39
41
|
RSpec::Core::RakeTask.new(:spec) do |spec|
|
40
|
-
spec.ruby_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
|
41
42
|
spec.pattern = 'spec/**/*_spec.rb'
|
42
43
|
end
|
43
44
|
|
44
45
|
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
45
|
-
spec.ruby_opts = ['--options', "#{File.expand_path(File.dirname(__FILE__))}/spec/spec.opts"]
|
46
46
|
spec.pattern = 'spec/**/*_spec.rb'
|
47
47
|
spec.rcov = true
|
48
48
|
end
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.6.
|
1
|
+
0.6.12
|
@@ -0,0 +1,16 @@
|
|
1
|
+
Feature: Polymorphic Collections
|
2
|
+
|
3
|
+
Background:
|
4
|
+
Given an empty Person document collection
|
5
|
+
And a Person document named 'Fry' :
|
6
|
+
| Name |
|
7
|
+
| Philip J. Fry |
|
8
|
+
And a VIP document named 'Leela' :
|
9
|
+
| Name | Title |
|
10
|
+
| Turanga Leela | Captain |
|
11
|
+
|
12
|
+
Scenario: Subclassed documents are in the same collection
|
13
|
+
Given I save the document 'Fry'
|
14
|
+
And I save the document 'Leela'
|
15
|
+
When I query people with count
|
16
|
+
Then the query result is 2 documents
|
@@ -10,6 +10,6 @@ When /^I query (.+) to find_one with the (.+) of the '(.+)' document$/ do |colle
|
|
10
10
|
self.finder_query = klass(collection).find_one(instance_variable_get("@#{doc_name}").send(id))
|
11
11
|
end
|
12
12
|
|
13
|
-
Then /^the query result was (\d+) documents$/ do |count|
|
13
|
+
Then /^the query result (?:is|was) (\d+) documents$/ do |count|
|
14
14
|
query.should == count.to_i
|
15
15
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Mongoid
|
2
2
|
module Contexts
|
3
3
|
module Ids
|
4
|
+
include IdConversion
|
5
|
+
|
4
6
|
# Return documents based on an id search. Will handle if a single id has
|
5
7
|
# been passed or mulitple ids.
|
6
8
|
#
|
@@ -15,27 +17,6 @@ module Mongoid
|
|
15
17
|
criteria.id(strings_to_object_ids(params))
|
16
18
|
params.is_a?(Array) ? criteria.entries : one
|
17
19
|
end
|
18
|
-
|
19
|
-
protected
|
20
|
-
|
21
|
-
# Convert ids from strings to +BSON::ObjectID+s
|
22
|
-
def strings_to_object_ids(ids)
|
23
|
-
if Array === ids
|
24
|
-
ids.map {|id| string_to_object_id(id) }
|
25
|
-
else
|
26
|
-
string_to_object_id(ids)
|
27
|
-
end
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
# Convert ids from strings to +BSON::ObjectID+s
|
32
|
-
def string_to_object_id(id)
|
33
|
-
if String === id
|
34
|
-
::BSON::ObjectID.from_string(id)
|
35
|
-
else
|
36
|
-
id
|
37
|
-
end
|
38
|
-
end
|
39
20
|
end
|
40
21
|
end
|
41
22
|
end
|
data/lib/mongo_doc/contexts.rb
CHANGED
data/lib/mongo_doc/document.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'mongo_doc/bson'
|
2
|
+
require 'mongo_doc/polymorphic_collection'
|
2
3
|
require 'mongo_doc/attributes'
|
3
4
|
require 'mongo_doc/root'
|
4
5
|
require 'mongo_doc/associations'
|
@@ -28,6 +29,7 @@ module MongoDoc
|
|
28
29
|
klass.class_eval do
|
29
30
|
include Attributes
|
30
31
|
include Root
|
32
|
+
extend PolymorphicCollection
|
31
33
|
extend Associations
|
32
34
|
extend ClassMethods
|
33
35
|
extend Criteria
|
@@ -151,10 +153,6 @@ module MongoDoc
|
|
151
153
|
@collection ||= MongoDoc::Collection.new(collection_name)
|
152
154
|
end
|
153
155
|
|
154
|
-
def collection_name
|
155
|
-
self.to_s.tableize.gsub('/', '.')
|
156
|
-
end
|
157
|
-
|
158
156
|
def create(attrs = {})
|
159
157
|
instance = new(attrs)
|
160
158
|
instance.save(true)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MongoDoc
|
2
|
+
module PolymorphicCollection
|
3
|
+
|
4
|
+
def collection_name(name = nil)
|
5
|
+
@_collection_name ||= determine_collection_name(name && name.to_s)
|
6
|
+
end
|
7
|
+
|
8
|
+
private
|
9
|
+
|
10
|
+
def _parentclass(parentclass = nil)
|
11
|
+
@_parentclass ||= parentclass
|
12
|
+
end
|
13
|
+
|
14
|
+
def default_collection_name
|
15
|
+
self.to_s.tableize.gsub('/', '.')
|
16
|
+
end
|
17
|
+
|
18
|
+
def determine_collection_name(name)
|
19
|
+
name || find_collection_name
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_collection_name
|
23
|
+
_parentclass.try(:collection_name) || default_collection_name
|
24
|
+
end
|
25
|
+
|
26
|
+
def inherited(subklass)
|
27
|
+
super
|
28
|
+
subklass.send(:_parentclass, self)
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
data/lib/mongo_doc.rb
CHANGED
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module Contexts
|
3
|
+
module IdConversion
|
4
|
+
protected
|
5
|
+
|
6
|
+
# Convert ids from strings to +BSON::ObjectID+s
|
7
|
+
def strings_to_object_ids(ids)
|
8
|
+
if Array === ids
|
9
|
+
ids.map {|id| string_to_object_id(id) }
|
10
|
+
else
|
11
|
+
string_to_object_id(ids)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
# Convert ids from strings to +BSON::ObjectID+s
|
17
|
+
def string_to_object_id(id)
|
18
|
+
if String === id
|
19
|
+
::BSON::ObjectID.from_string(id)
|
20
|
+
else
|
21
|
+
id
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -1,7 +1,12 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'mongoid/contexts/id_conversion'
|
4
|
+
|
2
5
|
module Mongoid #:nodoc:
|
3
6
|
module Criterion #:nodoc:
|
4
7
|
module Optional
|
8
|
+
include Mongoid::Contexts::IdConversion
|
9
|
+
|
5
10
|
# Tells the criteria that the cursor that gets returned needs to be
|
6
11
|
# cached. This is so multiple iterations don't hit the database multiple
|
7
12
|
# times, however this is not advisable when working with large data sets
|
@@ -70,7 +75,8 @@ module Mongoid #:nodoc:
|
|
70
75
|
#
|
71
76
|
# Returns: <tt>self</tt>
|
72
77
|
def id(*args)
|
73
|
-
|
78
|
+
ids = strings_to_object_ids(args.flatten)
|
79
|
+
(ids.size > 1) ? self.in(:_id => ids) : (@selector[:_id] = ids.first)
|
74
80
|
self
|
75
81
|
end
|
76
82
|
|
data/mongo_doc.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{mongo_doc}
|
8
|
-
s.version = "0.6.
|
8
|
+
s.version = "0.6.12"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Les Hill"]
|
12
|
-
s.date = %q{2010-07-
|
12
|
+
s.date = %q{2010-07-23}
|
13
13
|
s.description = %q{ODM for MongoDB}
|
14
14
|
s.email = %q{leshill@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
|
|
23
23
|
".rvmrc",
|
24
24
|
".watchr",
|
25
25
|
"Gemfile",
|
26
|
+
"Gemfile.lock",
|
26
27
|
"HISTORY.md",
|
27
28
|
"LICENSE",
|
28
29
|
"README.textile",
|
@@ -38,6 +39,7 @@ Gem::Specification.new do |s|
|
|
38
39
|
"features/mongodoc_base.feature",
|
39
40
|
"features/new_record.feature",
|
40
41
|
"features/partial_updates.feature",
|
42
|
+
"features/polymorphic_collections.feature",
|
41
43
|
"features/references.feature",
|
42
44
|
"features/removing_documents.feature",
|
43
45
|
"features/saving_an_object.feature",
|
@@ -99,6 +101,7 @@ Gem::Specification.new do |s|
|
|
99
101
|
"lib/mongo_doc/finders.rb",
|
100
102
|
"lib/mongo_doc/index.rb",
|
101
103
|
"lib/mongo_doc/matchers.rb",
|
104
|
+
"lib/mongo_doc/polymorphic_collection.rb",
|
102
105
|
"lib/mongo_doc/railtie.rb",
|
103
106
|
"lib/mongo_doc/railties/config.rb",
|
104
107
|
"lib/mongo_doc/railties/db_prepare.task",
|
@@ -110,6 +113,7 @@ Gem::Specification.new do |s|
|
|
110
113
|
"lib/mongo_doc/validations.rb",
|
111
114
|
"lib/mongo_doc/validations/validates_embedded.rb",
|
112
115
|
"lib/mongoid/contexts/enumerable.rb",
|
116
|
+
"lib/mongoid/contexts/id_conversion.rb",
|
113
117
|
"lib/mongoid/contexts/paging.rb",
|
114
118
|
"lib/mongoid/criteria.rb",
|
115
119
|
"lib/mongoid/criterion/complex.rb",
|
@@ -151,6 +155,7 @@ Gem::Specification.new do |s|
|
|
151
155
|
"spec/contexts/ids_spec.rb",
|
152
156
|
"spec/contexts/mongo_spec.rb",
|
153
157
|
"spec/contexts_spec.rb",
|
158
|
+
"spec/criteria/optional_spec.rb",
|
154
159
|
"spec/criteria_spec.rb",
|
155
160
|
"spec/cursor_spec.rb",
|
156
161
|
"spec/database_cleaner_spec.rb",
|
@@ -165,6 +170,7 @@ Gem::Specification.new do |s|
|
|
165
170
|
"spec/mongodb.yml",
|
166
171
|
"spec/mongodb_pairs.yml",
|
167
172
|
"spec/new_record_spec.rb",
|
173
|
+
"spec/polymorphic_collection_spec.rb",
|
168
174
|
"spec/references_many_spec.rb",
|
169
175
|
"spec/references_spec.rb",
|
170
176
|
"spec/root_spec.rb",
|
@@ -196,6 +202,7 @@ Gem::Specification.new do |s|
|
|
196
202
|
"spec/contexts/ids_spec.rb",
|
197
203
|
"spec/contexts/mongo_spec.rb",
|
198
204
|
"spec/contexts_spec.rb",
|
205
|
+
"spec/criteria/optional_spec.rb",
|
199
206
|
"spec/criteria_spec.rb",
|
200
207
|
"spec/cursor_spec.rb",
|
201
208
|
"spec/database_cleaner_spec.rb",
|
@@ -208,6 +215,7 @@ Gem::Specification.new do |s|
|
|
208
215
|
"spec/index_spec.rb",
|
209
216
|
"spec/matchers_spec.rb",
|
210
217
|
"spec/new_record_spec.rb",
|
218
|
+
"spec/polymorphic_collection_spec.rb",
|
211
219
|
"spec/references_many_spec.rb",
|
212
220
|
"spec/references_spec.rb",
|
213
221
|
"spec/root_spec.rb",
|
@@ -227,28 +235,34 @@ Gem::Specification.new do |s|
|
|
227
235
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
228
236
|
s.add_runtime_dependency(%q<activesupport>, [">= 3.0.0.beta.4"])
|
229
237
|
s.add_runtime_dependency(%q<activemodel>, [">= 3.0.0.beta.4"])
|
230
|
-
s.add_runtime_dependency(%q<mongo>, [">= 1.0.0"])
|
231
238
|
s.add_runtime_dependency(%q<bson>, [">= 1.0.0"])
|
232
239
|
s.add_runtime_dependency(%q<bson_ext>, [">= 1.0.0"])
|
233
|
-
s.
|
234
|
-
s.
|
240
|
+
s.add_runtime_dependency(%q<mongo>, [">= 1.0.0"])
|
241
|
+
s.add_runtime_dependency(%q<tzinfo>, [">= 0.3.22"])
|
242
|
+
s.add_development_dependency(%q<cucumber>, [">= 0.8.5"])
|
243
|
+
s.add_development_dependency(%q<jeweler>, [">= 1.4.0"])
|
244
|
+
s.add_development_dependency(%q<rspec>, [">= 2.0.0.beta.18"])
|
235
245
|
else
|
236
246
|
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta.4"])
|
237
247
|
s.add_dependency(%q<activemodel>, [">= 3.0.0.beta.4"])
|
238
|
-
s.add_dependency(%q<mongo>, [">= 1.0.0"])
|
239
248
|
s.add_dependency(%q<bson>, [">= 1.0.0"])
|
240
249
|
s.add_dependency(%q<bson_ext>, [">= 1.0.0"])
|
241
|
-
s.add_dependency(%q<
|
242
|
-
s.add_dependency(%q<
|
250
|
+
s.add_dependency(%q<mongo>, [">= 1.0.0"])
|
251
|
+
s.add_dependency(%q<tzinfo>, [">= 0.3.22"])
|
252
|
+
s.add_dependency(%q<cucumber>, [">= 0.8.5"])
|
253
|
+
s.add_dependency(%q<jeweler>, [">= 1.4.0"])
|
254
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.18"])
|
243
255
|
end
|
244
256
|
else
|
245
257
|
s.add_dependency(%q<activesupport>, [">= 3.0.0.beta.4"])
|
246
258
|
s.add_dependency(%q<activemodel>, [">= 3.0.0.beta.4"])
|
247
|
-
s.add_dependency(%q<mongo>, [">= 1.0.0"])
|
248
259
|
s.add_dependency(%q<bson>, [">= 1.0.0"])
|
249
260
|
s.add_dependency(%q<bson_ext>, [">= 1.0.0"])
|
250
|
-
s.add_dependency(%q<
|
251
|
-
s.add_dependency(%q<
|
261
|
+
s.add_dependency(%q<mongo>, [">= 1.0.0"])
|
262
|
+
s.add_dependency(%q<tzinfo>, [">= 0.3.22"])
|
263
|
+
s.add_dependency(%q<cucumber>, [">= 0.8.5"])
|
264
|
+
s.add_dependency(%q<jeweler>, [">= 1.4.0"])
|
265
|
+
s.add_dependency(%q<rspec>, [">= 2.0.0.beta.18"])
|
252
266
|
end
|
253
267
|
end
|
254
268
|
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mongoid::Criterion::Optional do
|
4
|
+
class OptionalTest
|
5
|
+
include MongoDoc::Document
|
6
|
+
end
|
7
|
+
|
8
|
+
let(:criteria) { Mongoid::Criteria.new(OptionalTest) }
|
9
|
+
let(:id) { BSON::ObjectID.new }
|
10
|
+
let(:string_id) { id.to_s }
|
11
|
+
|
12
|
+
describe "#id" do
|
13
|
+
it "converts a string id to bson ids" do
|
14
|
+
criteria.id(string_id)
|
15
|
+
BSON::ObjectID.should === criteria.selector[:_id]
|
16
|
+
end
|
17
|
+
|
18
|
+
it "converts many string ids to bson ids" do
|
19
|
+
criteria.id(string_id, string_id)
|
20
|
+
criteria.selector[:_id].should have_key('$in')
|
21
|
+
criteria.selector[:_id]['$in'].each do |selector_id|
|
22
|
+
BSON::ObjectID.should === selector_id
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe MongoDoc::PolymorphicCollection do
|
4
|
+
|
5
|
+
class BaseCollectionName
|
6
|
+
include MongoDoc::Document
|
7
|
+
|
8
|
+
attr_accessor :base
|
9
|
+
end
|
10
|
+
|
11
|
+
class SubCollectionName < BaseCollectionName
|
12
|
+
attr_accessor :sub
|
13
|
+
end
|
14
|
+
|
15
|
+
class OverriddenCollectionName < BaseCollectionName
|
16
|
+
collection_name :overridden
|
17
|
+
attr_accessor :over
|
18
|
+
end
|
19
|
+
|
20
|
+
class TwoSubCollectionName < OverriddenCollectionName
|
21
|
+
attr_accessor :two_sub
|
22
|
+
end
|
23
|
+
|
24
|
+
describe BaseCollectionName do
|
25
|
+
it "uses the default collection_name for base doc" do
|
26
|
+
BaseCollectionName.collection_name.should == BaseCollectionName.to_s.tableize.gsub('/', '.')
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe SubCollectionName do
|
31
|
+
it "uses the base's collection_name for the derived doc" do
|
32
|
+
SubCollectionName.collection_name.should == BaseCollectionName.to_s.tableize.gsub('/', '.')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe OverriddenCollectionName do
|
37
|
+
it "sets the collection_name to the overridden name" do
|
38
|
+
OverriddenCollectionName.collection_name.should == 'overridden'
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe TwoSubCollectionName do
|
43
|
+
it "climbs the inheritance chain looking for the collection name" do
|
44
|
+
TwoSubCollectionName.collection_name.should == 'overridden'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_doc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 6
|
9
|
-
-
|
10
|
-
version: 0.6.
|
9
|
+
- 12
|
10
|
+
version: 0.6.12
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Les Hill
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-23 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
type: :runtime
|
56
56
|
version_requirements: *id002
|
57
57
|
- !ruby/object:Gem::Dependency
|
58
|
-
name:
|
58
|
+
name: bson
|
59
59
|
prerelease: false
|
60
60
|
requirement: &id003 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
@@ -71,7 +71,7 @@ dependencies:
|
|
71
71
|
type: :runtime
|
72
72
|
version_requirements: *id003
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
|
-
name:
|
74
|
+
name: bson_ext
|
75
75
|
prerelease: false
|
76
76
|
requirement: &id004 !ruby/object:Gem::Requirement
|
77
77
|
none: false
|
@@ -87,7 +87,7 @@ dependencies:
|
|
87
87
|
type: :runtime
|
88
88
|
version_requirements: *id004
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
90
|
+
name: mongo
|
91
91
|
prerelease: false
|
92
92
|
requirement: &id005 !ruby/object:Gem::Requirement
|
93
93
|
none: false
|
@@ -103,22 +103,20 @@ dependencies:
|
|
103
103
|
type: :runtime
|
104
104
|
version_requirements: *id005
|
105
105
|
- !ruby/object:Gem::Dependency
|
106
|
-
name:
|
106
|
+
name: tzinfo
|
107
107
|
prerelease: false
|
108
108
|
requirement: &id006 !ruby/object:Gem::Requirement
|
109
109
|
none: false
|
110
110
|
requirements:
|
111
111
|
- - ">="
|
112
112
|
- !ruby/object:Gem::Version
|
113
|
-
hash:
|
113
|
+
hash: 63
|
114
114
|
segments:
|
115
|
-
- 2
|
116
115
|
- 0
|
117
|
-
-
|
118
|
-
-
|
119
|
-
|
120
|
-
|
121
|
-
type: :development
|
116
|
+
- 3
|
117
|
+
- 22
|
118
|
+
version: 0.3.22
|
119
|
+
type: :runtime
|
122
120
|
version_requirements: *id006
|
123
121
|
- !ruby/object:Gem::Dependency
|
124
122
|
name: cucumber
|
@@ -128,14 +126,48 @@ dependencies:
|
|
128
126
|
requirements:
|
129
127
|
- - ">="
|
130
128
|
- !ruby/object:Gem::Version
|
131
|
-
hash:
|
129
|
+
hash: 53
|
132
130
|
segments:
|
133
131
|
- 0
|
134
132
|
- 8
|
135
|
-
-
|
136
|
-
version: 0.8.
|
133
|
+
- 5
|
134
|
+
version: 0.8.5
|
137
135
|
type: :development
|
138
136
|
version_requirements: *id007
|
137
|
+
- !ruby/object:Gem::Dependency
|
138
|
+
name: jeweler
|
139
|
+
prerelease: false
|
140
|
+
requirement: &id008 !ruby/object:Gem::Requirement
|
141
|
+
none: false
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
hash: 7
|
146
|
+
segments:
|
147
|
+
- 1
|
148
|
+
- 4
|
149
|
+
- 0
|
150
|
+
version: 1.4.0
|
151
|
+
type: :development
|
152
|
+
version_requirements: *id008
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: rspec
|
155
|
+
prerelease: false
|
156
|
+
requirement: &id009 !ruby/object:Gem::Requirement
|
157
|
+
none: false
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
hash: 62196423
|
162
|
+
segments:
|
163
|
+
- 2
|
164
|
+
- 0
|
165
|
+
- 0
|
166
|
+
- beta
|
167
|
+
- 18
|
168
|
+
version: 2.0.0.beta.18
|
169
|
+
type: :development
|
170
|
+
version_requirements: *id009
|
139
171
|
description: ODM for MongoDB
|
140
172
|
email: leshill@gmail.com
|
141
173
|
executables: []
|
@@ -152,6 +184,7 @@ files:
|
|
152
184
|
- .rvmrc
|
153
185
|
- .watchr
|
154
186
|
- Gemfile
|
187
|
+
- Gemfile.lock
|
155
188
|
- HISTORY.md
|
156
189
|
- LICENSE
|
157
190
|
- README.textile
|
@@ -167,6 +200,7 @@ files:
|
|
167
200
|
- features/mongodoc_base.feature
|
168
201
|
- features/new_record.feature
|
169
202
|
- features/partial_updates.feature
|
203
|
+
- features/polymorphic_collections.feature
|
170
204
|
- features/references.feature
|
171
205
|
- features/removing_documents.feature
|
172
206
|
- features/saving_an_object.feature
|
@@ -228,6 +262,7 @@ files:
|
|
228
262
|
- lib/mongo_doc/finders.rb
|
229
263
|
- lib/mongo_doc/index.rb
|
230
264
|
- lib/mongo_doc/matchers.rb
|
265
|
+
- lib/mongo_doc/polymorphic_collection.rb
|
231
266
|
- lib/mongo_doc/railtie.rb
|
232
267
|
- lib/mongo_doc/railties/config.rb
|
233
268
|
- lib/mongo_doc/railties/db_prepare.task
|
@@ -239,6 +274,7 @@ files:
|
|
239
274
|
- lib/mongo_doc/validations.rb
|
240
275
|
- lib/mongo_doc/validations/validates_embedded.rb
|
241
276
|
- lib/mongoid/contexts/enumerable.rb
|
277
|
+
- lib/mongoid/contexts/id_conversion.rb
|
242
278
|
- lib/mongoid/contexts/paging.rb
|
243
279
|
- lib/mongoid/criteria.rb
|
244
280
|
- lib/mongoid/criterion/complex.rb
|
@@ -280,6 +316,7 @@ files:
|
|
280
316
|
- spec/contexts/ids_spec.rb
|
281
317
|
- spec/contexts/mongo_spec.rb
|
282
318
|
- spec/contexts_spec.rb
|
319
|
+
- spec/criteria/optional_spec.rb
|
283
320
|
- spec/criteria_spec.rb
|
284
321
|
- spec/cursor_spec.rb
|
285
322
|
- spec/database_cleaner_spec.rb
|
@@ -294,6 +331,7 @@ files:
|
|
294
331
|
- spec/mongodb.yml
|
295
332
|
- spec/mongodb_pairs.yml
|
296
333
|
- spec/new_record_spec.rb
|
334
|
+
- spec/polymorphic_collection_spec.rb
|
297
335
|
- spec/references_many_spec.rb
|
298
336
|
- spec/references_spec.rb
|
299
337
|
- spec/root_spec.rb
|
@@ -353,6 +391,7 @@ test_files:
|
|
353
391
|
- spec/contexts/ids_spec.rb
|
354
392
|
- spec/contexts/mongo_spec.rb
|
355
393
|
- spec/contexts_spec.rb
|
394
|
+
- spec/criteria/optional_spec.rb
|
356
395
|
- spec/criteria_spec.rb
|
357
396
|
- spec/cursor_spec.rb
|
358
397
|
- spec/database_cleaner_spec.rb
|
@@ -365,6 +404,7 @@ test_files:
|
|
365
404
|
- spec/index_spec.rb
|
366
405
|
- spec/matchers_spec.rb
|
367
406
|
- spec/new_record_spec.rb
|
407
|
+
- spec/polymorphic_collection_spec.rb
|
368
408
|
- spec/references_many_spec.rb
|
369
409
|
- spec/references_spec.rb
|
370
410
|
- spec/root_spec.rb
|