diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 26c40c873..8f7cf5b5e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-07-01 21:29:33 UTC using RuboCop version 0.86.0. +# on 2020-07-06 17:37:04 UTC using RuboCop version 0.86.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -47,52 +47,29 @@ Metrics/AbcSize: Max: 82 # Offense count: 5 -# Configuration parameters: CountComments, Max. +# Configuration parameters: CountComments. Metrics/ClassLength: - Exclude: - - 'app/controllers/apo_controller.rb' - - 'app/controllers/catalog_controller.rb' - - 'app/forms/apo_form.rb' - - 'app/models/user_log.rb' - - 'app/presenters/buttons_presenter.rb' + Max: 173 # Offense count: 11 -# Configuration parameters: IgnoredMethods, Max. +# Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: - Exclude: - - 'app/controllers/tags_controller.rb' - - 'app/forms/registration_form.rb' - - 'app/helpers/value_helper.rb' - - 'app/models/ability.rb' - - 'app/models/report.rb' - - 'app/models/track_sheet.rb' - - 'app/models/user.rb' - - 'app/models/user_log.rb' - - 'app/presenters/buttons_presenter.rb' - - 'app/services/apply_mods_metadata.rb' - - 'spec/support/fixtures.rb' + Max: 14 -# Offense count: 74 +# Offense count: 80 # Configuration parameters: CountComments, ExcludedMethods. Metrics/MethodLength: Max: 50 # Offense count: 3 -# Configuration parameters: Max, CountKeywordArgs. +# Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: - Exclude: - - 'app/components/action_button.rb' - - 'app/jobs/modsulator_job.rb' - - 'app/services/apply_mods_metadata.rb' + Max: 7 # Offense count: 4 -# Configuration parameters: IgnoredMethods, Max. +# Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: - Exclude: - - 'app/models/ability.rb' - - 'app/models/track_sheet.rb' - - 'app/presenters/buttons_presenter.rb' - - 'app/services/apply_mods_metadata.rb' + Max: 12 # Offense count: 1 Naming/AccessorMethodName: @@ -106,14 +83,7 @@ Naming/MemoizedInstanceVariableName: Exclude: - 'config/initializers/okcomputer.rb' -# Offense count: 1 -# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames. -# AllowedNames: io, id, to, by, on, in, at, ip, db, os, pp -Naming/MethodParameterName: - Exclude: - - 'app/helpers/dor_object_helper.rb' - -# Offense count: 16 +# Offense count: 17 RSpec/AnyInstance: Exclude: - 'spec/controllers/bulk_actions_controller_spec.rb' @@ -124,20 +94,21 @@ RSpec/AnyInstance: - 'spec/features/enable_buttons_spec.rb' - 'spec/features/item_registration_spec.rb' - 'spec/features/set_governing_apo_spec.rb' + - 'spec/requests/edit_datastream_spec.rb' - 'spec/requests/item_files_download_spec.rb' - 'spec/requests/manage_release_spec.rb' -# Offense count: 83 +# Offense count: 85 # Configuration parameters: Prefixes. # Prefixes: when, with, without RSpec/ContextWording: Enabled: false -# Offense count: 74 +# Offense count: 76 RSpec/DescribeClass: Enabled: false -# Offense count: 182 +# Offense count: 183 # Configuration parameters: Max. RSpec/ExampleLength: Enabled: false @@ -183,37 +154,22 @@ RSpec/MessageChain: - 'spec/jobs/descmetadata_download_job_spec.rb' - 'spec/views/items/_collection_ui.html.erb_spec.rb' -# Offense count: 233 +# Offense count: 232 # Configuration parameters: EnforcedStyle. # SupportedStyles: have_received, receive RSpec/MessageSpies: Enabled: false -# Offense count: 188 +# Offense count: 189 # Configuration parameters: IgnoreSharedExamples. RSpec/NamedSubject: Enabled: false # Offense count: 53 -# Configuration parameters: Max. RSpec/NestedGroups: - Exclude: - - 'spec/components/workflow_table_process_component_spec.rb' - - 'spec/controllers/bulk_actions_controller_spec.rb' - - 'spec/controllers/catalog_controller_spec.rb' - - 'spec/controllers/content_types_controller_spec.rb' - - 'spec/controllers/files_controller_spec.rb' - - 'spec/controllers/items_controller_spec.rb' - - 'spec/controllers/report_controller_spec.rb' - - 'spec/controllers/workflow_service_controller_spec.rb' - - 'spec/controllers/workflows_controller_spec.rb' - - 'spec/forms/apo_form_spec.rb' - - 'spec/jobs/checksum_report_job_spec.rb' - - 'spec/jobs/create_virtual_objects_job_spec.rb' - - 'spec/models/user_spec.rb' - - 'spec/services/state_service_spec.rb' + Max: 6 -# Offense count: 3 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: Strict, EnforcedStyle. # SupportedStyles: inflected, explicit @@ -253,7 +209,7 @@ Rails/ApplicationJob: - 'app/jobs/generic_job.rb' - 'app/jobs/modsulator_job.rb' -# Offense count: 6 +# Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: NilOrEmpty, NotPresent, UnlessPresent. Rails/Blank: @@ -345,7 +301,7 @@ Style/CommentedKeyword: - 'lib/tasks/argo.rake' - 'lib/tasks/argo_testing.rake' -# Offense count: 62 +# Offense count: 63 Style/Documentation: Enabled: false @@ -372,7 +328,7 @@ Style/NumericPredicate: - 'spec/**/*' - 'app/jobs/descmetadata_download_job.rb' -# Offense count: 290 +# Offense count: 291 # Cop supports --auto-correct. # Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https diff --git a/app/components/datastream_row.rb b/app/components/datastream_row.rb index 0b0ce3963..0a8229b9f 100644 --- a/app/components/datastream_row.rb +++ b/app/components/datastream_row.rb @@ -21,7 +21,7 @@ def control_group end def link_to_identifier - link_to dsid, ds_solr_document_path(pid, dsid), title: dsid, data: { blacklight_modal: 'trigger' } + link_to dsid, item_datastream_path(pid, dsid), title: dsid, data: { blacklight_modal: 'trigger' } end def size diff --git a/app/controllers/catalog_controller.rb b/app/controllers/catalog_controller.rb index 9093e4144..8f6664c69 100644 --- a/app/controllers/catalog_controller.rb +++ b/app/controllers/catalog_controller.rb @@ -5,7 +5,6 @@ class CatalogController < ApplicationController helper ArgoHelper include DateFacetConfigurations - before_action :show_aspect, only: %i[dc ds] before_action :limit_facets_on_home_page, only: [:index] configure_blacklight do |config| @@ -215,26 +214,8 @@ def show end end - def dc - respond_to do |format| - format.html { render layout: !request.xhr? } - end - end - - def ds - respond_to do |format| - format.html { render layout: !request.xhr? } - end - end - private - def show_aspect - pid = params[:id].include?('druid') ? params[:id] : "druid:#{params[:id]}" - @obj ||= Dor.find(pid) - @response, @document = search_service.fetch pid - end - def limit_facets_on_home_page return if has_search_parameters? || params[:all] diff --git a/app/controllers/datastreams_controller.rb b/app/controllers/datastreams_controller.rb new file mode 100644 index 000000000..7c61f42b8 --- /dev/null +++ b/app/controllers/datastreams_controller.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +class DatastreamsController < ApplicationController + include Blacklight::Catalog + copy_blacklight_config_from CatalogController + + before_action :show_aspect, only: %i[dc show edit] + + def dc + respond_to do |format| + format.html { render layout: !request.xhr? } + end + end + + def edit + @ds = @obj.datastreams[params[:id]] + render layout: !request.xhr? + end + + def show + if params[:dsid] == 'full_dc' + @content = Nokogiri::XML(Dor::Services::Client.object(@obj.pid).metadata.dublin_core).prettify + else + @ds = @obj.datastreams[params[:id]] + + @content = if @ds.respond_to? :ng_xml + Nokogiri::XML(@ds.ng_xml.to_s, &:noblanks).to_s + else + Nokogiri::XML(@ds.content, &:noblanks).to_s + end + end + + raise ActionController::RoutingError, 'Not Found' if @content.nil? + + respond_to do |format| + format.html { render layout: !request.xhr? } + end + end + + ## + # @option params [String] `:content` the XML with which to replace the datastream + # @option params [String] `:id` the identifier for the datastream, e.g., `identityMetadata` + # @option params [String] `:item_id` the druid to modify + def update + @object = Dor.find params[:item_id] + authorize! :manage_item, @object + + raise ArgumentError, 'Missing content' if params[:content].blank? + + begin + # check that the content is well-formed xml + Nokogiri::XML(params[:content], &:strict) + rescue Nokogiri::XML::SyntaxError + raise ArgumentError, 'XML is not well formed!' + end + @object.datastreams[params[:id]].content = params[:content] # set the XML to be verbatim as posted + @object.save + Argo::Indexer.reindex_pid_remotely(@object.pid) + + respond_to do |format| + format.any { redirect_to solr_document_path(params[:item_id]), notice: 'Datastream was successfully updated' } + end + end + + private + + def show_aspect + pid = params[:item_id].include?('druid') ? params[:item_id] : "druid:#{params[:item_id]}" + @obj = Dor.find(pid) + @response, @document = search_service.fetch pid # this does the authorization + end +end diff --git a/app/controllers/items_controller.rb b/app/controllers/items_controller.rb index c29f2c8cc..2668c7558 100644 --- a/app/controllers/items_controller.rb +++ b/app/controllers/items_controller.rb @@ -6,7 +6,6 @@ class ItemsController < ApplicationController before_action :create_obj, except: :purl_preview before_action :authorize_manage!, only: %i[ add_collection set_collection remove_collection - datastream_update mods purge_object source_id @@ -116,28 +115,6 @@ def embargo_update end end - ## - # @option params [String] `:content` the XML with which to replace the datastream - # @option params [String] `:dsid` the identifier for the datastream, e.g., `identityMetadata` - # @option params [String] `:id` the druid to modify - def datastream_update - raise ArgumentError, 'Missing content' unless params[:content].present? - raise ArgumentError, 'Missing datastream identifier' unless params[:dsid].present? - - begin - # check that the content is well-formed xml - Nokogiri::XML(params[:content], &:strict) - rescue Nokogiri::XML::SyntaxError - raise ArgumentError, 'XML is not well formed!' - end - @object.datastreams[params[:dsid]].content = params[:content] # set the XML to be verbatim as posted - save_and_reindex - - respond_to do |format| - format.any { redirect_to solr_document_path(params[:id]), notice: 'Datastream was successfully updated' } - end - end - # Given two instances of VersionTag, find the most significant difference # between the two (return nil if either one is nil or if they're the same) # @param [String] cur_version_tag current version tag diff --git a/app/helpers/dor_object_helper.rb b/app/helpers/dor_object_helper.rb index ce291f6dc..943047de0 100644 --- a/app/helpers/dor_object_helper.rb +++ b/app/helpers/dor_object_helper.rb @@ -9,12 +9,4 @@ def render_workflows(doc) end render 'catalog/show_workflows', document_id: doc.id, workflows: workflows end - - # rubocop:disable Layout/LineLength - def render_ds_profile_header(ds) - dscd = ds.createDate - dscd = dscd.xmlschema if dscd.is_a?(Time) - %(\n ) - end - # rubocop:enable Layout/LineLength end diff --git a/app/views/catalog/_full_view_links_default.html.erb b/app/views/catalog/_full_view_links_default.html.erb index 26345e8ee..8d3ecc6f3 100644 --- a/app/views/catalog/_full_view_links_default.html.erb +++ b/app/views/catalog/_full_view_links_default.html.erb @@ -1,4 +1,4 @@ diff --git a/app/views/catalog/ds.html.erb b/app/views/catalog/ds.html.erb deleted file mode 100644 index 4cca5b00f..000000000 --- a/app/views/catalog/ds.html.erb +++ /dev/null @@ -1,45 +0,0 @@ -<%= render BlacklightModalComponent.new do |component| %> - <% component.with(:header, params[:dsid]) %> - <% component.with(:body) do %> - <% - if(params[:edit]) - if can?(:manage_item, @obj) - %> - <%= form_tag url_for(controller: :items, action: :datastream_update), id: 'xmlEditForm', method: :POST do %> - - -
- -
-
- -
- <% end %> - <% - end - else - # If the user is a repo admin or is permitted to manage both content and - # rights, display raw xml editing - %> - <% if can?(:manage_item, @obj) && Settings.editable_datastreams.include?(params[:dsid]) %> - <%= link_to "Edit #{params[:dsid]}", ds_solr_document_path(params[:id], params[:dsid], edit: 'true'), title: params[:dsid], data: { blacklight_modal: 'preserve' } %> - <% end %> - <% content = if params[:dsid] == 'full_dc' - Nokogiri::XML(Dor::Services::Client.object(@obj.pid).metadata.dublin_core).prettify - elsif @obj.datastreams[params[:dsid]].respond_to? :ng_xml - Nokogiri::XML(@obj.datastreams[params[:dsid]].ng_xml.to_s, &:noblanks).to_s - else - Nokogiri::XML(@obj.datastreams[params[:dsid]].content, &:noblanks).to_s - end - raise ActionController::RoutingError, 'Not Found' if content.nil? - - output = CodeRay::Duo[:xml, :div].highlight content %> - <% unless params[:dsid] == 'full_dc' %> -
-
<%= render_ds_profile_header @obj.datastreams[params[:dsid]] %>
-
- <% end %> - <%= output.html_safe %> - <% end %> - <% end %> -<% end %> diff --git a/app/views/catalog/dc.html.erb b/app/views/datastreams/dc.html.erb similarity index 86% rename from app/views/catalog/dc.html.erb rename to app/views/datastreams/dc.html.erb index a14722f48..5f0364717 100644 --- a/app/views/catalog/dc.html.erb +++ b/app/views/datastreams/dc.html.erb @@ -4,7 +4,7 @@ <% dc_xml = Nokogiri::XML(Dor::Services::Client.object(@obj.pid).metadata.dublin_core) %> diff --git a/app/views/datastreams/edit.html.erb b/app/views/datastreams/edit.html.erb new file mode 100644 index 000000000..a439c6126 --- /dev/null +++ b/app/views/datastreams/edit.html.erb @@ -0,0 +1,17 @@ +<%= render BlacklightModalComponent.new do |component| %> + <% component.with(:header, params[:dsid]) %> + <% component.with(:body) do %> + <% if can?(:manage_item, @obj) %> + <%= form_tag item_datastream_path(@obj.pid, @ds.dsid), id: 'xmlEditForm', method: :patch do %> + + +
+ +
+
+ +
+ <% end %> + <% end %> + <% end %> +<% end %> diff --git a/app/views/datastreams/show.html.erb b/app/views/datastreams/show.html.erb new file mode 100644 index 000000000..84a563df4 --- /dev/null +++ b/app/views/datastreams/show.html.erb @@ -0,0 +1,20 @@ +<%= render BlacklightModalComponent.new do |component| %> + <% component.with(:header, params[:dsid]) %> + <% component.with(:body) do %> + <%# If the user is a repo admin or is permitted to manage both content and %> + <%# rights, display raw xml editing %> + <% if can?(:manage_item, @obj) && Settings.editable_datastreams.include?(params[:id]) %> + <%= link_to "Edit #{@ds.dsid}", edit_item_datastream_path(@ds.pid, @ds.dsid), title: @ds.dsid, data: { blacklight_modal: 'preserve' } %> + <% end %> + + <% unless params[:id] == 'full_dc' %> +
+
+          
+          
+        
+
+ <% end %> + <%= CodeRay::Duo[:xml, :div].highlight(@content).html_safe %> + <% end %> +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 423d5420c..57dc0ea6e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -28,11 +28,6 @@ resources :solr_documents, only: [:show], controller: 'catalog', path: '/view' do concerns :exportable - - member do - get 'dc', to: 'catalog#dc' - get 'ds/:dsid', to: 'catalog#ds', as: 'ds' - end end match 'catalog', via: %i[get post], to: redirect { |params, req| req.fullpath.sub(%r{^/catalog}, '/view') }, as: 'search_catalog_redirect' @@ -130,6 +125,12 @@ resource :manage_release, only: :show + resources :datastreams, only: %i[show edit update] do + member do + get 'dc' + end + end + member do get 'purl_preview' post 'refresh_metadata' @@ -137,7 +138,6 @@ get 'mods' post 'embargo', action: :embargo_update, as: 'embargo_update' get 'embargo_form' - post 'datastream', action: :datastream_update, as: 'datastream_update' get 'source_id_ui' get 'catkey_ui' match 'tags_bulk', via: %i[get post] diff --git a/spec/controllers/items_controller_spec.rb b/spec/controllers/items_controller_spec.rb index 4aba62ac1..a52e5ec58 100644 --- a/spec/controllers/items_controller_spec.rb +++ b/spec/controllers/items_controller_spec.rb @@ -220,49 +220,6 @@ end end - describe '#datastream_update' do - let(:xml) { '' } - let(:invalid_apo_xml) { '' } - - context 'without management access' do - before do - allow(controller).to receive(:authorize!).with(:manage_item, Dor::Item).and_raise(CanCan::AccessDenied) - end - - it 'prevents access' do - expect(item).not_to receive(:save) - post 'datastream_update', params: { dsid: 'contentMetadata', id: pid, content: xml } - expect(response).to have_http_status(:forbidden) - end - end - - context 'when they have manage access' do - before do - allow(controller).to receive(:authorize!).and_return(true) - end - - it 'updates the datastream' do - expect(item).to receive(:datastreams).and_return( - 'contentMetadata' => double(Dor::ContentMetadataDS, 'content=': xml) - ) - expect(item).to receive(:save) - expect(controller).to receive(:authorize!).with(:manage_item, Dor::Item).and_return(true) - post 'datastream_update', params: { dsid: 'contentMetadata', id: pid, content: xml } - expect(response).to have_http_status(:found) - end - - it 'errors on empty xml' do - expect { post 'datastream_update', params: { dsid: 'contentMetadata', id: pid, content: ' ' } }.to raise_error(ArgumentError) - end - it 'errors on malformed xml' do - expect { post 'datastream_update', params: { dsid: 'contentMetadata', id: pid, content: 'isnt well formed.' } }.to raise_error(ArgumentError) - end - it 'errors on missing dsid parameter' do - expect { post 'datastream_update', params: { id: pid, content: xml } }.to raise_error(ArgumentError) - end - end - end - describe '#add_collection' do context 'when they have manage access' do before do diff --git a/spec/requests/edit_datastream_spec.rb b/spec/requests/edit_datastream_spec.rb new file mode 100644 index 000000000..657b2bbee --- /dev/null +++ b/spec/requests/edit_datastream_spec.rb @@ -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 + + 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 diff --git a/spec/requests/update_datastream_spec.rb b/spec/requests/update_datastream_spec.rb new file mode 100644 index 000000000..258ab5d3b --- /dev/null +++ b/spec/requests/update_datastream_spec.rb @@ -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) { '' } + let(:invalid_apo_xml) { '' } + + 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 redirect_to "/view/#{pid}" + 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: 'isnt well formed.' } }.to raise_error(ArgumentError) + end + end +end diff --git a/spec/routing/catalog_spec.rb b/spec/routing/catalog_spec.rb index c3c5f02b8..69832091e 100644 --- a/spec/routing/catalog_spec.rb +++ b/spec/routing/catalog_spec.rb @@ -12,16 +12,6 @@ .to route_to('catalog#show', id: 'druid:xyz') end - it 'routes to #dc' do - expect(get: '/view/druid:xyz/dc') - .to route_to('catalog#dc', id: 'druid:xyz') - end - - it 'routes to #ds' do - expect(get: '/view/druid:xyz/ds/identityMetadata') - .to route_to('catalog#ds', id: 'druid:xyz', dsid: 'identityMetadata') - end - context 'redirections' do include RSpec::Rails::RequestExampleGroup diff --git a/spec/views/catalog/dc.html.erb_spec.rb b/spec/views/datastreams/dc.html.erb_spec.rb similarity index 95% rename from spec/views/catalog/dc.html.erb_spec.rb rename to spec/views/datastreams/dc.html.erb_spec.rb index 0033a5b01..8df8ed754 100644 --- a/spec/views/catalog/dc.html.erb_spec.rb +++ b/spec/views/datastreams/dc.html.erb_spec.rb @@ -2,7 +2,7 @@ require 'rails_helper' -RSpec.describe 'catalog/dc.html.erb' do +RSpec.describe 'datastreams/dc.html.erb' do let(:object_client) { instance_double(Dor::Services::Client::Object, metadata: metadata) } let(:metadata) { instance_double(Dor::Services::Client::Metadata, dublin_core: xml) } let(:xml) do diff --git a/spec/views/catalog/ds.html.erb_spec.rb b/spec/views/datastreams/show.html.erb_spec.rb similarity index 72% rename from spec/views/catalog/ds.html.erb_spec.rb rename to spec/views/datastreams/show.html.erb_spec.rb index cd7b56af7..15f7ee251 100644 --- a/spec/views/catalog/ds.html.erb_spec.rb +++ b/spec/views/datastreams/show.html.erb_spec.rb @@ -2,17 +2,18 @@ require 'rails_helper' -RSpec.describe 'catalog/ds.html.erb' do - let(:stub_ds) { instance_double(Dor::IdentityMetadataDS, content: '') } - +RSpec.describe 'datastreams/show.html.erb' do before do - params[:dsid] = dsid - params[:id] = 'druid:abc123' + params[:id] = dsid + params[:item_id] = pid allow(view).to receive(:can?).and_return(true) - allow(view).to receive(:render_ds_profile_header) - @obj = instance_double(Dor::Item, datastreams: { dsid => stub_ds }) + @obj = obj + @ds = Dor::IdentityMetadataDS.new(obj, 'identityMetadata') end + let(:pid) { 'druid:abc123' } + let(:obj) { instance_double(Dor::Item, pid: pid) } + context 'with an editable datastream' do let(:dsid) { 'identityMetadata' }