Use singular staging resource and beef up testing
This commit is contained in:
@@ -1,20 +1,8 @@
|
||||
class Cards::StagingsController < ApplicationController
|
||||
include CardScoped
|
||||
|
||||
before_action :set_stage
|
||||
|
||||
def create
|
||||
if @stage
|
||||
@card.toggle_stage @stage
|
||||
else
|
||||
@card.update!(stage: nil)
|
||||
end
|
||||
|
||||
def update
|
||||
@card.change_stage_to @collection.workflow.stages.find(params[:stage_id])
|
||||
render_card_replacement
|
||||
end
|
||||
|
||||
private
|
||||
def set_stage
|
||||
@stage = Workflow::Stage.find_by(id: params[:stage_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,8 +2,8 @@ module WorkflowsHelper
|
||||
def button_to_set_stage(card, stage)
|
||||
button_to \
|
||||
tag.span(stage.name, class: "overflow-ellipsis"),
|
||||
card_stagings_path(card, stage_id: stage),
|
||||
method: :post,
|
||||
card_staging_path(card, stage_id: stage),
|
||||
method: :put,
|
||||
class: [ "btn justify-start workflow-stage txt-uppercase workflow-stage", { "workflow-stage--current": stage == card.stage } ],
|
||||
form_class: "flex align-center gap-half",
|
||||
data: { turbo_frame: "_top" }
|
||||
|
||||
@@ -13,12 +13,10 @@ module Card::Staged
|
||||
stage&.workflow
|
||||
end
|
||||
|
||||
def toggle_stage(stage)
|
||||
new_stage, event = self.stage_id == stage.id ? [ nil, :unstaged ] : [ stage, :staged ]
|
||||
|
||||
def change_stage_to(new_stage)
|
||||
transaction do
|
||||
update! stage: new_stage
|
||||
track_event event, stage_id: stage.id, stage_name: stage.name
|
||||
track_event :staged, stage_id: new_stage.id, stage_name: new_stage.name
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
+2
-2
@@ -26,17 +26,17 @@ Rails.application.routes.draw do
|
||||
resources :cards do
|
||||
scope module: :cards do
|
||||
resource :engagement
|
||||
resource :goldness
|
||||
resource :image
|
||||
resource :pin
|
||||
resource :closure
|
||||
resource :publish
|
||||
resource :reading
|
||||
resource :recover
|
||||
resource :staging
|
||||
resource :watch
|
||||
resource :goldness
|
||||
|
||||
resources :assignments
|
||||
resources :stagings
|
||||
resources :taggings
|
||||
|
||||
resources :comments do
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
require "test_helper"
|
||||
|
||||
class Cards::StagingsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
end
|
||||
|
||||
test "update" do
|
||||
put card_staging_path(cards(:logo)), params: { stage_id: workflow_stages(:qa_in_progress).id }, as: :turbo_stream
|
||||
assert_card_container_rerendered(cards(:logo))
|
||||
end
|
||||
end
|
||||
@@ -25,19 +25,5 @@ class CardMessagesTest < ActionDispatch::IntegrationTest
|
||||
assert_predicate card.messages.last, :event_summary?
|
||||
assert_equal 1, card.messages.last.event_summary.events.count
|
||||
assert_equal "assigned", card.messages.last.messageable.events.last.action
|
||||
|
||||
# Stage it
|
||||
post card_stagings_path(card), params: { stage_id: workflow_stages(:qa_triage).id }
|
||||
assert_equal 3, card.messages.count
|
||||
assert_predicate card.messages.last, :event_summary?
|
||||
assert_equal 2, card.messages.last.event_summary.events.count
|
||||
assert_equal "staged", card.messages.last.messageable.events.last.action
|
||||
|
||||
# Unstage it
|
||||
post card_stagings_path(card), params: { stage_id: workflow_stages(:qa_triage).id }
|
||||
assert_equal 3, card.messages.count
|
||||
assert_predicate card.messages.last, :event_summary?
|
||||
assert_equal 3, card.messages.last.event_summary.events.count
|
||||
assert_equal "unstaged", card.messages.last.messageable.events.last.action
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
require "test_helper"
|
||||
|
||||
class Card::StagedTest < ActiveSupport::TestCase
|
||||
setup { Current.session = sessions(:david) }
|
||||
|
||||
test "change stage" do
|
||||
assert_difference -> { Event.where(action: :staged).count }, +1 do
|
||||
cards(:logo).change_stage_to(workflow_stages(:qa_in_progress))
|
||||
assert_equal workflow_stages(:qa_in_progress), cards(:logo).reload.stage
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user