Check for nil before splitting contact_ids param.
This commit is contained in:
parent
ed36786edc
commit
b3c859bcd5
2 changed files with 30 additions and 2 deletions
|
|
@ -29,8 +29,9 @@ class ConversationsController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
person_ids = Contact.where(:id => params[:contact_ids].split(',')).map! do |contact|
|
||||
contact.person_id
|
||||
# Can't split nil
|
||||
if params[:contact_ids]
|
||||
person_ids = Contact.where(:id => params[:contact_ids].split(',')).map(&:person_id)
|
||||
end
|
||||
|
||||
params[:conversation][:participant_ids] = person_ids | [current_user.person_id]
|
||||
|
|
|
|||
|
|
@ -192,6 +192,33 @@ describe ConversationsController do
|
|||
}.should_not change(Message, :count).by(1)
|
||||
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
|
||||
|
||||
describe '#show' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue