From 663761c4fa69f6931f7959e50aa0bfa376b7f528 Mon Sep 17 00:00:00 2001 From: Hilda Stastna Date: Mon, 26 Aug 2019 17:41:59 +0200 Subject: [PATCH] Add Back button to policy simulation page for non-explorer Fixes https://bugzilla.redhat.com/show_bug.cgi?id=1704395 --- .../application_controller/policy_support.rb | 2 ++ app/views/vm_common/_policies.html.haml | 9 +++++++++ .../policy_support_spec.rb | 16 ++++++++++++++++ spec/views/vm_common/_policies.html.haml_spec.rb | 13 +++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 spec/views/vm_common/_policies.html.haml_spec.rb diff --git a/app/controllers/application_controller/policy_support.rb b/app/controllers/application_controller/policy_support.rb index 35f54e2d741..9ff9baca7c2 100644 --- a/app/controllers/application_controller/policy_support.rb +++ b/app/controllers/application_controller/policy_support.rb @@ -98,6 +98,8 @@ def policy_sim(records = []) @refresh_partial = "layouts/policy_sim" replace_right_cell(:refresh_breadcrumbs => false) end + else + session[:edit] = @edit end end diff --git a/app/views/vm_common/_policies.html.haml b/app/views/vm_common/_policies.html.haml index 5bab4ad71cc..b346e22bb60 100644 --- a/app/views/vm_common/_policies.html.haml +++ b/app/views/vm_common/_policies.html.haml @@ -12,3 +12,12 @@ = _('* Items in red italics do not change the outcome of the scope or expression.').html_safe +- unless @explorer + #buttons{:align => 'right'} + -# Go back to policy simulation screen + = link_to(_('Back'), + {:action => 'policy_sim', :continue => true, :controller => 'vm'}, + :class => 'btn btn-default', + :alt => t = _('Back'), + :title => t, + :method => :post) diff --git a/spec/controllers/application_controller/policy_support_spec.rb b/spec/controllers/application_controller/policy_support_spec.rb index 935f4042884..7508a2c8681 100644 --- a/spec/controllers/application_controller/policy_support_spec.rb +++ b/spec/controllers/application_controller/policy_support_spec.rb @@ -66,4 +66,20 @@ end end end + + describe '#policy_sim' do + let(:vm) { FactoryBot.create(:vm_infra) } + + before do + allow(controller).to receive(:drop_breadcrumb) + allow(controller).to receive(:session).and_return(:tag_db => VmOrTemplate, :tag_items => [vm]) + allow(controller).to receive(:vm_or_instance).and_return('vm_infra') + controller.params = {:action => 'policy_sim', :continue => true, :controller => 'vm'} + end + + it 'sets session[:edit] when going back to policy simulation, in non-explorer screen' do + controller.send(:policy_sim) + expect(controller.session).to include(:edit => {:pol_items => [vm]}) + end + end end diff --git a/spec/views/vm_common/_policies.html.haml_spec.rb b/spec/views/vm_common/_policies.html.haml_spec.rb new file mode 100644 index 00000000000..f3c28716ab4 --- /dev/null +++ b/spec/views/vm_common/_policies.html.haml_spec.rb @@ -0,0 +1,13 @@ +describe 'vm_common/_policies.html.haml' do + before do + assign(:policy_options, :out_of_scope => true, :passed => true, :failed => true) + assign(:policy_simulation_tree, TreeBuilderPolicySimulation.new(:policy_simulation_tree, {}, true)) + assign(:record, FactoryBot.create(:vm_infra)) + set_controller_for_view('vm_or_template') + end + + it 'renders Back button for non explorer screens' do + render :partial => 'vm_common/policies' + expect(response).to include('Back') + end +end