dm-parse 0.3.3 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.3.3
1
+ 0.3.4
data/dm-parse.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dm-parse"
8
- s.version = "0.3.3"
8
+ s.version = "0.3.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Zhi-Qiang Lei"]
@@ -4,7 +4,12 @@ module DataMapper
4
4
  class ParseFile < Object
5
5
 
6
6
  def dump(value)
7
- value && { "__type" => "File", "name" => File.basename(value.path) }
7
+ case value
8
+ when ::URI
9
+ { "__type" => "File", "name" => File.basename(value.path), "url" => value.to_s }
10
+ when ::Hash
11
+ value
12
+ end
8
13
  end
9
14
 
10
15
  def load(value)
@@ -19,6 +24,8 @@ module DataMapper
19
24
  content_type = value.content_type
20
25
  response = adapter.upload_file(filename, content, content_type)
21
26
  URI(response["url"])
27
+ elsif value.is_a?(Hash)
28
+ URI(value["url"])
22
29
  end
23
30
  end
24
31
 
@@ -35,6 +35,19 @@ describe "resource" do
35
35
 
36
36
  it { should eq(content) }
37
37
  end
38
+
39
+ context "when resource is persisted" do
40
+ let(:resource) { Article.create attachment: attachment }
41
+ let(:new_attachment) { Struct.new(:original_filename, :read, :content_type).new("x.txt", "yy", "plain/txt") }
42
+
43
+ before { resource.update(attachment: new_attachment) }
44
+
45
+ describe "its file content" do
46
+ subject { Net::HTTP.get resource.attachment }
47
+
48
+ it { should eq("yy") }
49
+ end
50
+ end
38
51
  end
39
52
  end
40
53
 
@@ -31,7 +31,7 @@ describe DataMapper::Property::ParseFile do
31
31
 
32
32
  let(:value) { URI(url) }
33
33
 
34
- it { should eq("__type" => "File", "name" => name) }
34
+ it { should eq("__type" => "File", "name" => name, "url" => value.to_s) }
35
35
  end
36
36
 
37
37
  describe "#load" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dm-parse
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.3
4
+ version: 0.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -241,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  segments:
243
243
  - 0
244
- hash: 2256594259984366431
244
+ hash: -4078631318047556530
245
245
  required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  none: false
247
247
  requirements: