Skip to content

Commit

Permalink
Display flash message after clicking on unknown/not common provider
Browse files Browse the repository at this point in the history
  • Loading branch information
hstastna committed Sep 26, 2019
1 parent 1693853 commit 7b9c1b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion app/controllers/restful_redirect_controller.rb
Expand Up @@ -13,7 +13,12 @@ def index
elsif %w[ManageIQ::Providers::EmbeddedAnsible::AutomationManager].include?(record.type)
redirect_to(:controller => 'ansible_playbook', :action => 'show_list')
else
redirect_to(polymorphic_path(record))
begin
redirect_to(polymorphic_path(record))
rescue NoMethodError
flash_to_session(_("Cannot redirect to \"%{record}\" provider.") % {:record => record.name}, :error)
redirect_to(:controller => 'ops', :action => 'explorer')
end
end
else
handle_missing_record
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/restful_redirect_controller_spec.rb
Expand Up @@ -63,5 +63,13 @@
get :index, :params => {:model => "ExtManagementSystem/#{manager.id}"}
expect(response).to redirect_to(:controller => 'ansible_playbook', :action => 'show_list')
end

it 'redirects to ops controller and displays flash message that it cannot redirect to the selected provider' do
embedded_ansible = FactoryBot.create(:provider_embedded_ansible)
allow(ExtManagementSystem).to receive(:find_by).and_return(embedded_ansible)
get :index, :params => {:model => "ExtManagementSystem/#{embedded_ansible.id}"}
expect(response).to redirect_to(:controller => 'ops', :action => 'explorer')
expect(controller.instance_variable_get(:@flash_array)).to eq([{:message => "Cannot redirect to \"#{embedded_ansible.name}\" provider.", :level => :error}])
end
end
end

0 comments on commit 7b9c1b5

Please sign in to comment.