diff --git a/app/models/map_location.rb b/app/models/map_location.rb index 445b00aad..3b0b2b3c0 100644 --- a/app/models/map_location.rb +++ b/app/models/map_location.rb @@ -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? diff --git a/spec/models/map_location_spec.rb b/spec/models/map_location_spec.rb index cc54fda6f..04c323be5 100644 --- a/spec/models/map_location_spec.rb +++ b/spec/models/map_location_spec.rb @@ -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