Skip to content

Instantly share code, notes, and snippets.

@knewter
Created March 7, 2011 20:03
Show Gist options
  • Save knewter/859103 to your computer and use it in GitHub Desktop.
Save knewter/859103 to your computer and use it in GitHub Desktop.
require 'spec_helper'
describe ProgramManagerBatchInterface::AccountInformation, :real_transfer => true do
before(:each) do
write_enviro_config do
{
:development => {
:local_base_dir => '/tmp'
}
}
end
write_enviro_config_for_file_transfer_mixin do
{
:development => {
:sftp => {
:insight => {
:server => '127.0.0.1',
:username => 'bob',
:password => 'bobpass',
}
}
}
}
end
@tmp_upload_file_path = '/tmp/pm_account_inquiry_test_upload.txt'
File.open(@tmp_upload_file_path, 'w') do |f|
f << 'test data'
end
# Delete any files that might be floating around the ftp server related to these tests
subject.sftp_block(:insight) do |f|
f.remove!(subject.upload_path_for(@tmp_upload_file_path)) rescue nil # Delete any uploaded files
f.remove!(subject.archive_path_for(@tmp_upload_file_path)) rescue nil # Delete any archived files
end
end
it "should respond to #upload(key, path)" do
lambda{ subject.upload(:insight, @tmp_upload_file_path) }.should_not raise_error
end
it "should respond to #download(key, path)" do
# First, we upload a file to download
lambda{ subject.upload(:insight, @tmp_upload_file_path) }.should_not raise_error
# Then, we download it
lambda{ subject.download(:insight, subject.upload_path_for(@tmp_upload_file_path)) }.should_not raise_error
end
it "should move a processed file to the archive folder after downloading it" do
# First, we upload a file to download
lambda{ subject.upload(:insight, @tmp_upload_file_path) }.should_not raise_error
# Then, we download it
lambda{ subject.download(:insight, subject.upload_path_for(@tmp_upload_file_path)) }.should_not raise_error
# Then, we verify that it's been moved to the archive folder
lambda{
subject.sftp_block(:insight){|f| f.download!(subject.archive_path_for(@tmp_upload_file_path)) }
}.should_not raise_error
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment