Fix photo count in the profile view
This commit is contained in:
parent
6091b7c269
commit
d2222a97e5
5 changed files with 44 additions and 5 deletions
|
|
@ -86,7 +86,7 @@ class PeopleController < ApplicationController
|
|||
end
|
||||
gon.preloads[:person] = @person_json
|
||||
gon.preloads[:photos] = {
|
||||
count: photos_from(@person).count(:all),
|
||||
count: photos_from(@person, :all).count(:all)
|
||||
}
|
||||
gon.preloads[:contacts] = {
|
||||
count: Contact.contact_contacts_for(current_user, @person).count(:all),
|
||||
|
|
@ -144,7 +144,7 @@ class PeopleController < ApplicationController
|
|||
@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).count(:all),
|
||||
count: photos_from(@person, :all).count(:all)
|
||||
}
|
||||
gon.preloads[:contacts] = {
|
||||
count: @contacts_of_contact.count(:all),
|
||||
|
|
@ -220,9 +220,9 @@ class PeopleController < ApplicationController
|
|||
@person.try(:remote?) && !user_signed_in?
|
||||
end
|
||||
|
||||
def photos_from(person)
|
||||
def photos_from(person, limit)
|
||||
@photos ||= if user_signed_in?
|
||||
current_user.photos_from(person)
|
||||
current_user.photos_from(person, limit: limit)
|
||||
else
|
||||
Photo.where(author_id: person.id, public: true)
|
||||
end.order('created_at desc')
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class PhotosController < ApplicationController
|
|||
format.all do
|
||||
gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile
|
||||
gon.preloads[:photos] = {
|
||||
count: @posts.count(:all),
|
||||
count: current_user.photos_from(@person, limit: :all).count(:all)
|
||||
}
|
||||
gon.preloads[:contacts] = {
|
||||
count: Contact.contact_contacts_for(current_user, @person).count(:all),
|
||||
|
|
|
|||
|
|
@ -165,6 +165,9 @@ module User::Querying
|
|||
}
|
||||
defaults[:type] = Stream::Base::TYPES_OF_POST_IN_STREAM if klass == Post
|
||||
opts = defaults.merge(opts)
|
||||
if opts[:limit] == :all
|
||||
opts.delete(:limit)
|
||||
end
|
||||
|
||||
opts[:order_field] = opts[:order].split.first.to_sym
|
||||
opts[:order_with_table] = klass.table_name + '.' + opts[:order]
|
||||
|
|
|
|||
|
|
@ -218,6 +218,18 @@ describe PeopleController, :type => :controller do
|
|||
expect(assigns(:photos)).to include public_photo
|
||||
end
|
||||
|
||||
it "displays the correct number of photos" do
|
||||
16.times do |i|
|
||||
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
|
||||
end
|
||||
get :show, :id => eve.person.to_param
|
||||
expect(response.body).to include '"photos":{"count":16}'
|
||||
|
||||
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false)
|
||||
get :show, :id => eve.person.to_param
|
||||
expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice
|
||||
end
|
||||
|
||||
context "when the person is the current user" do
|
||||
it "succeeds" do
|
||||
get :show, :id => @user.person.to_param
|
||||
|
|
@ -473,6 +485,18 @@ describe PeopleController, :type => :controller do
|
|||
expect(flash[:error]).to be_present
|
||||
expect(response).to redirect_to people_path
|
||||
end
|
||||
|
||||
it "displays the correct number of photos" do
|
||||
16.times do |i|
|
||||
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
|
||||
end
|
||||
get :contacts, :person_id => eve.person.to_param
|
||||
expect(response.body).to include '"photos":{"count":16}'
|
||||
|
||||
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false)
|
||||
get :contacts, :person_id => eve.person.to_param
|
||||
expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice
|
||||
end
|
||||
end
|
||||
|
||||
describe '#diaspora_id?' do
|
||||
|
|
|
|||
|
|
@ -94,6 +94,18 @@ describe PhotosController, :type => :controller do
|
|||
expect(assigns[:posts]).to eq([@bobs_photo])
|
||||
end
|
||||
|
||||
it "displays the correct number of photos" do
|
||||
16.times do |i|
|
||||
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => true)
|
||||
end
|
||||
get :index, :person_id => eve.person.to_param
|
||||
expect(response.body).to include '"photos":{"count":16}'
|
||||
|
||||
eve.post(:photo, :user_file => uploaded_photo, :to => eve.aspects.first.id, :public => false)
|
||||
get :index, :person_id => eve.person.to_param
|
||||
expect(response.body).to include '"photos":{"count":16}' # eve is not sharing with alice
|
||||
end
|
||||
|
||||
it "returns json when requested" do
|
||||
request.env['HTTP_ACCEPT'] = 'application/json'
|
||||
get :index, :person_id => alice.person.guid.to_s
|
||||
|
|
|
|||
Loading…
Reference in a new issue