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.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.eslintrc +6 -5
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +0 -8
- data/README.md +10 -5
- data/app/actors/sufia/actors/attach_members_actor.rb +70 -0
- data/app/actors/sufia/apply_permission_template_actor.rb +4 -4
- data/app/actors/sufia/default_admin_set_actor.rb +10 -7
- data/app/assets/javascripts/sufia.js +3 -1
- data/app/assets/javascripts/sufia/app.js +7 -18
- data/app/assets/javascripts/sufia/autocomplete.es6 +56 -57
- data/app/assets/javascripts/sufia/autocomplete/language.es6 +1 -2
- data/app/assets/javascripts/sufia/autocomplete/location.es6 +1 -1
- data/app/assets/javascripts/sufia/autocomplete/subject.es6 +1 -3
- data/app/assets/javascripts/sufia/autocomplete/work.es6 +31 -22
- data/app/assets/javascripts/sufia/{editor.js → content_blocks.js} +0 -0
- data/app/assets/javascripts/sufia/editor.es6 +47 -0
- data/app/assets/javascripts/sufia/editor/admin_set_widget.es6 +39 -0
- data/app/assets/javascripts/sufia/notifications.es6 +13 -13
- data/app/assets/javascripts/sufia/permissions/control.es6 +3 -3
- data/app/assets/javascripts/sufia/permissions/group_controls.es6 +2 -2
- data/app/assets/javascripts/sufia/permissions/user_controls.es6 +3 -3
- data/app/assets/javascripts/sufia/relationships.js +4 -2
- data/app/assets/javascripts/sufia/relationships/control.es6 +83 -0
- data/app/assets/javascripts/sufia/relationships/registry.es6 +60 -0
- data/app/assets/javascripts/sufia/relationships/registry_entry.es6 +38 -0
- data/app/assets/javascripts/sufia/relationships/work.es6 +7 -0
- data/app/assets/javascripts/sufia/save_work/required_fields.es6 +1 -1
- data/app/assets/javascripts/sufia/save_work/save_work_control.es6 +19 -11
- data/app/assets/javascripts/sufia/save_work/visibility_component.es6 +19 -10
- data/app/assets/javascripts/sufia/select_work_type.es6 +8 -6
- data/app/controllers/concerns/sufia/batch_uploads_controller_behavior.rb +1 -1
- data/app/controllers/concerns/sufia/works_controller_behavior.rb +7 -0
- data/app/controllers/sufia/admin/admin_sets_controller.rb +5 -2
- data/app/forms/sufia/forms/batch_edit_form.rb +2 -1
- data/app/forms/sufia/forms/work_form.rb +19 -17
- data/app/models/concerns/sufia/admin_set_behavior.rb +38 -0
- data/app/presenters/sufia/admin_set_options_presenter.rb +51 -0
- data/app/presenters/sufia/admin_set_presenter.rb +11 -0
- data/app/search_builders/sufia/find_works_search_builder.rb +1 -0
- data/app/services/sufia/actor_factory.rb +1 -0
- data/app/services/sufia/admin_set_create_service.rb +9 -9
- data/app/services/sufia/admin_set_service.rb +0 -28
- data/app/services/sufia/workflow/abstract_notification.rb +14 -1
- data/app/services/sufia/workflow/changes_required_notification.rb +2 -2
- data/app/services/sufia/workflow/deposited_notification.rb +1 -1
- data/app/services/sufia/workflow/pending_review_notification.rb +1 -1
- data/app/views/curation_concerns/base/_find_work_widget.html.erb +10 -16
- data/app/views/curation_concerns/base/_form.html.erb +5 -1
- data/app/views/curation_concerns/base/_form_child_work_relationships.html.erb +22 -32
- data/app/views/curation_concerns/base/_form_relationships.html.erb +4 -7
- data/app/views/curation_concerns/base/_guts4form.html.erb +7 -1
- data/app/views/sufia/admin/admin_sets/_form_participants.html.erb +3 -3
- data/app/views/sufia/admin/admin_sets/show.html.erb +10 -2
- data/config/initializers/monkey_patch_admin_set.rb +2 -0
- data/config/locales/sufia.en.yml +2 -0
- data/db/migrate/20170317141521_permission_template_change_column_workflow_name.rb +5 -0
- data/lib/generators/sufia/templates/workflow.json.erb +1 -0
- data/lib/sufia/version.rb +1 -1
- data/lib/tasks/migrate.rake +1 -1
- data/spec/actors/sufia/actors/attach_members_actor_spec.rb +68 -0
- data/spec/actors/sufia/apply_permission_template_actor_spec.rb +7 -3
- data/spec/actors/sufia/default_admin_set_actor_spec.rb +1 -1
- data/spec/controllers/sufia/admin/admin_sets_controller_spec.rb +21 -6
- data/spec/controllers/sufia/admin/permission_templates_controller_spec.rb +1 -1
- data/spec/controllers/sufia/batch_uploads_controller_spec.rb +24 -2
- data/spec/factories/permission_templates.rb +1 -0
- data/spec/factories/workflows.rb +1 -1
- data/spec/forms/curation_concerns/generic_work_form_spec.rb +5 -2
- data/spec/forms/sufia/forms/batch_edit_form_spec.rb +1 -1
- data/spec/forms/sufia/forms/work_form_spec.rb +32 -19
- data/spec/javascripts/autocomplete_spec.js.coffee +12 -33
- data/spec/javascripts/helpers/test_fixtures.js.coffee +10 -1
- data/spec/javascripts/relationships_control_spec.js.coffee +27 -0
- data/spec/javascripts/save_work_spec.js +9 -6
- data/spec/javascripts/visibility_component_spec.js +17 -8
- data/spec/models/admin_set_spec.rb +69 -0
- data/spec/presenters/sufia/admin_set_options_presenter_spec.rb +73 -0
- data/spec/presenters/sufia/admin_set_presenter_spec.rb +31 -2
- data/spec/services/sufia/actor_factory_spec.rb +2 -0
- data/spec/services/sufia/admin_set_create_service_spec.rb +4 -2
- data/spec/services/sufia/admin_set_service_spec.rb +0 -72
- data/spec/services/sufia/workflow/changes_required_notification_spec.rb +1 -1
- data/spec/services/sufia/workflow/deposited_notification_spec.rb +1 -1
- data/spec/services/sufia/workflow/pending_review_notification_spec.rb +1 -1
- data/spec/views/curation_concerns/base/_find_work_widget.html.erb_spec.rb +1 -2
- data/spec/views/curation_concerns/base/_form_child_work_relationships.html.erb_spec.rb +27 -62
- data/spec/views/curation_concerns/base/_form_relationships.html.erb_spec.rb +4 -2
- data/spec/views/sufia/admin/admin_sets/_form_participants.html.erb_spec.rb +1 -1
- data/spec/views/sufia/admin/admin_sets/_form_visibility.html.erb_spec.rb +3 -1
- data/spec/views/sufia/admin/admin_sets/show.html.erb_spec.rb +59 -0
- data/sufia.gemspec +3 -2
- data/template.rb +1 -1
- metadata +34 -19
- data/app/assets/javascripts/sufia/relationships/table.es6 +0 -206
- data/app/assets/javascripts/sufia/relationships/table_row.es6 +0 -79
- data/app/views/curation_concerns/base/_form_parent_work_relationships.html.erb +0 -43
- data/app/views/records/edit_fields/_in_works_ids.html.erb +0 -59
- data/spec/javascripts/helpers/test_responses.js +0 -13
- data/spec/javascripts/relationships_table_spec.js.coffee +0 -83
- data/spec/views/curation_concerns/base/_form_parent_work_relationships.html.erb_spec.rb +0 -114
- data/spec/views/records/edit_fields/_in_works_ids.html.erb_spec.rb +0 -113
@@ -26,7 +26,7 @@ RSpec.describe Sufia::Admin::PermissionTemplatesController do
|
|
26
26
|
context "when signed in as an admin" do
|
27
27
|
describe "update participants" do
|
28
28
|
let(:admin_set) { create(:admin_set) }
|
29
|
-
let!(:permission_template) {
|
29
|
+
let!(:permission_template) { create(:permission_template, admin_set_id: admin_set.id) }
|
30
30
|
let(:grant_attributes) { [{ "agent_type" => "user", "agent_id" => "bob", "access" => "view" }] }
|
31
31
|
let(:input_params) do
|
32
32
|
{ admin_set_id: admin_set.id,
|
@@ -38,7 +38,7 @@ describe Sufia::BatchUploadsController do
|
|
38
38
|
end
|
39
39
|
|
40
40
|
describe "#create" do
|
41
|
-
context "
|
41
|
+
context "with expected params" do
|
42
42
|
it "is successful" do
|
43
43
|
expect(BatchCreateJob).to receive(:perform_later)
|
44
44
|
.with(user,
|
@@ -53,7 +53,29 @@ describe Sufia::BatchUploadsController do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
|
56
|
-
|
56
|
+
context 'with missing resource_type' do
|
57
|
+
let(:post_params) do
|
58
|
+
{
|
59
|
+
title: expected_individual_params,
|
60
|
+
uploaded_files: ['1', '2'],
|
61
|
+
batch_upload_item: batch_upload_item
|
62
|
+
}
|
63
|
+
end
|
64
|
+
it 'is successful' do
|
65
|
+
expect(BatchCreateJob).to receive(:perform_later)
|
66
|
+
.with(user,
|
67
|
+
expected_individual_params,
|
68
|
+
{},
|
69
|
+
['1', '2'],
|
70
|
+
expected_shared_params,
|
71
|
+
a_kind_of(Sufia::BatchCreateOperation))
|
72
|
+
post :create, params: post_params
|
73
|
+
expect(response).to redirect_to Sufia::Engine.routes.url_helpers.dashboard_works_path
|
74
|
+
expect(flash[:notice]).to include("Your files are being processed")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context "when submiting works on behalf of another user" do
|
57
79
|
let(:batch_upload_item) do
|
58
80
|
{
|
59
81
|
payload_concern: Atlas,
|
data/spec/factories/workflows.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
describe CurationConcerns::GenericWorkForm do
|
1
|
+
RSpec.describe CurationConcerns::GenericWorkForm do
|
2
2
|
let(:work) { GenericWork.new }
|
3
3
|
let(:form) { described_class.new(work, nil) }
|
4
4
|
|
@@ -39,12 +39,15 @@ describe CurationConcerns::GenericWorkForm do
|
|
39
39
|
end
|
40
40
|
|
41
41
|
describe '.model_attributes' do
|
42
|
+
before { create(:permission_template, admin_set_id: admin_set_id, workflow_name: workflow.name) }
|
43
|
+
let(:workflow) { create(:workflow) }
|
44
|
+
let(:admin_set_id) { '123' }
|
42
45
|
let(:params) do
|
43
46
|
ActionController::Parameters.new(
|
44
47
|
title: ['foo'],
|
45
48
|
description: [''],
|
46
49
|
visibility: 'open',
|
47
|
-
admin_set_id:
|
50
|
+
admin_set_id: admin_set_id,
|
48
51
|
representative_id: '456',
|
49
52
|
thumbnail_id: '789',
|
50
53
|
keyword: ['derp'],
|
@@ -1,4 +1,4 @@
|
|
1
|
-
describe Sufia::Forms::BatchEditForm do
|
1
|
+
RSpec.describe Sufia::Forms::BatchEditForm do
|
2
2
|
let(:model) { GenericWork.new }
|
3
3
|
let(:work1) { create :generic_work, title: ["title 1"], keyword: ["abc"], creator: ["Wilma"], language: ['en'], contributor: ['contributor1'], description: ['description1'], rights: ['rights1'], subject: ['subject1'], identifier: ['id1'], based_near: ['based_near1'], related_url: ['related_url1'] }
|
4
4
|
let(:work2) { create :generic_work, title: ["title 2"], keyword: ["123"], creator: ["Fred"], publisher: ['Rand McNally'], language: ['en'], resource_type: ['bar'], contributor: ['contributor2'], description: ['description2'], rights: ['rights2'], subject: ['subject2'], identifier: ['id2'], based_near: ['based_near2'], related_url: ['related_url2'] }
|
@@ -4,24 +4,13 @@ describe Sufia::Forms::WorkForm, :no_clean do
|
|
4
4
|
let(:works) { [GenericWork.new, FileSet.new, GenericWork.new] }
|
5
5
|
let(:files) { [FileSet.new, GenericWork.new, FileSet.new] }
|
6
6
|
|
7
|
-
describe "#
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe "#ordered_work_members" do
|
15
|
-
it "expects ordered work members" do
|
16
|
-
allow(work).to receive(:ordered_members).and_return(works)
|
17
|
-
expect(form.ordered_work_members.size).to eq(2)
|
7
|
+
describe "#work_members" do
|
8
|
+
subject { form.work_members }
|
9
|
+
before do
|
10
|
+
allow(work).to receive(:members).and_return(works)
|
18
11
|
end
|
19
|
-
|
20
|
-
|
21
|
-
describe "#in_work_members" do
|
22
|
-
it "expects parent work members" do
|
23
|
-
allow(work).to receive(:in_works).and_return(works)
|
24
|
-
expect(form.in_work_members.size).to eq(3)
|
12
|
+
it "expects members that are works" do
|
13
|
+
expect(form.work_members.size).to eq(2)
|
25
14
|
end
|
26
15
|
end
|
27
16
|
|
@@ -30,6 +19,7 @@ describe Sufia::Forms::WorkForm, :no_clean do
|
|
30
19
|
allow(described_class).to receive(:model_class).and_return(GenericWork)
|
31
20
|
end
|
32
21
|
subject { described_class.build_permitted_params }
|
22
|
+
|
33
23
|
context "without mediated deposit" do
|
34
24
|
it { is_expected.to include(permissions_attributes: [:type, :name, :access, :id, :_destroy]) }
|
35
25
|
end
|
@@ -42,8 +32,31 @@ describe Sufia::Forms::WorkForm, :no_clean do
|
|
42
32
|
subject { described_class.model_attributes(ActionController::Parameters.new(attributes)) }
|
43
33
|
|
44
34
|
context "when a user is granted edit access" do
|
45
|
-
let(:
|
46
|
-
|
35
|
+
let(:admin_set) { create(:admin_set) }
|
36
|
+
|
37
|
+
context "and a admin_set that allows grants has been selected" do
|
38
|
+
let(:attributes) { { admin_set_id: admin_set.id, permissions_attributes: [{ type: 'person', name: 'justin', access: 'edit' }] } }
|
39
|
+
before { create(:permission_template, admin_set_id: admin_set.id, workflow_name: workflow.name) }
|
40
|
+
let(:workflow) { create(:workflow, allows_access_grant: true) }
|
41
|
+
|
42
|
+
it do
|
43
|
+
is_expected.to eq ActionController::Parameters.new(admin_set_id: admin_set.id,
|
44
|
+
permissions_attributes: [ActionController::Parameters.new(type: 'person', name: 'justin', access: 'edit')]).permit!
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "and no admin_set has been selected" do
|
49
|
+
let(:attributes) { { permissions_attributes: [{ type: 'person', name: 'justin', access: 'edit' }] } }
|
50
|
+
it { is_expected.to eq ActionController::Parameters.new.permit! }
|
51
|
+
end
|
52
|
+
|
53
|
+
context "and an admin_set that doesn't allow grants has been selected" do
|
54
|
+
let(:attributes) { { admin_set_id: admin_set.id, permissions_attributes: [{ type: 'person', name: 'justin', access: 'edit' }] } }
|
55
|
+
before { create(:permission_template, admin_set_id: admin_set.id, workflow_name: workflow.name) }
|
56
|
+
let(:workflow) { create(:workflow, allows_access_grant: false) }
|
57
|
+
|
58
|
+
it { is_expected.to eq ActionController::Parameters.new(admin_set_id: admin_set.id).permit! }
|
59
|
+
end
|
47
60
|
end
|
48
61
|
|
49
62
|
context "without permssions being set" do
|
@@ -99,8 +99,8 @@ describe "auto complete", ->
|
|
99
99
|
describe "location", ->
|
100
100
|
beforeEach ->
|
101
101
|
# setup two inputs for us to attach auto complete to
|
102
|
-
setFixtures '<input class="generic_work_based_near"
|
103
|
-
<input class="generic_work_based_near"
|
102
|
+
setFixtures '<input class="generic_work_based_near" value="" id="generic_work_based_near" type="text" data-autocomplete="based_near" data-autocomplete-url="foo">
|
103
|
+
<input class="generic_work_based_near" value="" type="text" data-autocomplete="based_near" data-autocomplete-url="foo">'
|
104
104
|
|
105
105
|
# run all Blacklight.onload functions
|
106
106
|
Blacklight.activate()
|
@@ -136,42 +136,21 @@ describe "auto complete", ->
|
|
136
136
|
# verify that the ajax call was made
|
137
137
|
expect(@spy_on_json).toHaveBeenCalled()
|
138
138
|
|
139
|
-
describe "works", ->
|
139
|
+
describe "for works", ->
|
140
140
|
beforeEach ->
|
141
|
-
# setup two inputs for us to attach
|
142
|
-
setFixtures '<input class="generic_work_work"
|
143
|
-
<input class="generic_work_work"
|
141
|
+
# setup two inputs for us to attach auto complete to
|
142
|
+
setFixtures '<input class="generic_work_work" value="" id="generic_work_based_near" type="text" data-autocomplete="work" data-autocomplete-url="foo">
|
143
|
+
<input class="generic_work_work" value="" type="text" data-autocomplete="work" data-autocomplete-url="foo">'
|
144
144
|
|
145
145
|
# run all Blacklight.onload functions
|
146
146
|
Blacklight.activate()
|
147
147
|
|
148
|
-
describe "first input", ->
|
149
|
-
|
150
|
-
# field triggers auto complete
|
151
|
-
it "auto completes on typing", ->
|
152
|
-
# send a key stroke to the target input to activate the auto complete
|
148
|
+
describe "the first input", ->
|
149
|
+
it "initializes using select2", ->
|
153
150
|
target = $($("input.generic_work_work")[0])
|
154
|
-
target.
|
155
|
-
target.trigger(@typeEvent)
|
156
|
-
|
157
|
-
# move time along so that events have a chance to happen
|
158
|
-
jasmine.clock().tick(800)
|
159
|
-
|
160
|
-
# verify that the ajax call was made
|
161
|
-
expect(@spy_on_json).toHaveBeenCalled()
|
151
|
+
expect(target.select2('open')).toBe(true)
|
162
152
|
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
# field triggers auto complete
|
167
|
-
it "auto completes on typing", ->
|
168
|
-
# send a key stroke to the target input to activate the auto complete
|
153
|
+
describe "the second input", ->
|
154
|
+
it "initializes using select2", ->
|
169
155
|
target = $($("input.generic_work_work")[1])
|
170
|
-
target.
|
171
|
-
target.trigger(@typeEvent)
|
172
|
-
|
173
|
-
# move time along so that events have a chance to happen
|
174
|
-
jasmine.clock().tick(800)
|
175
|
-
|
176
|
-
# verify that the ajax call was made
|
177
|
-
expect(@spy_on_json).toHaveBeenCalled()
|
156
|
+
expect(target.select2('open')).toBe(true)
|
@@ -5,5 +5,14 @@ window.TestFixtures = {
|
|
5
5
|
}
|
6
6
|
}
|
7
7
|
|
8
|
-
window.TestFixtures.relationships_table["html"] =
|
8
|
+
window.TestFixtures.relationships_table["html"] =
|
9
|
+
"<form action='/concern/generic_works/#{TestFixtures.relationships_table.child_id}'><table class='table table-striped related-files relationships-ajax-enabled'> <thead> <tr> <th>Parent Work</th> <th>Actions</th> </tr> </thead> <tbody> <tr class='new-row'> <td> <a href='' class='title hidden'></a>
|
10
|
+
<input id=\"find_child_work\" name='find_child_work' value='' data-autocomplete=\"work\"> <div class='message has-warning hidden'></div> </td> <td> <div class='child-actions'> <a href='' class='edit hidden btn btn-default' target='_blank'>Edit</a> <a class='btn btn-danger btn-remove-row hidden'>Remove</a> <a class='btn btn-primary btn-add-row'>Add</a></div></td></tr></tbody></table></form>
|
9
11
|
|
12
|
+
<script type=\"text/x-tmpl\" id=\"tmpl-child-work\">
|
13
|
+
<tr>
|
14
|
+
<td>{%= o.title %}</td>
|
15
|
+
<td><button class=\"btn btn-danger\" data-behavior=\"remove-relationship\">Remove</button></td>
|
16
|
+
</tr>
|
17
|
+
</script>
|
18
|
+
"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
describe 'RelationshipsControl', ->
|
2
|
+
RelationshipsControl = require('sufia/relationships/control')
|
3
|
+
element = null
|
4
|
+
target = null
|
5
|
+
test_fixtures = TestFixtures
|
6
|
+
|
7
|
+
beforeEach ->
|
8
|
+
fixture = setFixtures(test_fixtures.relationships_table.html)
|
9
|
+
element = $("table")
|
10
|
+
target = new RelationshipsControl(element, 'work_members_attributes', 'tmpl-child-work')
|
11
|
+
jasmine.Ajax.install()
|
12
|
+
|
13
|
+
afterEach ->
|
14
|
+
jasmine.Ajax.uninstall()
|
15
|
+
|
16
|
+
describe 'attemptToAddRow', ->
|
17
|
+
it 'has errors when nothing is selected', ->
|
18
|
+
target.attemptToAddRow()
|
19
|
+
expect(target.errors).toEqual([ 'ID cannot be empty.' ])
|
20
|
+
|
21
|
+
it 'creates a row when something is selected', ->
|
22
|
+
spyOn(target.input, 'val').and.returnValue('123')
|
23
|
+
spyOn(target, 'searchData').and.returnValue({ id: '123', text: 'foo bar' })
|
24
|
+
expect(target.registry.nextIndex()).toEqual(0)
|
25
|
+
target.attemptToAddRow()
|
26
|
+
expect(target.errors).toBeNull()
|
27
|
+
expect(target.registry.nextIndex()).toEqual(1)
|
@@ -1,5 +1,6 @@
|
|
1
1
|
describe("SaveWorkControl", function() {
|
2
|
-
var
|
2
|
+
var SaveWorkControl = require('sufia/save_work/save_work_control');
|
3
|
+
var AdminSetWidget = require('sufia/editor/admin_set_widget');
|
3
4
|
|
4
5
|
describe("validateMetadata", function() {
|
5
6
|
var mockCheckbox = {
|
@@ -9,10 +10,12 @@ describe("SaveWorkControl", function() {
|
|
9
10
|
|
10
11
|
beforeEach(function() {
|
11
12
|
var fixture = setFixtures('<form id="edit_generic_work">' +
|
13
|
+
'<select><option></option></select>' +
|
12
14
|
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul>' +
|
13
15
|
'<input type="checkbox" name="agreement" id="agreement" value="1" required="required" checked="checked" />' +
|
14
16
|
'<input type="submit"></aside></form>');
|
15
|
-
|
17
|
+
admin_set = new AdminSetWidget(fixture.find('select'))
|
18
|
+
target = new SaveWorkControl(fixture.find('#form-progress'), admin_set);
|
16
19
|
target.requiredMetadata = mockCheckbox;
|
17
20
|
spyOn(mockCheckbox, 'check').and.stub();
|
18
21
|
spyOn(mockCheckbox, 'uncheck').and.stub();
|
@@ -52,7 +55,7 @@ describe("SaveWorkControl", function() {
|
|
52
55
|
'<aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul>' +
|
53
56
|
'<input type="checkbox" name="agreement" id="agreement" value="1" required="required" checked="checked" />' +
|
54
57
|
'<input type="submit"></aside></form>');
|
55
|
-
target = new
|
58
|
+
target = new SaveWorkControl(fixture.find('#form-progress'));
|
56
59
|
target.activate()
|
57
60
|
});
|
58
61
|
it("forces user to agree if new files are added", function() {
|
@@ -84,7 +87,7 @@ describe("SaveWorkControl", function() {
|
|
84
87
|
'<input type="checkbox" name="agreement" id="agreement" value="1" required="required" checked="checked" />' +
|
85
88
|
'<input type="submit"></aside></form>')
|
86
89
|
}
|
87
|
-
target = new
|
90
|
+
target = new SaveWorkControl(buildFixture(form_id).find('#form-progress'));
|
88
91
|
target.requiredFiles = mockCheckbox;
|
89
92
|
return target
|
90
93
|
}
|
@@ -142,7 +145,7 @@ describe("SaveWorkControl", function() {
|
|
142
145
|
var target;
|
143
146
|
beforeEach(function() {
|
144
147
|
var fixture = setFixtures('<form id="new_generic_work"><aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul><input type="submit"></aside></form>');
|
145
|
-
target = new
|
148
|
+
target = new SaveWorkControl(fixture.find('#form-progress'));
|
146
149
|
target.activate()
|
147
150
|
});
|
148
151
|
|
@@ -161,7 +164,7 @@ describe("SaveWorkControl", function() {
|
|
161
164
|
var target;
|
162
165
|
beforeEach(function() {
|
163
166
|
var fixture = setFixtures('<form id="new_generic_work"><aside id="form-progress"><ul><li id="required-metadata"><li id="required-files"></ul><input type="submit"></aside></form>');
|
164
|
-
target = new
|
167
|
+
target = new SaveWorkControl(fixture.find('#form-progress'));
|
165
168
|
target.activate()
|
166
169
|
});
|
167
170
|
|
@@ -1,12 +1,16 @@
|
|
1
1
|
describe("VisibilityComponent", function() {
|
2
|
-
var
|
2
|
+
var VisibilityComponent = require('sufia/save_work/visibility_component');
|
3
|
+
var AdminSetWidget = require('sufia/editor/admin_set_widget');
|
4
|
+
|
3
5
|
var target = null;
|
4
6
|
var element = null;
|
7
|
+
var admin_set = null;
|
5
8
|
|
6
9
|
beforeEach(function() {
|
7
10
|
var fixture = setFixtures(visibilityForm(''));
|
8
11
|
element = fixture.find('.visibility');
|
9
|
-
|
12
|
+
admin_set = new AdminSetWidget(fixture.find('select'))
|
13
|
+
target = new VisibilityComponent(element, admin_set);
|
10
14
|
});
|
11
15
|
|
12
16
|
//limitByAdminSet() - Also tests restrictToVisibility(selected) which is where much of logic sits
|
@@ -24,7 +28,7 @@ describe("VisibilityComponent", function() {
|
|
24
28
|
beforeEach(function() {
|
25
29
|
var fixture = setFixtures(visibilityForm('<option selected="selected">No Restrictions AdminSet</option>'));
|
26
30
|
element = fixture.find('.visibility');
|
27
|
-
target = new
|
31
|
+
target = new VisibilityComponent(element, admin_set);
|
28
32
|
spyOn(target, 'enableAllOptions');
|
29
33
|
});
|
30
34
|
it("enables all visibility options", function() {
|
@@ -36,7 +40,8 @@ describe("VisibilityComponent", function() {
|
|
36
40
|
beforeEach(function() {
|
37
41
|
var fixture = setFixtures(visibilityForm('<option data-visibility="authenticated" selected="selected">Institution-Only AdminSet</option>'));
|
38
42
|
element = fixture.find('.visibility');
|
39
|
-
|
43
|
+
admin_set = new AdminSetWidget(fixture.find('select'))
|
44
|
+
target = new VisibilityComponent(element, admin_set);
|
40
45
|
spyOn(target, 'applyRestrictions');
|
41
46
|
});
|
42
47
|
it("calls applyRestrictions with specified visibility", function() {
|
@@ -48,7 +53,8 @@ describe("VisibilityComponent", function() {
|
|
48
53
|
beforeEach(function() {
|
49
54
|
var fixture = setFixtures(visibilityForm('<option data-release-date="' + target.getToday() + '" data-release-before-date="false" selected="selected">Release Immediately AdminSet</option>'));
|
50
55
|
element = fixture.find('.visibility');
|
51
|
-
|
56
|
+
admin_set = new AdminSetWidget(fixture.find('select'))
|
57
|
+
target = new VisibilityComponent(element, admin_set);
|
52
58
|
spyOn(target, 'applyRestrictions');
|
53
59
|
});
|
54
60
|
it("calls applyRestrictions with specified date requirement", function() {
|
@@ -60,7 +66,8 @@ describe("VisibilityComponent", function() {
|
|
60
66
|
beforeEach(function() {
|
61
67
|
var fixture = setFixtures(visibilityForm('<option data-visibility="open" data-release-date="' + target.getToday() + '" data-release-before-date="false" selected="selected">Release Publicly Immediately AdminSet</option>'));
|
62
68
|
element = fixture.find('.visibility');
|
63
|
-
|
69
|
+
admin_set = new AdminSetWidget(fixture.find('select'))
|
70
|
+
target = new VisibilityComponent(element, admin_set);
|
64
71
|
spyOn(target, 'applyRestrictions');
|
65
72
|
});
|
66
73
|
it("calls applyRestrictions with specified date and visibility requirement", function() {
|
@@ -72,7 +79,8 @@ describe("VisibilityComponent", function() {
|
|
72
79
|
beforeEach(function() {
|
73
80
|
var fixture = setFixtures(visibilityForm('<option data-release-date="' + getOneYearFromToday() + '" data-release-before-date="false" selected="selected">Release in One Year AdminSet</option>'));
|
74
81
|
element = fixture.find('.visibility');
|
75
|
-
|
82
|
+
admin_set = new AdminSetWidget(fixture.find('select'))
|
83
|
+
target = new VisibilityComponent(element, admin_set);
|
76
84
|
spyOn(target, 'applyRestrictions');
|
77
85
|
});
|
78
86
|
it("calls applyRestrictions with specified date requirement", function() {
|
@@ -84,7 +92,8 @@ describe("VisibilityComponent", function() {
|
|
84
92
|
beforeEach(function() {
|
85
93
|
var fixture = setFixtures(visibilityForm('<option data-visibility="authenticated" data-release-date="' + getOneYearFromToday() + '" data-release-before-date="true" selected="selected">Release in One Year to Institution AdminSet</option>'));
|
86
94
|
element = fixture.find('.visibility');
|
87
|
-
|
95
|
+
admin_set = new AdminSetWidget(fixture.find('select'))
|
96
|
+
target = new VisibilityComponent(element, admin_set);
|
88
97
|
spyOn(target, 'applyRestrictions');
|
89
98
|
});
|
90
99
|
it("calls applyRestrictions with specified date and visibility requirement", function() {
|
@@ -0,0 +1,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe AdminSet, type: :model do
|
4
|
+
let(:gf1) { create(:generic_work, user: user) }
|
5
|
+
let(:gf2) { create(:generic_work, user: user) }
|
6
|
+
|
7
|
+
let(:user) { create(:user) }
|
8
|
+
|
9
|
+
before do
|
10
|
+
subject.title = ['Some title']
|
11
|
+
end
|
12
|
+
|
13
|
+
describe "#default_set?" do
|
14
|
+
context "with default AdminSet ID" do
|
15
|
+
it "returns true" do
|
16
|
+
expect(AdminSet.default_set?(described_class::DEFAULT_ID)).to be true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "with a non-default ID" do
|
21
|
+
it "returns false" do
|
22
|
+
expect(AdminSet.default_set?('different-id')).to be false
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
describe "#destroy" do
|
28
|
+
context "with member works" do
|
29
|
+
before do
|
30
|
+
subject.members = [gf1, gf2]
|
31
|
+
subject.save!
|
32
|
+
subject.destroy
|
33
|
+
end
|
34
|
+
|
35
|
+
it "does not delete adminset or member works" do
|
36
|
+
expect(subject.errors.full_messages).to eq ["Administrative set cannot be deleted as it is not empty"]
|
37
|
+
expect(AdminSet.exists?(subject.id)).to be true
|
38
|
+
expect(GenericWork.exists?(gf1.id)).to be true
|
39
|
+
expect(GenericWork.exists?(gf2.id)).to be true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "with no member works" do
|
44
|
+
before do
|
45
|
+
subject.members = []
|
46
|
+
subject.save!
|
47
|
+
subject.destroy
|
48
|
+
end
|
49
|
+
|
50
|
+
it "deletes the adminset" do
|
51
|
+
expect(AdminSet.exists?(subject.id)).to be false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "is default adminset" do
|
56
|
+
before do
|
57
|
+
subject.members = []
|
58
|
+
subject.id = described_class::DEFAULT_ID
|
59
|
+
subject.save!
|
60
|
+
subject.destroy
|
61
|
+
end
|
62
|
+
|
63
|
+
it "does not delete the adminset" do
|
64
|
+
expect(subject.errors.full_messages).to eq ["Administrative set cannot be deleted as it is the default set"]
|
65
|
+
expect(AdminSet.exists?(described_class::DEFAULT_ID)).to be true
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|