mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-01 04:15:11 -04:00
Added validation for garden names.
This commit is contained in:
@@ -7,10 +7,15 @@ class Garden < ActiveRecord::Base
|
||||
has_many :plantings, :order => 'created_at DESC', :dependent => :destroy
|
||||
has_many :crops, :through => :plantings
|
||||
|
||||
before_create :replace_blank_name
|
||||
# before_create :replace_blank_name
|
||||
|
||||
default_scope order("lower(name) asc")
|
||||
|
||||
validates :name,
|
||||
:format => {
|
||||
:with => /\S/
|
||||
}
|
||||
|
||||
def garden_slug
|
||||
"#{owner.login_name}-#{name}".downcase.gsub(' ', '-')
|
||||
end
|
||||
|
||||
@@ -14,9 +14,19 @@ describe Garden do
|
||||
@garden.description.should == "This is a **totally** cool garden"
|
||||
end
|
||||
|
||||
it "should have a name" do
|
||||
@no_name_garden = FactoryGirl.create(:garden, :name => nil, :description => "New Garden")
|
||||
@no_name_garden.name.should_not be_blank
|
||||
it "doesn't allow a nil name" do
|
||||
@garden = FactoryGirl.build(:garden, :name => nil)
|
||||
@garden.should_not be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a blank name" do
|
||||
@garden = FactoryGirl.build(:garden, :name => "")
|
||||
@garden.should_not be_valid
|
||||
end
|
||||
|
||||
it "doesn't allow a name with only spaces" do
|
||||
@garden = FactoryGirl.build(:garden, :name => " ")
|
||||
@garden.should_not be_valid
|
||||
end
|
||||
|
||||
it "should have an owner" do
|
||||
@@ -86,14 +96,4 @@ describe Garden do
|
||||
Planting.count.should == all - 2
|
||||
end
|
||||
|
||||
it "replaces missing name with (no name)" do
|
||||
@no_name_garden = FactoryGirl.create(:garden, :name => nil)
|
||||
@no_name_garden.name.should == "(no name)"
|
||||
end
|
||||
|
||||
it "replaces whitespace-only names with (no name)" do
|
||||
@no_name_garden = FactoryGirl.create(:garden, :name => " ")
|
||||
@no_name_garden.name.should == "(no name)"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user