npo_assets 0.1.5 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/npo_assets/asset.rb +3 -2
- data/npo_assets.gemspec +1 -1
- data/spec/npo_assets/asset_spec.rb +9 -1
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
data/lib/npo_assets/asset.rb
CHANGED
@@ -4,7 +4,7 @@ module NPO
|
|
4
4
|
include HTTParty
|
5
5
|
format :xml
|
6
6
|
|
7
|
-
attr_accessor :file
|
7
|
+
attr_accessor :file, :url
|
8
8
|
|
9
9
|
before_save :post_to_media_server
|
10
10
|
after_destroy :delete_from_media_server
|
@@ -49,9 +49,10 @@ module NPO
|
|
49
49
|
url = [NPO::Assets.base_url, 'assets']
|
50
50
|
url << self.remote_id unless new_record?
|
51
51
|
|
52
|
+
attrs = @file ? {:file => @file} : {:url => @url}
|
52
53
|
response = self.class.send(new_record? ? :post : :put,
|
53
54
|
url.join('/'),
|
54
|
-
:query => { :asset =>
|
55
|
+
:query => { :asset => attrs },
|
55
56
|
:headers => self.class.headers)
|
56
57
|
if response.code == 422
|
57
58
|
response['errors']['error'].each { |msg| errors[:base] << msg }
|
data/npo_assets.gemspec
CHANGED
@@ -24,12 +24,20 @@ describe NPO::Assets::Asset do
|
|
24
24
|
@asset.save
|
25
25
|
end
|
26
26
|
|
27
|
-
it "should send the correct vars" do
|
27
|
+
it "should send the correct vars with a file upload" do
|
28
28
|
NPO::Assets::Asset.should_receive(:post).with("http://test.com/assets",
|
29
29
|
:query => {:asset => {:file => "file"}},
|
30
30
|
:headers => {'X-Account' => 'account'})
|
31
31
|
do_create
|
32
32
|
end
|
33
|
+
|
34
|
+
it "should send the correct vars with a remote url" do
|
35
|
+
asset = NPO::Assets::Asset.new(:url => "remote_url")
|
36
|
+
NPO::Assets::Asset.should_receive(:post).with("http://test.com/assets",
|
37
|
+
:query => {:asset => {:url => "remote_url"}},
|
38
|
+
:headers => {'X-Account' => 'account'})
|
39
|
+
asset.save
|
40
|
+
end
|
33
41
|
|
34
42
|
describe "with successfull save" do
|
35
43
|
before(:each) do
|