Skip to content

Commit

Permalink
Merge pull request #5650 from guswhitten/main
Browse files Browse the repository at this point in the history
Add tests for previously merged commits: #5643, #5642, #5641
  • Loading branch information
compwron authored May 5, 2024
2 parents d0190c0 + f706920 commit f107091
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 3 deletions.
1 change: 0 additions & 1 deletion .allow_skipping_tests
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/case_contact_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions spec/controllers/application_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
45 changes: 45 additions & 0 deletions spec/presenters/case_contact_presenter_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit f107091

Please sign in to comment.