diff --git a/CHANGELOG.md b/CHANGELOG.md
index 718c547d..1f0cc432 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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.
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 113e6ec7..5b453fbc 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -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
diff --git a/app/jobs/users/mailer_sending_job.rb b/app/jobs/users/mailer_sending_job.rb
index fef4fcea..ae8b80dc 100644
--- a/app/jobs/users/mailer_sending_job.rb
+++ b/app/jobs/users/mailer_sending_job.rb
@@ -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
diff --git a/app/mailers/users_mailer.rb b/app/mailers/users_mailer.rb
index a06d3dc9..95afd3ea 100644
--- a/app/mailers/users_mailer.rb
+++ b/app/mailers/users_mailer.rb
@@ -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
diff --git a/app/models/user.rb b/app/models/user.rb
index 4ff89d3b..19da0fd3 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -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
diff --git a/app/views/stats/index.html.erb b/app/views/stats/index.html.erb
index 706e30b3..926b5b5e 100644
--- a/app/views/stats/index.html.erb
+++ b/app/views/stats/index.html.erb
@@ -25,7 +25,6 @@
All stats data above except for total distance and number of geopoints tracked is being updated daily
-
<% if current_user.active? %>
<%= link_to 'Update stats', update_all_stats_path, data: { turbo_method: :put }, class: 'btn btn-primary mt-5' %>
<% end %>
diff --git a/app/views/users_mailer/explore_features.html.erb b/app/views/users_mailer/explore_features.html.erb
index 9d8c64c0..9e70e509 100644
--- a/app/views/users_mailer/explore_features.html.erb
+++ b/app/views/users_mailer/explore_features.html.erb
@@ -17,12 +17,17 @@
-
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.
diff --git a/app/views/users_mailer/explore_features.text.erb b/app/views/users_mailer/explore_features.text.erb
index 0ffa8e99..e6b92042 100644
--- a/app/views/users_mailer/explore_features.text.erb
+++ b/app/views/users_mailer/explore_features.text.erb
@@ -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.
diff --git a/app/views/users_mailer/post_trial_reminder_early.html.erb b/app/views/users_mailer/post_trial_reminder_early.html.erb
new file mode 100644
index 00000000..c2459943
--- /dev/null
+++ b/app/views/users_mailer/post_trial_reminder_early.html.erb
@@ -0,0 +1,49 @@
+
+
+
+
+
+
+
+
+
+
+
Hi <%= @user.email %>, this is Evgenii from Dawarich.
+
+
+
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
+
+
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
+
+
+
+
diff --git a/app/views/users_mailer/post_trial_reminder_early.text.erb b/app/views/users_mailer/post_trial_reminder_early.text.erb
new file mode 100644
index 00000000..be2edcc8
--- /dev/null
+++ b/app/views/users_mailer/post_trial_reminder_early.text.erb
@@ -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
diff --git a/app/views/users_mailer/post_trial_reminder_late.html.erb b/app/views/users_mailer/post_trial_reminder_late.html.erb
new file mode 100644
index 00000000..f347ecb0
--- /dev/null
+++ b/app/views/users_mailer/post_trial_reminder_late.html.erb
@@ -0,0 +1,51 @@
+
+
+
+
+
+
+
+
+
+
+
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
+ - Regular updates and new features
+
+
+
Return to Dawarich
+
+
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!
+
+
+
+
diff --git a/app/views/users_mailer/post_trial_reminder_late.text.erb b/app/views/users_mailer/post_trial_reminder_late.text.erb
new file mode 100644
index 00000000..d43db950
--- /dev/null
+++ b/app/views/users_mailer/post_trial_reminder_late.text.erb
@@ -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!
diff --git a/app/views/users_mailer/trial_expired.html.erb b/app/views/users_mailer/trial_expired.html.erb
index 3294b88b..6407fdbf 100644
--- a/app/views/users_mailer/trial_expired.html.erb
+++ b/app/views/users_mailer/trial_expired.html.erb
@@ -17,13 +17,13 @@
π 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.
@@ -40,7 +40,7 @@
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
diff --git a/app/views/users_mailer/trial_expired.text.erb b/app/views/users_mailer/trial_expired.text.erb
index d43178f3..338f0899 100644
--- a/app/views/users_mailer/trial_expired.text.erb
+++ b/app/views/users_mailer/trial_expired.text.erb
@@ -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
diff --git a/app/views/users_mailer/trial_expires_soon.html.erb b/app/views/users_mailer/trial_expires_soon.html.erb
index c1e5ff6e..a0ac2f3f 100644
--- a/app/views/users_mailer/trial_expires_soon.html.erb
+++ b/app/views/users_mailer/trial_expires_soon.html.erb
@@ -17,13 +17,13 @@
β° 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.
@@ -40,7 +40,7 @@
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 or just reply to this email.
+
Questions? Drop me a message at hi@dawarich.app or just reply to this email.
Best regards,
Evgenii from Dawarich
diff --git a/app/views/users_mailer/trial_expires_soon.text.erb b/app/views/users_mailer/trial_expires_soon.text.erb
index c5f7352e..6b15ef3a 100644
--- a/app/views/users_mailer/trial_expires_soon.text.erb
+++ b/app/views/users_mailer/trial_expires_soon.text.erb
@@ -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
diff --git a/app/views/users_mailer/welcome.html.erb b/app/views/users_mailer/welcome.html.erb
index 07f80721..c3c34c82 100644
--- a/app/views/users_mailer/welcome.html.erb
+++ b/app/views/users_mailer/welcome.html.erb
@@ -16,9 +16,9 @@
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:
@@ -30,7 +30,7 @@
Start Exploring Dawarich
- 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
diff --git a/app/views/users_mailer/welcome.text.erb b/app/views/users_mailer/welcome.text.erb
index 8cbf42d2..5870f372 100644
--- a/app/views/users_mailer/welcome.text.erb
+++ b/app/views/users_mailer/welcome.text.erb
@@ -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
diff --git a/spec/jobs/cache/preheating_job_spec.rb b/spec/jobs/cache/preheating_job_spec.rb
index f32f31a6..79483db7 100644
--- a/spec/jobs/cache/preheating_job_spec.rb
+++ b/spec/jobs/cache/preheating_job_spec.rb
@@ -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) }
@@ -59,11 +57,11 @@ RSpec.describe Cache::PreheatingJob do
it 'handles users with no points gracefully' do
user_no_points = create(:user)
-
+
expect { described_class.new.perform }.not_to raise_error
-
+
cached_stats = Rails.cache.read("dawarich/user_#{user_no_points.id}_points_geocoded_stats")
expect(cached_stats).to eq({ geocoded: 0, without_data: 0 })
end
end
-end
\ No newline at end of file
+end
diff --git a/spec/mailers/users_mailer_spec.rb b/spec/mailers/users_mailer_spec.rb
index 11789e2b..eed70c31 100644
--- a/spec/mailers/users_mailer_spec.rb
+++ b/spec/mailers/users_mailer_spec.rb
@@ -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
diff --git a/spec/queries/stats_query_spec.rb b/spec/queries/stats_query_spec.rb
index 6347e4e6..8efcbb81 100644
--- a/spec/queries/stats_query_spec.rb
+++ b/spec/queries/stats_query_spec.rb
@@ -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({
- total: 0,
- geocoded: 0,
- without_data: 0
- })
+ 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({
- total: 3,
- geocoded: 2,
- without_data: 1
- })
+ 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({
- total: 3,
- geocoded: 2,
- without_data: 1
- })
+ 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({
- total: 5,
- geocoded: 5,
- without_data: 0
- })
+ 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({
- total: 3,
- geocoded: 3,
- without_data: 3
- })
+ 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({
- total: 4,
- geocoded: 0,
- without_data: 0
- })
+ expect(points_stats).to eq(
+ {
+ total: 4,
+ geocoded: 0,
+ without_data: 0
+ }
+ )
end
end
@@ -171,4 +182,4 @@ RSpec.describe StatsQuery do
end
end
end
-end
\ No newline at end of file
+end
diff --git a/spec/services/cache/clean_spec.rb b/spec/services/cache/clean_spec.rb
index 84c0b9f7..38ec04b9 100644
--- a/spec/services/cache/clean_spec.rb
+++ b/spec/services/cache/clean_spec.rb
@@ -3,86 +3,88 @@
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
expect(Rails.cache.exist?('cache_jobs_scheduled')).to be true
-
+
described_class.call
-
+
expect(Rails.cache.exist?('cache_jobs_scheduled')).to be false
end
it 'deletes version cache' do
expect(Rails.cache.exist?(CheckAppVersion::VERSION_CACHE_KEY)).to be true
-
+
described_class.call
-
+
expect(Rails.cache.exist?(CheckAppVersion::VERSION_CACHE_KEY)).to be false
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
expect(Rails.logger).to receive(:info).with('Cleaning cache...')
expect(Rails.logger).to receive(:info).with('Cache cleaned')
-
+
described_class.call
end
it 'handles users being added during execution gracefully' do
# Create a user that will be found during the cleaning process
user3 = nil
-
+
allow(User).to receive(:find_each).and_yield(user1).and_yield(user2) do |&block|
# Create a new user while iterating - this should not cause errors
user3 = create(:user)
Rails.cache.write("dawarich/user_#{user3.id}_years_tracked", { 2023 => ['May'] })
Rails.cache.write("dawarich/user_#{user3.id}_points_geocoded_stats", { geocoded: 1, without_data: 0 })
-
+
# Continue with the original block
[user1, user2].each(&block)
end
-
+
expect { described_class.call }.not_to raise_error
-
+
# The new user's cache should still exist since it wasn't processed
expect(Rails.cache.exist?("dawarich/user_#{user3.id}_years_tracked")).to be true
expect(Rails.cache.exist?("dawarich/user_#{user3.id}_points_geocoded_stats")).to be true
end
end
-end
\ No newline at end of file
+end