Prevent the creation of a garden with a negative number for the area. If entered, the area must be greater than or equal to zero.

This commit is contained in:
Wendy Smoak
2014-11-18 20:33:44 -05:00
parent 126cb1d191
commit 53d782bc83
2 changed files with 10 additions and 1 deletions

View File

@@ -26,7 +26,7 @@ class Garden < ActiveRecord::Base
}
validates :area,
:numericality => { :only_integer => false },
:numericality => { :only_integer => false, :greater_than_or_equal_to => 0 },
:allow_nil => true
AREA_UNITS_VALUES = {

View File

@@ -33,6 +33,15 @@ feature "Planting a crop", :js => true do
expect(page).to have_content "New garden"
end
scenario "Refuse to create new garden with negative area" do
visit new_garden_path
fill_in "Name", :with => "Negative Garden"
fill_in "Area", :with => -5
click_button "Save"
expect(page).not_to have_content "Garden was successfully created"
expect(page).to have_content "Area must be greater than or equal to 0"
end
scenario "Edit garden" do
visit new_garden_path
fill_in "Name", :with => "New garden"