Permalink
Browse files

Updating upload paths

  • Loading branch information...
1 parent a93bbff commit de47fef9a641e424385c7662ca732086c10c7010 @aubreyrhodes committed Nov 21, 2011
Showing with 25 additions and 2 deletions.
  1. +9 −1 lib/scribd-carrierwave.rb
  2. +16 −1 spec/scribd-carrierwave_spec.rb
View
@@ -11,7 +11,7 @@ def included(base)
end
def upload uploader
- args = { file: uploader.url, access: 'private' }
+ args = { file: full_path(uploader), access: 'private' }
scribd_user.upload(args)
end
@@ -20,6 +20,14 @@ def destroy uploader
document.destroy if !document.nil?
end
+ def full_path uploader
+ if uploader.url =~ /http(s?):\/\//
@wallace

wallace Nov 23, 2011

Would a ^ at the beginning of your regex make sense here?

@aubreyrhodes

aubreyrhodes Nov 23, 2011

Owner

Yes, that's a good suggestion.

+ uploader.url
+ else
+ uploader.root + uploader.url
+ end
+ end
+
module ClassMethods
def has_ipaper
include InstanceMethods
@@ -11,7 +11,8 @@
describe "upload" do
it "calls rscribd.upload with the correct arguments" do
@uploader.stubs(:url).returns('test_url')
- @scribd_user_mock.expects(:upload).with(has_entries(file: 'test_url', access: 'private'))
+ @uploader.stubs(:root).returns('/root/path/')
+ @scribd_user_mock.expects(:upload).with(has_entries(file: '/root/path/test_url', access: 'private'))
ScribdCarrierWave::upload @uploader
end
end
@@ -25,6 +26,20 @@
ScribdCarrierWave::destroy @uploader
end
end
+
+ describe "full_path" do
+ it "returns the full file path for file storage" do
+ @uploader.stubs(:url).returns('/test/path.pdf')
+ @uploader.stubs(:root).returns('/full/path')
+ ScribdCarrierWave::full_path(@uploader).should eq '/full/path/test/path.pdf'
+ end
+
+ it "returns the url for fog storage" do
+ @uploader.stubs(:url).returns('http://www.test.com/file.pdf')
+ @uploader.stubs(:root).returns('/full/path')
+ ScribdCarrierWave::full_path(@uploader).should eq 'http://www.test.com/file.pdf'
+ end
+ end
end
context "instance methods" do

0 comments on commit de47fef

Please sign in to comment.