Associate Event with Bubble
It's kind of a long way to get from one to the other right now. Every event belongs to a bubble, so let's link them directly.
This commit is contained in:
@@ -1,9 +1,13 @@
|
||||
module Bubble::Eventable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :events, dependent: :destroy
|
||||
end
|
||||
|
||||
private
|
||||
def track_event(action, creator: Current.user, **particulars)
|
||||
event = find_or_capture_event_summary.events.create! action: action, creator: creator, particulars: particulars
|
||||
event = find_or_capture_event_summary.events.create! action: action, creator: creator, bubble: self, particulars: particulars
|
||||
event.generate_notifications_later
|
||||
end
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ class Event < ApplicationRecord
|
||||
|
||||
belongs_to :creator, class_name: "User"
|
||||
belongs_to :summary, touch: true, class_name: "EventSummary"
|
||||
belongs_to :bubble
|
||||
|
||||
has_one :account, through: :creator
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
class AssociateEventsWithBubbles < ActiveRecord::Migration[8.1]
|
||||
def change
|
||||
change_table :events do |t|
|
||||
t.references :bubble, foreign_key: true
|
||||
end
|
||||
|
||||
execute "
|
||||
update events
|
||||
set bubble_id = m.bubble_id
|
||||
from event_summaries es
|
||||
join messages m on m.messageable_type = 'EventSummary' and m.messageable_id = es.id
|
||||
where events.summary_id = es.id
|
||||
"
|
||||
|
||||
change_column_null :events, :bubble_id, false
|
||||
end
|
||||
end
|
||||
Generated
+4
-1
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.1].define(version: 2025_01_15_122810) do
|
||||
ActiveRecord::Schema[8.1].define(version: 2025_01_17_142146) do
|
||||
create_table "accesses", force: :cascade do |t|
|
||||
t.integer "bucket_id", null: false
|
||||
t.integer "user_id", null: false
|
||||
@@ -147,6 +147,8 @@ ActiveRecord::Schema[8.1].define(version: 2025_01_15_122810) do
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.integer "summary_id", null: false
|
||||
t.integer "bubble_id", null: false
|
||||
t.index ["bubble_id"], name: "index_events_on_bubble_id"
|
||||
t.index ["creator_id"], name: "index_events_on_creator_id"
|
||||
t.index ["summary_id", "action"], name: "index_events_on_summary_id_and_action"
|
||||
end
|
||||
@@ -259,6 +261,7 @@ ActiveRecord::Schema[8.1].define(version: 2025_01_15_122810) do
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "bubbles", "workflow_stages", column: "stage_id"
|
||||
add_foreign_key "events", "bubbles"
|
||||
add_foreign_key "events", "event_summaries", column: "summary_id"
|
||||
add_foreign_key "messages", "bubbles"
|
||||
add_foreign_key "notifications", "bubbles"
|
||||
|
||||
Vendored
+14
@@ -1,11 +1,13 @@
|
||||
logo_published:
|
||||
creator: david
|
||||
bubble: logo
|
||||
action: published
|
||||
summary: logo_initial_activity
|
||||
created_at: <%= 1.week.ago %>
|
||||
|
||||
logo_assignment_jz:
|
||||
creator: david
|
||||
bubble: logo
|
||||
action: assigned
|
||||
summary: logo_initial_activity
|
||||
particulars: <%= { assignee_ids: [ ActiveRecord::FixtureSet.identify(:jz) ] }.to_json %>
|
||||
@@ -13,12 +15,14 @@ logo_assignment_jz:
|
||||
|
||||
logo_boost_dhh:
|
||||
creator: david
|
||||
bubble: logo
|
||||
action: boosted
|
||||
summary: logo_initial_activity
|
||||
created_at: <%= 1.week.ago + 2.hours %>
|
||||
|
||||
logo_assignment_km:
|
||||
creator: david
|
||||
bubble: logo
|
||||
action: assigned
|
||||
summary: logo_second_activity
|
||||
particulars: <%= { assignee_ids: [ ActiveRecord::FixtureSet.identify(:kevin) ] }.to_json %>
|
||||
@@ -26,36 +30,42 @@ logo_assignment_km:
|
||||
|
||||
logo_boost_km1:
|
||||
creator: kevin
|
||||
bubble: logo
|
||||
action: boosted
|
||||
summary: logo_second_activity
|
||||
created_at: <%= 1.day.ago + 1.hour %>
|
||||
|
||||
logo_boost_km2:
|
||||
creator: kevin
|
||||
bubble: logo
|
||||
action: boosted
|
||||
summary: logo_second_activity
|
||||
created_at: <%= 1.day.ago + 2.hours %>
|
||||
|
||||
logo_boost_jz1:
|
||||
creator: jz
|
||||
bubble: logo
|
||||
action: boosted
|
||||
summary: logo_second_activity
|
||||
created_at: <%= 1.day.ago + 3.hours %>
|
||||
|
||||
logo_boost_jz2:
|
||||
creator: jz
|
||||
bubble: logo
|
||||
action: boosted
|
||||
summary: logo_third_activity
|
||||
created_at: <%= 1.hour.ago %>
|
||||
|
||||
layout_published:
|
||||
creator: david
|
||||
bubble: layout
|
||||
action: published
|
||||
summary: layout_initial_activity
|
||||
created_at: <%= 1.week.ago %>
|
||||
|
||||
layout_commented:
|
||||
creator: david
|
||||
bubble: layout
|
||||
action: commented
|
||||
summary: layout_initial_activity
|
||||
particulars: <%= { comment_id: ActiveRecord::FixtureSet.identify(:layout_overflowing_david) }.to_json %>
|
||||
@@ -63,6 +73,7 @@ layout_commented:
|
||||
|
||||
layout_assignment_jz:
|
||||
creator: david
|
||||
bubble: layout
|
||||
action: assigned
|
||||
summary: layout_initial_activity
|
||||
particulars: <%= { assignee_ids: [ ActiveRecord::FixtureSet.identify(:jz) ] }.to_json %>
|
||||
@@ -70,18 +81,21 @@ layout_assignment_jz:
|
||||
|
||||
text_published:
|
||||
creator: kevin
|
||||
bubble: text
|
||||
action: published
|
||||
summary: text_initial_activity
|
||||
created_at: <%= 1.week.ago %>
|
||||
|
||||
shipping_published:
|
||||
creator: kevin
|
||||
bubble: shipping
|
||||
action: published
|
||||
summary: shipping_initial_activity
|
||||
created_at: <%= 1.week.ago %>
|
||||
|
||||
shipping_popped:
|
||||
creator: kevin
|
||||
bubble: shipping
|
||||
action: popped
|
||||
summary: shipping_initial_activity
|
||||
created_at: <%= 2.days.ago %>
|
||||
|
||||
@@ -8,7 +8,9 @@ class Notifier::AssignedTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
test "does not notify for self-assignments" do
|
||||
event = EventSummary.last.events.create! action: :assigned,
|
||||
event = EventSummary.last.events.create! \
|
||||
action: :assigned,
|
||||
bubble: bubbles(:logo),
|
||||
creator: users(:kevin),
|
||||
particulars: { assignee_ids: [ users(:kevin).id ] }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user