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:
@@ -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
|
||||
|
||||
@@ -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}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user