Skip to content

Commit 91b15b8

Browse files
committed
Merge remote-tracking branch 'upstream/main' into rails-8
1 parent 6215c59 commit 91b15b8

22 files changed

+144
-36
lines changed

.devcontainer/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Installs Ruby 3.2.2. When human-essentials moves to a newer version of ruby,
22
# it will be more efficient to change the image.
33
# See https://github.com/devcontainers/images/blob/main/src/ruby/history/
4-
FROM mcr.microsoft.com/devcontainers/ruby:dev-3.2-buster
4+
FROM mcr.microsoft.com/devcontainers/ruby:dev-3.2
55
RUN export DEBIAN_FRONTEND=noninteractive
66
RUN apt-get update && apt-get -y install vim curl gpg postgresql postgresql-contrib
77
RUN cd /tmp
88
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb \
9-
&& apt-get -y install ./google-chrome-stable_current_amd64.deb
9+
&& apt-get -y install ./google-chrome-stable_current_amd64.deb

.devcontainer/post-create.sh

+9
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,28 @@
11
RUBY_VERSION="$(cat .ruby-version | tr -d '\n')"
22

33
# copy the file only if it doesn't already exist
4+
echo "*** Creating initial .env and vscode settings, if needed"
45
cp -n .devcontainer/.env.codespaces .env
56
mkdir -p .vscode && cp -n .devcontainer/launch.json.codespaces .vscode/launch.json
67

78
# If the project's required ruby version changes from 3.2.2, this command
89
# will download and compile the correct version, but it will take a long time.
910
if [ "$RUBY_VERSION" != "3.2.2" ]; then
11+
echo "*** Installing Ruby $RUBY_VERSION (this may take a while)"
1012
rvm install $RUBY_VERSION
1113
rvm use $RUBY_VERSION
1214
echo "Ruby $RUBY_VERSION installed"
1315
fi
1416

17+
echo "*** Setting up node"
1518
nvm install node
19+
20+
echo "*** Setting up ruby environment"
1621
rbenv init bash
1722
rbenv init zsh
1823

24+
# echo "*** Forcing platform version of nokogiri"
25+
# gem install nokogiri -v 1.18.1 --platform=ruby -- --use-system-libraries
26+
27+
echo "*** Running project bin/setup"
1928
bin/setup

Gemfile

+1-3
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,7 @@ gem "paper_trail"
3232
# Associates users with roles.
3333
gem "rolify", "~> 6.0"
3434
# Enforces "safe" migrations.
35-
# Pinned to 1.8.0 because 2.0.0 no longer support postgres v10
36-
# And as of now we are using postgres v10 in production
37-
gem "strong_migrations", "1.8.0"
35+
gem "strong_migrations"
3836
# used in events
3937
gem 'dry-struct'
4038
# Use solid_cache as a cache store

Gemfile.lock

+5-5
Original file line numberDiff line numberDiff line change
@@ -686,9 +686,9 @@ GEM
686686
rubocop-rails (~> 2.25.0)
687687
stimulus-rails (1.3.4)
688688
railties (>= 6.0.0)
689-
stringio (3.1.5)
690-
strong_migrations (1.8.0)
691-
activerecord (>= 5.2)
689+
stringio (3.1.2)
690+
strong_migrations (2.2.0)
691+
activerecord (>= 7)
692692
terser (1.2.5)
693693
execjs (>= 0.3.0, < 3)
694694
thor (1.3.2)
@@ -824,11 +824,11 @@ DEPENDENCIES
824824
standard-performance
825825
standard-rails
826826
stimulus-rails
827-
strong_migrations (= 1.8.0)
827+
strong_migrations
828828
terser
829829
turbo-rails
830830
web-console
831831
webmock (~> 3.24)
832832

833833
BUNDLED WITH
834-
2.6.2
834+
2.6.5

app/assets/stylesheets/application.scss

