Skip to content

Commit

Permalink
Add specs for display methods in ops controller for Tenant
Browse files Browse the repository at this point in the history
Add also spec for updating view_options in nested_list in GenericShowMixin
  • Loading branch information
Hilda Stastna committed Sep 11, 2019
1 parent 0fca858 commit 7cac717
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 9 deletions.
33 changes: 33 additions & 0 deletions spec/controllers/mixins/generic_show_mixin_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
describe Mixins::GenericShowMixin do
class GenericShowMixinTestController < ActionController::Base
include Mixins::GenericShowMixin
end

describe '#nested_list' do
context 'displaying Service Templates thru Tenant textual summary' do
let(:controller) { OpsController.new }
let(:opts) do
{
:association => :nested_service_templates,
:parent => tenant,
:no_checkboxes => true
}
end
let(:tenant) { FactoryBot.create(:tenant) }

before do
allow(controller).to receive(:drop_breadcrumb)
allow(controller).to receive(:show_link)
allow(controller).to receive(:session).and_return(:view => nil)
allow(controller).to receive(:render)
controller.instance_variable_set(:@record, tenant)
controller.params = {}
end

it 'updates view_options also with :no_checkboxes' do
expect(controller).to receive(:get_view).with(ServiceTemplate, opts)
controller.send(:nested_list, ServiceTemplate, opts.merge(:breadcrumb_title => 'Catalog Items and Bundles'))
end
end
end
end
107 changes: 98 additions & 9 deletions spec/controllers/ops_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@
end
end

context "#db_backup" do
describe "#db_backup" do
it "posts db_backup action" do
session[:settings] = {:default_search => ''}

Expand All @@ -182,7 +182,7 @@
end
end

context "#edit_changed?" do
describe "#edit_changed?" do
it "should set session[:changed] as false" do
edit = {
:new => {:foo => 'bar'},
Expand Down Expand Up @@ -287,7 +287,7 @@
allow(controller).to receive(:data_for_breadcrumbs).and_return({})
end

context "#explorer" do
describe "#explorer" do
it "sets correct active accordion value" do
controller.instance_variable_set(:@sb, {})
allow(controller).to receive(:get_node_info)
Expand All @@ -305,7 +305,7 @@
end
end

context "#replace_explorer_trees" do
describe "#replace_explorer_trees" do
it "build trees that are passed in and met other conditions" do
controller.instance_variable_set(:@sb, {})
allow(controller).to receive(:x_build_dyna_tree)
Expand Down Expand Up @@ -389,8 +389,8 @@
end
end

context '#dialog_replace_right_cell' do
describe 'for an User' do
describe '#dialog_replace_right_cell' do
context 'for an User' do
before do
user = FactoryBot.create(:user)
allow(controller).to receive(:x_node).and_return("u-#{user.id}")
Expand All @@ -402,7 +402,7 @@
end
end

describe 'for a Group' do
context 'for a Group' do
let(:group) { FactoryBot.create(:miq_group) }

before do
Expand All @@ -417,7 +417,7 @@
end
end

context "#tree_selected_model" do
describe "#tree_selected_model" do
it 'sets @tree_model_selected to User for user node' do
allow(controller).to receive(:x_node).and_return('u-42')
controller.tree_selected_model
Expand Down Expand Up @@ -473,7 +473,7 @@
end
end

context '#tree_select' do
describe '#tree_select' do
it 'calls #tree_select_model' do
controller.instance_variable_set(:@sb, {})
controller.params[:id] = 'root'
Expand Down Expand Up @@ -529,4 +529,93 @@
expect(subject).to include(array_including(:smart_management))
end
end

context 'display methods for Tenant textual summary' do
let(:record) { FactoryBot.create(:tenant) }

before { controller.instance_variable_set(:@record, record) }

describe '#display_service_templates' do
let(:opts) do
{
:breadcrumb_title => _('Catalog Items and Bundles'),
:association => :nested_service_templates,
:parent => record,
:no_checkboxes => true
}
end

it 'calls nested_list to display Catalog Items and Bundles' do
expect(controller).to receive(:nested_list).with(ServiceTemplate, opts)
controller.send(:display_service_templates)
end
end

describe '#display_providers' do
let(:opts) do
{
:breadcrumb_title => _('Providers'),
:association => :nested_providers,
:parent => record,
:no_checkboxes => true,
:clickable => false
}
end

it 'calls nested_list to display Providers' do
expect(controller).to receive(:nested_list).with(ExtManagementSystem, opts)
controller.send(:display_providers)
end
end

describe '#display_ae_namespaces' do
let(:opts) do
{
:breadcrumb_title => _('Automate Domains'),
:association => :nested_ae_namespaces,
:parent => record,
:no_checkboxes => true,
:clickable => false
}
end

it 'calls nested_list to display Providers' do
expect(controller).to receive(:nested_list).with(MiqAeDomain, opts)
controller.send(:display_ae_namespaces)
end
end
end

describe '#nested_list' do
let(:record) { FactoryBot.create(:tenant) }
let(:opts) do
{
:association => :nested_service_templates,
:parent => record,
:no_checkboxes => true,
:breadcrumb_title => 'Catalog Items and Bundles'
}
end

before do
controller.instance_variable_set(:@record, record)
controller.instance_variable_set(:@breadcrumbs, [])
allow(controller).to receive(:render_to_string).and_return('')
end

context 'updating breadcrumbs' do
before { allow(controller).to receive(:render) }

it 'calls add_to_breadcrumbs and render_to_string' do
expect(controller).to receive(:render_to_string).with(:partial => 'layouts/gtl')
expect(controller).to receive(:add_to_breadcrumbs).with(:title => opts[:breadcrumb_title])
controller.send(:nested_list, ServiceTemplate, opts)
end
end

it 'updates right cell text' do
expect(controller).to receive(:render).with(:json => {:explorer => 'replace_main_div', :rightCellText => "#{record.name} (All #{opts[:breadcrumb_title]})", :updatePartials => {'ops_tabs' => '', :breadcrumbs => ''}})
controller.send(:nested_list, ServiceTemplate, opts)
end
end
end

0 comments on commit 7cac717

Please sign in to comment.