Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions db/migrate/20190110224307_unique_constraint.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

class UniqueConstraint < ActiveRecord::Migration[5.2]
def change
add_index :workflow_steps,
%i[druid version datastream process],
unique: true,
name: 'uk_workflow_steps'
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_01_10_221945) do
ActiveRecord::Schema.define(version: 2019_01_10_224307) do

create_table "workflow_steps", force: :cascade do |t|
t.string "druid", null: false
Expand All @@ -29,6 +29,7 @@
t.string "lane_id", default: "default", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["druid", "version", "datastream", "process"], name: "uk_workflow_steps", unique: true
t.index ["druid", "version"], name: "index_workflow_steps_on_druid_and_version"
t.index ["druid"], name: "index_workflow_steps_on_druid"
end
Expand Down
37 changes: 31 additions & 6 deletions spec/controllers/workflows_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,41 @@
let(:workflow) { 'accessionWF' }
let(:repository) { 'dor' }
let(:request_data) { workflow_create }
let(:client) { double(current_version: '1') }
let(:client) { double(current_version: current_version) }
let(:expected_count) { Nokogiri::XML(workflow_create).xpath('//process').count }

before do
allow(Dor::Services::Client).to receive(:object).with(druid).and_return(client)
end
it 'creates new workflows' do
expect do
put :create, body: request_data, params: { repo: repository, druid: druid, workflow: workflow, format: :xml }
end.to change(WorkflowStep, :count)
.by(Nokogiri::XML(workflow_create).xpath('//process').count)

context 'when no workflows exist' do
let(:current_version) { '1' }

it 'creates new workflows' do
expect do
put :create, body: request_data, params: { repo: repository, druid: druid, workflow: workflow, format: :xml }
end.to change(WorkflowStep, :count)
.by(expected_count)
end
end

context 'when some workflows exist' do
let(:current_version) { '2' }
before do
WorkflowParser.new(
workflow_create,
druid: druid,
repository: repository,
version: '1'
).create_workflow_steps
end

it 'creates new workflows' do
expect do
put :create, body: request_data, params: { repo: repository, druid: druid, workflow: workflow, format: :xml }
end.to change(WorkflowStep, :count)
.by(expected_count)
end
end
end
end