Skip to content

Commit

Permalink
Merge pull request #1860 from DarthSim/fix-new-model-blank-uploader
Browse files Browse the repository at this point in the history
Memorize uploader instance when creating a blank uploader
  • Loading branch information
thomasfedb committed Feb 2, 2016
2 parents fd9fc91 + 8b0195a commit 488dc4a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/carrierwave/mount.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def mount_uploader(column, uploader=nil, options={}, &block)
mod.class_eval <<-RUBY, __FILE__, __LINE__+1
def #{column}
_mounter(:#{column}).uploaders[0] or _mounter(:#{column}).blank_uploader
_mounter(:#{column}).uploaders[0] ||= _mounter(:#{column}).blank_uploader
end
def #{column}=(new_file)
Expand Down
5 changes: 5 additions & 0 deletions spec/mount_single_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ def rotate
expect(@instance.image).to be_blank
end

it "should return the same object every time when nothing has been assigned" do
expect(@instance).to receive(:read_uploader).with(:image).and_return(nil)
expect(@instance.image.object_id).to eq @instance.image.object_id
end

it "should return a blank uploader when an empty string has been assigned" do
expect(@instance).to receive(:read_uploader).with(:image).and_return('')
expect(@instance.image).to be_an_instance_of(@uploader)
Expand Down

0 comments on commit 488dc4a

Please sign in to comment.