diff --git a/app/admin/dashboard.rb b/app/admin/dashboard.rb index a1bc836..541913d 100644 --- a/app/admin/dashboard.rb +++ b/app/admin/dashboard.rb @@ -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 diff --git a/app/controllers/applications_controller.rb b/app/controllers/applications_controller.rb index 0546316..254864c 100644 --- a/app/controllers/applications_controller.rb +++ b/app/controllers/applications_controller.rb @@ -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 diff --git a/db/migrate/20260331160000_add_balance_due_emails_last_sent_at_to_application_settings.rb b/db/migrate/20260331160000_add_balance_due_emails_last_sent_at_to_application_settings.rb new file mode 100644 index 0000000..4311e83 --- /dev/null +++ b/db/migrate/20260331160000_add_balance_due_emails_last_sent_at_to_application_settings.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 524751e..924afa0 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema[7.1].define(version: 2025_03_04_203447) do +ActiveRecord::Schema[7.2].define(version: 2026_03_31_160000) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -54,11 +54,18 @@ t.string "content_type" t.text "metadata" t.bigint "byte_size", null: false - t.string "checksum", null: false + t.string "checksum" t.datetime "created_at", precision: nil, null: false + t.string "service_name", null: false t.index ["key"], name: "index_active_storage_blobs_on_key", unique: true end + create_table "active_storage_variant_records", id: :serial, force: :cascade do |t| + t.integer "blob_id", null: false + t.string "variation_digest", null: false + t.index ["blob_id", "variation_digest"], name: "index_active_storage_variant_records_uniqueness", unique: true + end + create_table "admin_users", force: :cascade do |t| t.string "email", default: "", null: false t.string "encrypted_password", default: "", null: false @@ -99,6 +106,7 @@ t.text "application_confirm_email_message" t.text "balance_due_email_message" t.text "special_offer_invite_email" + t.datetime "balance_due_emails_last_sent_at" end create_table "applications", force: :cascade do |t| @@ -211,6 +219,7 @@ end add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" + add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "applications", "partner_registrations" add_foreign_key "applications", "users" add_foreign_key "payments", "users" diff --git a/spec/requests/applications_spec.rb b/spec/requests/applications_spec.rb index f834d3d..c92ab68 100644 --- a/spec/requests/applications_spec.rb +++ b/spec/requests/applications_spec.rb @@ -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 @@ -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 @@ -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