From 89179ecbd3158efbb44ea7f871ae7ad057021059 Mon Sep 17 00:00:00 2001 From: Diaspora Europe Date: Fri, 24 Feb 2012 09:39:40 +0100 Subject: [PATCH 1/2] conversations should return JSON #2833 --- app/controllers/conversations_controller.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/controllers/conversations_controller.rb b/app/controllers/conversations_controller.rb index ecfa5076e..adcfc5bf7 100644 --- a/app/controllers/conversations_controller.rb +++ b/app/controllers/conversations_controller.rb @@ -19,6 +19,11 @@ class ConversationsController < ApplicationController @conversation = Conversation.joins(:conversation_visibilities).where( :conversation_visibilities => {:person_id => current_user.person.id, :conversation_id => params[:conversation_id]}).first + + respond_with do |format| + format.html + format.json { render :json => @conversations, :status => 200 } + end end def create @@ -56,6 +61,7 @@ class ConversationsController < ApplicationController respond_to do |format| format.html { redirect_to conversations_path(:conversation_id => @conversation.id) } format.js + format.json { render :json => @conversation, :status => 200 } end else redirect_to conversations_path From 57de352238f9b5273ab3c78e898aff715755eacd Mon Sep 17 00:00:00 2001 From: Diaspora Europe Date: Fri, 24 Feb 2012 10:22:16 +0100 Subject: [PATCH 2/2] added some specs for json response --- .../conversations_controller_spec.rb | 34 ++++++++++++++----- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/spec/controllers/conversations_controller_spec.rb b/spec/controllers/conversations_controller_spec.rb index 7d3bed8d9..50c1ceaa4 100644 --- a/spec/controllers/conversations_controller_spec.rb +++ b/spec/controllers/conversations_controller_spec.rb @@ -34,20 +34,29 @@ describe ConversationsController do end describe '#index' do - it 'succeeds' do - get :index - response.should be_success - end - - it 'retrieves all conversations for a user' do + before do hash = { :author => alice.person, :participant_ids => [alice.contacts.first.person.id, alice.person.id], :subject => 'not spam', :messages_attributes => [ {:author => alice.person, :text => 'cool stuff'} ] } - 3.times { Conversation.create(hash) } - + @conversations = Array.new(3) { Conversation.create(hash) } + end + + it 'succeeds' do + get :index + response.should be_success + assigns[:conversations].should == @conversations + end + + it 'succeeds with json' do + get :index, :format => :json + response.should be_success + response.body.should == @conversations.to_json + end + + it 'retrieves all conversations for a user' do get :index assigns[:conversations].count.should == 3 end @@ -137,11 +146,18 @@ describe ConversationsController do @conversation = Conversation.create(hash) end - it 'succeeds' do + it 'succeeds with js' do get :show, :id => @conversation.id, :format => :js response.should be_success assigns[:conversation].should == @conversation end + + it 'succeeds with json' do + get :show, :id => @conversation.id, :format => :json + response.should be_success + assigns[:conversation].should == @conversation + response.body.should == @conversation.to_json + end it 'redirects to index' do get :show, :id => @conversation.id