Add missing email templates for post-trial reminders

This commit is contained in:
Eugene Burmakin 2025-09-13 15:37:09 +02:00
parent bfeeeee234
commit 774860220e
22 changed files with 286 additions and 236 deletions

View file

@ -19,7 +19,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## Changed
- Stats page now loads significantly faster due to caching
- Stats page now loads significantly faster due to caching.
- Data on the Stats page is being updated daily, except for total distance and number of geopoints tracked, which are being updated on the fly. Also, charts with yearly and monthly stats are being updated every hour.
- Minor versions are now being built only for amd64 architecture to speed up the build process.
- If user is not authorized to see a page, they will be redirected to the home page with appropriate message instead of seeing an error.

View file

@ -21,58 +21,6 @@ module ApplicationHelper
%w[info success warning error accent secondary primary]
end
def countries_and_cities_stat_for_year(year, stats)
data = { countries: [], cities: [] }
stats.select { _1.year == year }.each do
data[:countries] << _1.toponyms.flatten.map { |t| t['country'] }.uniq.compact
data[:cities] << _1.toponyms.flatten.flat_map { |t| t['cities'].map { |c| c['city'] } }.compact.uniq
end
data[:cities].flatten!.uniq!
data[:countries].flatten!.uniq!
grouped_by_country = {}
stats.select { _1.year == year }.each do |stat|
stat.toponyms.flatten.each do |toponym|
country = toponym['country']
next if country.blank?
grouped_by_country[country] ||= []
next if toponym['cities'].blank?
toponym['cities'].each do |city_data|
city = city_data['city']
grouped_by_country[country] << city if city.present?
end
end
end
grouped_by_country.transform_values!(&:uniq)
{
countries_count: data[:countries].count,
cities_count: data[:cities].count,
grouped_by_country: grouped_by_country.transform_values(&:sort).sort.to_h,
year: year,
modal_id: "countries_cities_modal_#{year}"
}
end
def countries_and_cities_stat_for_month(stat)
countries = stat.toponyms.count { _1['country'] }
cities = stat.toponyms.sum { _1['cities'].count }
"#{countries} countries, #{cities} cities"
end
def year_distance_stat(year, user)
# Distance is now stored in meters, convert to user's preferred unit for display
total_distance_meters = Stat.year_distance(year, user).sum { _1[1] }
Stat.convert_distance(total_distance_meters, user.safe_settings.distance_unit)
end
def new_version_available?
CheckAppVersion.new.call
end

View file

@ -26,10 +26,6 @@ class Users::MailerSendingJob < ApplicationJob
user.active?
when 'post_trial_reminder_early', 'post_trial_reminder_late'
user.active? || !user.trial?
when 'subscription_expires_soon_early', 'subscription_expires_soon_late'
!user.active? || !user.active_until&.future?
when 'subscription_expired_early', 'subscription_expired_late'
user.active? || user.active_until&.future? || user.trial?
else
false
end
@ -41,10 +37,6 @@ class Users::MailerSendingJob < ApplicationJob
'user is already subscribed'
when 'post_trial_reminder_early', 'post_trial_reminder_late'
user.active? ? 'user is subscribed' : 'user is not in trial state'
when 'subscription_expires_soon_early', 'subscription_expires_soon_late'
'user is not active or subscription already expired'
when 'subscription_expired_early', 'subscription_expired_late'
'user is active, subscription not expired, or user is in trial'
else
'unknown reason'
end

View file

