Remove DraftCommenting

This commit is contained in:
Jason Zimdars
2025-04-16 19:01:21 -05:00
parent d257cb5fb6
commit 47d0ae98a1
4 changed files with 3 additions and 75 deletions
+1 -1
View File
@@ -1,5 +1,5 @@
class Card < ApplicationRecord
include Assignable, Colored, DraftCommenting, Engageable, Eventable, Golden,
include Assignable, Colored, Engageable, Eventable, Golden,
Messages, Notifiable, Pinnable, Closeable, Scorable, Searchable, Staged,
Statuses, Taggable, Watchable
-33
View File
@@ -1,33 +0,0 @@
module Card::DraftCommenting
extend ActiveSupport::Concern
included do
after_save :capture_draft_comment
end
def draft_comment
find_or_build_initial_comment.body.content
end
def draft_comment=(body)
if body.present?
@draft_comment = body
else
messages.comments.destroy_all
end
end
private
def find_or_build_initial_comment
message = messages.comments.first || messages.new(messageable: Comment.new)
message.comment
end
def capture_draft_comment
if @draft_comment.present?
find_or_build_initial_comment.update! body: @draft_comment, creator: creator
end
@draft_comment = nil
end
end
+2 -4
View File
@@ -36,19 +36,17 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
patch collection_card_path(collections(:writebook), cards(:logo)), params: {
card: {
title: "Logo needs to change",
due_on: 1.week.from_now,
image: fixture_file_upload("moon.jpg", "image/jpeg"),
draft_comment: "Something more in-depth",
description: "Something more in-depth",
tag_ids: [ tags(:mobile).id ] } }
assert_redirected_to collection_card_path(collections(:writebook), cards(:logo))
card = cards(:logo).reload
assert_equal "Logo needs to change", card.title
assert_equal 1.week.from_now.to_date, card.due_on
assert_equal "moon.jpg", card.image.filename.to_s
assert_equal [ tags(:mobile) ], card.tags
assert_equal "Something more in-depth", card.messages.comments.first.comment.body_plain_text.strip
assert_equal "Something more in-depth", card.description_plain_text.strip
end
test "users can only see cards in collections they have access to" do
-37
View File
@@ -6,41 +6,4 @@ class Card::MessagesTest < ActiveSupport::TestCase
assert_empty card.messages
end
test "creating a card with an initial draft comment" do
card = collections(:writebook).cards.create! creator: users(:kevin), title: "New",
draft_comment: "This is a comment"
assert_equal 1, card.messages.count
assert_equal "This is a comment", card.draft_comment.strip
end
test "updating the draft comment" do
card = collections(:writebook).cards.create! creator: users(:kevin), title: "New",
draft_comment: "This is a comment"
card.update! draft_comment: "This is an updated comment"
assert_equal 1, card.messages.count
assert_equal "This is an updated comment", card.draft_comment.strip
end
test "setting the draft comment to be blank removes it" do
card = collections(:writebook).cards.create! creator: users(:kevin), title: "New",
draft_comment: "This is a comment"
card.update! draft_comment: " "
assert card.messages.first.nil?
end
test "omitting the draft comment does not remove it" do
card = collections(:writebook).cards.create! creator: users(:kevin), title: "New",
draft_comment: "This is a comment"
card.update! title: "Newer"
assert_equal 1, card.messages.count
assert_equal "This is a comment", card.draft_comment.strip
end
end