Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fog storage handles missing files on size #2

Open
wants to merge 5 commits into
base: skroutz
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/carrierwave/orm/activerecord.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def mount_uploader(column, uploader=nil, options={}, &block)
after_commit :"mark_remove_#{column}_false", :on => :update
before_update :"store_previous_model_for_#{column}"
after_save :"remove_previously_stored_#{column}"
after_save :"invalidate_memoized_filename_for_#{column}"

class_eval <<-RUBY, __FILE__, __LINE__+1
def #{column}=(new_file)
Expand All @@ -51,6 +52,10 @@ def remove_#{column}!
_mounter(:#{column}).write_identifier
end

def invalidate_memoized_filename_for_#{column}
send(:instance_variable_set, :"@#{column}_regularized_filename", nil)
end

def serializable_hash(options=nil)
hash = {}

Expand Down
3 changes: 2 additions & 1 deletion lib/carrierwave/storage/fog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ def content_type=(new_content_type)
def delete
# avoid a get by just using local reference
directory.files.new(:key => path).destroy
rescue ::Fog::Service::NotFound
end

##
Expand Down Expand Up @@ -236,7 +237,7 @@ def read
# [Integer] size of file body
#
def size
file.content_length
file.nil? ? 0 : file.content_length
end

##
Expand Down
2 changes: 1 addition & 1 deletion lib/carrierwave/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module CarrierWave
VERSION = "0.10.0"
VERSION = "0.10.0.1.skroutz"
end
12 changes: 12 additions & 0 deletions spec/storage/fog_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ class FogSpec#{fog_credentials[:provider]}Uploader < CarrierWave::Uploader::Base
@fog_file.delete
@directory.files.head(store_path).should == nil
end

context "when the files has been deleted" do
before do
@fog_file.delete
end

it "does not blow up" do
expect {
@fog_file.size
}.not_to raise_error
end
end
end

describe '#retrieve!' do
Expand Down