couchrest 1.2.1 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,8 +6,8 @@ describe CouchRest::Design do
6
6
  it "should add a view to the design doc" do
7
7
  @des = CouchRest::Design.new
8
8
  method = @des.view_by :name
9
- method.should == "by_name"
10
- @des["views"]["by_name"].should_not be_nil
9
+ expect(method).to eql "by_name"
10
+ expect(@des["views"]["by_name"]).not_to be_nil
11
11
  end
12
12
  end
13
13
 
@@ -18,13 +18,13 @@ describe CouchRest::Design do
18
18
  end
19
19
  it "should accept a name" do
20
20
  @des.name = "mytest"
21
- @des.name.should == "mytest"
21
+ expect(@des.name).to eql "mytest"
22
22
  end
23
23
  it "should not save on view definition" do
24
- @des.rev.should be_nil
24
+ expect(@des.rev).to be_nil
25
25
  end
26
26
  it "should freak out on view access" do
27
- lambda{@des.view :by_name}.should raise_error
27
+ expect { @des.view :by_name }.to raise_error
28
28
  end
29
29
  end
30
30
 
@@ -35,7 +35,7 @@ describe CouchRest::Design do
35
35
  @des.database = reset_test_db!
36
36
  end
37
37
  it "should fail without a name" do
38
- lambda{@des.save}.should raise_error(ArgumentError)
38
+ expect(lambda{@des.save}).to raise_error(ArgumentError)
39
39
  end
40
40
  it "should work with a name" do
41
41
  @des.name = "myview"
@@ -55,14 +55,14 @@ describe CouchRest::Design do
55
55
  @des.name = "mydesign"
56
56
  @des.save
57
57
  res = @des.view :by_name
58
- res["rows"][0]["key"].should == "x"
58
+ expect(res["rows"][0]["key"]).to eql "x"
59
59
  end
60
60
  it "should be queryable on specified database" do
61
61
  @des.name = "mydesign"
62
62
  @des.save
63
63
  @des.database = nil
64
64
  res = @des.view_on @db, :by_name
65
- res["rows"][0]["key"].should == "x"
65
+ expect(res["rows"][0]["key"]).to eql "x"
66
66
  end
67
67
  end
68
68
 
@@ -81,16 +81,16 @@ describe CouchRest::Design do
81
81
  @des = @db.get "_design/test"
82
82
  end
83
83
  it "should be a Design" do
84
- @des.should be_an_instance_of(CouchRest::Design)
84
+ expect(@des).to be_an_instance_of(CouchRest::Design)
85
85
  end
86
86
  it "should have a modifiable name" do
87
- @des.name.should == "test"
87
+ expect(@des.name).to eql "test"
88
88
  @des.name = "supertest"
89
- @des.id.should == "_design/supertest"
89
+ expect(@des.id).to eql "_design/supertest"
90
90
  end
91
91
  it "should by queryable" do
92
92
  res = @des.view :by_name
93
- res["rows"][0]["key"].should == "a"
93
+ expect(res["rows"][0]["key"]).to eql "a"
94
94
  end
95
95
  end
96
96
 
@@ -106,15 +106,15 @@ describe CouchRest::Design do
106
106
  end
107
107
  it "should save them" do
108
108
  @d2 = @db.get(@des.id)
109
- @d2["views"]["by_name"]["couchrest-defaults"].should == {"descending"=>true}
109
+ expect(@d2["views"]["by_name"]["couchrest-defaults"]).to eql("descending" => true)
110
110
  end
111
111
  it "should use them" do
112
112
  res = @des.view :by_name
113
- res["rows"].first["key"].should == "z"
113
+ expect(res["rows"].first["key"]).to eql "z"
114
114
  end
115
115
  it "should override them" do
116
116
  res = @des.view :by_name, :descending => false
117
- res["rows"].first["key"].should == "a"
117
+ expect(res["rows"].first["key"]).to eql "a"
118
118
  end
119
119
  end
120
120
 
@@ -131,7 +131,7 @@ describe CouchRest::Design do
131
131
  end
132
132
  it "should work" do
