couch_potato 1.4.0 → 1.6.3

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.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -0
  3. data/.travis.yml +12 -8
  4. data/CHANGES.md +4 -0
  5. data/Gemfile +1 -1
  6. data/README.md +396 -276
  7. data/Rakefile +9 -9
  8. data/couch_potato-rspec.gemspec +20 -0
  9. data/couch_potato.gemspec +15 -16
  10. data/{active_support_4_0 → gemfiles/active_support_4_0} +3 -3
  11. data/{active_support_3_2 → gemfiles/active_support_4_1} +3 -2
  12. data/gemfiles/active_support_4_2 +11 -0
  13. data/lib/couch_potato-rspec.rb +3 -0
  14. data/lib/couch_potato.rb +3 -1
  15. data/lib/couch_potato/database.rb +42 -39
  16. data/lib/couch_potato/persistence/magic_timestamps.rb +5 -5
  17. data/lib/couch_potato/persistence/properties.rb +8 -2
  18. data/lib/couch_potato/persistence/simple_property.rb +11 -9
  19. data/lib/couch_potato/persistence/type_caster.rb +1 -1
  20. data/lib/couch_potato/railtie.rb +2 -0
  21. data/lib/couch_potato/version.rb +2 -1
  22. data/lib/couch_potato/view/base_view_spec.rb +18 -8
  23. data/lib/couch_potato/view/view_query.rb +2 -3
  24. data/spec/attachments_spec.rb +3 -3
  25. data/spec/callbacks_spec.rb +193 -113
  26. data/spec/conflict_handling_spec.rb +4 -4
  27. data/spec/create_spec.rb +5 -5
  28. data/spec/default_property_spec.rb +6 -6
  29. data/spec/destroy_spec.rb +5 -5
  30. data/spec/property_spec.rb +71 -61
  31. data/spec/rails_spec.rb +3 -3
  32. data/spec/railtie_spec.rb +12 -13
  33. data/spec/spec_helper.rb +3 -3
  34. data/spec/unit/active_model_compliance_spec.rb +16 -16
  35. data/spec/unit/attributes_spec.rb +36 -34
  36. data/spec/unit/base_view_spec_spec.rb +82 -35
  37. data/spec/unit/callbacks_spec.rb +2 -2
  38. data/spec/unit/couch_potato_spec.rb +3 -3
  39. data/spec/unit/create_spec.rb +12 -12
  40. data/spec/unit/custom_views_spec.rb +1 -1
  41. data/spec/unit/database_spec.rb +95 -95
  42. data/spec/unit/date_spec.rb +3 -3
  43. data/spec/unit/deep_dirty_attributes_spec.rb +104 -104
  44. data/spec/unit/dirty_attributes_spec.rb +19 -19
  45. data/spec/unit/forbidden_attributes_protection_spec.rb +4 -4
  46. data/spec/unit/initialize_spec.rb +37 -19
  47. data/spec/unit/json_spec.rb +4 -4
  48. data/spec/unit/lists_spec.rb +8 -8
  49. data/spec/unit/model_view_spec_spec.rb +14 -14
  50. data/spec/unit/persistence_spec.rb +6 -6
  51. data/spec/unit/properties_view_spec_spec.rb +4 -4
  52. data/spec/unit/rspec_matchers_spec.rb +73 -73
  53. data/spec/unit/rspec_stub_db_spec.rb +43 -42
  54. data/spec/unit/string_spec.rb +1 -1
  55. data/spec/unit/time_spec.rb +2 -2
  56. data/spec/unit/validation_spec.rb +1 -1
  57. data/spec/unit/view_query_spec.rb +54 -59
  58. data/spec/update_spec.rb +5 -5
  59. data/spec/view_updates_spec.rb +4 -4
  60. data/spec/views_spec.rb +43 -43
  61. metadata +18 -22
  62. data/lib/couch_potato/rspec.rb +0 -2
  63. data/lib/couch_potato/rspec/matchers.rb +0 -56
  64. data/lib/couch_potato/rspec/matchers/json2.js +0 -482
  65. data/lib/couch_potato/rspec/matchers/list_as_matcher.rb +0 -53
  66. data/lib/couch_potato/rspec/matchers/map_reduce_to_matcher.rb +0 -166
  67. data/lib/couch_potato/rspec/matchers/map_to_matcher.rb +0 -61
  68. data/lib/couch_potato/rspec/matchers/reduce_to_matcher.rb +0 -48
  69. data/lib/couch_potato/rspec/stub_db.rb +0 -57
