bizflow 0.0.1

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.
Files changed (96) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +27 -0
  3. data/.rspec +2 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +105 -0
  7. data/Rakefile +2 -0
  8. data/bin/bizflow +28 -0
  9. data/bizflow.gemspec +29 -0
  10. data/lib/bizflow/business_model/handler.rb +13 -0
  11. data/lib/bizflow/business_model/head.rb +34 -0
  12. data/lib/bizflow/business_model/input_action.rb +47 -0
  13. data/lib/bizflow/business_model/process.rb +46 -0
  14. data/lib/bizflow/business_model/simple_wrapper.rb +22 -0
  15. data/lib/bizflow/business_model/task.rb +41 -0
  16. data/lib/bizflow/business_model/task_action.rb +36 -0
  17. data/lib/bizflow/command/build_command.rb +33 -0
  18. data/lib/bizflow/command/clean_command.rb +9 -0
  19. data/lib/bizflow/command/command_helper.rb +19 -0
  20. data/lib/bizflow/command/help_command.rb +11 -0
  21. data/lib/bizflow/command/install_command.rb +16 -0
  22. data/lib/bizflow/command/setup_command.rb +29 -0
  23. data/lib/bizflow/config_generator.rb +16 -0
  24. data/lib/bizflow/data_model/action.rb +22 -0
  25. data/lib/bizflow/data_model/action_blueprint.rb +22 -0
  26. data/lib/bizflow/data_model/handler.rb +16 -0
  27. data/lib/bizflow/data_model/handler_blueprint.rb +17 -0
  28. data/lib/bizflow/data_model/head.rb +16 -0
  29. data/lib/bizflow/data_model/next_action.rb +17 -0
  30. data/lib/bizflow/data_model/next_action_blueprint.rb +17 -0
  31. data/lib/bizflow/data_model/process.rb +31 -0
  32. data/lib/bizflow/data_model/process_blueprint.rb +17 -0
  33. data/lib/bizflow/data_model/task.rb +17 -0
  34. data/lib/bizflow/data_model/task_blueprint.rb +17 -0
  35. data/lib/bizflow/fakes/action.rb +23 -0
  36. data/lib/bizflow/fakes/action_blueprint.rb +24 -0
  37. data/lib/bizflow/fakes/handler.rb +15 -0
  38. data/lib/bizflow/fakes/handler_blueprint.rb +18 -0
  39. data/lib/bizflow/fakes/head.rb +14 -0
  40. data/lib/bizflow/fakes/process.rb +20 -0
  41. data/lib/bizflow/fakes/process_blueprint.rb +14 -0
  42. data/lib/bizflow/fakes/task.rb +16 -0
  43. data/lib/bizflow/fakes/task_blueprint.rb +19 -0
  44. data/lib/bizflow/interpreters/domain_interpreter.rb +19 -0
  45. data/lib/bizflow/interpreters/input_action_interpreter.rb +35 -0
  46. data/lib/bizflow/interpreters/process_interpreter.rb +37 -0
  47. data/lib/bizflow/interpreters/task_action_interpreter.rb +29 -0
  48. data/lib/bizflow/lib/blueprint_builder.rb +90 -0
  49. data/lib/bizflow/lib/callback_handler.rb +27 -0
  50. data/lib/bizflow/lib/callbackable.rb +25 -0
  51. data/lib/bizflow/lib/process_builder.rb +61 -0
  52. data/lib/bizflow/lib/semantic_builder.rb +36 -0
  53. data/lib/bizflow/migrations/001_create_processes.rb +21 -0
  54. data/lib/bizflow/migrations/002_create_actions.rb +17 -0
  55. data/lib/bizflow/migrations/003_create_process_heads.rb +15 -0
  56. data/lib/bizflow/migrations/004_create_tasks.rb +16 -0
  57. data/lib/bizflow/migrations/005_create_process_blueprints.rb +14 -0
  58. data/lib/bizflow/migrations/006_action_blueprints.rb +16 -0
  59. data/lib/bizflow/migrations/007_next_action_blueprints.rb +14 -0
  60. data/lib/bizflow/migrations/008_handler_blueprints.rb +15 -0
  61. data/lib/bizflow/migrations/009_task_blueprints.rb +16 -0
  62. data/lib/bizflow/migrations/010_create_handlers.rb +16 -0
  63. data/lib/bizflow/migrations/011_next_actions.rb +14 -0
  64. data/lib/bizflow/monkey_patch.rb +12 -0
  65. data/lib/bizflow/repos/repo.rb +21 -0
  66. data/lib/bizflow/semantic_model/action.rb +29 -0
  67. data/lib/bizflow/semantic_model/domain_repo.rb +19 -0
  68. data/lib/bizflow/semantic_model/handler.rb +21 -0
  69. data/lib/bizflow/semantic_model/input_action.rb +19 -0
  70. data/lib/bizflow/semantic_model/process.rb +29 -0
  71. data/lib/bizflow/semantic_model/task.rb +18 -0
  72. data/lib/bizflow/semantic_model/task_action.rb +26 -0
  73. data/lib/bizflow/source_generator.rb +62 -0
  74. data/lib/bizflow/source_presenters/process_template_presenter.rb +26 -0
  75. data/lib/bizflow/templates/js/descriptor.tt +9 -0
  76. data/lib/bizflow/templates/js/process.tt +41 -0
  77. data/lib/bizflow/templates/rb/config.tt +11 -0
  78. data/lib/bizflow/templates/rb/handler.tt +4 -0
  79. data/lib/bizflow/templates/rb/process.tt +53 -0
  80. data/lib/bizflow/version.rb +3 -0
  81. data/lib/bizflow.rb +15 -0
  82. data/spec/factories/factories.rb +38 -0
  83. data/spec/spec_config.rb +42 -0
  84. data/spec/spec_helper.rb +89 -0
  85. data/spec/unit/business/business_process_spec.rb +203 -0
  86. data/spec/unit/business/process_alternative_spec.rb +77 -0
  87. data/spec/unit/command/build_order_spec.rb +44 -0
  88. data/spec/unit/command/build_spec.rb +44 -0
  89. data/spec/unit/creating_processes_spec.rb +59 -0
  90. data/spec/unit/dsl_scripts/breakfast/process_file.rb +50 -0
  91. data/spec/unit/dsl_scripts/order/order.rb +41 -0
  92. data/spec/unit/interpreters/interpreters_spec.rb +105 -0
  93. data/text/Master.odt +0 -0
  94. data/text/prezentacija.odp +0 -0
  95. data/text/zbornik.doc +0 -0
  96. metadata +248 -0