133
133
  res = @des.view :by_name_and_age
134
- res["rows"].first["key"].should == ["a",2]
134
+ expect(res["rows"].first["key"]).to eql ["a",2]
135
135
  end
136
136
  end
137
137
 
@@ -148,9 +148,9 @@ describe CouchRest::Design do
148
148
  end
149
149
  it "should work" do
150
150
  res = @des.view :by_code
151
- res["rows"][0]["key"].should == 0
152
- res["rows"][1]["key"].should == "a"
153
- res["rows"][2].should be_nil
151
+ expect(res["rows"][0]["key"]).to eql 0
152
+ expect(res["rows"][1]["key"]).to eql "a"
153
+ expect(res["rows"][2]).to be_nil
154
154
  end
155
155
  end
156
156
 
@@ -167,9 +167,9 @@ describe CouchRest::Design do
167
167
  end
168
168
  it "should work" do
169
169
  res = @des.view :by_code
170
- res["rows"][0]["key"].should == nil
171
- res["rows"][1]["key"].should == 0
172
- res["rows"][2]["key"].should == "a"
170
+ expect(res["rows"][0]["key"]).to be_nil
171
+ expect(res["rows"][1]["key"]).to eql 0
172
+ expect(res["rows"][2]["key"]).to eql "a"
173
173
  end
174
174
  end
175
175
 
@@ -186,19 +186,19 @@ describe CouchRest::Design do
186
186
  {"code" => 'b', "age" => 4},{"code" => 'c', "age" => 9}])
187
187
  end
188
188
  it "should not set a default parameter" do
189
- @des['views']['by_code']['couchrest-defaults'].should be_nil
189
+ expect(@des['views']['by_code']['couchrest-defaults']).to be_nil
190
190
  end
191
191
  it "should include reduce parameter in query" do
192
192
  # this would fail without it
193
193
  res = @des.view :by_code
194
- res["rows"][0]["key"].should == 'a'
194
+ expect(res["rows"][0]["key"]).to eql 'a'
195
195
  end
196
196
  it "should allow reduce to be performed" do
197
197
  res = @des.view :by_code, :reduce => true
198
- res["rows"][0]["value"].should eql(3)
198
+ expect(res["rows"][0]["value"]).to eql(3)
199
199
  end
200
200
  it "does not allow string keys to be passed to view as options" do
201
- lambda{ @des.view :by_code, 'reduce' => true }.should raise_error(ArgumentError, /set as symbols/)
201
+ expect(lambda{ @des.view :by_code, 'reduce' => true }).to raise_error(ArgumentError, /set as symbols/)
202
202
  end
203
203
  end
204
204
 
@@ -217,8 +217,8 @@ describe CouchRest::Design do
217
217
 
218
218
  it "should provide a summary info hash" do
219
219
  info = @des.info
220
- info['name'].should eql("test")
221
- info.should include("view_index")
220
+ expect(info['name']).to eql("test")
221
+ expect(info).to include("view_index")
222
222
  end
223
223
 
224
224
  end
@@ -12,20 +12,20 @@ describe CouchRest::Document do
12
12
  describe "#new" do
13
13
  it "should not be a Hash" do
14
14
  @doc = CouchRest::Document.new
15
- @doc.class.should eql(CouchRest::Document)
16
- @doc.is_a?(Hash).should be_false
15
+ expect(@doc.class).to eql(CouchRest::Document)
16
+ expect(@doc.is_a?(Hash)).to be_false
17
17
  end
18
18
 
19
19
  it "should be possible to initialize a new Document with attributes" do
20
20
  @doc = CouchRest::Document.new('foo' => 'bar', :test => 'foo')
21
- @doc['foo'].should eql('bar')
22
- @doc['test'].should eql('foo')
21
+ expect(@doc['foo']).to eql('bar')
22
+ expect(@doc['test']).to eql('foo')
23
23
  end
24
24
 
25
25
  it "should accept new with _id" do
26
26
  @doc = CouchRest::Document.new('_id' => 'sample', 'foo' => 'bar')
