rocking_chair 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock ADDED
@@ -0,0 +1,68 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ activemodel (3.0.9)
5
+ activesupport (= 3.0.9)
6
+ builder (~> 2.1.2)
7
+ i18n (~> 0.5.0)
8
+ activesupport (3.0.9)
9
+ builder (2.1.2)
10
+ couch_potato (0.5.6)
11
+ activemodel
12
+ couchrest (>= 1.0.1)
13
+ json
14
+ couchrest (1.0.1)
15
+ json (>= 1.4.6)
16
+ mime-types (>= 1.15)
17
+ rest-client (>= 1.5.1)
18
+ couchrest_extended_document (1.0.0)
19
+ activesupport (>= 2.3.0)
20
+ builder (>= 2.1.2)
21
+ couchrest (>= 1.0.0)
22
+ mime-types (>= 1.15)
23
+ git (1.2.5)
24
+ i18n (0.5.0)
25
+ jeweler (1.6.4)
26
+ bundler (~> 1.0)
27
+ git (>= 1.2.5)
28
+ rake
29
+ json (1.5.3)
30
+ mattmatt-validatable (1.8.4)
31
+ mime-types (1.16)
32
+ mocha (0.9.12)
33
+ rake (0.9.2)
34
+ rest-client (1.6.1)
35
+ mime-types (>= 1.16)
36
+ right_aws (2.1.0)
37
+ right_http_connection (>= 1.2.5)
38
+ right_http_connection (1.3.0)
39
+ shoulda (2.11.3)
40
+ shoulda-addons (0.2.3)
41
+ simply_stored (0.6.5)
42
+ activesupport
43
+ activesupport (~> 3.0.0)
44
+ couch_potato (= 0.5.6)
45
+ couch_potato (>= 0.2.15)
46
+ couchrest (= 1.0.1)
47
+ mattmatt-validatable (= 1.8.4)
48
+ mattmatt-validatable
49
+ mocha
50
+ rest-client (= 1.6.1)
51
+ rest-client (>= 1.4.2)
52
+ right_aws
53
+ shoulda
54
+ shoulda-addons
55
+ uuidtools
56
+ uuidtools (2.1.2)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ couch_potato (= 0.5.6)
63
+ couchrest_extended_document
64
+ jeweler
65
+ mocha
66
+ shoulda
67
+ simply_stored (= 0.6.5)
68
+ uuidtools
data/lib/rocking_chair.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  require "rubygems"
2
4
  require 'active_support/core_ext/kernel/reporting'
3
5
  require "active_support/core_ext/hash"
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RockingChair
2
4
  module CouchRestHttpAdapter
3
5
  URL_PARAMETER = /[a-zA-Z0-9\-\_\%]+/
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RockingChair
2
4
  class Database
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RockingChair
2
4
  class Error < StandardError
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RockingChair
2
4
  module Helper
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RockingChair
2
4
  module HttpAdapter
3
5
 
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RockingChair
2
4
  module Server
3
5
  BASE_URL = /(http:\/\/)?127\.0\.0\.1:5984\//
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module RockingChair
2
4
  class View
3
5
 
@@ -173,6 +175,7 @@ module RockingChair
173
175
  end
174
176
 
175
177
  def filter_items_by_key(attributes)
178
+ attributes = [attributes].flatten
176
179
  if options['startkey']
177
180
  filter_items_by_range(attributes)
178
181
  elsif options['filter_by_key'] || options['key']
@@ -207,7 +210,7 @@ module RockingChair
207
210
  end
208
211
 
209
212
  def filter_items_by_key_in_attribute_group(attribute)
210
- filter_key = (options['key'] || options['startkey']).to_s
213
+ filter_key = [options['key'] || options['startkey']].flatten.first.to_s
211
214
  @keys = keys.select do |key|
212
215
  document = ruby_store[key]
213
216
  document_attribute = RockingChair::Helper.access(attribute, document)
@@ -216,7 +219,7 @@ module RockingChair
216
219
  end
217
220
 
218
221
  def filter_items_by_query_document_attributes(belongs_to)
219
- filter_key = options['key'] || options['startkey']
222
+ filter_key = [options['key'] || options['startkey']].flatten.first
220
223
  filtering_document = ruby_store[filter_key.to_s]
221
224
  reverse_foreign_key = foreign_key_array_id(design_document_name)
