diff --git a/app/models/bubble/commentable.rb b/app/models/bubble/commentable.rb index 1fdc9b13f..1af10eacf 100644 --- a/app/models/bubble/commentable.rb +++ b/app/models/bubble/commentable.rb @@ -2,7 +2,7 @@ module Bubble::Commentable extend ActiveSupport::Concern included do - has_many :comments, dependent: :destroy + has_many :comments scope :ordered_by_comments, -> { left_joins(:comments).group(:id).order("COUNT(comments.id) DESC") } end diff --git a/app/models/bubble/eventable.rb b/app/models/bubble/eventable.rb index 0288e6b73..78e1559bf 100644 --- a/app/models/bubble/eventable.rb +++ b/app/models/bubble/eventable.rb @@ -2,7 +2,7 @@ module Bubble::Eventable extend ActiveSupport::Concern included do - has_many :events, dependent: :delete_all + has_many :events after_create -> { track_event :created } end diff --git a/app/models/concerns/threadable.rb b/app/models/concerns/threadable.rb index 10759aa98..c449d2c08 100644 --- a/app/models/concerns/threadable.rb +++ b/app/models/concerns/threadable.rb @@ -2,7 +2,7 @@ module Threadable extend ActiveSupport::Concern included do - has_one :thread_entry, as: :threadable, dependent: :destroy + has_one :thread_entry, as: :threadable after_create { create_thread_entry! bubble: bubble } after_update { bubble.touch } diff --git a/app/models/rollup.rb b/app/models/rollup.rb index 1968e4ce8..06a6bedf5 100644 --- a/app/models/rollup.rb +++ b/app/models/rollup.rb @@ -3,5 +3,5 @@ class Rollup < ApplicationRecord belongs_to :bubble - has_many :events, -> { chronologically } + has_many :events, -> { chronologically }, dependent: :delete_all end diff --git a/app/models/thread_entry.rb b/app/models/thread_entry.rb index 3efa6b97f..16e5dec0f 100644 --- a/app/models/thread_entry.rb +++ b/app/models/thread_entry.rb @@ -1,7 +1,7 @@ class ThreadEntry < ApplicationRecord belongs_to :bubble - delegated_type :threadable, types: %w[ Comment Rollup ] + delegated_type :threadable, types: %w[ Comment Rollup ], dependent: :destroy scope :chronologically, -> { order created_at: :asc, id: :desc } end diff --git a/test/fixtures/thread_entries.yml b/test/fixtures/thread_entries.yml index 4137af55b..df1634b9f 100644 --- a/test/fixtures/thread_entries.yml +++ b/test/fixtures/thread_entries.yml @@ -24,5 +24,17 @@ logo_5: created_at: <%= 1.hour.ago %> layout_1: + bubble: layout + threadable: layout_initial_activity (Rollup) + +layout_2: bubble: layout threadable: layout_overflowing_david (Comment) + +text_1: + bubble: text + threadable: text_initial_activity (Rollup) + +shipping_1: + bubble: shipping + threadable: shipping_initial_activity (Rollup)