dawarich/spec/models/place_spec.rb

61 lines
1.4 KiB
Ruby
Raw Normal View History

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
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
let(:place) { create(:place, :with_geodata) }
2024-08-12 16:18:11 -04:00
describe '#osm_id' do
it 'returns the osm_id' do
expect(place.osm_id).to eq(5_762_449_774)
end
end
describe '#osm_key' do
it 'returns the osm_key' do
expect(place.osm_key).to eq('amenity')
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)
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)
end
end
2024-08-12 16:18:11 -04:00
end
2024-08-05 15:23:08 -04:00
end