+4
Original file line numberDiff line numberDiff line change
@@ -225,3 +225,7 @@ div.distribution-request-unit {
225225
margin-right: 20px;
226226
white-space: nowrap;
227227
}
228+
229+
.git-version {
230+
color: gray;
231+
}

app/assets/stylesheets/base/_variables.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,4 +141,4 @@ $diaper-font-family-sans-serif-alt: "Helvetica Neue", Helvetica, Arial, sans-ser
141141

142142
// sizes
143143
$diaper-navbar-height: 57;
144-
$diaper-footer-height: 57;
144+
$diaper-footer-height: 75;

app/controllers/product_drives_controller.rb

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ def index
1111
.class_filter(filter_params)
1212
.within_date_range(@selected_date_range)
1313
.order(start_date: :desc)
14+
@paginated_product_drives = @product_drives.page(params[:page])
15+
1416
# to be used in the name filter to sort product drives in alpha order
1517
@product_drives_alphabetical = @product_drives.sort_by { |pd| pd.name.downcase }
1618
@item_categories = current_organization.item_categories

app/jobs/backup_db_rds.rb

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require "aws-sdk-s3"
2+
13
# to be called from Clock
24
module BackupDbRds
35
def self.run
@@ -10,15 +12,11 @@ def self.run
1012
backup_filename = "#{current_time}.rds.dump"
1113
system("PGPASSWORD='#{ENV["DIAPER_DB_PASSWORD"]}' pg_dump -Fc -v --host=#{ENV["DIAPER_DB_HOST"]} --username=#{ENV["DIAPER_DB_USERNAME"]} --dbname=#{ENV["DIAPER_DB_DATABASE"]} -f #{backup_filename}")
1214

13-
account_name = ENV["AZURE_STORAGE_ACCOUNT_NAME"]
14-
account_key = ENV["AZURE_STORAGE_ACCESS_KEY"]
15-
16-
blob_client = Azure::Storage::Blob::BlobService.create(
17-
storage_account_name: account_name,
18-
storage_access_key: account_key
19-
)
15+
client = Aws::S3::Client.new(region: "us-east-2")
2016

2117
logger.info("Uploading #{backup_filename}")
22-
blob_client.create_block_blob("backups", backup_filename, File.read(backup_filename))
18+
client.put_object(key: "backups/#{backup_filename}",
19+
body: File.read(backup_filename),
20+
bucket: "human-essentials-backups")
2321
end
2422
end

app/views/layouts/application.html.erb

+1
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@
9898
<div class="pull-right hidden-xs">
9999
</div>
100100
<strong>Human Essentials was built with <i class="fa fa-heart fa-beat" style="color:red;"></i> by <a href="http://rubyforgood.org">Ruby for Good</a>.</strong>
101+
<br><span class="git-version">Version: <%= ENV['GIT_SHA'] %></span>
101102
</footer>
102103

103104
</aside>

app/views/partners/_show_header.html.erb

-5
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,6 @@
4242
</div>
4343
</div>
4444
<!-- /.card-body -->
45-
<div class="card-footer">
46-
<span class="float-right">
47-
<%= download_button_to(partner_path(partner, format: :csv, filters: filter_params.merge(date_range: date_range_params)), {text: "Export Partner Distributions", size: "md"}) if partner_distributions.any? %>
48-
</span>
49-
</div>
5045
</div>
5146
<div id="seeZipcodes" class="modal fade">
5247
<div class="modal-dialog">

app/views/partners/profiles/step/_attached_documents_form.html.erb

+4-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
<strong>Attached files:</strong>
55
<ul>
66
<% profile.documents.each do |doc| %>
7-
<li><%= link_to doc.blob['filename'], rails_blob_path(doc), class: "font-weight-bold" %></li>
7+
<% if doc.persisted? %>
8+
<li><%= link_to doc.blob['filename'], rails_blob_path(doc), class: "font-weight-bold" %></li>
9+
<%= pf.hidden_field :documents, multiple: true, value: doc.signed_id %>
10+
<% end %>
811
<% end %>
912
</ul>
1013
<%= pf.file_field :documents, multiple: true, class: "form-control-file" %>

