Skip to content

Commit

Permalink
Renamed Card to Task
Browse files Browse the repository at this point in the history
Added creator method for Tasks
  • Loading branch information
rahoulb committed Jun 24, 2024
1 parent c45fc00 commit 8810f42
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 40 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ gem "guard-rspec"
gem "guard-bundler"
gem "yard"
gem "simplecov"
gem "solargraph"
31 changes: 31 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ GEM
remote: https://rubygems.org/
specs:
ast (2.4.2)
backport (1.2.0)
benchmark (0.3.0)
bigdecimal (3.1.8)
coderay (1.1.3)
concurrent-ruby (1.3.1)
Expand Down Expand Up @@ -39,6 +41,7 @@ GEM
dry-inflector (~> 1.0)
dry-logic (~> 1.4)
zeitwerk (~> 2.6)
e2mmap (0.1.0)
faker (3.4.1)
i18n (>= 1.8.11, < 2)
ffi (1.16.3)
Expand All @@ -64,7 +67,12 @@ GEM
i18n (1.14.5)
concurrent-ruby (~> 1.0)
ice_nine (0.11.2)
jaro_winkler (1.6.0)
json (2.7.2)
kramdown (2.4.0)
rexml
kramdown-parser-gfm (1.1.0)
kramdown (~> 2.0)
language_server-protocol (3.17.0.3)
lint_roller (1.1.0)
listen (3.9.0)
Expand All @@ -73,6 +81,8 @@ GEM
lumberjack (1.2.10)
method_source (1.0.0)
nenv (0.3.0)
nokogiri (1.16.6-arm64-darwin)
racc (~> 1.4)
notiffany (0.1.3)
nenv (~> 0.1)
shellany (~> 0.0)
Expand All @@ -89,7 +99,10 @@ GEM
rb-fsevent (0.11.2)
rb-inotify (0.10.1)
ffi (~> 1.0)
rbs (2.8.4)
regexp_parser (2.9.2)
reverse_markdown (2.1.1)
nokogiri
rexml (3.2.8)
strscan (>= 3.0.9)
rspec (3.13.0)
Expand Down Expand Up @@ -129,6 +142,22 @@ GEM
simplecov_json_formatter (~> 0.1)
simplecov-html (0.12.3)
simplecov_json_formatter (0.1.4)
solargraph (0.50.0)
backport (~> 1.2)
benchmark
bundler (~> 2.0)
diff-lcs (~> 1.4)
e2mmap
jaro_winkler (~> 1.5)
kramdown (~> 2.3)
kramdown-parser-gfm (~> 1.1)
parser (~> 3.0)
rbs (~> 2.0)
reverse_markdown (~> 2.0)
rubocop (~> 1.38)
thor (~> 1.0)
tilt (~> 2.0)
yard (~> 0.9, >= 0.9.24)
standard (1.36.0)
language_server-protocol (~> 3.17.0.2)
lint_roller (~> 1.0)
Expand All @@ -146,6 +175,7 @@ GEM
dry-types
strscan (3.1.0)
thor (1.3.1)
tilt (2.3.0)
unicode-display_width (2.5.0)
yard (0.9.36)
zeitwerk (2.6.15)
Expand All @@ -170,6 +200,7 @@ DEPENDENCIES
rake (~> 13.0)
rspec (~> 3.0)
simplecov
solargraph
standard (~> 1.3)
workflows!
yard
Expand Down
2 changes: 1 addition & 1 deletion lib/workflows.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Error < StandardError; end
require_relative "workflows/action"
require_relative "workflows/state"
require_relative "workflows/workflow"
require_relative "workflows/card"
require_relative "workflows/task"
require_relative "workflows/builder"

# @return [Plumbing::Pipe] message queue for broadcasting events
Expand Down
39 changes: 0 additions & 39 deletions lib/workflows/card.rb

This file was deleted.

12 changes: 12 additions & 0 deletions lib/workflows/task.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "dry/struct"

module Workflows
class Task < Dry::Struct
attribute :id, Types::ID
attribute :name, Types::Name
attribute :state, Types::State
end

end
4 changes: 4 additions & 0 deletions lib/workflows/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,9 @@ class Workflow < Dry::Struct
attribute :description, Types::String.default("")
# @return [Array(Workflows::State)]
attribute :states, Types::States

def create_task title:
Workflows.services["workflows.tasks.create"].call title: title
end
end
end
29 changes: 29 additions & 0 deletions spec/workflows/workflow_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require "spec_helper"

RSpec.describe Workflows::Workflow do
context "starting a task" do

WORKFLOW = <<~YML
name: Approvals
states:
- name: Requires review
type: initial
YML

it "creates a new task and sets it to the initial state" do
@task_creator = double "workflows_tasks_create"
Workflows.services["workflows.tasks.create"] = @task_creator

@configuration = {
name: "Workflow",
states: [{ name: "Start", type: "initial"}]
}
@workflow = Workflows::Builder.new(configuration: @configuration).call

@task = double "Workflows::Task"
expect(@task_creator).to receive(:call).with(title: "The title").and_return(@task)

expect(@workflow.create_task(title: "The title")).to eq @task
end
end
end

0 comments on commit 8810f42

Please sign in to comment.