dm-parse 0.3.1 → 0.3.2

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.1
1
+ 0.3.2
data/dm-parse.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "dm-parse"
8
- s.version = "0.3.1"
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 = ["Zhi-Qiang Lei"]
12
- s.date = "2012-07-02"
12
+ s.date = "2012-07-03"
13
13
  s.description = "An extension to make DataMapper working on Parse.com"
14
14
  s.email = "zhiqiang.lei@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -4,23 +4,25 @@ module DataMapper
4
4
  class ParseFile < Object
5
5
 
6
6
  def dump(value)
7
- if value.is_a?(Hash)
8
- value.merge("__type" => "File")
9
- elsif value.respond_to?(:original_filename) && value.respond_to?(:read) && value.respond_to?(:content_type)
7
+ value
8
+ end
9
+
10
+ def load(value)
11
+ value
12
+ end
13
+
14
+ def typecast(value)
15
+ if value.respond_to?(:original_filename) && value.respond_to?(:read) && value.respond_to?(:content_type)
10
16
  adapter = model.repository.adapter
11
17
  filename = value.original_filename
12
18
  content = value.read
13
19
  content_type = value.content_type
14
- dump adapter.upload_file(filename, content, content_type)
20
+ adapter.upload_file(filename, content, content_type).merge("__type" => "File")
15
21
  else
16
- nil
22
+ value
17
23
  end
18
24
  end
19
25
 
20
- def load(value)
21
- value
22
- end
23
-
24
26
  end
25
27
 
26
28
  end
@@ -25,6 +25,20 @@ describe "resource" do
25
25
  its(:id) { should_not be_nil }
26
26
  its(:created_at) { should_not be_nil }
27
27
  its(:updated_at) { should_not be_nil }
28
+
29
+ context "when resource has attachment" do
30
+ let(:resource) { Article.new attachment: attachment }
31
+ let(:attachment) { Struct.new(:original_filename, :read, :content_type).new("x.txt", content, "plain/txt") }
32
+ let(:content) { "xx" }
33
+
34
+ describe "its file content" do
35
+ subject { Net::HTTP.get URI(url) }
36
+
37
+ let(:url) { resource.attachment["url"] }
38
+
39
+ it { should eq(content) }
40
+ end
41
+ end
28
42
  end
29
43
 
30
44
  context "when resource is a child" do
@@ -5,12 +5,8 @@ describe DataMapper::Property::ParseFile do
5
5
 
6
6
  let(:property) { Article.properties[:attachment] }
7
7
 
8
- describe "#dump" do
9
- subject { property.dump value }
10
-
11
- let(:value) { { "name" => "xx.txt", "url" => "http://a.cn/xx.txt" } }
12
-
13
- it { should eq(value.merge("__type" => "File")) }
8
+ describe "#typecast" do
9
+ subject { property.typecast value }
14
10
 
15
11
  context "when value is nil" do
16
12
  let(:value) { nil }
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.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-07-02 00:00:00.000000000 Z
12
+ date: 2012-07-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: dm-core
@@ -241,7 +241,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
241
241
  version: '0'
242
242
  segments:
243
243
  - 0
244
- hash: -4597148251358288016
244
+ hash: 41573292717956535
245
245
  required_rubygems_version: !ruby/object:Gem::Requirement
246
246
  none: false
247
247
  requirements: