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
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)
end
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
end

View file

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

View file

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

View file

@ -130,7 +130,7 @@ describe PhotosController do
end
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
Photo.find_by_id(@alices_photo.id).should be_nil
end
@ -155,21 +155,21 @@ describe PhotosController do
describe "#update" 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!"
end
it "doesn't allow mass assignment of person" do
new_user = FactoryGirl.create(: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
end
it "doesn't allow mass assignment of person_id" do
new_user = FactoryGirl.create(:user)
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
end