78fc80cf35
* Allow Card#last_updated_at to be set This is useful when doing an import from another system. I'm currently working on a script to import our Github issues into Fizzy. This is discussed in https://github.com/basecamp/fizzy/pull/2056#discussion_r2609560246 * Add nil fallback and expand test coverage for last_active_at Adds a safety fallback to Time.current if created_at is unexpectedly nil during card creation. Test coverage to verify: * last_active_at defaults to created_at when not provided * last_active_at can be updated via API on existing cards * import workflow where last_active_at is restored after comments * publishing doesn't overwrite explicit last_active_at values --------- Co-authored-by: Jeremy Daer <jeremy@37signals.com>
39 lines
903 B
Ruby
39 lines
903 B
Ruby
module Card::Eventable
|
|
extend ActiveSupport::Concern
|
|
|
|
include ::Eventable
|
|
|
|
included do
|
|
before_create { self.last_active_at ||= created_at || Time.current }
|
|
|
|
after_save :track_title_change, if: :saved_change_to_title?
|
|
end
|
|
|
|
def event_was_created(event)
|
|
transaction do
|
|
create_system_comment_for(event)
|
|
touch_last_active_at unless was_just_published?
|
|
end
|
|
end
|
|
|
|
def touch_last_active_at
|
|
# Not using touch so that we can detect attribute change on callbacks
|
|
update!(last_active_at: Time.current)
|
|
end
|
|
|
|
private
|
|
def should_track_event?
|
|
published?
|
|
end
|
|
|
|
def track_title_change
|
|
if title_before_last_save.present?
|
|
track_event "title_changed", particulars: { old_title: title_before_last_save, new_title: title }
|
|
end
|
|
end
|
|
|
|
def create_system_comment_for(event)
|
|
SystemCommenter.new(self, event).comment
|
|
end
|
|
end
|