@@ -0,0 +1,38 @@
1
+ # This will guess the User class
2
+ FactoryGirl.define do
3
+
4
+ to_create { |instance| instance.save }
5
+
6
+ factory :process_bp , class: Bizflow::DataModel::ProcessBlueprint do
7
+ sequence(:name) { |n| "process_blueprint#{n}" }
8
+ start "action_blueprint1"
9
+ end
10
+
11
+ factory :input_bp, class: Bizflow::DataModel::ActionBlueprint do
12
+ sequence(:name) { |n| "input_action_blueprint#{n}" }
13
+ type "input"
14
+ end
15
+
16
+ factory :action_bp , class: Bizflow::DataModel::ActionBlueprint do
17
+ sequence(:name) { |n| "action_blueprint#{n}" }
18
+ type "task"
19
+ end
20
+
21
+ factory :task_bp , class: Bizflow::DataModel::TaskBlueprint do
22
+ sequence(:name) { |n| "task_blueprint#{n}" }
23
+ end
24
+
25
+ factory :process , class: Bizflow::DataModel::Process do
26
+ sequence(:name) { |n| "process#{n}" }
27
+ end
28
+
29
+ factory :action , class: Bizflow::DataModel::Action do
30
+ sequence(:name) { |n| "action#{n}" }
31
+ end
32
+
33
+ factory :next_action_bp, class: Bizflow::DataModel::NextActionBlueprint do
34
+
35
+ end
36
+
37
+
38
+ end
@@ -0,0 +1,42 @@
1
+ require "rubygems"
2
+ require "sequel"
3
+ require "database_cleaner"
4
+ require "factory_girl"
5
+
6
+ # using the sqlite memory database
7
+ Sequel::Model.db = Sequel.sqlite(':memory:')
8
+
9
+ # migrate and require all data models
10
+ Sequel.extension :migration, :core_extensions
11
+ Sequel::Migrator.run(Sequel::Model.db, File.expand_path("#{File.expand_path(File.dirname(__FILE__))}/../lib/bizflow/migrations"), :use_transactions=>false)
12
+
13
+ Dir["#{File.dirname(__FILE__)}/../lib/bizflow/data_model/*.rb"].each { |path| require_relative path }
14
+
15
+ FactoryGirl.find_definitions
16
+
17
+ RSpec.configure do |config|
18
+
19
+ config.include FactoryGirl::Syntax::Methods
20
+
21
+ config.before(:suite) do
22
+
23
+ # set database clean type
24
+ DatabaseCleaner.strategy = :transaction
25
+ DatabaseCleaner.clean_with(:truncation)
26
+
27
+ # lint
28
+ # DatabaseCleaner.start
29
+ # FactoryGirl.lint
30
+ # DatabaseCleaner.clean
31
+
32
+ end
33
+
34
+ config.before(:each) do
35
+ DatabaseCleaner.start
36
+ end
37
+
38
+ config.after(:each) do
39
+ DatabaseCleaner.clean
40
+ end
41
+
42
+ end
@@ -0,0 +1,89 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause this
4
+ # file to always be loaded, without a need to explicitly require it in any files.
5
+ #
6
+ # Given that it is always loaded, you are encouraged to keep this file as
7
+ # light-weight as possible. Requiring heavyweight dependencies from this file
8
+ # will add to the boot time of your test suite on EVERY test run, even for an
9
+ # individual file that may not need all of that loaded. Instead, consider making
10
+ # a separate helper file that requires the additional dependencies and performs
11
+ # the additional setup, and require it from the spec files that actually need it.
12
+ #
13
+ # The `.rspec` file also contains a few flags that are not defaults but that
14
+ # users commonly want.
15
+ #
16
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
17
+ RSpec.configure do |config|
18
+ # rspec-expectations config goes here. You can use an alternate
19
+ # assertion/expectation library such as wrong or the stdlib/minitest
20
+ # assertions if you prefer.
21
+ config.expect_with :rspec do |expectations|
22
+ # This option will default to `true` in RSpec 4. It makes the `description`
23
+ # and `failure_message` of custom matchers include text for helper methods
24
+ # defined using `chain`, e.g.:
25
+ # be_bigger_than(2).and_smaller_than(4).description
26
+ # # => "be bigger than 2 and smaller than 4"
27
+ # ...rather than:
28
+ # # => "be bigger than 2"
29
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
30
+ end
31
+
32
+ # rspec-mocks config goes here. You can use an alternate test double
33
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
34
+ config.mock_with :rspec do |mocks|
35
+ # Prevents you from mocking or stubbing a method that does not exist on
36
+ # a real object. This is generally recommended, and will default to
37
+ # `true` in RSpec 4.
38
+ mocks.verify_partial_doubles = true
39
+ end
40
+
41
+ # The settings below are suggested to provide a good initial experience
42
+ # with RSpec, but feel free to customize to your heart's content.
43
+ =begin
44
+ # These two settings work together to allow you to limit a spec run
45
+ # to individual examples or groups you care about by tagging them with
46
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
47
+ # get run.
48
+ config.filter_run :focus
49
+ config.run_all_when_everything_filtered = true
50
+
51
+ # Limits the available syntax to the non-monkey patched syntax that is recommended.
52
+ # For more details, see:
53
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
54
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
55
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
56
+ config.disable_monkey_patching!
57
+
58
+ # This setting enables warnings. It's recommended, but in some cases may
59
+ # be too noisy due to issues in dependencies.
60
+ config.warnings = true
61
+
62
+ # Many RSpec users commonly either run the entire suite or an individual
63
+ # file, and it's useful to allow more verbose output when running an
64
+ # individual spec file.
65
+ if config.files_to_run.one?
66
+ # Use the documentation formatter for detailed output,
67
+ # unless a formatter has already been configured
68
+ # (e.g. via a command-line flag).
69
+ config.default_formatter = 'doc'
70
+ end
71
+
72
+ # Print the 10 slowest examples and example groups at the
73
+ # end of the spec run, to help surface which specs are running
74
+ # particularly slow.
75
+ config.profile_examples = 10
76
+
77
+ # Run specs in random order to surface order dependencies. If you find an
78
+ # order dependency and want to debug it, you can fix the order by providing
79
+ # the seed, which is printed after each run.
80
+ # --seed 1234
81
+ config.order = :random
82
+
83
+ # Seed global randomization in this process using the `--seed` CLI option.
84
+ # Setting this allows you to use `--seed` to deterministically reproduce
85
+ # test failures related to randomization by passing the same `--seed` value
86
+ # as the one that triggered the failure.
87
+ Kernel.srand config.seed
88
+ =end
89
+ end
@@ -0,0 +1,203 @@
1
+ require "spec_config"
2
+
3
+ require "bizflow/lib/process_builder"
4
+ require "bizflow/business_model/process"
5
+ require "bizflow/business_model/task"
6
+ require "bizflow/business_model/task_action"
7
+ require "bizflow/business_model/input_action"
8
+
9
+ describe Bizflow::BusinessModel::Process, process: true do
10
+
11
+ before :each do
12
+
13
+ # schema
14
+ process_bp = create(:process_bp, name: "process1", start: "action0")
15
+
16
+ action_bp0 = create(:input_bp, process_blueprint: process_bp, name: "action0")
17
+ action_bp1 = create(:action_bp, process_blueprint: process_bp, name: "action1")
18
+ action_bp2 = create(:action_bp, process_blueprint: process_bp, name: "action2")
19
+ action_bp3 = create(:action_bp, process_blueprint: process_bp, name: "action3")
20
+
21
+ create(:next_action_bp, action_blueprint: action_bp0, next_blueprint: action_bp1, ending: "action1")
22
+ create(:next_action_bp, action_blueprint: action_bp0, next_blueprint: action_bp2, ending: "action2")
23
+
24
+ create(:next_action_bp, action_blueprint: action_bp1, next_blueprint: action_bp2)
25
+ create(:next_action_bp, action_blueprint: action_bp2, next_blueprint: action_bp3)
26
+
27
+ task_bp1 = create(:task_bp, action_blueprint: action_bp1, name: "task1")
28
+ task_bp2 = create(:task_bp, action_blueprint: action_bp1, name: "task2")
29
+ task_bp3 = create(:task_bp, action_blueprint: action_bp2, name: "task3")
30
+ task_bp4 = create(:task_bp, action_blueprint: action_bp3, name: "task4")
31
+
32
+ # actual process
33
+ @process = Bizflow::Lib::ProcessBuilder.new.build(process_bp.id, 1)
34
+ @b_process = Bizflow::BusinessModel::Process.new(@process)
35
+ end
36
+
37
+ it "moves its head to right positions as it progresses" do
38
+
39
+ # given
40
+ actions = @b_process.actions
41
+
42
+ expect(@b_process.current).to eq nil
43
+
44
+ # when
45
+ @b_process.start(13) do |on|
46
+
47
+ on.success { |r|
48
+
49
+ }
50
+
51
+ on.already_started { |res|
52
+ raise "test failed"
53
+ }
54
+
55
+ end
56
+
57
+ # then
58
+ expect( @b_process.finished_at ).to be nil
59
+ expect( @b_process.current.name ).to eq "action0"
60
+
61
+ # when
62
+ Bizflow::BusinessModel::InputAction.wrap(@b_process.current).submit_input("action2") do |on|
63
+
64
+ on.bad_input { |res|
65
+ raise res[:message]
66
+ }
67
+
68
+ on.not_active { |res|
69
+ raise res[:message]
70
+ }
71
+
72
+ on.success {
73
+
74
+ }
75
+
76
+ end
77
+
78
+ @b_process.reload
79
+
80
+ # then
81
+ expect(@b_process.current).to eq actions[2]
82
+
83
+ # when
84
+ Bizflow::BusinessModel::TaskAction.wrap(@b_process.current).finish
85
+ @b_process.reload
86
+
87
+ # then
88
+ expect(@b_process.current).to eq actions[3]
89
+
90
+ # when
91
+ Bizflow::BusinessModel::TaskAction.wrap(@b_process.current).finish
92
+ @b_process.reload
93
+
94
+ # then
95
+ expect(@b_process.current).to eq actions[3]
96
+ expect(@b_process.finished_at).to_not be nil
97
+
98
+ end
99
+
100
+ it "creates tasks as it progresses by finishing tasks" do
101
+
102
+ # when
103
+ @b_process.start(12) do |on|
104
+
105
+ on.success { |res|
106
+
107
+ }
108
+
109
+ on.already_started { |res|
110
+ raise "test failed"
111
+ }
112
+
113
+ end
114
+
115
+ # then
116
+ tasks = Bizflow::DataModel::Task.where(finished_at: nil)
117
+ expect(tasks.map(&:name)).to eq []
118
+
119
+ # when
120
+ Bizflow::BusinessModel::InputAction.wrap(@b_process.current).submit_input("action2") do |on|
121
+ on.bad_input { |res|
122
+ raise res[:message]
123
+ }
124
+
125
+ on.not_active { |res|
126
+ raise res[:message]
127
+ }
128
+
129
+ on.success {
130
+
131
+ }
132
+
133
+ end
134
+
135
+ # then
136
+ tasks = Bizflow::DataModel::Task.where(finished_at: nil)
137
+ expect(tasks.map(&:name)).to eq ["task3"]
138
+
139
+ # when
140
+ Bizflow::BusinessModel::Task.wraps(tasks).each do |bt|
141
+ bt.finish(41) do |on|
142
+
143
+ on.success {
144
+
145
+ }
146
+
147
+ on.already_finished { |res|
148
+ raise res[:message]
149
+ }
150
+
151
+ end
152
+
153
+ end
154
+
155
+ # then
156
+ tasks = Bizflow::DataModel::Task.where(finished_at: nil)
157
+ expect(tasks.map(&:name)).to eq ["task4"]
158
+
159
+ # when
160
+ Bizflow::BusinessModel::Task.wraps(tasks).each do |bt|
161
+ bt.finish(41) do |on|
162
+
163
+ on.success {
164
+
165
+ }
166
+
167
+ on.already_finished {
168
+
169
+ }
170
+
171
+ end
172
+
173
+ end
174
+
175
+ # then
176
+ tasks = Bizflow::DataModel::Task.where(finished_at: nil)
177
+ expect(tasks.map(&:name)).to eq []
178
+ @b_process.reload
179
+ expect(@b_process.finished_at).to_not be nil
180
+
181
+ end
182
+
183
+ it "follows runned_at, jumped_at times" do
184
+
185
+ @b_process.start(12) do |on|
186
+
187
+ on.success { |res|
188
+
189
+ }
190
+
191
+ on.already_started { |res|
192
+ raise "test failed"
193
+ }
194
+
195
+ end
196
+
197
+ expect(@b_process.runned_at).to_not be nil
198
+
199
+ Bizflow::BusinessModel::TaskAction.wrap(@b_process.actions[0]).finish
200
+
201
+ end
202
+
203
+ end
@@ -0,0 +1,77 @@
1
+ require "spec_config"
2
+
3
+ require "bizflow/lib/process_builder"
4
+ require "bizflow/business_model/process"
5
+ require "bizflow/business_model/task"
6
+ require "bizflow/business_model/task_action"
7
+ require "bizflow/business_model/input_action"
8
+
9
+ describe Bizflow::BusinessModel::Process, process: true do
10
+
11
+ before :each do
12
+
13
+ # schema
14
+ process_bp = create(:process_bp, name: "process1", start: "action0")
15
+
16
+ action_bp0 = create(:input_bp, process_blueprint: process_bp, name: "action0")
17
+ action_bp1 = create(:action_bp, process_blueprint: process_bp, name: "action1")
18
+ action_bp2 = create(:action_bp, process_blueprint: process_bp, name: "action2")
19
+ action_bp3 = create(:action_bp, process_blueprint: process_bp, name: "action3")
20
+
21
+ create(:next_action_bp, action_blueprint: action_bp0, next_blueprint: action_bp1, ending: "action1")
22
+ create(:next_action_bp, action_blueprint: action_bp0, next_blueprint: action_bp2, ending: "action2")
23
+
24
+ create(:next_action_bp, action_blueprint: action_bp1, next_blueprint: action_bp2)
25
+ create(:next_action_bp, action_blueprint: action_bp2, next_blueprint: action_bp3)
26
+
27
+ task_bp1 = create(:task_bp, action_blueprint: action_bp1, name: "task1")
28
+ task_bp2 = create(:task_bp, action_blueprint: action_bp1, name: "task2")
29
+ task_bp3 = create(:task_bp, action_blueprint: action_bp2, name: "task3")
30
+ task_bp4 = create(:task_bp, action_blueprint: action_bp3, name: "task4")
31
+
32
+ # actual process
33
+ @process = Bizflow::Lib::ProcessBuilder.new.build(process_bp.id, 1)
34
+ @bp = Bizflow::BusinessModel::Process.new(@process)
35
+ end
36
+
37
+ it "moves its head to right positions as it progresses" do
38
+
39
+ actions = @bp.actions
40
+
41
+ # given
42
+ expect(@bp.current).to eq nil
43
+ random_user_id = 12
44
+ res = nil
45
+
46
+ # when
47
+ @bp.start(random_user_id) do |on|
48
+
49
+ on.success { |r|
50
+ res = r[:message]
51
+ }
52
+
53
+ on.already_started { |r|
54
+ res = r[:message]
55
+ }
56
+
57
+ end
58
+
59
+ expect(res).to eq "process started successfully"
60
+
61
+ @bp.start(random_user_id) do |on|
62
+
63
+ on.success { |r|
64
+ res = r[:message]
65
+ }
66
+
67
+ on.already_started { |r|
68
+ res = r[:message]
69
+ }
70
+
71
+ end
72
+
73
+ expect(res).to eq "process has already been started"
74
+
75
+ end
76
+
77
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_config"
2
+ require "bizflow/lib/blueprint_builder"
3
+ require "bizflow/lib/semantic_builder"
4
+
5
+ describe "build command", command: true do
6
+
7
+ before :each do
8
+
9
+ @repo = Bizflow::SemanticModel::DomainRepo.new
10
+ builder = Bizflow::Lib::SemanticBuilder.new(File.expand_path("#{File.dirname(__FILE__)}/../dsl_scripts/order"))
11
+ builder.repo = @repo
12
+ builder.build
13
+
14
+ end
15
+
16
+ it "persists process blueprints" do
17
+
18
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
19
+ expect(Bizflow::DataModel::ProcessBlueprint.count).to eq 1
20
+
21
+ end
22
+
23
+ it "persists action blueprints" do
24
+
25
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
26
+ expect(Bizflow::DataModel::ActionBlueprint.count).to eq 4
27
+
28
+ end
29
+
30
+ it "persists next_action blueprints" do
31
+
32
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
33
+ expect(Bizflow::DataModel::NextActionBlueprint.count).to eq 5
34
+
35
+ end
36
+
37
+ it "persists task blueprints" do
38
+
39
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
40
+ expect(Bizflow::DataModel::TaskBlueprint.count).to eq 4
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,44 @@
1
+ require "spec_config"
2
+ require "bizflow/lib/blueprint_builder"
3
+ require "bizflow/lib/semantic_builder"
4
+
5
+ describe "build command", command: true do
6
+
7
+ before :each do
8
+
9
+ @repo = Bizflow::SemanticModel::DomainRepo.new
10
+ builder = Bizflow::Lib::SemanticBuilder.new(File.expand_path("#{File.dirname(__FILE__)}/../dsl_scripts/breakfast"))
11
+ builder.repo = @repo
12
+ builder.build
13
+
14
+ end
15
+
16
+ it "persists process blueprints" do
17
+
18
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
19
+ expect(Bizflow::DataModel::ProcessBlueprint.count).to eq 1
20
+
21
+ end
22
+
23
+ it "persists action blueprints" do
24
+
25
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
26
+ expect(Bizflow::DataModel::ActionBlueprint.count).to eq 4
27
+
28
+ end
29
+
30
+ it "persists next_action blueprints" do
31
+
32
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
33
+ expect(Bizflow::DataModel::NextActionBlueprint.count).to eq 5
34
+
35
+ end
36
+
37
+ it "persists task blueprints" do
38
+
39
+ Bizflow::Lib::BlueprintBuilder.new.build(@repo)
40
+ expect(Bizflow::DataModel::TaskBlueprint.count).to eq 6
41
+
42
+ end
43
+
44
+ end
@@ -0,0 +1,59 @@
1
+ require "spec_config"
2
+
3
+ require "bizflow/business_model/process"
4
+ require "bizflow/business_model/task_action"
5
+ require 'bizflow/lib/process_builder'
6
+
7
+ describe Bizflow::BusinessModel::Process, process: true do
8
+
9
+ before(:each) do
10
+
11
+ @process_bp = create(:process_bp, name: "new_process", start: "action_0")
12
+
13
+ action_bp0 = create(:input_bp, process_blueprint: @process_bp, name: "action_0", question: "Is there enaugh something?")
14
+ action_bp1 = create(:action_bp, process_blueprint: @process_bp, name: "action_1")
15
+ action_bp2 = create(:action_bp, process_blueprint: @process_bp, name: "action_2")
16
+ action_bp3 = create(:action_bp, process_blueprint: @process_bp, name: "action_3")
17
+
18
+ create(:next_action_bp, action_blueprint: action_bp0, next_blueprint: action_bp1, ending: "action_1")
19
+ create(:next_action_bp, action_blueprint: action_bp0, next_blueprint: action_bp2, ending: "action_2")
20
+
21
+ create(:next_action_bp, action_blueprint: action_bp1, next_blueprint: action_bp2)
22
+ create(:next_action_bp, action_blueprint: action_bp2, next_blueprint: action_bp3)
23
+
24
+ @process_builder = Bizflow::Lib::ProcessBuilder.new
25
+
26
+ end
27
+
28
+ it "creates and prepares a new process via #build" do
29
+
30
+ process = @process_builder.build(@process_bp.id, 1)
31
+
32
+ expect(Bizflow::DataModel::Process.count).to eq 1
33
+ expect(process.name).to eq "new_process"
34
+ expect(process.pid).to_not be nil
35
+
36
+ p = Bizflow::DataModel::Process.first
37
+
38
+ expect(Bizflow::DataModel::Action.count).to eq 4
39
+ expect(p.actions.count).to eq 4
40
+ expect(p.actions.map(&:name)).to eq ["action_0", "action_1", "action_2", "action_3"]
41
+ expect(p.actions.map(&:type)).to eq ["input", "task", "task", "task"]
42
+ expect(p.actions.map(&:question)).to eq ["Is there enaugh something?", nil, nil, nil]
43
+
44
+ biz_actions = Bizflow::BusinessModel::TaskAction.wraps(p.actions)
45
+ expect(biz_actions[0].next_actions.map(&:next)).to eq [p.actions[1], p.actions[2]]
46
+ expect(biz_actions[0].next_actions.map(&:ending)).to eq ["action_1", "action_2"]
47
+
48
+
49
+ expect(biz_actions[1].next_action).to eq p.actions[2]
50
+
51
+ heads = Bizflow::DataModel::Head.all
52
+ expect(heads.count).to eq 1
53
+ expect(p.heads.count).to eq 1
54
+
55
+ expect(p.start_action_id).to eq p.actions[0].id
56
+
57
+ end
58
+
59
+ end
@@ -0,0 +1,50 @@
1
+
2
+ process "make_breakfast" do
3
+
4
+ description "creates breakfast"
5
+
6
+ start "check_supplies"
7
+
8
+ input_action "check_supplies" do
9
+
10
+ description "checks if there are enaugh eggs, bacon and bread"
11
+ question "Are there enaugh supplies?"
12
+
13
+ next_actions(
14
+ not_enaugh_supplies: "get_supplies",
15
+ enaugh_supplies: "make_breakfast"
16
+ )
17
+
18
+ end
19
+
20
+ task_action "get_supplies" do
21
+
22
+ description "get enaugh eggs, bacon and bread"
23
+ task "get_bacon", roles: ["storage", "kitchen"], description: "optional description", auto_assign: true
24
+ task "get_eggs", roles: ["storage", "kitchen"]
25
+ task "get_bread", roles: ["storage"]
26
+
27
+ next_action "make_breakfast"
28
+
29
+ end
30
+
31
+ task_action "make_breakfast" do
32
+
33
+ description "sets stove, fry eggs, roast bacon"
34
+ task "make_breakfast", roles: ["kitchen"]
35
+
36
+ next_action "serve_breakfast"
37
+
38
+ end
39
+
40
+ task_action "serve_breakfast" do
41
+
42
+ task "prepare_table", roles: ["servers"]
43
+ task "slice_bread", roles: ["kitchen"]
44
+
45
+ next_action "process:finish"
46
+
47
+ end
48
+
49
+
50
+ end
@@ -0,0 +1,41 @@
1
+ process "narucivanje_jela" do
2
+
3
+ description "proces za narucivanje jela"
4
+ start "narucivanje_jela"
5
+
6
+ task_action "narucivanje_jela" do
7
+
8
+ description "klijent bira jelo"
9
+ input_task "odabir_jela", roles: ["klijent"]
10
+ input_task "izbor_lokacije",roles: ["klijent"]
11
+ next_action "priprema_jela"
12
+
13
+ end
14
+
15
+ task_action "priprema_jela" do
16
+
17
+ description "priprema narucenog jela"
18
+ task "priprema_jela", roles: ["kuhinja"]
19
+ next_action "isporuka_jela"
20
+
21
+ end
22
+
23
+ task_action "isporuka_jela" do
24
+
25
+ task "isporuka_jela", roles: ["dostavljac"]
26
+ next_action "provera_jela"
27
+
28
+ end
29
+
30
+ input_action "provera_jela" do
31
+
32
+ question "Da li je sve u redu sa jelom?"
33
+ roles ["klijent", "sef_kuhinje"]
34
+ next_actions(
35
+ ok: "process:success",
36
+ nije_ok: "priprema_jela"
37
+ )
38
+
39
+ end
40
+
41
+ end