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,24 +135,30 @@ class PeopleController < ApplicationController
end
def contacts
@person = Person.find_by_guid(params[:person_id])
respond_to do |format|
format.json { render nothing: true, status: 406 }
if @person
@contact = current_user.contact_for(@person)
@contacts_of_contact = Contact.contact_contacts_for(current_user, @person)
gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile
gon.preloads[:photos] = {
count: photos_from(@person, :all).count(:all)
}
gon.preloads[:contacts] = {
count: @contacts_of_contact.count(:all),
}
@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'
redirect_to people_path
format.any do
@person = Person.find_by_guid(params[:person_id])
if @person
@contact = current_user.contact_for(@person)
@contacts_of_contact = Contact.contact_contacts_for(current_user, @person)
gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile
gon.preloads[:photos] = {
count: photos_from(@person, :all).count(:all)
}
gon.preloads[:contacts] = {
count: @contacts_of_contact.count(:all),
}
@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"
redirect_to people_path
end
end
end
end

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