-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract a workspaces controller from objects controller
- Loading branch information
Showing
6 changed files
with
97 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
# Handles API routes for managing the DOR workspace | ||
class WorkspacesController < ApplicationController | ||
before_action :load_item | ||
|
||
rescue_from(DruidTools::SameContentExistsError, DruidTools::DifferentContentExistsError) do |e| | ||
render status: 409, plain: e.message | ||
end | ||
|
||
# POST /v1/objects/:druid/workspace | ||
# and the deprecated: | ||
# POST /v1/objects/:druid/initialize_workspace | ||
def create | ||
WorkspaceService.create(@item, params[:source]) | ||
head :created | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe WorkspacesController do | ||
let(:item) { Dor::Item.new(pid: 'druid:aa123bb4567') } | ||
|
||
before do | ||
login | ||
allow(Dor).to receive(:find).and_return(item) | ||
rights_metadata_xml = Dor::RightsMetadataDS.new | ||
allow(rights_metadata_xml).to receive_messages(ng_xml: Nokogiri::XML('<xml/>')) | ||
allow(item).to receive_messages( | ||
id: 'druid:aa123bb4567', | ||
datastreams: { 'rightsMetadata' => rights_metadata_xml }, | ||
rightsMetadata: rights_metadata_xml, | ||
remove_druid_prefix: 'aa123bb4567' | ||
) | ||
allow(rights_metadata_xml).to receive(:dra_object).and_return(Dor::RightsAuth.parse(Nokogiri::XML('<xml/>'), true)) | ||
end | ||
|
||
describe '#create' do | ||
before do | ||
clean_workspace | ||
end | ||
|
||
after do | ||
clean_workspace | ||
end | ||
|
||
it 'creates a druid tree in the dor workspace for the passed in druid' do | ||
post :create, params: { id: item.pid } | ||
expect(File).to be_directory(TEST_WORKSPACE + '/aa/123/bb/4567') | ||
end | ||
|
||
it 'creates a link in the dor workspace to the path passed in as source' do | ||
post :create, params: { id: item.pid, source: '/some/path' } | ||
expect(File).to be_symlink(TEST_WORKSPACE + '/aa/123/bb/4567/aa123bb4567') | ||
end | ||
|
||
context 'when the link/directory already exists' do | ||
before do | ||
druid = DruidTools::Druid.new(item.pid, TEST_WORKSPACE) | ||
druid.mkdir | ||
end | ||
|
||
it 'returns a 409 Conflict http status code' do | ||
post :create, params: { id: item.pid } | ||
expect(response.status).to eq(409) | ||
expect(response.body).to match(/The directory already exists/) | ||
end | ||
end | ||
|
||
context 'when the workspace already exists with different content' do | ||
before do | ||
druid = DruidTools::Druid.new(item.pid, TEST_WORKSPACE) | ||
druid.mkdir | ||
end | ||
|
||
it 'returns a 409 Conflict http status code' do | ||
post :create, params: { id: item.pid, source: '/some/path' } | ||
expect(response.status).to eq(409) | ||
expect(response.body).to match(/Unable to create link, directory already exists/) | ||
end | ||
end | ||
end | ||
end |