mongoid 0.12.0 → 1.0.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.
- data/HISTORY +12 -0
- data/README.rdoc +56 -0
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/lib/mongoid.rb +6 -2
- data/lib/mongoid/associations.rb +18 -9
- data/lib/mongoid/attributes.rb +41 -2
- data/lib/mongoid/callbacks.rb +23 -0
- data/lib/mongoid/components.rb +21 -0
- data/lib/mongoid/criteria.rb +2 -1
- data/lib/mongoid/document.rb +32 -112
- data/lib/mongoid/extensions/string/inflections.rb +8 -0
- data/lib/mongoid/fields.rb +58 -0
- data/lib/mongoid/{field.rb → fields/field.rb} +0 -0
- data/lib/mongoid/indexes.rb +30 -0
- data/mongoid.gemspec +18 -8
- data/spec/integration/mongoid/document_spec.rb +15 -0
- data/spec/unit/mongoid/attributes_spec.rb +53 -11
- data/spec/unit/mongoid/callbacks_spec.rb +55 -0
- data/spec/unit/mongoid/commands_spec.rb +0 -1
- data/spec/unit/mongoid/document_spec.rb +0 -186
- data/spec/unit/mongoid/extensions/string/inflections_spec.rb +41 -0
- data/spec/unit/mongoid/fields_spec.rb +148 -0
- data/spec/unit/mongoid/indexes_spec.rb +93 -0
- metadata +16 -6
- data/README.textile +0 -64
@@ -109,4 +109,45 @@ describe Mongoid::Extensions::String::Inflections do
|
|
109
109
|
end
|
110
110
|
|
111
111
|
end
|
112
|
+
|
113
|
+
describe "#reader" do
|
114
|
+
|
115
|
+
context "when string is a reader" do
|
116
|
+
|
117
|
+
it "returns self" do
|
118
|
+
"attribute".reader.should == "attribute"
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when string is a writer" do
|
124
|
+
|
125
|
+
it "returns the reader" do
|
126
|
+
"attribute=".reader.should == "attribute"
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
describe "#writer?" do
|
134
|
+
|
135
|
+
context "when string is a reader" do
|
136
|
+
|
137
|
+
it "returns false" do
|
138
|
+
"attribute".writer?.should be_false
|
139
|
+
end
|
140
|
+
|
141
|
+
end
|
142
|
+
|
143
|
+
context "when string is a writer" do
|
144
|
+
|
145
|
+
it "returns true" do
|
146
|
+
"attribute=".writer?.should be_true
|
147
|
+
end
|
148
|
+
|
149
|
+
end
|
150
|
+
|
151
|
+
end
|
152
|
+
|
112
153
|
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Fields do
|
4
|
+
|
5
|
+
describe ".defaults" do
|
6
|
+
|
7
|
+
it "returns a hash of all the default values" do
|
8
|
+
Game.defaults.should == { "high_score" => 500, "score" => 0 }
|
9
|
+
end
|
10
|
+
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#defaults" do
|
14
|
+
|
15
|
+
context "on parent classes" do
|
16
|
+
|
17
|
+
before do
|
18
|
+
@shape = Shape.new
|
19
|
+
end
|
20
|
+
|
21
|
+
it "does not return subclass defaults" do
|
22
|
+
@shape.defaults.should == { "x" => 0, "y" => 0 }
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
context "on subclasses" do
|
28
|
+
|
29
|
+
before do
|
30
|
+
@circle = Circle.new
|
31
|
+
end
|
32
|
+
|
33
|
+
it "has the parent and child defaults" do
|
34
|
+
@circle.defaults.should == { "x" => 0, "y" => 0, "radius" => 0 }
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
describe ".field" do
|
42
|
+
|
43
|
+
context "with no options" do
|
44
|
+
|
45
|
+
before do
|
46
|
+
Person.field(:testing)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "adds a reader for the fields defined" do
|
50
|
+
@person = Person.new(:testing => "Test")
|
51
|
+
@person.testing.should == "Test"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "adds a writer for the fields defined" do
|
55
|
+
@person = Person.new(:testing => "Test")
|
56
|
+
@person.testing = "Testy"
|
57
|
+
@person.testing.should == "Testy"
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
context "when type is an object" do
|
63
|
+
|
64
|
+
before do
|
65
|
+
@person = Person.new
|
66
|
+
@drink = MixedDrink.new(:name => "Jack and Coke")
|
67
|
+
@person.mixed_drink = @drink
|
68
|
+
end
|
69
|
+
|
70
|
+
it "allows proper access to the object" do
|
71
|
+
@person.mixed_drink.should == @drink
|
72
|
+
@person.attributes[:mixed_drink].except(:_id).except(:_type).should ==
|
73
|
+
{ "name" => "Jack and Coke" }
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when type is a boolean" do
|
79
|
+
|
80
|
+
before do
|
81
|
+
@person = Person.new(:terms => true)
|
82
|
+
end
|
83
|
+
|
84
|
+
it "adds an accessor method with a question mark" do
|
85
|
+
@person.terms?.should be_true
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
context "when as is specified" do
|
91
|
+
|
92
|
+
before do
|
93
|
+
Person.field :aliased, :as => :alias, :type => Boolean
|
94
|
+
@person = Person.new(:alias => true)
|
95
|
+
end
|
96
|
+
|
97
|
+
it "uses the alias to write the attribute" do
|
98
|
+
@person.expects(:write_attribute).with(:aliased, true)
|
99
|
+
@person.alias = true
|
100
|
+
end
|
101
|
+
|
102
|
+
it "uses the alias to read the attribute" do
|
103
|
+
@person.expects(:read_attribute).with(:aliased)
|
104
|
+
@person.alias
|
105
|
+
end
|
106
|
+
|
107
|
+
it "uses the alias for the query method" do
|
108
|
+
@person.expects(:read_attribute).with(:aliased)
|
109
|
+
@person.alias?
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
|
116
|
+
describe "#fields" do
|
117
|
+
|
118
|
+
context "on parent classes" do
|
119
|
+
|
120
|
+
before do
|
121
|
+
@shape = Shape.new
|
122
|
+
end
|
123
|
+
|
124
|
+
it "does not return subclass fields" do
|
125
|
+
@shape.fields.keys.should include("x")
|
126
|
+
@shape.fields.keys.should include("y")
|
127
|
+
@shape.fields.keys.should_not include("radius")
|
128
|
+
end
|
129
|
+
|
130
|
+
end
|
131
|
+
|
132
|
+
context "on subclasses" do
|
133
|
+
|
134
|
+
before do
|
135
|
+
@circle = Circle.new
|
136
|
+
end
|
137
|
+
|
138
|
+
it "has the parent and child fields" do
|
139
|
+
@circle.fields.keys.should include("x")
|
140
|
+
@circle.fields.keys.should include("y")
|
141
|
+
@circle.fields.keys.should include("radius")
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Mongoid::Indexes do
|
4
|
+
|
5
|
+
describe ".included" do
|
6
|
+
|
7
|
+
before do
|
8
|
+
@class = Class.new do
|
9
|
+
include Mongoid::Indexes
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
it "adds an indexed accessor" do
|
14
|
+
@class.should respond_to(:indexed)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "defaults indexed to false" do
|
18
|
+
@class.indexed.should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
describe ".add_indexes" do
|
24
|
+
|
25
|
+
before do
|
26
|
+
@collection = mock
|
27
|
+
end
|
28
|
+
|
29
|
+
context "when indexes have not been added" do
|
30
|
+
|
31
|
+
before do
|
32
|
+
@class = Class.new do
|
33
|
+
include Mongoid::Indexes
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
it "adds the _type index" do
|
38
|
+
@class.expects(:_collection).returns(@collection)
|
39
|
+
@collection.expects(:create_index).with(:_type, false)
|
40
|
+
@class.add_indexes
|
41
|
+
@class.indexed.should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "when indexes have been added" do
|
47
|
+
|
48
|
+
before do
|
49
|
+
@class = Class.new do
|
50
|
+
include Mongoid::Indexes
|
51
|
+
end
|
52
|
+
@class.indexed = true
|
53
|
+
end
|
54
|
+
|
55
|
+
it "ignores the request" do
|
56
|
+
@class.add_indexes
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
describe ".index" do
|
64
|
+
|
65
|
+
before do
|
66
|
+
@collection = mock
|
67
|
+
@class = Class.new do
|
68
|
+
include Mongoid::Indexes
|
69
|
+
end
|
70
|
+
@class.expects(:collection).returns(@collection)
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when unique" do
|
74
|
+
|
75
|
+
it "creates a unique index on the collection" do
|
76
|
+
@collection.expects(:create_index).with(:name, true)
|
77
|
+
@class.index(:name, :unique => true)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when not unique" do
|
83
|
+
|
84
|
+
it "creates an index on the collection" do
|
85
|
+
@collection.expects(:create_index).with(:name, false)
|
86
|
+
@class.index(:name)
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
93
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Durran Jordan
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-01-
|
12
|
+
date: 2010-01-09 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -40,7 +40,7 @@ dependencies:
|
|
40
40
|
requirements:
|
41
41
|
- - ">="
|
42
42
|
- !ruby/object:Gem::Version
|
43
|
-
version:
|
43
|
+
version: 2.0.0
|
44
44
|
version:
|
45
45
|
- !ruby/object:Gem::Dependency
|
46
46
|
name: leshill-will_paginate
|
@@ -79,13 +79,13 @@ executables: []
|
|
79
79
|
extensions: []
|
80
80
|
|
81
81
|
extra_rdoc_files:
|
82
|
-
- README.
|
82
|
+
- README.rdoc
|
83
83
|
files:
|
84
84
|
- .gitignore
|
85
85
|
- .watchr
|
86
86
|
- HISTORY
|
87
87
|
- MIT_LICENSE
|
88
|
-
- README.
|
88
|
+
- README.rdoc
|
89
89
|
- Rakefile
|
90
90
|
- VERSION
|
91
91
|
- lib/mongoid.rb
|
@@ -99,6 +99,7 @@ files:
|
|
99
99
|
- lib/mongoid/associations/options.rb
|
100
100
|
- lib/mongoid/associations/proxy.rb
|
101
101
|
- lib/mongoid/attributes.rb
|
102
|
+
- lib/mongoid/callbacks.rb
|
102
103
|
- lib/mongoid/commands.rb
|
103
104
|
- lib/mongoid/commands/create.rb
|
104
105
|
- lib/mongoid/commands/delete.rb
|
@@ -108,6 +109,7 @@ files:
|
|
108
109
|
- lib/mongoid/commands/destroy_all.rb
|
109
110
|
- lib/mongoid/commands/save.rb
|
110
111
|
- lib/mongoid/complex_criterion.rb
|
112
|
+
- lib/mongoid/components.rb
|
111
113
|
- lib/mongoid/config.rb
|
112
114
|
- lib/mongoid/criteria.rb
|
113
115
|
- lib/mongoid/document.rb
|
@@ -132,8 +134,10 @@ files:
|
|
132
134
|
- lib/mongoid/extensions/string/inflections.rb
|
133
135
|
- lib/mongoid/extensions/symbol/inflections.rb
|
134
136
|
- lib/mongoid/extensions/time/conversions.rb
|
135
|
-
- lib/mongoid/
|
137
|
+
- lib/mongoid/fields.rb
|
138
|
+
- lib/mongoid/fields/field.rb
|
136
139
|
- lib/mongoid/finders.rb
|
140
|
+
- lib/mongoid/indexes.rb
|
137
141
|
- lib/mongoid/memoization.rb
|
138
142
|
- lib/mongoid/timestamps.rb
|
139
143
|
- lib/mongoid/versioning.rb
|
@@ -156,6 +160,7 @@ files:
|
|
156
160
|
- spec/unit/mongoid/associations/options_spec.rb
|
157
161
|
- spec/unit/mongoid/associations_spec.rb
|
158
162
|
- spec/unit/mongoid/attributes_spec.rb
|
163
|
+
- spec/unit/mongoid/callbacks_spec.rb
|
159
164
|
- spec/unit/mongoid/commands/create_spec.rb
|
160
165
|
- spec/unit/mongoid/commands/delete_all_spec.rb
|
161
166
|
- spec/unit/mongoid/commands/delete_spec.rb
|
@@ -187,7 +192,9 @@ files:
|
|
187
192
|
- spec/unit/mongoid/extensions/symbol/inflections_spec.rb
|
188
193
|
- spec/unit/mongoid/extensions/time/conversions_spec.rb
|
189
194
|
- spec/unit/mongoid/field_spec.rb
|
195
|
+
- spec/unit/mongoid/fields_spec.rb
|
190
196
|
- spec/unit/mongoid/finders_spec.rb
|
197
|
+
- spec/unit/mongoid/indexes_spec.rb
|
191
198
|
- spec/unit/mongoid/memoization_spec.rb
|
192
199
|
- spec/unit/mongoid/timestamps_spec.rb
|
193
200
|
- spec/unit/mongoid/versioning_spec.rb
|
@@ -237,6 +244,7 @@ test_files:
|
|
237
244
|
- spec/unit/mongoid/associations/options_spec.rb
|
238
245
|
- spec/unit/mongoid/associations_spec.rb
|
239
246
|
- spec/unit/mongoid/attributes_spec.rb
|
247
|
+
- spec/unit/mongoid/callbacks_spec.rb
|
240
248
|
- spec/unit/mongoid/commands/create_spec.rb
|
241
249
|
- spec/unit/mongoid/commands/delete_all_spec.rb
|
242
250
|
- spec/unit/mongoid/commands/delete_spec.rb
|
@@ -268,7 +276,9 @@ test_files:
|
|
268
276
|
- spec/unit/mongoid/extensions/symbol/inflections_spec.rb
|
269
277
|
- spec/unit/mongoid/extensions/time/conversions_spec.rb
|
270
278
|
- spec/unit/mongoid/field_spec.rb
|
279
|
+
- spec/unit/mongoid/fields_spec.rb
|
271
280
|
- spec/unit/mongoid/finders_spec.rb
|
281
|
+
- spec/unit/mongoid/indexes_spec.rb
|
272
282
|
- spec/unit/mongoid/memoization_spec.rb
|
273
283
|
- spec/unit/mongoid/timestamps_spec.rb
|
274
284
|
- spec/unit/mongoid/versioning_spec.rb
|
data/README.textile
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
<h2>Overview</h2>
|
2
|
-
|
3
|
-
<h3>About Mongoid</h3>
|
4
|
-
|
5
|
-
<p>
|
6
|
-
Mongoid is an ODM (Object-Document-Mapper) framework for MongoDB in Ruby.
|
7
|
-
</p>
|
8
|
-
|
9
|
-
<h3>Project Tracking</h3>
|
10
|
-
|
11
|
-
<a href="http://www.pivotaltracker.com/projects/27482">Mongoid on Pivotal Tracker</a>
|
12
|
-
<a href="http://groups.google.com/group/mongoid">Mongoid Google Group</a>
|
13
|
-
<a href="http://mongoid.org:4444/">Mongoid on CI Joe</a>
|
14
|
-
<a href="http://mongoid.org">Mongoid Website and Documentation</a>
|
15
|
-
|
16
|
-
<h3>Compatibility</h3>
|
17
|
-
|
18
|
-
<p>
|
19
|
-
Mongoid is developed against Ruby 1.8.6, 1.8.7, 1.9.1, 1.9.2
|
20
|
-
</p>
|
21
|
-
|
22
|
-
<p>
|
23
|
-
Note API changes will be frequent until 1.0, releases will be frequent, and
|
24
|
-
backwards compatibility will not be supported. Do not expect the gem to be of full
|
25
|
-
production quality until that point. However, once 1.0 is released I will be providing
|
26
|
-
backwards compatibility through each minor version upgrade, as well as detailed
|
27
|
-
release notes and documentation with each release.
|
28
|
-
</p>
|
29
|
-
|
30
|
-
<h2>Documentation</h2>
|
31
|
-
|
32
|
-
<p>Please see the new Mongoid website for up-to-date documentation: <a href="http://mongoid.org">mongoid.org</a></p>
|
33
|
-
|
34
|
-
<h2>License</h2>
|
35
|
-
|
36
|
-
<p>
|
37
|
-
Copyright (c) 2009 Durran Jordan
|
38
|
-
</p>
|
39
|
-
<p>
|
40
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
41
|
-
a copy of this software and associated documentation files (the
|
42
|
-
"Software"), to deal in the Software without restriction, including
|
43
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
44
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
45
|
-
permit persons to whom the Software is furnished to do so, subject to
|
46
|
-
the following conditions:
|
47
|
-
</p>
|
48
|
-
<p>
|
49
|
-
The above copyright notice and this permission notice shall be
|
50
|
-
included in all copies or substantial portions of the Software.
|
51
|
-
</p>
|
52
|
-
<p>
|
53
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
54
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
55
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
56
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
57
|
-
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
58
|
-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
59
|
-
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
60
|
-
</p>
|
61
|
-
|
62
|
-
<h2>Credits</h2>
|
63
|
-
|
64
|
-
Durran Jordan: durran at gmail dot com
|