added a validation of participant, as well as messages controller spec wip

This commit is contained in:
zhitomirskiyi 2011-03-01 19:24:07 -08:00
parent 21fd546cd0
commit 3812612c86
3 changed files with 18 additions and 0 deletions

View file

@ -25,6 +25,8 @@ class Message < ActiveRecord::Base
self
end
validate :participant_of_parent_conversation
def diaspora_handle
self.author.diaspora_handle
end
@ -54,4 +56,13 @@ class Message < ActiveRecord::Base
def parent= parent
self.conversation = parent
end
private
def participant_of_parent_conversation
if self.parent && !self.parent.participants.include?(self.author)
errors[:base] << "Author is not participating in the conversation"
else
true
end
end
end

View file

@ -26,7 +26,9 @@ Diaspora::Application.routes.draw do
resources :contacts
resources :aspect_memberships, :only => [:destroy, :create]
resources :conversations do
resources :messages, :only => [:create, :show]
resource :conversation_visibility, :only => [:destroy], :path => '/visibility/'
end

View file

@ -18,6 +18,11 @@ describe Message do
@xml = @message.to_diaspora_xml
end
it 'validates that the author is a participant in the conversation' do
msg = Message.new(:text => 'yo', :author => eve.person, :conversation_id => @cnv.id)
pp msg.valid?
end
describe '#before_create' do
it 'signs the message' do
@message.author_signature.should_not be_blank