Skip to content

Commit

Permalink
Merge pull request #13871 from eclarizio/issue13792
Browse files Browse the repository at this point in the history
Fix for ImportFileUpload model is tightly coupled to UI Issue 13792
  • Loading branch information
gmcculloug authored Feb 15, 2017
2 parents 4ff192e + 5b6cd13 commit fdb12b1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 57 deletions.
31 changes: 6 additions & 25 deletions app/models/import_file_upload.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,10 @@ def policy_import_data
def service_dialog_list
sorted_service_dialogs = uploaded_yaml_content.sort_by { |service_dialog| service_dialog["label"].downcase }
sorted_service_dialogs.collect.with_index do |dialog, index|
status_icon = Dialog.exists?(:label => dialog["label"]) ? "checkmark" : "equal-green"
status = determine_status(status_icon)

{
:id => index,
:name => dialog["label"],
:status_icon => ActionController::Base.helpers.image_path("16/#{status_icon}.png"),
:status => status
:id => index,
:name => dialog["label"],
:exists => Dialog.exists?(:label => dialog["label"])
}
end
end
Expand All @@ -26,14 +22,10 @@ def widget_list
end

sorted_widgets.collect.with_index do |widget, index|
status_icon = MiqWidget.exists?(:title => widget["MiqWidget"]["title"]) ? "checkmark" : "equal-green"
status = determine_status(status_icon)

{
:id => index,
:name => widget["MiqWidget"]["title"],
:status_icon => ActionController::Base.helpers.image_path("16/#{status_icon}.png"),
:status => status
:id => index,
:name => widget["MiqWidget"]["title"],
:exists => MiqWidget.exists?(:title => widget["MiqWidget"]["title"])
}
end
end
Expand All @@ -53,15 +45,4 @@ def uploaded_content
def uploaded_yaml_content
YAML.load(binary_blob.binary)
end

private

def determine_status(status_icon)
case status_icon
when "checkmark"
_("This object already exists in the database with the same name")
when "equal-green"
_("New object")
end
end
end
56 changes: 24 additions & 32 deletions spec/models/import_file_upload_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,13 @@

it "returns json with a checkmark status icon" do
expected_list = [{
:id => 0,
:name => "dialog",
:status_icon => ActionController::Base.helpers.image_path('16/checkmark.png'),
:status => "This object already exists in the database with the same name"
:id => 0,
:name => "dialog",
:exists => true
}, {
:id => 1,
:name => "Dialog2",
:status_icon => ActionController::Base.helpers.image_path('16/checkmark.png'),
:status => "This object already exists in the database with the same name"
:id => 1,
:name => "Dialog2",
:exists => true
}]

expect(import_file_upload.service_dialog_list).to eq(expected_list)
Expand All @@ -46,15 +44,13 @@

it "returns json with an equal-green status icon" do
expected_list = [{
:id => 0,
:name => "dialog",
:status_icon => ActionController::Base.helpers.image_path('16/equal-green.png'),
:status => "New object"
:id => 0,
:name => "dialog",
:exists => false
}, {
:id => 1,
:name => "Dialog2",
:status_icon => ActionController::Base.helpers.image_path('16/equal-green.png'),
:status => "New object"
:id => 1,
:name => "Dialog2",
:exists => false
}]

expect(import_file_upload.service_dialog_list).to eq(expected_list)
Expand Down Expand Up @@ -83,15 +79,13 @@

it "returns json with a checkmark status icon" do
expected_list = [{
:id => 0,
:name => "widget",
:status_icon => ActionController::Base.helpers.image_path('16/checkmark.png'),
:status => "This object already exists in the database with the same name"
:id => 0,
:name => "widget",
:exists => true
}, {
:id => 1,
:name => "Widget1",
:status_icon => ActionController::Base.helpers.image_path('16/checkmark.png'),
:status => "This object already exists in the database with the same name"
:id => 1,
:name => "Widget1",
:exists => true
}]

expect(import_file_upload.widget_list).to eq(expected_list)
Expand All @@ -103,15 +97,13 @@

it "returns json with an equal-green status icon" do
expected_list = [{
:id => 0,
:name => "widget",
:status_icon => ActionController::Base.helpers.image_path('16/equal-green.png'),
:status => "New object"
:id => 0,
:name => "widget",
:exists => false
}, {
:id => 1,
:name => "Widget1",
:status_icon => ActionController::Base.helpers.image_path('16/equal-green.png'),
:status => "New object"
:id => 1,
:name => "Widget1",
:exists => false
}]

expect(import_file_upload.widget_list).to eq(expected_list)
Expand Down

0 comments on commit fdb12b1

Please sign in to comment.