Skip to content

Commit

Permalink
Changed Domain/Namespace add/edit flash messages to be consistent
Browse files Browse the repository at this point in the history
Changed Domain/Namespace add/edit flash messages to be consistent with delete method.
Added spec tests to verify flash message when deleting/updating records.

https://bugzilla.redhat.com/show_bug.cgi?id=1477037
  • Loading branch information
h-kataria committed Aug 2, 2017
1 parent 67768fe commit 31791dd
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 5 deletions.
10 changes: 5 additions & 5 deletions app/controllers/miq_ae_class_controller.rb
Expand Up @@ -1051,7 +1051,7 @@ def update_ns
@changed = true
javascript_flash
else
add_flash(_("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:model => @edit[:typ]), :name => ae_ns.name})
add_flash(_("%{model} \"%{name}\" was saved") % {:model => ui_lookup(:model => @edit[:typ]), :name => get_record_display_name(ae_ns)})
AuditEvent.success(build_saved_audit(ae_ns, @edit))
session[:edit] = nil # clean out the saved info
@in_a_form = false
Expand Down Expand Up @@ -1231,7 +1231,7 @@ def create_ns
end
ns_set_record_vars(add_ae_ns) # Set the record variables, but don't save
if add_ae_ns.valid? && !flash_errors? && add_ae_ns.save
add_flash(_("%{model} \"%{name}\" was added") % {:model => ui_lookup(:model => add_ae_ns.class.name), :name => add_ae_ns.name})
add_flash(_("%{model} \"%{name}\" was added") % {:model => ui_lookup(:model => add_ae_ns.class.name), :name => get_record_display_name(add_ae_ns)})
@in_a_form = false
replace_right_cell(:replace_trees => [:ae])
else
Expand Down Expand Up @@ -1838,7 +1838,7 @@ def delete_domain
domain.git_enabled? ? git_domains.push(domain) : aedomains.push(domain.id)
else
add_flash(_("Read Only %{model} \"%{name}\" cannot be deleted") %
{:model => ui_lookup(:model => "MiqAeDomain"), :name => domain.name}, :error)
{:model => ui_lookup(:model => "MiqAeDomain"), :name => get_record_display_name(domain)}, :error)
end
end
end
Expand Down Expand Up @@ -1887,7 +1887,7 @@ def items_to_delete(selected)
ns_list.push(from_cid(item[1]))
else
add_flash(_("\"%{field}\" %{model} cannot be deleted") %
{:model => ui_lookup(:model => "MiqAeDomain"), :field => record.name},
{:model => ui_lookup(:model => "MiqAeDomain"), :field => get_record_display_name(record)},
:error)
end
else
Expand Down Expand Up @@ -2316,7 +2316,7 @@ def edit_domain_or_namespace
@ae_ns = find_record_with_rbac(typ, from_cid(obj[0].split('-')[1]))
if @ae_ns.domain? && !@ae_ns.editable_properties?
add_flash(_("Read Only %{model} \"%{name}\" cannot be edited") %
{:model => ui_lookup(:model => "MiqAeDomain"), :name => @ae_ns.name},
{:model => ui_lookup(:model => "MiqAeDomain"), :name => get_record_display_name(@ae_ns)},
:error)
else
ns_set_form_vars
Expand Down
53 changes: 53 additions & 0 deletions spec/controllers/miq_ae_class_controller_spec.rb
Expand Up @@ -709,6 +709,59 @@
flash_messages = assigns(:flash_array)
expect(flash_messages.first[:message]).to include("Automate Namespace \"foo_namespace\": Delete successful")
end

it "Should use description in flash message when available" do
controller.instance_variable_set(:@_params,
:miq_grid_checks => "aen-#{@namespace.id}",
:id => @namespace.id)
@namespace.update_column(:description, "foo_description")
@namespace.reload
controller.send(:delete_namespaces_or_classes)
flash_messages = assigns(:flash_array)
expect(flash_messages.first[:message]).to include("Automate Namespace \"foo_description\": Delete successful")
end
end

context "#update_ns" do
before do
stub_user(:features => :all)
domain = FactoryGirl.create(:miq_ae_domain, :tenant => Tenant.seed)
@namespace = FactoryGirl.create(:miq_ae_namespace,
:name => "foo_namespace",
:description => "foo_description",
:parent => domain)
session[:edit] = {
:ae_ns_id => @namespace.id,
:typ => "MiqAeDomain",
:key => "aens_edit__#{@namespace.id}",
:rec_id => @namespace.id,
:new => {
:ns_name => "test1",
:ns_description => "desc",
:enabled => true
},
:current => {
:ns_name => "test",
:ns_description => "desc",
:enabled => true
}
}
controller.instance_variable_set(:@sb,
:trees => {},
:active_tree => :ae_tree)
allow(controller).to receive(:replace_right_cell)
controller.x_node = "aen-#{@namespace.compressed_id}"
allow(controller).to receive(:find_records_with_rbac).and_return([@namespace])
end

it "Should use description in flash message when editing a domain" do
controller.instance_variable_set(:@_params,
:button => "save",
:id => @namespace.id)
controller.send(:update_ns)
flash_messages = assigns(:flash_array)
expect(flash_messages.first[:message]).to include("Automate Domain \"desc\" was saved")
end
end

context "#deleteclasses" do
Expand Down

0 comments on commit 31791dd

Please sign in to comment.