forked from rubyforgood/casa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rubyforgood#5647 from sarvaiyanidhi/refactor_displ…
…ay_volunteer Refactor code of displaying assigned volunteer next to Case Number
- Loading branch information
Showing
10 changed files
with
58 additions
and
59 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module VolunteerHelper | ||
def volunteer_badge(casa_case, current_user) | ||
return "" if current_user.volunteer? | ||
|
||
badge_content = if casa_case.assigned_volunteers.present? | ||
casa_case.assigned_volunteers.map(&:display_name).join(", ") | ||
else | ||
"Unassigned" | ||
end | ||
|
||
content_tag(:span, badge_content, class: "badge badge-pill light-bg text-black fs-6 fw-medium") | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails_helper" | ||
|
||
RSpec.describe VolunteerHelper, type: :helper do | ||
let(:casa_case) { create(:casa_case) } | ||
let(:current_user) { create(:user) } | ||
|
||
context "when user is not a volunteer" do | ||
it "returns the assigned volunteers' names" do | ||
volunteer = create(:volunteer) | ||
casa_case.volunteers << volunteer | ||
|
||
badge_html = helper.volunteer_badge(casa_case, current_user) | ||
|
||
expect(badge_html).to include("badge") | ||
expect(badge_html).to include(volunteer.display_name) | ||
end | ||
|
||
it "returns 'Unassigned' when no volunteers are present" do | ||
badge_html = helper.volunteer_badge(casa_case, current_user) | ||
|
||
expect(badge_html).to include("badge") | ||
expect(badge_html).to include("Unassigned") | ||
end | ||
end | ||
|
||
context "when user is a volunteer" do | ||
let(:current_user) { create(:volunteer) } | ||
|
||
it "returns an empty string" do | ||
badge_html = helper.volunteer_badge(casa_case, current_user) | ||
|
||
expect(badge_html).to eq("") | ||
end | ||
end | ||
end |