Created
June 12, 2009 19:07
-
-
Save Paxa/128846 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#model | |
class Comment < ActiveRecord::Base | |
belongs_to :podcast | |
validates_presence_of :content | |
validates_presence_of :author_name | |
validates_presence_of :podcast_id | |
validates_length_of :author_name, :within => 2..40 | |
validates_length_of :author_url, :within => 5..200, :allow_blank => true | |
validates_format_of :author_url, :with => /^[^\"\'\\]*$/, | |
:message => "can't include backslash or bracket" | |
end | |
#spec | |
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper') | |
describe Comment do | |
it { should validate_presence_of(:content) } | |
it { should validate_presence_of(:author_name) } | |
it { should validate_presence_of(:podcast_id) } | |
it { should ensure_length_of(:author_name).is_at_least(2).is_at_most(40) } | |
it { should ensure_length_of(:author_url).is_at_least(5).is_at_most(200) } | |
it { should belong_to :podcast } | |
it { should allow_value(nil).for(:author_url) } | |
it "should not allow back slash in author url" do | |
should_not allow_value("http://example.com\\").for(:author_url) | |
end | |
it "should allow usual url" do | |
should allow_value("http://example.com").for(:author_url) | |
end | |
it "should not allow brackets in author url" do | |
should_not allow_value("http://example.com\"").for(:author_url) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment