mongoid 0.8.10 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -42,4 +42,39 @@ describe Mongoid::Extensions::String::Inflections do
42
42
 
43
43
  end
44
44
 
45
+ describe "invert" do
46
+
47
+ context "when asc" do
48
+
49
+ it "returns desc" do
50
+ "asc".invert.should == "desc"
51
+ end
52
+
53
+ end
54
+
55
+ context "when ascending" do
56
+
57
+ it "returns descending" do
58
+ "ascending".invert.should == "descending"
59
+ end
60
+
61
+ end
62
+
63
+ context "when desc" do
64
+
65
+ it "returns asc" do
66
+ "desc".invert.should == "asc"
67
+ end
68
+
69
+ end
70
+
71
+ context "when descending" do
72
+
73
+ it "returns ascending" do
74
+ "descending".invert.should == "ascending"
75
+ end
76
+
77
+ end
78
+
79
+ end
45
80
  end
@@ -42,4 +42,40 @@ describe Mongoid::Extensions::Symbol::Inflections do
42
42
 
43
43
  end
44
44
 
45
+ describe "invert" do
46
+
47
+ context "when :asc" do
48
+
49
+ it "returns :desc" do
50
+ :asc.invert.should == :desc
51
+ end
52
+
53
+ end
54
+
55
+ context "when :ascending" do
56
+
57
+ it "returns :descending" do
58
+ :ascending.invert.should == :descending
59
+ end
60
+
61
+ end
62
+
63
+ context "when :desc" do
64
+
65
+ it "returns :asc" do
66
+ :desc.invert.should == :asc
67
+ end
68
+
69
+ end
70
+
71
+ context "when :descending" do
72
+
73
+ it "returns :ascending" do
74
+ :descending.invert.should == :ascending
75
+ end
76
+
77
+ end
78
+
79
+ end
80
+
45
81
  end
@@ -17,16 +17,14 @@ describe Mongoid::Finders do
17
17
  describe ".all" do
18
18
 
19
19
  before do
20
- @cursor = stub(:count => 100)
21
- @people = []
20
+ @conditions = { :conditions => { :test => "Test" } }
22
21
  end
23
22
 
24
23
  context "when a selector is provided" do
25
24
 
26
25
  it "finds from the collection and instantiate objects for each returned" do
27
- @collection.expects(:find).with({ :test => "Test" }, {}).returns(@cursor)
28
- @cursor.expects(:collect).returns(@people)
29
- Person.all(:conditions => {:test => "Test"})
26
+ Mongoid::Criteria.expects(:translate).with(Person, @conditions)
27
+ Person.all(@conditions)
30
28
  end
31
29
 
32
30
  end
@@ -34,8 +32,7 @@ describe Mongoid::Finders do
34
32
  context "when a selector is not provided" do
35
33
 
36
34
  it "finds from the collection and instantiate objects for each returned" do
37
- @collection.expects(:find).with(nil, {}).returns(@cursor)
38
- @cursor.expects(:collect).returns(@people)
35
+ Mongoid::Criteria.expects(:translate).with(Person, nil)
39
36
  Person.all
40
37
  end
41
38
 
@@ -46,21 +43,21 @@ describe Mongoid::Finders do
46
43
  describe ".count" do
47
44
 
48
45
  before do
49
- @params = { :conditions => { :title => "Sir" } }
46
+ @conditions = { :conditions => { :title => "Sir" } }
50
47
  @criteria = mock
51
48
  end
52
49
 
53
50
  it "delegates to the criteria api" do
54
- Mongoid::Criteria.expects(:translate).with(@params).returns(@criteria)
55
- @criteria.expects(:count).with(Person).returns(10)
56
- Person.count(@params).should == 10
51
+ Mongoid::Criteria.expects(:translate).with(Person, @conditions).returns(@criteria)
52
+ @criteria.expects(:count).returns(10)
53
+ Person.count(@conditions).should == 10
57
54
  end
58
55
 
59
56
  context "when no options provided" do
60
57
 
61
58
  it "adds in the default parameters" do
62
- Mongoid::Criteria.expects(:translate).with(nil).returns(@criteria)
63
- @criteria.expects(:count).with(Person).returns(10)
59
+ Mongoid::Criteria.expects(:translate).with(Person, nil).returns(@criteria)
60
+ @criteria.expects(:count).returns(10)
64
61
  Person.count.should == 10
65
62
  end
66
63
 
