test/dirmon_entry_test.rb in rocketjob-1.2.1 vs test/dirmon_entry_test.rb in rocketjob-1.3.0

- old
+ new

@@ -1,10 +1,20 @@ require_relative 'test_helper' require_relative 'jobs/test_job' # Unit Test for RocketJob::Job class DirmonEntryTest < Minitest::Test + class WithFullFileNameJob < RocketJob::Job + # Dirmon will store the filename in this property when starting the job + key :full_file_name, String + + def perform + # Do something with the file name stored in :full_file_name + end + end + + describe RocketJob::DirmonEntry do describe '.config' do it 'support multiple databases' do assert_equal 'test_rocketjob', RocketJob::DirmonEntry.collection.db.name end @@ -184,15 +194,21 @@ @archive_path.mkpath @archive_path = @archive_path.realdirpath @entry = RocketJob::DirmonEntry.new( pattern: 'test/files/**/*', job_class_name: 'Jobs::TestJob', - arguments: [{input: 'yes'}], + arguments: [{}], properties: {priority: 23, perform_method: :event}, archive_directory: @archive_directory ) - @job = Jobs::TestJob.new + @job = Jobs::TestJob.new( + @entry.properties.merge( + arguments: @entry.arguments, + properties: @entry.properties, + perform_method: @entry.perform_method + ) + ) @file = Tempfile.new('archive') @file_name = @file.path @pathname = Pathname.new(@file_name) File.open(@file_name, 'w') { |file| file.write('Hello World') } assert File.exists?(@file_name) @@ -220,12 +236,32 @@ assert File.exists?(@archive_real_name) end end describe '#upload_default' do - it 'upload' do + it 'sets full_file_name in Hash argument' do @entry.send(:upload_default, @job, @pathname) assert_equal @archive_real_name, @job.arguments.first[:full_file_name], @job.arguments + end + + it 'sets full_file_name property' do + @entry = RocketJob::DirmonEntry.new( + pattern: 'test/files/**/*', + job_class_name: 'DirmonEntryTest::WithFullFileNameJob', + archive_directory: @archive_directory + ) + assert @entry.valid?, @entry.errors.messages + job = @entry.job_class.new + @entry.send(:upload_default, job, @pathname) + archive_real_name = @archive_path.join("#{job.id}_#{File.basename(@file_name)}").to_s + assert_equal archive_real_name, job.full_file_name, job.arguments + end + + it 'handles non hash argument and missing property' do + @job.arguments = [1] + assert_raises ArgumentError do + @entry.send(:upload_default, @job, @pathname) + end end end describe '#upload_file' do it 'upload using #file_store_upload' do