app/views/partners/show.html.erb

+3
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@
222222
<!-- Default box -->
223223
<div class="card card-primary card-outline">
224224
<div class="card-header">
225+
<span class="float-right">
226+
<%= download_button_to(partner_path(@partner, format: :csv, filters: filter_params.merge(date_range: date_range_params)), {text: "Export Partner Distributions", size: "md"}) if @partner_distributions.any? %>
227+
</span>
225228
<h2 class="card-title fs-3">Prior Distributions</h2>
226229
</div>
227230
<div class="card-body p-0">

app/views/product_drives/index.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
</tr>
103103
</thead>
104104
<tbody>
105-
<% @product_drives.each do |product_drive| %>
105+
<% @paginated_product_drives.each do |product_drive| %>
106106
<tr>
107107
<td><%= product_drive.name %></td>
108108
<td><%= product_drive.start_date.strftime("%m-%d-%Y") %></td>
@@ -119,9 +119,9 @@
119119
</table>
120120
</div>
121121
<!-- /.card-body -->
122-
<!-- <div class="card-footer clearfix">-->
123-
<%#= paginate @paginated_requests %>
124-
<!-- </div>-->
122+
<div class="card-footer clearfix">
123+
<%= paginate @paginated_product_drives %>
124+
</div>
125125
<!-- /.card-footer-->
126126
</div>
127127
<!-- /.card -->

app/views/product_drives/show.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@
6161
<div class="row">
6262
<div class="col-12">
6363
<!-- Default box -->
64+
<div class="card-footer clearfix">
65+
<%= edit_button_to edit_product_drive_path(@product_drive), { text: "Make a correction", size: "md" } %>
66+
<%= delete_button_to product_drive_path(@product_drive), { confirm: "Are you sure you want to permanently remove this product drive?", size: "md" } if current_user.has_cached_role?(Role::ORG_ADMIN, current_organization) %>
67+
</div>
6468
<div class="card">
6569
<div class="card-body p-0">
6670
<table class="table">
@@ -90,10 +94,6 @@
9094
<p style="text-align: center">
9195
To add additional donations to this product drive, please edit that donation and select this product drive from the appropriate dropdown.
9296
</p>
93-
<div class="card-footer clearfix">
94-
<%= edit_button_to edit_product_drive_path(@product_drive), { text: "Make a correction", size: "md" } %>
95-
<%= delete_button_to product_drive_path(@product_drive), { confirm: "Are you sure you want to permanently remove this product drive?", size: "md" } if current_user.has_cached_role?(Role::ORG_ADMIN, current_organization) %>
96-
</div>
9797
<!-- /.card-footer-->
9898
</div>
9999
<!-- /.card -->

bin/setup

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ FileUtils.chdir APP_ROOT do
4040
#
4141
# Validate that the ruby version requirement is met.
4242
#
43-
expected_ruby_version = `cat .ruby-version`.chomp
43+
expected_ruby_version = `cat .ruby-version`.chomp.gsub(/\.\d+\z/, "")
4444
current_ruby_version = `ruby -v`.chomp
4545
unless current_ruby_version.include?(expected_ruby_version)
4646
log "Ruby version must be #{expected_ruby_version}. You are on #{current_ruby_version}", color: :red

config/initializers/git_sha.rb

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ENV['GIT_SHA'] = `cat #{Rails.root}/REVISION`

config/initializers/strong_migrations.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
# Set the version of the production database
1414
# so the right checks are run in development
15-
StrongMigrations.target_version = 10
15+
StrongMigrations.target_version = 16.3
1616

1717
# Add custom checks
1818
# StrongMigrations.add_check do |method, args|

lib/tasks/fetch_latest_db.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def fetch_latest_backups
5959
# Retrieve the most up to date version of the DB dump
6060
#
6161
backup = backups.contents.select { |b| b.key.match?(".rds.dump") }.sort do |a,b|
62-
Time.parse(a.last_modified) <=> Time.parse(b.last_modified)
62+
a.last_modified <=> b.last_modified
6363
end.reverse.first
6464

