hyrax 2.3.3 → 2.4.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.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/.github/stale.yml +19 -0
  4. data/README.md +2 -2
  5. data/app/actors/hyrax/actors/apply_permission_template_actor.rb +2 -4
  6. data/app/actors/hyrax/actors/create_with_files_ordered_members_actor.rb +45 -0
  7. data/app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb +96 -0
  8. data/app/actors/hyrax/actors/file_set_ordered_members_actor.rb +16 -0
  9. data/app/actors/hyrax/actors/ordered_members_actor.rb +28 -0
  10. data/app/assets/javascripts/hyrax/collections.js +2 -0
  11. data/app/assets/stylesheets/hyrax/_file-listing.scss +2 -1
  12. data/app/assets/stylesheets/hyrax/_work-show.scss +4 -0
  13. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +1 -1
  14. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +5 -2
  15. data/app/controllers/hyrax/dashboard/nest_collections_controller.rb +2 -9
  16. data/app/helpers/hyrax/batch_edits_helper.rb +0 -1
  17. data/app/helpers/hyrax/hyrax_helper_behavior.rb +1 -0
  18. data/app/helpers/hyrax/iiif_helper.rb +12 -0
  19. data/app/jobs/attach_files_to_work_with_ordered_members_job.rb +41 -0
  20. data/app/presenters/hyrax/work_show_presenter.rb +29 -2
  21. data/app/services/hyrax/permission_template_applicator.rb +48 -0
  22. data/app/views/hyrax/admin/collection_types/_form_settings.html.erb +1 -1
  23. data/app/views/hyrax/admin/collection_types/index.html.erb +1 -1
  24. data/app/views/hyrax/base/_form_rendering.html.erb +7 -5
  25. data/app/views/hyrax/base/_form_representative.html.erb +4 -2
  26. data/app/views/hyrax/base/_form_thumbnail.html.erb +4 -2
  27. data/app/views/hyrax/base/_member.html.erb +1 -1
  28. data/app/views/hyrax/base/_representative_media.html.erb +1 -4
  29. data/app/views/hyrax/base/_show_actions.html.erb +6 -4
  30. data/app/views/hyrax/base/iiif_viewers/_universal_viewer.html.erb +4 -0
  31. data/app/views/hyrax/base/show.html.erb +2 -2
  32. data/app/views/hyrax/dashboard/works/_default_group.html.erb +1 -1
  33. data/app/views/hyrax/file_sets/_file_set_title.erb +2 -2
  34. data/app/views/hyrax/homepage/_featured.html.erb +0 -3
  35. data/app/views/hyrax/my/_collection_action_menu.html.erb +1 -0
  36. data/app/views/hyrax/my/collections/_default_group.html.erb +1 -9
  37. data/app/views/hyrax/my/collections/_list_collections.html.erb +1 -1
  38. data/app/views/hyrax/users/_activity_log.html.erb +1 -1
  39. data/config/locales/hyrax.de.yml +2 -0
  40. data/config/locales/hyrax.en.yml +2 -0
  41. data/config/locales/hyrax.es.yml +2 -0
  42. data/config/locales/hyrax.fr.yml +2 -0
  43. data/config/locales/hyrax.it.yml +2 -0
  44. data/config/locales/hyrax.pt-BR.yml +2 -0
  45. data/config/locales/hyrax.zh.yml +2 -0
  46. data/hyrax.gemspec +1 -0
  47. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +1 -1
  48. data/lib/generators/hyrax/templates/config/locales/hyrax.de.yml +1 -1
  49. data/lib/generators/hyrax/templates/config/locales/hyrax.en.yml +1 -1
  50. data/lib/generators/hyrax/templates/config/locales/hyrax.es.yml +1 -1
  51. data/lib/generators/hyrax/templates/config/locales/hyrax.fr.yml +1 -1
  52. data/lib/generators/hyrax/templates/config/locales/hyrax.it.yml +1 -1
  53. data/lib/generators/hyrax/templates/config/locales/hyrax.zh.yml +1 -1
  54. data/lib/hyrax/configuration.rb +1 -1
  55. data/lib/hyrax/transactions.rb +23 -0
  56. data/lib/hyrax/transactions/container.rb +63 -0
  57. data/lib/hyrax/transactions/create_work.rb +47 -0
  58. data/lib/hyrax/transactions/steps/apply_permission_template.rb +29 -0
  59. data/lib/hyrax/transactions/steps/ensure_admin_set.rb +23 -0
  60. data/lib/hyrax/transactions/steps/ensure_permission_template.rb +27 -0
  61. data/lib/hyrax/transactions/steps/save_work.rb +35 -0
  62. data/lib/hyrax/transactions/steps/set_default_admin_set.rb +25 -0
  63. data/lib/hyrax/transactions/steps/set_modified_date.rb +25 -0
  64. data/lib/hyrax/transactions/steps/set_uploaded_date.rb +28 -0
  65. data/lib/hyrax/version.rb +1 -1
  66. data/spec/actors/hyrax/actors/create_with_files_ordered_members_actor_spec.rb +41 -0
  67. data/spec/actors/hyrax/actors/create_with_remote_files_ordered_members_actor_spec.rb +49 -0
  68. data/spec/actors/hyrax/actors/file_set_ordered_members_actor_spec.rb +35 -0
  69. data/spec/actors/hyrax/actors/ordered_members_actor_spec.rb +59 -0
  70. data/spec/controllers/hyrax/embargoes_controller_spec.rb +2 -0
  71. data/spec/controllers/hyrax/generic_works_controller_spec.rb +6 -1
  72. data/spec/factories/generic_works.rb +6 -0
  73. data/spec/features/collection_multi_membership_spec.rb +6 -6
  74. data/spec/features/work_show_spec.rb +58 -5
  75. data/spec/helpers/hyrax/batch_edits_helper_spec.rb +4 -2
  76. data/spec/helpers/hyrax/iiif_helper_spec.rb +44 -0
  77. data/spec/hyrax/transactions/create_work_spec.rb +155 -0
  78. data/spec/hyrax/transactions/steps/apply_permission_template_spec.rb +72 -0
  79. data/spec/hyrax/transactions/steps/ensure_admin_set_spec.rb +25 -0
  80. data/spec/hyrax/transactions/steps/ensure_permission_template_spec.rb +33 -0
  81. data/spec/hyrax/transactions/steps/save_work_spec.rb +32 -0
  82. data/spec/hyrax/transactions/steps/set_default_admin_set_spec.rb +38 -0
  83. data/spec/hyrax/transactions/steps/set_modified_date_spec.rb +22 -0
  84. data/spec/hyrax/transactions/steps/set_uploaded_date_spec.rb +32 -0
  85. data/spec/jobs/attach_files_to_work_with_ordered_members_job_spec.rb +13 -0
  86. data/spec/presenters/hyrax/presenter_renderer_spec.rb +4 -2
  87. data/spec/presenters/hyrax/work_show_presenter_spec.rb +46 -2
  88. data/spec/services/hyrax/permission_template_applicator_spec.rb +69 -0
  89. data/spec/spec_helper.rb +13 -2
  90. data/spec/views/catalog/index.html.erb_spec.rb +7 -4
  91. data/spec/views/hyrax/admin/admin_sets/_show_actions.html.erb_spec.rb +2 -0
  92. data/spec/views/hyrax/admin/admin_sets/_show_document_list_row.html.erb_spec.rb +4 -1
  93. data/spec/views/hyrax/admin/admin_sets/index.html.erb_spec.rb +6 -2
  94. data/spec/views/hyrax/admin/admin_sets/index.json.erb_spec.rb +1 -2
  95. data/spec/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb_spec.rb +1 -1
  96. data/spec/views/hyrax/admin/collection_types/_form_settings.html.erb_spec.rb +5 -26
  97. data/spec/views/hyrax/admin/collection_types/index.html.erb_spec.rb +26 -5
  98. data/spec/views/hyrax/admin/stats/show.html.erb_spec.rb +1 -0
  99. data/spec/views/hyrax/base/_attribute_rows.html.erb_spec.rb +5 -1
  100. data/spec/views/hyrax/base/_attributes.html.erb_spec.rb +1 -0
  101. data/spec/views/hyrax/base/_form_rendering.html.erb_spec.rb +5 -1
  102. data/spec/views/hyrax/base/_items.html.erb_spec.rb +2 -0
  103. data/spec/views/hyrax/base/_relationships.html.erb_spec.rb +2 -1
  104. data/spec/views/hyrax/base/_show_actions.html.erb_spec.rb +71 -0
  105. data/spec/views/hyrax/base/file_manager.html.erb_spec.rb +11 -14
  106. data/spec/views/hyrax/base/show.html.erb_spec.rb +2 -2
  107. data/spec/views/hyrax/base/show.json.jbuilder_spec.rb +3 -1
  108. data/spec/views/hyrax/collections/_show_document_list_row.html.erb_spec.rb +6 -1
  109. data/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb +5 -5
  110. data/spec/views/hyrax/collections/_subcollection_list.html.erb_spec.rb +1 -1
  111. data/spec/views/hyrax/collections/show.html.erb_spec.rb +3 -2
  112. data/spec/views/hyrax/dashboard/collections/_form_share.erb_spec.rb +1 -1
  113. data/spec/views/hyrax/dashboard/collections/_form_share_table.html.erb_spec.rb +1 -1
  114. data/spec/views/hyrax/dashboard/collections/_show_document_list_row.html.erb_spec.rb +6 -1
  115. data/spec/views/hyrax/dashboard/collections/_subcollection_list.html.erb_spec.rb +1 -1
  116. data/spec/views/hyrax/dashboard/collections/edit.html.erb_spec.rb +3 -1
  117. data/spec/views/hyrax/dashboard/profiles/show.html.erb_spec.rb +2 -3
  118. data/spec/views/hyrax/file_sets/_show_characterization_details.html.erb_spec.rb +1 -2
  119. data/spec/views/hyrax/file_sets/_single_use_links.html.erb_spec.rb +1 -2
  120. data/spec/views/hyrax/homepage/_sortable_featured.html.erb_spec.rb +1 -1
  121. data/spec/views/hyrax/my/_collection_action_menu.html.erb_spec.rb +5 -5
  122. data/spec/views/hyrax/my/collections/_list_collections.html.erb_spec.rb +11 -8
  123. data/spec/views/hyrax/users/index.html.erb_spec.rb +1 -0
  124. data/spec/views/hyrax/users/show.html.erb_spec.rb +3 -0
  125. data/template.rb +1 -1
  126. metadata +65 -3
  127. data/app/views/hyrax/dashboard/collections/_form_default_group_delt.html.erb +0 -27
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ ##
5
+ # A transaction for creating a Work ready for use in Hyrax. Handles
6
+ # ensuring admin sets and permission templates are present, and setting
7
+ # system managed dates prior to save.
8
+ #
9
+ # @note This is an experimental replacement for the actor stack's `#create`
10
+ # stack. In time, we hope this will have feature parity with that stack,
11
+ # along with improved architecture, error handling, readability, and
12
+ # customizability. While this develops, please provide feedback.
13
+ #
14
+ # @since 2.4.0
15
+ #
16
+ # @example Creating a work transactionally
17
+ # work = MyWork.new(title: ['Comet in Moominland'])
18
+ # result = Hyrax::Transactions::CreateWork.call(work)
19
+ # result.success? => true
20
+ #
21
+ # @example Handling errors with procedural style
22
+ # work = MyWork.new # invalid work (no title)
23
+ # result = Hyrax::Transactions::CreateWork.call(work)
24
+ # result.success? => false
25
+ #
26
+ # result.failure # => failure description or object
27
+ #
28
+ # @example Handling errors with `#or`
29
+ # work = MyWork.new # invalid work (no title)
30
+ #
31
+ # Hyrax::Transactions::CreateWork
32
+ # .call(work)
33
+ # .or { |error| handle_error(error) }
34
+ #
35
+ # @see https://dry-rb.org/gems/dry-transaction/
36
+ class CreateWork
37
+ include Dry::Transaction(container: Hyrax::Transactions::Container)
38
+
39
+ step :set_default_admin_set, with: 'work.set_default_admin_set'
40
+ step :ensure_admin_set, with: 'work.ensure_admin_set'
41
+ step :apply_permission_template, with: 'work.apply_permission_template'
42
+ step :set_modified_date, with: 'work.set_modified_date'
43
+ step :set_uploaded_date, with: 'work.set_uploaded_date'
44
+ step :save_work, with: 'work.save_work'
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ module Steps
5
+ ##
6
+ # A `dry-transcation` step that applies a permission template.
7
+ #
8
+ # @since 2.4.0
9
+ class ApplyPermissionTemplate
10
+ include Dry::Transaction::Operation
11
+
12
+ ##
13
+ # @param [Hyrax::WorkBehavior] work
14
+ #
15
+ # @return [Dry::Monads::Result]
16
+ def call(work)
17
+ return Failure(:missing_permission) unless
18
+ (template = work&.admin_set&.permission_template)
19
+
20
+ Hyrax::PermissionTemplateApplicator.apply(template).to(model: work)
21
+
22
+ Success(work)
23
+ rescue ActiveRecord::RecordNotFound => err
24
+ Failure(err)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ module Steps
5
+ ##
6
+ # A `dry-transaction` step that ensures the input `work` has an AdminSet.
7
+ #
8
+ # @since 2.4.0
9
+ class EnsureAdminSet
10
+ include Dry::Transaction::Operation
11
+
12
+ ##
13
+ # @param [Hyrax::WorkBehavior] work
14
+ #
15
+ # @return [Dry::Monads::Result] `Failure` if there is no `AdminSet` for
16
+ # the input; `Success(input)`, otherwise.
17
+ def call(work)
18
+ work.admin_set_id ? Success(work) : Failure(:no_admin_set_id)
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ module Steps
5
+ ##
6
+ # A `dry-transaction` step that ensures the input `work` has a permission
7
+ # template.
8
+ #
9
+ # @since 2.4.0
10
+ class EnsurePermissionTemplate
11
+ include Dry::Transaction::Operation
12
+
13
+ ##
14
+ # @param [Hyrax::WorkBehavior] work
15
+ #
16
+ # @return [Dry::Monads::Result] `Failure` if there is no
17
+ # `PermissionTemplate` for the input; `Success(input)`, otherwise.
18
+ def call(work)
19
+ return Failure(:no_permission_template) unless
20
+ Hyrax::PermissionTemplate.find_by(source_id: work.admin_set&.id)
21
+
22
+ Success(work)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,35 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ module Steps
5
+ ##
6
+ # A `dry-transaction` step that saves an input work.
7
+ #
8
+ # @example saving a work
9
+ # step = Hyrax::Transactions::Steps::SaveWork.new
10
+ # work = MyWork.new(title: ['Comet in Moominland'])
11
+ #
12
+ # step.call(work) # => Success
13
+ #
14
+ # @example handling error cases
15
+ # step = Hyrax::Transactions::Steps::SaveWork.new
16
+ # work = MyWork.new(title: [:invalid_title])
17
+ #
18
+ # step.call(work).or { |err| puts err.messages }
19
+ #
20
+ # @since 2.4.0
21
+ class SaveWork
22
+ include Dry::Transaction::Operation
23
+
24
+ ##
25
+ # @param [Hyrax::WorkBehavior] work
26
+ #
27
+ # @return [Dry::Monads::Result] `Failure` if the work fails to save;
28
+ # `Success(input)`, otherwise.
29
+ def call(work)
30
+ work.save ? Success(work) : Failure(work.errors)
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ module Steps
5
+ ##
6
+ # A `dry-transaction` step that sets the `AdminSet` for an input work to
7
+ # the default admin set, if none is already set. Creates the default
8
+ # admin set if it doesn't already exist.
9
+ class SetDefaultAdminSet
10
+ include Dry::Transaction::Operation
11
+
12
+ ##
13
+ # @param [Hyrax::WorkBehavior] work
14
+ #
15
+ # @return [Dry::Monads::Result]
16
+ def call(work)
17
+ work.admin_set ||=
18
+ AdminSet.find(AdminSet.find_or_create_default_admin_set_id)
19
+
20
+ Success(work)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ module Steps
5
+ ##
6
+ # A `dry-transaction` step that sets the modified date to now for an
7
+ # input work.
8
+ #
9
+ # @since 2.4.0
10
+ class SetModifiedDate
11
+ include Dry::Transaction::Operation
12
+
13
+ ##
14
+ # @param [Hyrax::WorkBehavior] work
15
+ #
16
+ # @return [Dry::Monads::Result]
17
+ def call(work)
18
+ work.date_modified = Hyrax::TimeService.time_in_utc
19
+
20
+ Success(work)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module Transactions
4
+ module Steps
5
+ ##
6
+ # A `dry-transaction` step that sets the uploaded date to now for an
7
+ # input work.
8
+ #
9
+ # @since 2.4.0
10
+ class SetUploadedDate
11
+ include Dry::Transaction::Operation
12
+
13
+ ##
14
+ # @note the current implementation sets the uploaded date to
15
+ # `#date_modified` if it exists, falling back on the current datetime.
16
+ #
17
+ # @param [Hyrax::WorkBehavior] work
18
+ #
19
+ # @return [Dry::Monads::Result]
20
+ def call(work)
21
+ work.date_uploaded =
22
+ work.date_modified || Hyrax::TimeService.time_in_utc
23
+ Success(work)
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -1,3 +1,3 @@
1
1
  module Hyrax