@ -2,62 +2,44 @@
class UsersMailer < ApplicationMailer
def welcome
# Sent after user signs up
@user = params[:user]
mail(to: @user.email, subject: 'Welcome to Dawarich!')
end
def explore_features
# Sent 2 days after user signs up
@user = params[:user]
mail(to: @user.email, subject: 'Explore Dawarich features!')
end
def trial_expires_soon
# Sent 2 days before trial expires
@user = params[:user]
mail(to: @user.email, subject: '⚠️ Your Dawarich trial expires in 2 days')
end
def trial_expired
# Sent when trial expires
@user = params[:user]
mail(to: @user.email, subject: '💔 Your Dawarich trial expired')
end
def post_trial_reminder_early
# Sent 2 days after trial expires
@user = params[:user]
mail(to: @user.email, subject: '🚀 Still interested in Dawarich? Subscribe now!')
end
def post_trial_reminder_late
# Sent 7 days after trial expires
@user = params[:user]
mail(to: @user.email, subject: '📍 Your location data is waiting - Subscribe to Dawarich')
end
def subscription_expires_soon_early
@user = params[:user]
mail(to: @user.email, subject: '⚠️ Your Dawarich subscription expires in 14 days')
end
def subscription_expires_soon_late
@user = params[:user]
mail(to: @user.email, subject: '🚨 Your Dawarich subscription expires in 2 days')
end
def subscription_expired_early
@user = params[:user]
mail(to: @user.email, subject: '💔 Your Dawarich subscription expired - Reactivate now')
end
def subscription_expired_late
@user = params[:user]
mail(to: @user.email, subject: '📍 Missing your location insights? Renew Dawarich subscription')
end
end

View file

@ -18,7 +18,6 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
after_create :create_api_key
after_commit :activate, on: :create, if: -> { DawarichSettings.self_hosted? }
after_commit :start_trial, on: :create, if: -> { !DawarichSettings.self_hosted? }
after_commit :schedule_subscription_emails_on_activation, if: :should_schedule_subscription_emails?
before_save :sanitize_input
@ -170,45 +169,6 @@ class User < ApplicationRecord # rubocop:disable Metrics/ClassLength
Users::MailerSendingJob.set(wait: 14.days).perform_later(id, 'post_trial_reminder_late')
end
def schedule_subscription_expiry_emails
return unless active? && active_until&.future?
days_until_expiry = (active_until.to_date - Time.current.to_date).to_i
if days_until_expiry >= 14
Users::MailerSendingJob.set(wait: (days_until_expiry - 14).days).perform_later(id,
'subscription_expires_soon_early')
end
if days_until_expiry >= 2
Users::MailerSendingJob.set(wait: (days_until_expiry - 2).days).perform_later(id,
'subscription_expires_soon_late')
end
schedule_subscription_expired_emails
end
def schedule_subscription_expired_emails
return unless active? && active_until&.future?
days_until_expiry = (active_until.to_date - Time.current.to_date).to_i
Users::MailerSendingJob.set(wait: (days_until_expiry + 7).days).perform_later(id, 'subscription_expired_early')
Users::MailerSendingJob.set(wait: (days_until_expiry + 14).days).perform_later(id, 'subscription_expired_late')
end
def should_schedule_subscription_emails?
return false unless persisted?
# Schedule if status changed to active or active_until was updated for an active user
(saved_change_to_status? && status == 'active') ||
(saved_change_to_active_until? && active? && active_until&.future?)
end
def schedule_subscription_emails_on_activation
schedule_subscription_expiry_emails
end
def countries_visited_uncached
points
.without_raw_data

View file

@ -25,7 +25,6 @@
All stats data above except for total distance and number of geopoints tracked is being updated daily
</div>
<% if current_user.active? %>
<%= link_to 'Update stats', update_all_stats_path, data: { turbo_method: :put }, class: 'btn btn-primary mt-5' %>
<% end %>

View file

@ -17,12 +17,17 @@
<h1>Explore Dawarich Features</h1>
</div>
<div class="content">
<p>Hi <%= @user.email %>,</p>
<p>Hi <%= @user.email %>, this is Evgenii from Dawarich.</p>
<p>You're now 2 days into your Dawarich trial! We hope you're enjoying tracking your location data.</p>
<p>You're now 2 days into your Dawarich trial! I hope you're enjoying tracking your location data.</p>
<p>Here are some powerful features you might want to explore:</p>
<div class="feature">
<h3>✈️ Reliving your travels</h3>
<p>Revisit your past journeys with detailed maps and insights.</p>
</div>
<div class="feature">
<h3>📊 Statistics & Analytics</h3>
<p>View detailed insights about distances traveled and time spent in different locations.</p>

