mirror of
https://github.com/ditkrg/workflower-1.git
synced 2026-01-22 13:56:51 +00:00
Rspec Unit tests
This commit is contained in:
parent
1cd56e6a89
commit
b4778982fd
14
.byebug_history
Normal file
14
.byebug_history
Normal file
@ -0,0 +1,14 @@
|
||||
c
|
||||
attrs
|
||||
c
|
||||
attrs
|
||||
attrs["workflow_state"]
|
||||
attrs[:workflow_state]
|
||||
attrs
|
||||
c
|
||||
@current_sequence
|
||||
item
|
||||
c
|
||||
n
|
||||
item
|
||||
@transitions
|
||||
1
.ruby-version
Normal file
1
.ruby-version
Normal file
@ -0,0 +1 @@
|
||||
3.0.0
|
||||
@ -13,6 +13,7 @@ GEM
|
||||
minitest (~> 5.1)
|
||||
tzinfo (~> 1.1)
|
||||
ast (2.4.2)
|
||||
byebug (11.1.3)
|
||||
concurrent-ruby (1.1.8)
|
||||
diff-lcs (1.4.4)
|
||||
i18n (1.8.9)
|
||||
@ -56,9 +57,11 @@ GEM
|
||||
unicode-display_width (1.7.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
x86_64-linux
|
||||
|
||||
DEPENDENCIES
|
||||
byebug
|
||||
rake (~> 13.0)
|
||||
rspec (~> 3.0)
|
||||
rubocop (~> 0.80)
|
||||
|
||||
@ -1,13 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "active_support"
|
||||
|
||||
# Workflower Module Defintion
|
||||
module Workflower
|
||||
mattr_accessor :workflower_state_column_name
|
||||
mattr_accessor :workflow_model
|
||||
mattr_accessor :transition_model
|
||||
mattr_accessor :conditions
|
||||
|
||||
# ActsAsWorkflower Module Definition
|
||||
module ActsAsWorkflower
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
# InstanceMethods
|
||||
module InstanceMethods
|
||||
# mattr_accessor :workflower_base
|
||||
attr_accessor :possible_events, :allowed_events, :allowed_transitions
|
||||
@ -54,7 +60,9 @@ module Workflower
|
||||
end
|
||||
end
|
||||
|
||||
# Class Methods
|
||||
module ClassMethods
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def workflower(options = { workflower_state_column_name: "workflow_state" })
|
||||
if options[:source].blank? || options[:conditions].blank?
|
||||
raise Workflower::WorkflowerError, "Options can't be blank"
|
||||
@ -75,21 +83,20 @@ module Workflower
|
||||
def workflower_abilities
|
||||
load = source.get_workflows.values.flatten.uniq
|
||||
|
||||
unless load.blank?
|
||||
# transitions = load.transitions.where("(metadata->>'roles') IS NOT NULL")
|
||||
transitions = load.select { |item| item.try(:[], :metadata).try(:key?, :roles) }
|
||||
return [] if load.blank?
|
||||
|
||||
roles = transitions.map { |item| item[:metadata][:roles] }.flatten.uniq
|
||||
# transitions = load.transitions.where("(metadata->>'roles') IS NOT NULL")
|
||||
transitions = load.select { |item| item.try(:[], :metadata).try(:key?, :roles) }
|
||||
|
||||
roles_hash = {}
|
||||
roles = transitions.map { |item| item[:metadata][:roles] }.flatten.uniq
|
||||
|
||||
roles.each do |role|
|
||||
roles_hash[role] = transitions.select { |trans| trans[:metadata][:roles].to_a.include?(role) }.map { |item| item[:event] }.uniq
|
||||
end
|
||||
|
||||
roles_hash
|
||||
roles_hash = {}
|
||||
|
||||
roles.each do |role|
|
||||
roles_hash[role] = transitions.select { |trans| trans[:metadata][:roles].to_a.include?(role) }.map { |item| item[:event] }.uniq
|
||||
end
|
||||
|
||||
roles_hash
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@ -2,6 +2,7 @@ module Workflower
|
||||
class Flow
|
||||
attr_accessor :state, :transition_into, :trigger_action_name, :boolean_action_name, :sequence, :downgrade_sequence, :event, :condition, :condition_type, :before_transit, :after_transit, :metadata, :workflow_id, :deviation_id
|
||||
|
||||
# rubocop:disable Metrics/AbcSize
|
||||
def initialize(options)
|
||||
@state = options[:state]
|
||||
@transition_into = options[:transition_into]
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
require "workflower/errors"
|
||||
require "workflower/flow"
|
||||
|
||||
require "byebug"
|
||||
module Workflower
|
||||
class Manager
|
||||
attr_reader :events, :flows_container, :allowed_events
|
||||
|
||||
29
spec/dummy_feature.rb
Normal file
29
spec/dummy_feature.rb
Normal file
@ -0,0 +1,29 @@
|
||||
# A dummy class to showcase the use of the Gem
|
||||
|
||||
require "workflower"
|
||||
require "workflow_source"
|
||||
require "byebug"
|
||||
|
||||
class DummyFeature
|
||||
attr_accessor :workflow_id, :workflow_state, :sequence
|
||||
|
||||
include Workflower::ActsAsWorkflower
|
||||
|
||||
def initialize
|
||||
@workflow_id = 1
|
||||
@workflow_state = "saved"
|
||||
@sequence = 1
|
||||
end
|
||||
|
||||
def self.before_create(method_name)
|
||||
end
|
||||
|
||||
def assign_attributes(attrs)
|
||||
@workflow_state = attrs["workflow_state"]
|
||||
@sequence = attrs["sequence"]
|
||||
end
|
||||
|
||||
workflower source: WorkflowSource.new,
|
||||
workflower_state_column_name: "workflow_state",
|
||||
conditions: { name: "Test Workflow", workflow_model_name: "DummyEntity" }
|
||||
end
|
||||
22
spec/workflow_source.rb
Normal file
22
spec/workflow_source.rb
Normal file
@ -0,0 +1,22 @@
|
||||
class WorkflowSource
|
||||
def initialize
|
||||
@workflows = {
|
||||
"1": [
|
||||
{
|
||||
state: "saved",
|
||||
transition_into: "submitted",
|
||||
event: "submit",
|
||||
sequence: 1
|
||||
}
|
||||
].flatten
|
||||
}
|
||||
end
|
||||
|
||||
def get_workflows
|
||||
@workflows
|
||||
end
|
||||
|
||||
def get_workflows_for_workflow_id(workflow_id)
|
||||
get_workflows[workflow_id.to_s.to_sym]
|
||||
end
|
||||
end
|
||||
@ -1,11 +1,17 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "dummy_feature"
|
||||
|
||||
RSpec.describe Workflower do
|
||||
it "has a version number" do
|
||||
expect(Workflower::VERSION).not_to be nil
|
||||
end
|
||||
|
||||
it "transitions from saved to submitted" do
|
||||
expect(true).to eq(true)
|
||||
@test = DummyFeature.new
|
||||
@test.workflower_initializer
|
||||
|
||||
@test.submit!
|
||||
expect(@test.workflow_state).to eq("submitted")
|
||||
end
|
||||
end
|
||||
|
||||
@ -30,8 +30,9 @@ Gem::Specification.new do |spec|
|
||||
spec.require_paths = ["lib"]
|
||||
|
||||
# Uncomment to register a new dependency of your gem
|
||||
spec.add_dependency 'activesupport', '~> 5.0', '>= 5.0.0.1'
|
||||
|
||||
spec.add_dependency "activesupport", "~> 5.0", ">= 5.0.0.1"
|
||||
spec.add_development_dependency "byebug"
|
||||
|
||||
# For more information and examples about making a new gem, checkout our
|
||||
# guide at: https://bundler.io/guides/creating_gem.html
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user