rails_workflow 0.4.3 → 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/concerns/rails_workflow/has_context.rb +18 -0
- data/app/models/rails_workflow/error.rb +1 -1
- data/app/models/rails_workflow/operation.rb +1 -1
- data/app/models/rails_workflow/process.rb +1 -1
- data/lib/rails_workflow/operation_builder.rb +11 -4
- data/lib/rails_workflow/version.rb +1 -1
- data/spec/dummy/log/test.log +0 -0
- data/spec/factories/operation_templates.rb +1 -0
- data/spec/lib/operation_builder_spec.rb +25 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dea54167aac6920c8627f69c61a216dcc2e537e7
|
4
|
+
data.tar.gz: 1d2ae941198813cf7b96cc09b6b52f89723c41bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eb6704ad409c7f714988401587bbc392d3fe93d3bbcf804a9d25d2fa7b8f8f45ebe9f2e3b941d65a3ea48740f5a47f4bca288d3b5321523b97d52a919348c3aa
|
7
|
+
data.tar.gz: 73afc4682184789ade697bcfc02fbf8365af632e07e5b4f0b60dc6b6a11f457bde92b222d1d384cda247bdf963015fcb77e802a35d16cda6f94795b5e915a04f
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'active_support/concern'
|
4
|
+
|
5
|
+
module RailsWorkflow
|
6
|
+
module HasContext
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
included do
|
10
|
+
has_one :context, class_name: 'RailsWorkflow::Context', as: :parent
|
11
|
+
|
12
|
+
after_save :save_context
|
13
|
+
def save_context
|
14
|
+
context&.save
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -3,8 +3,8 @@
|
|
3
3
|
module RailsWorkflow
|
4
4
|
# Stores error information
|
5
5
|
class Error < ActiveRecord::Base
|
6
|
+
include HasContext
|
6
7
|
belongs_to :parent, polymorphic: true, required: false
|
7
|
-
has_one :context, class_name: 'RailsWorkflow::Context', as: :parent
|
8
8
|
scope :unresolved, -> { where('resolved is null or resolved = false') }
|
9
9
|
|
10
10
|
delegate :data, to: :context
|
@@ -8,12 +8,12 @@ module RailsWorkflow
|
|
8
8
|
include OperationStatus
|
9
9
|
include Operations::Dependencies
|
10
10
|
include Operations::Assignments
|
11
|
+
include HasContext
|
11
12
|
|
12
13
|
belongs_to :process, class_name: 'RailsWorkflow::Process'
|
13
14
|
alias parent process
|
14
15
|
belongs_to :template, class_name: 'RailsWorkflow::OperationTemplate'
|
15
16
|
belongs_to :child_process, class_name: 'RailsWorkflow::Process', required: false
|
16
|
-
has_one :context, class_name: 'RailsWorkflow::Context', as: :parent
|
17
17
|
has_many :workflow_errors, class_name: 'RailsWorkflow::Error', as: :parent
|
18
18
|
|
19
19
|
delegate :data, to: :context
|
@@ -5,6 +5,7 @@ module RailsWorkflow
|
|
5
5
|
# all operations, parent operation, context etc.
|
6
6
|
class Process < ActiveRecord::Base
|
7
7
|
include Status
|
8
|
+
include HasContext
|
8
9
|
|
9
10
|
belongs_to :template, class_name: 'RailsWorkflow::ProcessTemplate'
|
10
11
|
has_many :operations, class_name: 'RailsWorkflow::Operation'
|
@@ -13,7 +14,6 @@ module RailsWorkflow
|
|
13
14
|
foreign_key: :child_process_id
|
14
15
|
|
15
16
|
alias parent parent_operation
|
16
|
-
has_one :context, class_name: 'RailsWorkflow::Context', as: :parent
|
17
17
|
has_many :workflow_errors, class_name: 'RailsWorkflow::Error', as: :parent
|
18
18
|
|
19
19
|
delegate :data, to: :context
|
@@ -20,16 +20,23 @@ module RailsWorkflow
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def create_operation!
|
23
|
-
operation = operation_class.create(prepared_attributes) do |
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
operation = operation_class.create(prepared_attributes) do |new_operation|
|
24
|
+
new_operation.context = build_context(
|
25
|
+
new_operation, completed_dependencies
|
26
|
+
)
|
27
|
+
|
28
|
+
after_operation_create(new_operation)
|
27
29
|
end
|
28
30
|
|
29
31
|
build_child_process(operation)
|
30
32
|
operation
|
31
33
|
end
|
32
34
|
|
35
|
+
def after_operation_create(operation)
|
36
|
+
return unless template.respond_to?(:after_operation_create)
|
37
|
+
template.after_operation_create(operation)
|
38
|
+
end
|
39
|
+
|
33
40
|
def prepared_dependencies
|
34
41
|
completed_dependencies.map do |dep|
|
35
42
|
{
|
data/spec/dummy/log/test.log
CHANGED
Binary file
|
@@ -51,6 +51,31 @@ module RailsWorkflow
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
+
context 'operation context data' do
|
55
|
+
it { expect(operation.data).to eq(msg: 'Test message') } # from factory
|
56
|
+
|
57
|
+
context 'custom' do
|
58
|
+
before do
|
59
|
+
new_class = Class.new(RailsWorkflow::OperationTemplate) do
|
60
|
+
def after_operation_create(new_operation)
|
61
|
+
new_operation.data[:new_key] = 'abc'
|
62
|
+
end
|
63
|
+
end
|
64
|
+
stub_const('NewTemplateClass', new_class)
|
65
|
+
end
|
66
|
+
|
67
|
+
let(:operation_template) do
|
68
|
+
create :operation_template,
|
69
|
+
type: 'NewTemplateClass',
|
70
|
+
operation_class: 'RailsWorkflow::UserByGroupOperation'
|
71
|
+
end
|
72
|
+
|
73
|
+
let(:template) { operation_template.becomes(NewTemplateClass) }
|
74
|
+
|
75
|
+
it { expect(operation.data).to include(new_key: 'abc') }
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
54
79
|
context 'should build child process' do
|
55
80
|
let(:parent_template) { create :parent_operation_template }
|
56
81
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_workflow
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxim Madzhuga
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-11-
|
11
|
+
date: 2017-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- Rakefile
|
192
192
|
- app/assets/javascripts/rails_workflow/application.js
|
193
193
|
- app/assets/stylesheets/rails_workflow/application.css
|
194
|
+
- app/concerns/rails_workflow/has_context.rb
|
194
195
|
- app/concerns/rails_workflow/operation_status.rb
|
195
196
|
- app/concerns/rails_workflow/operation_templates/assignments.rb
|
196
197
|
- app/concerns/rails_workflow/operation_templates/dependencies.rb
|