hyrax-doi 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +65 -0
- data/Rakefile +23 -0
- data/app/actors/hyrax/actors/doi_actor.rb +50 -0
- data/app/assets/config/hyrax_doi_manifest.js +2 -0
- data/app/assets/javascripts/hyrax/doi/application.js +15 -0
- data/app/assets/stylesheets/hyrax/doi/application.css +15 -0
- data/app/controllers/hyrax/doi/application_controller.rb +15 -0
- data/app/controllers/hyrax/doi/hyrax_doi_controller.rb +91 -0
- data/app/forms/concerns/hyrax/doi/datacite_doi_form_behavior.rb +18 -0
- data/app/forms/concerns/hyrax/doi/doi_form_behavior.rb +18 -0
- data/app/helpers/hyrax/doi/helper_behavior.rb +9 -0
- data/app/helpers/hyrax/doi/work_form_helper.rb +15 -0
- data/app/helpers/hyrax/doi/work_show_helper.rb +12 -0
- data/app/jobs/hyrax/doi/application_job.rb +7 -0
- data/app/jobs/hyrax/doi/register_doi_job.rb +18 -0
- data/app/models/concerns/hyrax/doi/datacite_doi_behavior.rb +21 -0
- data/app/models/concerns/hyrax/doi/doi_behavior.rb +38 -0
- data/app/models/concerns/hyrax/doi/solr_document/datacite_doi_behavior.rb +14 -0
- data/app/models/concerns/hyrax/doi/solr_document/doi_behavior.rb +14 -0
- data/app/presenters/concerns/hyrax/doi/datacite_doi_presenter_behavior.rb +20 -0
- data/app/presenters/concerns/hyrax/doi/doi_presenter_behavior.rb +12 -0
- data/app/services/bolognese/readers/hyrax_work_reader.rb +99 -0
- data/app/services/bolognese/writers/hyrax_work_writer.rb +50 -0
- data/app/services/hyrax/doi/datacite_client.rb +138 -0
- data/app/services/hyrax/doi/datacite_registrar.rb +121 -0
- data/app/views/hyrax/base/_attribute_rows.html.erb +18 -0
- data/app/views/hyrax/base/_form_doi.html.erb +73 -0
- data/config/locales/hyrax_doi.en.yml +7 -0
- data/config/routes.rb +5 -0
- data/lib/generators/hyrax/doi/add_to_work_type_generator.rb +97 -0
- data/lib/generators/hyrax/doi/install_generator.rb +74 -0
- data/lib/generators/hyrax/doi/templates/config/initializers/hyrax-doi.rb +15 -0
- data/lib/hyrax/doi.rb +9 -0
- data/lib/hyrax/doi/engine.rb +28 -0
- data/lib/hyrax/doi/errors.rb +8 -0
- data/lib/hyrax/doi/spec/shared_specs.rb +9 -0
- data/lib/hyrax/doi/spec/shared_specs/datacite_doi_behavior.rb +40 -0
- data/lib/hyrax/doi/spec/shared_specs/datacite_doi_form_behavior.rb +17 -0
- data/lib/hyrax/doi/spec/shared_specs/datacite_doi_presenter_behavior.rb +39 -0
- data/lib/hyrax/doi/spec/shared_specs/doi_behavior.rb +63 -0
- data/lib/hyrax/doi/spec/shared_specs/doi_form_behavior.rb +17 -0
- data/lib/hyrax/doi/spec/shared_specs/doi_presenter_behavior.rb +19 -0
- data/lib/hyrax/doi/spec/shared_specs/solr_document/datacite_doi_behavior.rb +20 -0
- data/lib/hyrax/doi/spec/shared_specs/solr_document/doi_behavior.rb +20 -0
- data/lib/hyrax/doi/version.rb +6 -0
- data/lib/tasks/hyrax/doi_tasks.rake +5 -0
- metadata +319 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
<%# Overridden to display doi attribute (Copied here from Hyrax 2.9) %>
|
2
|
+
<%# _attribute_rows.html.erb is likely to be overridden per work type so this provides a %>
|
3
|
+
<%# simple out of the box way to show the doi while not impedeing those who choose to customize %>
|
4
|
+
<%= presenter.attribute_to_html(:date_modified, label: t('hyrax.base.show.last_modified'), html_dl: true) %>
|
5
|
+
<%= presenter.attribute_to_html(:creator, render_as: :faceted, html_dl: true) %>
|
6
|
+
<%= presenter.attribute_to_html(:contributor, render_as: :faceted, html_dl: true) %>
|
7
|
+
<%= presenter.attribute_to_html(:subject, render_as: :faceted, html_dl: true) %>
|
8
|
+
<%= presenter.attribute_to_html(:publisher, render_as: :faceted, html_dl: true) %>
|
9
|
+
<%= presenter.attribute_to_html(:language, render_as: :faceted, html_dl: true) %>
|
10
|
+
<%= presenter.attribute_to_html(:identifier, render_as: :linked, search_field: 'identifier_tesim', html_dl: true) %>
|
11
|
+
<%= presenter.attribute_to_html(:keyword, render_as: :faceted, html_dl: true) %>
|
12
|
+
<%= presenter.attribute_to_html(:date_created, render_as: :linked, search_field: 'date_created_tesim', html_dl: true) %>
|
13
|
+
<%= presenter.attribute_to_html(:based_near_label, html_dl: true) %>
|
14
|
+
<%= presenter.attribute_to_html(:related_url, render_as: :external_link, html_dl: true) %>
|
15
|
+
<%= presenter.attribute_to_html(:resource_type, render_as: :faceted, html_dl: true) %>
|
16
|
+
<%= presenter.attribute_to_html(:source, html_dl: true) %>
|
17
|
+
<%= presenter.attribute_to_html(:rights_statement, render_as: :rights_statement, html_dl: true) %>
|
18
|
+
<%= presenter.attribute_to_html(:doi, render_as: :external_link, html_dl: true) if respond_to?(:render_doi?) && render_doi?(presenter) %>
|
@@ -0,0 +1,73 @@
|
|
1
|
+
<div>
|
2
|
+
<%# TODO: Make this appear as singular %>
|
3
|
+
<%= render_edit_field_partial('doi', f: f) %>
|
4
|
+
|
5
|
+
<%= link_to "Create draft DOI",
|
6
|
+
Hyrax::DOI::Engine.routes.url_helpers.create_draft_doi_path,
|
7
|
+
remote: true,
|
8
|
+
method: :get,
|
9
|
+
data: {
|
10
|
+
disable_with: "Creating draft DOI...",
|
11
|
+
params: {
|
12
|
+
curation_concern: curation_concern.class.name.underscore,
|
13
|
+
attribute: 'doi'
|
14
|
+
}
|
15
|
+
},
|
16
|
+
class: 'btn btn-default',
|
17
|
+
id: 'doi-create-draft-btn' %>
|
18
|
+
|
19
|
+
<%= link_to "Autofill form",
|
20
|
+
Hyrax::DOI::Engine.routes.url_helpers.autofill_path,
|
21
|
+
remote: true,
|
22
|
+
method: :get,
|
23
|
+
data: {
|
24
|
+
confirm: "This operation is destructive and will replace any information already filled in on this form.",
|
25
|
+
disable_with: "Autofilling form...",
|
26
|
+
params: { curation_concern: curation_concern.class.name.underscore }
|
27
|
+
},
|
28
|
+
class: 'btn btn-primary',
|
29
|
+
id: 'doi-autofill-btn' %>
|
30
|
+
|
31
|
+
<br/><br/><br/>
|
32
|
+
|
33
|
+
<fieldset class="set-doi-status-when-public">
|
34
|
+
<label class="control-label">DOI status when work is public</label>
|
35
|
+
|
36
|
+
<div class="form-group" style="margin-left: 20px">
|
37
|
+
<label class="radio" style="font-weight: normal">
|
38
|
+
<%= f.radio_button :doi_status_when_public, '', style: 'margin-top: 0px;' %>
|
39
|
+
Do not mint
|
40
|
+
</label>
|
41
|
+
<label class="radio" style="font-weight: normal">
|
42
|
+
<%= f.radio_button :doi_status_when_public, 'draft', style: 'margin-top: 0px;' %>
|
43
|
+
Draft
|
44
|
+
</label>
|
45
|
+
<label class="radio" style="font-weight: normal">
|
46
|
+
<%= f.radio_button :doi_status_when_public, 'registered', style: 'margin-top: 0px;' %>
|
47
|
+
Registered
|
48
|
+
</label>
|
49
|
+
<label class="radio" style="font-weight: normal">
|
50
|
+
<%= f.radio_button :doi_status_when_public, 'findable', style: 'margin-top: 0px;' %>
|
51
|
+
Findable
|
52
|
+
</label>
|
53
|
+
</div>
|
54
|
+
</fieldset>
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<script type="text/javascript">
|
58
|
+
// Append the DOI filled in the form to the request
|
59
|
+
// Note this uses jQuery since we're using jquery-ujs still
|
60
|
+
// There is probably a better way to do this but this works for now
|
61
|
+
$("#doi-autofill-btn").on("ajax:beforeSend", function(e, xhr, settings) {
|
62
|
+
doi = $('#generic_work_doi').val()
|
63
|
+
settings.url = settings.url + "&doi=" + encodeURIComponent(doi)
|
64
|
+
});
|
65
|
+
|
66
|
+
$("#doi-create-draft-btn").on("ajax:error", function(e, xhr, status, error) {
|
67
|
+
alert(xhr.responseText);
|
68
|
+
});
|
69
|
+
|
70
|
+
$("#doi-autofill-btn").on("ajax:error", function(e, xhr, status, error) {
|
71
|
+
alert(xhr.responseText);
|
72
|
+
});
|
73
|
+
</script>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/model_helpers'
|
4
|
+
|
5
|
+
module Hyrax
|
6
|
+
module DOI
|
7
|
+
class AddToWorkTypeGenerator < Rails::Generators::NamedBase
|
8
|
+
# ActiveSupport can interpret models as plural which causes
|
9
|
+
# counter-intuitive route paths. Pull in ModelHelpers from
|
10
|
+
# Rails which warns users about pluralization when generating
|
11
|
+
# new models or scaffolds.
|
12
|
+
include Rails::Generators::ModelHelpers
|
13
|
+
|
14
|
+
# Required due to non-standard capitalization of DOI namespace
|
15
|
+
namespace 'hyrax:doi:add_to_work_type'
|
16
|
+
# Same as adding --skip-namespace flag to generator call
|
17
|
+
# This removes the hyrax/doi namespace from class_path
|
18
|
+
# Namespaces passed as the argument will still appear in class_path
|
19
|
+
class_option :skip_namespace, default: true
|
20
|
+
|
21
|
+
# DataCite-specific support
|
22
|
+
class_option :datacite, type: :boolean, default: false, desc: "Add DataCite-specific behavior."
|
23
|
+
|
24
|
+
desc "Add DOI support to given work type"
|
25
|
+
def inject_into_model
|
26
|
+
# rubocop:disable Style/RedundantSelf
|
27
|
+
# For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
|
28
|
+
self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
|
29
|
+
model_file = File.join(self.destination_root, 'app', 'models', *class_path, "#{file_name}.rb")
|
30
|
+
# rubocop:enable Style/RedundantSelf
|
31
|
+
|
32
|
+
insert_into_file model_file, after: 'include ::Hyrax::WorkBehavior' do
|
33
|
+
"\n" \
|
34
|
+
" # Adds behaviors for hyrax-doi plugin.\n" \
|
35
|
+
" include Hyrax::DOI::DOIBehavior"
|
36
|
+
end
|
37
|
+
|
38
|
+
return unless options[:datacite]
|
39
|
+
|
40
|
+
# DataCite specific behavior
|
41
|
+
insert_into_file model_file, after: 'include Hyrax::DOI::DOIBehavior' do
|
42
|
+
"\n" \
|
43
|
+
" # Adds behaviors for DataCite DOIs via hyrax-doi plugin.\n" \
|
44
|
+
" include Hyrax::DOI::DataCiteDOIBehavior"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
desc "Add DOI support to given work type form"
|
49
|
+
def inject_into_form
|
50
|
+
# rubocop:disable Style/RedundantSelf
|
51
|
+
# For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
|
52
|
+
self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
|
53
|
+
form_file = File.join(self.destination_root, 'app', 'forms', 'hyrax', *class_path, "#{file_name}_form.rb")
|
54
|
+
# rubocop:enable Style/RedundantSelf
|
55
|
+
|
56
|
+
insert_into_file form_file, after: 'Hyrax::Forms::WorkForm' do
|
57
|
+
"\n" \
|
58
|
+
" # Adds behaviors for hyrax-doi plugin.\n" \
|
59
|
+
" include Hyrax::DOI::DOIFormBehavior"
|
60
|
+
end
|
61
|
+
|
62
|
+
return unless options[:datacite]
|
63
|
+
|
64
|
+
# DataCite specific behavior
|
65
|
+
insert_into_file form_file, after: 'include Hyrax::DOI::DOIFormBehavior' do
|
66
|
+
"\n" \
|
67
|
+
" # Adds behaviors for DataCite DOIs via hyrax-doi plugin.\n" \
|
68
|
+
" include Hyrax::DOI::DataCiteDOIFormBehavior"
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
desc "Add DOI support to given work type presenter"
|
73
|
+
def inject_into_presenter
|
74
|
+
# rubocop:disable Style/RedundantSelf
|
75
|
+
# For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
|
76
|
+
self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
|
77
|
+
presenter_file = File.join(self.destination_root, 'app', 'presenters', 'hyrax', *class_path, "#{file_name}_presenter.rb")
|
78
|
+
# rubocop:enable Style/RedundantSelf
|
79
|
+
|
80
|
+
insert_into_file presenter_file, after: '::WorkShowPresenter' do
|
81
|
+
"\n" \
|
82
|
+
" # Adds behaviors for hyrax-doi plugin.\n" \
|
83
|
+
" include Hyrax::DOI::DOIPresenterBehavior"
|
84
|
+
end
|
85
|
+
|
86
|
+
return unless options[:datacite]
|
87
|
+
|
88
|
+
# DataCite specific behavior
|
89
|
+
insert_into_file presenter_file, after: 'include Hyrax::DOI::DOIPresenterBehavior' do
|
90
|
+
"\n" \
|
91
|
+
" # Adds behaviors for DataCite DOIs via hyrax-doi plugin.\n" \
|
92
|
+
" include Hyrax::DOI::DataCiteDOIPresenterBehavior"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'rails/generators'
|
3
|
+
require 'rails/generators/model_helpers'
|
4
|
+
|
5
|
+
module Hyrax
|
6
|
+
module DOI
|
7
|
+
class InstallGenerator < Rails::Generators::Base
|
8
|
+
source_root File.expand_path('../templates', __FILE__)
|
9
|
+
|
10
|
+
# Required due to non-standard capitalization of DOI namespace
|
11
|
+
namespace 'hyrax:doi:install'
|
12
|
+
# Same as adding --skip-namespace flag to generator call
|
13
|
+
# This removes the hyrax/doi namespace from class_path
|
14
|
+
# Namespaces passed as the argument will still appear in class_path
|
15
|
+
class_option :skip_namespace, default: true
|
16
|
+
|
17
|
+
# DataCite-specific support
|
18
|
+
class_option :datacite, type: :boolean, default: false, desc: "Add DataCite-specific behavior."
|
19
|
+
|
20
|
+
def generate_config
|
21
|
+
# rubocop:disable Style/RedundantSelf
|
22
|
+
# For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
|
23
|
+
self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
|
24
|
+
initializer_file = File.join(self.destination_root, 'config', 'initializers', 'hyrax-doi.rb')
|
25
|
+
# rubocop:enable Style/RedundantSelf
|
26
|
+
|
27
|
+
copy_file "config/initializers/hyrax-doi.rb", initializer_file
|
28
|
+
end
|
29
|
+
|
30
|
+
def inject_into_helper
|
31
|
+
# rubocop:disable Style/RedundantSelf
|
32
|
+
# For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
|
33
|
+
self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
|
34
|
+
helper_file = File.join(self.destination_root, 'app', 'helpers', "hyrax_helper.rb")
|
35
|
+
# rubocop:enable Style/RedundantSelf
|
36
|
+
|
37
|
+
insert_into_file helper_file, after: 'include Hyrax::HyraxHelperBehavior' do
|
38
|
+
"\n" \
|
39
|
+
" # Helpers provided by hyrax-doi plugin.\n" \
|
40
|
+
" include Hyrax::DOI::HelperBehavior"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def inject_into_solr_document
|
45
|
+
# rubocop:disable Style/RedundantSelf
|
46
|
+
# For some reason I had to use self.destination_root here to get all contexts to work (calling from hyrax app, calling from this engine to test app, rspec tests)
|
47
|
+
self.destination_root = Rails.root if self.destination_root.blank? || self.destination_root == Hyrax::DOI::Engine.root.to_s
|
48
|
+
solr_document_file = File.join(self.destination_root, 'app', 'models', "solr_document.rb")
|
49
|
+
# rubocop:enable Style/RedundantSelf
|
50
|
+
|
51
|
+
insert_into_file solr_document_file, after: 'include Hyrax::SolrDocumentBehavior' do
|
52
|
+
"\n" \
|
53
|
+
" # Add attributes for DOIs for hyrax-doi plugin.\n" \
|
54
|
+
" include Hyrax::DOI::SolrDocument::DOIBehavior"
|
55
|
+
end
|
56
|
+
|
57
|
+
return unless options[:datacite]
|
58
|
+
|
59
|
+
# DataCite specific behavior
|
60
|
+
insert_into_file solr_document_file, after: 'Hyrax::DOI::SolrDocument::DOIBehavior' do
|
61
|
+
"\n" \
|
62
|
+
" # Add attributes for DataCite DOIs for hyrax-doi plugin.\n" \
|
63
|
+
" include Hyrax::DOI::SolrDocument::DataCiteDOIBehavior"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def mount_engine_routes
|
68
|
+
inject_into_file 'config/routes.rb', after: /mount Hyrax::Engine, at: '\S*'\n/ do
|
69
|
+
" mount Hyrax::DOI::Engine, at: '/doi', as: 'hyrax_doi'\n"
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
## Set a default host for urls generated by the DOI registrars (if necessary)
|
3
|
+
# Rails.application.routes.default_url_options[:host] = 'localhost:3000'
|
4
|
+
|
5
|
+
## Remote identifiers configuration
|
6
|
+
# Add registrar implementations by uncommenting and adding to the hash below.
|
7
|
+
# See app/services/hyrax/identifier/registrar.rb for the registrar interface
|
8
|
+
Hyrax.config.identifier_registrars = { datacite: Hyrax::DOI::DataCiteRegistrar }
|
9
|
+
|
10
|
+
## For DataCite DOIs
|
11
|
+
# Test mode will use the DataCite test environment
|
12
|
+
Hyrax::DOI::DataCiteRegistrar.mode = :test # Possible options are [:production, :test]
|
13
|
+
Hyrax::DOI::DataCiteRegistrar.prefix = ENV['DATACITE_PREFIX']
|
14
|
+
Hyrax::DOI::DataCiteRegistrar.username = ENV['DATACITE_USERNAME']
|
15
|
+
Hyrax::DOI::DataCiteRegistrar.password = ENV['DATACITE_PASSWORD']
|
data/lib/hyrax/doi.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module DOI
|
4
|
+
class Engine < ::Rails::Engine
|
5
|
+
isolate_namespace Hyrax::DOI
|
6
|
+
|
7
|
+
config.before_configuration do
|
8
|
+
# Fix camelizing of paths for autoloading
|
9
|
+
# With this hyrax/doi/application_helper -> Hyrax::DOI::ApplicationHelper
|
10
|
+
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
11
|
+
inflect.acronym 'DOI'
|
12
|
+
inflect.acronym 'DataCite'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
config.after_initialize do
|
17
|
+
Hyrax::CurationConcern.actor_factory.use Hyrax::Actors::DOIActor
|
18
|
+
|
19
|
+
require 'bolognese'
|
20
|
+
Bolognese::Metadata.prepend Bolognese::Readers::HyraxWorkReader
|
21
|
+
Bolognese::Metadata.prepend Bolognese::Writers::HyraxWorkWriter
|
22
|
+
|
23
|
+
# Prepend our views so they have precedence
|
24
|
+
ActionController::Base.prepend_view_path(paths['app/views'].existent)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,9 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
require 'hyrax/doi/spec/shared_specs/datacite_doi_behavior'
|
3
|
+
require 'hyrax/doi/spec/shared_specs/datacite_doi_form_behavior'
|
4
|
+
require 'hyrax/doi/spec/shared_specs/datacite_doi_presenter_behavior'
|
5
|
+
require 'hyrax/doi/spec/shared_specs/doi_behavior'
|
6
|
+
require 'hyrax/doi/spec/shared_specs/doi_form_behavior'
|
7
|
+
require 'hyrax/doi/spec/shared_specs/doi_presenter_behavior'
|
8
|
+
require 'hyrax/doi/spec/shared_specs/solr_document/datacite_doi_behavior'
|
9
|
+
require 'hyrax/doi/spec/shared_specs/solr_document/doi_behavior'
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
RSpec.shared_examples "a DataCite DOI-enabled model" do
|
3
|
+
subject { work }
|
4
|
+
|
5
|
+
let(:properties) do
|
6
|
+
[:doi_status_when_public]
|
7
|
+
end
|
8
|
+
|
9
|
+
describe "properties" do
|
10
|
+
it "has DataCite DOI properties" do
|
11
|
+
properties.each do |property|
|
12
|
+
expect(subject).to respond_to(property)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe 'validations' do
|
18
|
+
it 'validates inclusion of doi_status_when_public' do
|
19
|
+
expect(subject).to validate_inclusion_of(:doi_status_when_public).in_array([nil] + Hyrax::DOI::DataCiteRegistrar::STATES).allow_nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe 'to_solr' do
|
24
|
+
let(:solr_doc) { subject.to_solr }
|
25
|
+
|
26
|
+
let(:solr_fields) do
|
27
|
+
[:doi_status_when_public_ssi]
|
28
|
+
end
|
29
|
+
|
30
|
+
before do
|
31
|
+
work.doi_status_when_public = 'draft'
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'has solr fields' do
|
35
|
+
solr_fields.each do |field|
|
36
|
+
expect(solr_doc.fetch(field.to_s)).not_to be_blank
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
RSpec.shared_examples "a DataCite DOI-enabled form" do
|
3
|
+
subject { form }
|
4
|
+
|
5
|
+
describe "properties" do
|
6
|
+
it { is_expected.to delegate_method(:doi_status_when_public).to(:model) }
|
7
|
+
|
8
|
+
it 'includes properties in the list of terms' do
|
9
|
+
expect(subject.terms).to include(:doi_status_when_public)
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'does not include properties in primary or secondary' do
|
13
|
+
expect(subject.primary_terms).not_to include(:doi_status_when_public)
|
14
|
+
expect(subject.secondary_terms).not_to include(:doi_status_when_public)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
RSpec.shared_examples "a DataCite DOI-enabled presenter" do
|
3
|
+
subject { presenter }
|
4
|
+
|
5
|
+
let(:presenter) { presenter_class.new(solr_document, nil, nil) }
|
6
|
+
let(:solr_document) { instance_double(solr_document_class) }
|
7
|
+
|
8
|
+
it { is_expected.to delegate_method(:doi_status_when_public).to(:solr_document) }
|
9
|
+
|
10
|
+
describe 'doi_status' do
|
11
|
+
before do
|
12
|
+
allow(solr_document).to receive(:doi_status_when_public).and_return(doi_status_when_public)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:doi_status_when_public) { 'draft' }
|
16
|
+
|
17
|
+
context 'when findable' do
|
18
|
+
let(:doi_status_when_public) { 'findable' }
|
19
|
+
|
20
|
+
context 'when public' do
|
21
|
+
it 'is findable' do
|
22
|
+
allow(solr_document).to receive(:public?).and_return(true)
|
23
|
+
expect(subject.doi_status).to eq 'findable'
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when not public' do
|
28
|
+
it 'is registered' do
|
29
|
+
allow(solr_document).to receive(:public?).and_return(false)
|
30
|
+
expect(subject.doi_status).to eq 'registered'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'returns the status' do
|
36
|
+
expect(subject.doi_status).to eq doi_status_when_public
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|