@@ -33,13 +33,13 @@ describe 'callbacks' do
33
33
  it "should call the callbacks of the super class" do
34
34
  tree = AppleTree.new :leaf_count => 1
35
35
  tree.valid?
36
- tree.leaf_count.should == 2
36
+ expect(tree.leaf_count).to eq(2)
37
37
  end
38
38
 
39
39
  it "should call the callbacks of the child class" do
40
40
  tree = AppleTree.new :leaf_count => 1
41
41
  tree.valid?
42
- tree.should be_watered
42
+ expect(tree).to be_watered
43
43
  end
44
44
  end
45
45
 
@@ -10,19 +10,19 @@ describe CouchPotato, 'full_url_to_database' do
10
10
 
11
11
  it "should add the default localhost and port if only a name is set" do
12
12
  CouchPotato::Config.database_name = 'test'
13
- CouchPotato.full_url_to_database.should == 'http://127.0.0.1:5984/test'
13
+ expect(CouchPotato.full_url_to_database).to eq('http://127.0.0.1:5984/test')
14
14
  end
15
15
 
16
16
  it "should return the set url" do
17
17
  CouchPotato::Config.database_name = 'http://db.local/test'
18
- CouchPotato.full_url_to_database.should == 'http://db.local/test'
18
+ expect(CouchPotato.full_url_to_database).to eq('http://db.local/test')
19
19
  end
20
20
  end
21
21
 
22
22
  describe CouchPotato, 'use' do
23
23
  it 'should return the db object' do
24
24
  db = CouchPotato.use("testdb")
25
- db.couchrest_database.root.should == 'http://127.0.0.1:5984/testdb'
25
+ expect(db.couchrest_database.root.to_s).to eq('http://127.0.0.1:5984/testdb')
26
26
  end
27
27
  end
28
28
 
@@ -9,29 +9,29 @@ describe "create" do
9
9
 
10
10
  def create_comment
11
11
  comment = Comment.new :title => 'my_title'
12
- CouchPotato::Database.new(stub('database', :save_doc => {'rev' => '123', 'id' => '456'}, :info => nil)).save_document!(comment)
12
+ CouchPotato::Database.new(double('database', :save_doc => {'rev' => '123', 'id' => '456'}, :info => nil)).save_document!(comment)
13
13
  comment
14
14
  end
15
15
 
16
16
  it "should assign the id" do
17
- create_comment._id.should == '456'
17
+ expect(create_comment._id).to eq('456')
18
18
  end
19
19
 
20
20
  it "should assign the revision" do
21
- create_comment._rev.should == '123'
21
+ expect(create_comment._rev).to eq('123')
22
22
  end
23
23
 
24
24
  it "should set created at in the current time zone" do
25
25
  Time.zone = 'Europe/Berlin'
26
26
  Timecop.travel Time.zone.parse('2010-01-01 12:00 +0100') do
27
- create_comment.created_at.to_s.should == '2010-01-01 12:00:00 +0100'
27
+ expect(create_comment.created_at.to_s).to eq('2010-01-01 12:00:00 +0100')
28
28
  end
29
29
  end
30
30
 
31
31
  it "should set updated at in the current time zone" do
32
32
  Time.zone = 'Europe/Berlin'
33
33
  Timecop.travel Time.zone.parse('2010-01-01 12:00 +0100') do
34
- create_comment.updated_at.to_s.should == '2010-01-01 12:00:00 +0100'
34
+ expect(create_comment.updated_at.to_s).to eq('2010-01-01 12:00:00 +0100')
35
35
  end
36
36
  end
37
37
  end
@@ -39,30 +39,30 @@ describe "create" do
39
39
  describe "fails" do
40
40
  before(:each) do
41
41
  @comment = Comment.new
42
- CouchPotato::Database.new(stub('database', :info => nil)).save_document(@comment)
42
+ CouchPotato::Database.new(double('database', :info => nil)).save_document(@comment)
43
43
  end
44
44
 
45
45
  it "should not assign an id" do
46
- @comment._id.should be_nil
46
+ expect(@comment._id).to be_nil
47
47
  end
48
48
 
49
49
  it "should not assign a revision" do
50
- @comment._rev.should be_nil
50
+ expect(@comment._rev).to be_nil
51
51
  end
52
52
 
53
53
  it "should not set created at" do
54
- @comment.created_at.should be_nil
54
+ expect(@comment.created_at).to be_nil
55
55
  end
56
56
 
57
57
  it "should set updated at" do
58
- @comment.updated_at.should be_nil
58
+ expect(@comment.updated_at).to be_nil
59
59
  end
60
60
 
61
61
  describe "with bank" do
62
62
  it "should raise an exception" do
63
- lambda {
63
+ expect {
64
64
  @comment.save!
65
- }.should raise_error
65
+ }.to raise_error
66
66
  end
67
67
  end
68
68
  end
@@ -9,7 +9,7 @@ describe CouchPotato::View::CustomViews do
9
9
  end
10
10
 
11
11
  it "should use a custom viewspec class" do
12
- MyViewSpec.should_receive(:new)
12
+ expect(MyViewSpec).to receive(:new)
13
13
  ModelWithView.all
14
14
  end
15
15
  end
@@ -22,42 +22,42 @@ describe CouchPotato::Database, 'full_url_to_database' do
22
22
 
23
23
  it "should return the full URL when it starts with https" do
24
24
  CouchPotato::Config.database_name = "https://example.com/database"
25
- CouchPotato.full_url_to_database.should == 'https://example.com/database'
25
+ expect(CouchPotato.full_url_to_database).to eq('https://example.com/database')
26
26
  end
27
27
 
28
28
  it "should return the full URL when it starts with http" do
29
29
  CouchPotato::Config.database_name = "http://example.com/database"
30
- CouchPotato.full_url_to_database.should == 'http://example.com/database'
30
+ expect(CouchPotato.full_url_to_database).to eq('http://example.com/database')
31
31
  end
32
32
 
33
33
  it "should use localhost when no protocol was specified" do
34
34
  CouchPotato::Config.database_name = "database"
35
- CouchPotato.full_url_to_database.should == 'http://127.0.0.1:5984/database'
35
+ expect(CouchPotato.full_url_to_database).to eq('http://127.0.0.1:5984/database')
36
36
  end
37
37
  end
38
38
 
39
39
  describe CouchPotato::Database, 'load' do
40
40
 
41
- let(:couchrest_db) { stub('couchrest db', :info => nil).as_null_object }
41
+ let(:couchrest_db) { double('couchrest db', :info => nil).as_null_object }
42
42
  let(:db) { CouchPotato::Database.new couchrest_db }
43
43
 
44
44
  it "should raise an exception if nil given" do
45
- lambda {
45
+ expect {
46
46
  db.load nil
47
- }.should raise_error("Can't load a document without an id (got nil)")
47
+ }.to raise_error("Can't load a document without an id (got nil)")
48
48
  end
49
49
 
50
50
  it "should set itself on the model" do
51
- user = mock('user').as_null_object
52
- DbTestUser.stub!(:new).and_return(user)
53
- couchrest_db.stub(:get).and_return DbTestUser.json_create({JSON.create_id => 'DbTestUser'})
54
- user.should_receive(:database=).with(db)
51
+ user = double('user').as_null_object
52
+ allow(DbTestUser).to receive(:new).and_return(user)
53
+ allow(couchrest_db).to receive(:get).and_return DbTestUser.json_create({JSON.create_id => 'DbTestUser'})
54
+ expect(user).to receive(:database=).with(db)
55
55
  db.load '1'
