Merge pull request #2795 from urbanrotnik/ur-sci-4932

Default flow, added to seed [SCI-4932]
This commit is contained in:
Urban Rotnik 2020-08-27 11:24:18 +02:00 committed by GitHub
commit fef6c05287
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 0 deletions

View file

@ -21,4 +21,22 @@ class MyModuleStatusFlow < ApplicationRecord
def final_status
my_module_statuses.left_outer_joins(:next_status).find_by('next_statuses_my_module_statuses.id': nil)
end
def self.ensure_default
return if MyModuleStatusFlow.global.any?
status_flow = MyModuleStatusFlow.create!(name: Extends::DEFAULT_FLOW_NAME, visibility: :global)
prev_id = nil
Extends::DEFAULT_FLOW_STATUSES.each do |status|
new_status = MyModuleStatus.create!(my_module_status_flow: status_flow,
name: status[:name],
color: status[:color],
previous_status_id: prev_id)
prev_id = new_status.id
status[:conditions]&.each { |condition| condition.constantize.create!(my_module_status: new_status) }
status[:implications]&.each { |implication| implication.constantize.create!(my_module_status: new_status) }
status[:consequences]&.each { |consequence| consequence.constantize.create!(my_module_status: new_status) }
end
end
end

View file

@ -317,4 +317,12 @@ class Extends
}.freeze
DASHBOARD_BLACKLIST_ACTIVITY_TYPES = %i(export_protocol_in_repository copy_protocol_in_repository).freeze
DEFAULT_FLOW_NAME = 'SciNote Free default task flow'
DEFAULT_FLOW_STATUSES = [
{ name: 'Not started', color: '#406d86' },
{ name: 'In progress', color: '#0065ff' },
{ name: 'Completed', color: '#00b900' }
]
end

View file

@ -1,5 +1,7 @@
include UsersGenerator
MyModuleStatusFlow.ensure_default
if User.count.zero?
if ENV['ADMIN_NAME'].present? &&
ENV['ADMIN_EMAIL'].present? &&

View file

@ -46,4 +46,21 @@ describe MyModuleStatusFlow, type: :model do
it { expect(my_module_team_workflow).to validate_presence_of :team }
end
end
describe 'self.ensure_default' do
context 'when there is no global flow' do
it 'adds new global workflow' do
expect { described_class.ensure_default }
.to change { MyModuleStatusFlow.global.count }.by(1).and(change { MyModuleStatus.count }.by(3))
end
end
context 'when there is global flow' do
it 'adds new global workflow' do
described_class.ensure_default
expect { described_class.ensure_default }.not_to(change { MyModuleStatusFlow.global.count })
end
end
end
end