dm-parse 0.3.2 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/dm-parse.gemspec +1 -1
- data/lib/adapters/parse_adapter.rb +1 -1
- data/lib/dm-parse.rb +1 -0
- data/lib/property/parse_date.rb +5 -1
- data/lib/property/parse_file.rb +4 -5
- data/spec/integration_spec.rb +1 -4
- data/spec/parse_date_spec.rb +8 -0
- data/spec/parse_file_spec.rb +17 -9
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.3.
|
1
|
+
0.3.3
|
data/dm-parse.gemspec
CHANGED
@@ -25,7 +25,7 @@ module DataMapper
|
|
25
25
|
result = engine.create storage_name, params
|
26
26
|
|
27
27
|
initialize_serial resource, result["objectId"]
|
28
|
-
resource.created_at = resource.updated_at = result["createdAt"]
|
28
|
+
resource.created_at = resource.updated_at = result["createdAt"]
|
29
29
|
end.size
|
30
30
|
end
|
31
31
|
|
data/lib/dm-parse.rb
CHANGED
data/lib/property/parse_date.rb
CHANGED
@@ -4,13 +4,17 @@ module DataMapper
|
|
4
4
|
class ParseDate < Object
|
5
5
|
|
6
6
|
def dump(value)
|
7
|
-
value && {"__type" => "Date", "iso" => value.
|
7
|
+
value && {"__type" => "Date", "iso" => value.utc.iso8601(3)}
|
8
8
|
end
|
9
9
|
|
10
10
|
def load(value)
|
11
11
|
value && (value.is_a?(Hash) ? value["iso"].to_datetime : value.to_datetime)
|
12
12
|
end
|
13
13
|
|
14
|
+
def typecast(value)
|
15
|
+
value && value.to_datetime
|
16
|
+
end
|
17
|
+
|
14
18
|
end
|
15
19
|
|
16
20
|
end
|
data/lib/property/parse_file.rb
CHANGED
@@ -4,11 +4,11 @@ module DataMapper
|
|
4
4
|
class ParseFile < Object
|
5
5
|
|
6
6
|
def dump(value)
|
7
|
-
value
|
7
|
+
value && { "__type" => "File", "name" => File.basename(value.path) }
|
8
8
|
end
|
9
9
|
|
10
10
|
def load(value)
|
11
|
-
value
|
11
|
+
value && URI(value["url"])
|
12
12
|
end
|
13
13
|
|
14
14
|
def typecast(value)
|
@@ -17,9 +17,8 @@ module DataMapper
|
|
17
17
|
filename = value.original_filename
|
18
18
|
content = value.read
|
19
19
|
content_type = value.content_type
|
20
|
-
adapter.upload_file(filename, content, content_type)
|
21
|
-
|
22
|
-
value
|
20
|
+
response = adapter.upload_file(filename, content, content_type)
|
21
|
+
URI(response["url"])
|
23
22
|
end
|
24
23
|
end
|
25
24
|
|
data/spec/integration_spec.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "uri"
|
3
2
|
require "net/http"
|
4
3
|
require "net/https"
|
5
4
|
|
@@ -32,9 +31,7 @@ describe "resource" do
|
|
32
31
|
let(:content) { "xx" }
|
33
32
|
|
34
33
|
describe "its file content" do
|
35
|
-
subject { Net::HTTP.get
|
36
|
-
|
37
|
-
let(:url) { resource.attachment["url"] }
|
34
|
+
subject { Net::HTTP.get resource.attachment }
|
38
35
|
|
39
36
|
it { should eq(content) }
|
40
37
|
end
|
data/spec/parse_date_spec.rb
CHANGED
data/spec/parse_file_spec.rb
CHANGED
@@ -3,7 +3,9 @@ require "spec_helper"
|
|
3
3
|
describe DataMapper::Property::ParseFile do
|
4
4
|
subject { property }
|
5
5
|
|
6
|
-
let(:property)
|
6
|
+
let(:property) { Article.properties[:attachment] }
|
7
|
+
let(:url) { "http://files.parse.com/3f10b6f9-bec4-4583-b907-8f2ece6e965a/003ce5ad-06c4-4be6-9475-b074b6bd4dc8-test.png" }
|
8
|
+
let(:name) { File.basename URI(url).path }
|
7
9
|
|
8
10
|
describe "#typecast" do
|
9
11
|
subject { property.typecast value }
|
@@ -17,21 +19,27 @@ describe DataMapper::Property::ParseFile do
|
|
17
19
|
context "when value is io" do
|
18
20
|
let(:value) { StringIO.new "xx" }
|
19
21
|
|
20
|
-
before { value.stub(original_filename: "
|
21
|
-
before { DataMapper::Adapters::ParseAdapter.any_instance.stub(upload_file: {"name" =>
|
22
|
+
before { value.stub(original_filename: "test.png", content_type: "image/png") }
|
23
|
+
before { DataMapper::Adapters::ParseAdapter.any_instance.stub(upload_file: { "name" => name, "url" => url }) }
|
22
24
|
|
23
|
-
it { should
|
24
|
-
it { should be_has_key("name") }
|
25
|
-
it { should be_has_key("url") }
|
25
|
+
it { should eq(URI(url)) }
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
+
describe "#dump" do
|
30
|
+
subject { property.dump value }
|
31
|
+
|
32
|
+
let(:value) { URI(url) }
|
33
|
+
|
34
|
+
it { should eq("__type" => "File", "name" => name) }
|
35
|
+
end
|
36
|
+
|
29
37
|
describe "#load" do
|
30
38
|
subject { property.load value }
|
31
39
|
|
32
|
-
let(:value) { { "__type" => "File", "name" =>
|
40
|
+
let(:value) { { "__type" => "File", "name" => name, "url" => url } }
|
33
41
|
|
34
|
-
it { should eq(
|
42
|
+
it { should eq(URI(url)) }
|
35
43
|
|
36
44
|
context "when value is nil" do
|
37
45
|
let(:value) { nil }
|
@@ -43,7 +51,7 @@ describe DataMapper::Property::ParseFile do
|
|
43
51
|
describe "#valid?" do
|
44
52
|
subject { property.valid? value }
|
45
53
|
|
46
|
-
let(:value) {
|
54
|
+
let(:value) { URI(url) }
|
47
55
|
|
48
56
|
it { should be_true }
|
49
57
|
end
|
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.
|
4
|
+
version: 0.3.3
|
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:
|
244
|
+
hash: 2256594259984366431
|
245
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
246
|
none: false
|
247
247
|
requirements:
|