Skip to content
Extraits de code Groupes Projets
Valider c3b9da8d rédigé par Sarah Mei's avatar Sarah Mei
Parcourir les fichiers

Add specs to conversations#new. Unpending spec for create.

parent 8d7aa182
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -5,20 +5,20 @@ class ConversationsController < ApplicationController ...@@ -5,20 +5,20 @@ class ConversationsController < ApplicationController
def index def index
@conversations = Conversation.joins(:conversation_visibilities).where( @conversations = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person.id}).paginate( :conversation_visibilities => {:person_id => current_user.person.id}).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC') :page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@visibilities = ConversationVisibility.where( :person_id => current_user.person.id ).paginate( @visibilities = ConversationVisibility.where(:person_id => current_user.person.id).paginate(
:page => params[:page], :per_page => 15, :order => 'updated_at DESC') :page => params[:page], :per_page => 15, :order => 'updated_at DESC')
@unread_counts = {} @unread_counts = {}
@visibilities.each{|v| @unread_counts[v.conversation_id] = v.unread} @visibilities.each { |v| @unread_counts[v.conversation_id] = v.unread }
@authors = {} @authors = {}
@conversations.each{|c| @authors[c.id] = c.last_author} @conversations.each { |c| @authors[c.id] = c.last_author }
@conversation = Conversation.joins(:conversation_visibilities).where( @conversation = Conversation.joins(:conversation_visibilities).where(
:conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first :conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first
end end
def create def create
...@@ -43,7 +43,7 @@ class ConversationsController < ApplicationController ...@@ -43,7 +43,7 @@ class ConversationsController < ApplicationController
def show def show
@conversation = Conversation.joins(:conversation_visibilities).where(:id => params[:id], @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
...@@ -58,7 +58,7 @@ class ConversationsController < ApplicationController ...@@ -58,7 +58,7 @@ class ConversationsController < ApplicationController
end end
def new def new
@all_contacts_and_ids = current_user.contacts.map{|c| {:value => c.id, :name => c.person.name}} @all_contacts_and_ids = current_user.contacts.map { |c| {:value => c.id, :name => c.person.name} }
@contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id] @contact = current_user.contacts.find(params[:contact_id]) if params[:contact_id]
render :layout => false render :layout => false
end end
......
...@@ -4,15 +4,24 @@ describe ConversationsController do ...@@ -4,15 +4,24 @@ describe ConversationsController do
render_views render_views
before do before do
@user1 = alice @alice = alice
sign_in :user, @user1 sign_in :user, @alice
end end
describe '#new' do describe '#new' do
it 'succeeds' do before do
get :new get :new
end
it 'succeeds' do
response.should be_success response.should be_success
end end
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}}
end
it "assigns a contact if passed a contact id" do
get :new, :contact_id => @alice.contacts.first.id
assigns(:contact).should == @alice.contacts.first
end
end end
describe '#index' do describe '#index' do
...@@ -22,12 +31,9 @@ describe ConversationsController do ...@@ -22,12 +31,9 @@ describe ConversationsController do
end end
it 'retrieves all conversations for a user' do it 'retrieves all conversations for a user' do
hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.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 do
cnv = Conversation.create(hash)
end
get :index get :index
assigns[:conversations].count.should == 3 assigns[:conversations].count.should == 3
...@@ -36,10 +42,12 @@ describe ConversationsController do ...@@ -36,10 +42,12 @@ describe ConversationsController do
describe '#create' do describe '#create' do
before do before do
@hash = {:conversation => { @hash = {
:subject => "secret stuff", :conversation => {
:text => 'text'}, :subject => "secret stuff",
:contact_ids => '@user1.contacts.first.id'} :text => 'text'},
:contact_ids => [@alice.contacts.first.id]
}
end end
it 'creates a conversation' do it 'creates a conversation' do
...@@ -55,19 +63,17 @@ describe ConversationsController do ...@@ -55,19 +63,17 @@ describe ConversationsController do
end end
it 'sets the author to the current_user' do it 'sets the author to the current_user' do
pending
@hash[:author] = Factory.create(:user) @hash[:author] = Factory.create(:user)
post :create, @hash post :create, @hash
Message.first.author.should == @user1.person Message.first.author.should == @alice.person
Conversation.first.author.should == @user1.person Conversation.first.author.should == @alice.person
end end
it 'dispatches the conversation' do it 'dispatches the conversation' do
cnv = Conversation.create(@hash[:conversation].merge({ cnv = Conversation.create(
:author => @user1.person, @hash[:conversation].merge({:author => @alice.person, :participant_ids => [@alice.contacts.first.person.id]}))
:participant_ids => [@user1.contacts.first.person.id]}))
p = Postzord::Dispatch.new(@user1, 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
...@@ -76,8 +82,8 @@ describe ConversationsController do ...@@ -76,8 +82,8 @@ describe ConversationsController do
describe '#show' do describe '#show' do
before do before do
hash = { :author => @user1.person, :participant_ids => [@user1.contacts.first.person.id, @user1.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
......
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