From 2b333ba96f7b0dd94f15d607341a241a5bf21557 Mon Sep 17 00:00:00 2001 From: Josiah Ivey Date: Thu, 5 Oct 2023 12:21:13 -0700 Subject: [PATCH] fix checking nil books_used_details (#1206) --- .../educator_signup/complete_profile.rb | 2 +- .../educator_signup/complete_profile_spec.rb | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/app/handlers/newflow/educator_signup/complete_profile.rb b/app/handlers/newflow/educator_signup/complete_profile.rb index adc00d0cb..435dabca6 100644 --- a/app/handlers/newflow/educator_signup/complete_profile.rb +++ b/app/handlers/newflow/educator_signup/complete_profile.rb @@ -143,7 +143,7 @@ def books_used end def books_used_details - signup_params.books_used_details.reject do |k, v| + (signup_params.books_used_details || {}).reject do |k, v| k.blank? || v.dig('how_using_book').blank? || v.dig('num_students_using_book').blank? end end diff --git a/spec/handlers/newflow/educator_signup/complete_profile_spec.rb b/spec/handlers/newflow/educator_signup/complete_profile_spec.rb index 4fe530a09..c14e5aa47 100644 --- a/spec/handlers/newflow/educator_signup/complete_profile_spec.rb +++ b/spec/handlers/newflow/educator_signup/complete_profile_spec.rb @@ -50,6 +50,25 @@ module EducatorSignup } end + context 'with a different profile' do + let(:params) do + { + signup: { + school_name: 'School Name', + books_of_interest: ['Test Book'], + books_used: ['Test Book'], + using_openstax_how: Newflow::EducatorSignup::CompleteProfile::AS_FUTURE, + educator_specific_role: Newflow::EducatorSignup::CompleteProfile::INSTRUCTOR, + } + } + end + + it "should not error" do + result = handle + expect(result.errors.count).to eq 0 + end + end + context 'books used details' do let(:educator_specific_role) { Newflow::EducatorSignup::CompleteProfile::INSTRUCTOR }