Merge pull request #413 from basecamp/refactor-workflow-default-stages
Refactor workflow default stages
This commit is contained in:
@@ -10,6 +10,6 @@ class Collections::WorkflowsController < ApplicationController
|
||||
|
||||
private
|
||||
def set_workflow
|
||||
@workflow = Workflow.find(params.expect(collection: [ :workflow_id ]).require(:workflow_id))
|
||||
@workflow = Workflow.find(params[:collection][:workflow_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,8 +11,6 @@ class WorkflowsController < ApplicationController
|
||||
|
||||
def create
|
||||
@workflow = Workflow.create! workflow_params
|
||||
# FIXME: this should definitely change.
|
||||
[ "Triage", "In progress", "On Hold", "Review" ].each { |name| @workflow.stages.create! name: name }
|
||||
redirect_to workflows_path
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
class Workflow < ApplicationRecord
|
||||
DEFAULT_STAGES = [ "Triage", "In progress", "On Hold", "Review" ]
|
||||
|
||||
has_many :stages, dependent: :delete_all
|
||||
|
||||
after_create_commit :create_default_stages
|
||||
|
||||
private
|
||||
def create_default_stages
|
||||
Workflow::Stage.insert_all \
|
||||
DEFAULT_STAGES.collect { |default_stage_name| { workflow_id: id, name: default_stage_name } }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,8 +5,8 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as :kevin
|
||||
|
||||
get users_path
|
||||
assert_match /#{users(:david).name}/, @response.body
|
||||
assert_match /#{users(:kevin).name}/, @response.body
|
||||
assert_in_body users(:david).name
|
||||
assert_in_body users(:kevin).name
|
||||
end
|
||||
|
||||
test "new" do
|
||||
@@ -32,7 +32,7 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as :kevin
|
||||
|
||||
get user_path(users(:david))
|
||||
assert_match /#{users(:david).name}/, @response.body
|
||||
assert_in_body users(:david).name
|
||||
end
|
||||
|
||||
test "update oneself" do
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
require "test_helper"
|
||||
|
||||
class WorkflowsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in_as :kevin
|
||||
end
|
||||
|
||||
test "index" do
|
||||
get workflows_path
|
||||
assert_in_body workflows(:on_call).name
|
||||
end
|
||||
|
||||
test "create" do
|
||||
get new_workflow_path
|
||||
assert_response :success
|
||||
|
||||
assert_difference -> { Workflow.count }, +1 do
|
||||
post workflows_path, params: { workflow: { name: "My new workflow!" } }
|
||||
assert_redirected_to workflows_path
|
||||
end
|
||||
end
|
||||
|
||||
test "show" do
|
||||
get workflow_path(workflows(:on_call))
|
||||
assert_in_body workflows(:on_call).name
|
||||
end
|
||||
|
||||
test "update" do
|
||||
get edit_workflow_path(workflows(:on_call))
|
||||
assert_response :success
|
||||
|
||||
put workflow_path(workflows(:on_call)), params: { workflow: { name: "Monkeyflow!" } }
|
||||
follow_redirect!
|
||||
assert_in_body "Monkeyflow!"
|
||||
end
|
||||
|
||||
test "destroy" do
|
||||
assert_difference -> { Workflow.count }, -1 do
|
||||
delete workflow_path(workflows(:on_call))
|
||||
assert_redirected_to workflows_path
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,8 @@
|
||||
require "test_helper"
|
||||
|
||||
class WorkflowTest < ActiveSupport::TestCase
|
||||
test "create with default stages" do
|
||||
workflow = Workflow.create name: "My New Workflow"
|
||||
assert_equal Workflow::DEFAULT_STAGES.sort, workflow.stages.collect(&:name).sort
|
||||
end
|
||||
end
|
||||
@@ -11,5 +11,15 @@ module ActiveSupport
|
||||
fixtures :all
|
||||
|
||||
include CardTestHelper, ChangeTestHelper, SessionTestHelper
|
||||
|
||||
# FIXME: Remove when upstream in Rails has landed (https://github.com/rails/rails/pull/54938)
|
||||
def assert_in_body(text)
|
||||
assert_match /#{text}/, @response.body
|
||||
end
|
||||
|
||||
# FIXME: Remove when upstream in Rails has landed (https://github.com/rails/rails/pull/54938)
|
||||
def assert_not_in_body(text)
|
||||
assert_no_match /#{text}/, @response.body
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user