Skip to content

Commit

Permalink
Fix serialization of followers/following counts when user hides their…
Browse files Browse the repository at this point in the history
… network (mastodon#16418)

* Add tests

* Fix serialization of followers/following counts when user hides their network

Fixes mastodon#16382

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
  • Loading branch information
ClearlyClaire committed Jan 28, 2022
1 parent 19edb7a commit c0b2c2c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/controllers/follower_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def restrict_fields_to
if page_requested? || !@account.user_hides_network?
# Return all fields
else
%i(id type totalItems)
%i(id type total_items)
end
end
end
2 changes: 1 addition & 1 deletion app/controllers/following_accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def restrict_fields_to
if page_requested? || !@account.user_hides_network?
# Return all fields
else
%i(id type totalItems)
%i(id type total_items)
end
end
end
19 changes: 18 additions & 1 deletion spec/controllers/follower_accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe FollowerAccountsController do
render_views

let(:alice) { Fabricate(:account, username: 'alice') }
let(:alice) { Fabricate(:user).account }
let(:follower0) { Fabricate(:account) }
let(:follower1) { Fabricate(:account) }

Expand Down Expand Up @@ -101,6 +101,23 @@
expect(body['partOf']).to be_blank
end

context 'when account hides their network' do
before do
alice.user.settings.hide_network = true
end

it 'returns followers count' do
expect(body['totalItems']).to eq 2
end

it 'does not return items' do
expect(body['items']).to be_blank
expect(body['orderedItems']).to be_blank
expect(body['first']).to be_blank
expect(body['last']).to be_blank
end
end

context 'when account is permanently suspended' do
before do
alice.suspend!
Expand Down
19 changes: 18 additions & 1 deletion spec/controllers/following_accounts_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
describe FollowingAccountsController do
render_views

let(:alice) { Fabricate(:account, username: 'alice') }
let(:alice) { Fabricate(:user).account }
let(:followee0) { Fabricate(:account) }
let(:followee1) { Fabricate(:account) }

Expand Down Expand Up @@ -101,6 +101,23 @@
expect(body['partOf']).to be_blank
end

context 'when account hides their network' do
before do
alice.user.settings.hide_network = true
end

it 'returns followers count' do
expect(body['totalItems']).to eq 2
end

it 'does not return items' do
expect(body['items']).to be_blank
expect(body['orderedItems']).to be_blank
expect(body['first']).to be_blank
expect(body['last']).to be_blank
end
end

context 'when account is permanently suspended' do
before do
alice.suspend!
Expand Down

0 comments on commit c0b2c2c

Please sign in to comment.