diff options
author | Louise Crow <louise.crow@gmail.com> | 2013-01-14 14:45:41 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2013-01-14 14:45:41 +0000 |
commit | 843805e5d92eded943bd2a32b02ac967539245e8 (patch) | |
tree | 7b370cd90c329f2e68a5528ceefe55b06935ce03 | |
parent | 115161e5cc9f11cf6d1de041d1a17dced2ce72b4 (diff) |
As we're validating filename with validates_presence_of, which doesn't allow blanks, ensure_filename! should populate a default filename on a blank filename, as well as on nil.
-rw-r--r-- | app/models/foi_attachment.rb | 2 | ||||
-rw-r--r-- | spec/models/foi_attachment_spec.rb | 13 |
2 files changed, 13 insertions, 2 deletions
diff --git a/app/models/foi_attachment.rb b/app/models/foi_attachment.rb index 2f8a9ab04..723bc4abb 100644 --- a/app/models/foi_attachment.rb +++ b/app/models/foi_attachment.rb @@ -219,7 +219,7 @@ class FoiAttachment < ActiveRecord::Base def ensure_filename! - if self.filename.nil? + if self.filename.blank? calc_ext = AlaveteliFileTypes.mimetype_to_extension(self.content_type) if !calc_ext calc_ext = "bin" diff --git a/spec/models/foi_attachment_spec.rb b/spec/models/foi_attachment_spec.rb index 9d44957e4..537a3363c 100644 --- a/spec/models/foi_attachment_spec.rb +++ b/spec/models/foi_attachment_spec.rb @@ -30,6 +30,17 @@ describe FoiAttachment, " when calculating due date" do main.delete_cached_file! main = im.get_main_body_text_part main.body.should == orig_body - + end end + +describe FoiAttachment, "when ensuring a filename is present" do + + it 'should create a filename for an instance with a blank filename' do + attachment = FoiAttachment.new + attachment.filename = '' + attachment.ensure_filename! + attachment.filename.should == 'attachment.bin' + end + +end |