Skip to content

Commit

Permalink
hides comments posted as mod/admin from user page
Browse files Browse the repository at this point in the history
  • Loading branch information
xuanxu committed Nov 12, 2015
1 parent c258a4f commit 1ca7ca6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Expand Up @@ -47,7 +47,7 @@ def load_debates
end

def load_comments
@comments = Comment.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page])
@comments = Comment.not_as_admin_or_moderator.where(user_id: @user.id).includes(:commentable).order(created_at: :desc).page(params[:page])
end

def valid_access?
Expand Down
30 changes: 26 additions & 4 deletions spec/features/users_spec.rb
Expand Up @@ -174,31 +174,53 @@
@user = create(:user)
end

scenario "is not shown if no user logged in" do
scenario 'is not shown if no user logged in' do
visit user_path(@user)
expect(page).to_not have_content(@user.email)
end

scenario "is not shown if logged in user is a regular user" do
scenario 'is not shown if logged in user is a regular user' do
login_as(create(:user))
visit user_path(@user)
expect(page).to_not have_content(@user.email)
end

scenario "is not shown if logged in user is moderator" do
scenario 'is not shown if logged in user is moderator' do
login_as(create(:moderator).user)
visit user_path(@user)
expect(page).to_not have_content(@user.email)
end

scenario "is shown if logged in user is admin" do
scenario 'is shown if logged in user is admin' do
login_as(create(:administrator).user)
visit user_path(@user)
expect(page).to have_content(@user.email)
end

end
end

feature 'Special comments' do

scenario 'comments posted as moderator are not visible in user activity' do
moderator = create(:administrator).user
comment = create(:comment, user: moderator)
moderator_comment = create(:comment, user: moderator, moderator_id: moderator.id)

visit user_path(moderator)
expect(page).to have_content(comment.body)
expect(page).to_not have_content(moderator_comment.body)
end

scenario 'comments posted as admin are not visible in user activity' do
admin = create(:administrator).user
comment = create(:comment, user: admin)
admin_comment = create(:comment, user: admin, administrator_id: admin.id)

visit user_path(admin)
expect(page).to have_content(comment.body)
expect(page).to_not have_content(admin_comment.body)
end
end

end

0 comments on commit 1ca7ca6

Please sign in to comment.