Allow boosts on cards (#2411)

* Add reactions association to Card model

Adds `has_many :reactions` to Card, matching the implementation in Comment.
This allows cards to be reacted to directly with emoji reactions.

The association:
- Orders reactions chronologically
- Uses polymorphic `:reactable` interface
- Deletes reactions when card is destroyed

Includes test coverage for the new association.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add reactions UI to card detail view

- Create Cards::ReactionsController with turbo stream responses
- Add card reactions views (reactions list, new form, menu partial)
- Position reaction button flush-right when no reactions exist
- Show reactions on bottom-left when present, with button inline
- Handle narrow viewports by flowing button below meta section
- Add controller tests for card reactions

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add boost count to card preview

Display reaction count alongside comment count on card tiles in board
columns. Introduces a .card__counts wrapper to group both counts with
proper positioning on all viewport sizes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Consolidate reaction views for cards and comments

Extract shared views to app/views/reactions/ using polymorphic routing.
Both card and comment reactions now render the same partials, with a
helper to compute the correct path prefix for nested routes.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix emoji picker width in card reactions

Override .card .popup { inline-size: 260px } for the reaction popup
so the emoji grid displays without horizontal scrollbar.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Hide boost count where comment count is hidden

Add .card__boosts alongside .card__comments in:
- Tray view (display: none)
- Cards with background images (opacity toggle on hover)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Fix reactions button overlap with zoom button in card footer

When a card has a background image, the footer contains both a reactions
button and a zoom button. Previously they would overlap because the
reactions button was absolutely positioned to the bottom-right.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Tighten up previews

* Move card reactions from meta partial to container

Fixes two issues:

1. Reactions were duplicated each time a card was assigned because the
   turbo stream replaced the meta div with the full perma/meta partial,
   which included reactions outside the replaced element.

2. Draft cards incorrectly showed the boost button because the meta
   partial was shared between published and draft containers.

Moving reactions to _container.html.erb (published cards only) fixes
both issues and keeps the meta partial focused on meta content.

Fixes https://app.fizzy.do/5986089/cards/3837
Fixes https://app.fizzy.do/5986089/cards/3835

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* WIP adjust perma page

* Position and style the footer

* Render the stamp in the card body instead of the footer

* Fix undefined local variable in public cards view

Changed `card` to `@card` when rendering the stamp partial.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Preload card reactions to avoid N+1 queries

Include reactions and their reacters in the preloaded scope, matching
what we already do for comments.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Add model tests for card and comment reaction cleanup

Test that:
- Creating a card reaction touches the card's last_active_at
- Reactions are deleted when their parent comment is destroyed
- Reactions are deleted when their parent card is destroyed

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Minor improvements to reactions code

- Use size instead of count in boosts partial to avoid extra SQL query
  on already-loaded collection
- Add else clause to reaction_path_prefix_for to raise ArgumentError
  for unknown reactable types instead of silently returning nil

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

* Bump specificity of reaction popup in the card perma

---------

Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Andy Smith <andy@37signals.com>
This commit is contained in:
Mike Dalessio
2026-01-23 13:25:55 -05:00
committed by GitHub
parent ffb2a0b82a
commit cb61b36715
41 changed files with 1177 additions and 94 deletions
@@ -0,0 +1,67 @@
require "test_helper"
class Cards::ReactionsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :david
@card = cards(:logo)
end
test "index" do
get card_reactions_path(@card)
assert_response :success
end
test "new" do
get new_card_reaction_path(@card)
assert_response :success
end
test "create" do
assert_difference -> { @card.reactions.count }, 1 do
post card_reactions_path(@card, format: :turbo_stream), params: { reaction: { content: "Great work!" } }
assert_turbo_stream action: :replace, target: dom_id(@card, :reacting)
end
end
test "destroy" do
reaction = reactions(:logo_card_david)
assert_difference -> { @card.reactions.count }, -1 do
delete card_reaction_path(@card, reaction, format: :turbo_stream)
assert_turbo_stream action: :remove, target: dom_id(reaction)
end
end
test "non-owner cannot destroy reaction" do
reaction = reactions(:logo_card_kevin)
assert_no_difference -> { @card.reactions.count } do
delete card_reaction_path(@card, reaction, format: :turbo_stream)
assert_response :forbidden
end
end
test "index as JSON" do
get card_reactions_path(@card), as: :json
assert_response :success
assert_equal @card.reactions.count, @response.parsed_body.count
end
test "create as JSON" do
assert_difference -> { @card.reactions.count }, 1 do
post card_reactions_path(@card), params: { reaction: { content: "👍" } }, as: :json
end
assert_response :created
end
test "destroy as JSON" do
reaction = reactions(:logo_card_david)
assert_difference -> { @card.reactions.count }, -1 do
delete card_reaction_path(@card, reaction), as: :json
end
assert_response :no_content
end
end
+14
View File
@@ -11,3 +11,17 @@ david:
content: "👍"
reactable: logo_agreement_jz_uuid (Comment)
reacter: david_uuid
logo_card_kevin:
id: <%= ActiveRecord::FixtureSet.identify("logo_card_kevin_reaction", :uuid) %>
account: 37s_uuid
content: "🎯"
reactable: logo_uuid (Card)
reacter: kevin_uuid
logo_card_david:
id: <%= ActiveRecord::FixtureSet.identify("logo_card_david_reaction", :uuid) %>
account: 37s_uuid
content: "👍"
reactable: logo_uuid (Card)
reacter: david_uuid
@@ -0,0 +1,31 @@
require "test_helper"
class CardPreviewBoostCountTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :kevin
@card_with_reactions = cards(:logo)
@card_without_reactions = cards(:layout)
@column = @card_with_reactions.column
end
test "card preview displays boost count when card has reactions" do
get board_column_path(@column.board, @column)
assert_response :success
# Check that boost count is displayed for cards with reactions
assert_select ".card__boosts", text: /2/
end
test "card preview does not display boost count when card has no reactions" do
# Ensure layout card is in the same column for this test
@card_without_reactions.update!(column: @column)
get board_column_path(@column.board, @column)
assert_response :success
# Find the card without reactions and verify no boost count is shown
# We check the overall page doesn't have a boost count for zero reactions
# (This is an imperfect test but reasonable given the structure)
assert @card_without_reactions.reactions.none?
end
end
+14
View File
@@ -199,4 +199,18 @@ class CardTest < ActiveSupport::TestCase
assert card.watched_by?(kevin), "Kevin's watch should remain (has board access)"
assert_not card.watched_by?(david), "David's watch should be deleted (no board access)"
end
test "card has reactions association" do
card = cards(:logo)
user = users(:david)
assert_difference "card.reactions.count", +1 do
card.reactions.create!(content: "👍", reacter: user)
end
reaction = card.reactions.last
assert_equal "👍", reaction.content
assert_equal user, reaction.reacter
assert_equal card, reaction.reactable
end
end
+32 -1
View File
@@ -5,9 +5,40 @@ class ReactionTest < ActiveSupport::TestCase
Current.session = sessions(:david)
end
test "creating a reaction touches the card activity" do
test "creating a comment reaction touches the card activity" do
assert_changes -> { cards(:logo).reload.last_active_at } do
comments(:logo_1).reactions.create!(content: "Nice!")
end
end
test "reactions are deleted when comment is destroyed" do
comment = comments(:logo_1)
comment.reactions.create!(content: "👍")
reaction_ids = comment.reactions.pluck(:id)
assert reaction_ids.any?, "Expected comment to have reactions"
comment.destroy
assert_empty Reaction.where(id: reaction_ids)
end
test "creating a card reaction touches the card activity" do
card = cards(:logo)
assert_changes -> { card.reload.last_active_at } do
card.reactions.create!(content: "🎉")
end
end
test "reactions are deleted when card is destroyed" do
card = cards(:logo)
reaction_ids = card.reactions.pluck(:id)
assert reaction_ids.any?, "Expected card to have reactions"
card.destroy
assert_empty Reaction.where(id: reaction_ids)
end
end