27
- @doc['_id'].should eql('sample')
28
- @doc['foo'].should eql('bar')
27
+ expect(@doc['_id']).to eql('sample')
28
+ expect(@doc['foo']).to eql('bar')
29
29
  end
30
30
 
31
31
  context "replacing initalize" do
@@ -48,7 +48,7 @@ describe CouchRest::Document do
48
48
  @doc = CouchRest::Document.new(:foo => 'bar')
49
49
  [:to_a, :==, :eql?, :keys, :values, :each, :reject, :reject!, :empty?,
50
50
  :clear, :merge, :merge!, :encode_json, :as_json, :to_json, :frozen?].each do |call|
51
- @doc.should respond_to(call)
51
+ expect(@doc).to respond_to(call)
52
52
  end
53
53
  end
54
54
  end
@@ -58,18 +58,18 @@ describe CouchRest::Document do
58
58
  @doc = CouchRest::Document.new
59
59
  end
60
60
  it "should work" do
61
- @doc["enamel"].should == nil
61
+ expect(@doc["enamel"]).to be_nil
62
62
  @doc["enamel"] = "Strong"
63
- @doc["enamel"].should == "Strong"
63
+ expect(@doc["enamel"]).to eql "Strong"
64
64
  end
65
65
  it "[]= should convert to string" do
66
- @doc["enamel"].should == nil
66
+ expect(@doc["enamel"]).to be_nil
67
67
  @doc[:enamel] = "Strong"
68
- @doc["enamel"].should == "Strong"
68
+ expect(@doc["enamel"]).to eql "Strong"
69
69
  end
70
70
  it "should read as a string" do
71
71
  @doc[:enamel] = "Strong"
72
- @doc[:enamel].should == "Strong"
72
+ expect(@doc[:enamel]).to eql "Strong"
73
73
  end
74
74
  end
75
75
 
@@ -79,12 +79,12 @@ describe CouchRest::Document do
79
79
  end
80
80
  it "should confirm existance of key" do
81
81
  @doc[:test] = 'example'
82
- @doc.has_key?('test').should be_true
83
- @doc.has_key?(:test).should be_true
82
+ expect(@doc.has_key?('test')).to be_true
83
+ expect(@doc.has_key?(:test)).to be_true
84
84
  end
85
85
  it "should deny existance of key" do
86
- @doc.has_key?(:bardom).should be_false
87
- @doc.has_key?('bardom').should be_false
86
+ expect(@doc.has_key?(:bardom)).to be_false
87
+ expect(@doc.has_key?('bardom')).to be_false
88
88
  end
89
89
  end
90
90
 
@@ -93,8 +93,8 @@ describe CouchRest::Document do
93
93
  @doc = CouchRest::Document.new('foo' => 'bar')
94
94
  @doc2 = @doc.dup
95
95
  @doc2.delete('foo')
96
- @doc2['foo'].should be_nil
97
- @doc['foo'].should eql('bar')
96
+ expect(@doc2['foo']).to be_nil
97
+ expect(@doc['foo']).to eql('bar')
98
98
  end
99
99
  end
100
100
 
@@ -103,8 +103,8 @@ describe CouchRest::Document do
103
103
  @doc = CouchRest::Document.new('foo' => 'bar')
104
104
  @doc2 = @doc.clone
105
105
  @doc2.delete('foo')
106
- @doc2['foo'].should be_nil
107
- @doc['foo'].should eql('bar')
106
+ expect(@doc2['foo']).to be_nil
107
+ expect(@doc['foo']).to eql('bar')
108
108
  end
109
109
  end
110
110
 
@@ -114,8 +114,8 @@ describe CouchRest::Document do
114
114
  klass.class_eval { attr_accessor :test_attr }
115
115
  @doc = klass.new('foo' => 'bar')
116
116
  @doc.freeze
117
- lambda { @doc['foo'] = 'bar2' }.should raise_error(/frozen/)
118
- lambda { @doc.test_attr = "bar3" }.should_not raise_error
117
+ expect(lambda { @doc['foo'] = 'bar2' }).to raise_error(/frozen/)
118
+ expect(lambda { @doc.test_attr = "bar3" }).not_to raise_error
119
119
  end
120
120
  end
121
121
 
@@ -123,30 +123,30 @@ describe CouchRest::Document do
123
123
  it "should provide a hash of data from normal document" do
124
124
  @doc = CouchRest::Document.new('foo' => 'bar')
125
125
  h = @doc.as_couch_json
126
- h.should be_a(Hash)
127
- h['foo'].should eql('bar')
126
+ expect(h).to be_a(Hash)
127
+ expect(h['foo']).to eql('bar')
128
128
  end
129
129
 
130
130
  it "should handle nested documents" do
131
131
  @doc = CouchRest::Document.new('foo' => 'bar', 'doc' => CouchRest::Document.new('foo2' => 'bar2'))
132
132
  h = @doc.as_couch_json
133
- h['doc'].should be_a(Hash)
134
- h['doc']['foo2'].should eql('bar2')
133
+ expect(h['doc']).to be_a(Hash)
134
+ expect(h['doc']['foo2']).to eql('bar2')
135
135
  end
136
136
  end
137
137
 
138
138
  describe "#inspect" do
139
139
  it "should provide a string of keys and values of the Response" do
140
140
  @doc = CouchRest::Document.new('foo' => 'bar')
141
- @doc.inspect.should eql("#<CouchRest::Document foo: \"bar\">")
141
+ expect(@doc.inspect).to eql("#<CouchRest::Document foo: \"bar\">")
142
142
  end
143
143
  end
144
144
 
145
145
  describe "responding to Hash methods" do
146
146
  it "should delegate requests" do
147
147
  @doc = CouchRest::Document.new('foo' => 'bar')
148
- @doc.keys.should eql(['foo'])
149
- @doc.values.should eql(['bar'])
148
+ expect(@doc.keys).to eql(['foo'])
149
+ expect(@doc.values).to eql(['bar'])
150
150
  end
151
151
  end
152
152
 
@@ -155,19 +155,19 @@ describe CouchRest::Document do
155
155
  Video.use_database nil
156
156
  end
157
157
  it "should be set using use_database on the model" do
158
- Video.new.database.should be_nil
158
+ expect(Video.new.database).to be_nil
159
159
  Video.use_database @db
160
- Video.new.database.should == @db
160
+ expect(Video.new.database).to eql @db
161
161
  Video.use_database nil
162
162
  end
163
163
 
164
164
  it "should be overwritten by instance" do
165
165
  db = @couch.database('test')
166
166
  article = Video.new
167
- article.database.should be_nil
167
+ expect(article.database).to be_nil
168
168
  article.database = db
169
- article.database.should_not be_nil
170
- article.database.should == db
169
+ expect(article.database).not_to be_nil
170
+ expect(article.database).to eql db
171
171
  end
172
172
  end
173
173
 
@@ -176,20 +176,20 @@ describe CouchRest::Document do
176
176
  @doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
177
177
  end
178
178
  it "should create itself from a Hash" do
179
- @doc["key"].should == [1,2,3]
180
- @doc["more"].should == "values"
179
+ expect(@doc["key"]).to eql [1,2,3]
180
+ expect(@doc["more"]).to eql "values"
181
181
  end
182
182
  it "should not have rev and id" do
183
- @doc.rev.should be_nil
184
- @doc.id.should be_nil
183
+ expect(@doc.rev).to be_nil
184
+ expect(@doc.id).to be_nil
185
185
  end
186
186
  it "should be possible to set id" do
187
187
  @doc.id = 1
188
- @doc.id.should eql(1)
188
+ expect(@doc.id).to eql(1)
189
189
  end
190
190
 
191
191
  it "should freak out when saving without a database" do
192
- lambda{@doc.save}.should raise_error(ArgumentError)
192
+ expect(lambda{@doc.save}).to raise_error(ArgumentError)
193
193
  end
194
194
 
195
195
  end
@@ -202,19 +202,19 @@ describe CouchRest::Document do
202
202
  @resp = @db.save_doc(@doc)
203
203
  end
204
204
  it "should apply the database" do
205
- @doc.database.should == @db
205
+ expect(@doc.database).to eql @db
206
206
  end
