Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Show error and flash-notice when sending messages to non contacts

  • Loading branch information...
commit 597ab2071569e84ef68668a3a9d2fc18cf59bd0f 1 parent dd8660b
@movilla movilla authored
View
1  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
View
5 app/controllers/conversations_controller.rb
@@ -37,11 +37,14 @@ def create
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])
View
1  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:
View
48 spec/controllers/conversations_controller_spec.rb
@@ -113,6 +113,30 @@
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 @@
}.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
Please sign in to comment.
Something went wrong with that request. Please try again.