From 08d64119f441c5fa4c47dab6ca43ccedda786bf2 Mon Sep 17 00:00:00 2001 From: Jirka Kremser Date: Wed, 15 Mar 2017 17:34:00 +0100 Subject: [PATCH] wip: more tests for controllers --- .../middleware_server_controller_spec.rb | 61 ++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/spec/controllers/middleware_server_controller_spec.rb b/spec/controllers/middleware_server_controller_spec.rb index b6c95d866722..f7bf9ea4a518 100644 --- a/spec/controllers/middleware_server_controller_spec.rb +++ b/spec/controllers/middleware_server_controller_spec.rb @@ -25,10 +25,17 @@ it do is_expected.to have_http_status 200 - is_expected.to render_template(:partial => 'layouts/listnav/_middleware_server') is_expected.to render_template(:partial => 'layouts/_textual_groups_generic') end end + + context 'render listnav partial' do + render_views + it do + is_expected.to have_http_status 200 + is_expected.to render_template(:partial => 'layouts/listnav/_middleware_server') + end + end end # FIXME: should test for nested entities: %w(middleware_datasources middleware_deployments middleware_messagings) @@ -44,4 +51,56 @@ assert_nested_list(server, [deployment], 'middleware_deployments', 'All Middleware Deployments') end end + + context '#tags_edit' do + let!(:user) { stub_user(:features => :all) } + before(:each) do + EvmSpecHelper.create_guid_miq_server_zone + @server = FactoryGirl.create(:hawkular_middleware_server, :properties => {}, :middleware_server_group => nil) + allow(@server).to receive(:tagged_with).with(:cat => user.userid).and_return('my tags') + classification = FactoryGirl.create(:classification, :name => 'department', :description => 'Department') + @tag1 = FactoryGirl.create(:classification_tag, + :name => 'tag1', + :parent => classification) + @tag2 = FactoryGirl.create(:classification_tag, + :name => 'tag2', + :parent => classification) + allow(Classification).to receive(:find_assigned_entries).with(@server).and_return([@tag1, @tag2]) + session[:tag_db] = 'MiddlewareServer' + edit = { + :key => "MiddlewareServer_edit_tags__#{@server.id}", + :tagging => 'MiddlewareServer', + :object_ids => [@server.id], + :current => {:assignments => []}, + :new => {:assignments => [@tag1.id, @tag2.id]} + } + session[:edit] = edit + end + + after(:each) do + expect(response.status).to eq(200) + end + + it 'builds tagging screen' do + post :button, :params => { :pressed => 'middleware_server_tag', :format => :js, :id => @server.id } + expect(assigns(:flash_array)).to be_nil + end + + it 'cancels tags edit' do + session[:breadcrumbs] = [{:url => "middleware_server/show/#{@server.id}"}, 'placeholder'] + post :tagging_edit, :params => { :button => 'cancel', :format => :js, :id => @server.id } + expect(assigns(:flash_array).first[:message]).to include('was cancelled by the user') + expect(assigns(:edit)).to be_nil + end + + it 'save tags' do + session[:breadcrumbs] = [{:url => "middleware_server/show/#{@server.id}"}, 'placeholder'] + post :tagging_edit, :params => { :button => 'save', :format => :js, :id => @server.id } + expect(assigns(:flash_array).first[:message]).to include('Tag edits were successfully saved') + expect(assigns(:edit)).to be_nil + end + end + + # todo: + # include_examples '#download_summary_pdf', :middleware_server end