Newer
Older
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe MessagesController do
before do
@conversation_params = {
:author => alice.person,
:participant_ids => [alice.contacts.first.person.id, alice.person.id],
:subject => 'cool stuff',
:messages_attributes => [ {:author => alice.person, :text => 'stuff'} ]
@conversation = Conversation.create!(@conversation_params)
context "with a valid message" do
before do
@message_params = {
:conversation_id => @conversation.id,
:message => { :text => "here is something else" }
}
end
it 'redirects to conversation' do
}.should change(Message, :count).by(1)
response.status.should == 302
response.should redirect_to(conversations_path(:conversation_id => @conversation))
end
end
context "with an empty message" do
before do
@message_params = {
:conversation_id => @conversation.id,
:message => { :text => " " }
}
end
it 'does not create the message' do
lambda {
post :create, @message_params
}.should_not change(Message, :count)
flash[:error].should be_present
end
end
context "on a post from a contact" do
before do
@conversation_params[:author] = bob.person
@conversation = Conversation.create!(@conversation_params)
@message_params = {
:conversation_id => @conversation.id,
:message => { :text => "here is something else" }
}
post :create, @message_params
response.status.should == 302
response.should redirect_to(conversations_path(:conversation_id => @conversation))
@message_params[:author_id] = new_user.person.id.to_s
post :create, @message_params
created_message = Message.find_by_text(@message_params[:message][:text])
created_message.author.should == alice.person
old_message = Message.create!(
:text => "hello",
:author_id => alice.person.id,
:conversation_id => @conversation.id
)
@message_params[:id] = old_message.id
post :create, @message_params
old_message.reload.text.should == 'hello'
end
end
context 'on a post from a stranger' do
before do
conversation = Conversation.create!(
:author => eve.person,
:participant_ids => [eve.person.id, bob.person.id]
)
@message_params = {
:conversation_id => conversation.id,
:message => { :text => "here is something else" }
}
it 'does not create the message' do
lambda {
post :create, @message_params
}.should_not change(Message, :count)
flash[:error].should be_present