207
207
  it "should get id and rev" do
208
- @doc.id.should == @resp["id"]
209
- @doc.rev.should == @resp["rev"]
208
+ expect(@doc.id).to eql @resp["id"]
209
+ expect(@doc.rev).to eql @resp["rev"]
210
210
  end
211
211
  it "should generate a correct URI" do
212
- @doc.uri.should == "#{@db.root}/#{@doc.id}"
213
- URI.parse(@doc.uri).to_s.should == @doc.uri
212
+ expect(@doc.uri).to eql "#{@db.root}/#{@doc.id}"
213
+ expect(URI.parse(@doc.uri).to_s).to eql @doc.uri
214
214
  end
215
215
  it "should generate a correct URI with revision" do
216
- @doc.uri(true).should == "#{@db.root}/#{@doc.id}?rev=#{@doc.rev}"
217
- URI.parse(@doc.uri(true)).to_s.should == @doc.uri(true)
216
+ expect(@doc.uri(true)).to eql "#{@db.root}/#{@doc.id}?rev=#{@doc.rev}"
217
+ expect(URI.parse(@doc.uri(true)).to_s).to eql @doc.uri(true)
218
218
  end
219
219
  end
220
220
 
@@ -227,9 +227,9 @@ describe CouchRest::Document do
227
227
  doc = CouchRest::Document.new({"_id" => "bulkdoc", "val" => 3})
228
228
  doc.database = @db
229
229
  doc.save(true)
230
- lambda { doc.database.get(doc["_id"]) }.should raise_error(RestClient::ResourceNotFound)
230
+ expect(lambda { doc.database.get(doc["_id"]) }).to raise_error(CouchRest::NotFound)
231
231
  doc.database.bulk_save
232
- doc.database.get(doc["_id"])["val"].should == doc["val"]
232
+ expect(doc.database.get(doc["_id"])["val"]).to eql doc["val"]
233
233
  end
234
234
  end
235
235
 
@@ -242,18 +242,18 @@ describe CouchRest::Document do
242
242
  @doc = @db.get @resp['id']
243
243
  end
244
244
  it "should return a document" do
245
- @doc.should be_an_instance_of(CouchRest::Document)
245
+ expect(@doc).to be_an_instance_of(CouchRest::Document)
246
246
  end
247
247
  it "should have a database" do
248
- @doc.database.should == @db
248
+ expect(@doc.database).to eql @db
249
249
  end
250
250
  it "should be saveable and resavable" do
251
251
  @doc["more"] = "keys"
252
252
  @doc.save
253
- @db.get(@resp['id'])["more"].should == "keys"
253
+ expect(@db.get(@resp['id'])["more"]).to eql "keys"
254
254
  @doc["more"] = "these keys"
255
255
  @doc.save
256
- @db.get(@resp['id'])["more"].should == "these keys"
256
+ expect(@db.get(@resp['id'])["more"]).to eql "these keys"
257
257
  end
258
258
  end
259
259
 
@@ -267,11 +267,11 @@ describe CouchRest::Document do
267
267
  end
268
268
  it "should make it disappear" do
269
269
  @doc.destroy
270
- lambda{@db.get @resp['id']}.should raise_error
270
+ expect(lambda{@db.get @resp['id']}).to raise_error
271
271
  end
272
272
  it "should error when there's no db" do
273
273
  @doc = CouchRest::Document.new("key" => [1,2,3], :more => "values")
274
- lambda{@doc.destroy}.should raise_error(ArgumentError)
274
+ expect(lambda{@doc.destroy}).to raise_error(ArgumentError)
275
275
  end
276
276
  end
277
277
 
@@ -286,11 +286,11 @@ describe CouchRest::Document do
286
286
  end
287
287
  it "should defer actual deletion" do
288
288
  @doc.destroy(true)
289
- @doc['_id'].should == nil
290
- @doc['_rev'].should == nil
291
- lambda{@db.get @resp['id']}.should_not raise_error
289
+ expect(@doc['_id']).to be_nil
290
+ expect(@doc['_rev']).to be_nil
291
+ expect(lambda{@db.get @resp['id']}).not_to raise_error
292
292
  @db.bulk_save
293
- lambda{@db.get @resp['id']}.should raise_error
293
+ expect(lambda{@db.get @resp['id']}).to raise_error
294
294
  end
295
295
  end
296
296
 
@@ -305,10 +305,10 @@ describe CouchRest::Document do
305
305
  it "should work" do
306
306
  @doc.copy @docid
307
307
  newdoc = @db.get(@docid)
308
- newdoc['key'].should == 'value'
308
+ expect(newdoc['key']).to eql 'value'
309
309
  end
310
310
  it "should fail without a database" do
311
- lambda{CouchRest::Document.new({"not"=>"a real doc"}).copy}.should raise_error(ArgumentError)
311
+ expect(lambda{CouchRest::Document.new({"not"=>"a real doc"}).copy}).to raise_error(ArgumentError)
312
312
  end
313
313
  end
314
314
  describe "to an existing location" do
@@ -316,19 +316,19 @@ describe CouchRest::Document do
316
316
  @db.save_doc({'_id' => @docid, 'will-exist' => 'here'})
317
317
  end
318
318
  it "should fail without a rev" do
319
- lambda{@doc.copy @docid}.should raise_error(RestClient::RequestFailed)
319
+ expect(lambda{@doc.copy @docid}).to raise_error(CouchRest::RequestFailed)
320
320
  end
321
321
  it "should succeed with a rev" do
322
322
  @to_be_overwritten = @db.get(@docid)
323
323
  @doc.copy "#{@docid}?rev=#{@to_be_overwritten['_rev']}"
324
324
  newdoc = @db.get(@docid)
325
- newdoc['key'].should == 'value'
325
+ expect(newdoc['key']).to eql 'value'
326
326
  end
327
327
  it "should succeed given the doc to overwrite" do
328
328
  @to_be_overwritten = @db.get(@docid)
329
329
  @doc.copy @to_be_overwritten
330
330
  newdoc = @db.get(@docid)
331
- newdoc['key'].should == 'value'
331
+ expect(newdoc['key']).to eql 'value'
332
332
  end
333
333
  end
334
334
  end
@@ -358,17 +358,17 @@ describe "dealing with attachments" do
358
358
  end
359
359
 
360
360
  it "is there" do
361
- @db.fetch_attachment(@doc, 'test.html').should == @attach
361
+ expect(@db.fetch_attachment(@doc, 'test.html')).to eql @attach
362
362
  end
363
363
 
364
364
  it "updates the revision" do
365
- @doc[:_rev].should_not == @rev
365
+ expect(@doc[:_rev]).not_to eql @rev
366
366
  end
367
367
 
368
368
  it "updates attachments" do
369
369
  @attach2 = "<html><head><title>My Doc</title></head><body><p>Is Different.</p></body></html>"
370
370
  @doc.put_attachment('test.html', @attach2)
371
- @db.fetch_attachment(@doc, 'test.html').should == @attach2
371
+ expect(@db.fetch_attachment(@doc, 'test.html')).to eql @attach2
372
372
  end
373
373
  end
374
374
 
@@ -378,7 +378,7 @@ describe "dealing with attachments" do
378
378
  end
379
379
 
380
380
  it "pulls the attachment" do
381
- @doc.fetch_attachment('test.html').should == @attach
381
+ expect(@doc.fetch_attachment('test.html')).to eql @attach
382
382
  end
383
383
  end
384
384
 
@@ -389,11 +389,13 @@ describe "dealing with attachments" do
389
389
  end
390
390
 
391
391
  it "removes it" do
392
- lambda { @db.fetch_attachment(@doc, 'test.html').should }.should raise_error(RestClient::ResourceNotFound)
392
+ expect {
393
+ @db.fetch_attachment(@doc, 'test.html')
394
+ }.to raise_error(CouchRest::NotFound)
393
395
  end
394
396
 
395
397
  it "updates the revision" do
396
- @doc[:_rev].should_not == @rev
398
+ expect(@doc[:_rev]).not_to eql @rev
397
399
  end
398
400
  end
399
401