sufia 7.3.0.rc3 → 7.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (103) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.eslintrc +6 -5
  4. data/.rubocop.yml +0 -1
  5. data/.rubocop_todo.yml +0 -8
  6. data/README.md +10 -5
  7. data/app/actors/sufia/actors/attach_members_actor.rb +70 -0
  8. data/app/actors/sufia/apply_permission_template_actor.rb +4 -4
  9. data/app/actors/sufia/default_admin_set_actor.rb +10 -7
  10. data/app/assets/javascripts/sufia.js +3 -1
  11. data/app/assets/javascripts/sufia/app.js +7 -18
  12. data/app/assets/javascripts/sufia/autocomplete.es6 +56 -57
  13. data/app/assets/javascripts/sufia/autocomplete/language.es6 +1 -2
  14. data/app/assets/javascripts/sufia/autocomplete/location.es6 +1 -1
  15. data/app/assets/javascripts/sufia/autocomplete/subject.es6 +1 -3
  16. data/app/assets/javascripts/sufia/autocomplete/work.es6 +31 -22
  17. data/app/assets/javascripts/sufia/{editor.js → content_blocks.js} +0 -0
  18. data/app/assets/javascripts/sufia/editor.es6 +47 -0
  19. data/app/assets/javascripts/sufia/editor/admin_set_widget.es6 +39 -0
  20. data/app/assets/javascripts/sufia/notifications.es6 +13 -13
  21. data/app/assets/javascripts/sufia/permissions/control.es6 +3 -3
  22. data/app/assets/javascripts/sufia/permissions/group_controls.es6 +2 -2
  23. data/app/assets/javascripts/sufia/permissions/user_controls.es6 +3 -3
  24. data/app/assets/javascripts/sufia/relationships.js +4 -2
  25. data/app/assets/javascripts/sufia/relationships/control.es6 +83 -0
  26. data/app/assets/javascripts/sufia/relationships/registry.es6 +60 -0
  27. data/app/assets/javascripts/sufia/relationships/registry_entry.es6 +38 -0
  28. data/app/assets/javascripts/sufia/relationships/work.es6 +7 -0
  29. data/app/assets/javascripts/sufia/save_work/required_fields.es6 +1 -1
  30. data/app/assets/javascripts/sufia/save_work/save_work_control.es6 +19 -11
  31. data/app/assets/javascripts/sufia/save_work/visibility_component.es6 +19 -10
  32. data/app/assets/javascripts/sufia/select_work_type.es6 +8 -6
  33. data/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb +1 -1
  34. data/app/controllers/concerns/sufia/works_controller_behavior.rb +7 -0
  35. data/app/controllers/sufia/admin/admin_sets_controller.rb +5 -2
  36. data/app/forms/sufia/forms/batch_edit_form.rb +2 -1
  37. data/app/forms/sufia/forms/work_form.rb +19 -17
  38. data/app/models/concerns/sufia/admin_set_behavior.rb +38 -0
  39. data/app/presenters/sufia/admin_set_options_presenter.rb +51 -0
  40. data/app/presenters/sufia/admin_set_presenter.rb +11 -0
  41. data/app/search_builders/sufia/find_works_search_builder.rb +1 -0
  42. data/app/services/sufia/actor_factory.rb +1 -0
  43. data/app/services/sufia/admin_set_create_service.rb +9 -9
  44. data/app/services/sufia/admin_set_service.rb +0 -28
  45. data/app/services/sufia/workflow/abstract_notification.rb +14 -1
  46. data/app/services/sufia/workflow/changes_required_notification.rb +2 -2
  47. data/app/services/sufia/workflow/deposited_notification.rb +1 -1
  48. data/app/services/sufia/workflow/pending_review_notification.rb +1 -1
  49. data/app/views/curation_concerns/base/_find_work_widget.html.erb +10 -16
  50. data/app/views/curation_concerns/base/_form.html.erb +5 -1
  51. data/app/views/curation_concerns/base/_form_child_work_relationships.html.erb +22 -32
  52. data/app/views/curation_concerns/base/_form_relationships.html.erb +4 -7
  53. data/app/views/curation_concerns/base/_guts4form.html.erb +7 -1
  54. data/app/views/sufia/admin/admin_sets/_form_participants.html.erb +3 -3
  55. data/app/views/sufia/admin/admin_sets/show.html.erb +10 -2
  56. data/config/initializers/monkey_patch_admin_set.rb +2 -0
  57. data/config/locales/sufia.en.yml +2 -0
  58. data/db/migrate/20170317141521_permission_template_change_column_workflow_name.rb +5 -0
  59. data/lib/generators/sufia/templates/workflow.json.erb +1 -0
  60. data/lib/sufia/version.rb +1 -1
  61. data/lib/tasks/migrate.rake +1 -1
  62. data/spec/actors/sufia/actors/attach_members_actor_spec.rb +68 -0
  63. data/spec/actors/sufia/apply_permission_template_actor_spec.rb +7 -3
  64. data/spec/actors/sufia/default_admin_set_actor_spec.rb +1 -1
  65. data/spec/controllers/sufia/admin/admin_sets_controller_spec.rb +21 -6
  66. data/spec/controllers/sufia/admin/permission_templates_controller_spec.rb +1 -1
  67. data/spec/controllers/sufia/batch_uploads_controller_spec.rb +24 -2
  68. data/spec/factories/permission_templates.rb +1 -0
  69. data/spec/factories/workflows.rb +1 -1
  70. data/spec/forms/curation_concerns/generic_work_form_spec.rb +5 -2
  71. data/spec/forms/sufia/forms/batch_edit_form_spec.rb +1 -1
  72. data/spec/forms/sufia/forms/work_form_spec.rb +32 -19
  73. data/spec/javascripts/autocomplete_spec.js.coffee +12 -33
  74. data/spec/javascripts/helpers/test_fixtures.js.coffee +10 -1
  75. data/spec/javascripts/relationships_control_spec.js.coffee +27 -0
  76. data/spec/javascripts/save_work_spec.js +9 -6
  77. data/spec/javascripts/visibility_component_spec.js +17 -8
  78. data/spec/models/admin_set_spec.rb +69 -0
  79. data/spec/presenters/sufia/admin_set_options_presenter_spec.rb +73 -0
  80. data/spec/presenters/sufia/admin_set_presenter_spec.rb +31 -2
  81. data/spec/services/sufia/actor_factory_spec.rb +2 -0
  82. data/spec/services/sufia/admin_set_create_service_spec.rb +4 -2
  83. data/spec/services/sufia/admin_set_service_spec.rb +0 -72
  84. data/spec/services/sufia/workflow/changes_required_notification_spec.rb +1 -1
  85. data/spec/services/sufia/workflow/deposited_notification_spec.rb +1 -1
  86. data/spec/services/sufia/workflow/pending_review_notification_spec.rb +1 -1
  87. data/spec/views/curation_concerns/base/_find_work_widget.html.erb_spec.rb +1 -2
  88. data/spec/views/curation_concerns/base/_form_child_work_relationships.html.erb_spec.rb +27 -62
  89. data/spec/views/curation_concerns/base/_form_relationships.html.erb_spec.rb +4 -2
  90. data/spec/views/sufia/admin/admin_sets/_form_participants.html.erb_spec.rb +1 -1
  91. data/spec/views/sufia/admin/admin_sets/_form_visibility.html.erb_spec.rb +3 -1
  92. data/spec/views/sufia/admin/admin_sets/show.html.erb_spec.rb +59 -0
  93. data/sufia.gemspec +3 -2
  94. data/template.rb +1 -1
  95. metadata +34 -19
  96. data/app/assets/javascripts/sufia/relationships/table.es6 +0 -206
  97. data/app/assets/javascripts/sufia/relationships/table_row.es6 +0 -79
  98. data/app/views/curation_concerns/base/_form_parent_work_relationships.html.erb +0 -43
  99. data/app/views/records/edit_fields/_in_works_ids.html.erb +0 -59
  100. data/spec/javascripts/helpers/test_responses.js +0 -13
  101. data/spec/javascripts/relationships_table_spec.js.coffee +0 -83
  102. data/spec/views/curation_concerns/base/_form_parent_work_relationships.html.erb_spec.rb +0 -114
  103. data/spec/views/records/edit_fields/_in_works_ids.html.erb_spec.rb +0 -113
