Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Fixed fog file extension method #1253

Merged
merged 3 commits into from

2 participants

@mzubala

When I upload a file using fog storage and then try to get the file's extension I get full file name when the file has no extension. This pull request fixes that problem.

@bensie
Owner

Can you include a spec that fails without this patch?

@mzubala

I included a spec for this change. I'm not sure why Travis CI build fails. All tests pass on my local environment.

@bensie bensie merged commit 02b9652 into carrierwaveuploader:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 25, 2013
  1. @mzubala
  2. @mzubala

    Update fog.rb

    mzubala authored
    Documentation comment update
Commits on Nov 27, 2013
  1. @mzubala
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 12 deletions.
  1. +3 −2 lib/carrierwave/storage/fog.rb
  2. +24 −10 spec/storage/fog_helper.rb
View
5 lib/carrierwave/storage/fog.rb
@@ -192,10 +192,11 @@ def delete
#
# === Returns
#
- # [String] extension of file
+ # [String] extension of file or nil if the file has no extension
#
def extension
- path.split('.').last
+ path_elements = path.split('.')
+ path_elements.last if path_elements.size > 1
end
##
View
34 spec/storage/fog_helper.rb
@@ -7,10 +7,10 @@ def fog_tests(fog_credentials)
before do
CarrierWave.configure do |config|
config.reset_config
- config.fog_attributes = {}
- config.fog_credentials = fog_credentials
- config.fog_directory = CARRIERWAVE_DIRECTORY
- config.fog_public = true
+ config.fog_attributes = {}
+ config.fog_credentials = fog_credentials
+ config.fog_directory = CARRIERWAVE_DIRECTORY
+ config.fog_public = true
config.fog_use_ssl_for_aws = true
end
@@ -34,27 +34,30 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
it "should cache_stored_file! after store!" do
uploader = @uploader.new
uploader.store!(@file)
- lambda{ uploader.cache_stored_file! }.should_not raise_error
+ lambda { uploader.cache_stored_file! }.should_not raise_error
end
end
describe '#store!' do
+
+ let(:store_path) { 'uploads/test+.jpg' }
+
before do
- @uploader.stub!(:store_path).and_return('uploads/test+.jpg')
+ @uploader.stub!(:store_path).and_return(store_path)
@fog_file = @storage.store!(@file)
end
it "should upload the file" do
- @directory.files.get('uploads/test+.jpg').body.should == 'this is stuff'
+ @directory.files.get(store_path).body.should == 'this is stuff'
end
it "should have a path" do
- @fog_file.path.should == 'uploads/test+.jpg'
+ @fog_file.path.should == store_path
end
it "should have a content_type" do
@fog_file.content_type.should == 'image/jpeg'
- @directory.files.get('uploads/test+.jpg').content_type.should == 'image/jpeg'
+ @directory.files.get(store_path).content_type.should == 'image/jpeg'
end
it "should have an extension" do
@@ -151,6 +154,17 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
@fog_file.url.should == 'http://foo.bar/uploads/test%2B.jpg'
end
end
+
+ end
+
+ context "without extension" do
+
+ let(:store_path) { 'uploads/test' }
+
+ it "should have no extension" do
+ @fog_file.extension.should be_nil
+ end
+
end
it "should return filesize" do
@@ -159,7 +173,7 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
it "should be deletable" do
@fog_file.delete
- @directory.files.head('uploads/test+.jpg').should == nil
+ @directory.files.head(store_path).should == nil
end
end
Something went wrong with that request. Please try again.