diff --git a/app/models/bubble/assignable.rb b/app/models/bubble/assignable.rb index 1e6d0bf56..98ea3d8ea 100644 --- a/app/models/bubble/assignable.rb +++ b/app/models/bubble/assignable.rb @@ -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 diff --git a/app/models/bubble/commentable.rb b/app/models/bubble/commentable.rb index 152eeb7a0..5b8f630f5 100644 --- a/app/models/bubble/commentable.rb +++ b/app/models/bubble/commentable.rb @@ -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 diff --git a/app/models/bubble/watchable.rb b/app/models/bubble/watchable.rb index 39ef98f85..a021b9249 100644 --- a/app/models/bubble/watchable.rb +++ b/app/models/bubble/watchable.rb @@ -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 diff --git a/app/views/bubbles/watches/show.html.erb b/app/views/bubbles/watches/show.html.erb index 9fcb89eae..f5147e541 100644 --- a/app/views/bubbles/watches/show.html.erb +++ b/app/views/bubbles/watches/show.html.erb @@ -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 %> Stop watching diff --git a/test/fixtures/watches.yml b/test/fixtures/watches.yml index 3691b81af..470fbc362 100644 --- a/test/fixtures/watches.yml +++ b/test/fixtures/watches.yml @@ -38,11 +38,6 @@ text_jz: user: jz watching: true -text_kevin: - bubble: text - user: kevin - watching: true - shipping_david: bubble: shipping user: david diff --git a/test/models/bubble/assignable_test.rb b/test/models/bubble/assignable_test.rb new file mode 100644 index 000000000..ae61906f8 --- /dev/null +++ b/test/models/bubble/assignable_test.rb @@ -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 diff --git a/test/models/bubble/commentable_test.rb b/test/models/bubble/commentable_test.rb new file mode 100644 index 000000000..7541f6a2e --- /dev/null +++ b/test/models/bubble/commentable_test.rb @@ -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