Files
fizzy/test/models/event_test.rb
T
Rob Zolkos 6a71856b3d Add JSON activities API endpoint (#2783)
* Add JSON events API endpoint

* Add regression test for event particulars defaults

* Move JSON events API to a dedicated ActivitiesController

The events endpoint served both the HTML day timeline and the JSON API
feed, but the two paths shared no data or behavior — the HTML side uses
DayTimelinesScoped while the JSON side built its own query. Splitting
into ActivitiesController gives the API its own home at
GET /:account/activities.json without dragging in the timeline
before_actions.

Also preloads comment creator in Event.preloaded to avoid an N+1 when
rendering comment eventables in the JSON feed.
2026-04-08 08:39:36 -04:00

54 lines
1.7 KiB
Ruby

require "test_helper"
class EventTest < ActiveSupport::TestCase
test "blank creator and board filters return the current relation unchanged" do
relation = Event.where(action: "card_published")
assert_equal relation.to_sql, relation.for_creators(nil).to_sql
assert_equal relation.to_sql, relation.for_creators([]).to_sql
assert_equal relation.to_sql, relation.for_boards(nil).to_sql
assert_equal relation.to_sql, relation.for_boards([]).to_sql
end
test "blank creator and board filters remain chainable" do
relation = Event.where(action: "card_published")
assert_nothing_raised do
relation.for_creators([]).for_boards([]).load
end
end
test "api_particulars returns empty strings for missing nested board change values" do
event = boards(:writebook).events.create!(
action: "card_board_changed",
creator: users(:david),
eventable: cards(:logo),
account: accounts("37s"),
particulars: {}
)
assert_equal({ "old_board" => "", "new_board" => "" }, event.api_particulars)
end
test "api_particulars returns empty strings for missing nested title and column values" do
title_event = boards(:writebook).events.create!(
action: "card_title_changed",
creator: users(:david),
eventable: cards(:logo),
account: accounts("37s"),
particulars: {}
)
triage_event = boards(:writebook).events.create!(
action: "card_triaged",
creator: users(:david),
eventable: cards(:logo),
account: accounts("37s"),
particulars: {}
)
assert_equal({ "old_title" => "", "new_title" => "" }, title_event.api_particulars)
assert_equal({ "column" => "" }, triage_event.api_particulars)
end
end