Skip to content

Instantly share code, notes, and snippets.

@Paxa
Created June 12, 2009 19:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Paxa/128846 to your computer and use it in GitHub Desktop.
Save Paxa/128846 to your computer and use it in GitHub Desktop.
#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