validate instead of throwing a db error

This commit is contained in:
danielgrippi 2011-08-10 10:38:10 -07:00
parent f51b71b7db
commit aa3d626ada
2 changed files with 9 additions and 0 deletions

View file

@ -29,6 +29,8 @@ class Post < ActiveRecord::Base
belongs_to :author, :class_name => 'Person'
validates_uniqueness_of :guid
def diaspora_handle
read_attribute(:diaspora_handle) || self.author.diaspora_handle
end

View file

@ -10,6 +10,13 @@ describe Post do
@aspect = @user.aspects.create(:name => "winners")
end
describe 'validations' do
it 'validates uniqueness of guid and does not throw a db error' do
message = Factory(:status_message)
Factory.build(:status_message, :guid => message.guid).should_not be_valid
end
end
describe 'deletion' do
it 'should delete a posts comments on delete' do
post = Factory.create(:status_message, :author => @user.person)