2024-05-25 07:26:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-03-15 18:27:31 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Point, type: :model do
|
|
|
|
|
describe 'associations' do
|
2024-03-15 19:01:00 -04:00
|
|
|
it { is_expected.to belong_to(:import).optional }
|
2024-07-12 15:59:03 -04:00
|
|
|
it { is_expected.to belong_to(:user) }
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
|
it { is_expected.to validate_presence_of(:latitude) }
|
|
|
|
|
it { is_expected.to validate_presence_of(:longitude) }
|
|
|
|
|
it { is_expected.to validate_presence_of(:timestamp) }
|
|
|
|
|
end
|
2024-07-12 15:59:03 -04:00
|
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
|
describe '.reverse_geocoded' do
|
2024-12-02 08:44:22 -05:00
|
|
|
let(:point) { create(:point, :reverse_geocoded) }
|
2024-07-12 15:59:03 -04:00
|
|
|
let(:point_without_address) { create(:point, city: nil, country: nil) }
|
|
|
|
|
|
|
|
|
|
it 'returns points with reverse geocoded address' do
|
|
|
|
|
expect(described_class.reverse_geocoded).to eq([point])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '.not_reverse_geocoded' do
|
|
|
|
|
let(:point) { create(:point, country: 'Country', city: 'City') }
|
|
|
|
|
let(:point_without_address) { create(:point, city: nil, country: nil) }
|
|
|
|
|
|
|
|
|
|
it 'returns points without reverse geocoded address' do
|
|
|
|
|
expect(described_class.not_reverse_geocoded).to eq([point_without_address])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-31 13:35:35 -04:00
|
|
|
|
|
|
|
|
describe 'methods' do
|
|
|
|
|
describe '#recorded_at' do
|
|
|
|
|
let(:point) { create(:point, timestamp: 1_554_317_696) }
|
|
|
|
|
|
|
|
|
|
it 'returns recorded at time' do
|
|
|
|
|
expect(point.recorded_at).to eq(Time.zone.at(1_554_317_696))
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#async_reverse_geocode' do
|
|
|
|
|
let(:point) { build(:point) }
|
|
|
|
|
|
2024-08-05 15:23:08 -04:00
|
|
|
it 'enqueues ReverseGeocodeJob with correct arguments' do
|
|
|
|
|
point.save
|
|
|
|
|
|
|
|
|
|
expect { point.async_reverse_geocode }.to have_enqueued_job(ReverseGeocodingJob)
|
|
|
|
|
.with('Point', point.id)
|
|
|
|
|
end
|
2024-12-25 06:38:32 -05:00
|
|
|
|
|
|
|
|
context 'when point is imported' do
|
|
|
|
|
let(:point) { build(:point, import_id: 1) }
|
|
|
|
|
|
|
|
|
|
it 'does not enqueue ReverseGeocodeJob' do
|
|
|
|
|
expect { point.async_reverse_geocode }.not_to have_enqueued_job(ReverseGeocodingJob)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
context 'when reverse geocoding is forced' do
|
|
|
|
|
it 'enqueues ReverseGeocodeJob' do
|
|
|
|
|
expect { point.async_reverse_geocode(force: true) }.to have_enqueued_job(ReverseGeocodingJob)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2024-07-31 13:35:35 -04:00
|
|
|
end
|
|
|
|
|
end
|
2024-03-15 18:27:31 -04:00
|
|
|
end
|