From 76b0fca7be310117998e864ce598972e70fe9027 Mon Sep 17 00:00:00 2001 From: Lucas Silva Date: Thu, 5 Oct 2017 16:15:32 -0300 Subject: [PATCH] Added tests for physical server controller --- .../physical_server_controller_spec.rb | 80 ++++++++++++++----- 1 file changed, 62 insertions(+), 18 deletions(-) diff --git a/spec/controllers/physical_server_controller_spec.rb b/spec/controllers/physical_server_controller_spec.rb index 349be0a915d8..1e181db3951a 100644 --- a/spec/controllers/physical_server_controller_spec.rb +++ b/spec/controllers/physical_server_controller_spec.rb @@ -1,32 +1,76 @@ describe PhysicalServerController do include CompressedIds + render_views + let!(:server) { EvmSpecHelper.local_miq_server(:zone => zone) } let(:zone) { FactoryGirl.build(:zone) } - describe "#show" do - render_views - before(:each) do - EvmSpecHelper.create_guid_miq_server_zone - login_as FactoryGirl.create(:user) - ems = FactoryGirl.create(:ems_physical_infra) - asset_details = FactoryGirl.create(:asset_details) - computer_system = FactoryGirl.create(:computer_system, :hardware => FactoryGirl.create(:hardware)) - physical_server = FactoryGirl.create(:physical_server, - :asset_details => asset_details, - :computer_system => computer_system, - :ems_id => ems.id) - get :show, :params => {:id => physical_server.id} - end - it { expect(response.status).to eq(200) } + before(:each) do + stub_user(:features => :all) + EvmSpecHelper.create_guid_miq_server_zone + login_as FactoryGirl.create(:user) + ems = FactoryGirl.create(:ems_physical_infra) + asset_details = FactoryGirl.create(:asset_details) + computer_system = FactoryGirl.create(:computer_system, :hardware => FactoryGirl.create(:hardware)) + @physical_server = FactoryGirl.create(:physical_server, + :asset_details => asset_details, + :computer_system => computer_system, + :ems_id => ems.id, + :id => 1) end describe "#show_list" do before(:each) do - stub_user(:features => :all) FactoryGirl.create(:physical_server) - get :show_list end - it { expect(response.status).to eq(200) } + + subject { get :show_list } + + it do + is_expected.to have_http_status 200 + is_expected.to render_template(:partial => "layouts/_gtl") + end + end + + describe "#show" do + context "with valid id" do + subject { get :show, :params => {:id => @physical_server.id} } + + it "should respond to show" do + is_expected.to have_http_status 200 + is_expected.to render_template(:partial => "layouts/_textual_groups_generic") + end + end + + context "with invalid id" do + subject { get :show, :params => {:id => 2 } } + + it "should redirect to #show_list" do + is_expected.to have_http_status 302 + is_expected.to redirect_to(:action => :show_list) + + flash_messages = assigns(:flash_array) + expect(flash_messages.first[:message]).to include("Can't access selected records") + end + end + + context "display=timeline" do + it do + post :show, :params => {:id => @physical_server.id, :display => "timeline"} + expect(response.status).to eq 200 + is_expected.to render_template(:partial => "layouts/_tl_show_async") + expect(controller.send(:flash_errors?)).to be_falsey + end + end + end + + describe "#button" do + subject { post :button, :params => { :id => @physical_server.id, :pressed => "physical_server_timeline", :format => :js } } + + it "when timelines button is pressed" do + is_expected.to have_http_status 200 + expect(response.body).to include(%(window.location.href = "/physical_server/show/#{@physical_server.id}?display=timeline")) + end end end