File tree Expand file tree Collapse file tree 5 files changed +54
-65
lines changed
Expand file tree Collapse file tree 5 files changed +54
-65
lines changed Original file line number Diff line number Diff line change @@ -8,28 +8,4 @@ def show
88 @task_status_counts = task_service . task_counts
99 render :show , locals : { current_form : }
1010 end
11-
12- def mark_pages_section_completed
13- authorize current_form , :can_view_form?
14- @pages = current_form . pages
15- @mark_complete_input = Forms ::MarkPagesSectionCompleteInput . new ( mark_complete_input_params )
16-
17- if @mark_complete_input . submit
18- success_message = if @mark_complete_input . mark_complete == "true"
19- t ( "banner.success.form.pages_saved_and_section_completed" )
20- else
21- t ( "banner.success.form.pages_saved" )
22- end
23- redirect_to form_path ( current_form . id ) , success : success_message
24- else
25- @mark_complete_input . mark_complete = "false"
26- render "pages/index" , locals : { current_form : } , status : :unprocessable_content
27- end
28- end
29-
30- private
31-
32- def mark_complete_input_params
33- params . require ( :forms_mark_pages_section_complete_input ) . permit ( :mark_complete ) . merge ( form : current_form )
34- end
3511end
Original file line number Diff line number Diff line change @@ -83,6 +83,23 @@ def move_page
8383 redirect_to form_pages_path , success : success_message
8484 end
8585
86+ def mark_pages_section_completed
87+ @pages = current_form . pages
88+ @mark_complete_input = Forms ::MarkPagesSectionCompleteInput . new ( mark_complete_input_params )
89+
90+ if @mark_complete_input . submit
91+ success_message = if @mark_complete_input . mark_complete == "true"
92+ t ( "banner.success.form.pages_saved_and_section_completed" )
93+ else
94+ t ( "banner.success.form.pages_saved" )
95+ end
96+ redirect_to form_path ( current_form . id ) , success : success_message
97+ else
98+ @mark_complete_input . mark_complete = "false"
99+ render "pages/index" , locals : { current_form : } , status : :unprocessable_content
100+ end
101+ end
102+
86103private
87104
88105 def clear_draft_questions_data
@@ -126,6 +143,10 @@ def setup_draft_question_for_existing_page
126143 edit_draft_question
127144 end
128145
146+ def mark_complete_input_params
147+ params . require ( :forms_mark_pages_section_complete_input ) . permit ( :mark_complete ) . merge ( form : current_form )
148+ end
149+
129150 def set_answer_type_logging_attribute
130151 if @draft_question . present?
131152 CurrentLoggingAttributes . answer_type = @draft_question . answer_type
Original file line number Diff line number Diff line change 8585
8686 scope "/pages" do
8787 get "/" => "pages#index" , as : :form_pages
88- post "/" => "forms #mark_pages_section_completed"
88+ post "/" => "pages #mark_pages_section_completed"
8989 post "/move-page" => "pages#move_page" , as : :move_page
9090 get "/change-order" => "pages/change_order#new" , as : :change_order_new
9191 post "/change-order" => "pages/change_order#create" , as : :change_order_create
Original file line number Diff line number Diff line change 7070 expect ( response . status ) . to eq ( 404 )
7171 end
7272 end
73-
74- describe "#mark_pages_section_completed" do
75- let ( :pages ) do
76- [ build ( :page , id : 99 ) ]
77- end
78-
79- let ( :form ) { create ( :form , pages :, question_section_completed : "false" ) }
80-
81- let ( :user ) do
82- standard_user
83- end
84-
85- before do
86- login_as user
87-
88- post form_pages_path ( form . id ) , params : { forms_mark_pages_section_complete_input : { mark_complete : "true" } }
89- end
90-
91- it "Redirects you to the form overview page" do
92- expect ( response ) . to redirect_to ( form_path ( form . id ) )
93- end
94-
95- context "when the mark completed form is invalid" do
96- before do
97- post form_pages_path ( form . id ) , params : { forms_mark_pages_section_complete_input : { mark_complete : nil } }
98- end
99-
100- it "renders the index page" do
101- expect ( response ) . to render_template ( "pages/index" )
102- end
103-
104- it "returns 422 error code" do
105- expect ( response . status ) . to eq ( 422 )
106- end
107-
108- it "sets mark_complete to false" do
109- expect ( assigns [ :mark_complete_input ] . mark_complete ) . to eq ( "false" )
110- end
111- end
112- end
11373end
Original file line number Diff line number Diff line change 393393 end
394394 end
395395 end
396+
397+ describe "#mark_pages_section_completed" do
398+ let ( :form ) { create ( :form , :with_pages , question_section_completed : "false" ) }
399+
400+ before do
401+ group . group_forms . create! ( form : form )
402+
403+ post form_pages_path ( form . id ) , params : { forms_mark_pages_section_complete_input : { mark_complete : "true" } }
404+ end
405+
406+ it "Redirects you to the form overview page" do
407+ expect ( response ) . to redirect_to ( form_path ( form . id ) )
408+ end
409+
410+ context "when the mark completed form is invalid" do
411+ before do
412+ post form_pages_path ( form . id ) , params : { forms_mark_pages_section_complete_input : { mark_complete : nil } }
413+ end
414+
415+ it "renders the index page" do
416+ expect ( response ) . to render_template ( "pages/index" )
417+ end
418+
419+ it "returns 422 error code" do
420+ expect ( response . status ) . to eq ( 422 )
421+ end
422+
423+ it "sets mark_complete to false" do
424+ expect ( assigns [ :mark_complete_input ] . mark_complete ) . to eq ( "false" )
425+ end
426+ end
427+ end
396428end
You can’t perform that action at this time.
0 commit comments