Fix legislation proposal crash with SDG enabled
Now we check the given record or name is a relatable instance or class to avoid trying to render goals for records which don't have a goals association. Note for now we are ignoring the case where we pass a controller_path for an unsupported class (for example, `legislation/proposals` or `budgets/headings`) because we never use it. We might need to revisit this case in the future. Co-Authored-By: Javi Martín <javim@elretirao.net>
This commit is contained in:
committed by
Javi Martín
parent
046e2273c7
commit
fb611d91ca
@@ -7,7 +7,7 @@ class SDG::ProcessEnabled
|
|||||||
end
|
end
|
||||||
|
|
||||||
def enabled?
|
def enabled?
|
||||||
feature?("sdg") && feature?(process_name) && setting["sdg.process.#{process_name}"]
|
feature?("sdg") && feature?(process_name) && setting["sdg.process.#{process_name}"] && relatable?
|
||||||
end
|
end
|
||||||
|
|
||||||
def name
|
def name
|
||||||
@@ -39,4 +39,10 @@ class SDG::ProcessEnabled
|
|||||||
def module_name
|
def module_name
|
||||||
name.split("::").first
|
name.split("::").first
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def relatable?
|
||||||
|
return true if controller_path_name?
|
||||||
|
|
||||||
|
(SDG::Related::RELATABLE_TYPES & [record_or_name.class.name, record_or_name]).any?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -31,6 +31,12 @@ describe SDG::ProcessEnabled do
|
|||||||
|
|
||||||
expect(process).to be_enabled
|
expect(process).to be_enabled
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "returns false when record or name are not a relatable type" do
|
||||||
|
expect(SDG::ProcessEnabled.new(build(:legislation_proposal))).not_to be_enabled
|
||||||
|
expect(SDG::ProcessEnabled.new("Legislation::Proposal")).not_to be_enabled
|
||||||
|
expect(SDG::ProcessEnabled.new("officing/booth")).not_to be_enabled
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "SDG feature is disabled" do
|
context "SDG feature is disabled" do
|
||||||
|
|||||||
@@ -226,7 +226,10 @@ describe "Legislation Proposals" do
|
|||||||
expect(page).to have_content "Open concert"
|
expect(page).to have_content "Open concert"
|
||||||
end
|
end
|
||||||
|
|
||||||
scenario "Show proposal tags on show", :js do
|
scenario "Show proposal tags on show when SDG is enabled", :js do
|
||||||
|
Setting["feature.sdg"] = true
|
||||||
|
Setting["sdg.process.legislation"] = true
|
||||||
|
|
||||||
proposal = create(:legislation_proposal, process: process, tag_list: "Culture")
|
proposal = create(:legislation_proposal, process: process, tag_list: "Culture")
|
||||||
|
|
||||||
visit legislation_process_proposal_path(proposal.process, proposal)
|
visit legislation_process_proposal_path(proposal.process, proposal)
|
||||||
|
|||||||
Reference in New Issue
Block a user