FIX: do not show links with 0 click on topic map

This commit is contained in:
Arpit Jalan 2018-07-18 09:44:50 +05:30
parent 281538ae61
commit 7da22e395b
2 changed files with 13 additions and 6 deletions

View File

@ -61,6 +61,8 @@ SQL
# note that ILIKE means "case insensitive LIKE"
builder.where("NOT(ftl.url ILIKE '%.png' OR ftl.url ILIKE '%.jpg' OR ftl.url ILIKE '%.gif')")
builder.where("COALESCE(ft.archetype, 'regular') <> :archetype", archetype: Archetype.private_message)
# do not show links with 0 click
builder.where("clicks > 0")
builder.secure_category(guardian.secure_category_ids)

View File

@ -321,16 +321,20 @@ http://b.com/#{'a' * 500}
it 'has the correct results' do
TopicLink.extract_from(post)
topic_link = post.topic.topic_links.first
TopicLinkClick.create(topic_link: topic_link, ip_address: '192.168.1.1')
topic_link_first = post.topic.topic_links.first
TopicLinkClick.create!(topic_link: topic_link_first, ip_address: '192.168.1.1')
TopicLinkClick.create!(topic_link: topic_link_first, ip_address: '192.168.1.2')
topic_link_second = post.topic.topic_links.second
TopicLinkClick.create!(topic_link: topic_link_second, ip_address: '192.168.1.1')
expect(counts_for[post.id]).to be_present
expect(counts_for[post.id].find { |l| l[:url] == 'http://google.com' }[:clicks]).to eq(0)
expect(counts_for[post.id].first[:clicks]).to eq(1)
expect(counts_for[post.id].first[:clicks]).to eq(2)
expect(counts_for[post.id].second[:clicks]).to eq(1)
array = TopicLink.topic_map(Guardian.new, post.topic_id)
expect(array.length).to eq(6)
expect(array[0].clicks).to eq(1)
expect(array.length).to eq(2)
expect(array[0].clicks).to eq(2)
expect(array[1].clicks).to eq(1)
end
it 'secures internal links correctly' do
@ -340,6 +344,7 @@ http://b.com/#{'a' * 500}
url = "http://#{test_uri.host}/t/topic-slug/#{secret_topic.id}"
post = Fabricate(:post, raw: "hello test topic #{url}")
TopicLink.extract_from(post)
TopicLinkClick.create!(topic_link: post.topic.topic_links.first, ip_address: '192.168.1.1')
expect(TopicLink.topic_map(Guardian.new, post.topic_id).count).to eq(1)
expect(TopicLink.counts_for(Guardian.new, post.topic, [post]).length).to eq(1)