56
56
  end
57
57
 
58
58
  it "should load namespaced models" do
59
- couchrest_db.stub(:get).and_return Parent::Child.json_create({JSON.create_id => 'Parent::Child'})
60
- db.load('1').class.should == Parent::Child
59
+ allow(couchrest_db).to receive(:get).and_return Parent::Child.json_create({JSON.create_id => 'Parent::Child'})
60
+ expect(db.load('1').class).to eq(Parent::Child)
61
61
  end
62
62
 
63
63
  context "when several ids given" do
@@ -68,32 +68,32 @@ describe CouchPotato::Database, 'load' do
68
68
  end
69
69
 
70
70
  before(:each) do
71
- couchrest_db.stub(:bulk_load) { response }
71
+ allow(couchrest_db).to receive(:bulk_load) { response }
72
72
  end
73
73
 
74
74
  it "requests the couchrest bulk method" do
75
- couchrest_db.should_receive(:bulk_load).with(['1', '2', '3'])
75
+ expect(couchrest_db).to receive(:bulk_load).with(['1', '2', '3'])
76
76
  db.load ['1', '2', '3']
77
77
  end
78
78
 
79
79
  it "returns only found documents" do
80
- db.load(['1', '2', '3']).should have(2).items
80
+ expect(db.load(['1', '2', '3']).size).to eq(2)
81
81
  end
82
82
 
83
83
  it "writes itself to each of the documents" do
84
84
  db.load(['1', '2', '3']).each do |doc|
85
- doc.database.should eql(db)
85
+ expect(doc.database).to eql(db)
86
86
  end
87
87
  end
88
88
 
89
89
  it 'does not write itself to a document that has no database= method' do
90
- doc1 = stub(:doc1)
91
- doc1.stub(:respond_to?).with(:database=) { false }
92
- couchrest_db.stub(:bulk_load) do
90
+ doc1 = double(:doc1)
91
+ allow(doc1).to receive(:respond_to?).with(:database=) { false }
92
+ allow(couchrest_db).to receive(:bulk_load) do
93
93
  {"rows" => [{'doc' => doc1}]}
94
94
  end
95
95
 
96
- doc1.should_not_receive(:database=)
96
+ expect(doc1).not_to receive(:database=)
97
97
 
98
98
  db.load(['1'])
99
99
  end
@@ -102,19 +102,19 @@ end
102
102
 
103
103
  describe CouchPotato::Database, 'load!' do
104
104
 
105
- let(:db) { CouchPotato::Database.new(stub('couchrest db', :info => nil).as_null_object) }
105
+ let(:db) { CouchPotato::Database.new(double('couchrest db', :info => nil).as_null_object) }
106
106
 
107
107
  it "should raise an error if no document found" do
108
- db.couchrest_database.stub(:get).and_raise(RestClient::ResourceNotFound)
109
- lambda {
108
+ allow(db.couchrest_database).to receive(:get).and_return(nil)
109
+ expect {
110
110
  db.load! '1'
111
- }.should raise_error(CouchPotato::NotFound)
111
+ }.to raise_error(CouchPotato::NotFound)
112
112
  end
113
113
 
114
114
  it 'returns the found document' do
115
- doc = stub(:doc).as_null_object
116
- db.couchrest_database.stub(:get) {doc}
117
- db.load!('1').should == doc
115
+ doc = double(:doc).as_null_object
116
+ allow(db.couchrest_database).to receive(:get) {doc}
117
+ expect(db.load!('1')).to eq(doc)
118
118
  end
119
119
 
120
120
  context "when several ids given" do
@@ -127,33 +127,33 @@ describe CouchPotato::Database, 'load!' do
127
127
  end
128
128
 
129
129
  before(:each) do
130
- db.stub(:load).and_return(docs)
130
+ allow(db).to receive(:load).and_return(docs)
131
131
  end
