validate instead of throwing a db error
This commit is contained in:
parent
f51b71b7db
commit
aa3d626ada
2 changed files with 9 additions and 0 deletions
|
|
@ -29,6 +29,8 @@ class Post < ActiveRecord::Base
|
||||||
|
|
||||||
belongs_to :author, :class_name => 'Person'
|
belongs_to :author, :class_name => 'Person'
|
||||||
|
|
||||||
|
validates_uniqueness_of :guid
|
||||||
|
|
||||||
def diaspora_handle
|
def diaspora_handle
|
||||||
read_attribute(:diaspora_handle) || self.author.diaspora_handle
|
read_attribute(:diaspora_handle) || self.author.diaspora_handle
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,13 @@ describe Post do
|
||||||
@aspect = @user.aspects.create(:name => "winners")
|
@aspect = @user.aspects.create(:name => "winners")
|
||||||
end
|
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
|
describe 'deletion' do
|
||||||
it 'should delete a posts comments on delete' do
|
it 'should delete a posts comments on delete' do
|
||||||
post = Factory.create(:status_message, :author => @user.person)
|
post = Factory.create(:status_message, :author => @user.person)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue