rails_workflow 0.4.3 → 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1d85d2776fc4b5bc25da7f7555318ad088641307
4
- data.tar.gz: 3f7d947d513ec8f4431829329432ca38ec97296d
3
+ metadata.gz: dea54167aac6920c8627f69c61a216dcc2e537e7
4
+ data.tar.gz: 1d2ae941198813cf7b96cc09b6b52f89723c41bd
5
5
  SHA512:
6
- metadata.gz: c8c2b93714080e1ccdf5d687aa4fde94b42d0cca08eac931217d44971439793c421b5d52787a81b46aed66b60e672400be7993aa987ec74d47acbf82494237ef
7
- data.tar.gz: 2871b11611017711cfefba38526fefb1dee5bfe06eaa4a269aa333b8bab6824ed9196d8760b71d90c8808ab71a6bf6331e5d3c5c96284287c23f3c347c7617cd
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 |op|
24
- op.context = build_context(op, completed_dependencies)
25
- # Can add OperationTemplate#after_operation_create callback
26
- template.after_operation_create(op) if template.respond_to?(:after_operation_create)
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
  {
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsWorkflow
4
- VERSION = '0.4.3'
4
+ VERSION = '0.4.4'
5
5
  end
Binary file
@@ -4,6 +4,7 @@ FactoryGirl.define do
4
4
  factory :operation_template, class: 'RailsWorkflow::OperationTemplate' do
5
5
  title 'Operation Template'
6
6
  kind 'default'
7
+ type nil
7
8
  is_background true
8
9
  association :process_template, factory: :process_template
9
10
 
@@ -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.3
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-09 00:00:00.000000000 Z
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