mirror of
https://github.com/Freika/dawarich.git
synced 2026-01-10 01:01:39 -05:00
Update tests a bit
This commit is contained in:
parent
48e73b4f1d
commit
96108b12d0
4 changed files with 19 additions and 36 deletions
|
|
@ -39,7 +39,6 @@ class TripsController < ApplicationController
|
|||
|
||||
def update
|
||||
if @trip.update(trip_params)
|
||||
# Only recalculate if date range changed (handled by model callback)
|
||||
redirect_to @trip, notice: 'Trip was successfully updated.', status: :see_other
|
||||
else
|
||||
render :edit, status: :unprocessable_entity
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
class CreatePathsForTrips < ActiveRecord::Migration[8.0]
|
||||
def up
|
||||
Trip.find_each do |trip|
|
||||
Trips::CreatePathJob.perform_later(trip.id)
|
||||
Trips::CalculatePathJob.perform_later(trip.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'rails_helper'
|
||||
|
||||
RSpec.describe Trips::CreatePathJob, type: :job do
|
||||
let!(:trip) { create(:trip, :with_points) }
|
||||
let(:points) { trip.points }
|
||||
let(:trip_path) do
|
||||
"LINESTRING (#{points.map do |point|
|
||||
"#{point.lon.to_f.round(5)} #{point.lat.to_f.round(5)}"
|
||||
end.join(', ')})"
|
||||
end
|
||||
|
||||
before do
|
||||
trip.update(path: nil, distance: nil)
|
||||
end
|
||||
|
||||
it 'creates a path for a trip' do
|
||||
described_class.perform_now(trip.id)
|
||||
|
||||
expect(trip.reload.path.to_s).to eq(trip_path)
|
||||
end
|
||||
end
|
||||
|
|
@ -20,17 +20,18 @@ RSpec.describe Trip, type: :model do
|
|||
describe 'callbacks' do
|
||||
let(:user) { create(:user) }
|
||||
let(:trip) { create(:trip, :with_points, user:) }
|
||||
let(:calculated_distance) { trip.send(:calculate_distance) }
|
||||
|
||||
it 'sets the distance' do
|
||||
expect(trip.distance).to eq(calculated_distance)
|
||||
context 'when the trip is created' do
|
||||
let(:trip) { build(:trip, :with_points, user:) }
|
||||
|
||||
it 'enqueues the calculation jobs' do
|
||||
expect(Trips::CalculateAllJob).to receive(:perform_later)
|
||||
|
||||
trip.save
|
||||
end
|
||||
end
|
||||
|
||||
it 'sets the path' do
|
||||
expect(trip.path).to be_present
|
||||
end
|
||||
|
||||
context 'when DawarichSettings.store_geodata is enabled' do
|
||||
context 'when DawarichSettings.store_geodata? is enabled' do
|
||||
before do
|
||||
allow(DawarichSettings).to receive(:store_geodata?).and_return(true)
|
||||
end
|
||||
|
|
@ -40,11 +41,17 @@ RSpec.describe Trip, type: :model do
|
|||
end
|
||||
end
|
||||
|
||||
context 'when DawarichSettings.store_geodata is disabled' do
|
||||
context 'when DawarichSettings.store_geodata? is disabled' do
|
||||
let(:countries_service) { instance_double(Trips::Countries, call: []) }
|
||||
let(:trip) { build(:trip, :with_points, user:) }
|
||||
|
||||
before do
|
||||
allow(DawarichSettings).to receive(:store_geodata?).and_return(false)
|
||||
end
|
||||
|
||||
it 'sets the visited countries' do
|
||||
countries_service = instance_double(Trips::Countries, call: [])
|
||||
expect(Trips::Countries).to receive(:new).with(trip).and_return(countries_service)
|
||||
expect(countries_service).to receive(:call)
|
||||
expect(any_instance_of(Trips::Countries)).to receive(:call)
|
||||
|
||||
trip.save
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue