Start watching when participating on a bubble
If you're added as an assignee, or if you comment, then your watching preference will be toggled on.
This commit is contained in:
@@ -21,6 +21,8 @@ module Bubble::Assignable
|
||||
private
|
||||
def assign(user)
|
||||
assignments.create! assignee: user, assigner: Current.user
|
||||
set_watching(user, true)
|
||||
|
||||
track_event :assigned, assignee_ids: [ user.id ]
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
# Already assigned
|
||||
|
||||
@@ -7,6 +7,8 @@ module Bubble::Commentable
|
||||
|
||||
def comment_created(comment)
|
||||
increment! :comments_count
|
||||
set_watching comment.creator, true
|
||||
|
||||
track_event :commented, comment_id: comment.id
|
||||
rescore
|
||||
end
|
||||
|
||||
@@ -8,7 +8,7 @@ module Bubble::Watchable
|
||||
after_create :create_initial_watches
|
||||
end
|
||||
|
||||
def watching?(user)
|
||||
def watched_by?(user)
|
||||
watches.where(user: user, watching: true).exists?
|
||||
end
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<%= turbo_frame_tag dom_id(@bubble, :watch) do %>
|
||||
<% if @bubble.watching? Current.user %>
|
||||
<% if @bubble.watched_by? Current.user %>
|
||||
<%= button_to bucket_bubble_watch_path(@bubble.bucket, @bubble), method: :delete, class: "btn" do %>
|
||||
<%= image_tag "bookmark.svg", aria: { hidden: true }, size: 24 %>
|
||||
<span class="overflow-ellipsis">Stop watching</span>
|
||||
|
||||
Vendored
-5
@@ -38,11 +38,6 @@ text_jz:
|
||||
user: jz
|
||||
watching: true
|
||||
|
||||
text_kevin:
|
||||
bubble: text
|
||||
user: kevin
|
||||
watching: true
|
||||
|
||||
shipping_david:
|
||||
bubble: shipping
|
||||
user: david
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
require "test_helper"
|
||||
|
||||
class Bubble::AssignableTest < ActiveSupport::TestCase
|
||||
test "assigning a user makes them watch the bubble" do
|
||||
assert_not bubbles(:layout).assigned_to?(users(:kevin))
|
||||
bubbles(:layout).set_watching(users(:kevin), false)
|
||||
|
||||
with_current_user(:jz) do
|
||||
bubbles(:layout).toggle_assignment(users(:kevin))
|
||||
end
|
||||
|
||||
assert bubbles(:layout).assigned_to?(users(:kevin))
|
||||
assert bubbles(:layout).watched_by?(users(:kevin))
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,13 @@
|
||||
require "test_helper"
|
||||
|
||||
class Bubble::CommentableTest < ActiveSupport::TestCase
|
||||
test "creating a comment on a bubble makes the creator watch the bubble" do
|
||||
assert_not bubbles(:text).watched_by?(users(:kevin))
|
||||
|
||||
with_current_user(:kevin) do
|
||||
bubbles(:text).capture Comment.new(body: "This sounds interesting!")
|
||||
end
|
||||
|
||||
assert bubbles(:text).watched_by?(users(:kevin))
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user