mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-14 03:05:59 -04:00
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:
@@ -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 = {
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user