Skip to content

Commit

Permalink
Added tests for physical server controller
Browse files Browse the repository at this point in the history
  • Loading branch information
lucashsilva committed Oct 19, 2017
1 parent 7ca38d9 commit 1bc0f40
Showing 1 changed file with 62 additions and 18 deletions.
80 changes: 62 additions & 18 deletions spec/controllers/physical_server_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -1,33 +1,77 @@
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

context "#button" do
Expand Down

0 comments on commit 1bc0f40

Please sign in to comment.