2
- VERSION = '2.3.3'.freeze
2
+ VERSION = '2.4.0'.freeze
3
3
  end
@@ -0,0 +1,41 @@
1
+ RSpec.describe Hyrax::Actors::CreateWithFilesOrderedMembersActor do
2
+ let(:user) { create(:user) }
3
+ let(:ability) { ::Ability.new(user) }
4
+ let(:work) { create(:generic_work, user: user) }
5
+ let(:env) { Hyrax::Actors::Environment.new(work, ability, attributes) }
6
+ let(:terminator) { Hyrax::Actors::Terminator.new }
7
+ let(:uploaded_file1) { create(:uploaded_file, user: user) }
8
+ let(:uploaded_file2) { create(:uploaded_file, user: user) }
9
+ let(:uploaded_file_ids) { [uploaded_file1.id, uploaded_file2.id] }
10
+ let(:attributes) { { uploaded_files: uploaded_file_ids } }
11
+
12
+ subject(:middleware) do
13
+ stack = ActionDispatch::MiddlewareStack.new.tap do |middleware|
14
+ middleware.use described_class
15
+ end
16
+ stack.build(terminator)
17
+ end
18
+
19
+ [:create, :update].each do |mode|
20
+ context "on #{mode}" do
21
+ before do
22
+ allow(terminator).to receive(mode).and_return(true)
23
+ end
24
+ context "when uploaded_file" do
25
+ it "invoke the job" do
26
+ expect(AttachFilesToWorkWithOrderedMembersJob).to receive(:perform_later)
27
+ middleware.public_send(mode, env)
28
+ end
29
+ end
30
+
31
+ context "when no uploaded_file" do
32
+ let(:uploaded_file_ids) { [] }
33
+
34
+ it "doesn't invoke job" do
35
+ expect(AttachFilesToWorkWithOrderedMembersJob).not_to receive(:perform_later)
36
+ expect(middleware.public_send(mode, env)).to be true
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,49 @@
1
+ RSpec.describe Hyrax::Actors::CreateWithRemoteFilesOrderedMembersActor do
2
+ let(:terminator) { Hyrax::Actors::Terminator.new }
3
+ let(:actor) { stack.build(terminator) }
4
+ let(:stack) do
5
+ ActionDispatch::MiddlewareStack.new.tap do |middleware|
6
+ middleware.use described_class
7
+ end
8
+ end
9
+ let(:user) { create(:user) }
10
+ let(:ability) { Ability.new(user) }
11
+ let(:work) { create(:generic_work, user: user) }
12
+ let(:url1) { "https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt" }
13
+ let(:url2) { "https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf" }
14
+
15
+ let(:remote_files) do
16
+ [{ url: url1,
17
+ expires: "2014-03-31T20:37:36.214Z",
18
+ file_name: "filepicker-demo.txt.txt" },
19
+ { url: url2,
20
+ expires: "2014-03-31T20:37:36.731Z",
21
+ file_name: "Getting+Started.pdf" }]
22
+ end
23
+ let(:attributes) { { remote_files: remote_files } }
24
+ let(:environment) { Hyrax::Actors::Environment.new(work, ability, attributes) }
25
+
26
+ before do
27
+ allow(terminator).to receive(:create).and_return(true)
28
+ end
29
+
30
+ context "with two file_sets" do
31
+ let(:remote_files) do
32
+ [{ url: url1,
33
+ expires: "2014-03-31T20:37:36.214Z",
34
+ file_name: "filepicker-demo.txt.txt" },
35
+ { url: url2,
36
+ expires: "2014-03-31T20:37:36.731Z",
37
+ file_name: "Getting+Started.pdf" }]
38
+ end
39
+
40
+ it "attaches files and passes ordered_members to OrderedMembersActor in correct order" do
41
+ expect(Hyrax::Actors::OrderedMembersActor).to receive(:new).with([FileSet, FileSet], user).and_return(Hyrax::Actors::OrderedMembersActor)
42
+ expect(Hyrax::Actors::OrderedMembersActor).to receive(:attach_ordered_members_to_work).with(work)
43
+ expect(ImportUrlJob).to receive(:perform_later).with(FileSet, Hyrax::Operation, {}).twice
44
+ expect(actor.create(environment)).to be true
45
+ expect(actor.ordered_members.first.label).to eq('filepicker-demo.txt.txt')
46
+ expect(actor.ordered_members.last.label).to eq('Getting+Started.pdf')
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,35 @@
1
+ RSpec.describe Hyrax::Actors::FileSetOrderedMembersActor do
2
+ include ActionDispatch::TestProcess
3
+
4
+ let(:user) { create(:user) }
5
+ let(:file_path) { File.join(fixture_path, 'world.png') }
6
+ let(:file) { fixture_file_upload(file_path, 'image/png') } # we will override for the different types of File objects
7
+ let(:local_file) { File.open(file_path) }
8
+ let(:file_set) { create(:file_set, content: local_file) }
9
+ let(:actor) { described_class.new(file_set, user) }
10
+ let(:relation) { :original_file }
11
+ let(:file_actor) { Hyrax::Actors::FileActor.new(file_set, relation, user) }
12
+
13
+ describe 'creating metadata, content and attaching to a work' do
14
+ let(:work) { create(:generic_work) }
15
+ let(:date_today) { DateTime.current }
16
+
17
+ subject { file_set.reload }
18
+
19
+ before do
20
+ allow(DateTime).to receive(:current).and_return(date_today)
21
+ allow(actor).to receive(:acquire_lock_for).and_yield
22
+ actor.create_metadata
23
+ actor.create_content(file)
24
+ actor.attach_to_work(work)
25
+ end
26
+
27
+ context 'when a work is provided' do
28
+ it 'does not add the FileSet to the parent work' do
29
+ expect(subject.parents).to eq []
30
+ expect(subject.visibility).to eq 'restricted'
31
+ expect(work.reload.file_sets).not_to include(subject)
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,59 @@
1
+ require 'redlock'
2
+
3
+ RSpec.describe Hyrax::Actors::OrderedMembersActor do
4
+ include ActionDispatch::TestProcess
5
+
6
+ let(:user) { create(:user) }
7
+ let(:actor) { described_class.new([file_set], user) }
8
+ let(:file_set) { build(:file_set) }
9
+ let(:work) { create(:generic_work) }
10
+
11
+ describe 'attaching to a work' do
12
+ before do
13
+ allow(actor).to receive(:acquire_lock_for).and_yield
14
+ actor.attach_ordered_members_to_work(work)
15
+ end
16
+
17
+ context 'when a work is provided' do
18
+ it 'adds the FileSet to the parent work' do
19
+ expect(file_set.parents).to eq [work]
20
+ expect(work.reload.file_sets).to include(file_set)
21
+ end
22
+ end
23
+
24
+ context 'with multiple file_sets' do
25
+ let(:work_v1) { create(:generic_work) } # this version of the work has no members
26
+
27
+ before do # another file_set is added
28
+ work.ordered_members << create(:file_set)
29
+ work.save!
30
+ end
31
+
32
+ it "now contains two file_sets" do
33
+ expect(work.members.size).to eq 2
34
+ end
35
+ end
36
+
37
+ context 'with multiple versions' do
38
+ let(:work_v1) { create(:generic_work) } # this version of the work has no members
39
+
40
+ before do # another version of the same work is saved with a member
41
+ work_v2 = ActiveFedora::Base.find(work_v1.id)
42
+ work_v2.ordered_members << create(:file_set)
43
+ work_v2.save!
44
+ end
45
+
46
+ it "writes to the most up to date version" do
47
+ actor.attach_ordered_members_to_work(work_v1)
48
+ expect(work_v1.members.size).to eq 2
49
+ end
50
+ end
51
+ end
52
+
53
+ describe "#runs callbacks" do
54
+ it 'runs callbacks' do
55
+ expect(FileSetAttachedEventJob).to receive(:perform_later).with(file_set, user)
56
+ actor.attach_ordered_members_to_work(work)
57
+ end
58
+ end
59
+ end
@@ -107,6 +107,7 @@ RSpec.describe Hyrax::EmbargoesController do
107
107
  expect(a_work.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
108
108
  expect(file_set.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
109
109
  expect(response).to redirect_to embargoes_path
110
+ expect(flash[:notice]).to be_present
110
111
  end
111
112
  end
112
113
 
@@ -138,6 +139,7 @@ RSpec.describe Hyrax::EmbargoesController do
138
139
  expect(file_set2.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
139
140
  expect(file_set3.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
140
141
  expect(response).to redirect_to embargoes_path
142
+ expect(flash[:notice]).to be_present
141
143
  end
142
144
  end
143
145
  end