Skip to content

Commit 7314863

Browse files
committed
fixed total post count regression when showing a user
1 parent e2c2f6a commit 7314863

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

app/controllers/users_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,12 +45,13 @@ def index
4545

4646
def show
4747
@abilities = Ability.on_user(@user)
48+
@limit = params[:limit]&.to_i || 15
4849

4950
@posts = set_posts.user_sort({ term: params[:sort], default: :score },
5051
age: :created_at, score: :score)
51-
.first(15)
5252

5353
@total_post_count = @posts.count
54+
@posts = @posts.first(@limit)
5455
render layout: 'without_sidebar'
5556
end
5657

test/controllers/users_controller_test.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,20 @@ class UsersControllerTest < ActionController::TestCase
4848
assert_response(:not_found)
4949
end
5050

51+
test 'should correctly show user post count' do
52+
std = users(:standard_user)
53+
post_count = Post.all.by(std).count
54+
limit = post_count - 1
55+
56+
assert post_count.positive? && limit.positive?
57+
58+
sign_in std
59+
get :show, params: { id: std.id, limit: limit }
60+
61+
assert_equal assigns(:posts)&.count, limit
62+
assert_equal assigns(:total_post_count), post_count
63+
end
64+
5165
test 'should get mod tools page' do
5266
sign_in users(:moderator)
5367
get :mod, params: { id: users(:standard_user).id }

0 commit comments

Comments
 (0)