Merge pull request #5751 from svbergerem/fix-photo-count-profile

Fix photo count in the profile view
This commit is contained in:
Jonne Haß 2015-03-10 17:44:44 +01:00
commit 8ab6f31e0a
6 changed files with 45 additions and 5 deletions

View file

@ -142,6 +142,7 @@ diaspora.yml file**. The existing settings from 0.4.x and before will not work a
* Improved stripping markdown in post titles [#5730](https://github.com/diaspora/diaspora/pull/5730) * Improved stripping markdown in post titles [#5730](https://github.com/diaspora/diaspora/pull/5730)
* Remove border from reply form for conversations [#5744](https://github.com/diaspora/diaspora/pull/5744) * Remove border from reply form for conversations [#5744](https://github.com/diaspora/diaspora/pull/5744)
* Fix overflow for headings, blockquotes and other elements [#5731](https://github.com/diaspora/diaspora/pull/5731) * Fix overflow for headings, blockquotes and other elements [#5731](https://github.com/diaspora/diaspora/pull/5731)
* Correct photo count on profile page [#5751](https://github.com/diaspora/diaspora/pull/5751)
## Features ## Features
* Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105) * Don't pull jQuery from a CDN by default [#5105](https://github.com/diaspora/diaspora/pull/5105)

View file

@ -86,7 +86,7 @@ class PeopleController < ApplicationController
end end
gon.preloads[:person] = @person_json gon.preloads[:person] = @person_json
gon.preloads[:photos] = { gon.preloads[:photos] = {
count: photos_from(@person).count(:all), count: photos_from(@person, :all).count(:all)
} }
gon.preloads[:contacts] = { gon.preloads[:contacts] = {
count: Contact.contact_contacts_for(current_user, @person).count(:all), 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) @contacts_of_contact = Contact.contact_contacts_for(current_user, @person)
gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile
gon.preloads[:photos] = { gon.preloads[:photos] = {
count: photos_from(@person).count(:all), count: photos_from(@person, :all).count(:all)
} }
gon.preloads[:contacts] = { gon.preloads[:contacts] = {
count: @contacts_of_contact.count(:all), count: @contacts_of_contact.count(:all),
@ -220,9 +220,9 @@ class PeopleController < ApplicationController
@person.try(:remote?) && !user_signed_in? @person.try(:remote?) && !user_signed_in?
end end
def photos_from(person) def photos_from(person, limit)
@photos ||= if user_signed_in? @photos ||= if user_signed_in?
current_user.photos_from(person) current_user.photos_from(person, limit: limit)
else else
Photo.where(author_id: person.id, public: true) Photo.where(author_id: person.id, public: true)
end.order('created_at desc') end.order('created_at desc')

View file

@ -29,7 +29,7 @@ class PhotosController < ApplicationController
format.all do format.all do
gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile gon.preloads[:person] = PersonPresenter.new(@person, current_user).full_hash_with_profile
gon.preloads[:photos] = { gon.preloads[:photos] = {
count: @posts.count(:all), count: current_user.photos_from(@person, limit: :all).count(:all)
} }
gon.preloads[:contacts] = { gon.preloads[:contacts] = {
count: Contact.contact_contacts_for(current_user, @person).count(:all), count: Contact.contact_contacts_for(current_user, @person).count(:all),

View file

@ -165,6 +165,9 @@ module User::Querying
} }
defaults[:type] = Stream::Base::TYPES_OF_POST_IN_STREAM if klass == Post defaults[:type] = Stream::Base::TYPES_OF_POST_IN_STREAM if klass == Post
opts = defaults.merge(opts) opts = defaults.merge(opts)
if opts[:limit] == :all
opts.delete(:limit)
end
opts[:order_field] = opts[:order].split.first.to_sym opts[:order_field] = opts[:order].split.first.to_sym
opts[:order_with_table] = klass.table_name + '.' + opts[:order] opts[:order_with_table] = klass.table_name + '.' + opts[:order]

View file

@ -218,6 +218,18 @@ describe PeopleController, :type => :controller do
expect(assigns(:photos)).to include public_photo expect(assigns(:photos)).to include public_photo
end 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 context "when the person is the current user" do
it "succeeds" do it "succeeds" do
get :show, :id => @user.person.to_param get :show, :id => @user.person.to_param
@ -473,6 +485,18 @@ describe PeopleController, :type => :controller do
expect(flash[:error]).to be_present expect(flash[:error]).to be_present
expect(response).to redirect_to people_path expect(response).to redirect_to people_path
end 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 end
describe '#diaspora_id?' do describe '#diaspora_id?' do

View file

@ -94,6 +94,18 @@ describe PhotosController, :type => :controller do
expect(assigns[:posts]).to eq([@bobs_photo]) expect(assigns[:posts]).to eq([@bobs_photo])
end 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 it "returns json when requested" do
request.env['HTTP_ACCEPT'] = 'application/json' request.env['HTTP_ACCEPT'] = 'application/json'
get :index, :person_id => alice.person.guid.to_s get :index, :person_id => alice.person.guid.to_s