Validate MapLocation lat/long/zoom have numeric values

This commit is contained in:
Bertocq
2018-02-02 21:37:50 +01:00
parent 6f87f4b07c
commit 24b1e64113
2 changed files with 10 additions and 1 deletions

View File

@@ -3,7 +3,7 @@ class MapLocation < ActiveRecord::Base
belongs_to :proposal, touch: true
belongs_to :investment, class_name: Budget::Investment, touch: true
validates :longitude, :latitude, :zoom, presence: true
validates :longitude, :latitude, :zoom, presence: true, numericality: true
def available?
latitude.present? && longitude.present? && zoom.present?

View File

@@ -13,6 +13,15 @@ describe MapLocation do
map_location.latitude = nil
map_location.zoom = nil
expect(map_location).not_to be_valid
expect(map_location.errors.size).to eq(6)
end
it "is invalid when longitude/latitude/zoom are not numbers" do
map_location.longitude = 'wadus'
map_location.latitude = 'stuff'
map_location.zoom = '$%·'
expect(map_location).not_to be_valid
expect(map_location.errors.size).to eq(3)
end