222
225
  @keys = RockingChair::Helper.access(reverse_foreign_key, filtering_document) || []
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocking_chair
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease: false
4
+ hash: 15
5
+ prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jonathan Weiss
@@ -15,13 +15,70 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-04-04 00:00:00 +02:00
19
- default_executable:
18
+ date: 2011-08-11 00:00:00 Z
20
19
  dependencies:
21
20
  - !ruby/object:Gem::Dependency
21
+ version_requirements: &id001 !ruby/object:Gem::Requirement
22
+ none: false
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ hash: 3
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ name: uuidtools
31
+ prerelease: false
32
+ type: :runtime
33
+ requirement: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ version_requirements: &id002 !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - "="
39
+ - !ruby/object:Gem::Version
40
+ hash: 13
41
+ segments:
42
+ - 0
43
+ - 6
44
+ - 5
45
+ version: 0.6.5
22
46
  name: simply_stored
23
47
  prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
48
+ type: :runtime
49
+ requirement: *id002
50
+ - !ruby/object:Gem::Dependency
51
+ version_requirements: &id003 !ruby/object:Gem::Requirement
52
+ none: false
53
+ requirements:
54
+ - - "="
55
+ - !ruby/object:Gem::Version
56
+ hash: 7
57
+ segments:
58
+ - 0
59
+ - 5
60
+ - 6
61
+ version: 0.5.6
62
+ name: couch_potato
63
+ prerelease: false
64
+ type: :runtime
65
+ requirement: *id003
66
+ - !ruby/object:Gem::Dependency
67
+ version_requirements: &id004 !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ hash: 3
73
+ segments:
74
+ - 0
75
+ version: "0"
76
+ name: jeweler
77
+ prerelease: false
78
+ type: :runtime
79
+ requirement: *id004
80
+ - !ruby/object:Gem::Dependency
81
+ version_requirements: &id005 !ruby/object:Gem::Requirement
25
82
  none: false
26
83
  requirements:
27
84
  - - ">="
@@ -32,12 +89,12 @@ dependencies:
32
89
  - 1
33
90
  - 12
34
91
  version: 0.1.12
92
+ name: simply_stored
93
+ prerelease: false
35
94
  type: :runtime
36
- version_requirements: *id001
95
+ requirement: *id005
37
96
  - !ruby/object:Gem::Dependency
38
- name: rest-client
39
- prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
97
+ version_requirements: &id006 !ruby/object:Gem::Requirement
41
98
  none: false
42
99
  requirements:
43
100
  - - ">="
@@ -48,12 +105,12 @@ dependencies:
48
105
  - 6
49
106
  - 1
50
107
  version: 1.6.1
108
+ name: rest-client
109
+ prerelease: false
51
110
  type: :runtime
52
- version_requirements: *id002
111
+ requirement: *id006
53
112
  - !ruby/object:Gem::Dependency
54
- name: couchrest
55
- prerelease: false
56
- requirement: &id003 !ruby/object:Gem::Requirement
113
+ version_requirements: &id007 !ruby/object:Gem::Requirement
57
114
  none: false
58
115
  requirements:
59
116
  - - ">="
@@ -64,8 +121,10 @@ dependencies:
64
121
  - 0
65
122
  - 1
66
123
  version: 1.0.1
124
+ name: couchrest
125
+ prerelease: false
67
126
  type: :runtime
68
- version_requirements: *id003
127
+ requirement: *id007
69
128
  description: In-memory CouchDB for Couchrest and SimplyStored. Works for database and document API, by_attribute views, and for SimplyStored generated views
70
129
  email: jw@innerewut.de
71
130
  executables: []
@@ -76,6 +135,7 @@ extra_rdoc_files:
76
135
  - LICENSE.txt
77
136
  - README.md
78
137
  files:
138
+ - Gemfile.lock
79
139
  - LICENSE.txt
80
140
  - README.md
81
141
  - lib/rocking_chair.rb
@@ -86,21 +146,12 @@ files:
86
146
  - lib/rocking_chair/http_adapter.rb
87
147
  - lib/rocking_chair/server.rb
88
148
  - lib/rocking_chair/view.rb
89
- - test/couch_rest_test.rb
90
- - test/database_test.rb
91
- - test/extended_couch_rest_test.rb
92
- - test/fixtures/extended_couch_rest_fixtures.rb
93
- - test/fixtures/simply_stored_fixtures.rb
94
- - test/simply_stored_test.rb
95
- - test/test_helper.rb
96
- - test/view_test.rb
97
- has_rdoc: true
98
149
  homepage: http://github.com/jweiss/rocking_chair
