Skip to content

Commit

Permalink
* support zipping multiple files
Browse files Browse the repository at this point in the history
  • Loading branch information
hone committed Jan 12, 2009
1 parent 7261bc8 commit 41288d6
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
16 changes: 15 additions & 1 deletion app/models/remote_mail.rb
Expand Up @@ -65,6 +65,20 @@ def zip( files, output_file )
end end
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
end end
31 changes: 25 additions & 6 deletions spec/models/remote_mail_spec.rb
Expand Up @@ -34,28 +34,47 @@ def should_have_error_on_attribute( attribute, value = nil, error_num = 1 )


before(:each) do before(:each) do
setup_remote_mail setup_remote_mail
FileUtils.touch( TMP_MBOX_FILE ) end

after(:all) do
remove_file( TMP_MBOX_FILE )
remove_file( @zip_output )
end end


it "should zip a single mbox" do it "should zip a single mbox" do
FileUtils.touch( TMP_MBOX_FILE )
@remote_mail.zip( [TMP_MBOX_FILE], @zip_output ) @remote_mail.zip( [TMP_MBOX_FILE], @zip_output )
File.should be_exist( @zip_output ) File.should be_exist( @zip_output )
File.should_not be_exist( TMP_MBOX_FILE ) File.should_not be_exist( TMP_MBOX_FILE )
end 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 it "should overwrite existing zip file" do
FileUtils.touch( TMP_MBOX_FILE )
remove_file( @zip_output ) remove_file( @zip_output )
File.open( @zip_output, 'w' ) {|file| file.puts "delete this" } File.open( @zip_output, 'w' ) {|file| file.puts "delete this" }


@remote_mail.zip( [TMP_MBOX_FILE], @zip_output ) @remote_mail.zip( [TMP_MBOX_FILE], @zip_output )
File.should be_exist( @zip_output ) File.should be_exist( @zip_output )
File.open( @zip_output ) {|file| file.readlines.first.should_not match /delete this/ } File.open( @zip_output ) {|file| file.readlines.first.should_not match /delete this/ }
end end

after(:all) do
remove_file( TMP_MBOX_FILE )
remove_file( @zip_output )
end
end end


describe RemoteMail, "validations" do describe RemoteMail, "validations" do
Expand Down

0 comments on commit 41288d6

Please sign in to comment.