loose_change 0.3.4 → 0.3.5
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 +1 -0
- data/lib/loose_change/persistence.rb +1 -1
- data/loose_change.gemspec +1 -1
- data/test/attachment_test.rb +7 -6
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.5
|
@@ -26,6 +26,7 @@ module LooseChange
|
|
26
26
|
# instance, whether or not that file has been saved back to
|
27
27
|
# CouchDB. Will return nil if no attachment by that name exists.
|
28
28
|
def attachment(name)
|
29
|
+
name = name.to_s
|
29
30
|
return attachments[name][:file] if @attachments.try(:[], :name).try(:[], :file)
|
30
31
|
begin
|
31
32
|
result = retrieve_attachment(name)
|
@@ -47,7 +47,7 @@ module LooseChange
|
|
47
47
|
model.new_record = false
|
48
48
|
if hash['_attachments']
|
49
49
|
attachment_names = hash['_attachments'].map {|name, _| name}
|
50
|
-
model.attachments = attachment_names.inject({}) {|acc, name| acc[name
|
50
|
+
model.attachments = attachment_names.inject({}) {|acc, name| acc[name] = {:content_type => hash['_attachments'][name]['content_type']}; acc}
|
51
51
|
end
|
52
52
|
model
|
53
53
|
end
|
data/loose_change.gemspec
CHANGED
data/test/attachment_test.rb
CHANGED
@@ -15,21 +15,22 @@ class AttachmentTest < ActiveSupport::TestCase
|
|
15
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
|
-
assert_equal({
|
19
|
-
assert_not_nil @retrieved.attachment(
|
18
|
+
assert_equal({"photo" => {:content_type => 'image/png'}}, @retrieved.attachments)
|
19
|
+
assert_not_nil @retrieved.attachment("photo")
|
20
20
|
assert_equal @retrieved.attachment(:photo).size, @model.attachment(:photo).size
|
21
21
|
end
|
22
22
|
|
23
23
|
should "persist attachment between saves" do
|
24
|
-
@model.attach
|
24
|
+
@model.attach "Photo", File.open(File.join(File.dirname(__FILE__), 'resources', 'couchdb.png')), :content_type => 'image/png'
|
25
25
|
assert @model.save
|
26
26
|
@retrieved = AttachmentModel.find(@model.id)
|
27
|
+
assert_not_nil @retrieved.attachment "Photo"
|
27
28
|
@retrieved.name = "Photo"
|
28
29
|
@retrieved.save
|
29
30
|
@retrieved = AttachmentModel.find(@model.id)
|
30
|
-
assert_equal({
|
31
|
-
assert_not_nil @retrieved.attachment(
|
32
|
-
assert_equal @retrieved.attachment(
|
31
|
+
assert_equal({"Photo" => {:content_type => 'image/png'}}, @retrieved.attachments)
|
32
|
+
assert_not_nil @retrieved.attachment("Photo")
|
33
|
+
assert_equal @retrieved.attachment("Photo").size, @model.attachment("Photo").size
|
33
34
|
assert @retrieved.save
|
34
35
|
end
|
35
36
|
|
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
|
+
- 5
|
9
|
+
version: 0.3.5
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Joshua Miller
|
@@ -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: -1881381695233606524
|
135
135
|
segments:
|
136
136
|
- 0
|
137
137
|
version: "0"
|