Deal gracefully with hidden followable in my activity

We were seeing an exception when a user was following a proposal and
that proposal becomes hidden

With this commit we are skipping this proposals and hopefully fixing
this exception

We are also adjusting the count of followed proposals, without
including hidden proposals. It might be cleaner, to remove a `Follow`
when its `Followable` becomes hidden. But then we should probably
activate the `Follow` again if the `Followable` becomes non-hidden…

For now this commit should suffice 😌
This commit is contained in:
rgarcia
2018-05-10 16:07:53 +02:00
committed by decabeza
parent f7f1f12b82
commit 88cde6d018
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), 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), budget_investments: (Setting['feature.budgets'] ? Budget::Investment.where(author_id: @user.id).count : 0),
comments: only_active_commentables.count, comments: only_active_commentables.count,
follows: @user.follows.count) follows: @user.follows.map(&:followable).compact.count)
end end
def load_filtered_activity def load_filtered_activity

View File

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

View File

@@ -428,7 +428,7 @@ feature 'Users' do
@user = create(:user) @user = create(:user)
end 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) visit user_path(@user)
expect(page).not_to have_content('0 Following') 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") expect(page).to have_selector(".activity li.is-active", text: "1 Following")
end 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 describe 'Proposals' do
scenario 'Display following tab when user is following one proposal at least' 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") expect(page).to have_link('Citizen proposals', href: "#citizen_proposals")
end 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") visit user_path(@user, filter: "follows")
expect(page).not_to have_link('Citizen proposals', href: "#citizen_proposals") expect(page).not_to have_link('Citizen proposals', href: "#citizen_proposals")