Skip to content

Commit

Permalink
Merge pull request #526 from eclarizio/BZ1427531
Browse files Browse the repository at this point in the history
Fix for inability to import an automate zip file
  • Loading branch information
mzazrivec authored Mar 6, 2017
2 parents abbb9b3 + d464cf8 commit 03f4f3c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
13 changes: 7 additions & 6 deletions app/services/automate_import_json_serializer_service.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
class AutomateImportJsonSerializerService
def serialize(import_file_upload)
temp_file = Tempfile.new(['automate_temporary_zip', '.zip'])
temp_file.binmode
temp_file.write(import_file_upload.binary_blob.binary)
ae_import = MiqAeImport.new("*", "zip_file" => temp_file.path)

temp_file.unlink
ae_import = nil
Tempfile.open(['automate_temporary_zip', '.zip']) do |temp_file|
temp_file.binmode
temp_file.write(import_file_upload.binary_blob.binary)
temp_file.close
ae_import = MiqAeImport.new("*", "zip_file" => temp_file.path)
end

domains = ae_import.domain_entries("*")

Expand Down
10 changes: 7 additions & 3 deletions spec/services/automate_import_json_serializer_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
allow(import_file_upload).to receive(:binary_blob).and_return(binary_blob)
allow(binary_blob).to receive(:binary).and_return('a bunch of junk')
allow(tempfile).to receive(:binmode)
allow(Tempfile).to receive(:new).with(['automate_temporary_zip', '.zip']).and_return(tempfile)
allow(tempfile).to receive(:close)
allow(Tempfile).to receive(:open).with(['automate_temporary_zip', '.zip']).and_yield(tempfile)
allow(MiqAeImport).to receive(:new).with('*', 'zip_file' => tempfile.path).and_return(miq_ae_yaml_import_zipfs)
allow(miq_ae_yaml_import_zipfs).to receive(:domain_entries).with('*').and_return(
['Customer/test1.yml', 'ManageIQ/test2.yml']
Expand Down Expand Up @@ -95,8 +96,11 @@
tempfile.unlink
end

it 'sets the tempfile to binmode' do
expect(tempfile).to receive(:binmode)
it "sets the tempfile to binmode, writes to it, and then closes it" do
expect(tempfile).to receive(:binmode).ordered
expect(tempfile).to receive(:write).with("a bunch of junk").ordered
expect(tempfile).to receive(:close).ordered

automate_import_json_serializer_service.serialize(import_file_upload)
end

Expand Down

0 comments on commit 03f4f3c

Please sign in to comment.