Skip to content

Commit

Permalink
Extract building consultation and call for evidence dependencies fro…
Browse files Browse the repository at this point in the history
…m the view

We shouldn't be building dependencies within a view. This extends the
build_edition_dependenices method to handle building consultation
and call for evidence dependencies.
  • Loading branch information
davidgisbey committed Sep 18, 2023
1 parent 5d1009c commit bd1d783
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
7 changes: 7 additions & 0 deletions app/controllers/admin/calls_for_evidence_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ def cope_with_call_for_evidence_response_form_data_action_params
def document_can_be_previously_published
false
end

def build_edition_dependencies
super
participation = @edition.call_for_evidence_participation || @edition.build_call_for_evidence_participation
response_form = participation.call_for_evidence_response_form || participation.build_call_for_evidence_response_form
response_form.call_for_evidence_response_form_data || response_form.build_call_for_evidence_response_form_data
end
end
7 changes: 7 additions & 0 deletions app/controllers/admin/consultations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,11 @@ def cope_with_consultation_response_form_data_action_params
def document_can_be_previously_published
false
end

def build_edition_dependencies
super
participation = @edition.consultation_participation || @edition.build_consultation_participation
response_form = participation.consultation_response_form || participation.build_consultation_response_form
response_form.consultation_response_form_data || response_form.build_consultation_response_form_data
end
end
6 changes: 3 additions & 3 deletions app/views/admin/calls_for_evidence/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
heading_size: "l"
} do %>

<% call_for_evidence_participation = edition.call_for_evidence_participation || edition.build_call_for_evidence_participation %>
<% call_for_evidence_participation = edition.call_for_evidence_participation %>

<%= form.fields_for :call_for_evidence_participation, call_for_evidence_participation do |call_for_evidence_participation_form| %>
<%= render "govuk_publishing_components/components/input", {
Expand Down Expand Up @@ -83,7 +83,7 @@
rows: 4,
} %>

<% call_for_evidence_response_form = call_for_evidence_participation.call_for_evidence_response_form || call_for_evidence_participation.build_call_for_evidence_response_form %>
<% call_for_evidence_response_form = call_for_evidence_participation.call_for_evidence_response_form %>

<%= call_for_evidence_participation_form.fields_for :call_for_evidence_response_form, call_for_evidence_response_form do |response_form| %>
<%= render "govuk_publishing_components/components/input", {
Expand All @@ -97,7 +97,7 @@
error_items: errors_for(call_for_evidence_response_form.errors, :title),
} %>

<% call_for_evidence_response_form_data = call_for_evidence_response_form.call_for_evidence_response_form_data || call_for_evidence_response_form.build_call_for_evidence_response_form_data %>
<% call_for_evidence_response_form_data = call_for_evidence_response_form.call_for_evidence_response_form_data %>

<%= response_form.fields_for :call_for_evidence_response_form_data, call_for_evidence_response_form_data do |call_for_evidence_response_form_data_form| %>
<%= call_for_evidence_response_form_data_form.hidden_field :file_cache, value: call_for_evidence_response_form_data.file_cache %>
Expand Down
6 changes: 3 additions & 3 deletions app/views/admin/consultations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
heading_level: 3,
heading_size: "l"
} do %>
<% consultation_participation = edition.consultation_participation || edition.build_consultation_participation %>
<% consultation_participation = edition.consultation_participation %>

<%= form.fields_for :consultation_participation, consultation_participation do |consultation_participation_form| %>
<%= render "govuk_publishing_components/components/input", {
Expand Down Expand Up @@ -82,7 +82,7 @@
rows: 4,
} %>

<% consultation_response_form = consultation_participation.consultation_response_form || consultation_participation.build_consultation_response_form %>
<% consultation_response_form = consultation_participation.consultation_response_form %>

<%= consultation_participation_form.fields_for :consultation_response_form, consultation_response_form do |response_form| %>
<%= render "govuk_publishing_components/components/input", {
Expand All @@ -96,7 +96,7 @@
error_items: errors_for(consultation_response_form.errors, :title),
} %>

<% consultation_response_form_data = consultation_response_form.consultation_response_form_data || consultation_response_form.build_consultation_response_form_data %>
<% consultation_response_form_data = consultation_response_form.consultation_response_form_data %>

<%= response_form.fields_for :consultation_response_form_data, consultation_response_form_data do |consultation_response_form_data_form| %>
<%= consultation_response_form_data_form.hidden_field :file_cache, value: consultation_response_form_data.file_cache %>
Expand Down

0 comments on commit bd1d783

Please sign in to comment.