diff --git a/app/models/form/page.rb b/app/models/form/page.rb index 73a1ee143..676802458 100644 --- a/app/models/form/page.rb +++ b/app/models/form/page.rb @@ -6,9 +6,9 @@ class Form::Page @id = id @header = hsh["header"] @description = hsh["description"] - @questions = hsh["questions"].map { |q_id, q| Form::Question.new(q_id, q, self) } + @questions = hsh["questions"].map { |id, q| Form::Question.new(id, q, self) } @depends_on = hsh["depends_on"] - @soft_validations = hsh["soft_validations"]&.map { |v_id, s| Form::Question.new(v_id, s, self) } + @soft_validations = hsh["soft_validations"]&.map { |id, s| Form::Question.new(id, s, self) } @subsection = subsection end diff --git a/app/models/form/section.rb b/app/models/form/section.rb index 477fc9f18..703869536 100644 --- a/app/models/form/section.rb +++ b/app/models/form/section.rb @@ -5,6 +5,6 @@ class Form::Section @id = id @label = hsh["label"] @form = form - @subsections = hsh["subsections"].map { |s_id, s| Form::Subsection.new(s_id, s, self) } + @subsections = hsh["subsections"].map { |id, s| Form::Subsection.new(id, s, self) } end end diff --git a/app/models/form/subsection.rb b/app/models/form/subsection.rb index 19700d935..fa6db2d6d 100644 --- a/app/models/form/subsection.rb +++ b/app/models/form/subsection.rb @@ -5,7 +5,7 @@ class Form::Subsection @id = id @label = hsh["label"] @depends_on = hsh["depends_on"] - @pages = hsh["pages"].map { |s_id, p| Form::Page.new(s_id, p, self) } + @pages = hsh["pages"].map { |id, p| Form::Page.new(id, p, self) } @section = section end diff --git a/spec/requests/case_log_controller_spec.rb b/spec/requests/case_log_controller_spec.rb index e91d8dd2c..1de107342 100644 --- a/spec/requests/case_log_controller_spec.rb +++ b/spec/requests/case_log_controller_spec.rb @@ -278,9 +278,9 @@ RSpec.describe CaseLogsController, type: :request do describe "Submit Form" do let(:user) { FactoryBot.create(:user) } + let(:form) { Form.new("spec/fixtures/forms/test_form.json") } let(:case_log) { FactoryBot.create(:case_log, :in_progress) } let(:page_id) { "person_1_age" } - let(:answer) { 2000 } let(:params) do { id: case_log.id, @@ -292,12 +292,25 @@ RSpec.describe CaseLogsController, type: :request do end before do + allow(FormHandler.instance).to receive(:get_form).and_return(form) sign_in user post "/case_logs/#{case_log.id}/form", params: params end - it "re-renders the same page with errors if validation fails" do - expect(response).to have_http_status(:unprocessable_entity) + context "invalid answers" do + let(:answer) { 2000 } + + it "re-renders the same page with errors if validation fails" do + expect(response).to have_http_status(:unprocessable_entity) + end + end + + context "valid answers" do + let(:answer) { 20 } + + it "re-renders the same page with errors if validation fails" do + expect(response).to have_http_status(:redirect) + end end end end