diff --git a/.allow_skipping_tests b/.allow_skipping_tests index 72251df04a..a92d8b94a8 100644 --- a/.allow_skipping_tests +++ b/.allow_skipping_tests @@ -39,7 +39,6 @@ policies/learning_hour_topic_policy.rb policies/learning_hour_type_policy.rb policies/note_policy.rb presenters/base_presenter.rb -presenters/case_contact_presenter.rb services/case_contacts_export_csv_service.rb services/court_report_format_contact_date.rb services/create_all_casa_admin_service.rb diff --git a/app/presenters/case_contact_presenter.rb b/app/presenters/case_contact_presenter.rb index c4c2e886be..1f1a80fdc5 100644 --- a/app/presenters/case_contact_presenter.rb +++ b/app/presenters/case_contact_presenter.rb @@ -8,8 +8,8 @@ def initialize(case_contacts) end def display_case_number(casa_case_id) - if casa_case_id - "#{casa_cases[casa_case_id]&.decorate&.transition_aged_youth_icon} #{casa_cases[casa_case_id]&.case_number}" + if casa_cases[casa_case_id]&.case_number.present? + "#{casa_cases[casa_case_id].decorate.transition_aged_youth_icon} #{casa_cases[casa_case_id].case_number}" else "" end diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index 37d41faa45..3513e8a534 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -19,6 +19,10 @@ def handle_short_url(url_list) super end + def store_referring_location + super + end + def not_authorized_error raise Pundit::NotAuthorizedError end @@ -115,4 +119,24 @@ def unknown_organization expect(controller.send(:sms_acct_creation_notice, "admin", "sent")).to eq("New admin created successfully. SMS has been sent!") end end + + describe "#store_referring_location" do + it "stores referring location in session if referer is present and not sign in page" do + request.env["HTTP_REFERER"] = "http://example.com" + controller.store_referring_location + expect(session[:return_to]).to eq("http://example.com") + end + + it "does not store referring location if referer is sign in page" do + request.env["HTTP_REFERER"] = "http://example.com/users/sign_in" + controller.store_referring_location + expect(session[:return_to]).to be_nil + end + + it "does not store referring location if referer is not present" do + request.env["HTTP_REFERER"] = nil + controller.store_referring_location + expect(session[:return_to]).to be_nil + end + end end diff --git a/spec/presenters/case_contact_presenter_spec.rb b/spec/presenters/case_contact_presenter_spec.rb new file mode 100644 index 0000000000..59dc621c41 --- /dev/null +++ b/spec/presenters/case_contact_presenter_spec.rb @@ -0,0 +1,45 @@ +require "rails_helper" + +RSpec.describe CaseContactPresenter do + let(:organization) { build(:casa_org) } + let(:user) { create(:casa_admin, casa_org: organization) } + let(:case_contacts) { create_list(:case_contact, 5, casa_case: casa_case) } + let(:presenter) { described_class.new(case_contacts) } + + before do + allow_any_instance_of(described_class).to receive(:current_user).and_return(user) + allow_any_instance_of(described_class).to receive(:current_organization).and_return(organization) + end + + describe "#display_case_number" do + context "with transition aged youth" do + let(:casa_case) { create(:casa_case, birth_month_year_youth: 15.years.ago, casa_org: organization) } + + it "displays the case number with correct icon" do + casa_case_id = casa_case.id + case_number = casa_case.case_number + + expect(presenter.display_case_number(casa_case_id)).to eql("🦋 #{case_number}") + end + + it "does not error when case number is nil" do + expect(presenter.display_case_number(nil)).to eql("") + end + end + + context "with non-transition aged youth" do + let(:casa_case) { create(:casa_case, birth_month_year_youth: 12.years.ago, casa_org: organization) } + + it "displays the case number with correct icon" do + casa_case_id = casa_case.id + case_number = casa_case.case_number + + expect(presenter.display_case_number(casa_case_id)).to eql("🐛 #{case_number}") + end + + it "does not error when case number is nil" do + expect(presenter.display_case_number(nil)).to eql("") + end + end + end +end