Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/admin/dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@
span do
button_to 'Send Balance Due email', send_balance_due_url, class: 'btn'
end
span do
if current_application_settings.balance_due_emails_last_sent_at.present?
zone = current_application_settings.time_zone.presence || Time.zone.name
"Last sent: #{current_application_settings.balance_due_emails_last_sent_at.in_time_zone(zone).strftime('%B %-d, %Y at %-I:%M %p %Z')}"
else
'Last sent: never'
end
end
end
end
column do
Expand Down
1 change: 1 addition & 0 deletions app/controllers/applications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ def send_balance_due
message_count += 1
end
end
current_application_settings&.update(balance_due_emails_last_sent_at: Time.current)
flash[:alert] = "#{message_count} balance due messages sent."
redirect_to admin_root_path
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddBalanceDueEmailsLastSentAtToApplicationSettings < ActiveRecord::Migration[7.0]
def change
add_column :application_settings, :balance_due_emails_last_sent_at, :datetime
end
end
13 changes: 11 additions & 2 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion spec/requests/applications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@
end
end

describe "GET /send_balance_due" do
describe "GET /send_balance_due", :real_application_settings do
context "when admin user is not signed in" do
it "redirects to admin sign in page" do
post send_balance_due_path
Expand All @@ -190,6 +190,8 @@
end

context "when admin user is signed in" do
let!(:application_setting) { create(:application_setting, active_application: true) }

before do
sign_in admin_user
# Mock the mailer to prevent actual emails from being sent
Expand All @@ -201,6 +203,7 @@
post send_balance_due_path
expect(response).to redirect_to(admin_root_path)
expect(flash[:alert]).to eq('1 balance due messages sent.')
expect(application_setting.reload.balance_due_emails_last_sent_at).to be_present
end
end
end
Expand Down
Loading