FIX: broken links on admin dashboard in Top Referrers section

This commit is contained in:
Neil Lalonde 2016-02-22 14:30:58 -05:00
parent 5415b2666d
commit cab5dd09d3
3 changed files with 7 additions and 6 deletions

View File

@ -285,7 +285,7 @@
{{#each r in top_referrers.data}}
<tbody>
<tr>
<td class="title">{{#link-to 'adminUser' r}}{{unbound r.username}}{{/link-to}}</td>
<td class="title">{{#link-to 'adminUser' r.user_id r.username}}{{unbound r.username}}{{/link-to}}</td>
<td class="value">{{r.num_clicks}}</td>
<td class="value">{{r.num_topics}}</td>
</tr>

View File

@ -35,9 +35,10 @@ class IncomingLinksReport
num_clicks = link_count_per_user
num_topics = topic_count_per_user
user_id_lookup = User.where(username: num_clicks.keys).select(:id, :username).inject({}) {|sum,v| sum[v.username] = v.id; sum;}
report.data = []
num_clicks.each_key do |username|
report.data << {username: username, num_clicks: num_clicks[username], num_topics: num_topics[username]}
report.data << {username: username, user_id: user_id_lookup[username], num_clicks: num_clicks[username], num_topics: num_topics[username]}
end
report.data = report.data.sort_by {|x| x[:num_clicks]}.reverse[0,10]
end

View File

@ -40,8 +40,8 @@ describe IncomingLinksReport do
r = IncomingLinksReport.find('top_referrers').as_json
expect(r[:data]).to eq [
{username: p1.user.username, num_clicks: 7 + 2, num_topics: 2},
{username: p2.user.username, num_clicks: 3, num_topics: 1}
{username: p1.user.username, user_id: p1.user.id, num_clicks: 7 + 2, num_topics: 2},
{username: p2.user.username, user_id: p2.user.id, num_clicks: 3, num_topics: 1}
]
r = IncomingLinksReport.find('top_traffic_sources').as_json
@ -98,8 +98,8 @@ describe IncomingLinksReport do
Fabricate(:incoming_link, user: bob, post: post1).save
end
expect(top_referrers[:data][0]).to eq({username: 'amy', num_clicks: 3, num_topics: 2})
expect(top_referrers[:data][1]).to eq({username: 'bob', num_clicks: 2, num_topics: 1})
expect(top_referrers[:data][0]).to eq({username: 'amy', user_id: amy.id, num_clicks: 3, num_topics: 2})
expect(top_referrers[:data][1]).to eq({username: 'bob', user_id: bob.id, num_clicks: 2, num_topics: 1})
end
end