couch_surfer 0.3.2 → 0.3.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.
- data/lib/couchrest/extensions.rb +9 -1
- data/spec/lib/attachments_spec.rb +13 -0
- metadata +3 -3
data/lib/couchrest/extensions.rb
CHANGED
@@ -3,7 +3,7 @@ module CouchRest
|
|
3
3
|
# Query a CouchDB view as defined by a <tt>_design</tt> document. Accepts
|
4
4
|
# paramaters as described in http://wiki.apache.org/couchdb/HttpViewApi
|
5
5
|
#/db/_design/examples/_list/index-posts/posts-by-date
|
6
|
-
|
6
|
+
|
7
7
|
def list(list_name, view_name, doc_name, params = {})
|
8
8
|
url = CouchRest.paramify_url "#{@root}/_design/#{doc_name}/_list/#{list_name}/#{view_name}", params
|
9
9
|
response = RestClient.get(url)
|
@@ -11,6 +11,14 @@ module CouchRest
|
|
11
11
|
rescue
|
12
12
|
response
|
13
13
|
end
|
14
|
+
|
15
|
+
# PUT an attachment directly to CouchDB
|
16
|
+
def put_attachment(doc, name, file, options = {})
|
17
|
+
docid = escape_docid(doc['_id'])
|
18
|
+
uri = url_for_attachment(doc, name)
|
19
|
+
JSON.parse(HttpAbstraction.put(uri, file, options))
|
20
|
+
end
|
21
|
+
|
14
22
|
end
|
15
23
|
|
16
24
|
class Design
|
@@ -24,6 +24,19 @@ describe CouchSurfer::Attachments do
|
|
24
24
|
@person.put_attachment("couchdb.png", open_fixture("attachments/couchdb.png")).should be_true
|
25
25
|
end
|
26
26
|
|
27
|
+
it "should not escape spaces" do
|
28
|
+
@person.put_attachment("couch db.png", open_fixture("attachments/couchdb.png")).should be_true
|
29
|
+
@person.reload["_attachments"].keys.should include "couch db.png"
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not store filenames beginning with an underscore" do
|
33
|
+
lambda{ @person.put_attachment("_couch db.png", open_fixture("attachments/couchdb.png")) }.should raise_error RestClient::RequestFailed
|
34
|
+
end
|
35
|
+
|
36
|
+
it "should not store filenames which are non-utf8" do
|
37
|
+
lambda{ @person.put_attachment("®#†π¶®¥π€.png", open_fixture("attachments/couchdb.png")) }.should raise_error RestClient::RequestFailed
|
38
|
+
end
|
39
|
+
|
27
40
|
it "should raise an exception if the record is not yet saved" do
|
28
41
|
person = Person.new(:name => "John", :email => "john@mail.com")
|
29
42
|
lambda {person.put_attachment("couchdb.png", open_fixture("attachments/couchdb.png"))}.should raise_error(ArgumentError)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: couch_surfer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Groves
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-01-27 00:00:00 +01:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
requirements: []
|
105
105
|
|
106
106
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.3.
|
107
|
+
rubygems_version: 1.3.5
|
108
108
|
signing_key:
|
109
109
|
specification_version: 3
|
110
110
|
summary: ORM based on CouchRest::Model
|