loose_change 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/loose_change/attachments.rb +2 -2
- data/lib/loose_change/persistence.rb +8 -3
- data/loose_change.gemspec +2 -2
- data/test/attachment_test.rb +10 -1
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.6
|
@@ -40,7 +40,7 @@ module LooseChange
|
|
40
40
|
# Returns a hash composed of <tt>file</tt> and <tt>content_type</tt> as
|
41
41
|
# returned from CouchDB identified by +name+.
|
42
42
|
def retrieve_attachment(name)
|
43
|
-
{ :file => RestClient.get("#{ uri }/#{ name }"),
|
43
|
+
{ :file => RestClient.get("#{ uri }/#{ CGI.escape(name) }"),
|
44
44
|
:content_type => JSON.parse(RestClient.get(uri))['_attachments']['name'] }
|
45
45
|
end
|
46
46
|
|
@@ -52,7 +52,7 @@ module LooseChange
|
|
52
52
|
# recipe.put_attachment(:photo)
|
53
53
|
def put_attachment(name)
|
54
54
|
return unless attachments[name]
|
55
|
-
result = JSON.parse(RestClient.put("#{ uri }/#{ name }#{ '?rev=' + @_rev if @_rev }", attachments[name][:file], {:content_type => attachments[name][:content_type], :accept => 'text/json'}))
|
55
|
+
result = JSON.parse(RestClient.put("#{ uri }/#{ CGI.escape(name) }#{ '?rev=' + @_rev if @_rev }", attachments[name][:file], {:content_type => attachments[name][:content_type], :accept => 'text/json'}))
|
56
56
|
@_rev = result['rev']
|
57
57
|
end
|
58
58
|
|
@@ -100,8 +100,11 @@ module LooseChange
|
|
100
100
|
raise DatabaseNotSet.new("Cannot save without database set.") unless @database
|
101
101
|
apply_defaults
|
102
102
|
return false unless valid?
|
103
|
-
new_record
|
104
|
-
|
103
|
+
if new_record
|
104
|
+
post_record and put_attachments
|
105
|
+
else
|
106
|
+
put_record and put_attachments
|
107
|
+
end
|
105
108
|
self
|
106
109
|
end
|
107
110
|
|
@@ -133,7 +136,9 @@ module LooseChange
|
|
133
136
|
end
|
134
137
|
|
135
138
|
def put_attachments
|
136
|
-
(@attachments || {}).each { |name, attachment|
|
139
|
+
(@attachments || {}).each { |name, attachment|
|
140
|
+
put_attachment(name) if attachment[:dirty]
|
141
|
+
}
|
137
142
|
end
|
138
143
|
|
139
144
|
def attachment_ivar(name)
|
data/loose_change.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{loose_change}
|
8
|
-
s.version = "0.3.
|
8
|
+
s.version = "0.3.6"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Joshua Miller"]
|
12
|
-
s.date = %q{2010-12-
|
12
|
+
s.date = %q{2010-12-15}
|
13
13
|
s.email = %q{josh@joshinharrisburg.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
data/test/attachment_test.rb
CHANGED
@@ -12,7 +12,7 @@ class AttachmentTest < ActiveSupport::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
should 'accept an attachment' do
|
15
|
-
@model.attach
|
15
|
+
@model.attach "photo", File.open(File.join(File.dirname(__FILE__), 'resources', 'couchdb.png')), :content_type => 'image/png'
|
16
16
|
assert @model.save
|
17
17
|
@retrieved = AttachmentModel.find(@model.id)
|
18
18
|
assert_equal({"photo" => {:content_type => 'image/png'}}, @retrieved.attachments)
|
@@ -20,6 +20,15 @@ class AttachmentTest < ActiveSupport::TestCase
|
|
20
20
|
assert_equal @retrieved.attachment(:photo).size, @model.attachment(:photo).size
|
21
21
|
end
|
22
22
|
|
23
|
+
should 'accept an attachment with spaces in its name' do
|
24
|
+
@model.attach "first photo", File.open(File.join(File.dirname(__FILE__), 'resources', 'couchdb.png')), :content_type => 'image/png'
|
25
|
+
assert @model.save
|
26
|
+
@retrieved = AttachmentModel.find(@model.id)
|
27
|
+
assert_equal({"first photo" => {:content_type => 'image/png'}}, @retrieved.attachments)
|
28
|
+
assert_not_nil @retrieved.attachment("first photo")
|
29
|
+
assert_equal @retrieved.attachment("first photo").size, @model.attachment("first photo").size
|
30
|
+
end
|
31
|
+
|
23
32
|
should "persist attachment between saves" do
|
24
33
|
@model.attach "Photo", File.open(File.join(File.dirname(__FILE__), 'resources', 'couchdb.png')), :content_type => 'image/png'
|
25
34
|
assert @model.save
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 6
|
9
|
+
version: 0.3.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joshua Miller
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2010-12-
|
17
|
+
date: 2010-12-15 00:00:00 -05:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -131,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
131
|
requirements:
|
132
132
|
- - ">="
|
133
133
|
- !ruby/object:Gem::Version
|
134
|
-
hash: -
|
134
|
+
hash: -727594084289976830
|
135
135
|
segments:
|
136
136
|
- 0
|
137
137
|
version: "0"
|