Permalink
Browse files

* support zipping multiple files

  • Loading branch information...
1 parent 7261bc8 commit 41288d631f18fd3940e620763780259a1be3892e @hone committed Jan 12, 2009
Showing with 40 additions and 7 deletions.
  1. +15 −1 app/models/remote_mail.rb
  2. +25 −6 spec/models/remote_mail_spec.rb
@@ -65,6 +65,20 @@ def zip( files, output_file )
end
end
- files.each {|file| FileUtils.rm( file ) }
+ files.each {|file| remove_file_dir( file ) }
+ end
+
+ def remove_file_dir( path )
+ if File.exist?( path )
+ if File.directory?( path )
+ Dir[ "#{path}/*" ].each do |file|
+ remove_dir( file )
+ end
+
+ FileUtils.rmdir( path )
+ else
+ FileUtils.rm( path )
+ end
+ end
end
end
@@ -34,28 +34,47 @@ def should_have_error_on_attribute( attribute, value = nil, error_num = 1 )
before(:each) do
setup_remote_mail
- FileUtils.touch( TMP_MBOX_FILE )
+ end
+
+ after(:all) do
+ remove_file( TMP_MBOX_FILE )
+ remove_file( @zip_output )
end
it "should zip a single mbox" do
+ FileUtils.touch( TMP_MBOX_FILE )
@remote_mail.zip( [TMP_MBOX_FILE], @zip_output )
File.should be_exist( @zip_output )
File.should_not be_exist( TMP_MBOX_FILE )
end
+
+ it "should zip mbox and folder" do
+ parent_dir = "#{TMP_MBOX_FILE}/INBOX"
+ parent_mbox = "#{parent_dir}.mbox"
+ child_mbox = "#{parent_dir}/Drafts.mbox"
+ remove_dir( TMP_MBOX_FILE )
+ remove_dir( parent_dir )
+ remove_file( parent_mbox )
+
+ FileUtils.mkdir( TMP_MBOX_FILE )
+ FileUtils.touch( parent_mbox )
+ FileUtils.mkdir( parent_dir )
+ FileUtils.touch( child_mbox )
+ @remote_mail.zip( [parent_mbox, parent_dir], @zip_output )
+
+ File.should be_exist( @zip_output )
+ File.should_not be_exist( parent_dir )
+ end
it "should overwrite existing zip file" do
+ FileUtils.touch( TMP_MBOX_FILE )
remove_file( @zip_output )
File.open( @zip_output, 'w' ) {|file| file.puts "delete this" }
@remote_mail.zip( [TMP_MBOX_FILE], @zip_output )
File.should be_exist( @zip_output )
File.open( @zip_output ) {|file| file.readlines.first.should_not match /delete this/ }
end
-
- after(:all) do
- remove_file( TMP_MBOX_FILE )
- remove_file( @zip_output )
- end
end
describe RemoteMail, "validations" do

0 comments on commit 41288d6

Please sign in to comment.