mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-11 09:41:40 -05:00
Move APP_VERSION to a constant
This commit is contained in:
parent
be3a9c69b5
commit
79bf74add4
7 changed files with 12 additions and 15 deletions
|
|
@ -69,10 +69,6 @@ module ApplicationHelper
|
|||
CheckAppVersion.new.call
|
||||
end
|
||||
|
||||
def app_version
|
||||
File.read('.app_version').strip
|
||||
end
|
||||
|
||||
def app_theme
|
||||
current_user&.theme == 'light' ? 'light' : 'dark'
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ class ReverseGeocodingJob < ApplicationJob
|
|||
def perform(klass, id)
|
||||
return unless REVERSE_GEOCODING_ENABLED
|
||||
|
||||
sleep 1 if PHOTON_API_HOST == 'photon.komoot.io'
|
||||
|
||||
data_fetcher(klass, id).call
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -5,11 +5,10 @@ class CheckAppVersion
|
|||
|
||||
def initialize
|
||||
@repo_url = 'https://api.github.com/repos/Freika/dawarich/tags'
|
||||
@app_version = File.read('.app_version').strip
|
||||
end
|
||||
|
||||
def call
|
||||
latest_version != @app_version
|
||||
latest_version != APP_VERSION
|
||||
rescue StandardError
|
||||
false
|
||||
end
|
||||
|
|
|
|||
|
|
@ -19,10 +19,10 @@
|
|||
<a href="https://github.com/Freika/dawarich/releases/latest" target="_blank" class="inline-flex items-center">
|
||||
<% if new_version_available? %>
|
||||
<span class="tooltip tooltip-bottom" data-tip="New version available! Check out Github releases!">
|
||||
<span class="hidden sm:inline"><%= app_version %> !</span>
|
||||
<span class="hidden sm:inline"><%= APP_VERSION %> !</span>
|
||||
</span>
|
||||
<% else %>
|
||||
<span class="hidden sm:inline"><%= app_version %></span>
|
||||
<span class="hidden sm:inline"><%= APP_VERSION %></span>
|
||||
<% end %>
|
||||
</a>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ REVERSE_GEOCODING_ENABLED = ENV.fetch('REVERSE_GEOCODING_ENABLED', 'true') == 't
|
|||
PHOTON_API_HOST = ENV.fetch('PHOTON_API_HOST', nil)
|
||||
PHOTON_API_USE_HTTPS = ENV.fetch('PHOTON_API_USE_HTTPS', 'true') == 'true'
|
||||
DISTANCE_UNIT = ENV.fetch('DISTANCE_UNIT', 'km').to_sym
|
||||
APP_VERSION = File.read('.app_version').strip
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ settings = {
|
|||
cache: Redis.new,
|
||||
always_raise: :all,
|
||||
use_https: PHOTON_API_USE_HTTPS,
|
||||
http_headers: { 'User-Agent' => "Dawarich #{APP_VERSION} (https://dawarich.app)" },
|
||||
cache_options: {
|
||||
expiration: 1.day
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,27 +6,25 @@ RSpec.describe CheckAppVersion do
|
|||
describe '#call' do
|
||||
subject(:check_app_version) { described_class.new.call }
|
||||
|
||||
let(:app_version) { File.read('.app_version').strip }
|
||||
|
||||
before do
|
||||
stub_request(:any, 'https://api.github.com/repos/Freika/dawarich/tags')
|
||||
.to_return(status: 200, body: '[{"name": "1.0.0"}]', headers: {})
|
||||
|
||||
stub_const('APP_VERSION', '1.0.0')
|
||||
end
|
||||
|
||||
context 'when latest version is newer' do
|
||||
before { allow(File).to receive(:read).with('.app_version').and_return('0.9.0') }
|
||||
before { stub_const('APP_VERSION', '0.9.0') }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
||||
context 'when latest version is the same' do
|
||||
before { allow(File).to receive(:read).with('.app_version').and_return('1.0.0') }
|
||||
|
||||
it { is_expected.to be false }
|
||||
end
|
||||
|
||||
context 'when latest version is older' do
|
||||
before { allow(File).to receive(:read).with('.app_version').and_return('1.1.0') }
|
||||
before { stub_const('APP_VERSION', '1.1.0') }
|
||||
|
||||
it { is_expected.to be true }
|
||||
end
|
||||
|
|
@ -34,7 +32,7 @@ RSpec.describe CheckAppVersion do
|
|||
context 'when request fails' do
|
||||
before do
|
||||
allow(Net::HTTP).to receive(:get).and_raise(StandardError)
|
||||
allow(File).to receive(:read).with('.app_version').and_return(app_version)
|
||||
allow(File).to receive(:read).with('.app_version').and_return(APP_VERSION)
|
||||
end
|
||||
|
||||
it { is_expected.to be false }
|
||||
|
|
|
|||
Loading…
Reference in a new issue