@@ -1,79 +0,0 @@
1
- export class RelationshipsTableRow {
2
- /**
3
- * Inititializes a new table row class
4
- * @param {jQuery} $table the table which this row is related to
5
- */
6
- constructor($table){
7
- this.table = $table;
8
- this.element = null;
9
- }
10
-
11
- /**
12
- * The title element
13
- * @returns {jQuery} the title element
14
- */
15
- get title() { return this.element.find("a.title:first"); }
16
-
17
- /**
18
- * The input field
19
- * @returns {jQuery} the input field
20
- */
21
- get input() { return this.element.find("input.related_works_ids:first"); }
22
-
23
- /**
24
- * The "Add" button
25
- * @returns {jQuery} the add button element
26
- */
27
- get addButton() { return this.element.find(".btn-add-row"); }
28
-
29
- /**
30
- * The "Remove" button
31
- * @returns {jQuery} the remove button element
32
- */
33
- get removeButton() { return this.element.find(".btn-remove-row"); }
34
-
35
- /**
36
- * The "Edit" button
37
- * @returns {jQuery} the edit button element
38
- */
39
- get editButton() { return this.element.find("a.edit:first"); }
40
-
41
- /**
42
- * Clone the row, set the element in this instance of the class, and reset the proper styles for this row. Insert
43
- * this new row before the row passed in.. leaving the passed in row styled as-is, the caller of this method is responsible
44
- * for properly handling adjustment to the passed in row
45
- * @param {jQuery} $row the row to be cloned
46
- */
47
- clone($row){
48
- this.element = $row.clone();
49
- this.addButton.addClass("hidden");
50
- this.removeButton.removeClass("hidden");
51
- this.element.insertBefore($row);
52
- }
53
-
54
- /**
55
- * Make an ajax call to the supplied url.
56
- * After a row is cloned, this method could be called to refresh the row with more details (title, appropriate links, etc)
57
- * based on the details returned from the server.
58
- * @param {String} query_url the url to be called for querying details from the server
59
- */
60
- callAjaxQuery(query_url) {
61
- let $this = this;
62
- $.getJSON(query_url, function (data) {
63
- // Set the cloned input to have the proper name and value for posting the
64
- // form to the server, and hide it.
65
- $this.input.removeClass("new-form-control")
66
- .addClass("hidden")
67
- .val(data.id);
68
-
69
- // Set the linkified title and show.
70
- $this.title.text(data.title[0])
71
- .attr("href", query_url)
72
- .removeClass("hidden");
73
-
74
- // Set the edit button link and show.
75
- $this.editButton.attr("href", query_url + "/edit")
76
- .removeClass("hidden");
77
- });
78
- }
79
- }
@@ -1,43 +0,0 @@
1
- <div class="form-group multi_value optional managed">
2
-
3
- <table class="table table-striped related-files relationships-ajax-enabled"
4
- data-query-url="<%= polymorphic_path([main_app, :curation_concerns, curation_concern.model_name.singular], id: '$id') %>">
5
- <thead>
6
- <tr>
7
- <th>Parent Work</th>
8
- <th>Actions</th>
9
- </tr>
10
- </thead>
11
- <tbody>
12
-
13
- <% f.object.in_work_members.each do |member| %>
14
- <tr>
15
- <td>
16
- <%= link_to member.title.first, [main_app, member] %>
17
- <input class="string multi_value optional form-control related_works_ids form-control multi-text-field hidden" value="<%= member.id %>" id="work_in_works_ids" aria-labelledby="work_in_works_ids_label" name="<%= f.object.model_name.param_key %>[in_works_ids][]" type="text">
18
- </td>
19
- <td>
20
- <div class="child-actions">
21
- <%= link_to "Edit", [main_app, :edit, member], target: "_blank", class: 'btn btn-default' %>
22
- <a class="btn btn-danger btn-remove-row">Remove</a>
23
- </div>
24
- </td>
25
- </tr>
26
- <% end %>
27
- <tr class="new-row">
28
- <td>
29
- <a href="" class="title hidden"></a>
30
- <%= render "find_work_widget", f: f, id_name: 'work_parent_members_ids', id_type: 'in_works_ids', user_email: current_user.email, id: f.object.model.id %>
31
- <div class="message has-warning hidden"></div>
32
- </td>
33
- <td>
34
- <div class="child-actions">
35
- <a href="" class="edit hidden btn btn-default" target="_blank">Edit</a>
36
- <a class="btn btn-danger btn-remove-row hidden">Remove</a>
37
- <a class="btn btn-primary btn-add-row">Add</a>
38
- </div>
39
- </td>
40
- </tr>
41
- </tbody>
42
- </table>
43
- </div>
@@ -1,59 +0,0 @@
1
- <%# Form UI behavior code and details;
2
- Code:
3
- app/assets/javascripts/sufia/relationships
4
- CSS:
5
- table.relationships-ajax-enabled : Used by sufia JS app as selector to wire up the UI functionality
6
- tr.new-row : The basic template row for cloning when user clicks "Add"
7
- .btn-remove-row : Button to remove its parent TR from the table
8
- .btn-add-row : Button to clone its parent TR and inject a new row into the table
9
- input.new-form-control : Input field for client client side validation and additional features
10
- .message.has-warning : Used to display UI errors related to input values and server errors
11
- HTML Properties:
12
- table:
13
- data-query-url : URL base to append newly added work ID to for querying details (title, href)
14
- %>
15
- <% if f.object.class.multiple? key %>
16
- <div class="form-group multi_value optional work_in_works_ids managed">
17
- <table class="table table-striped related-files relationships-ajax-enabled"
18
- data-query-url="<%=polymorphic_path([main_app, :curation_concerns, curation_concern.model_name.singular], id: '$id') %>">
19
- <thead>
20
- <tr>
21
- <th>Parent Work</th>
22
- <th>Actions</th>
23
- </tr>
24
- </thead>
25
- <tbody>
26
- <% curation_concern.in_works.each do |parent| %>
27
- <tr>
28
- <td>
29
- <%= link_to "#{parent.title.first}", polymorphic_path([main_app, :curation_concerns, curation_concern.model_name.singular], id: parent.id) %>
30
- <input class="string multi_value optional form-control related_works_ids form-control multi-text-field hidden" name="<%= curation_concern.model_name.param_key %>[in_works_ids][]" value="<%= parent.id %>" id="work_in_works_ids" aria-labelledby="work_in_works_ids_label" type="text">
31
- </td>
32
- <td>
33
- <div class="child-actions">
34
- <%= link_to "Edit", edit_polymorphic_path([main_app, :curation_concerns, curation_concern.model_name.singular], id: parent.id), target: "_blank", class: 'btn btn-default' %>
35
- <a class="btn btn-danger btn-remove-row">Remove</a>
36
- </div>
37
- </td>
38
- </tr>
39
- <% end %>
40
- <tr class="new-row">
41
- <td>
42
- <a href="" class="title hidden"></a>
43
- <input class="new-form-control string multi_value optional related_works_ids form-control multi-text-field" name="<%= curation_concern.model_name.param_key %>[in_works_ids][]" value="" aria-labelledby="work_in_works_ids_label" type="text">
44
- <div class="message has-warning hidden"></div>
45
- </td>
46
- <td>
47
- <div class="child-actions">
48
- <a href="" class="edit hidden btn btn-default" target="_blank">Edit</a>
49
- <a class="btn btn-danger btn-remove-row hidden">Remove</a>
50
- <a class="btn btn-primary btn-add-row">Add</a>
51
- </div>
52
- </td>
53
- </tr>
54
- </tbody>
55
- </table>
56
- </div>
57
- <% else %>
58
- <%= f.input key, required: f.object.required?(key) %>
59
- <% end %>
@@ -1,13 +0,0 @@
1
- var TestResponses = {
2
- relationships_table: {
3
- query_url_success: {
4
- id: "parent5678",
5
- title: ["Parent"]
6
- },
7
- ajax_add_success:{},
8
- ajax_remove_success:{},
9
- ajax_error: {
10
- responseText: "Error"
11
- },
12
- }
13
- }
@@ -1,83 +0,0 @@
1
- describe 'RelationshipsTable', ->
2
- control = require('sufia/relationships/table')
3
- form = null
4
- element = null
5
- btn_remove = null
6
- btn_add = null
7
- btn_edit = null
8
- input = null
9
- message = null
10
- test_fixtures = TestFixtures
11
- test_responses = TestResponses
12
- deferred_ajax = null
13
-
14
- beforeEach ->
15
- form = $(test_fixtures.relationships_table.html)
16
- element = form.find("table")
17
- btn_remove = element.find('.btn-remove-row')
18
- btn_add = element.find('.btn-add-row')
19
- btn_edit = element.find('.edit')
20
- input = element.find('.new-form-control')
21
- message = element.find('.message')
22
- target = new control.RelationshipsTable(element)
23
- jasmine.Ajax.install()
24
- deferred_ajax = new jQuery.Deferred()
25
- spyOn($,'ajax').and.returnValue(deferred_ajax)
26
- spyOn($,'getJSON').and.callFake((url, success) ->
27
- success(test_responses.relationships_table.query_url_success))
28
-
29
- afterEach ->
30
- jasmine.Ajax.uninstall()
31
-
32
- describe 'when adding/removing a row', ->
33
- # the new-row is properly rendered
34
- it 'only displays one new row with an add button visible', ->
35
- expect(btn_remove.hasClass("hidden")).toBeTruthy()
36
- expect(btn_edit.hasClass("hidden")).toBeTruthy()
37
- expect(btn_add.hasClass("hidden")).toBeFalsy()
38
-
39
- it 'clicks add with a valid id', ->
40
- input.val(test_fixtures.relationships_table.parent_id)
41
- btn_add.click()
42
- deferred_ajax.resolve(test_responses.relationships_table.ajax_add_success)
43
- expect(message.hasClass("hidden")).toBeTruthy()
44
- expect(element.find("tbody tr").length).toEqual(2)
45
-
46
- it 'clicks add with an invalid id', ->
47
- input.val('invalid')
48
- btn_add.click()
49
- deferred_ajax.reject(test_responses.relationships_table.ajax_error)
50
- expect(message.hasClass("hidden")).toBeFalsy()
51
- expect(element.find("tbody tr").length).toEqual(1)
52
-
53
- it 'clicks add without an id', ->
54
- expect(message.hasClass("hidden")).toBeTruthy()
55
- btn_add.click()
56
- expect(message.hasClass("hidden")).toBeFalsy()
57
- expect(message.text()).toContain("ID cannot be empty")
58
- expect(element.find("tbody tr").length).toEqual(1)
59
-
60
- it 'clicks remove to remove a work', ->
61
- input.val(test_fixtures.relationships_table.parent_id)
62
- btn_add.click()
63
- deferred_ajax.resolve(test_responses.relationships_table.ajax_add_success)
64
- expect(element.find("tbody tr").length).toEqual(2)
65
- parent_row = element.find("tbody tr:first")
66
- parent_delete = parent_row.find(".btn-remove-row")
67
- parent_delete.click()
68
- deferred_ajax.resolve(test_responses.relationships_table.ajax_remove_success)
69
- expect(element.find("tbody tr").length).toEqual(1)
70
-
71
- it 'clicks add with a duplicate id', ->
72
- input.val(test_fixtures.relationships_table.parent_id)
73
- btn_add.click()
74
- deferred_ajax.resolve(test_responses.relationships_table.ajax_add_success)
75
- expect(element.find("tbody tr").length).toEqual(2)
76
- input = element.find("tbody tr:nth-child(2) .new-form-control")
77
- input.val(test_fixtures.relationships_table.parent_id)
78
- btn_add = element.find("tbody tr:nth-child(2) .btn-add-row")
79
- btn_add.click()
80
- message = element.find("tbody tr:nth-child(2) .message")
81
- expect(element.find("tbody tr").length).toEqual(2)
82
- expect(message.hasClass("hidden")).toBeFalsy()
83
- expect(message.text()).toContain("Work is already related")
@@ -1,114 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "curation_concerns/base/_form_parent_work_relationships.html.erb", type: :view do
4
- let(:work) do
5
- stub_model(GenericWork, id: '456', title: ["MyWork"])
6
- end
7
-
8
- let(:work_2) do
9
- stub_model(GenericWork, id: '567', title: ["Parent Work"])
10
- end
11
-
12
- let(:ability) { double }
13
-
14
- let(:form) do
15
- Sufia::Forms::WorkForm.new(work, ability)
16
- end
17
-
18
- let(:f) { double }
19
-
20
- let(:page) do
21
- render
22
- Capybara::Node::Simple.new(rendered)
23
- end
24
-
25
- before do
26
- view.lookup_context.view_paths.push 'app/views/curation_concerns'
27
- allow(view).to receive(:params).and_return(id: work.id)
28
- allow(view).to receive(:curation_concern).and_return(work)
29
- allow(view).to receive(:f).and_return(f)
30
- allow(f).to receive(:object).and_return(form)
31
- allow(controller).to receive(:current_user).and_return(stub_model(User))
32
- stub_template '_find_work_widget.html.erb' => "<input value=''/>"
33
- assign(:form, form)
34
- end
35
-
36
- context "When editing a work" do
37
- context "and no parent works are present" do
38
- before do
39
- allow(work).to receive(:in_works).and_return([])
40
- end
41
- it "has 1 empty parent work input" do
42
- expect(page).to have_selector("input[value='']", count: 1)
43
- end
44
-
45
- it "will not display the remove button in the actions" do
46
- expect(page).to have_selector(".btn-remove-row", visible: false)
47
- end
48
-
49
- it "will display the add button in the actions" do
50
- expect(page).to have_selector(".btn-add-row", visible: true, count: 1)
51
- end
52
- end
53
- context "When 1 parent work is present" do
54
- let(:work_2) do
55
- stub_model(GenericWork, id: '567', title: ["Test Parent Work"])
56
- end
57
-
58
- before do
59
- allow(work).to receive(:in_works).and_return([work_2])
60
- end
61
- it "has 1 empty parent work input with add button" do
62
- expect(page).to have_selector("input[value='']", count: 1)
63
- expect(page).to have_selector(".btn-add-row", visible: true, count: 1)
64
- end
65
-
66
- it "has an input box that is filled in with the parent id" do
67
- expect(page).to have_selector("input[value='#{work_2.id}']", count: 1)
68
- end
69
-
70
- it "generates a link for the parents first title" do
71
- expect(page).to have_link("Test Parent Work")
72
- end
73
-
74
- it "has an edit and remove button" do
75
- within ".old-row" do
76
- expect(page).to have_selector(".btn-remove-row", visible: true, count: 1)
77
- expect(page).to have_selector(".btn-edit-row", visible: true, count: 1)
78
- end
79
- end
80
- end
81
- context "When multiple parent works are present" do
82
- let(:work_2) do
83
- stub_model(GenericWork, id: '567', title: ["Test Parent Work"])
84
- end
85
- let(:work_3) do
86
- stub_model(GenericWork, id: '789', title: ["Test Parent Work 2"])
87
- end
88
- before do
89
- allow(work).to receive(:in_works).and_return([work_2, work_3])
90
- end
91
- it "has 1 empty parent work input with add button" do
92
- expect(page).to have_selector("input[value='']", count: 1)
93
- expect(page).to have_selector(".btn-add-row", visible: true, count: 1)
94
- end
95
-
96
- it "has an input box that is filled in with the parent ids" do
97
- expect(page).to have_selector("input[value='#{work_2.id}']", count: 1)
98
- expect(page).to have_selector("input[value='#{work_3.id}']", count: 1)
99
- end
100
-
101
- it "generates a link for the parents first title" do
102
- expect(page).to have_link("Test Parent Work")
103
- expect(page).to have_link("Test Parent Work 2")
104
- end
105
-
106
- it "has an edit and remove button" do
107
- within ".old-row" do
108
- expect(page).to have_selector(".btn-remove-row", visible: true, count: 2)
109
- expect(page).to have_selector(".btn-edit-row", visible: true, count: 2)
110
- end
111
- end
112
- end
113
- end
114
- end
@@ -1,113 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "records/edit_fields/_in_works_ids.html.erb", type: :view do
4
- let(:work) do
5
- stub_model(GenericWork, id: '456', title: ["MyWork"])
6
- end
7
-
8
- let(:work_2) do
9
- stub_model(GenericWork, id: '567', title: ["Child Work"])
10
- end
11
-
12
- let(:ability) { double }
13
-
14
- let(:form) do
15
- CurationConcerns::GenericWorkForm.new(work, ability)
16
- end
17
-
18
- let(:f) { double(object: form) }
19
-
20
- let(:page) do
21
- render
22
- Capybara::Node::Simple.new(rendered)
23
- end
24
-
25
- before do
26
- view.lookup_context.view_paths.push 'app/views/curation_concerns'
27
- allow(::ActiveFedora::Base).to receive(:find).and_return(work_2)
28
- allow(view).to receive(:curation_concern).and_return(work)
29
- allow(view).to receive(:f).and_return(f)
30
- allow(view).to receive(:key).and_return(:in_works_ids)
31
- allow(controller).to receive(:current_user).and_return(stub_model(User))
32
- assign(:form, form)
33
- end
34
-
35
- context "When editing a work" do
36
- context "and no parents are present" do
37
- before do
38
- allow(work).to receive(:in_works).and_return([])
39
- end
40
- it "has 1 empty parent work input" do
41
- expect(page).to have_selector("input[value='']", count: 1)
42
- end
43
-
44
- it "does not display the remove button in the actions" do
45
- expect(page).to have_selector(".btn-remove-row", visible: false)
46
- end
47
-
48
- it "displays the add button in the actions" do
49
- expect(page).to have_selector(".btn-add-row", visible: true, count: 1)
50
- end
51
- end
52
- context "When 1 parent work is present" do
53
- let(:work_2) do
54
- stub_model(GenericWork, id: '567', title: ["Test Parent Work"])
55
- end
56
-
57
- before do
58
- allow(work).to receive(:in_works).and_return([work_2])
59
- end
60
- it "has 1 empty parent work input with add button" do
61
- expect(page).to have_selector("input[value='']", count: 1)
62
- expect(page).to have_selector(".btn-add-row", visible: true, count: 1)
63
- end
64
-
65
- it "has an input box that is filled in with the parent id" do
66
- expect(page).to have_selector("input[value='#{work_2.id}']", count: 1)
67
- end
68
-
69
- it "generates a link for the parents first title" do
70
- expect(page).to have_link("Test Parent Work")
71
- end
72
-
73
- it "has an edit and remove button" do
74
- within ".old-row" do
75
- expect(page).to have_selector(".btn-remove-row", visible: true, count: 1)
76
- expect(page).to have_selector(".btn-edit-row", visible: true, count: 1)
77
- end
78
- end
79
- end
80
- context "When multiple parent works are present" do
81
- let(:work_2) do
82
- stub_model(GenericWork, id: '567', title: ["Test Parent Work"])
83
- end
84
- let(:work_3) do
85
- stub_model(GenericWork, id: '789', title: ["Test Parent Work 2"])
86
- end
87
- before do
88
- allow(work).to receive(:in_works).and_return([work_2, work_3])
89
- end
90
- it "has 1 empty parent work input with add button" do
91
- expect(page).to have_selector("input[value='']", count: 1)
92
- expect(page).to have_selector(".btn-add-row", visible: true, count: 1)
93
- end
94
-
95
- it "has an input box that is filled in with the parent ids" do
96
- expect(page).to have_selector("input[value='#{work_2.id}']", count: 1)
97
- expect(page).to have_selector("input[value='#{work_3.id}']", count: 1)
98
- end
99
-
100
- it "generates a link for the parents first title" do
101
- expect(page).to have_link("Test Parent Work")
102
- expect(page).to have_link("Test Parent Work 2")
103
- end
104
-
105
- it "has an edit and remove button" do
106
- within ".old-row" do
107
- expect(page).to have_selector(".btn-remove-row", visible: true, count: 2)
108
- expect(page).to have_selector(".btn-edit-row", visible: true, count: 2)
109
- end
110
- end
111
- end
112
- end
113
- end