Browse files

Merge pull request #9 from czarneckid/master

Allow for upload to use the filename of the local file by default and test
  • Loading branch information...
2 parents 09f1b79 + 1126977 commit a9a80646e258bc27dda2b3d879d859516dba0243 @delano delano committed Jul 18, 2011
Showing with 16 additions and 2 deletions.
  1. +2 −2 lib/net/sftp/session.rb
  2. +14 −0 test/test_upload.rb
View
4 lib/net/sftp/session.rb
@@ -94,12 +94,12 @@ def initialize(session, &block)
#
# uploader = sftp.upload("/local/path", "/remote/path")
# uploader.wait
- def upload(local, remote, options={}, &block)
+ def upload(local, remote = File.basename(local), options={}, &block)
Operations::Upload.new(self, local, remote, options, &block)
end
# Identical to #upload, but blocks until the upload is complete.
- def upload!(local, remote, options={}, &block)
+ def upload!(local, remote = File.basename(local), options={}, &block)
upload(local, remote, options, &block).wait
end
View
14 test/test_upload.rb
@@ -10,6 +10,20 @@ def test_upload_file_should_send_file_contents
assert_scripted_command { sftp.upload("/path/to/local", "/path/to/remote") }
end
+ def test_upload_file_without_remote_uses_filename_of_local_file
+ expect_file_transfer("/path/to/local", "local", "here are the contents")
+
+ assert_scripted_command do
+ sftp.upload("/path/to/local") { |*args| record_progress(args) }
+ end
+
+ assert_progress_reported_open(:remote => "local")
+ assert_progress_reported_put(0, "here are the contents", :remote => "local")
+ assert_progress_reported_close(:remote => "local")
+ assert_progress_reported_finish
+ assert_no_more_reported_events
+ end
+
def test_upload_file_with_progress_should_report_progress
expect_file_transfer("/path/to/local", "/path/to/remote", "here are the contents")

0 comments on commit a9a8064

Please sign in to comment.