mongomatic 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongomatic.rb +3 -3
- data/lib/mongomatic/base.rb +6 -0
- data/test/test_mongomatic.rb +28 -0
- metadata +7 -16
data/lib/mongomatic.rb
CHANGED
data/lib/mongomatic/base.rb
CHANGED
@@ -33,6 +33,12 @@ module Mongomatic
|
|
33
33
|
Mongomatic::Cursor.new(self, collection.find(query, opts))
|
34
34
|
end
|
35
35
|
|
36
|
+
def find_one(query = nil, opts = {})
|
37
|
+
query = BSON::ObjectID(query) if query.is_a? String
|
38
|
+
return nil unless doc = self.collection.find_one(query, opts)
|
39
|
+
self.new(doc)
|
40
|
+
end
|
41
|
+
|
36
42
|
def all
|
37
43
|
find
|
38
44
|
end
|
data/test/test_mongomatic.rb
CHANGED
@@ -1,6 +1,34 @@
|
|
1
1
|
require 'helper'
|
2
2
|
|
3
3
|
class TestMongomatic < Test::Unit::TestCase
|
4
|
+
should "find one with a query" do
|
5
|
+
Person.collection.remove
|
6
|
+
p1 = Person.new(:name => "Jordan")
|
7
|
+
p1.insert
|
8
|
+
|
9
|
+
assert_equal p1, Person.find_one(:name => "Jordan")
|
10
|
+
end
|
11
|
+
should "find one with an instance of BSON::ObjectID" do
|
12
|
+
Person.collection.remove
|
13
|
+
p1 = Person.new(:name => "Jordan")
|
14
|
+
p1.insert
|
15
|
+
|
16
|
+
assert_equal p1, Person.find_one(p1['_id'])
|
17
|
+
end
|
18
|
+
should "find one with a string" do
|
19
|
+
Person.collection.remove
|
20
|
+
p1 = Person.new(:name => "Jordan")
|
21
|
+
p1.insert
|
22
|
+
|
23
|
+
assert_equal p1, Person.find_one(p1['_id'].to_s)
|
24
|
+
end
|
25
|
+
should "return an instance of class when finding one" do
|
26
|
+
Person.collection.remove
|
27
|
+
p1 = Person.new(:name => "Jordan")
|
28
|
+
p1.insert
|
29
|
+
|
30
|
+
assert_equal Person, Person.find_one(:name => "Jordan").class
|
31
|
+
end
|
4
32
|
should "work with enumerable methods" do
|
5
33
|
Person.collection.remove
|
6
34
|
p1 = Person.new(:name => "Ben1", :birth_year => 1984, :created_at => Time.now.utc, :admin => true)
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 9
|
9
|
+
version: 0.0.9
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Ben Myles
|
@@ -14,14 +14,13 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-08-
|
17
|
+
date: 2010-08-11 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: shoulda
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
-
none: false
|
25
24
|
requirements:
|
26
25
|
- - ">="
|
27
26
|
- !ruby/object:Gem::Version
|
@@ -36,9 +35,8 @@ dependencies:
|
|
36
35
|
name: bson
|
37
36
|
prerelease: false
|
38
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
-
none: false
|
40
38
|
requirements:
|
41
|
-
- - "
|
39
|
+
- - ">="
|
42
40
|
- !ruby/object:Gem::Version
|
43
41
|
segments:
|
44
42
|
- 1
|
@@ -51,9 +49,8 @@ dependencies:
|
|
51
49
|
name: bson_ext
|
52
50
|
prerelease: false
|
53
51
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
|
-
none: false
|
55
52
|
requirements:
|
56
|
-
- - "
|
53
|
+
- - ">="
|
57
54
|
- !ruby/object:Gem::Version
|
58
55
|
segments:
|
59
56
|
- 1
|
@@ -66,9 +63,8 @@ dependencies:
|
|
66
63
|
name: mongo
|
67
64
|
prerelease: false
|
68
65
|
requirement: &id004 !ruby/object:Gem::Requirement
|
69
|
-
none: false
|
70
66
|
requirements:
|
71
|
-
- - "
|
67
|
+
- - ">="
|
72
68
|
- !ruby/object:Gem::Version
|
73
69
|
segments:
|
74
70
|
- 1
|
@@ -81,7 +77,6 @@ dependencies:
|
|
81
77
|
name: activesupport
|
82
78
|
prerelease: false
|
83
79
|
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
-
none: false
|
85
80
|
requirements:
|
86
81
|
- - ">="
|
87
82
|
- !ruby/object:Gem::Version
|
@@ -130,8 +125,6 @@ files:
|
|
130
125
|
- lib/mongomatic/validatable/validations/validation_base.rb
|
131
126
|
- LICENSE
|
132
127
|
- README.rdoc
|
133
|
-
- test/helper.rb
|
134
|
-
- test/test_mongomatic.rb
|
135
128
|
has_rdoc: true
|
136
129
|
homepage: http://github.com/benmyles/mongomatic
|
137
130
|
licenses: []
|
@@ -142,7 +135,6 @@ rdoc_options:
|
|
142
135
|
require_paths:
|
143
136
|
- lib
|
144
137
|
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
138
|
requirements:
|
147
139
|
- - ">="
|
148
140
|
- !ruby/object:Gem::Version
|
@@ -150,7 +142,6 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
150
142
|
- 0
|
151
143
|
version: "0"
|
152
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
145
|
requirements:
|
155
146
|
- - ">="
|
156
147
|
- !ruby/object:Gem::Version
|
@@ -160,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
160
151
|
requirements: []
|
161
152
|
|
162
153
|
rubyforge_project:
|
163
|
-
rubygems_version: 1.3.
|
154
|
+
rubygems_version: 1.3.6
|
164
155
|
signing_key:
|
165
156
|
specification_version: 3
|
166
157
|
summary: Mongomatic is a simple Ruby object mapper for Mongo
|