Fix few errors

This commit is contained in:
Eugene Burmakin 2025-04-12 13:06:32 +02:00
parent 3996d4c9dc
commit b0b0a11c30
6 changed files with 60 additions and 2 deletions

View file

@ -27,6 +27,7 @@ gem 'activerecord-postgis-adapter'
gem 'puma'
gem 'pundit'
gem 'rails', '~> 8.0'
gem 'rexml'
gem 'rgeo'
gem 'rgeo-activerecord'
gem 'rswag-api'

View file

@ -506,6 +506,7 @@ DEPENDENCIES
pundit
rails (~> 8.0)
redis
rexml
rgeo
rgeo-activerecord
rspec-rails

View file

@ -1,5 +1,7 @@
# frozen_string_literal: true
require 'rexml/document'
class Gpx::TrackImporter
include Imports::Broadcaster

View file

@ -7,7 +7,7 @@
<div class="hero-content text-center">
<div class="max-w-md">
<h1 class="text-5xl font-bold">Hello there!</h1>
<% if current_user.active_until.future? %>
<% if current_user.active_until&.future? %>
<p class="py-6">
You are currently subscribed to Dawarich, hurray!
</p>

View file

@ -5,7 +5,9 @@ class RunInitialVisitSuggestion < ActiveRecord::Migration[7.1]
start_at = 30.years.ago
end_at = Time.current
VisitSuggestingJob.perform_later(start_at:, end_at:)
User.find_each do |user|
VisitSuggestingJob.perform_later(user_id: user.id, start_at:, end_at:)
end
end
def down

View file

@ -1,11 +1,24 @@
# frozen_string_literal: true
require 'rails_helper'
require 'sidekiq/web'
RSpec.describe '/sidekiq', type: :request do
before do
# Allow any ENV key to be accessed and return nil by default
allow(ENV).to receive(:[]).and_return(nil)
# Stub Sidekiq::Web with a simple Rack app for testing
allow(Sidekiq::Web).to receive(:call) do |_env|
[200, { 'Content-Type' => 'text/html' }, ['Sidekiq Web UI']]
end
end
context 'when Dawarich is in self-hosted mode' do
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(true)
allow(ENV).to receive(:[]).with('SIDEKIQ_USERNAME').and_return(nil)
allow(ENV).to receive(:[]).with('SIDEKIQ_PASSWORD').and_return(nil)
end
context 'when user is not authenticated' do
@ -48,6 +61,8 @@ RSpec.describe '/sidekiq', type: :request do
context 'when Dawarich is not in self-hosted mode' do
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
allow(ENV).to receive(:[]).with('SIDEKIQ_USERNAME').and_return(nil)
allow(ENV).to receive(:[]).with('SIDEKIQ_PASSWORD').and_return(nil)
Rails.application.reload_routes!
end
@ -70,4 +85,41 @@ RSpec.describe '/sidekiq', type: :request do
end
end
end
context 'when SIDEKIQ_USERNAME and SIDEKIQ_PASSWORD are set' do
before do
allow(DawarichSettings).to receive(:self_hosted?).and_return(false)
allow(ENV).to receive(:[]).with('SIDEKIQ_USERNAME').and_return('admin')
allow(ENV).to receive(:[]).with('SIDEKIQ_PASSWORD').and_return('password')
end
context 'when user is not authenticated' do
it 'redirects to sign in page' do
get sidekiq_url
expect(response).to redirect_to('/users/sign_in')
end
end
context 'when user is not admin' do
before { sign_in create(:user) }
it 'redirects to root page' do
get sidekiq_url
expect(response).to redirect_to(root_url)
expect(flash[:error]).to eq('You are not authorized to perform this action.')
end
end
context 'when user is admin' do
before { sign_in create(:user, :admin) }
it 'renders a successful response' do
get sidekiq_url
expect(response).to be_successful
end
end
end
end