2024-08-12 16:18:11 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
2024-08-05 15:23:08 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
|
|
RSpec.describe Place, type: :model do
|
2024-08-12 16:18:11 -04:00
|
|
|
describe 'associations' do
|
|
|
|
|
it { is_expected.to have_many(:visits).dependent(:destroy) }
|
|
|
|
|
it { is_expected.to have_many(:place_visits).dependent(:destroy) }
|
|
|
|
|
it { is_expected.to have_many(:suggested_visits).through(:place_visits) }
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
|
it { is_expected.to validate_presence_of(:name) }
|
2025-03-03 16:39:43 -05:00
|
|
|
it { is_expected.to validate_presence_of(:lonlat) }
|
2024-08-12 16:18:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'enums' do
|
2024-08-13 12:25:48 -04:00
|
|
|
it { is_expected.to define_enum_for(:source).with_values(%i[manual photon]) }
|
2024-08-12 16:18:11 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe 'methods' do
|
2025-03-09 09:58:30 -04:00
|
|
|
let(:place) { create(:place, :with_geodata) }
|
2024-08-12 16:18:11 -04:00
|
|
|
|
2025-03-09 09:58:30 -04:00
|
|
|
describe '#osm_id' do
|
|
|
|
|
it 'returns the osm_id' do
|
2025-03-09 10:37:32 -04:00
|
|
|
expect(place.osm_id).to eq(5_762_449_774)
|
2025-03-09 09:58:30 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#osm_key' do
|
|
|
|
|
it 'returns the osm_key' do
|
2025-03-09 10:37:32 -04:00
|
|
|
expect(place.osm_key).to eq('amenity')
|
2025-03-09 09:58:30 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#osm_value' do
|
|
|
|
|
it 'returns the osm_value' do
|
|
|
|
|
expect(place.osm_value).to eq('restaurant')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#osm_type' do
|
|
|
|
|
it 'returns the osm_type' do
|
|
|
|
|
expect(place.osm_type).to eq('N')
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#lon' do
|
|
|
|
|
it 'returns the longitude' do
|
2025-11-16 18:23:48 -05:00
|
|
|
expect(place.lon).to be_within(0.000001).of(13.0948638)
|
2025-03-09 09:58:30 -04:00
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
describe '#lat' do
|
|
|
|
|
it 'returns the latitude' do
|
2025-11-16 18:23:48 -05:00
|
|
|
expect(place.lat).to be_within(0.000001).of(54.2905245)
|
2025-03-09 09:58:30 -04:00
|
|
|
end
|
|
|
|
|
end
|
2024-08-12 16:18:11 -04:00
|
|
|
end
|
2024-08-05 15:23:08 -04:00
|
|
|
end
|