Skip to content

Commit

Permalink
Merge branch 'rubyforgood:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
MclPio authored Oct 15, 2024
2 parents 30e3774 + 4f68eb6 commit fe0e42f
Show file tree
Hide file tree
Showing 9 changed files with 217 additions and 172 deletions.
13 changes: 3 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ GEM
mini_magick (>= 4.9.5, < 5)
ruby-vips (>= 2.0.17, < 3)
io-console (0.7.2)
irb (1.14.0)
irb (1.14.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
jbuilder (2.12.0)
Expand Down Expand Up @@ -330,7 +330,7 @@ GEM
racc (~> 1.4)
nokogiri (1.16.7-x86_64-linux)
racc (~> 1.4)
noticed (2.4.1)
noticed (2.4.3)
rails (>= 6.1.0)
oj (3.16.5)
bigdecimal (>= 3.0)
Expand Down Expand Up @@ -426,8 +426,7 @@ GEM
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rexml (3.3.6)
strscan
rexml (3.3.8)
rspec-core (3.13.1)
rspec-support (~> 3.13.0)
rspec-expectations (3.13.3)
Expand Down Expand Up @@ -490,11 +489,6 @@ GEM
scout_apm (5.4.0)
parser
securerandom (0.3.1)
base64 (~> 0.2)
logger (~> 1.4)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
selenium-webdriver (4.25.0)
base64 (~> 0.2)
logger (~> 1.4)
Expand Down Expand Up @@ -537,7 +531,6 @@ GEM
stringio (3.1.1)
strong_migrations (2.0.0)
activerecord (>= 6.1)
strscan (3.1.0)
thor (1.3.2)
timeout (0.4.1)
traceroute (0.8.1)
Expand Down
14 changes: 14 additions & 0 deletions app/controllers/concerns/users/time_zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ module TimeZone

included do
helper_method :browser_time_zone
helper_method :to_user_timezone
end

def browser_time_zone
Expand All @@ -12,5 +13,18 @@ def browser_time_zone
rescue TZInfo::UnknownTimezone, TZInfo::InvalidTimezoneIdentifier
Time.zone
end

def to_user_timezone(time_date)
return "" if time_date.nil? || (time_date.instance_of?(String) && time_date.empty?)

time_zone = user_timezone
return time_date.in_time_zone(time_zone) if time_date.respond_to?(:in_time_zone)

time_date.to_time(time_zone)
end

def user_timezone
(browser_time_zone && browser_time_zone != Time.zone) ? browser_time_zone : "Eastern Time (US & Canada)"
end
end
end
4 changes: 2 additions & 2 deletions app/helpers/ui_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ def grouped_options_for_assigning_case(volunteer)
[
[
"Not Assigned",
CasaCase
CasaCase.eager_load([:assigned_volunteers])
.not_assigned(@volunteer.casa_org).active
.uniq { |casa_case| casa_case.case_number }
.map { |casa_case| ["#{casa_case.case_number} - #{volunteer_badge(casa_case, current_user)}".html_safe, casa_case.id] }
],
[
"Assigned",
CasaCase
CasaCase.eager_load([:assigned_volunteers])
.actively_assigned_excluding_volunteer(@volunteer)
.uniq { |casa_case| casa_case.case_number }
.map { |casa_case| ["#{casa_case.case_number} - #{volunteer_badge(casa_case, current_user)}".html_safe, casa_case.id] }
Expand Down
2 changes: 1 addition & 1 deletion app/models/volunteer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def deactivate
end

def case_assignments_with_cases
case_assignments.includes(:casa_case)
case_assignments.includes(casa_case: :assigned_volunteers)
end

def has_supervisor?
Expand Down
2 changes: 1 addition & 1 deletion app/views/casa_org/_sent_emails.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<%= sent_email.user.display_name %> &lt;<%= sent_email.sent_address %>&gt;
</td>
<td>
<%= sent_email.created_at.strftime("%l:%M%P %d %b %Y") %>
<%= to_user_timezone(sent_email.created_at).strftime("%l:%M%P %d %b %Y") %>
</td>
</tr>
<% end %>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build:css:dev": "sass app/assets/stylesheets/application.scss app/assets/builds/application.css --load-path=node_modules --watch"
},
"dependencies": {
"@babel/core": "^7.25.2",
"@babel/core": "^7.25.7",
"@fortawesome/fontawesome-free": "^6.6.0",
"@hotwired/stimulus": "^3.2.2",
"@hotwired/turbo-rails": "^8.0.10",
Expand Down Expand Up @@ -45,7 +45,7 @@
"strftime": "^0.10.3",
"sweetalert2": "^11.3.5",
"tom-select": "^2.3.1",
"trix": "^2.1.2"
"trix": "^2.1.6"
},
"version": "0.1.0",
"devDependencies": {
Expand Down
48 changes: 48 additions & 0 deletions spec/controllers/concerns/users/time_zone_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class MockController < ApplicationController

RSpec.describe MockController, type: :controller do
let(:browser_time_zone) { "America/Los_Angeles" }
let(:default_time_zone) { "Eastern Time (US & Canada)" }
let(:time_date) { Time.zone.now }
before do
allow(controller).to receive(:cookies).and_return(browser_time_zone: browser_time_zone)
end
Expand Down Expand Up @@ -37,4 +39,50 @@ class MockController < ApplicationController
end
end
end

describe "#to_user_timezone" do
it "takes a time_date and converts it to user's time zone" do
expected = controller.to_user_timezone(time_date)
returned = time_date.in_time_zone(browser_time_zone)
expect(expected.zone).to eq(returned.zone)
expect(expected.day).to eq(returned.day)
expect(expected.hour).to eq(returned.hour)
end

context "when invalid param is sent" do
it "returns the empty string for nil param" do
expect(controller.to_user_timezone(nil)).to eq("")
end

it "returns empty string if empty string param provided" do
expect(controller.to_user_timezone("")).to eq("")
end

it "returns nil for invalid date string" do
expect(controller.to_user_timezone("invalid-date")).to eq(nil)
end
end
end

describe "#user_timezone" do
context "when browser time zone has an invalid value" do
before do
allow(controller).to receive(:cookies).and_return(browser_time_zone: "Invalid/Timezone")
end

it "returns the default time zone" do
expect(controller.user_timezone).to eq(default_time_zone)
end
end

context "when browser time zone is not set" do
before do
allow(controller).to receive(:cookies).and_return({})
end

it "returns the default time zone" do
expect(controller.user_timezone).to eq(default_time_zone)
end
end
end
end
3 changes: 3 additions & 0 deletions spec/views/casa_orgs/edit.html.erb_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@
organization = build_stubbed(:casa_org)
admin = build_stubbed(:casa_admin, casa_org: organization)
allow(view).to receive(:current_organization).and_return(organization)
without_partial_double_verification do
allow(view).to receive(:to_user_timezone).and_return(Time.zone.local(2021, 1, 2, 12, 30, 0))
end

sent_email = build_stubbed(:sent_email, user: admin, created_at: Time.zone.local(2021, 1, 2, 12, 30, 0))
assign(:sent_emails, [sent_email])
Expand Down
Loading

0 comments on commit fe0e42f

Please sign in to comment.