99
150
  licenses: []
100
151
 
101
152
  post_install_message:
102
- rdoc_options:
103
- - --charset=UTF-8
153
+ rdoc_options: []
154
+
104
155
  require_paths:
105
156
  - lib
106
157
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -124,16 +175,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
175
  requirements: []
125
176
 
126
177
  rubyforge_project:
127
- rubygems_version: 1.3.7
178
+ rubygems_version: 1.8.7
128
179
  signing_key:
129
180
  specification_version: 3
130
181
  summary: In-memory CouchDB for Couchrest and SimplyStored
131
- test_files:
132
- - test/couch_rest_test.rb
133
- - test/database_test.rb
134
- - test/extended_couch_rest_test.rb
135
- - test/fixtures/extended_couch_rest_fixtures.rb
136
- - test/fixtures/simply_stored_fixtures.rb
137
- - test/simply_stored_test.rb
138
- - test/test_helper.rb
139
- - test/view_test.rb
182
+ test_files: []
183
+
@@ -1,350 +0,0 @@
1
- require File.dirname(__FILE__) + "/test_helper"
2
-
3
- class CouchRestTest < Test::Unit::TestCase
4
- context "The HTTP Apdapter for CouchRest" do
5
- setup do
6
- RockingChair::Server.reset
7
- @couch = CouchRest.new("http://127.0.0.1:5984")
8
- end
9
-
10
- context "Database API" do
11
-
12
- should "return the info JSON" do
13
- assert_equal({"couchdb" => "Welcome","version" => "0.10.1"}, @couch.info)
14
- end
15
-
16
- should "return a list of all databases" do
17
- assert_equal [], @couch.databases
18
- @couch.create_db('database-name')
19
- assert_equal ['database-name'], @couch.databases
20
- end
21
-
22
- should "create a database" do
23
- db = @couch.create_db('database-name')
24
- end
25
-
26
- should "return information on a database" do
27
- @couch.create_db('database-name')
28
- assert_equal({
29
- "db_name" => "database-name",
30
- "doc_count" => 0,
31
- "doc_del_count" => 0,
32
- "update_seq" => 10,
33
- "purge_seq" => 0,
34
- "compact_running" => false,
35
- "disk_size" => 16473,
36
- "instance_start_time" => "1265409273572320",
37
- "disk_format_version" => 4}, @couch.database('database-name').info)
38
- end
39
-
40
- should "delete a database" do
41
- db = @couch.database('database-name')
42
- db.delete!
43
- end
44
-
45
- end
46
-
47
- context "when asking for UUIDs" do
48
- should "return a UUID" do
49
- RockingChair::Database.expects(:uuids).with('2').returns(['1', '2'])
50
- assert_equal '2', @couch.next_uuid(2)
51
- end
52
- end
53
-
54
- context "Bulk Document API" do
55
- setup do
56
- @db = @couch.create_db('RockingChair')
57
- RockingChair::Database.any_instance.stubs(:rev).returns('the-revision')
58
- end
59
-
60
- context "loading all documents" do
61
- should "load the total documents" do
62
- 5.times do |i|
63
- @db.save_doc({'_id' => "item-#{i}", 'a' => 'b'})
64
- end
65
- assert_equal({
66
- "total_rows" => 5, "offset" => 0, "rows" => [
67
- {"id" => "item-0", "key" => "item-0", "value" => {"rev" => "the-revision"}},
68
- {"id" => "item-1", "key" => "item-1", "value" => {"rev" => "the-revision"}},
69
- {"id" => "item-2", "key" => "item-2", "value" => {"rev" => "the-revision"}},
70
- {"id" => "item-3", "key" => "item-3", "value" => {"rev" => "the-revision"}},
71
- {"id" => "item-4", "key" => "item-4", "value" => {"rev" => "the-revision"}}
72
- ]
73
- }, @db.documents)
74
- end
75
-
76
- should "sort the result by ID ascending" do
77
- @db.save_doc({'_id' => "C", 'a' => 'b'})
78
- @db.save_doc({'_id' => "B", 'a' => 'b'})
79
- @db.save_doc({'_id' => "A", 'a' => 'b'})
80
- assert_equal({
81
- "total_rows" => 3, "offset" => 0, "rows" => [
82
- {"id" => "A", "key" => "A", "value" => {"rev" => "the-revision"}},
83
- {"id" => "B", "key" => "B", "value" => {"rev" => "the-revision"}},
84
- {"id" => "C", "key" => "C", "value" => {"rev" => "the-revision"}}
85
- ]
86
- }, @db.documents)
87
- end
88
-
89
- should "sort the result by ID descending" do
90
- @db.save_doc({'_id' => "C", 'a' => 'b'})
91
- @db.save_doc({'_id' => "B", 'a' => 'b'})
92
- @db.save_doc({'_id' => "A", 'a' => 'b'})
93
- assert_equal({
94
- "total_rows" => 3, "offset" => 0, "rows" => [
95
- {"id" => "C", "key" => "C", "value" => {"rev" => "the-revision"}},
96
- {"id" => "B", "key" => "B", "value" => {"rev" => "the-revision"}},
97
- {"id" => "A", "key" => "A", "value" => {"rev" => "the-revision"}}
98
- ]
99
- }, @db.documents('descending' => true))
100
- end
101
-
102
- should "start by the given key" do
103
- @db.save_doc({'_id' => "C", 'a' => 'b'})
104
- @db.save_doc({'_id' => "B", 'a' => 'b'})
105
- @db.save_doc({'_id' => "A", 'a' => 'b'})
106
-
107
- assert_equal({
108
- "total_rows" => 3, "offset" => 0, "rows" => [
109
- {"id" => "B", "key" => "B", "value" => {"rev" => "the-revision"}},
110
- {"id" => "C", "key" => "C", "value" => {"rev" => "the-revision"}}
111
- ]
112
- }, @db.documents(:startkey => 'B'))
113
- end
114
-
115
- should "start by the given key, include docs, descending and limit" do
116
- @db.save_doc({'_id' => "C", 'a' => 'b'})
117
- @db.save_doc({'_id' => "B", 'a' => 'b'})
118
- @db.save_doc({'_id' => "A", 'a' => 'b'})
119
- @db.save_doc({'_id' => "D", 'a' => 'b'})
120
-
121
- assert_equal({
122
- "total_rows" => 4, "offset" => 0, "rows" => [
123
- {"id" => "C", "key" => "C", "value" => {"rev" => "the-revision", '_rev' => 'the-revision', '_id' => 'C', 'a' => 'b'}},
124
- {"id" => "B", "key" => "B", "value" => {"rev" => "the-revision", '_rev' => 'the-revision', '_id' => 'B', 'a' => 'b'}}
125
- ]
126
- }, @db.documents(:startkey => "C\u999", :endkey => "B", :limit => 2, :include_docs => true, :descending => true))
127
- end
128
- end
129
-
130
- context "bulk modifications" do
131
-
132
- should "accept bulk inserts/updates" do
133
- RockingChair::Database.stubs(:uuid).returns('foo-id')
134
-
135
- docs = [{"_id" => 'a', "value" => 1}, {"_id" => 'b', 'value' => 2}, {'value' => 3}]
136
- assert_equal([
137
- {'id' => 'a', "rev" => 'the-revision'},
138
- {'id' => 'b', "rev" => 'the-revision'},
139
- {'id' => 'foo-id', "rev" => 'the-revision'}
140
- ], @db.bulk_save(docs))
141
- end
142
-
143
- should "handle automatic inserts/updates" do
144
- @db.bulk_save_cache_limit = 5
145
- assert_nothing_raised do
146
- 10.times do |i|
147
- @db.save_doc({'_id' => "new-item-#{i}", 'content' => 'here'}, true)
148
- end
149
- end
150
- assert_equal 10, @db.info['doc_count']
151
- end
152
-
153
- should "do updates" do
154
- @db.save_doc({'_id' => "A", 'a' => 'b'})
155
- @db.save_doc({'_id' => "B", 'a' => 'b'})
156
-
157
- docs = [{"_id" => 'A', "a" => 1, '_rev' => 'the-revision'}, {'value' => 3}]
158
- @db.bulk_save(docs)
159
-
160
- assert_equal({'_id' => 'A', 'a' => 1, '_rev' => 'the-revision'}, @db.get('A'))
161
- end
162
-
163
- should "do deletes" do
164
- @db.save_doc({'_id' => "A", 'a' => 'b'})
165
- @db.save_doc({'_id' => "B", 'a' => 'b'})
166
-
167
- docs = [{"_id" => 'A', "a" => 1, '_rev' => 'the-revision', '_deleted' => true}]
168
- @db.bulk_save(docs)
169
-
170
- assert_raise(RestClient::ResourceNotFound) do
171
- @db.get('A')
172
- end
173
- end
174
-
175
- end
176
- end
177
-
178
- context "Document API" do
179
- setup do
180
- @db = @couch.create_db('RockingChair')
181
- RockingChair::Database.any_instance.stubs(:rev).returns('the-revision')
182
- end
183
-
184
- context "when retrieving a document (GET)" do
185
- setup do
186
- @db.save_doc({'_id' => 'the-doc-id', 'a' => 'b'})
187
- end
188
-
189
- should "load the document" do
190
- assert_equal({"_id" => "the-doc-id","a" => "b", '_rev' => 'the-revision'}, @db.get('the-doc-id'))
191
- end
192
-
193
- should "raise a 404 if the document does not exist" do
194
- assert_raise(RestClient::ResourceNotFound) do
195
- @db.get('no-such-id')
196
- end
197
- end
198
-
199
- should "load the document by a specific revision" do
200
- assert_equal({"_id" => "the-doc-id","a" => "b", '_rev' => 'the-revision'}, @db.get('the-doc-id', :rev => 'the-revision'))
201
- end
202
-
203
- should "raise a 404 if the revision is not there" do
204
- assert_raise(RestClient::ResourceNotFound) do
205
- @db.get('the-doc-id', :rev => 'non-existant-revision')
206
- end
207
- end
208
-
209
- should "load the document witht the revisions history" do
210
- assert_equal({"_id" => "the-doc-id","a" => "b", '_rev' => 'the-revision', "_revisions" => {"start" => 1,"ids" => ["the-revision"]}}, @db.get('the-doc-id', :revs => 'true'))
211
- end
212
-
213
- should "load the document witht the detailed revisions history" do
214
- assert_equal({"_id" => "the-doc-id","a" => "b", '_rev' => 'the-revision', "_revs_info" => [{"rev" => "the-revision", "status" => "disk"}]}, @db.get('the-doc-id', :revs_info => 'true'))
215
- end
216
- end
217
-
218
- context "when storing a document (PUT)" do
219
- should "store a new the document" do
220
- assert_equal 0, @db.info['doc_count']
221
- @db.save_doc({'_id' => 'new-item', 'content' => 'here'})
222
- assert_equal 1, @db.info['doc_count']
223
- assert_equal({"_id" => "new-item","content" => "here", '_rev' => 'the-revision'}, @db.get('new-item'))
224
- end
225
-
226
- should "update a document" do
227
- seq = sequence('revision')
228
- RockingChair::Database.any_instance.expects(:rev).returns('first-rev').in_sequence(seq)
229
- RockingChair::Database.any_instance.expects(:rev).returns('second-rev').in_sequence(seq)
230
-
231
- @db.save_doc({'_id' => 'new-item', 'content' => 'here'})
232
- @db.save_doc({'_id' => 'new-item', 'content' => 'better', '_rev' => 'first-rev'})
233
-
234
- assert_equal({"_id" => "new-item","content" => "better", '_rev' => 'second-rev'}, @db.get('new-item'))
235
- end
236
-
237
- should "raise 409 on a revision conflict" do
238
- @db.save_doc({'_id' => 'new-item', 'content' => 'here'})
239
- assert_raise(RestClient::Conflict) do
240
- @db.save_doc({'_id' => 'new-item', 'content' => 'better', '_rev' => 'wrong-revision'})
241
- end
242
-
243
- assert_equal({"_id" => "new-item","content" => "here", '_rev' => 'the-revision'}, @db.get('new-item'))
244
- end
245
-
246
- should "ignore the batch parameter" do
247
- assert_nothing_raised do
248
- @db.save_doc({'_id' => 'new-item', 'content' => 'here'}, false, true)
249
- end
250
- assert_equal({"_id" => "new-item","content" => "here", '_rev' => 'the-revision'}, @db.get('new-item'))
251
- end
252
-
253
- end
254
-
255
- context "when storing a document (POST)" do
256
- should "store a new the document" do
257
- RockingChair::Database.expects(:uuid).returns('5')
258
- assert_equal 0, @db.info['doc_count']
259
- assert_equal({"rev"=>"the-revision", "id"=>"5", "ok"=>true},
260
- CouchRest.post('127.0.0.1:5984/RockingChair/', {'content' => 'here'}))
261
- assert_equal 1, @db.info['doc_count']
262
- end
263
- end
264
-
265
- context "when deleting a document (DELETE)" do
266
- should "delete if the rev matches" do
267
- RockingChair::Database.any_instance.stubs(:rev).returns('123')
268
-
269
- @db.save_doc({'a' => 'b', '_id' => 'delete_me'})
270
- @db.delete_doc({'a' => 'b', '_id' => 'delete_me', '_rev' => '123'})
271
- assert_raise(RestClient::ResourceNotFound) do
272
- @db.get('delete_me')
273
- end
274
- end
275
-
276
- should "fail with conflich if the rev does not matche" do
277
- @db.save_doc({'a' => 'b', '_id' => 'delete_me'})
278
- assert_raise(RestClient::Conflict) do
279
- @db.delete_doc({'a' => 'b', '_id' => 'delete_me', '_rev' => 'wrong-revision'})
280
- end
281
- assert_nothing_raised do
282
- @db.get('delete_me')
283
- end
284
- end
285
- end
286
-
287
- context "when copying a document (COPY)" do
288
- setup do
289
- RockingChair::Database.any_instance.stubs(:rev).returns('123')
290
- @db.save_doc({'a' => 'b', '_id' => 'original'})
291
- end
292
-
293
- context "when using an destination ID" do
294
-
295
- should "copy" do
296
- @db.copy_doc({'a' => 'b', '_id' => 'original', '_rev' => '123'}, 'the_new_id')
297
- assert_equal({'a' => 'b', '_id' => 'the_new_id', '_rev' => '123'}, @db.get('the_new_id'))
298
- end
299
-
300
- should "copy with overwrite with revision" do
301
- seq = sequence('revision')
302
- RockingChair::Database.any_instance.expects(:rev).returns('first-rev').in_sequence(seq)
303
- RockingChair::Database.any_instance.expects(:rev).returns('second-rev').in_sequence(seq)
304
-
305
- @db.save_doc({'1' => '2', '_id' => 'destination'})
306
-
307
- @db.copy_doc({'a' => 'b', '_id' => 'original', '_rev' => '123'}, "destination?rev=first-rev")
308
- assert_equal({'a' => 'b', '_id' => 'destination', '_rev' => 'second-rev'}, @db.get('destination'))
309
- end
310
-
311
- should "not copy with overwrite if the revision does not match" do
312
- @db.save_doc({'1' => '2', '_id' => 'destination'})
313
- assert_raise(RestClient::Conflict) do
314
- @db.copy_doc({'a' => 'b', '_id' => 'original', '_rev' => '123'}, 'destination?rev=not-here')
315
- end
316
- end
317
-
318
- end
319
-
320
- context "when using a destination object" do
321
- should "copy" do
322
- destination = {"_id" => 'destination', 'c' => 'a', '_rev' => '123'}
323
- @db.copy_doc({'a' => 'b', '_id' => 'original', '_rev' => '123'}, destination)
324
- assert_equal({'a' => 'b', '_id' => 'destination', '_rev' => '123'}, @db.get('destination'))
325
- end
326
-
327
- should "copy with overwrite with revision" do
328
- seq = sequence('revision')
329
- RockingChair::Database.any_instance.expects(:rev).returns('first-rev').in_sequence(seq)
330
- RockingChair::Database.any_instance.expects(:rev).returns('second-rev').in_sequence(seq)
331
-
332
- @db.save_doc({'1' => '2', '_id' => 'destination'})
333
-
334
- @db.copy_doc({'a' => 'b', '_id' => 'original', '_rev' => '123'}, {'1' => '2', '_id' => 'destination', '_rev' => 'first-rev'})
335
- assert_equal({'a' => 'b', '_id' => 'destination', '_rev' => 'second-rev'}, @db.get('destination'))
336
- end
337
-
338
- should "not copy with overwrite if the revision does not match" do
339
- @db.save_doc({'1' => '2', '_id' => 'destination'})
340
- assert_raise(RestClient::Conflict) do
341
- @db.copy_doc({'a' => 'b', '_id' => 'original', '_rev' => '123'}, {'1' => '2', '_id' => 'destination', '_rev' => 'missing'})
342
- end
343
- end
344
- end
345
- end
346
-
347
- end
348
-
349
- end
350
- end