makes user page to show only active feature comments

This commit is contained in:
Juanjo Bazán
2017-01-10 21:28:04 +01:00
parent 7a448b6890
commit 053a3e7b41
2 changed files with 38 additions and 5 deletions

View File

@@ -13,9 +13,9 @@ class UsersController < ApplicationController
def set_activity_counts def set_activity_counts
@activity_counts = HashWithIndifferentAccess.new( @activity_counts = HashWithIndifferentAccess.new(
proposals: Proposal.where(author_id: @user.id).count, proposals: Proposal.where(author_id: @user.id).count,
debates: Debate.where(author_id: @user.id).count, debates: (Setting['feature.debates'] ? Debate.where(author_id: @user.id).count : 0),
budget_investments: Budget::Investment.where(author_id: @user.id).count, budget_investments: (Setting['feature.budgets'] ? Budget::Investment.where(author_id: @user.id).count : 0),
comments: Comment.not_as_admin_or_moderator.where(user_id: @user.id).count) comments: only_active_commentables.count)
end end
def load_filtered_activity def load_filtered_activity
@@ -54,7 +54,7 @@ class UsersController < ApplicationController
end end
def load_comments def load_comments
@comments = Comment.not_as_admin_or_moderator.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page]) @comments = only_active_commentables.includes(:commentable).order(created_at: :desc).page(params[:page])
end end
def load_budget_investments def load_budget_investments
@@ -77,4 +77,19 @@ class UsersController < ApplicationController
@authorized_current_user ||= current_user && (current_user == @user || current_user.moderator? || current_user.administrator?) @authorized_current_user ||= current_user && (current_user == @user || current_user.moderator? || current_user.administrator?)
end end
def all_user_comments
Comment.not_as_admin_or_moderator.where(user_id: @user.id)
end
def only_active_commentables
disabled_commentables = []
disabled_commentables << "Debate" unless Setting['feature.debates']
disabled_commentables << "Budget::Investment" unless Setting['feature.budgets']
if disabled_commentables.present?
all_user_comments.where("commentable_type NOT IN (?)", disabled_commentables)
else
all_user_comments
end
end
end end

View File

@@ -235,6 +235,24 @@ feature 'Users' do
expect(page).to have_content(comment.body) expect(page).to have_content(comment.body)
expect(page).to_not have_content(admin_comment.body) expect(page).to_not have_content(admin_comment.body)
end end
scenario 'shows only comments from active features' do
user = create(:user)
1.times {create(:comment, user: user, commentable: create(:debate))}
2.times {create(:comment, user: user, commentable: create(:budget_investment))}
4.times {create(:comment, user: user, commentable: create(:proposal))}
visit user_path(user)
expect(page).to have_content('7 Comments')
Setting['feature.debates'] = nil
visit user_path(user)
expect(page).to have_content('6 Comments')
Setting['feature.budgets'] = nil
visit user_path(user)
expect(page).to have_content('4 Comments')
end
end end
end end