6565
#

spec/fixtures/files/document1.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Food Pantry Program Overview
2+
3+
Our food pantry serves families in need within the community.
4+
5+
## Services Provided
6+
7+
- Weekly food distribution
8+
- Emergency food assistance
9+
10+
## Contact Information
11+
12+
13+
Phone: (555) 123-4567

spec/fixtures/files/document2.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Delivery Guidelines
2+
3+
Please follow these guidelines when delivering goods:
4+
5+
1. Ensure all packages are labeled.
6+
2. Deliveries must be completed by 5 PM.
7+
3. Contact us immediately if there are delays.
8+
9+
Thank you for your cooperation!

spec/requests/product_drives_requests_spec.rb

+34
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,40 @@
159159
end
160160
end
161161
end
162+
163+
describe "pagination" do
164+
around do |ex|
165+
Kaminari.config.default_per_page = 2
166+
ex.run
167+
Kaminari.config.default_per_page = 5
168+
end
169+
170+
before do
171+
# Create a list of Product Drives to exceed pagination limit
172+
create_list(:product_drive, 10, organization: organization)
173+
174+
# Fetch Product Drives before assertions
175+
get product_drives_path
176+
end
177+
178+
it "displays pagination controls when there are more product drives than default per page" do
179+
expect(response).to be_successful
180+
181+
parsed_html = Nokogiri::HTML(response.body)
182+
183+
# Select the Product Drives table, which is the only table in the view
184+
# and count the rows
185+
product_drives_table = parsed_html.at_css("table.table")
186+
row_count = product_drives_table.css("tbody tr").size
187+
188+
# There should be 2 rows on the first page--the default per page configured above
189+
expect(row_count).to eq(2)
190+
191+
# Check that pagination controls (e.g., "Next" button) appear
192+
next_button = parsed_html.at_css('a, button') { |el| el.text.strip == 'Next' }
193+
expect(next_button).not_to be_nil
194+
end
195+
end
162196
end
163197

164198
describe "GET #new" do

spec/system/partners/profile_edit_system_spec.rb

+38
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,44 @@
9999
expect(page).to have_css("#partner_settings.accordion-collapse.collapse.show", visible: true)
100100
end
101101

102+
it "preserves previously uploaded documents when adding new attachments" do
103+
# Upload the first document
104+
find("button[data-bs-target='#attached_documents']").click
105+
expect(page).to have_css("#attached_documents.accordion-collapse.collapse.show", visible: true)
106+
107+
within "#attached_documents" do
108+
attach_file("partner_profile_documents", Rails.root.join("spec/fixtures/files/document1.md"), make_visible: true)
109+
end
110+
111+
# Save Progress
112+
all("input[type='submit'][value='Save Progress']").last.click
113+
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")
114+
115+
# Verify the document is listed
116+
visit edit_partners_profile_path
117+
find("button[data-bs-target='#attached_documents']").click
118+
within "#attached_documents" do
119+
expect(page).to have_link("document1.md")
120+
end
121+
122+
# Upload a second document
123+
within "#attached_documents" do
124+
attach_file("partner_profile_documents", Rails.root.join("spec/fixtures/files/document2.md"), make_visible: true)
125+
end
126+
127+
# Save Progress
128+
all("input[type='submit'][value='Save Progress']").last.click
129+
expect(page).to have_css(".alert-success", text: "Details were successfully updated.")
130+
131+
# Verify both documents are listed
132+
visit edit_partners_profile_path
133+
find("button[data-bs-target='#attached_documents']").click
134+
within "#attached_documents" do
135+
expect(page).to have_link("document1.md")
136+
expect(page).to have_link("document2.md")
137+
end
138+
end
139+
102140
it "persists file upload when there are validation errors" do
103141
# Open up Agency Information section and upload proof-of-status letter
104142
find("button[data-bs-target='#agency_information']").click

0 commit comments

Comments
 (0)