loose_change 0.3.1 → 0.3.2
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/.gitignore +1 -0
- data/VERSION +1 -1
- data/lib/loose_change/base.rb +1 -0
- data/lib/loose_change/persistence.rb +3 -2
- data/loose_change.gemspec +2 -2
- data/test/attachment_test.rb +14 -1
- metadata +4 -4
data/.gitignore
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.2
|
data/lib/loose_change/base.rb
CHANGED
@@ -44,6 +44,7 @@ module LooseChange
|
|
44
44
|
def instantiate_from_hash(hash)
|
45
45
|
model = new(hash.reject {|k, _| 'model_name' == k || '_attachments' == k})
|
46
46
|
model.id = hash['_id']
|
47
|
+
model._attachments = hash['_attachments']
|
47
48
|
model.new_record = false
|
48
49
|
if hash['_attachments']
|
49
50
|
attachment_names = hash['_attachments'].map {|name, _| name}
|
@@ -56,7 +57,7 @@ module LooseChange
|
|
56
57
|
|
57
58
|
module PersistenceClassMethods
|
58
59
|
|
59
|
-
attr_accessor :new_record, :destroyed, :database, :id, :_rev, :_id
|
60
|
+
attr_accessor :new_record, :destroyed, :database, :id, :_rev, :_id, :_attachments
|
60
61
|
|
61
62
|
def new_record?() @new_record end
|
62
63
|
def destroyed?() @destroyed end
|
@@ -123,7 +124,7 @@ module LooseChange
|
|
123
124
|
end
|
124
125
|
|
125
126
|
def put_record
|
126
|
-
result = JSON.parse(RestClient.put(uri, self.to_json(:methods => [:model_name, :_rev, :_id], :except => [:id]), default_headers))
|
127
|
+
result = JSON.parse(RestClient.put(uri, self.to_json(:methods => [:model_name, :_rev, :_id, :_attachments], :except => [:id]), default_headers))
|
127
128
|
@_rev = result['rev']
|
128
129
|
result
|
129
130
|
end
|
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.2"
|
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
|
+
s.date = %q{2010-12-03}
|
13
13
|
s.email = %q{josh@joshinharrisburg.com}
|
14
14
|
s.extra_rdoc_files = [
|
15
15
|
"LICENSE",
|
data/test/attachment_test.rb
CHANGED
@@ -5,6 +5,7 @@ class AttachmentTest < ActiveSupport::TestCase
|
|
5
5
|
setup do
|
6
6
|
class AttachmentModel < LooseChange::Base
|
7
7
|
use_database "test_db"
|
8
|
+
property :name
|
8
9
|
end
|
9
10
|
|
10
11
|
@model = AttachmentModel.new
|
@@ -18,5 +19,17 @@ class AttachmentTest < ActiveSupport::TestCase
|
|
18
19
|
assert_not_nil @retrieved.attachment(:photo)
|
19
20
|
assert_equal @retrieved.attachment(:photo).size, @model.attachment(:photo).size
|
20
21
|
end
|
21
|
-
|
22
|
+
|
23
|
+
should "persist attachment between saves" do
|
24
|
+
@model.attach :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
|
+
@retrieved.name = "Photo"
|
28
|
+
@retrieved.save
|
29
|
+
@retrieved = AttachmentModel.find(@model.id)
|
30
|
+
assert_equal({:photo => {:content_type => 'image/png'}}, @retrieved.attachments)
|
31
|
+
assert_not_nil @retrieved.attachment(:photo)
|
32
|
+
assert_equal @retrieved.attachment(:photo).size, @model.attachment(:photo).size
|
33
|
+
end
|
34
|
+
|
22
35
|
end
|
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
|
+
- 2
|
9
|
+
version: 0.3.2
|
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-
|
17
|
+
date: 2010-12-03 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: -3418827720380525957
|
135
135
|
segments:
|
136
136
|
- 0
|
137
137
|
version: "0"
|