added a validation of participant, as well as messages controller spec wip
This commit is contained in:
parent
21fd546cd0
commit
3812612c86
3 changed files with 18 additions and 0 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue