diff --git a/app/models/place.rb b/app/models/place.rb index b2d7525c..4ee6a0e1 100644 --- a/app/models/place.rb +++ b/app/models/place.rb @@ -12,10 +12,11 @@ class Place < ApplicationRecord has_many :place_visits, dependent: :destroy has_many :suggested_visits, -> { distinct }, through: :place_visits, source: :visit + before_validation :build_lonlat, if: -> { latitude.present? && longitude.present? } + validates :name, presence: true validates :latitude, :longitude, presence: true - - before_validation :build_lonlat, if: -> { latitude.present? && longitude.present? } + validates :lonlat, presence: true enum :source, { manual: 0, photon: 1 } diff --git a/spec/models/place_spec.rb b/spec/models/place_spec.rb index cf6852c4..915ab0ca 100644 --- a/spec/models/place_spec.rb +++ b/spec/models/place_spec.rb @@ -47,13 +47,13 @@ RSpec.describe Place, type: :model do describe '#lon' do it 'returns the longitude' do - expect(place.lon).to eq(13.0948638) + expect(place.lon).to be_within(0.000001).of(13.0948638) end end describe '#lat' do it 'returns the latitude' do - expect(place.lat).to eq(54.2905245) + expect(place.lat).to be_within(0.000001).of(54.2905245) end end end