dawarich/spec/jobs/reverse_geocoding_job_spec.rb

47 lines
1.4 KiB
Ruby
Raw Permalink Normal View History

2024-07-12 15:59:03 -04:00
# frozen_string_literal: true
2024-04-02 17:20:25 -04:00
require 'rails_helper'
RSpec.describe ReverseGeocodingJob, type: :job do
describe '#perform' do
2024-08-05 15:23:08 -04:00
subject(:perform) { described_class.new.perform('Point', point.id) }
2024-04-02 17:20:25 -04:00
let(:point) { create(:point) }
before do
allow(Geocoder).to receive(:search).and_return([double(city: 'City', country: 'Country')])
end
context 'when reverse geocoding is disabled' do
before { allow(DawarichSettings).to receive(:reverse_geocoding_enabled?).and_return(false) }
2024-04-02 17:20:25 -04:00
it 'does not update point' do
2024-05-23 14:12:23 -04:00
expect { perform }.not_to(change { point.reload.city })
2024-04-02 17:20:25 -04:00
end
2024-08-05 15:23:08 -04:00
it 'does not call ReverseGeocoding::Points::FetchData' do
allow(ReverseGeocoding::Points::FetchData).to receive(:new).and_call_original
2024-07-12 15:59:03 -04:00
2024-04-02 17:20:25 -04:00
perform
2024-08-05 15:23:08 -04:00
expect(ReverseGeocoding::Points::FetchData).not_to have_received(:new)
2024-04-02 17:20:25 -04:00
end
end
context 'when reverse geocoding is enabled' do
before { allow(DawarichSettings).to receive(:reverse_geocoding_enabled?).and_return(true) }
2024-04-02 17:20:25 -04:00
2024-07-12 15:59:03 -04:00
let(:stubbed_geocoder) { OpenStruct.new(data: { city: 'City', country: 'Country' }) }
2024-04-02 17:20:25 -04:00
it 'calls Geocoder' do
2024-07-12 15:59:03 -04:00
allow(Geocoder).to receive(:search).and_return([stubbed_geocoder])
2024-08-05 15:23:08 -04:00
allow(ReverseGeocoding::Points::FetchData).to receive(:new).and_call_original
2024-04-02 17:20:25 -04:00
2024-07-12 15:59:03 -04:00
perform
2024-04-02 17:20:25 -04:00
2024-08-05 15:23:08 -04:00
expect(ReverseGeocoding::Points::FetchData).to have_received(:new).with(point.id)
2024-04-02 17:20:25 -04:00
end
end
end
end