16a80ff3a6
This introduces a more dynamic system of activity scoring, to improve the way bubbles "bubble up" due to their activity. There are a few different parts we can tune here, and it's likely we'll need to make adjustments once we get a feel for how this works in practice. The basic idea here is: - We assign points for certain types of event that happen on a bubble. A boost gets 1 point, a comment gets 10 points, and so on. - These points decay over time, at a rate of 50% per day. So old activity is worth much less than new activity. Bubbles should rise up quickly when acted upon, bit will float back down if left idle. - Some comments can score higher than others: the first comment from each person on a bubble is worth more (20) because it signals that more people are getting involved; and comments that follow a comment by a different author are also worth more (15) because that signals there's ongoing conversation between people, not just a series of notes being left by one individual. In terms of implementation, we persist the score on the bubble whenever it changes, but we handle the decay on the client side. That allows us to cache the bubble representation without having to continually change it while its activity decays. We also keep a separate `activity_score_order` attribute on the model. This can be used to sort the bubbles in order of "most active", without having to think about the decay.
66 lines
1.9 KiB
Ruby
66 lines
1.9 KiB
Ruby
require "test_helper"
|
|
|
|
class CommentTest < ActiveSupport::TestCase
|
|
setup do
|
|
Current.session = sessions(:david)
|
|
end
|
|
|
|
test "searchable by body" do
|
|
message = bubbles(:logo).capture Comment.new(body: "I'd prefer something more rustic")
|
|
|
|
assert_includes Comment.search("something rustic"), message.comment
|
|
end
|
|
|
|
test "updating bubble counter" do
|
|
assert_difference -> { bubbles(:logo).comments_count } do
|
|
assert_changes -> { bubbles(:logo).activity_score } do
|
|
bubbles(:logo).capture Comment.new(body: "I'd prefer something more rustic")
|
|
end
|
|
end
|
|
|
|
assert_difference -> { bubbles(:logo).comments_count }, -1 do
|
|
assert_changes -> { bubbles(:logo).activity_score } do
|
|
bubbles(:logo).messages.comments.last.destroy
|
|
end
|
|
end
|
|
end
|
|
|
|
test "first_by_author_on_bubble?" do
|
|
assert_not Comment.new.first_by_author_on_bubble?
|
|
|
|
with_current_user :david do
|
|
comment = Comment.new.tap { |c| bubbles(:logo).capture c }
|
|
assert comment.first_by_author_on_bubble?
|
|
|
|
comment = Comment.new.tap { |c| bubbles(:logo).capture c }
|
|
assert_not comment.first_by_author_on_bubble?
|
|
end
|
|
|
|
with_current_user :kevin do
|
|
comment = Comment.new.tap { |c| bubbles(:logo).capture c }
|
|
assert_not comment.first_by_author_on_bubble?
|
|
end
|
|
end
|
|
|
|
test "follows_comment_by_another_author?" do
|
|
assert_not Comment.new.follows_comment_by_another_author?
|
|
|
|
bubble = buckets(:writebook).bubbles.create!
|
|
|
|
with_current_user :david do
|
|
comment = Comment.new.tap { |c| bubble.capture c }
|
|
assert_not comment.follows_comment_by_another_author?
|
|
end
|
|
|
|
with_current_user :kevin do
|
|
comment = Comment.new.tap { |c| bubble.capture c }
|
|
assert comment.follows_comment_by_another_author?
|
|
end
|
|
|
|
with_current_user :david do
|
|
comment = Comment.new.tap { |c| bubble.capture c }
|
|
assert comment.follows_comment_by_another_author?
|
|
end
|
|
end
|
|
end
|