Skip to content

Commit

Permalink
validate presence of name
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesgolick committed Dec 9, 2008
1 parent faaaf1f commit 1386a9e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/tag.rb
@@ -1,5 +1,6 @@
class Tag < ActiveRecord::Base
has_many :taggings

validates_presence_of :name
validates_uniqueness_of :name
end
7 changes: 7 additions & 0 deletions test/tag_test.rb
Expand Up @@ -8,4 +8,11 @@
expect Tag.new(:name => "duplicate").not.to.be.valid? do
Tag.create!(:name => "duplicate")
end

expect Tag.new.not.to.be.valid?
expect String do
t = Tag.new
t.valid?
t.errors[:name]
end
end

0 comments on commit 1386a9e

Please sign in to comment.