Merge pull request #4229 from davexunit/4227-private-message-error

Check for nil before splitting contact_ids param in ConversationsController
This commit is contained in:
Jonne Haß 2013-06-17 15:29:53 +02:00
commit c9e981096c
3 changed files with 31 additions and 2 deletions

View file

@ -25,6 +25,7 @@
* Fix dynamic loading of asset_sync * Fix dynamic loading of asset_sync
* Fix login for short passwords [#4123](https://github.com/diaspora/diaspora/issues/4123) * Fix login for short passwords [#4123](https://github.com/diaspora/diaspora/issues/4123)
* Add loading indicator on tag pages, remove the second one from the profile page [#4041](https://github.com/diaspora/diaspora/issues/4041) * Add loading indicator on tag pages, remove the second one from the profile page [#4041](https://github.com/diaspora/diaspora/issues/4041)
* Leaving the `to` field blank when sending a private message causes a server error [#4227](https://github.com/diaspora/diaspora/issues/4227)
## Features ## Features

View file

@ -29,8 +29,9 @@ class ConversationsController < ApplicationController
end end
def create def create
person_ids = Contact.where(:id => params[:contact_ids].split(',')).map! do |contact| # Can't split nil
contact.person_id if params[:contact_ids]
person_ids = Contact.where(:id => params[:contact_ids].split(',')).map(&:person_id)
end end
params[:conversation][:participant_ids] = person_ids | [current_user.person_id] params[:conversation][:participant_ids] = person_ids | [current_user.person_id]

View file

@ -192,6 +192,33 @@ describe ConversationsController do
}.should_not change(Message, :count).by(1) }.should_not change(Message, :count).by(1)
end end
end end
context 'with nil contact' do
before do
@hash = {
:conversation => {
:subject => 'secret stuff',
:text => 'text debug'
},
:contact_ids => nil
}
Conversation.stub(:new).and_return(double(Conversation,
:save => false,
:id => 1))
end
it 'does not create a conversation' do
lambda {
post :create, @hash
}.should_not change(Conversation, :count).by(1)
end
it 'does not create a message' do
lambda {
post :create, @hash
}.should_not change(Message, :count).by(1)
end
end
end end
describe '#show' do describe '#show' do