Skip to content

Commit

Permalink
Allow importing into a new domain with the same name as import from
Browse files Browse the repository at this point in the history
  • Loading branch information
eclarizio committed Aug 11, 2015
1 parent 7c019c8 commit c0f3abc
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/controllers/miq_ae_tools_controller.rb
Expand Up @@ -90,7 +90,10 @@ def import_export
drop_breadcrumb( {:name=>"Import / Export", :url=>"/miq_ae_tools/import_export"} )
@lastaction = "import_export"
@layout = "miq_ae_export"
@importable_domain_options = MiqAeDomain.all_unlocked.collect { |domain| [domain.name, domain.name] }
@importable_domain_options = [["<Same as import from>", nil]]
MiqAeDomain.all_unlocked.collect do |domain|
@importable_domain_options << [domain.name, domain.name]
end
render :action=>"show"
end

Expand Down
2 changes: 1 addition & 1 deletion app/services/automate_import_service.rb
Expand Up @@ -12,7 +12,7 @@ def import_datastore(import_file_upload,
namespace_or_class_list)
File.open("automate_temporary_zip.zip", "wb") { |file| file.write(import_file_upload.binary_blob.binary) }
import_options = {
"import_as" => domain_name_to_import_to,
"import_as" => domain_name_to_import_to.presence || domain_name_to_import_from,
"overwrite" => true,
"zip_file" => "automate_temporary_zip.zip"
}
Expand Down
20 changes: 20 additions & 0 deletions spec/controllers/miq_ae_tools_controller_spec.rb
Expand Up @@ -20,6 +20,26 @@
end
end

describe "#import_export" do
include_context "valid session"

let(:fake_domain) { active_record_instance_double("MiqAeDomain", :name => "test_domain") }

before do
bypass_rescue
MiqAeDomain.stub(:all_unlocked).and_return([fake_domain])
end

it "includes a list of importable domain options" do
get :import_export

expect(assigns(:importable_domain_options)).to eq([
["<Same as import from>", nil],
%w(test_domain test_domain)
])
end
end

describe "#cancel_import" do
include_context "valid session"

Expand Down
12 changes: 12 additions & 0 deletions spec/services/automate_import_service_spec.rb
Expand Up @@ -86,6 +86,18 @@
"import stats"
)
end

context "when the domain name to import to is blank" do
it "creates a new MiqAeImport with the correct import options" do
expect(MiqAeImport).to receive(:new).with(
"carrot",
"import_as" => "carrot",
"overwrite" => true,
"zip_file" => "automate_temporary_zip.zip"
).and_return(miq_ae_import)
automate_import_service.import_datastore(import_file_upload, "carrot", "", ["starch"])
end
end
end

describe "#store_for_import" do
Expand Down

0 comments on commit c0f3abc

Please sign in to comment.