Merge pull request #2752 from consul/following-hidden-proposals

Deal gracefully with hidden followable in my activity
This commit is contained in:
Alberto
2018-07-10 18:44:34 +02:00
committed by GitHub
3 changed files with 18 additions and 3 deletions

View File

@@ -17,7 +17,7 @@ class UsersController < ApplicationController
debates: (Setting['feature.debates'] ? Debate.where(author_id: @user.id).count : 0),
budget_investments: (Setting['feature.budgets'] ? Budget::Investment.where(author_id: @user.id).count : 0),
comments: only_active_commentables.count,
follows: @user.follows.count)
follows: @user.follows.map(&:followable).compact.count)
end
def load_filtered_activity

View File

@@ -12,6 +12,8 @@ module FollowablesHelper
end
def render_follow(follow)
return unless follow.followable.present?
followable = follow.followable
partial = followable_class_name(followable) + "_follow"
locals = {followable_class_name(followable).to_sym => followable}

View File

@@ -428,7 +428,7 @@ feature 'Users' do
@user = create(:user)
end
scenario 'Not display following tab when user is not following any followable' do
scenario "Do not display follows' tab when user is not following any followables" do
visit user_path(@user)
expect(page).not_to have_content('0 Following')
@@ -443,6 +443,19 @@ feature 'Users' do
expect(page).to have_selector(".activity li.is-active", text: "1 Following")
end
scenario "Gracefully handle followables that have been hidden", :focus do
active_proposal = create(:proposal)
hidden_proposal = create(:proposal)
create(:follow, followable: active_proposal, user: @user)
create(:follow, followable: hidden_proposal, user: @user)
hidden_proposal.hide
visit user_path(@user)
expect(page).to have_content('1 Following')
end
describe 'Proposals' do
scenario 'Display following tab when user is following one proposal at least' do
@@ -463,7 +476,7 @@ feature 'Users' do
expect(page).to have_link('Citizen proposals', href: "#citizen_proposals")
end
scenario 'Not display proposal tab when user is not following any proposal' do
scenario "Do not display proposals' tab when user is not following any proposal" do
visit user_path(@user, filter: "follows")
expect(page).not_to have_link('Citizen proposals', href: "#citizen_proposals")