couchrest 1.2.1 → 2.0.0.beta1
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.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +1 -0
- data/README.md +11 -7
- data/VERSION +1 -1
- data/couchrest.gemspec +7 -6
- data/history.txt +8 -0
- data/lib/couchrest.rb +26 -31
- data/lib/couchrest/connection.rb +251 -0
- data/lib/couchrest/database.rb +75 -79
- data/lib/couchrest/design.rb +1 -1
- data/lib/couchrest/exceptions.rb +108 -0
- data/lib/couchrest/helper/pager.rb +3 -1
- data/lib/couchrest/helper/stream_row_parser.rb +93 -0
- data/lib/couchrest/rest_api.rb +33 -134
- data/lib/couchrest/server.rb +34 -47
- data/spec/couchrest/connection_spec.rb +415 -0
- data/spec/couchrest/couchrest_spec.rb +61 -67
- data/spec/couchrest/database_spec.rb +151 -147
- data/spec/couchrest/design_spec.rb +28 -28
- data/spec/couchrest/document_spec.rb +72 -70
- data/spec/couchrest/exceptions_spec.rb +74 -0
- data/spec/couchrest/helpers/pager_spec.rb +22 -22
- data/spec/couchrest/helpers/stream_row_parser_spec.rb +154 -0
- data/spec/couchrest/rest_api_spec.rb +44 -208
- data/spec/couchrest/server_spec.rb +0 -29
- data/spec/spec_helper.rb +11 -6
- metadata +31 -17
- data/lib/couchrest/helper/streamer.rb +0 -63
- data/lib/couchrest/monkeypatches.rb +0 -25
- data/spec/couchrest/helpers/streamer_spec.rb +0 -134
@@ -16,146 +16,151 @@ describe CouchRest do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
+
let :mock_server do
|
20
|
+
CouchRest.new("http://mock")
|
21
|
+
end
|
22
|
+
|
19
23
|
describe "getting info" do
|
20
24
|
it "should list databases" do
|
21
|
-
@cr.databases.
|
25
|
+
expect(@cr.databases).to be_an_instance_of(Array)
|
22
26
|
end
|
23
27
|
it "should get info" do
|
24
|
-
@cr.info["couchdb"].
|
25
|
-
@cr.info.class.
|
28
|
+
expect(@cr.info["couchdb"]).to eq "Welcome"
|
29
|
+
expect(@cr.info.class).to eq Hash
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
29
33
|
it "should restart" do
|
30
34
|
# we really do not need to perform a proper restart!
|
31
|
-
|
32
|
-
|
35
|
+
stub_request(:post, "http://mock/_restart")
|
36
|
+
.to_return(:body => "{\"ok\":true}")
|
37
|
+
mock_server.restart!
|
33
38
|
end
|
34
39
|
|
35
40
|
it "should provide one-time access to uuids" do
|
36
|
-
@cr.next_uuid.
|
41
|
+
expect(@cr.next_uuid).not_to be_nil
|
37
42
|
end
|
38
43
|
|
39
44
|
describe "initializing a database" do
|
40
45
|
it "should return a db" do
|
41
46
|
db = @cr.database(TESTDB)
|
42
|
-
db.
|
43
|
-
db.
|
47
|
+
expect(db).to be_an_instance_of(CouchRest::Database)
|
48
|
+
expect(db.uri).to eq(@cr.uri + TESTDB)
|
44
49
|
end
|
45
50
|
end
|
46
51
|
|
47
52
|
describe "parsing urls" do
|
48
53
|
it "should parse just a dbname" do
|
49
54
|
db = CouchRest.parse "my-db"
|
50
|
-
db[:database].
|
51
|
-
db[:host].
|
55
|
+
expect(db[:database]).to eq "my-db"
|
56
|
+
expect(db[:host]).to eq "http://127.0.0.1:5984"
|
52
57
|
end
|
53
58
|
it "should parse a host and db" do
|
54
59
|
db = CouchRest.parse "127.0.0.1/my-db"
|
55
|
-
db[:database].
|
56
|
-
db[:host].
|
60
|
+
expect(db[:database]).to eq "my-db"
|
61
|
+
expect(db[:host]).to eq "http://127.0.0.1"
|
57
62
|
end
|
58
63
|
it "should parse a host and db with http" do
|
59
64
|
db = CouchRest.parse "http://127.0.0.1/my-db"
|
60
|
-
db[:database].
|
61
|
-
db[:host].
|
65
|
+
expect(db[:database]).to eq "my-db"
|
66
|
+
expect(db[:host]).to eq "http://127.0.0.1"
|
62
67
|
end
|
63
68
|
it "should parse a host and db with https" do
|
64
69
|
db = CouchRest.parse "https://127.0.0.1/my-db"
|
65
|
-
db[:database].
|
66
|
-
db[:host].
|
70
|
+
expect(db[:database]).to eq "my-db"
|
71
|
+
expect(db[:host]).to eq "https://127.0.0.1"
|
67
72
|
end
|
68
73
|
it "should parse a host with a port and db" do
|
69
74
|
db = CouchRest.parse "127.0.0.1:5555/my-db"
|
70
|
-
db[:database].
|
71
|
-
db[:host].
|
75
|
+
expect(db[:database]).to eq "my-db"
|
76
|
+
expect(db[:host]).to eq "http://127.0.0.1:5555"
|
72
77
|
end
|
73
78
|
it "should parse a host with a port and db with http" do
|
74
79
|
db = CouchRest.parse "http://127.0.0.1:5555/my-db"
|
75
|
-
db[:database].
|
76
|
-
db[:host].
|
80
|
+
expect(db[:database]).to eq "my-db"
|
81
|
+
expect(db[:host]).to eq "http://127.0.0.1:5555"
|
77
82
|
end
|
78
83
|
it "should parse a host with a port and db with https" do
|
79
84
|
db = CouchRest.parse "https://127.0.0.1:5555/my-db"
|
80
|
-
db[:database].
|
81
|
-
db[:host].
|
85
|
+
expect(db[:database]).to eq "my-db"
|
86
|
+
expect(db[:host]).to eq "https://127.0.0.1:5555"
|
82
87
|
end
|
83
88
|
it "should parse just a host" do
|
84
89
|
db = CouchRest.parse "http://127.0.0.1:5555/"
|
85
|
-
db[:database].
|
86
|
-
db[:host].
|
90
|
+
expect(db[:database]).to be_nil
|
91
|
+
expect(db[:host]).to eq "http://127.0.0.1:5555"
|
87
92
|
end
|
88
93
|
it "should parse just a host with https" do
|
89
94
|
db = CouchRest.parse "https://127.0.0.1:5555/"
|
90
|
-
db[:database].
|
91
|
-
db[:host].
|
95
|
+
expect(db[:database]).to be_nil
|
96
|
+
expect(db[:host]).to eq "https://127.0.0.1:5555"
|
92
97
|
end
|
93
98
|
it "should parse just a host no slash" do
|
94
99
|
db = CouchRest.parse "http://127.0.0.1:5555"
|
95
|
-
db[:host].
|
96
|
-
db[:database].
|
100
|
+
expect(db[:host]).to eq "http://127.0.0.1:5555"
|
101
|
+
expect(db[:database]).to be_nil
|
97
102
|
end
|
98
103
|
it "should parse just a host no slash and https" do
|
99
104
|
db = CouchRest.parse "https://127.0.0.1:5555"
|
100
|
-
db[:host].
|
101
|
-
db[:database].
|
105
|
+
expect(db[:host]).to eq "https://127.0.0.1:5555"
|
106
|
+
expect(db[:database]).to be_nil
|
102
107
|
end
|
103
108
|
it "should get docid" do
|
104
109
|
db = CouchRest.parse "127.0.0.1:5555/my-db/my-doc"
|
105
|
-
db[:database].
|
106
|
-
db[:host].
|
107
|
-
db[:doc].
|
110
|
+
expect(db[:database]).to eq "my-db"
|
111
|
+
expect(db[:host]).to eq "http://127.0.0.1:5555"
|
112
|
+
expect(db[:doc]).to eq "my-doc"
|
108
113
|
end
|
109
114
|
it "should get docid with http" do
|
110
115
|
db = CouchRest.parse "http://127.0.0.1:5555/my-db/my-doc"
|
111
|
-
db[:database].
|
112
|
-
db[:host].
|
113
|
-
db[:doc].
|
116
|
+
expect(db[:database]).to eq "my-db"
|
117
|
+
expect(db[:host]).to eq "http://127.0.0.1:5555"
|
118
|
+
expect(db[:doc]).to eq "my-doc"
|
114
119
|
end
|
115
120
|
it "should get docid with https" do
|
116
121
|
db = CouchRest.parse "https://127.0.0.1:5555/my-db/my-doc"
|
117
|
-
db[:database].
|
118
|
-
db[:host].
|
119
|
-
db[:doc].
|
122
|
+
expect(db[:database]).to eq "my-db"
|
123
|
+
expect(db[:host]).to eq "https://127.0.0.1:5555"
|
124
|
+
expect(db[:doc]).to eq "my-doc"
|
120
125
|
end
|
121
126
|
end
|
122
127
|
|
123
128
|
describe "easy initializing a database adapter" do
|
124
129
|
it "should be possible without an explicit CouchRest instantiation" do
|
125
130
|
db = CouchRest.database "http://127.0.0.1:5984/couchrest-test"
|
126
|
-
db.
|
127
|
-
db.
|
131
|
+
expect(db).to be_an_instance_of(CouchRest::Database)
|
132
|
+
expect(db.uri.to_s).to eq "http://127.0.0.1:5984/couchrest-test"
|
128
133
|
end
|
129
134
|
# TODO add https support (need test environment...)
|
130
135
|
# it "should work with https" # do
|
131
136
|
# db = CouchRest.database "https://127.0.0.1:5984/couchrest-test"
|
132
|
-
# db.host.
|
137
|
+
# expect(db.host).to eq "https://127.0.0.1:5984"
|
133
138
|
# end
|
134
139
|
it "should not create the database automatically" do
|
135
140
|
db = CouchRest.database "http://127.0.0.1:5984/couchrest-test"
|
136
|
-
lambda{db.info}.
|
141
|
+
expect(lambda{db.info}).to raise_error(CouchRest::NotFound)
|
137
142
|
end
|
138
143
|
end
|
139
144
|
|
140
145
|
describe "ensuring the db exists" do
|
141
146
|
it "should be super easy" do
|
142
147
|
db = CouchRest.database! "#{COUCHHOST}/couchrest-test-2"
|
143
|
-
db.name.
|
144
|
-
db.info["db_name"].
|
148
|
+
expect(db.name).to eq 'couchrest-test-2'
|
149
|
+
expect(db.info["db_name"]).to eq 'couchrest-test-2'
|
145
150
|
end
|
146
151
|
end
|
147
152
|
|
148
153
|
describe "successfully creating a database" do
|
149
154
|
it "should start without a database" do
|
150
|
-
@cr.databases.
|
155
|
+
expect(@cr.databases).not_to include(TESTDB)
|
151
156
|
end
|
152
157
|
it "should return the created database" do
|
153
158
|
db = @cr.create_db(TESTDB)
|
154
|
-
db.
|
159
|
+
expect(db).to be_an_instance_of(CouchRest::Database)
|
155
160
|
end
|
156
161
|
it "should create the database" do
|
157
162
|
db = @cr.create_db(TESTDB)
|
158
|
-
@cr.databases.
|
163
|
+
expect(@cr.databases).to include(TESTDB)
|
159
164
|
end
|
160
165
|
end
|
161
166
|
|
@@ -164,34 +169,23 @@ describe CouchRest do
|
|
164
169
|
db = @cr.create_db(TESTDB)
|
165
170
|
end
|
166
171
|
it "should start with the test database" do
|
167
|
-
@cr.databases.
|
172
|
+
expect(@cr.databases).to include(TESTDB)
|
168
173
|
end
|
169
174
|
it "should PUT the database and raise an error" do
|
170
|
-
|
175
|
+
expect {
|
171
176
|
@cr.create_db(TESTDB)
|
172
|
-
}.
|
177
|
+
}.to raise_error(CouchRest::PreconditionFailed)
|
173
178
|
end
|
174
179
|
end
|
175
180
|
|
176
|
-
describe "using a proxy for
|
177
|
-
it "should set proxy url
|
181
|
+
describe "using a proxy for connections" do
|
182
|
+
it "should set proxy url" do
|
178
183
|
CouchRest.proxy 'http://localhost:8888/'
|
179
|
-
proxy_uri = URI.parse(
|
180
|
-
proxy_uri.host.
|
181
|
-
proxy_uri.port.
|
184
|
+
proxy_uri = URI.parse(CouchRest::Connection.proxy)
|
185
|
+
expect(proxy_uri.host).to eql( 'localhost' )
|
186
|
+
expect(proxy_uri.port).to eql( 8888 )
|
182
187
|
CouchRest.proxy nil
|
183
188
|
end
|
184
189
|
end
|
185
190
|
|
186
|
-
describe "Including old ExtendedDocument library" do
|
187
|
-
|
188
|
-
it "should raise an exception" do
|
189
|
-
lambda do
|
190
|
-
class TestDoc < CouchRest::ExtendedDocument
|
191
|
-
attr_reader :fail
|
192
|
-
end
|
193
|
-
end.should raise_error(RuntimeError)
|
194
|
-
end
|
195
|
-
|
196
|
-
end
|
197
191
|
end
|
@@ -4,22 +4,24 @@ describe CouchRest::Database do
|
|
4
4
|
before(:each) do
|
5
5
|
@cr = CouchRest.new(COUCHHOST)
|
6
6
|
@db = @cr.database(TESTDB)
|
7
|
-
@db.delete! rescue
|
7
|
+
@db.delete! rescue CouchRest::NotFound
|
8
8
|
@db = @cr.create_db(TESTDB) # rescue nil
|
9
9
|
end
|
10
10
|
|
11
11
|
describe "database name including slash" do
|
12
12
|
it "should escape the name in the URI" do
|
13
13
|
db = @cr.database("foo/bar")
|
14
|
-
db.name.
|
15
|
-
db.root.
|
16
|
-
db.uri.
|
14
|
+
expect(db.name).to eq "foo/bar"
|
15
|
+
expect(db.root).to eq URI("#{COUCHHOST}/foo%2Fbar")
|
16
|
+
expect(db.uri).to eq URI("#{COUCHHOST}/foo%2Fbar")
|
17
|
+
expect(db.to_s).to eq "#{COUCHHOST}/foo%2Fbar"
|
18
|
+
expect(db.path).to eq "/foo%2Fbar"
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
22
|
describe "#info" do
|
21
23
|
it "should request basic database data" do
|
22
|
-
@db.info['db_name'].
|
24
|
+
expect(@db.info['db_name']).to eql(TESTDB)
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
@@ -34,23 +36,23 @@ describe CouchRest::Database do
|
|
34
36
|
end
|
35
37
|
it "should return the result of the temporary function" do
|
36
38
|
rs = @db.temp_view(@temp_view)
|
37
|
-
rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length.
|
39
|
+
expect(rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length).to eq 1
|
38
40
|
end
|
39
41
|
it "should work with a range" do
|
40
42
|
rs = @db.temp_view(@temp_view, :startkey => "b", :endkey => "z")
|
41
|
-
rs['rows'].length.
|
43
|
+
expect(rs['rows'].length).to eq 2
|
42
44
|
end
|
43
45
|
it "should work with a key" do
|
44
46
|
rs = @db.temp_view(@temp_view, :key => "wild")
|
45
|
-
rs['rows'].length.
|
47
|
+
expect(rs['rows'].length).to eq 1
|
46
48
|
end
|
47
49
|
it "should work with a limit" do
|
48
50
|
rs = @db.temp_view(@temp_view, :limit => 1)
|
49
|
-
rs['rows'].length.
|
51
|
+
expect(rs['rows'].length).to eq 1
|
50
52
|
end
|
51
53
|
it "should work with multi-keys" do
|
52
54
|
rs = @db.temp_view(@temp_view, :keys => ["another", "wild"])
|
53
|
-
rs['rows'].length.
|
55
|
+
expect(rs['rows'].length).to eq 2
|
54
56
|
end
|
55
57
|
end
|
56
58
|
|
@@ -64,8 +66,8 @@ describe CouchRest::Database do
|
|
64
66
|
end
|
65
67
|
it "should return the result of the temporary function" do
|
66
68
|
rs = @db.temp_view(:map => "function(doc){emit(doc.beverage, doc.count)}", :reduce => "function(beverage,counts){return sum(counts)}")
|
67
|
-
# rs.
|
68
|
-
rs['rows'][0]['value'].
|
69
|
+
# expect(rs).to eq 'x'
|
70
|
+
expect(rs['rows'][0]['value']).to eq 9
|
69
71
|
end
|
70
72
|
end
|
71
73
|
|
@@ -91,10 +93,10 @@ describe CouchRest::Database do
|
|
91
93
|
{"word" => "and again"}
|
92
94
|
])
|
93
95
|
r = @db.view('test/test')
|
94
|
-
r['total_rows'].
|
96
|
+
expect(r['total_rows']).to eq 1
|
95
97
|
end
|
96
98
|
it "should round trip" do
|
97
|
-
@db.get("_design/test")['views'].
|
99
|
+
expect(@db.get("_design/test")['views']).to eq @view
|
98
100
|
end
|
99
101
|
end
|
100
102
|
|
@@ -115,60 +117,60 @@ describe CouchRest::Database do
|
|
115
117
|
])
|
116
118
|
end
|
117
119
|
it "should have the view" do
|
118
|
-
@db.get('_design/first')['views']['test']['map'].
|
120
|
+
expect(@db.get('_design/first')['views']['test']['map']).to include("for(var w in doc)")
|
119
121
|
end
|
120
122
|
it "should list from the view" do
|
121
123
|
rs = @db.view('first/test')
|
122
|
-
rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length.
|
124
|
+
expect(rs['rows'].select{|r|r['key'] == 'wild' && r['value'] == 'and random'}.length).to eq 1
|
123
125
|
end
|
124
126
|
it "should work with a range" do
|
125
127
|
rs = @db.view('first/test', :startkey => "b", :endkey => "z")
|
126
|
-
rs['rows'].length.
|
128
|
+
expect(rs['rows'].length).to eq 2
|
127
129
|
end
|
128
130
|
it "should work with a key" do
|
129
131
|
rs = @db.view('first/test', :key => "wild")
|
130
|
-
rs['rows'].length.
|
132
|
+
expect(rs['rows'].length).to eq 1
|
131
133
|
end
|
132
134
|
it "should work with a limit" do
|
133
135
|
rs = @db.view('first/test', :limit => 1)
|
134
|
-
rs['rows'].length.
|
136
|
+
expect(rs['rows'].length).to eq 1
|
135
137
|
end
|
136
138
|
it "should work with multi-keys" do
|
137
139
|
rs = @db.view('first/test', :keys => ["another", "wild"])
|
138
|
-
rs['rows'].length.
|
140
|
+
expect(rs['rows'].length).to eq 2
|
139
141
|
end
|
140
142
|
it "should not modify given params" do
|
141
143
|
original_params = {:keys => ["another", "wild"]}
|
142
144
|
params = original_params.dup
|
143
|
-
|
144
|
-
params.
|
145
|
+
@db.view('first/test', params)
|
146
|
+
expect(params).to eq original_params
|
145
147
|
end
|
146
148
|
it "should accept a block" do
|
147
149
|
rows = []
|
148
150
|
rs = @db.view('first/test', :include_docs => true) do |row|
|
149
151
|
rows << row
|
150
152
|
end
|
151
|
-
rows.length.
|
152
|
-
rs["total_rows"].
|
153
|
+
expect(rows.length).to eq 3
|
154
|
+
expect(rs["total_rows"]).to eq 3
|
153
155
|
end
|
154
156
|
it "should accept a block with several params" do
|
155
157
|
rows = []
|
156
158
|
rs = @db.view('first/test', :include_docs => true, :limit => 2) do |row|
|
157
159
|
rows << row
|
158
160
|
end
|
159
|
-
rows.length.
|
161
|
+
expect(rows.length).to eq 2
|
160
162
|
end
|
161
163
|
it "should accept a payload" do
|
162
164
|
rs = @db.view('first/test', {}, :keys => ["another", "wild"])
|
163
|
-
rs['rows'].length.
|
165
|
+
expect(rs['rows'].length).to eq 2
|
164
166
|
end
|
165
167
|
it "should accept a payload with block" do
|
166
168
|
rows = []
|
167
169
|
rs = @db.view('first/test', {:include_docs => true}, :keys => ["another", "wild"]) do |row|
|
168
170
|
rows << row
|
169
171
|
end
|
170
|
-
rows.length.
|
171
|
-
rows.first['doc']['another'].
|
172
|
+
expect(rows.length).to eq 2
|
173
|
+
expect(rows.first['doc']['another']).not_to be_empty
|
172
174
|
end
|
173
175
|
end
|
174
176
|
|
@@ -186,25 +188,25 @@ describe CouchRest::Database do
|
|
186
188
|
|
187
189
|
it "should produce a basic list of changes" do
|
188
190
|
c = @db.changes
|
189
|
-
c['results'].length.
|
191
|
+
expect(c['results'].length).to eql(3)
|
190
192
|
end
|
191
193
|
|
192
194
|
it "should include all changes in continuous feed" do
|
193
195
|
changes = []
|
194
196
|
begin
|
195
|
-
|
197
|
+
@db.changes("feed" => "continuous", "since" => "0") do |change|
|
196
198
|
changes << change
|
197
199
|
raise RuntimeError.new # escape from infinite loop
|
198
200
|
end
|
199
201
|
rescue RuntimeError
|
200
202
|
end
|
201
|
-
changes.first["seq"].
|
203
|
+
expect(changes.first["seq"]).to eql(1)
|
202
204
|
end
|
203
205
|
|
204
206
|
it "should provide id of last document" do
|
205
207
|
c = @db.changes
|
206
208
|
doc = @db.get(c['results'].last['id'])
|
207
|
-
doc['another'].
|
209
|
+
expect(doc['another']).not_to be_empty
|
208
210
|
end
|
209
211
|
end
|
210
212
|
|
@@ -216,10 +218,10 @@ describe CouchRest::Database do
|
|
216
218
|
end
|
217
219
|
it "should get the document" do
|
218
220
|
doc = @db.get(@r['id'])
|
219
|
-
doc['lemons'].
|
221
|
+
expect(doc['lemons']).to eq 'from texas'
|
220
222
|
end
|
221
223
|
it "should work with a funky id" do
|
222
|
-
@db.get(@docid)['will-exist'].
|
224
|
+
expect(@db.get(@docid)['will-exist']).to eq 'here'
|
223
225
|
end
|
224
226
|
end
|
225
227
|
|
@@ -231,16 +233,17 @@ describe CouchRest::Database do
|
|
231
233
|
{"another" => ["set","of","keys"]}
|
232
234
|
])
|
233
235
|
rs.each do |r|
|
234
|
-
@db.get(r['id']).rev.
|
236
|
+
expect(@db.get(r['id']).rev).to eq r["rev"]
|
235
237
|
end
|
236
238
|
end
|
237
239
|
|
238
240
|
it "should use uuids when ids aren't provided" do
|
239
|
-
@db.server.stub
|
241
|
+
@db.server.stub(:next_uuid).and_return('asdf6sgadkfhgsdfusdf')
|
240
242
|
|
241
243
|
docs = [{'key' => 'value'}, {'_id' => 'totally-uniq'}]
|
242
244
|
id_docs = [{'key' => 'value', '_id' => 'asdf6sgadkfhgsdfusdf'}, {'_id' => 'totally-uniq'}]
|
243
|
-
|
245
|
+
|
246
|
+
expect(@db.connection).to receive(:post).with("/couchrest-test/_bulk_docs", {:docs => id_docs})
|
244
247
|
|
245
248
|
@db.bulk_save(docs)
|
246
249
|
end
|
@@ -252,22 +255,22 @@ describe CouchRest::Database do
|
|
252
255
|
{"another" => ["set","of","keys"]}
|
253
256
|
])
|
254
257
|
rs.each do |r|
|
255
|
-
@db.get(r['id']).rev.
|
258
|
+
expect(@db.get(r['id']).rev).to eq r["rev"]
|
256
259
|
end
|
257
260
|
end
|
258
261
|
|
259
262
|
it "should empty the bulk save cache if no documents are given" do
|
260
263
|
@db.save_doc({"_id" => "bulk_cache_1", "val" => "test"}, true)
|
261
|
-
|
264
|
+
expect do
|
262
265
|
@db.get('bulk_cache_1')
|
263
|
-
end.
|
266
|
+
end.to raise_error(CouchRest::NotFound)
|
264
267
|
@db.bulk_save
|
265
|
-
@db.get("bulk_cache_1")["val"].
|
268
|
+
expect(@db.get("bulk_cache_1")["val"]).to eq "test"
|
266
269
|
end
|
267
270
|
|
268
271
|
it "should make an atomic write when all_or_nothing is set" do
|
269
272
|
docs = [{"_id" => "oneB", "wild" => "and random"}, {"_id" => "twoB", "mild" => "yet local"}]
|
270
|
-
|
273
|
+
expect(@db.connection).to receive(:post).with("/couchrest-test/_bulk_docs", {:all_or_nothing => true, :docs => docs})
|
271
274
|
|
272
275
|
@db.bulk_save(docs, false, true)
|
273
276
|
end
|
@@ -280,25 +283,25 @@ describe CouchRest::Database do
|
|
280
283
|
{"_id" => "free", "mild" => "yet local"},
|
281
284
|
{"another" => ["set","of","keys"]}
|
282
285
|
])
|
283
|
-
rescue
|
286
|
+
rescue CouchRest::RequestFailed => e
|
284
287
|
# soon CouchDB will provide _which_ docs conflicted
|
285
|
-
MultiJson.decode(e.response.body)['error'].
|
288
|
+
expect(MultiJson.decode(e.response.body)['error']).to eq 'conflict'
|
286
289
|
end
|
287
290
|
end
|
288
291
|
end
|
289
292
|
|
290
293
|
describe "new document without an id" do
|
291
294
|
it "should start empty" do
|
292
|
-
@db.documents["total_rows"].
|
295
|
+
expect(@db.documents["total_rows"]).to eq 0
|
293
296
|
end
|
294
297
|
it "should create the document and return the id" do
|
295
298
|
r = @db.save_doc({'lemons' => 'from texas', 'and' => 'spain'})
|
296
299
|
r2 = @db.get(r['id'])
|
297
|
-
r2["lemons"].
|
300
|
+
expect(r2["lemons"]).to eq "from texas"
|
298
301
|
end
|
299
302
|
it "should use PUT with UUIDs" do
|
300
|
-
|
301
|
-
r = @db.save_doc({'just' => ['another document']})
|
303
|
+
expect(@db.connection).to receive(:put).and_return({"ok" => true, "id" => "100", "rev" => "55"})
|
304
|
+
r = @db.save_doc({'just' => ['another document']})
|
302
305
|
end
|
303
306
|
|
304
307
|
end
|
@@ -321,11 +324,11 @@ describe CouchRest::Database do
|
|
321
324
|
|
322
325
|
# Depreacated
|
323
326
|
# it "should get the attachment with the doc's _id" do
|
324
|
-
# @db.fetch_attachment("mydocwithattachment", "test.html").
|
327
|
+
# expect(@db.fetch_attachment("mydocwithattachment", "test.html")).to eq @attach
|
325
328
|
# end
|
326
329
|
|
327
330
|
it "should get the attachment with the doc itself" do
|
328
|
-
@db.fetch_attachment(@db.get('mydocwithattachment'), 'test.html').
|
331
|
+
expect(@db.fetch_attachment(@db.get('mydocwithattachment'), 'test.html')).to eq @attach
|
329
332
|
end
|
330
333
|
end
|
331
334
|
|
@@ -339,12 +342,12 @@ describe CouchRest::Database do
|
|
339
342
|
end
|
340
343
|
it "should save the attachment to a new doc" do
|
341
344
|
r = @db.put_attachment({'_id' => 'attach-this'}, 'couchdb.png', image = @file.read, {:content_type => 'image/png'})
|
342
|
-
r['ok'].
|
345
|
+
expect(r['ok']).to be_true
|
343
346
|
doc = @db.get("attach-this")
|
344
347
|
attachment = @db.fetch_attachment(doc, "couchdb.png")
|
345
|
-
(attachment == image).
|
348
|
+
expect((attachment == image)).to be_true
|
346
349
|
#if attachment.respond_to?(:net_http_res)
|
347
|
-
# attachment.net_http_res.body.
|
350
|
+
# expect(attachment.net_http_res.body).to eq image
|
348
351
|
#end
|
349
352
|
end
|
350
353
|
end
|
@@ -366,11 +369,11 @@ describe CouchRest::Database do
|
|
366
369
|
@doc = @db.get("mydocwithattachment")
|
367
370
|
end
|
368
371
|
it "should save and be indicated" do
|
369
|
-
@doc['_attachments']['test.html']['length'].
|
372
|
+
expect(@doc['_attachments']['test.html']['length']).to eq @attach.length
|
370
373
|
end
|
371
374
|
it "should be there" do
|
372
375
|
attachment = @db.fetch_attachment(@doc,"test.html")
|
373
|
-
attachment.
|
376
|
+
expect(attachment).to eq @attach
|
374
377
|
end
|
375
378
|
end
|
376
379
|
|
@@ -387,15 +390,15 @@ describe CouchRest::Database do
|
|
387
390
|
}
|
388
391
|
}
|
389
392
|
@db.save_doc(doc)
|
390
|
-
doc['_rev'].
|
393
|
+
expect(doc['_rev']).not_to be_nil
|
391
394
|
doc['field'] << 'another value'
|
392
|
-
@db.save_doc(doc)["ok"].
|
395
|
+
expect(@db.save_doc(doc)["ok"]).to be_true
|
393
396
|
end
|
394
397
|
|
395
398
|
it 'should be there' do
|
396
399
|
doc = @db.get('mydocwithattachment')
|
397
400
|
attachment = @db.fetch_attachment(doc, 'test.html')
|
398
|
-
Base64.decode64(attachment).
|
401
|
+
expect(Base64.decode64(attachment)).to eq @attach
|
399
402
|
end
|
400
403
|
end
|
401
404
|
|
@@ -421,16 +424,16 @@ describe CouchRest::Database do
|
|
421
424
|
@doc = @db.get("mydocwithattachment")
|
422
425
|
end
|
423
426
|
it "should save and be indicated" do
|
424
|
-
@doc['_attachments']['test.html']['length'].
|
425
|
-
@doc['_attachments']['other.html']['length'].
|
427
|
+
expect(@doc['_attachments']['test.html']['length']).to eq @attach.length
|
428
|
+
expect(@doc['_attachments']['other.html']['length']).to eq @attach2.length
|
426
429
|
end
|
427
430
|
it "should be there" do
|
428
431
|
attachment = @db.fetch_attachment(@doc,"test.html")
|
429
|
-
attachment.
|
432
|
+
expect(attachment).to eq @attach
|
430
433
|
end
|
431
434
|
it "should be there" do
|
432
435
|
attachment = @db.fetch_attachment(@doc,"other.html")
|
433
|
-
attachment.
|
436
|
+
expect(attachment).to eq @attach2
|
434
437
|
end
|
435
438
|
end
|
436
439
|
|
@@ -449,10 +452,10 @@ describe CouchRest::Database do
|
|
449
452
|
@doc = @db.get('mydocwithattachment')
|
450
453
|
end
|
451
454
|
it "should delete the attachment" do
|
452
|
-
lambda { @db.fetch_attachment(@doc,'test.html') }.
|
455
|
+
expect(lambda { @db.fetch_attachment(@doc,'test.html') }).not_to raise_error
|
453
456
|
@db.delete_attachment(@doc, "test.html")
|
454
457
|
@doc = @db.get('mydocwithattachment') # avoid getting a 409
|
455
|
-
lambda{ @db.fetch_attachment(@doc,'test.html')}.
|
458
|
+
expect(lambda{ @db.fetch_attachment(@doc,'test.html')}).to raise_error
|
456
459
|
end
|
457
460
|
|
458
461
|
it "should force a delete even if we get a 409" do
|
@@ -460,8 +463,8 @@ describe CouchRest::Database do
|
|
460
463
|
@db.put_attachment(@doc, 'test', File.open(File.join(FIXTURE_PATH, 'attachments', 'test.html')).read)
|
461
464
|
# at this point the revision number changed, if we try to save doc one more time
|
462
465
|
# we would get a 409.
|
463
|
-
lambda{ @db.save_doc(@doc) }.
|
464
|
-
lambda{ @db.delete_attachment(@doc, "test", true) }.
|
466
|
+
expect(lambda{ @db.save_doc(@doc) }).to raise_error
|
467
|
+
expect(lambda{ @db.delete_attachment(@doc, "test", true) }).not_to raise_error
|
465
468
|
end
|
466
469
|
end
|
467
470
|
|
@@ -481,12 +484,12 @@ describe CouchRest::Database do
|
|
481
484
|
end
|
482
485
|
it "should save and be indicated" do
|
483
486
|
doc = @db.get(@docid)
|
484
|
-
doc['_attachments']['http://example.com/stuff.cgi?things=and%20stuff']['length'].
|
487
|
+
expect(doc['_attachments']['http://example.com/stuff.cgi?things=and%20stuff']['length']).to eq @attach.length
|
485
488
|
end
|
486
489
|
it "should be there" do
|
487
490
|
doc = @db.get(@docid)
|
488
491
|
attachment = @db.fetch_attachment(doc,"http://example.com/stuff.cgi?things=and%20stuff")
|
489
|
-
attachment.
|
492
|
+
expect(attachment).to eq @attach
|
490
493
|
end
|
491
494
|
end
|
492
495
|
|
@@ -494,8 +497,8 @@ describe CouchRest::Database do
|
|
494
497
|
it "should create the document" do
|
495
498
|
@docid = "http://example.com/stuff.cgi?things=and%20stuff"
|
496
499
|
@db.save_doc({'_id' => @docid, 'will-exist' => 'here'})
|
497
|
-
lambda{@db.save_doc({'_id' => @docid})}.
|
498
|
-
@db.get(@docid)['will-exist'].
|
500
|
+
expect(lambda{@db.save_doc({'_id' => @docid})}).to raise_error(CouchRest::RequestFailed)
|
501
|
+
expect(@db.get(@docid)['will-exist']).to eq 'here'
|
499
502
|
end
|
500
503
|
end
|
501
504
|
|
@@ -503,7 +506,7 @@ describe CouchRest::Database do
|
|
503
506
|
it "should start without the document" do
|
504
507
|
# r = @db.save_doc({'lemons' => 'from texas', 'and' => 'spain'})
|
505
508
|
@db.documents['rows'].each do |doc|
|
506
|
-
doc['id'].
|
509
|
+
expect(doc['id']).not_to eq 'my-doc'
|
507
510
|
end
|
508
511
|
# should_not include({'_id' => 'my-doc'})
|
509
512
|
# this needs to be a loop over docs on content with the post
|
@@ -511,7 +514,7 @@ describe CouchRest::Database do
|
|
511
514
|
end
|
512
515
|
it "should create the document" do
|
513
516
|
@db.save_doc({'_id' => 'my-doc', 'will-exist' => 'here'})
|
514
|
-
lambda{@db.save_doc({'_id' => 'my-doc'})}.
|
517
|
+
expect(lambda{@db.save_doc({'_id' => 'my-doc'})}).to raise_error(CouchRest::RequestFailed)
|
515
518
|
end
|
516
519
|
end
|
517
520
|
|
@@ -523,26 +526,26 @@ describe CouchRest::Database do
|
|
523
526
|
@db.save_doc({'_id' => @docid, 'now' => 'save'})
|
524
527
|
end
|
525
528
|
it "should start with the document" do
|
526
|
-
@doc['will-exist'].
|
527
|
-
@db.get(@docid)['now'].
|
529
|
+
expect(@doc['will-exist']).to eq 'here'
|
530
|
+
expect(@db.get(@docid)['now']).to eq 'save'
|
528
531
|
end
|
529
532
|
it "should save with url id" do
|
530
533
|
doc = @db.get(@docid)
|
531
534
|
doc['yaml'] = ['json', 'word.']
|
532
535
|
@db.save_doc doc
|
533
|
-
@db.get(@docid)['yaml'].
|
536
|
+
expect(@db.get(@docid)['yaml']).to eq ['json', 'word.']
|
534
537
|
end
|
535
538
|
it "should fail to resave without the rev" do
|
536
539
|
@doc['them-keys'] = 'huge'
|
537
540
|
@doc['_rev'] = 'wrong'
|
538
541
|
# @db.save_doc(@doc)
|
539
|
-
lambda {@db.save_doc(@doc)}.
|
542
|
+
expect(lambda {@db.save_doc(@doc)}).to raise_error
|
540
543
|
end
|
541
544
|
it "should update the document" do
|
542
545
|
@doc['them-keys'] = 'huge'
|
543
546
|
@db.save_doc(@doc)
|
544
547
|
now = @db.get('my-doc')
|
545
|
-
now['them-keys'].
|
548
|
+
expect(now['them-keys']).to eq 'huge'
|
546
549
|
end
|
547
550
|
end
|
548
551
|
|
@@ -550,7 +553,7 @@ describe CouchRest::Database do
|
|
550
553
|
it "stores documents in a database-specific cache" do
|
551
554
|
td = {"_id" => "btd1", "val" => "test"}
|
552
555
|
@db.save_doc(td, true)
|
553
|
-
@db.instance_variable_get("@bulk_save_cache").
|
556
|
+
expect(@db.instance_variable_get("@bulk_save_cache")).to eq [td]
|
554
557
|
|
555
558
|
end
|
556
559
|
|
@@ -560,17 +563,17 @@ describe CouchRest::Database do
|
|
560
563
|
td2 = {"_id" => "td2", "val" => 4}
|
561
564
|
@db.save_doc(td1, true)
|
562
565
|
@db.save_doc(td2, true)
|
563
|
-
|
566
|
+
expect do
|
564
567
|
@db.get(td1["_id"])
|
565
|
-
end.
|
566
|
-
|
568
|
+
end.to raise_error(CouchRest::NotFound)
|
569
|
+
expect do
|
567
570
|
@db.get(td2["_id"])
|
568
|
-
end.
|
571
|
+
end.to raise_error(CouchRest::NotFound)
|
569
572
|
td3 = {"_id" => "td3", "val" => "foo"}
|
570
573
|
@db.save_doc(td3, true)
|
571
|
-
@db.get(td1["_id"])["val"].
|
572
|
-
@db.get(td2["_id"])["val"].
|
573
|
-
@db.get(td3["_id"])["val"].
|
574
|
+
expect(@db.get(td1["_id"])["val"]).to eq td1["val"]
|
575
|
+
expect(@db.get(td2["_id"])["val"]).to eq td2["val"]
|
576
|
+
expect(@db.get(td3["_id"])["val"]).to eq td3["val"]
|
574
577
|
end
|
575
578
|
|
576
579
|
it "clears the bulk save cache the first time a non bulk save is requested" do
|
@@ -578,12 +581,12 @@ describe CouchRest::Database do
|
|
578
581
|
td2 = {"_id" => "steve", "val" => 3}
|
579
582
|
@db.bulk_save_cache_limit = 50
|
580
583
|
@db.save_doc(td1, true)
|
581
|
-
|
584
|
+
expect do
|
582
585
|
@db.get(td1["_id"])
|
583
|
-
end.
|
586
|
+
end.to raise_error(CouchRest::NotFound)
|
584
587
|
@db.save_doc(td2)
|
585
|
-
@db.get(td1["_id"])["val"].
|
586
|
-
@db.get(td2["_id"])["val"].
|
588
|
+
expect(@db.get(td1["_id"])["val"]).to eq td1["val"]
|
589
|
+
expect(@db.get(td2["_id"])["val"]).to eq td2["val"]
|
587
590
|
end
|
588
591
|
end
|
589
592
|
|
@@ -595,24 +598,24 @@ describe CouchRest::Database do
|
|
595
598
|
end
|
596
599
|
it "should work" do
|
597
600
|
doc = @db.get(@r['id'])
|
598
|
-
doc['and'].
|
601
|
+
expect(doc['and']).to eq 'spain'
|
599
602
|
@db.delete_doc doc
|
600
|
-
lambda{@db.get @r['id']}.
|
603
|
+
expect(lambda{@db.get @r['id']}).to raise_error
|
601
604
|
end
|
602
605
|
it "should work with uri id" do
|
603
606
|
doc = @db.get(@docid)
|
604
607
|
@db.delete_doc doc
|
605
|
-
lambda{@db.get @docid}.
|
608
|
+
expect(lambda{@db.get @docid}).to raise_error
|
606
609
|
end
|
607
610
|
it "should fail without an _id" do
|
608
|
-
lambda{@db.delete_doc({"not"=>"a real doc"})}.
|
611
|
+
expect(lambda{@db.delete_doc({"not"=>"a real doc"})}).to raise_error(ArgumentError)
|
609
612
|
end
|
610
613
|
it "should defer actual deletion when using bulk save" do
|
611
614
|
doc = @db.get(@docid)
|
612
615
|
@db.delete_doc doc, true
|
613
|
-
lambda{@db.get @docid}.
|
616
|
+
expect(lambda{@db.get @docid}).not_to raise_error
|
614
617
|
@db.bulk_save
|
615
|
-
lambda{@db.get @docid}.
|
618
|
+
expect(lambda{@db.get @docid}).to raise_error
|
616
619
|
end
|
617
620
|
|
618
621
|
end
|
@@ -628,10 +631,10 @@ describe CouchRest::Database do
|
|
628
631
|
@db.update_doc @id do |doc|
|
629
632
|
doc['upvotes'] += 1
|
630
633
|
end
|
631
|
-
@db.get(@id)['upvotes'].
|
634
|
+
expect(@db.get(@id)['upvotes']).to eq 11
|
632
635
|
end
|
633
636
|
it "should fail if update_limit is reached" do
|
634
|
-
|
637
|
+
expect do
|
635
638
|
@db.update_doc @id do |doc|
|
636
639
|
# modify and save the doc so that a collision happens
|
637
640
|
conflicting_doc = @db.get @id
|
@@ -641,12 +644,12 @@ describe CouchRest::Database do
|
|
641
644
|
# then try saving it through the update
|
642
645
|
doc['upvotes'] += 1
|
643
646
|
end
|
644
|
-
end.
|
647
|
+
end.to raise_error(CouchRest::RequestFailed)
|
645
648
|
end
|
646
649
|
it "should not fail if update_limit is not reached" do
|
647
650
|
limit = 5
|
648
|
-
|
649
|
-
|
651
|
+
expect do
|
652
|
+
@db.update_doc @id do |doc|
|
650
653
|
# same as the last spec except we're only forcing 5 conflicts
|
651
654
|
if limit > 0
|
652
655
|
conflicting_doc = @db.get @id
|
@@ -657,8 +660,8 @@ describe CouchRest::Database do
|
|
657
660
|
doc['upvotes'] += 1
|
658
661
|
doc
|
659
662
|
end
|
660
|
-
end.
|
661
|
-
@db.get(@id)['upvotes'].
|
663
|
+
end.not_to raise_error
|
664
|
+
expect(@db.get(@id)['upvotes']).to eq 16
|
662
665
|
end
|
663
666
|
end
|
664
667
|
|
@@ -672,10 +675,10 @@ describe CouchRest::Database do
|
|
672
675
|
it "should work" do
|
673
676
|
@db.copy_doc @doc, @docid
|
674
677
|
newdoc = @db.get(@docid)
|
675
|
-
newdoc['artist'].
|
678
|
+
expect(newdoc['artist']).to eq 'Zappa'
|
676
679
|
end
|
677
680
|
it "should fail without an _id" do
|
678
|
-
lambda{@db.copy_doc({"not"=>"a real doc"})}.
|
681
|
+
expect(lambda{@db.copy_doc({"not"=>"a real doc"})}).to raise_error(ArgumentError)
|
679
682
|
end
|
680
683
|
end
|
681
684
|
describe "to an existing location" do
|
@@ -683,19 +686,19 @@ describe CouchRest::Database do
|
|
683
686
|
@db.save_doc({'_id' => @docid, 'will-exist' => 'here'})
|
684
687
|
end
|
685
688
|
it "should fail without a rev" do
|
686
|
-
lambda{@db.copy_doc @doc, @docid}.
|
689
|
+
expect(lambda{@db.copy_doc @doc, @docid}).to raise_error(CouchRest::RequestFailed)
|
687
690
|
end
|
688
691
|
it "should succeed with a rev" do
|
689
692
|
@to_be_overwritten = @db.get(@docid)
|
690
693
|
@db.copy_doc @doc, "#{@docid}?rev=#{@to_be_overwritten['_rev']}"
|
691
694
|
newdoc = @db.get(@docid)
|
692
|
-
newdoc['artist'].
|
695
|
+
expect(newdoc['artist']).to eq 'Zappa'
|
693
696
|
end
|
694
697
|
it "should succeed given the doc to overwrite" do
|
695
698
|
@to_be_overwritten = @db.get(@docid)
|
696
699
|
@db.copy_doc @doc, @to_be_overwritten
|
697
700
|
newdoc = @db.get(@docid)
|
698
|
-
newdoc['artist'].
|
701
|
+
expect(newdoc['artist']).to eq 'Zappa'
|
699
702
|
end
|
700
703
|
end
|
701
704
|
end
|
@@ -706,9 +709,9 @@ describe CouchRest::Database do
|
|
706
709
|
@db.save_doc({'another' => 'doc', 'will-exist' => 'anywhere'})
|
707
710
|
end
|
708
711
|
ds = @db.documents
|
709
|
-
ds['rows'].
|
710
|
-
ds['rows'][0]['id'].
|
711
|
-
ds['total_rows'].
|
712
|
+
expect(ds['rows']).to be_an_instance_of(Array)
|
713
|
+
expect(ds['rows'][0]['id']).not_to be_nil
|
714
|
+
expect(ds['total_rows']).to eq 5
|
712
715
|
end
|
713
716
|
|
714
717
|
# This is redundant with the latest view code, but left in place for prosterity.
|
@@ -720,28 +723,28 @@ describe CouchRest::Database do
|
|
720
723
|
end
|
721
724
|
it "should list documents with keys and such" do
|
722
725
|
ds = @db.documents
|
723
|
-
ds['rows'].
|
724
|
-
ds['rows'][0]['id'].
|
725
|
-
ds['total_rows'].
|
726
|
+
expect(ds['rows']).to be_an_instance_of(Array)
|
727
|
+
expect(ds['rows'][0]['id']).to eq "doc0"
|
728
|
+
expect(ds['total_rows']).to eq 9
|
726
729
|
end
|
727
730
|
it "should take query params" do
|
728
731
|
ds = @db.documents(:startkey => 'doc0', :endkey => 'doc3')
|
729
|
-
ds['rows'].length.
|
732
|
+
expect(ds['rows'].length).to eq 4
|
730
733
|
ds = @db.documents(:key => 'doc0')
|
731
|
-
ds['rows'].length.
|
734
|
+
expect(ds['rows'].length).to eq 1
|
732
735
|
end
|
733
736
|
it "should work with multi-key" do
|
734
737
|
rs = @db.documents :keys => ["doc0", "doc7"]
|
735
|
-
rs['rows'].length.
|
738
|
+
expect(rs['rows'].length).to eq 2
|
736
739
|
end
|
737
740
|
it "should work with include_docs" do
|
738
741
|
ds = @db.documents(:startkey => 'doc0', :endkey => 'doc3', :include_docs => true)
|
739
|
-
ds['rows'][0]['doc']['another'].
|
742
|
+
expect(ds['rows'][0]['doc']['another']).to eq "doc"
|
740
743
|
end
|
741
744
|
it "should have the bulk_load macro" do
|
742
745
|
rs = @db.bulk_load ["doc0", "doc7"]
|
743
|
-
rs['rows'].length.
|
744
|
-
rs['rows'][0]['doc']['another'].
|
746
|
+
expect(rs['rows'].length).to eq 2
|
747
|
+
expect(rs['rows'][0]['doc']['another']).to eq "doc"
|
745
748
|
end
|
746
749
|
end
|
747
750
|
|
@@ -750,20 +753,21 @@ describe CouchRest::Database do
|
|
750
753
|
# Can cause failures in recent versions of CouchDB, just ensure
|
751
754
|
# we actually send the right command.
|
752
755
|
it "should compact the database" do
|
753
|
-
|
754
|
-
|
756
|
+
db = @cr.database('couchrest-test')
|
757
|
+
expect(db.connection).to receive(:post).with("/couchrest-test/_compact")
|
758
|
+
db.compact!
|
755
759
|
end
|
756
760
|
end
|
757
761
|
|
758
762
|
describe "deleting a database" do
|
759
763
|
it "should start with the test database" do
|
760
|
-
@cr.databases.
|
764
|
+
expect(@cr.databases).to include('couchrest-test')
|
761
765
|
end
|
762
766
|
it "should delete the database" do
|
763
767
|
db = @cr.database('couchrest-test')
|
764
768
|
r = db.delete!
|
765
|
-
r['ok'].
|
766
|
-
@cr.databases.
|
769
|
+
expect(r['ok']).to be_true
|
770
|
+
expect(@cr.databases).not_to include('couchrest-test')
|
767
771
|
end
|
768
772
|
end
|
769
773
|
|
@@ -779,8 +783,8 @@ describe CouchRest::Database do
|
|
779
783
|
end
|
780
784
|
|
781
785
|
it "should replicate via pulling" do
|
782
|
-
|
783
|
-
include("
|
786
|
+
expect(@other_db.connection).to receive(:post).with(
|
787
|
+
include("_replicate"),
|
784
788
|
include(
|
785
789
|
:create_target => false,
|
786
790
|
:continuous => false,
|
@@ -792,8 +796,8 @@ describe CouchRest::Database do
|
|
792
796
|
end
|
793
797
|
|
794
798
|
it "should replicate via pushing" do
|
795
|
-
|
796
|
-
include("
|
799
|
+
expect(@db.connection).to receive(:post).with(
|
800
|
+
include("_replicate"),
|
797
801
|
include(
|
798
802
|
:create_target => false,
|
799
803
|
:continuous => false,
|
@@ -805,8 +809,8 @@ describe CouchRest::Database do
|
|
805
809
|
end
|
806
810
|
|
807
811
|
it "should replacicate with a specific doc" do
|
808
|
-
|
809
|
-
include("
|
812
|
+
expect(@db.connection).to receive(:post).with(
|
813
|
+
include("_replicate"),
|
810
814
|
include(
|
811
815
|
:create_target => false,
|
812
816
|
:continuous => false,
|
@@ -820,8 +824,8 @@ describe CouchRest::Database do
|
|
820
824
|
|
821
825
|
describe "implicitly creating target" do
|
822
826
|
it "should replicate via pulling" do
|
823
|
-
|
824
|
-
include("
|
827
|
+
expect(@other_db.connection).to receive(:post).with(
|
828
|
+
include("_replicate"),
|
825
829
|
include(
|
826
830
|
:create_target => true,
|
827
831
|
:continuous => false
|
@@ -831,8 +835,8 @@ describe CouchRest::Database do
|
|
831
835
|
end
|
832
836
|
|
833
837
|
it "should replicate via pushing" do
|
834
|
-
|
835
|
-
include("
|
838
|
+
expect(@db.connection).to receive(:post).with(
|
839
|
+
include("_replicate"),
|
836
840
|
include(
|
837
841
|
:create_target => true,
|
838
842
|
:continuous => false
|
@@ -844,8 +848,8 @@ describe CouchRest::Database do
|
|
844
848
|
|
845
849
|
describe "continuous replication" do
|
846
850
|
it "should replicate via pulling" do
|
847
|
-
|
848
|
-
include("
|
851
|
+
expect(@other_db.connection).to receive(:post).with(
|
852
|
+
include("_replicate"),
|
849
853
|
include(
|
850
854
|
:create_target => false,
|
851
855
|
:continuous => true
|
@@ -855,8 +859,8 @@ describe CouchRest::Database do
|
|
855
859
|
end
|
856
860
|
|
857
861
|
it "should replicate via pushing" do
|
858
|
-
|
859
|
-
include("
|
862
|
+
expect(@db.connection).to receive(:post).with(
|
863
|
+
include("_replicate"),
|
860
864
|
include(
|
861
865
|
:create_target => false,
|
862
866
|
:continuous => true
|
@@ -875,9 +879,9 @@ describe CouchRest::Database do
|
|
875
879
|
end
|
876
880
|
|
877
881
|
it "should just work fine" do
|
878
|
-
@cr.databases.
|
882
|
+
expect(@cr.databases).not_to include('couchrest-test-db_to_create')
|
879
883
|
@db.create!
|
880
|
-
@cr.databases.
|
884
|
+
expect(@cr.databases).to include('couchrest-test-db_to_create')
|
881
885
|
end
|
882
886
|
end
|
883
887
|
|
@@ -890,15 +894,15 @@ describe CouchRest::Database do
|
|
890
894
|
end
|
891
895
|
|
892
896
|
it "should drop and recreate a database" do
|
893
|
-
@cr.databases.
|
897
|
+
expect(@cr.databases).to include(@db.name)
|
894
898
|
@db.recreate!
|
895
|
-
@cr.databases.
|
899
|
+
expect(@cr.databases).to include(@db.name)
|
896
900
|
end
|
897
901
|
|
898
902
|
it "should recreate a db even though it doesn't exist" do
|
899
|
-
@cr.databases.
|
903
|
+
expect(@cr.databases).not_to include(@db2.name)
|
900
904
|
@db2.recreate!
|
901
|
-
@cr.databases.
|
905
|
+
expect(@cr.databases).to include(@db2.name)
|
902
906
|
end
|
903
907
|
end
|
904
908
|
|
@@ -916,9 +920,9 @@ describe CouchRest::Database do
|
|
916
920
|
if couchdb_lucene_available?
|
917
921
|
result = @db.search('search/people', :q => 'name:J*')
|
918
922
|
doc_ids = result['rows'].collect{ |row| row['id'] }
|
919
|
-
doc_ids.size.
|
920
|
-
doc_ids.
|
921
|
-
doc_ids.
|
923
|
+
expect(doc_ids.size).to eq 2
|
924
|
+
expect(doc_ids).to include('john')
|
925
|
+
expect(doc_ids).to include('jack')
|
922
926
|
end
|
923
927
|
end
|
924
928
|
end
|