Remove "save as draft"

Removes the creating status completely as well as the abandoned cards system. It will
always resume drafts if they exist, for a given collection and user.

https://app.box-car.com/5986089/cards/2489
This commit is contained in:
Jorge Manrubia
2025-11-02 11:20:16 +01:00
parent efd5c1dba2
commit 9d4dd3b00e
19 changed files with 35 additions and 125 deletions
@@ -21,11 +21,12 @@ class Cards::PublishesControllerTest < ActionDispatch::IntegrationTest
card.drafted!
assert_changes -> { card.reload.published? }, from: false, to: true do
assert_difference -> { Card.creating.count }, +1 do
assert_difference -> { Card.count }, +1 do
post card_publish_path(card, creation_type: "add_another")
end
end
assert_redirected_to Card.creating.last
assert Card.last.drafted?
assert_redirected_to Card.last
end
end
+14 -2
View File
@@ -15,11 +15,23 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
assert_response :success
end
test "create" do
test "create a new draft" do
assert_difference -> { Card.count }, 1 do
post collection_cards_path(collections(:writebook))
end
assert_redirected_to card_path(Card.last)
assert Card.last.drafted?
assert_redirected_to Card.last
end
test "create resumes existing draft if it exists" do
draft = collections(:writebook).cards.create!(creator: users(:kevin), status: :drafted)
assert_no_difference -> { Card.count } do
post collection_cards_path(collections(:writebook))
end
assert_redirected_to draft
end
test "show" do
@@ -1,18 +0,0 @@
require "test_helper"
class Cards::RecoversControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in_as :jz
end
test "create" do
abandoned_card = collections(:writebook).cards.create! creator: users(:kevin)
abandoned_card.update!(title: "An edited title")
unsaved_card = collections(:writebook).cards.create! creator: users(:kevin)
post card_recover_path(unsaved_card)
assert_redirected_to abandoned_card
assert_equal [ abandoned_card ], Card.creating
end
end
+2 -38
View File
@@ -1,12 +1,10 @@
require "test_helper"
class Card::StatusesTest < ActiveSupport::TestCase
test "cards start out in a `creating` state" do
test "cards start out in a `drafted` state" do
card = collections(:writebook).cards.create! creator: users(:kevin), title: "Newly created card"
assert card.creating?
assert_not_includes Card.published_or_drafted_by(users(:kevin)), card
assert_not_includes Card.published_or_drafted_by(users(:jz)), card
assert card.drafted?
end
test "cards are only visible to the creator when drafted" do
@@ -51,38 +49,4 @@ class Card::StatusesTest < ActiveSupport::TestCase
assert_equal card, Event.last.eventable
assert_equal "card_published", Event.last.action
end
test "can_recover_abandoned_creation?" do
card = collections(:writebook).cards.create! creator: users(:kevin)
unsaved_card = collections(:writebook).cards.new creator: users(:kevin)
assert_not unsaved_card.can_recover_abandoned_creation?
card.update!(title: "Something worth keeping")
assert unsaved_card.can_recover_abandoned_creation?
end
test "recover_abandoned_creation" do
card_edited = collections(:writebook).cards.create! creator: users(:kevin)
card_edited.update!(title: "Something worth keeping")
card_not_edited = collections(:writebook).cards.create! creator: users(:kevin)
assert card_not_edited.can_recover_abandoned_creation?
assert_equal card_edited, card_not_edited.recover_abandoned_creation
assert_raises(ActiveRecord::RecordNotFound) { card_not_edited.reload }
end
test "remove_abandoned_creations" do
card_old = collections(:writebook).cards.create! creator: users(:kevin), updated_at: 2.days.ago
card_recent = collections(:writebook).cards.create! creator: users(:kevin)
assert_equal 2, Card.creating.count
Card.remove_abandoned_creations
assert_equal [ card_recent ], Card.creating
end
end