Merge pull request #452 from wsmoak/negative-area

Prevent the creation of a garden with a negative number for the area.
This commit is contained in:
Skud
2014-11-19 17:18:09 +11:00
3 changed files with 15 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

@@ -35,6 +35,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"

View File

@@ -102,6 +102,11 @@ describe Garden do
@garden.should be_valid
end
it "doesn't allow negative area" do
@garden = FactoryGirl.build(:garden, :area => -5)
@garden.should_not be_valid
end
it 'allows decimal quantities' do
@garden = FactoryGirl.build(:garden, :area => 3.3)
@garden.should be_valid