Skip to content

Instantly share code, notes, and snippets.

@abacha
Last active April 14, 2026 17:57
Show Gist options
  • Select an option

  • Save abacha/168294f24effb2dfc0d55c7126af4558 to your computer and use it in GitHub Desktop.

Select an option

Save abacha/168294f24effb2dfc0d55c7126af4558 to your computer and use it in GitHub Desktop.
Review App UAT Script: Hubstaff Extra Emails (HUB-14055)
ActiveRecord::Base.transaction do
puts "⚙️ Setting up test data for Review App..."
# Find an organization with at least one manager and two shifts
active_shift = AttendanceShift.where.not(user_id: nil).last
inactive_shift = AttendanceShift.where.not(id: active_shift&.id, user_id: nil).last
active_break = WorkBreak.where.not(user_id: nil).last
inactive_break = WorkBreak.where.not(id: active_break&.id, user_id: nil).last
unless active_shift && inactive_shift && active_break && inactive_break
puts "❌ Could not find enough Shifts or Work Breaks to test."
raise ActiveRecord::Rollback
end
active_user = active_shift.user
inactive_user = inactive_shift.user
# Force the 'last_activity' dates so the mailer logic responds as expected
active_user.update_column(:last_activity, 2.days.ago)
inactive_user.update_column(:last_activity, 40.days.ago)
# Also update the breaks' users to match
active_break.update_column(:user_id, active_user.id)
inactive_break.update_column(:user_id, inactive_user.id)
achievement = Achievement.last
# The recipient (manager) can be any arbitrary user in the org for the sake of triggering the mailer
manager = active_user.organizations.first.members.first || active_user
puts "\n✅ Data setup complete!"
puts " Active Worker: #{active_user.id} (last_activity: #{active_user.last_activity})"
puts " Inactive Worker: #{inactive_user.id} (last_activity: #{inactive_user.last_activity})"
# ==============================================================================
# PART 1: REMOVED EMAILS
# ==============================================================================
puts "\n--- AchievementMailer.earned_achievements ---"
begin
AchievementMailer.earned_achievements(active_user.id, achievement&.id || 1).deliver_now
puts "❌ Expected NoMethodError, but it succeeded!"
rescue NoMethodError => e
puts "✅ Executed. Method no longer exists! (Expected result)"
rescue => e
puts "⚠️ Unexpected Error: #{e.message}"
end
# ==============================================================================
# PART 2: SUPPRESSED EMAILS (Inactive > 30 days)
# ==============================================================================
puts "\n--- AttendanceMailer.management_late_shift_notice ---"
AttendanceMailer.management_late_shift_notice(active_shift.id, user: manager).deliver_now
puts " ✅ Active Worker tested (SHOULD BE SENT TO MANAGERS)"
AttendanceMailer.management_late_shift_notice(inactive_shift.id, user: manager).deliver_now
puts " ✅ Inactive Worker tested (SHOULD BE SUPPRESSED)"
puts "\n--- AttendanceMailer.management_missed_shift_notice ---"
AttendanceMailer.management_missed_shift_notice(active_shift.id, user: manager).deliver_now
puts " ✅ Active Worker tested (SHOULD BE SENT TO MANAGERS)"
AttendanceMailer.management_missed_shift_notice(inactive_shift.id, user: manager).deliver_now
puts " ✅ Inactive Worker tested (SHOULD BE SUPPRESSED)"
puts "\n--- AttendanceMailer.management_abandoned_shift_notice ---"
AttendanceMailer.management_abandoned_shift_notice(active_shift.id, user: manager).deliver_now
puts " ✅ Active Worker tested (SHOULD BE SENT TO MANAGERS)"
AttendanceMailer.management_abandoned_shift_notice(inactive_shift.id, user: manager).deliver_now
puts " ✅ Inactive Worker tested (SHOULD BE SUPPRESSED)"
puts "\n--- WorkBreakMailer.send_notice ---"
WorkBreakMailer.send_notice(active_break.id, user: manager).deliver_now
puts " ✅ Active Worker tested (SHOULD BE SENT TO MANAGERS)"
WorkBreakMailer.send_notice(inactive_break.id, user: manager).deliver_now
puts " ✅ Inactive Worker tested (SHOULD BE SUPPRESSED)"
puts "\n🎉 Done! Rolling back database..."
raise ActiveRecord::Rollback
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment