Validate MapLocation lat/long/zoom have numeric values
This commit is contained in:
@@ -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?
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user