Skip to content

Commit 311cafe

Browse files
committed
fix Protip#topic_ids
#topic_ids was returning ids of both the topics and the tagged user.
1 parent 636f915 commit 311cafe

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

app/models/protip.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ def event_type(options={})
403403
end
404404

405405
def topic_ids
406-
self.taggings.joins('inner join tags on taggings.tag_id = tags.id').select('tags.id').map(&:id)
406+
topics_tags.pluck(:id)
407407
end
408408

409409
def to_indexed_json

spec/models/protip_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@
126126
expect(protip.topics).to eq(%w(ruby python heroku))
127127
expect(protip.topics.count).to eq(3)
128128
end
129+
130+
it '#topic_ids should return ids of topics only' do
131+
protip = Fabricate(:protip, topics: 'ruby python', user: Fabricate(:user))
132+
protip.save!
133+
ruby_id = Tag.find_by_name("ruby").id
134+
python_id = Tag.find_by_name("python").id
135+
expect(protip.topic_ids).to match_array([ruby_id, python_id])
136+
end
129137
end
130138

131139
describe 'linking and featuring an image' do

0 commit comments

Comments
 (0)