@@ -82,8 +79,7 @@ describe Mongoid::Finders do
82
79
  end
83
80
 
84
81
  it "delegates to criteria" do
85
- Mongoid::Criteria.expects(:translate).with(@id.to_s).returns(@criteria)
86
- @criteria.expects(:execute).with(Person).returns(@attributes)
82
+ Mongoid::Criteria.expects(:translate).with(Person, @id.to_s).returns(Person.new)
87
83
  Person.find(@id.to_s)
88
84
  end
89
85
 
@@ -92,8 +88,8 @@ describe Mongoid::Finders do
92
88
  context "when finding first" do
93
89
 
94
90
  it "delegates to criteria" do
95
- Mongoid::Criteria.expects(:translate).with(:first, :conditions => { :test => "Test" }).returns(@criteria)
96
- @criteria.expects(:execute).with(Person).returns(@attributes)
91
+ Mongoid::Criteria.expects(:translate).with(Person, :conditions => { :test => "Test" }).returns(@criteria)
92
+ @criteria.expects(:one).returns(@attributes)
97
93
  Person.find(:first, :conditions => { :test => "Test" })
98
94
  end
99
95
 
@@ -102,14 +98,12 @@ describe Mongoid::Finders do
102
98
  context "when finding all" do
103
99
 
104
100
  before do
105
- @cursor = stub(:count => 100)
106
- @people = []
101
+ @conditions = { :conditions => { :test => "Test" } }
107
102
  end
108
103
 
109
104
  it "delegates to find_all" do
110
- @collection.expects(:find).with({:test => "Test"}, {}).returns(@cursor)
111
- @cursor.expects(:collect).returns(@people)
112
- Person.find(:all, :conditions => { :test => "Test" })
105
+ Mongoid::Criteria.expects(:translate).with(Person, @conditions).returns(@criteria)
106
+ Person.find(:all, @conditions)
113
107
  end
114
108
 
115
109
  end
@@ -117,14 +111,12 @@ describe Mongoid::Finders do
117
111
  context "when sorting" do
118
112
 
119
113
  before do
120
- @cursor = stub(:count => 50)
121
- @people = []
114
+ @conditions = { :conditions => { :test => "Test" }, :sort => { :test => -1 } }
122
115
  end
123
116
 
124
117
  it "adds the sort parameters for the collection call" do
125
- @collection.expects(:find).with({ :test => "Test" }, { :sort => { :test => -1 }}).returns(@cursor)
126
- @cursor.expects(:collect).returns(@people)
127
- Person.find(:all, :conditions => { :test => "Test" }, :sort => { :test => -1 })
118
+ Mongoid::Criteria.expects(:translate).with(Person, @conditions).returns(@criteria)
119
+ Person.find(:all, @conditions)
128
120
  end
129
121
  end
130
122
 
@@ -133,11 +125,12 @@ describe Mongoid::Finders do
133
125
  describe ".find_by_id" do
134
126
 
135
127
  before do
136
- @criteria = stub_everything
128
+ @criteria = mock
137
129
  end
138
130
 
139
131
  it "delegates to find with an id parameter" do
140
- Mongoid::Criteria.expects(:translate).with(:first, :conditions => { "_id" => "1" }).returns(@criteria)
132
+ Mongoid::Criteria.expects(:translate).with(Person, :conditions => { "_id" => "1" }).returns(@criteria)
133
+ @criteria.expects(:one).returns(Person.new)
141
134
  Person.find_by_id("1")
142
135
  end
143
136
 
@@ -146,14 +139,16 @@ describe Mongoid::Finders do
146
139
  describe ".first" do
147
140
 
148
141
  before do
149
- @attributes = { "age" => 100 }
142
+ @criteria = mock
143
+ @conditions = { :conditions => { :test => "Test" } }
150
144
  end
151
145
 
152
146
  context "when a selector is provided" do
153
147
 
154
148
  it "finds the first document from the collection and instantiates it" do
155
- @collection.expects(:find_one).with({ :test => "Test" }, {}).returns(@attributes)
156
- Person.first(:conditions => {:test => "Test"}).attributes.except(:_id).should == @attributes
149
+ Mongoid::Criteria.expects(:translate).with(Person, @conditions).returns(@criteria)
150
+ @criteria.expects(:one)
151
+ Person.first(@conditions)
157
152
  end
158
153
 
159
154
  end
