Skip to content

Commit

Permalink
Merge pull request #674 from h-kataria/fix_catalog_item_link
Browse files Browse the repository at this point in the history
Fixed an error when clicking on items in Service Catalogs accordion
  • Loading branch information
Dan Clarizio authored Mar 13, 2017
2 parents ecd75e7 + 917373b commit 6349fee
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
10 changes: 8 additions & 2 deletions app/controllers/catalog_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def explorer
set_form_locals_for_sysprep
end
template_locals = {:locals => {:controller => "catalog"}}
template_locals[:locals].merge!(fetch_playbook_details) if TreeBuilder.get_model_for_prefix(@nodetype) == "ServiceTemplate" && !@view && @record.prov_type == "generic_ansible_playbook"
template_locals[:locals].merge!(fetch_playbook_details) if need_ansible_locals?

render :layout => "application", :action => "explorer", :locals => template_locals
end
Expand Down Expand Up @@ -1933,7 +1933,7 @@ def replace_right_cell(options = {})
r[:partial => "shared/buttons/ab_list"]
else
template_locals = {:controller => "catalog"}
template_locals.merge!(fetch_playbook_details) if TreeBuilder.get_model_for_prefix(@nodetype) == "ServiceTemplate" && @record.prov_type == "generic_ansible_playbook"
template_locals.merge!(fetch_playbook_details) if need_ansible_locals?
r[:partial => "catalog/#{x_active_tree}_show", :locals => template_locals]
end
elsif @sb[:buttons_node]
Expand Down Expand Up @@ -2027,6 +2027,12 @@ def replace_right_cell(options = {})
render :json => presenter.for_render
end

def need_ansible_locals?
x_active_tree == :sandt_tree &&
TreeBuilder.get_model_for_prefix(@nodetype) == "ServiceTemplate" &&
@record.prov_type == "generic_ansible_playbook"
end

# Build a Catalog Items explorer tree
def build_st_tree
TreeBuilderCatalogItems.new('sandt_tree', 'sandt', @sb)
Expand Down
40 changes: 40 additions & 0 deletions spec/controllers/catalog_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -690,4 +690,44 @@
expect(response).to have_http_status 200
end
end

context "#need_ansible_locals?" do
before do
controller.instance_variable_set(:@nodetype, 'st')
st = FactoryGirl.create(:service_template,
:type => "ServiceTemplateAnsiblePlaybook",
:prov_type => "generic_ansible_playbook")
controller.instance_variable_set(:@record, st)
end

it "returns true for Ansible Playbook Service Template in Catalog Items accordion only" do
controller.instance_variable_set(:@sb,
:trees => {:sandt_tree => {:open_nodes => []}},
:active_tree => :sandt_tree)
expect(controller.send(:need_ansible_locals?)).to be_truthy
end

it "returns false for Ansible Playbook Service Template in other accordions" do
controller.instance_variable_set(:@sb,
:trees => {:svccat_tree => {:open_nodes => []}},
:active_tree => :svccat_tree)
expect(controller.send(:need_ansible_locals?)).to be_falsey
end

it "returns false for any other Service Template in Catalog Items accordions" do
controller.instance_variable_set(:@record, FactoryGirl.create(:service_template))
controller.instance_variable_set(:@sb,
:trees => {:svccat_tree => {:open_nodes => []}},
:active_tree => :svccat_tree)
expect(controller.send(:need_ansible_locals?)).to be_falsey
end

it "returns false for any other Service Template in other accordions" do
controller.instance_variable_set(:@record, FactoryGirl.create(:service_template))
controller.instance_variable_set(:@sb,
:trees => {:svccat_tree => {:open_nodes => []}},
:active_tree => :svccat_tree)
expect(controller.send(:need_ansible_locals?)).to be_falsey
end
end
end

0 comments on commit 6349fee

Please sign in to comment.