-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
And fix problems the test finds
- Loading branch information
Showing
6 changed files
with
139 additions
and
125 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
This file was deleted.
Oops, something went wrong.
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,58 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Draw the edit datastream form' do | ||
let(:item) do | ||
instance_double(Dor::Item, pid: 'druid:bc123df4567', datastreams: { 'descMetadata' => datastream }) | ||
end | ||
let(:datastream) do | ||
instance_double(Dor::DescMetadataDS, dsid: 'descMetadata', content: xml) | ||
end | ||
|
||
let(:xml) do | ||
<<~XML | ||
<descMetadata></descMetadata> | ||
XML | ||
end | ||
|
||
let(:document) do | ||
instance_double(SolrDocument, | ||
id: 'druid:bc123df4567', | ||
object_type: 'item', | ||
title: 'My item', | ||
released_to: ['Searchworks']) | ||
end | ||
|
||
let(:user) { create(:user) } | ||
|
||
before do | ||
allow(Dor).to receive(:find).with('druid:bc123df4567').and_return(item) | ||
end | ||
|
||
context 'for content managers' do | ||
before do | ||
sign_in create(:user), groups: ['sdr:administrator-role'] | ||
|
||
allow_any_instance_of(Blacklight::Solr::Repository).to receive(:find) | ||
.with('druid:bc123df4567', {}) | ||
.and_return(instance_double(Blacklight::Solr::Response, documents: [document])) | ||
end | ||
|
||
it 'authorizes the view' do | ||
get '/items/druid:bc123df4567/datastreams/descMetadata/edit', xhr: true | ||
expect(response).to have_http_status(:success) | ||
end | ||
end | ||
|
||
context 'for unauthorized_user' do | ||
before do | ||
sign_in user | ||
end | ||
|
||
it 'returns not found' do | ||
expect { get '/items/druid:bc123df4567/datastreams/descMetadata/edit' } | ||
.to raise_error Blacklight::Exceptions::RecordNotFound | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
|
||
RSpec.describe 'Update a datastream' do | ||
before do | ||
allow(Dor).to receive(:find).with(pid).and_return(item) | ||
allow(item).to receive_messages(save: nil) | ||
allow(Argo::Indexer).to receive(:reindex_pid_remotely) | ||
end | ||
|
||
let(:pid) { 'druid:bc123df4567' } | ||
let(:item) { Dor::Item.new pid: pid } | ||
let(:user) { create(:user) } | ||
let(:state_service) { instance_double(StateService, allows_modification?: true) } | ||
let(:xml) { '<contentMetadata/>' } | ||
let(:invalid_apo_xml) { '<hydra:isGovernedBy rdf:resource="info:fedora/druid:not_exist"/>' } | ||
|
||
context 'without management access' do | ||
before do | ||
sign_in user | ||
end | ||
|
||
it 'prevents access' do | ||
expect(item).not_to receive(:save) | ||
patch "/items/#{pid}/datastreams/contentMetadata", params: { content: xml } | ||
expect(response).to have_http_status(:forbidden) | ||
end | ||
end | ||
|
||
context 'when they have manage access' do | ||
before do | ||
sign_in user, groups: ['sdr:administrator-role'] | ||
end | ||
|
||
it 'updates the datastream' do | ||
expect(item).to receive(:datastreams).and_return( | ||
'contentMetadata' => double(Dor::ContentMetadataDS, 'content=': xml) | ||
) | ||
expect(item).to receive(:save) | ||
patch "/items/#{pid}/datastreams/contentMetadata", params: { content: xml } | ||
expect(response).to have_http_status(:found) | ||
end | ||
|
||
it 'errors on empty xml' do | ||
expect { patch "/items/#{pid}/datastreams/contentMetadata", params: { content: ' ' } }.to raise_error(ArgumentError) | ||
end | ||
|
||
it 'errors on malformed xml' do | ||
expect { patch "/items/#{pid}/datastreams/contentMetadata", params: { content: '<this>isnt well formed.' } }.to raise_error(ArgumentError) | ||
end | ||
end | ||
end |