@@ -161,8 +156,9 @@ describe Mongoid::Finders do
161
156
  context "when a selector is not provided" do
162
157
 
163
158
  it "finds the first document from the collection and instantiates it" do
164
- @collection.expects(:find_one).with(nil, {}).returns(@attributes)
165
- Person.first.attributes.except(:_id).should == @attributes
159
+ Mongoid::Criteria.expects(:translate).with(Person, nil).returns(@criteria)
160
+ @criteria.expects(:one)
161
+ Person.first
166
162
  end
167
163
 
168
164
  end
@@ -172,12 +168,13 @@ describe Mongoid::Finders do
172
168
  describe ".last" do
173
169
 
174
170
  before do
175
- @attributes = { :_id => 1, :title => "Sir" }
176
- @collection.expects(:find_one).with({}, :sort => [[:_id, :desc]]).returns(@attributes)
171
+ @criteria = mock
177
172
  end
178
173
 
179
174
  it "finds the last document by the id" do
180
- Person.last.should == Person.instantiate(@attributes)
175
+ Mongoid::Criteria.expects(:translate).with(Person, nil).returns(@criteria)
176
+ @criteria.expects(:last)
177
+ Person.last
181
178
  end
182
179
 
183
180
  end
@@ -193,8 +190,8 @@ describe Mongoid::Finders do
193
190
  end
194
191
 
195
192
  it "executes the finder" do
196
- Mongoid::Criteria.expects(:translate).with(:first, :conditions => @conditions).returns(@criteria)
197
- @criteria.expects(:execute).with(Person).returns(@document)
193
+ Mongoid::Criteria.expects(:translate).with(Person, :conditions => @conditions).returns(@criteria)
194
+ @criteria.expects(:one).returns(@document)
198
195
  Person.find_by_title_and_age("Sir", 30)
199
196
  end
200
197
 
@@ -211,8 +208,8 @@ describe Mongoid::Finders do
211
208
  context "when document is found" do
212
209
 
213
210
  it "returns the document" do
214
- Mongoid::Criteria.expects(:translate).with(:first, :conditions => @conditions).returns(@criteria)
215
- @criteria.expects(:execute).with(Person).returns(@document)
211
+ Mongoid::Criteria.expects(:translate).with(Person, :conditions => @conditions).returns(@criteria)
212
+ @criteria.expects(:one).returns(@document)
216
213
  Person.find_or_initialize_by_title_and_age("Sir", 30).should == @document
217
214
  end
218
215
 
@@ -221,8 +218,8 @@ describe Mongoid::Finders do
221
218
  context "when document is not found" do
222
219
 
223
220
  it "instantiates a new document" do
224
- Mongoid::Criteria.expects(:translate).with(:first, :conditions => @conditions).returns(@criteria)
225
- @criteria.expects(:execute).with(Person).returns(nil)
221
+ Mongoid::Criteria.expects(:translate).with(Person, :conditions => @conditions).returns(@criteria)
222
+ @criteria.expects(:one).returns(nil)
226
223
  new_doc = Person.find_or_initialize_by_title_and_age("Sir", 30)
227
224
  new_doc.new_record?.should be_true
228
225
  new_doc.title.should == "Sir"
@@ -248,8 +245,8 @@ describe Mongoid::Finders do
248
245
  end
249
246
 
250
247
  it "delegates to will paginate with the results" do
251
- Mongoid::Criteria.expects(:translate).with(:all, @params).returns(@criteria)
252
- @criteria.expects(:paginate).with(Person).returns([])
248
+ Mongoid::Criteria.expects(:translate).with(Person, @params).returns(@criteria)
249
+ @criteria.expects(:paginate).returns([])
253
250
  Person.paginate(@params)
254
251
  end
255
252
 
@@ -262,8 +259,8 @@ describe Mongoid::Finders do
262
259
  end
263
260
 
264
261
  it "delegates to will paginate with default values" do
265
- Mongoid::Criteria.expects(:translate).with(:all, @params).returns(@criteria)
266
- @criteria.expects(:paginate).with(Person).returns([])
262
+ Mongoid::Criteria.expects(:translate).with(Person, @params).returns(@criteria)
263
+ @criteria.expects(:paginate).returns([])
267
264
  Person.paginate(:conditions => { :test => "Test" })
268
265
  end
269
266
 
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.8.10
4
+ version: 0.9.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: 2009-11-27 00:00:00 -05:00
12
+ date: 2009-11-28 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency