Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix results/query in api/v1/featured_tags/suggestions #29597

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ def index
private

def set_recently_used_tags
@recently_used_tags = Tag.recently_used(current_account).where.not(id: current_account.featured_tags).limit(10)
@recently_used_tags = Tag.recently_used(current_account).where.not(id: featured_tag_ids).limit(10)
end

def featured_tag_ids
current_account.featured_tags.pluck(:tag_id)
end
end
2 changes: 1 addition & 1 deletion spec/fabricators/featured_tag_fabricator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Fabricator(:featured_tag) do
account { Fabricate.build(:account) }
tag { Fabricate.build(:tag) }
tag { nil }
name { sequence(:name) { |i| "Tag#{i}" } }
end
30 changes: 26 additions & 4 deletions spec/requests/api/v1/featured_tags/suggestions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,35 @@
let(:token) { Fabricate(:accessible_access_token, resource_owner_id: user.id, scopes: scopes) }
let(:scopes) { 'read:accounts' }
let(:headers) { { 'Authorization' => "Bearer #{token.token}" } }
let(:account) { Fabricate(:account) }
let(:account) { Fabricate(:account, user: user) }

describe 'GET /api/v1/featured_tags/suggestions' do
it 'returns http success' do
get '/api/v1/featured_tags/suggestions', params: { account_id: account.id, limit: 2 }, headers: headers
let!(:unused_featured_tag) { Fabricate(:tag, name: 'unused_featured_tag') }
let!(:used_tag) { Fabricate(:tag, name: 'used_tag') }
let!(:used_featured_tag) { Fabricate(:tag, name: 'used_featured_tag') }

expect(response).to have_http_status(200)
before do
_unused_tag = Fabricate(:tag, name: 'unused_tag')

# Make relevant tags used by account
status = Fabricate(:status, account: account)
status.tags << used_tag
status.tags << used_featured_tag

# Feature the relevant tags
Fabricate :featured_tag, account: account, name: unused_featured_tag.name
Fabricate :featured_tag, account: account, name: used_featured_tag.name
end

it 'returns http success and recently used but not featured tags' do
get '/api/v1/featured_tags/suggestions', params: { limit: 2 }, headers: headers

expect(response)
.to have_http_status(200)
expect(body_as_json)
.to contain_exactly(
include(name: used_tag.name)
)
end
end
end