Skip to content

Commit

Permalink
Show error and flash-notice when sending messages to non contacts
Browse files Browse the repository at this point in the history
  • Loading branch information
movilla committed Dec 26, 2012
1 parent dd8660b commit 597ab20
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -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

Expand Down
5 changes: 4 additions & 1 deletion app/controllers/conversations_controller.rb
Expand Up @@ -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])
Expand Down
1 change: 1 addition & 0 deletions config/locales/diaspora/en.yml
Expand Up @@ -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:
Expand Down
48 changes: 48 additions & 0 deletions spec/controllers/conversations_controller_spec.rb
Expand Up @@ -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 = {
Expand All @@ -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
Expand Down

0 comments on commit 597ab20

Please sign in to comment.