132
132
 
133
133
  it "raises an exception when not all documents could be found" do
134
- lambda {
134
+ expect {
135
135
  db.load! ['1', '2', '3', '4']
136
- }.should raise_error(CouchPotato::NotFound, '3, 4')
136
+ }.to raise_error(CouchPotato::NotFound, '3, 4')
137
137
  end
138
138
 
139
139
  it "raises no exception when all documents are found" do
140
140
  docs << DbTestUser.new(:id => '3')
141
- lambda {
141
+ expect {
142
142
  db.load! ['1', '2', '3']
143
- }.should_not raise_error(CouchPotato::NotFound)
143
+ }.not_to raise_error
144
144
  end
145
145
  end
146
146
  end
147
147
 
148
148
  describe CouchPotato::Database, 'save_document' do
149
149
  before(:each) do
150
- @db = CouchPotato::Database.new(stub('couchrest db').as_null_object)
150
+ @db = CouchPotato::Database.new(double('couchrest db').as_null_object)
151
151
  end
152
152
 
153
153
  it "should set itself on the model for a new object before doing anything else" do
154
- @db.stub(:valid_document?).and_return false
155
- user = stub('user', :new? => true).as_null_object
156
- user.should_receive(:database=).with(@db)
154
+ allow(@db).to receive(:valid_document?).and_return false
155
+ user = double('user', :new? => true).as_null_object
156
+ expect(user).to receive(:database=).with(@db)
157
157
  @db.save_document user
158
158
  end
159
159
 
@@ -164,33 +164,33 @@ describe CouchPotato::Database, 'save_document' do
164
164
  end
165
165
 
166
166
  it "should return false when creating a new document and the validations failed" do
167
- CouchPotato.database.save_document(Category.new).should == false
167
+ expect(CouchPotato.database.save_document(Category.new)).to eq(false)
168
168
  end
169
169
 
170
170
  it "should return false when saving an existing document and the validations failed" do
171
171
  category = Category.new(:name => "pizza")
172
- CouchPotato.database.save_document(category).should == true
172
+ expect(CouchPotato.database.save_document(category)).to eq(true)
173
173
  category.name = nil
174
- CouchPotato.database.save_document(category).should == false
174
+ expect(CouchPotato.database.save_document(category)).to eq(false)
175
175
  end
176
176
 
177
177
  describe "when creating with validate options" do
178
178
  it "should not run the validations when saved with false" do
179
179
  category = Category.new
180
180
  @db.save_document(category, false)
181
- category.new?.should == false
181
+ expect(category.new?).to eq(false)
182
182
  end
183
183
 
184
184
  it "should run the validations when saved with true" do
185
185
  category = Category.new
186
186
  @db.save_document(category, true)
187
- category.new?.should == true
187
+ expect(category.new?).to eq(true)
188
188
  end
189
189
 
190
190
  it "should run the validations when saved with default" do
191
191
  category = Category.new
192
192
  @db.save_document(category)
193
- category.new?.should == true
193
+ expect(category.new?).to eq(true)
194
194
  end
195
195
  end
196
196
 
@@ -198,29 +198,29 @@ describe CouchPotato::Database, 'save_document' do
198
198
  it "should not run the validations when saved with false" do
199
199
  category = Category.new(:name => 'food')
200
200
  @db.save_document(category)
201
- category.new?.should be_false
201
+ expect(category.new?).to be_falsey
202
202
  category.name = nil
203
203
  @db.save_document(category, false)
204
- category.dirty?.should be_false
204
+ expect(category.dirty?).to be_falsey
205
205
  end
206
206
 
207
207
  it "should run the validations when saved with true" do
208
208
  category = Category.new(:name => "food")
209
209
  @db.save_document(category)
210
- category.new?.should == false
210
+ expect(category.new?).to eq(false)
211
211
  category.name = nil
212
212
  @db.save_document(category, true)
213
- category.dirty?.should == true
214
- category.valid?.should == false
213
+ expect(category.dirty?).to eq(true)
214
+ expect(category.valid?).to eq(false)
215
215
  end