View file

@ -1,11 +1,14 @@
Explore Dawarich Features
Hi <%= @user.email %>,
Hi <%= @user.email %>, this is Evgenii from Dawarich.
You're now 2 days into your Dawarich trial! We hope you're enjoying tracking your location data.
You're now 2 days into your Dawarich trial! I hope you're enjoying tracking your location data.
Here are some powerful features you might want to explore:
✈️ Reliving your travels
Revisit your past journeys with detailed maps and insights.
📊 Statistics & Analytics
View detailed insights about distances traveled and time spent in different locations.

View file

@ -0,0 +1,49 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #2563eb; color: white; padding: 20px; text-align: center; }
.content { padding: 20px; background: #f9fafb; }
.cta { background: #2563eb; color: white; padding: 12px 24px; text-decoration: none; border-radius: 6px; display: inline-block; margin: 20px 0; }
.reminder { background: #dbeafe; border: 1px solid #2563eb; padding: 15px; border-radius: 6px; margin: 20px 0; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>🚀 Still Interested in Dawarich?</h1>
</div>
<div class="content">
<p>Hi <%= @user.email %>, this is Evgenii from Dawarich.</p>
<div class="reminder">
<p><strong>Your Dawarich trial ended 2 days ago.</strong></p>
</div>
<p>I noticed you haven't subscribed yet, but I don't want you to miss out on the amazing features Dawarich has to offer!</p>
<p>Your location data is still safely stored and waiting for you for 365 days. With a subscription, you can pick up exactly where you left off.</p>
<h3>🌟 What you're missing:</h3>
<ul>
<li>Real-time location tracking and analysis</li>
<li>Beautiful, interactive maps with your travel history</li>
<li>Detailed statistics and insights about your journeys</li>
<li>Data export capabilities for your peace of mind</li>
</ul>
<a href="https://my.dawarich.app?utm_source=email&utm_medium=email&utm_campaign=post_trial_reminder_early&utm_content=subscribe_now" class="cta">Subscribe Now</a>
<p>Ready to unlock your location story? Subscribe today and continue your journey with Dawarich!</p>
<p>Questions? Just reply to this email I'm here to help.</p>
<p>Best regards,<br>
Evgenii from Dawarich</p>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,24 @@
🚀 Still Interested in Dawarich?
Hi <%= @user.email %>,
Your Dawarich trial ended 2 days ago.
I noticed you haven't subscribed yet, but I don't want you to miss out on the amazing features Dawarich has to offer!
Your location data is still safely stored and waiting for you for 365 days. With a subscription, you can pick up exactly where you left off.
🌟 What you're missing:
- Real-time location tracking and analysis
- Beautiful, interactive maps with your travel history
- Detailed statistics and insights about your journeys
- Data export capabilities for your peace of mind
Subscribe now: https://my.dawarich.app
Ready to unlock your location story? Subscribe today and continue your journey with Dawarich!
Questions? Just reply to this email I'm here to help.
Best regards,
Evgenii from Dawarich

View file

@ -0,0 +1,51 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
body { font-family: Arial, sans-serif; line-height: 1.6; color: #333; }
.container { max-width: 600px; margin: 0 auto; padding: 20px; }
.header { background: #059669; color: white; padding: 20px; text-align: center; }
.content { padding: 20px; background: #f9fafb; }
.cta { background: #059669; color: white; padding: 12px 24px; text-decoration: none; border-radius: 6px; display: inline-block; margin: 20px 0; }
.waiting { background: #d1fae5; border: 1px solid #059669; padding: 15px; border-radius: 6px; margin: 20px 0; }
.special { background: #fef3c7; border: 1px solid #f59e0b; padding: 15px; border-radius: 6px; margin: 20px 0; }
</style>
</head>
<body>
<div class="container">
<div class="header">
<h1>📍 Your Location Data is Waiting</h1>
</div>
<div class="content">
<p>Hi <%= @user.email %>, this is Evgenii from Dawarich.</p>
<div class="waiting">
<p><strong>It's been a week since your Dawarich trial ended.</strong></p>
</div>
<p>Your location data is still safely stored and patiently waiting for you to return. I understand that choosing the right tool for your location tracking needs is important, and I wanted to reach out one more time.</p>
<h3>🗺️ Here's what's waiting for you:</h3>
<ul>
<li>All your location data, preserved and ready</li>
<li>Reliving your travels through detailed maps and insights</li>
<li>Privacy-first approach your data stays yours</li>
<li>Beautiful visualizations of your travel patterns</li>
<li>Regular updates and new features</li>
</ul>
<a href="https://my.dawarich.app?utm_source=email&utm_medium=email&utm_campaign=post_trial_reminder_late&utm_content=special_offer" class="cta">Return to Dawarich</a>
<p>This is my final reminder about your trial. If Dawarich isn't the right fit for you right now, I completely understand. Your data will remain secure for the next year, and you're always welcome back.</p>
<p>Thank you for giving Dawarich a try. I hope to see you again soon!</p>
<p>Safe travels,<br>
Evgenii from Dawarich</p>
<p><em>P.S. If you have any questions or need assistance, just hit reply I'm here to help!</em></p>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,26 @@
📍 Your Location Data is Waiting
Hi <%= @user.email %>, this is Evgenii from Dawarich.
It's been a week since your Dawarich trial ended.
Your location data is still safely stored and patiently waiting for you to return. I understand that choosing the right tool for your location tracking needs is important, and I wanted to reach out one more time.
🗺️ Here's what's waiting for you:
- All your location data, preserved and ready
- Reliving your travels through detailed maps and insights
- Privacy-first approach your data stays yours
- Beautiful visualizations of your travel patterns
- Integration with popular location apps and services
- Regular updates and new features
Return to Dawarich: https://my.dawarich.app
This is my final reminder about your trial. If Dawarich isn't the right fit for you right now, I completely understand. Your data will remain secure for the next year, and you're always welcome back.
Thank you for giving Dawarich a try. I hope to see you again soon!
Safe travels,
Evgenii from Dawarich
P.S. If you have any questions or need assistance, just hit reply I'm here to help!

View file

@ -17,13 +17,13 @@
<h1>🔒 Your Trial Has Expired</h1>
</div>
<div class="content">
<p>Hi <%= @user.email %>,</p>
<p>Hi <%= @user.email %>, this is Evgenii from Dawarich.</p>
<div class="expired">
<p><strong>Your 7-day Dawarich trial has ended.</strong></p>
</div>
<p>Thank you for trying Dawarich! We hope you enjoyed exploring your location data over the past week.</p>
<p>Thank you for trying Dawarich! I hope you enjoyed exploring your location data over the past week.</p>
<p>Your trial account is now limited, but your data is safe and secure. To regain full access to all features, please subscribe to continue your journey with Dawarich.</p>
@ -40,7 +40,7 @@
<p>Ready to unlock the full power of location insights? Subscribe now and pick up right where you left off!</p>
<p>We'd love to have you back as a subscriber.</p>
<p>I'd love to have you back as a subscriber.</p>
<p>Best regards,<br>
Evgenii from Dawarich</p>

View file

@ -1,10 +1,10 @@
🔒 Your Trial Has Expired
Hi <%= @user.email %>,
Hi <%= @user.email %>, this is Evgenii from Dawarich.
Your 7-day Dawarich trial has ended.
Thank you for trying Dawarich! We hope you enjoyed exploring your location data over the past week.
Thank you for trying Dawarich! I hope you enjoyed exploring your location data over the past week.
Your trial account is now limited, but your data is safe and secure. To regain full access to all features, please subscribe to continue your journey with Dawarich.
@ -19,7 +19,7 @@ Subscribe to continue: https://my.dawarich.app
Ready to unlock the full power of location insights? Subscribe now and pick up right where you left off!
We'd love to have you back as a subscriber.
I'd love to have you back as a subscriber.
Best regards,
Evgenii from Dawarich

View file

@ -17,13 +17,13 @@
<h1>⏰ Your Trial Expires Soon</h1>
</div>
<div class="content">
<p>Hi <%= @user.email %>,</p>
<p>Hi <%= @user.email %>, this is Evgenii from Dawarich.</p>
<div class="urgent">
<p><strong>⚠️ Important:</strong> Your Dawarich trial expires in just <strong>2 days</strong>!</p>
</div>
<p>We hope you've enjoyed exploring your location data with Dawarich over the past 5 days.</p>
<p>I hope you've enjoyed exploring your location data with Dawarich over the past 5 days.</p>
<p>To continue using all of Dawarich's powerful features after your trial ends, you'll need to subscribe to a plan.</p>
@ -40,7 +40,7 @@
<p>Don't lose access to your location insights. Subscribe today and continue your journey with Dawarich!</p>
<p>Questions? Drop us a message at hi@dawarich.app or just reply to this email.</p>
<p>Questions? Drop me a message at hi@dawarich.app or just reply to this email.</p>
<p>Best regards,<br>
Evgenii from Dawarich</p>

View file

@ -1,10 +1,10 @@
⏰ Your Trial Expires Soon
Hi <%= @user.email %>,
Hi <%= @user.email %>, this is Evgenii from Dawarich.
⚠️ Important: Your Dawarich trial expires in just 2 days!
We hope you've enjoyed exploring your location data with Dawarich over the past 5 days.
I hope you've enjoyed exploring your location data with Dawarich over the past 5 days.
To continue using all of Dawarich's powerful features after your trial ends, you'll need to subscribe to a plan.
@ -19,7 +19,7 @@ Subscribe now: https://my.dawarich.app
Don't lose access to your location insights. Subscribe today and continue your journey with Dawarich!
Questions? Drop us a message at hi@dawarich.app
Questions? Drop me a message at hi@dawarich.app or just reply to this email.
Best regards,
Evgenii from Dawarich

View file

@ -16,9 +16,9 @@
<h1>Welcome to Dawarich!</h1>
</div>
<div class="content">
<p>Hi <%= @user.email %>,</p>
<p>Hi <%= @user.email %>, this is Evgenii from Dawarich.</p>
<p>Welcome to Dawarich! We're excited to have you on board.</p>
<p>Welcome to Dawarich! I'm excited to have you on board.</p>
<p>Your 7-day free trial has started. During this time, you can:</p>
<ul>
@ -30,7 +30,7 @@
<a href="https://my.dawarich.app?utm_source=email&utm_medium=email&utm_campaign=welcome&utm_content=start_exploring" class="cta">Start Exploring Dawarich</a>
<p>If you have any questions, feel free to drop us a message at hi@dawarich.app or just reply to this email.</p>
<p>If you have any questions, feel free to drop me a message at hi@dawarich.app or just reply to this email.</p>
<p>Happy tracking!<br>
Evgenii from Dawarich</p>

View file

@ -1,8 +1,8 @@
Welcome to Dawarich!
Hi <%= @user.email %>,
Hi <%= @user.email %>, this is Evgenii from Dawarich.
Welcome to Dawarich! We're excited to have you on board.
Welcome to Dawarich! I'm excited to have you on board.
Your 7-day free trial has started. During this time, you can:
- Track your location data
@ -12,7 +12,7 @@ Your 7-day free trial has started. During this time, you can:
Start exploring Dawarich: https://my.dawarich.app
If you have any questions, feel free to drop us a message at hi@dawarich.app or just reply to this email.
If you have any questions, feel free to drop me a message at hi@dawarich.app or just reply to this email.
Happy tracking!
Evgenii from Dawarich

View file

@ -3,9 +3,7 @@
require 'rails_helper'
RSpec.describe Cache::PreheatingJob do
before do
Rails.cache.clear
end
before { Rails.cache.clear }
describe '#perform' do
let!(:user1) { create(:user) }

View file

@ -1,6 +1,6 @@
# frozen_string_literal: true
require "rails_helper"
require 'rails_helper'
RSpec.describe UsersMailer, type: :mailer do
let(:user) { create(:user, email: 'test@example.com') }
@ -9,43 +9,43 @@ RSpec.describe UsersMailer, type: :mailer do
stub_const('ENV', ENV.to_hash.merge('SMTP_FROM' => 'hi@dawarich.app'))
end
describe "welcome" do
describe 'welcome' do
let(:mail) { UsersMailer.with(user: user).welcome }
it "renders the headers" do
expect(mail.subject).to eq("Welcome to Dawarich!")
expect(mail.to).to eq(["test@example.com"])
it 'renders the headers' do
expect(mail.subject).to eq('Welcome to Dawarich!')
expect(mail.to).to eq(['test@example.com'])
end
it "renders the body" do
expect(mail.body.encoded).to match("test@example.com")
it 'renders the body' do
expect(mail.body.encoded).to match('test@example.com')
end
end
describe "explore_features" do
describe 'explore_features' do
let(:mail) { UsersMailer.with(user: user).explore_features }
it "renders the headers" do
expect(mail.subject).to eq("Explore Dawarich features!")
expect(mail.to).to eq(["test@example.com"])
it 'renders the headers' do
expect(mail.subject).to eq('Explore Dawarich features!')
expect(mail.to).to eq(['test@example.com'])
end
end
describe "trial_expires_soon" do
describe 'trial_expires_soon' do
let(:mail) { UsersMailer.with(user: user).trial_expires_soon }
it "renders the headers" do
expect(mail.subject).to eq("⚠️ Your Dawarich trial expires in 2 days")
expect(mail.to).to eq(["test@example.com"])
it 'renders the headers' do
expect(mail.subject).to eq('⚠️ Your Dawarich trial expires in 2 days')
expect(mail.to).to eq(['test@example.com'])
end
end
describe "trial_expired" do
describe 'trial_expired' do
let(:mail) { UsersMailer.with(user: user).trial_expired }
it "renders the headers" do
expect(mail.subject).to eq("💔 Your Dawarich trial expired")
expect(mail.to).to eq(["test@example.com"])
it 'renders the headers' do
expect(mail.subject).to eq('💔 Your Dawarich trial expired')
expect(mail.to).to eq(['test@example.com'])
end
end
end

View file

@ -3,9 +3,8 @@
require 'rails_helper'
RSpec.describe StatsQuery do
before do
Rails.cache.clear
end
before { Rails.cache.clear }
describe '#points_stats' do
subject(:points_stats) { described_class.new(user).points_stats }
@ -14,11 +13,13 @@ RSpec.describe StatsQuery do
context 'when user has no points' do
it 'returns zero counts for all statistics' do
expect(points_stats).to eq({
expect(points_stats).to eq(
{
total: 0,
geocoded: 0,
without_data: 0
})
}
)
end
end
@ -48,11 +49,13 @@ RSpec.describe StatsQuery do
end
it 'returns correct counts for all statistics' do
expect(points_stats).to eq({
expect(points_stats).to eq(
{
total: 3,
geocoded: 2,
without_data: 1
})
}
)
end
context 'when another user has points' do
@ -67,11 +70,13 @@ RSpec.describe StatsQuery do
end
it 'only counts points for the specified user' do
expect(points_stats).to eq({
expect(points_stats).to eq(
{
total: 3,
geocoded: 2,
without_data: 1
})
}
)
end
end
end
@ -86,11 +91,13 @@ RSpec.describe StatsQuery do
end
it 'returns correct statistics' do
expect(points_stats).to eq({
expect(points_stats).to eq(
{
total: 5,
geocoded: 5,
without_data: 0
})
}
)
end
end
@ -104,11 +111,13 @@ RSpec.describe StatsQuery do
end
it 'returns correct statistics' do
expect(points_stats).to eq({
expect(points_stats).to eq(
{
total: 3,
geocoded: 3,
without_data: 3
})
}
)
end
end
@ -122,11 +131,13 @@ RSpec.describe StatsQuery do
end
it 'returns correct statistics' do
expect(points_stats).to eq({
expect(points_stats).to eq(
{
total: 4,
geocoded: 0,
without_data: 0
})
}
)
end
end

View file

@ -3,22 +3,24 @@
require 'rails_helper'
RSpec.describe Cache::Clean do
before do
Rails.cache.clear
end
before { Rails.cache.clear }
describe '.call' do
let!(:user1) { create(:user) }
let!(:user2) { create(:user) }
let(:user_1_years_tracked_key) { "dawarich/user_#{user1.id}_years_tracked" }
let(:user_2_years_tracked_key) { "dawarich/user_#{user2.id}_years_tracked" }
let(:user_1_points_geocoded_stats_key) { "dawarich/user_#{user1.id}_points_geocoded_stats" }
let(:user_2_points_geocoded_stats_key) { "dawarich/user_#{user2.id}_points_geocoded_stats" }
before do
# Set up cache entries that should be cleaned
Rails.cache.write('cache_jobs_scheduled', true)
Rails.cache.write(CheckAppVersion::VERSION_CACHE_KEY, '1.0.0')
Rails.cache.write("dawarich/user_#{user1.id}_years_tracked", { 2023 => ['Jan', 'Feb'] })
Rails.cache.write("dawarich/user_#{user2.id}_years_tracked", { 2023 => ['Mar', 'Apr'] })
Rails.cache.write("dawarich/user_#{user1.id}_points_geocoded_stats", { geocoded: 5, without_data: 2 })
Rails.cache.write("dawarich/user_#{user2.id}_points_geocoded_stats", { geocoded: 3, without_data: 1 })
Rails.cache.write(user_1_years_tracked_key, { 2023 => %w[Jan Feb] })
Rails.cache.write(user_2_years_tracked_key, { 2023 => %w[Mar Apr] })
Rails.cache.write(user_1_points_geocoded_stats_key, { geocoded: 5, without_data: 2 })
Rails.cache.write(user_2_points_geocoded_stats_key, { geocoded: 3, without_data: 1 })
end
it 'deletes control flag cache' do
@ -38,23 +40,23 @@ RSpec.describe Cache::Clean do
end
it 'deletes years tracked cache for all users' do
expect(Rails.cache.exist?("dawarich/user_#{user1.id}_years_tracked")).to be true
expect(Rails.cache.exist?("dawarich/user_#{user2.id}_years_tracked")).to be true
expect(Rails.cache.exist?(user_1_years_tracked_key)).to be true
expect(Rails.cache.exist?(user_2_years_tracked_key)).to be true
described_class.call
expect(Rails.cache.exist?("dawarich/user_#{user1.id}_years_tracked")).to be false
expect(Rails.cache.exist?("dawarich/user_#{user2.id}_years_tracked")).to be false
expect(Rails.cache.exist?(user_1_years_tracked_key)).to be false
expect(Rails.cache.exist?(user_2_years_tracked_key)).to be false
end
it 'deletes points geocoded stats cache for all users' do
expect(Rails.cache.exist?("dawarich/user_#{user1.id}_points_geocoded_stats")).to be true
expect(Rails.cache.exist?("dawarich/user_#{user2.id}_points_geocoded_stats")).to be true
expect(Rails.cache.exist?(user_1_points_geocoded_stats_key)).to be true
expect(Rails.cache.exist?(user_2_points_geocoded_stats_key)).to be true
described_class.call
expect(Rails.cache.exist?("dawarich/user_#{user1.id}_points_geocoded_stats")).to be false
expect(Rails.cache.exist?("dawarich/user_#{user2.id}_points_geocoded_stats")).to be false
expect(Rails.cache.exist?(user_1_points_geocoded_stats_key)).to be false
expect(Rails.cache.exist?(user_2_points_geocoded_stats_key)).to be false
end
it 'logs cache cleaning process' do