diff --git a/Changelog.md b/Changelog.md index 8b8101347..53735b606 100644 --- a/Changelog.md +++ b/Changelog.md @@ -19,6 +19,7 @@ * Add flash warning to conversation mobile, unification of flash warning with login and register mobile, and add support for flash warning to Opera browser. [#3686](https://github.com/diaspora/diaspora/pull/3686) * Add progress percentage to upload images. [#3740](https://github.com/diaspora/diaspora/pull/3740) * Mark all unread post-related notifications as read, if one of this gets opened. [#3787](https://github.com/diaspora/diaspora/pull/3787) +* Add flash-notice when sending messages to non-contacts. [#3723](https://github.com/diaspora/diaspora/pull/3723) ## Bug Fixes diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index c4eae4a5d..acf91a70e 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -37,11 +37,14 @@ class ConversationsController < ApplicationController params[:conversation][:messages_attributes] = [ {:author => current_user.person, :text => message_text }] @conversation = Conversation.new(params[:conversation]) - if @conversation.save + if person_ids.present? && @conversation.save Postzord::Dispatcher.build(current_user, @conversation).post flash[:notice] = I18n.t('conversations.create.sent') else flash[:error] = I18n.t('conversations.create.fail') + if person_ids.blank? + flash[:error] = I18n.t('conversations.create.no_contact') + end end if params[:profile] redirect_to person_path(params[:profile]) diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 431a83c7e..d63e1ec40 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -345,6 +345,7 @@ en: create: sent: "Message sent" fail: "Invalid message" + no_contact: "Hey, you need to add the contact first!" new_message: fail: "Invalid message" destroy: diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index ef4cdd86a..a0963bcf8 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -113,6 +113,30 @@ describe ConversationsController do end end + context 'with empty subject' do + before do + @hash = { + :conversation => { + :subject => ' ', + :text => 'text debug' + }, + :contact_ids => [alice.contacts.first.id] + } + end + + it 'creates a conversation' do + lambda { + post :create, @hash + }.should change(Conversation, :count).by(1) + end + + it 'creates a message' do + lambda { + post :create, @hash + }.should change(Message, :count).by(1) + end + end + context 'with empty text' do before do @hash = { @@ -136,6 +160,30 @@ describe ConversationsController do }.should_not change(Message, :count).by(1) end end + + context 'with empty contact' do + before do + @hash = { + :conversation => { + :subject => 'secret stuff', + :text => 'text debug' + }, + :contact_ids => ' ' + } + 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