Skip to content

Commit

Permalink
Fix for Cancel and Submit data and endpoints for generic objects cust…
Browse files Browse the repository at this point in the history
…om buttons
  • Loading branch information
lgalis committed Nov 30, 2017
1 parent c762060 commit 80947a4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ ManageIQ.angular.app.controller('dialogUserController', ['API', 'dialogFieldRefr
}

function cancelClicked(_event) {
miqService.miqAjaxButton(cancelEndpoint);
miqService.redirectBack(__('Dialog Canceled'), 'info', cancelEndpoint);
}

function saveable() {
Expand Down
10 changes: 9 additions & 1 deletion app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,15 @@ def determine_dialog_locals_for_custom_button(obj, button_name)
force_old_dialog_use = false
when /GenericObject/
api_collection_name = "generic_objects"
cancel_endpoint = "/service/generic_object/"
cancel_endpoint = if params[:id]
url_for_only_path(:controller => controller_name,
:id => record.id,
:action => :show,
:display => "generic_objects",
:only_path => true)
else
"/service/explorer"
end
force_old_dialog_use = false
else
force_old_dialog_use = true
Expand Down
6 changes: 5 additions & 1 deletion app/controllers/service_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ def service_form_fields
}
end

def item_url(record_id, item_id)
"/#{controller_name}/show/#{record_id}?show=#{item_id}"
end

def generic_object
return unless init_show_variables

Expand All @@ -171,7 +175,7 @@ def generic_object
@item = @record.generic_objects.find(from_cid(id)).first
drop_breadcrumb(:name => _("%{name} (All Generic Objects)") % {:name => @record.name},
:url => show_link(@record, :display => @display))
drop_breadcrumb(:name => @item.name, :url => "/#{controller_name}/show/#{@record.id}?display=generic_objects/show=#{id}")
drop_breadcrumb(:name => @item.name, :url => item_url(@record.id, @item.id))
@view = get_db_view(GenericObject)
@sb[:rec_id] = id
show_item
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,35 @@ describe('dialogUserController', function() {
$controller.setDialogData({data: {field1: 'field1'}});
});

context('when the submit endpoint deals with generic objects', function() {
beforeEach(inject(function(_$controller_) {
$controller = _$controller_('dialogUserController', {
API: API,
dialogFieldRefreshService: dialogFieldRefreshService,
miqService: miqService,
dialogId: '1234',
apiSubmitEndpoint: 'generic_objects',
apiAction: 'custom_action',
cancelEndpoint: 'cancel endpoint',
});

$controller.setDialogData({data: {field1: 'field1'}});

spyOn(API, 'post').and.returnValue(Promise.resolve('awesome'));
}));

it('posts to the API with the right data', function(done) {
$controller.submitButtonClicked();

setTimeout(function() {
expect(API.post).toHaveBeenCalledWith('generic_objects', {
action: 'custom_action', parameters: {field1: 'field1'}
});
done();
});
});
});

context('when the API call succeeds', function() {
beforeEach(function() {
spyOn(API, 'post').and.returnValue(Promise.resolve('awesome'));
Expand Down Expand Up @@ -145,7 +174,7 @@ describe('dialogUserController', function() {
describe('cancelClicked', function() {
it('uses the miqService to make a call to catalog/explorer', function() {
$controller.cancelClicked('event');
expect(miqService.miqAjaxButton).toHaveBeenCalledWith('cancel endpoint');
expect(miqService.redirectBack).toHaveBeenCalledWith('Dialog Canceled', 'info', 'cancel endpoint');
});
});

Expand Down

0 comments on commit 80947a4

Please sign in to comment.