Skip to content
Extraits de code Groupes Projets
Valider 3387c20b rédigé par Raphael Sofaer's avatar Raphael Sofaer
Parcourir les fichiers

Fix redirect away from conversation

parent 1df287b2
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -42,14 +42,17 @@ class ConversationsController < ApplicationController ...@@ -42,14 +42,17 @@ class ConversationsController < ApplicationController
end end
def show def show
@conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id], if @conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id],
:conversation_visibilities => {:person_id => current_user.person.id}).first :conversation_visibilities => {:person_id => current_user.person.id}).first
if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first if @visibility = ConversationVisibility.where(:conversation_id => params[:id], :person_id => current_user.person.id).first
@visibility.unread = 0 @visibility.unread = 0
@visibility.save @visibility.save
end end
respond_with @conversation respond_with @conversation
else
redirect_to conversations_path
end
end end
def new def new
......
...@@ -4,8 +4,7 @@ describe ConversationsController do ...@@ -4,8 +4,7 @@ describe ConversationsController do
render_views render_views
before do before do
@alice = alice sign_in :user, alice
sign_in :user, @alice
end end
describe '#new' do describe '#new' do
...@@ -16,11 +15,11 @@ describe ConversationsController do ...@@ -16,11 +15,11 @@ describe ConversationsController do
response.should be_success response.should be_success
end end
it "assigns a list of the user's contacts" do it "assigns a list of the user's contacts" do
assigns(:all_contacts_and_ids).should == @alice.contacts.collect{|c| {"value" => c.id, "name" => c.person.name}} assigns(:all_contacts_and_ids).should == alice.contacts.collect{|c| {"value" => c.id, "name" => c.person.name}}
end end
it "assigns a contact if passed a contact id" do it "assigns a contact if passed a contact id" do
get :new, :contact_id => @alice.contacts.first.id get :new, :contact_id => alice.contacts.first.id
assigns(:contact).should == @alice.contacts.first assigns(:contact).should == alice.contacts.first
end end
end end
...@@ -31,7 +30,7 @@ describe ConversationsController do ...@@ -31,7 +30,7 @@ describe ConversationsController do
end end
it 'retrieves all conversations for a user' do it 'retrieves all conversations for a user' do
hash = {:author => @alice.person, :participant_ids => [@alice.contacts.first.person.id, @alice.person.id], hash = {:author => alice.person, :participant_ids => [alice.contacts.first.person.id, alice.person.id],
:subject => 'not spam', :text => 'cool stuff'} :subject => 'not spam', :text => 'cool stuff'}
3.times { Conversation.create(hash) } 3.times { Conversation.create(hash) }
...@@ -46,7 +45,7 @@ describe ConversationsController do ...@@ -46,7 +45,7 @@ describe ConversationsController do
:conversation => { :conversation => {
:subject => "secret stuff", :subject => "secret stuff",
:text => 'text'}, :text => 'text'},
:contact_ids => [@alice.contacts.first.id] :contact_ids => [alice.contacts.first.id]
} }
end end
...@@ -65,15 +64,15 @@ describe ConversationsController do ...@@ -65,15 +64,15 @@ describe ConversationsController do
it 'sets the author to the current_user' do it 'sets the author to the current_user' do
@hash[:author] = Factory.create(:user) @hash[:author] = Factory.create(:user)
post :create, @hash post :create, @hash
Message.first.author.should == @alice.person Message.first.author.should == alice.person
Conversation.first.author.should == @alice.person Conversation.first.author.should == alice.person
end end
it 'dispatches the conversation' do it 'dispatches the conversation' do
cnv = Conversation.create( cnv = Conversation.create(
@hash[:conversation].merge({:author => @alice.person, :participant_ids => [@alice.contacts.first.person.id]})) @hash[:conversation].merge({:author => alice.person, :participant_ids => [alice.contacts.first.person.id]}))
p = Postzord::Dispatch.new(@alice, cnv) p = Postzord::Dispatch.new(alice, cnv)
Postzord::Dispatch.stub!(:new).and_return(p) Postzord::Dispatch.stub!(:new).and_return(p)
p.should_receive(:post) p.should_receive(:post)
post :create, @hash post :create, @hash
...@@ -82,7 +81,7 @@ describe ConversationsController do ...@@ -82,7 +81,7 @@ describe ConversationsController do
describe '#show' do describe '#show' do
before do before do
hash = {:author => @alice.person, :participant_ids => [@alice.contacts.first.person.id, @alice.person.id], hash = {:author => alice.person, :participant_ids => [alice.contacts.first.person.id, alice.person.id],
:subject => 'not spam', :text => 'cool stuff'} :subject => 'not spam', :text => 'cool stuff'}
@conversation = Conversation.create(hash) @conversation = Conversation.create(hash)
end end
...@@ -94,8 +93,7 @@ describe ConversationsController do ...@@ -94,8 +93,7 @@ describe ConversationsController do
end end
it 'does not let you access conversations where you are not a recipient' do it 'does not let you access conversations where you are not a recipient' do
user2 = eve sign_in :user, eve
sign_in :user, user2
get :show, :id => @conversation.id get :show, :id => @conversation.id
response.code.should == '302' response.code.should == '302'
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter