always pass desired format in specs unless it's html

This commit is contained in:
Jonne Haß 2013-09-21 15:58:25 +02:00
parent 645a427798
commit 21feb91d27
4 changed files with 23 additions and 18 deletions

View file

@ -139,12 +139,12 @@ describe CommentsController do
it 'returns all the comments for a post' do it 'returns all the comments for a post' do
comments = [alice, bob, eve].map{ |u| u.comment!(@message, "hey") } comments = [alice, bob, eve].map{ |u| u.comment!(@message, "hey") }
get :index, :post_id => @message.id, :format => 'js' get :index, :post_id => @message.id, :format => :json
assigns[:comments].map(&:id).should =~ comments.map(&:id) assigns[:comments].map(&:id).should =~ comments.map(&:id)
end end
it 'returns a 404 on a nonexistent post' do it 'returns a 404 on a nonexistent post' do
get :index, :post_id => 235236, :format => 'js' get :index, :post_id => 235236, :format => :json
response.status.should == 404 response.status.should == 404
end end

View file

@ -53,20 +53,20 @@ describe ConversationsController do
} }
@conversations = Array.new(3) { Conversation.create(hash) } @conversations = Array.new(3) { Conversation.create(hash) }
end end
it 'succeeds' do it 'succeeds' do
get :index get :index
response.should be_success response.should be_success
assigns[:conversations].should =~ @conversations assigns[:conversations].should =~ @conversations
end end
it 'succeeds with json' do it 'succeeds with json' do
get :index, :format => :json get :index, :format => :json
response.should be_success response.should be_success
json = JSON.parse(response.body) json = JSON.parse(response.body)
json.first['conversation'].should be_present json.first['conversation'].should be_present
end end
it 'retrieves all conversations for a user' do it 'retrieves all conversations for a user' do
get :index get :index
assigns[:conversations].count.should == 3 assigns[:conversations].count.should == 3
@ -77,6 +77,7 @@ describe ConversationsController do
context 'with a valid conversation' do context 'with a valid conversation' do
before do before do
@hash = { @hash = {
:format => :js,
:conversation => { :conversation => {
:subject => "secret stuff", :subject => "secret stuff",
:text => 'text debug' :text => 'text debug'
@ -131,6 +132,7 @@ describe ConversationsController do
context 'with empty subject' do context 'with empty subject' do
before do before do
@hash = { @hash = {
:format => :js,
:conversation => { :conversation => {
:subject => ' ', :subject => ' ',
:text => 'text debug' :text => 'text debug'
@ -162,6 +164,7 @@ describe ConversationsController do
context 'with empty text' do context 'with empty text' do
before do before do
@hash = { @hash = {
:format => :js,
:conversation => { :conversation => {
:subject => 'secret stuff', :subject => 'secret stuff',
:text => ' ' :text => ' '
@ -192,6 +195,7 @@ describe ConversationsController do
context 'with empty contact' do context 'with empty contact' do
before do before do
@hash = { @hash = {
:format => :js,
:conversation => { :conversation => {
:subject => 'secret stuff', :subject => 'secret stuff',
:text => 'text debug' :text => 'text debug'
@ -222,6 +226,7 @@ describe ConversationsController do
context 'with nil contact' do context 'with nil contact' do
before do before do
@hash = { @hash = {
:format => :js,
:conversation => { :conversation => {
:subject => 'secret stuff', :subject => 'secret stuff',
:text => 'text debug' :text => 'text debug'
@ -254,13 +259,13 @@ describe ConversationsController do
} }
@conversation = Conversation.create(hash) @conversation = Conversation.create(hash)
end end
it 'succeeds with js' do it 'succeeds with js' do
get :show, :id => @conversation.id, :format => :js get :show, :id => @conversation.id, :format => :js
response.should be_success response.should be_success
assigns[:conversation].should == @conversation assigns[:conversation].should == @conversation
end end
it 'succeeds with json' do it 'succeeds with json' do
get :show, :id => @conversation.id, :format => :json get :show, :id => @conversation.id, :format => :json
response.should be_success response.should be_success
@ -273,7 +278,7 @@ describe ConversationsController do
response.should redirect_to(conversations_path(:conversation_id => @conversation.id)) response.should redirect_to(conversations_path(:conversation_id => @conversation.id))
assigns[:conversation].should == @conversation assigns[:conversation].should == @conversation
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
sign_in :user, eve sign_in :user, eve

View file

@ -14,20 +14,20 @@ describe NotificationsController do
note = mock_model( Notification ) note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] ) Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( true ) note.should_receive( :set_read_state ).with( true )
get :update, "id" => note.id get :update, "id" => note.id, :format => :json
end end
it 'marks a notification as read if it is told to' do it 'marks a notification as read if it is told to' do
note = mock_model( Notification ) note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] ) Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( true ) note.should_receive( :set_read_state ).with( true )
get :update, "id" => note.id, :set_unread => "false" get :update, "id" => note.id, :set_unread => "false", :format => :json
end end
it 'marks a notification as unread if it is told to' do it 'marks a notification as unread if it is told to' do
note = mock_model( Notification ) note = mock_model( Notification )
Notification.should_receive( :where ).and_return( [note] ) Notification.should_receive( :where ).and_return( [note] )
note.should_receive( :set_read_state ).with( false ) note.should_receive( :set_read_state ).with( false )
get :update, "id" => note.id, :set_unread => "true" get :update, "id" => note.id, :set_unread => "true", :format => :json
end end
it 'only lets you read your own notifications' do it 'only lets you read your own notifications' do
@ -36,7 +36,7 @@ describe NotificationsController do
FactoryGirl.create(:notification, :recipient => alice) FactoryGirl.create(:notification, :recipient => alice)
note = FactoryGirl.create(:notification, :recipient => user2) note = FactoryGirl.create(:notification, :recipient => user2)
get :update, "id" => note.id, :set_unread => "false" get :update, "id" => note.id, :set_unread => "false", :format => :json
Notification.find(note.id).unread.should == true Notification.find(note.id).unread.should == true
end end
@ -64,7 +64,7 @@ describe NotificationsController do
get :index, :format => :mobile get :index, :format => :mobile
response.should be_success response.should be_success
end end
it 'paginates the notifications' do it 'paginates the notifications' do
25.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } 25.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
get :index get :index
@ -76,7 +76,7 @@ describe NotificationsController do
it "supports a limit per_page parameter" do it "supports a limit per_page parameter" do
5.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) } 5.times { FactoryGirl.create(:notification, :recipient => alice, :target => @post) }
get :index, "per_page" => 5 get :index, "per_page" => 5
assigns[:notifications].count.should == 5 assigns[:notifications].count.should == 5
end end
describe "special case for start sharing notifications" do describe "special case for start sharing notifications" do

View file

@ -130,7 +130,7 @@ describe PhotosController do
end end
it 'will let you delete your profile picture' do it 'will let you delete your profile picture' do
get :make_profile_photo, :photo_id => @alices_photo.id get :make_profile_photo, :photo_id => @alices_photo.id, :format => :js
delete :destroy, :id => @alices_photo.id delete :destroy, :id => @alices_photo.id
Photo.find_by_id(@alices_photo.id).should be_nil Photo.find_by_id(@alices_photo.id).should be_nil
end end
@ -155,21 +155,21 @@ describe PhotosController do
describe "#update" do describe "#update" do
it "updates the caption of a photo" do it "updates the caption of a photo" do
put :update, :id => @alices_photo.id, :photo => { :text => "now with lasers!" } put :update, :id => @alices_photo.id, :photo => { :text => "now with lasers!" }, :format => :js
@alices_photo.reload.text.should == "now with lasers!" @alices_photo.reload.text.should == "now with lasers!"
end end
it "doesn't allow mass assignment of person" do it "doesn't allow mass assignment of person" do
new_user = FactoryGirl.create(:user) new_user = FactoryGirl.create(:user)
params = { :text => "now with lasers!", :author => new_user } params = { :text => "now with lasers!", :author => new_user }
put :update, :id => @alices_photo.id, :photo => params put :update, :id => @alices_photo.id, :photo => params, :format => :js
@alices_photo.reload.author.should == alice.person @alices_photo.reload.author.should == alice.person
end end
it "doesn't allow mass assignment of person_id" do it "doesn't allow mass assignment of person_id" do
new_user = FactoryGirl.create(:user) new_user = FactoryGirl.create(:user)
params = { :text => "now with lasers!", :author_id => new_user.id } params = { :text => "now with lasers!", :author_id => new_user.id }
put :update, :id => @alices_photo.id, :photo => params put :update, :id => @alices_photo.id, :photo => params, :format => :js
@alices_photo.reload.author_id.should == alice.person.id @alices_photo.reload.author_id.should == alice.person.id
end end