216
216
 
217
217
  it "should run the validations when saved with default" do
218
218
  category = Category.new(:name => "food")
219
219
  @db.save_document(category)
220
- category.new?.should == false
220
+ expect(category.new?).to eq(false)
221
221
  category.name = nil
222
222
  @db.save_document(category)
223
- category.dirty?.should == true
223
+ expect(category.dirty?).to eq(true)
224
224
  end
225
225
  end
226
226
 
@@ -241,23 +241,23 @@ describe CouchPotato::Database, 'save_document' do
241
241
  it "should keep errors added in before_validation_on_* callbacks when creating a new object" do
242
242
  spock = Vulcan.new(:name => 'spock')
243
243
  @db.save_document(spock)
244
- spock.errors[:validation].should == ['failed']
244
+ expect(spock.errors[:validation]).to eq(['failed'])
245
245
  end
246
246
 
247
247
  it "should keep errors added in before_validation_on_* callbacks when creating a new object" do
248
248
  spock = Vulcan.new(:name => 'spock')
249
249
  @db.save_document(spock, false)
250
- spock.new?.should == false
250
+ expect(spock.new?).to eq(false)
251
251
  spock.name = "spock's father"
252
252
  @db.save_document(spock)
253
- spock.errors[:validation].should == ['failed']
253
+ expect(spock.errors[:validation]).to eq(['failed'])
254
254
  end
255
255
 
256
256
  it "should keep errors generated from normal validations together with errors set in normal validations" do
257
257
  spock = Vulcan.new
258
258
  @db.save_document(spock)
259
- spock.errors[:validation].should == ['failed']
260
- spock.errors[:name].first.should =~ /can't be (empty|blank)/
259
+ expect(spock.errors[:validation]).to eq(['failed'])
260
+ expect(spock.errors[:name].first).to match(/can't be (empty|blank)/)
261
261
  end
262
262
 
263
263
  it "should clear errors on subsequent, valid saves when creating" do
@@ -266,7 +266,7 @@ describe CouchPotato::Database, 'save_document' do
266
266
 
267
267
  spock.name = 'Spock'
268
268
  @db.save_document(spock)
269
- spock.errors[:name].should == []
269
+ expect(spock.errors[:name]).to eq([])
270
270
  end
271
271
 
272
272
  it "should clear errors on subsequent, valid saves when updating" do
@@ -275,11 +275,11 @@ describe CouchPotato::Database, 'save_document' do
275
275
 
276
276
  spock.name = nil
277
277
  @db.save_document(spock)
278
- spock.errors[:name].first.should =~ /can't be (empty|blank)/
278
+ expect(spock.errors[:name].first).to match(/can't be (empty|blank)/)
279
279
 
280
280
  spock.name = 'Spock'
281
281
  @db.save_document(spock)
282
- spock.errors[:name].should == []
282
+ expect(spock.errors[:name]).to eq([])
283
283
  end
284
284
 
285
285
  end
@@ -287,59 +287,59 @@ end
287
287
 
288
288
  describe CouchPotato::Database, 'first' do
289
289
  before(:each) do
290
- @couchrest_db = stub('couchrest db').as_null_object
290
+ @couchrest_db = double('couchrest db').as_null_object
291
291
  @db = CouchPotato::Database.new(@couchrest_db)
292
- @result = stub('result')
293
- @spec = stub('view spec', :process_results => [@result]).as_null_object
294
- CouchPotato::View::ViewQuery.stub(:new => stub('view query', :query_view! => {'rows' => [@result]}))
292
+ @result = double('result')
293
+ @spec = double('view spec', :process_results => [@result]).as_null_object
294
+ allow(CouchPotato::View::ViewQuery).to receive_messages(:new => double('view query', :query_view! => {'rows' => [@result]}))
295
295
  end
296
296
 
297
297
  it "should return the first result from a view query" do
298
- @db.first(@spec).should == @result
298
+ expect(@db.first(@spec)).to eq(@result)
299
299
  end
300
300
 
301
301
  it "should return nil if there are no results" do
302
- @spec.stub(:process_results => [])
303
- @db.first(@spec).should be_nil
302
+ allow(@spec).to receive_messages(:process_results => [])
303
+ expect(@db.first(@spec)).to be_nil
304
304
  end
305
305
  end
306
306
 
307
307
  describe CouchPotato::Database, 'first!' do
308
308
  before(:each) do
309
- @couchrest_db = stub('couchrest db').as_null_object
309
+ @couchrest_db = double('couchrest db').as_null_object
310
310
  @db = CouchPotato::Database.new(@couchrest_db)
311
- @result = stub('result')
312
- @spec = stub('view spec', :process_results => [@result]).as_null_object
313
- CouchPotato::View::ViewQuery.stub(:new => stub('view query', :query_view! => {'rows' => [@result]}))
311
+ @result = double('result')
312
+ @spec = double('view spec', :process_results => [@result]).as_null_object
313
+ allow(CouchPotato::View::ViewQuery).to receive_messages(:new => double('view query', :query_view! => {'rows' => [@result]}))
314
314
  end
315
315
 
316
316
  it "returns the first result from a view query" do
317
- @db.first!(@spec).should == @result
317
+ expect(@db.first!(@spec)).to eq(@result)
318
318
  end
319
319
 
320
320
  it "raises an error if there are no results" do
321
- @spec.stub(:process_results => [])
322
- lambda {
321
+ allow(@spec).to receive_messages(:process_results => [])
322
+ expect {
323
323
  @db.first!(@spec)
324
- }.should raise_error(CouchPotato::NotFound)
324
+ }.to raise_error(CouchPotato::NotFound)
325
325
  end
326
326
  end
327
327
 
328
328
  describe CouchPotato::Database, 'view' do
329
329
  before(:each) do
330
- @couchrest_db = stub('couchrest db').as_null_object
330
+ @couchrest_db = double('couchrest db').as_null_object
331
331
  @db = CouchPotato::Database.new(@couchrest_db)
332
- @result = stub('result')
333
- @spec = stub('view spec', :process_results => [@result]).as_null_object
334
- CouchPotato::View::ViewQuery.stub(:new => stub('view query', :query_view! => {'rows' => [@result]}))
332
+ @result = double('result')
333
+ @spec = double('view spec', :process_results => [@result]).as_null_object
334
+ allow(CouchPotato::View::ViewQuery).to receive_messages(:new => double('view query', :query_view! => {'rows' => [@result]}))
335
335
  end
336
336
 
337
337
  it "initialzes a view query with map/reduce/list/lib funtions" do
338
- @spec.stub(:design_document => 'design_doc', :view_name => 'my_view',
338
+ allow(@spec).to receive_messages(:design_document => 'design_doc', :view_name => 'my_view',
339
339
  :map_function => '<map_code>', :reduce_function => '<reduce_code>',
340
340
  :lib => {:test => '<test_code>'},
341
341
  :list_name => 'my_list', :list_function => '<list_code>', :language => 'javascript')
342
- CouchPotato::View::ViewQuery.should_receive(:new).with(
342
+ expect(CouchPotato::View::ViewQuery).to receive(:new).with(
343
343
  @couchrest_db,
344
344
  'design_doc',
345
345
  {'my_view' => {
@@ -353,11 +353,11 @@ describe CouchPotato::Database, 'view' do
353
353
  end
354
354
 
355
355
  it "initialzes a view query with map/reduce/list funtions" do
356
- @spec.stub(:design_document => 'design_doc', :view_name => 'my_view',
356
+ allow(@spec).to receive_messages(:design_document => 'design_doc', :view_name => 'my_view',
357
357
  :map_function => '<map_code>', :reduce_function => '<reduce_code>',
358
358
  :lib => nil, :list_name => 'my_list', :list_function => '<list_code>',
359
359
  :language => 'javascript')
360
- CouchPotato::View::ViewQuery.should_receive(:new).with(
360
+ expect(CouchPotato::View::ViewQuery).to receive(:new).with(
361
361
  @couchrest_db,
362
362
  'design_doc',
363
363
  {'my_view' => {
@@ -371,11 +371,11 @@ describe CouchPotato::Database, 'view' do
371
371
  end
372
372
 
373
373
  it "initialzes a view query with only map/reduce/lib functions" do
374
- @spec.stub(:design_document => 'design_doc', :view_name => 'my_view',
374
+ allow(@spec).to receive_messages(:design_document => 'design_doc', :view_name => 'my_view',
375
375
  :map_function => '<map_code>', :reduce_function => '<reduce_code>',
376
376
  :list_name => nil, :list_function => nil,
377
- :lib => {:test => '<test_code>'}).as_null_object
378
- CouchPotato::View::ViewQuery.should_receive(:new).with(
377
+ :lib => {:test => '<test_code>'})
378
+ expect(CouchPotato::View::ViewQuery).to receive(:new).with(
379
379
  @couchrest_db,
380
380
  'design_doc',
381
381
  {'my_view' => {
@@ -386,10 +386,10 @@ describe CouchPotato::Database, 'view' do
386
386
  end
387
387
 
388
388
  it "initialzes a view query with only map/reduce functions" do
389
- @spec.stub(:design_document => 'design_doc', :view_name => 'my_view',
389
+ allow(@spec).to receive_messages(:design_document => 'design_doc', :view_name => 'my_view',
390
390
  :map_function => '<map_code>', :reduce_function => '<reduce_code>',
391
- :lib => nil, :list_name => nil, :list_function => nil).as_null_object
392
- CouchPotato::View::ViewQuery.should_receive(:new).with(
391
+ :lib => nil, :list_name => nil, :list_function => nil)
392
+ expect(CouchPotato::View::ViewQuery).to receive(:new).with(
393
393
  @couchrest_db,
394
394
  'design_doc',
395
395
  {'my_view' => {
@@ -400,21 +400,21 @@ describe CouchPotato::Database, 'view' do
400
400
  end
401
401
 
402
402
  it "sets itself on returned results that have an accessor" do
403
- @result.stub(:respond_to?).with(:database=).and_return(true)
404
- @result.should_receive(:database=).with(@db)
403
+ allow(@result).to receive(:respond_to?).with(:database=).and_return(true)
404
+ expect(@result).to receive(:database=).with(@db)
405
405
  @db.view(@spec)
406
406
  end
407
407
 
408
408
  it "does not set itself on returned results that don't have an accessor" do
409
- @result.stub(:respond_to?).with(:database=).and_return(false)
410
- @result.should_not_receive(:database=).with(@db)
409
+ allow(@result).to receive(:respond_to?).with(:database=).and_return(false)
410
+ expect(@result).not_to receive(:database=).with(@db)
411
411
  @db.view(@spec)
412
412
  end
413
413
 
414
414
  it "does not try to set itself on result sets that are not collections" do
415
- lambda {
416
- @spec.stub(:process_results => 1)
417
- }.should_not raise_error
415
+ expect {
416
+ allow(@spec).to receive_messages(:process_results => 1)
417
+ }.not_to raise_error
418
418
 
419
419
  @db.view(@spec)
420
420
  end
@@ -423,10 +423,10 @@ end
423
423
  describe CouchPotato::Database, '#destroy' do
424
424
  it 'does not try to delete an already deleted document' do
425
425
  couchrest_db = double(:couchrest_db)
426
- couchrest_db.stub(:delete_doc).and_raise(RestClient::Conflict)
426
+ allow(couchrest_db).to receive(:delete_doc).and_raise(CouchRest::Conflict)
427
427
  db = CouchPotato::Database.new couchrest_db
428
428
  document = double(:document, reload: nil).as_null_object
429
- document.stub(:run_callbacks).and_yield
429
+ allow(document).to receive(:run_callbacks).and_yield
430
430
 
431
431
  expect {
432
432
  db.destroy document