diff --git a/app/models/user.rb b/app/models/user.rb index 796cf738..64e45425 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,8 +1,6 @@ # frozen_string_literal: true class User < ApplicationRecord - # Include default devise modules. Others available are: - # :confirmable, :lockable, :timeoutable, and :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :validatable, :trackable diff --git a/config/routes.rb b/config/routes.rb index d8926bd0..8d28efde 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -57,8 +57,6 @@ Rails.application.routes.draw do put 'users' => 'devise/registrations#update', :as => 'user_registration' end - # And then modify the app/views/devise/shared/_links.erb - get 'map', to: 'map#index' namespace :api do diff --git a/spec/requests/stats_spec.rb b/spec/requests/stats_spec.rb index 224cb3b5..c7473bed 100644 --- a/spec/requests/stats_spec.rb +++ b/spec/requests/stats_spec.rb @@ -27,12 +27,10 @@ RSpec.describe '/stats', type: :request do end context 'when user is signed in' do - before do - sign_in user - end - let(:user) { create(:user) } + before { sign_in user } + describe 'GET /index' do it 'renders a successful response' do get stats_url @@ -54,10 +52,32 @@ RSpec.describe '/stats', type: :request do describe 'POST /update' do let(:stat) { create(:stat, user:, year: 2024) } + context 'when updating a specific month' do + it 'enqueues Stats::CalculatingJob for the given year and month' do + put update_year_month_stats_url(year: '2024', month: '1') + + expect(Stats::CalculatingJob).to have_been_enqueued.with(user.id, '2024', '1') + end + end + + context 'when updating the whole year' do + it 'enqueues Stats::CalculatingJob for each month of the year' do + put update_year_month_stats_url(year: '2024', month: 'all') + + (1..12).each do |month| + expect(Stats::CalculatingJob).to have_been_enqueued.with(user.id, '2024', month) + end + end + end + end + + describe 'PUT /update_all' do + let(:stat) { create(:stat, user:, year: 2024) } + it 'enqueues Stats::CalculatingJob for each tracked year and month' do allow(user).to receive(:years_tracked).and_return([{ year: 2024, months: %w[Jan Feb] }]) - post stats_url + put update_all_stats_url expect(Stats::CalculatingJob).to have_been_enqueued.with(user.id, 2024, 1) expect(Stats::CalculatingJob).to have_been_enqueued.with(user.id, 2024, 2)