Return 406 on people/guid/contacts, format json

This commit is contained in:
Steffen van Bergerem 2015-04-04 03:46:27 +02:00
parent 4b841ef076
commit a6b9c6c057
2 changed files with 28 additions and 17 deletions

View file

@ -135,6 +135,10 @@ class PeopleController < ApplicationController
end
def contacts
respond_to do |format|
format.json { render nothing: true, status: 406 }
format.any do
@person = Person.find_by_guid(params[:person_id])
if @person
@ -147,14 +151,16 @@ class PeopleController < ApplicationController
gon.preloads[:contacts] = {
count: @contacts_of_contact.count(:all),
}
@contacts_of_contact = @contacts_of_contact.paginate(:page => params[:page], :per_page => (params[:limit] || 15))
@contacts_of_contact = @contacts_of_contact.paginate(page: params[:page], per_page: (params[:limit] || 15))
@hashes = hashes_for_people @contacts_of_contact, @aspects
respond_with @person, layout: "with_header"
else
flash[:error] = I18n.t 'people.show.does_not_exist'
flash[:error] = I18n.t "people.show.does_not_exist"
redirect_to people_path
end
end
end
end
# shows the dropdown list of aspects the current user has set for the given person.
# renders "thats you" in case the current user views himself

View file

@ -497,6 +497,11 @@ describe PeopleController, :type => :controller do
get :contacts, :person_id => eve.person.to_param
expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice
end
it "returns a 406 for json format" do
get :contacts, person_id: "foo", format: :json
expect(response.code).to eq("406")
end
end
describe '#diaspora_id?' do