sufia 5.0.0 → 6.0.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -8
- data/Gemfile +3 -12
- data/History.md +0 -36
- data/LICENSE.md +14 -0
- data/README.md +4 -8
- data/SUFIA_VERSION +1 -1
- data/app/assets/javascripts/sufia.js +1 -17
- data/app/assets/javascripts/sufia/batch_edit.js +43 -28
- data/app/assets/javascripts/sufia/edit_metadata.js +9 -14
- data/app/assets/javascripts/sufia/multiForm.js +67 -0
- data/app/assets/javascripts/sufia/permissions.js +92 -35
- data/app/assets/stylesheets/sufia.css.scss +1 -6
- data/app/assets/stylesheets/sufia/_batch-edit.scss +0 -8
- data/app/assets/stylesheets/sufia/_dashboard.scss +1 -15
- data/app/assets/stylesheets/sufia/_file-listing.scss +1 -1
- data/app/assets/stylesheets/sufia/_settings.scss +0 -1
- data/app/controllers/concerns/sufia/batch_edits_controller_behavior.rb +3 -10
- data/app/controllers/concerns/sufia/breadcrumbs.rb +3 -8
- data/app/controllers/concerns/sufia/catalog.rb +1 -1
- data/app/controllers/concerns/sufia/controller.rb +3 -1
- data/app/controllers/concerns/sufia/downloads_controller_behavior.rb +1 -1
- data/app/controllers/concerns/sufia/files_controller/browse_everything.rb +1 -1
- data/app/controllers/concerns/sufia/files_controller_behavior.rb +16 -4
- data/app/controllers/concerns/sufia/homepage_controller.rb +1 -1
- data/app/controllers/concerns/sufia/my_controller_behavior.rb +2 -2
- data/app/controllers/concerns/sufia/transfers_controller_behavior.rb +3 -4
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +2 -7
- data/app/controllers/my/collections_controller.rb +3 -4
- data/app/controllers/my/highlights_controller.rb +2 -2
- data/app/controllers/my/shares_controller.rb +3 -3
- data/app/controllers/single_use_links_controller.rb +5 -9
- data/app/controllers/single_use_links_viewer_controller.rb +4 -4
- data/app/helpers/generic_file_helper.rb +9 -0
- data/app/helpers/sufia/records_helper_behavior.rb +16 -0
- data/app/helpers/sufia/sufia_helper_behavior.rb +0 -11
- data/app/jobs/content_depositor_change_event_job.rb +1 -1
- data/app/jobs/ingest_local_file_job.rb +2 -1
- data/app/models/concerns/sufia/solr_document_behavior.rb +10 -10
- data/app/models/featured_work_list.rb +7 -9
- data/app/presenters/sufia/version_list_presenter.rb +15 -0
- data/app/presenters/sufia/version_presenter.rb +30 -0
- data/app/views/batch/_metadata.html.erb +51 -29
- data/app/views/batch/_more_metadata.html.erb +1 -1
- data/app/views/batch/edit.html.erb +10 -8
- data/app/views/batch_edits/edit.html.erb +13 -9
- data/app/views/collections/_edit_descriptions.html.erb +1 -1
- data/app/views/collections/_form.html.erb +4 -4
- data/app/views/collections/_form_for_select_collection.html.erb +1 -1
- data/app/views/collections/_show_document_list_menu.html.erb +7 -5
- data/app/views/collections/_show_document_list_row.html.erb +2 -2
- data/app/views/collections/edit.html.erb +0 -1
- data/app/views/collections/edit_fields/_description.html.erb +4 -0
- data/app/views/collections/edit_fields/_title.html.erb +3 -0
- data/app/views/collections/show.html.erb +0 -1
- data/app/views/dashboard/_index_partials/_stats.html.erb +3 -3
- data/app/views/generic_files/_descriptions.html.erb +9 -9
- data/app/views/generic_files/_field_form.html.erb +11 -25
- data/app/views/generic_files/_permission.html.erb +6 -4
- data/app/views/generic_files/_permission_form.html.erb +15 -17
- data/app/views/generic_files/_show_details.html.erb +1 -11
- data/app/views/generic_files/_versioning.html.erb +5 -5
- data/app/views/generic_files/edit.html.erb +5 -4
- data/app/views/generic_files/show.html.erb +6 -6
- data/app/views/homepage/_featured_fields.html.erb +2 -2
- data/app/views/homepage/_recent_document.html.erb +1 -1
- data/app/views/layouts/_head_tag_content.html.erb +0 -2
- data/app/views/layouts/error.html.erb +0 -1
- data/app/views/my/_index_partials/_default_group.html.erb +1 -1
- data/app/views/my/_index_partials/_list_files.html.erb +1 -1
- data/app/views/my/index.html.erb +2 -2
- data/app/views/records/_edit_field.html.erb +17 -19
- data/app/views/records/edit_fields/_default.html.erb +10 -12
- data/app/views/records/edit_fields/_description.html.erb +10 -3
- data/app/views/records/edit_fields/_resource_type.html.erb +4 -5
- data/app/views/records/edit_fields/_rights.html.erb +9 -2
- data/app/views/records/edit_fields/_suffix.html.erb +10 -0
- data/app/views/records/edit_fields/_type.html.erb +8 -2
- data/app/views/records/show_fields/_based_near.html.erb +1 -1
- data/app/views/records/show_fields/_creator.html.erb +1 -1
- data/app/views/records/show_fields/_language.html.erb +1 -1
- data/app/views/records/show_fields/_publisher.html.erb +1 -1
- data/app/views/records/show_fields/_resource_type.html.erb +1 -1
- data/app/views/records/show_fields/_subject.html.erb +1 -1
- data/app/views/records/show_fields/_tag.html.erb +1 -1
- data/app/views/single_use_links/new_download.html.erb +2 -2
- data/app/views/users/_profile.html.erb +2 -1
- data/app/views/users/_social_media_info.html.erb +20 -0
- data/app/views/users/_user_info.html.erb +3 -20
- data/app/views/users/edit.html.erb +2 -11
- data/app/views/users/show.html.erb +1 -1
- data/bin/audit_repository +1 -1
- data/config/initializers/sufia_events.rb +4 -4
- data/config/locales/sufia.en.yml +0 -5
- data/config/routes.rb +1 -1
- data/lib/generators/sufia/install_generator.rb +0 -4
- data/lib/generators/sufia/templates/catalog_controller.rb +59 -59
- data/lib/sufia.rb +1 -4
- data/lib/sufia/version.rb +1 -1
- data/spec/actors/generic_file/actor_spec.rb +67 -8
- data/spec/controllers/batch_controller_spec.rb +72 -86
- data/spec/controllers/batch_edits_controller_spec.rb +17 -19
- data/spec/controllers/catalog_controller_spec.rb +16 -24
- data/spec/controllers/collections_controller_spec.rb +47 -74
- data/spec/controllers/downloads_controller_spec.rb +40 -35
- data/spec/controllers/generic_files_controller_spec.rb +363 -428
- data/spec/controllers/homepage_controller_spec.rb +12 -9
- data/spec/controllers/mailbox_controller_spec.rb +1 -4
- data/spec/controllers/my/files_controller_spec.rb +0 -10
- data/spec/controllers/single_use_links_controller_spec.rb +28 -35
- data/spec/controllers/single_use_links_viewer_controller_spec.rb +27 -41
- data/spec/controllers/transfers_controller_spec.rb +6 -6
- data/spec/controllers/users_controller_spec.rb +121 -124
- data/spec/factories/generic_files.rb +9 -17
- data/spec/features/browse_dashboard_files_spec.rb +8 -10
- data/spec/features/browse_files_spec.rb +12 -25
- data/spec/features/catalog_search_spec.rb +49 -49
- data/spec/features/collection_spec.rb +18 -24
- data/spec/features/contact_form_spec.rb +26 -20
- data/spec/features/ingest_upload_files_spec.rb +8 -6
- data/spec/features/ownership_transfer_spec.rb +2 -6
- data/spec/features/proxy_spec.rb +1 -1
- data/spec/features/search_spec.rb +2 -3
- data/spec/features/single_use_links_spec.rb +1 -1
- data/spec/features/users_spec.rb +1 -1
- data/spec/helpers/records_helper_spec.rb +24 -10
- data/spec/jobs/active_fedora_pid_based_job_spec.rb +1 -5
- data/spec/jobs/audit_job_spec.rb +66 -21
- data/spec/jobs/batch_update_job_spec.rb +49 -36
- data/spec/jobs/content_depositor_change_event_job_spec.rb +2 -4
- data/spec/jobs/create_derivatives_job_spec.rb +18 -19
- data/spec/jobs/event_jobs_spec.rb +17 -21
- data/spec/jobs/import_url_job_spec.rb +1 -6
- data/spec/jobs/ingest_local_file_job_spec.rb +0 -4
- data/spec/lib/sufia/breadcrumbs_spec.rb +8 -46
- data/spec/lib/sufia/id_service_spec.rb +8 -3
- data/spec/lib/sufia/user_stat_importer_spec.rb +18 -25
- data/spec/lib/sufia/writable_permissions_spec.rb +0 -4
- data/spec/models/ability_spec.rb +25 -18
- data/spec/models/batch_spec.rb +16 -45
- data/spec/models/characterization_spec.rb +1 -1
- data/spec/models/checksum_audit_log_spec.rb +51 -29
- data/spec/models/collection_spec.rb +0 -5
- data/spec/models/featured_work_list_spec.rb +2 -4
- data/spec/models/file_content_datastream_spec.rb +27 -60
- data/spec/models/file_usage_spec.rb +16 -21
- data/spec/models/fits_datastream_spec.rb +47 -2
- data/spec/models/generic_file/web_form_spec.rb +1 -1
- data/spec/models/generic_file_spec.rb +238 -735
- data/spec/models/local_authority_spec.rb +8 -13
- data/spec/models/proxy_deposit_request_spec.rb +3 -7
- data/spec/models/single_use_link_spec.rb +12 -16
- data/spec/models/solr_document_spec.rb +1 -1
- data/spec/models/trophy_spec.rb +1 -3
- data/spec/models/user_spec.rb +47 -75
- data/spec/presenters/sufia/version_list_presenter_spec.rb +22 -0
- data/spec/presenters/sufia/version_presenter_spec.rb +51 -0
- data/spec/services/generic_file_audit_service_spec.rb +85 -0
- data/spec/services/repository_audit_service_spec.rb +18 -0
- data/spec/spec_helper.rb +26 -7
- data/spec/support/fixture_helpers.rb +2 -4
- data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -4
- data/spec/views/batch/edit.html.erb_spec.rb +17 -7
- data/spec/views/catalog/index.html.erb_spec.rb +8 -6
- data/spec/views/collections/_form.html.erb_spec.rb +4 -2
- data/spec/views/collections/_show_document_list.erb_spec.rb +31 -0
- data/spec/views/dashboard/index_spec.rb +2 -2
- data/spec/views/generic_file/edit.html.erb_spec.rb +20 -6
- data/spec/views/generic_file/show.html.erb_spec.rb +3 -3
- data/spec/views/users/show.html.erb_spec.rb +1 -1
- data/sufia-models/app/actors/sufia/generic_file/actor.rb +8 -10
- data/sufia-models/app/jobs/active_fedora_pid_based_job.rb +2 -3
- data/sufia-models/app/jobs/audit_job.rb +46 -32
- data/sufia-models/app/jobs/batch_update_job.rb +9 -8
- data/sufia-models/app/jobs/import_url_job.rb +2 -2
- data/sufia-models/app/models/batch.rb +11 -12
- data/sufia-models/app/models/checksum_audit_log.rb +12 -10
- data/sufia-models/app/models/concerns/sufia/ability.rb +4 -6
- data/sufia-models/app/models/concerns/sufia/collection.rb +4 -5
- data/sufia-models/app/models/concerns/sufia/generic_file.rb +3 -86
- data/sufia-models/app/models/concerns/sufia/generic_file/batches.rb +29 -0
- data/sufia-models/app/models/concerns/sufia/generic_file/characterization.rb +3 -3
- data/sufia-models/app/models/concerns/sufia/generic_file/content.rb +13 -0
- data/sufia-models/app/models/concerns/sufia/generic_file/derivatives.rb +5 -5
- data/sufia-models/app/models/concerns/sufia/generic_file/export.rb +4 -0
- data/sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb +2 -2
- data/sufia-models/app/models/concerns/sufia/generic_file/indexing.rb +23 -0
- data/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb +80 -11
- data/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb +12 -3
- data/sufia-models/app/models/concerns/sufia/generic_file/versions.rb +4 -4
- data/sufia-models/app/models/concerns/sufia/generic_file/web_form.rb +14 -6
- data/sufia-models/app/models/concerns/sufia/model_methods.rb +11 -9
- data/sufia-models/app/models/concerns/sufia/user.rb +11 -33
- data/sufia-models/app/models/datastreams/file_content_datastream.rb +1 -1
- data/sufia-models/app/models/datastreams/fits_datastream.rb +1 -1
- data/sufia-models/app/models/file_usage.rb +3 -3
- data/sufia-models/app/models/local_authority.rb +2 -2
- data/sufia-models/app/models/proxy_deposit_request.rb +1 -1
- data/sufia-models/app/services/sufia/generic_file_audit_service.rb +83 -0
- data/sufia-models/app/services/sufia/id_service.rb +5 -5
- data/sufia-models/app/services/sufia/noid.rb +10 -7
- data/sufia-models/app/services/sufia/repository_audit_service.rb +9 -0
- data/sufia-models/lib/generators/sufia/models/cached_stats_generator.rb +47 -3
- data/sufia-models/lib/generators/sufia/models/install_generator.rb +31 -11
- data/sufia-models/lib/generators/sufia/models/proxies_generator.rb +31 -2
- data/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb +10 -0
- data/sufia-models/lib/generators/sufia/models/upgrade400_generator.rb +33 -2
- data/sufia-models/lib/sufia/models/engine.rb +13 -4
- data/sufia-models/lib/sufia/models/file_content/versions.rb +9 -11
- data/sufia-models/lib/sufia/models/stats/user_stat_importer.rb +5 -9
- data/sufia-models/lib/sufia/models/version.rb +1 -1
- data/sufia-models/lib/sufia/permissions/writable.rb +34 -16
- data/sufia-models/sufia-models.gemspec +4 -2
- data/sufia.gemspec +4 -5
- data/tasks/jetty.rake +0 -26
- data/tasks/sufia-dev.rake +14 -2
- metadata +49 -64
- data/LICENSE +0 -15
- data/app/assets/images/orcid.png +0 -0
- data/app/assets/javascripts/sufia/manage_repeating_fields.js +0 -74
- data/app/assets/stylesheets/sufia/_multi_value_fields.css.scss +0 -67
- data/app/inputs/multi_value_input.rb +0 -84
- data/app/views/records/_rights_modal.html.erb +0 -1
- data/config/initializers/simple_form.rb +0 -167
- data/config/initializers/simple_form_bootstrap.rb +0 -137
- data/config/locales/simple_form.en.yml +0 -31
- data/fedora_conf/conf/development/fedora.fcfg +0 -946
- data/fedora_conf/conf/test/fedora.fcfg +0 -946
- data/spec/models/generic_file/reload_on_save_spec.rb +0 -25
- data/spec/models/generic_file_rdf_datastream_spec.rb +0 -12
- data/spec/models/properties_datastream_spec.rb +0 -41
- data/spec/views/generic_file/_permission_form.html.erb_spec.rb +0 -19
- data/sufia-models/app/models/concerns/sufia/generic_file/audit.rb +0 -116
- data/sufia-models/app/models/concerns/sufia/generic_file/reload_on_save.rb +0 -18
- data/sufia-models/app/models/concerns/sufia/properties_datastream_behavior.rb +0 -32
- data/sufia-models/app/models/datastreams/batch_rdf_datastream.rb +0 -6
- data/sufia-models/app/models/datastreams/generic_file_rdf_datastream.rb +0 -69
- data/sufia-models/app/models/datastreams/paranoid_rights_datastream.rb +0 -22
- data/sufia-models/app/models/datastreams/properties_datastream.rb +0 -4
- data/sufia-models/app/models/sufia/orcid_validator.rb +0 -8
- data/sufia-models/lib/generators/sufia/models/abstract_migration_generator.rb +0 -30
- data/sufia-models/lib/generators/sufia/models/orcid_field_generator.rb +0 -19
- data/sufia-models/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +0 -5
- data/sufia-models/lib/generators/sufia/models/user_stats_generator.rb +0 -31
@@ -1,22 +1,15 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe CollectionsController
|
4
|
-
|
3
|
+
describe CollectionsController do
|
4
|
+
routes { Hydra::Collections::Engine.routes }
|
5
5
|
before do
|
6
|
-
allow(controller).to receive(:has_access?).and_return(true)
|
7
6
|
allow_any_instance_of(User).to receive(:groups).and_return([])
|
8
7
|
end
|
9
8
|
|
10
9
|
let(:user) { FactoryGirl.create(:user) }
|
11
10
|
|
12
|
-
after (:all) do
|
13
|
-
Collection.destroy_all
|
14
|
-
GenericFile.destroy_all
|
15
|
-
User.destroy_all
|
16
|
-
end
|
17
|
-
|
18
11
|
describe '#new' do
|
19
|
-
before do
|
12
|
+
before do
|
20
13
|
sign_in user
|
21
14
|
end
|
22
15
|
|
@@ -27,16 +20,16 @@ describe CollectionsController, :type => :controller do
|
|
27
20
|
end
|
28
21
|
|
29
22
|
describe '#create' do
|
30
|
-
before do
|
23
|
+
before do
|
31
24
|
sign_in user
|
32
25
|
end
|
33
26
|
|
34
27
|
it "should create a Collection" do
|
35
|
-
expect
|
36
|
-
|
37
|
-
|
38
|
-
expect(Collection.count).to eq(old_count+1)
|
28
|
+
expect {
|
29
|
+
post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
|
30
|
+
}.to change{ Collection.count }.by(1)
|
39
31
|
end
|
32
|
+
|
40
33
|
it "should create a Collection with files I can access" do
|
41
34
|
@asset1 = GenericFile.new(title: ["First of the Assets"])
|
42
35
|
@asset1.apply_depositor_metadata(user.user_key)
|
@@ -47,18 +40,12 @@ describe CollectionsController, :type => :controller do
|
|
47
40
|
@asset3 = GenericFile.new(title: ["Third of the Assets"], depositor:'abc')
|
48
41
|
@asset3.apply_depositor_metadata('abc')
|
49
42
|
@asset3.save
|
50
|
-
expect
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
expect(Collection.count).to eq(old_count+1)
|
43
|
+
expect {
|
44
|
+
post :create, collection: { title: "My own Collection", description: "The Description\r\n\r\nand more" },
|
45
|
+
batch_document_ids: [@asset1.id, @asset2.id, @asset3.id]
|
46
|
+
}.to change{ Collection.count }.by(1)
|
55
47
|
collection = assigns(:collection)
|
56
|
-
expect(collection.members).to
|
57
|
-
expect(collection.members).to include (@asset2)
|
58
|
-
expect(collection.members.to_a).not_to include (@asset3) # .to_a to avoid a call to any? which doesn't exist in AF::HABTM
|
59
|
-
@asset1.destroy
|
60
|
-
@asset2.destroy
|
61
|
-
@asset3.destroy
|
48
|
+
expect(collection.members).to match_array [@asset1, @asset2]
|
62
49
|
end
|
63
50
|
|
64
51
|
it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
|
@@ -67,22 +54,22 @@ describe CollectionsController, :type => :controller do
|
|
67
54
|
@asset1.save
|
68
55
|
post :create, batch_document_ids: [@asset1.id],
|
69
56
|
collection: { title: "My Secong Collection ", description: "The Description\r\n\r\nand more" }
|
70
|
-
expect(assigns[:collection].members).to eq
|
57
|
+
expect(assigns[:collection].members).to eq [@asset1]
|
71
58
|
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
72
|
-
expect(asset_results["response"]["numFound"]).to eq
|
59
|
+
expect(asset_results["response"]["numFound"]).to eq 1
|
73
60
|
doc = asset_results["response"]["docs"].first
|
74
|
-
expect(doc["id"]).to eq
|
75
|
-
afterupdate = GenericFile.find(@asset1.
|
76
|
-
expect(doc[Solrizer.solr_name(:collection)]).to eq
|
61
|
+
expect(doc["id"]).to eq @asset1.id
|
62
|
+
afterupdate = GenericFile.find(@asset1.id)
|
63
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq afterupdate.to_solr[Solrizer.solr_name(:collection)]
|
77
64
|
end
|
78
65
|
|
79
66
|
end
|
80
67
|
|
81
68
|
describe "#update" do
|
82
69
|
before do
|
83
|
-
@collection = Collection.
|
84
|
-
|
85
|
-
|
70
|
+
@collection = Collection.create(title: "Collection Title") do |collection|
|
71
|
+
collection.apply_depositor_metadata(user.user_key)
|
72
|
+
end
|
86
73
|
@asset1 = GenericFile.new(title: ["First of the Assets"])
|
87
74
|
@asset1.apply_depositor_metadata(user.user_key)
|
88
75
|
@asset1.save
|
@@ -94,29 +81,23 @@ describe CollectionsController, :type => :controller do
|
|
94
81
|
@asset3.save
|
95
82
|
sign_in user
|
96
83
|
end
|
97
|
-
after do
|
98
|
-
@collection.destroy
|
99
|
-
@asset1.destroy
|
100
|
-
@asset2.destroy
|
101
|
-
@asset3.destroy
|
102
|
-
end
|
103
84
|
|
104
85
|
it "should set collection on members" do
|
105
|
-
put :update, id: @collection
|
106
|
-
expect(response).to redirect_to
|
107
|
-
expect(assigns[:collection].members
|
108
|
-
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.
|
109
|
-
expect(asset_results["response"]["numFound"]).to eq
|
86
|
+
put :update, id: @collection, collection: {members:"add"}, batch_document_ids: [@asset3.id, @asset1.id, @asset2.id]
|
87
|
+
expect(response).to redirect_to routes.url_helpers.collection_path(@collection.noid)
|
88
|
+
expect(assigns[:collection].members).to match_array [@asset2, @asset3, @asset1]
|
89
|
+
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
90
|
+
expect(asset_results["response"]["numFound"]).to eq 1
|
110
91
|
doc = asset_results["response"]["docs"].first
|
111
|
-
expect(doc["id"]).to eq
|
112
|
-
afterupdate = GenericFile.find(@asset2.
|
113
|
-
expect(doc[Solrizer.solr_name(:collection)]).to eq
|
114
|
-
put :update, id: @collection
|
115
|
-
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.
|
116
|
-
expect(asset_results["response"]["numFound"]).to eq
|
92
|
+
expect(doc["id"]).to eq @asset2.id
|
93
|
+
afterupdate = GenericFile.find(@asset2.id)
|
94
|
+
expect(doc[Solrizer.solr_name(:collection)]).to eq afterupdate.to_solr[Solrizer.solr_name(:collection)]
|
95
|
+
put :update, id: @collection, collection: {members:"remove"}, batch_document_ids: [@asset2]
|
96
|
+
asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
|
97
|
+
expect(asset_results["response"]["numFound"]).to eq 1
|
117
98
|
doc = asset_results["response"]["docs"].first
|
118
|
-
expect(doc["id"]).to eq
|
119
|
-
afterupdate = GenericFile.find(@asset2.
|
99
|
+
expect(doc["id"]).to eq @asset2.id
|
100
|
+
afterupdate = GenericFile.find(@asset2.id)
|
120
101
|
expect(doc[Solrizer.solr_name(:collection)]).to be_nil
|
121
102
|
end
|
122
103
|
end
|
@@ -125,47 +106,39 @@ describe CollectionsController, :type => :controller do
|
|
125
106
|
before do
|
126
107
|
@asset1 = GenericFile.new(title: ["First of the Assets"])
|
127
108
|
@asset1.apply_depositor_metadata(user.user_key)
|
128
|
-
@asset1.save!
|
129
109
|
@asset2 = GenericFile.new(title: ["Second of the Assets"], depositor:user.user_key)
|
130
110
|
@asset2.apply_depositor_metadata(user.user_key)
|
131
|
-
@asset2.save!
|
132
111
|
@asset3 = GenericFile.new(title: ["Third of the Assets"], depositor:user.user_key)
|
133
112
|
@asset3.apply_depositor_metadata(user.user_key)
|
134
|
-
@asset3.save!
|
135
113
|
@asset4 = GenericFile.new(title: ["Third of the Assets"], depositor:user.user_key)
|
136
114
|
@asset4.apply_depositor_metadata(user.user_key)
|
137
|
-
@
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
@collection.members = [@asset1,@asset2,@asset3]
|
143
|
-
@collection.save!
|
115
|
+
@collection = Collection.create(title: "My collection",
|
116
|
+
description: "My incredibly detailed description of the collection",
|
117
|
+
members: [@asset1,@asset2,@asset3]) do |collection|
|
118
|
+
collection.apply_depositor_metadata(user)
|
119
|
+
end
|
144
120
|
allow(controller).to receive(:authorize!).and_return(true)
|
145
|
-
allow(controller).to receive(:apply_gated_search)
|
146
121
|
end
|
147
122
|
context "when signed in" do
|
148
|
-
before do
|
123
|
+
before do
|
149
124
|
sign_in user
|
150
125
|
end
|
151
126
|
|
152
127
|
it "should return the collection and its members" do
|
153
|
-
get :show, id: @collection
|
128
|
+
get :show, id: @collection
|
154
129
|
expect(response).to be_successful
|
155
|
-
expect(assigns[:collection].title).to eq
|
156
|
-
|
157
|
-
expect(ids).to include @asset1.pid, @asset2.pid, @asset3.pid
|
158
|
-
expect(ids).to_not include @asset4.pid
|
130
|
+
expect(assigns[:collection].title).to eq @collection.title
|
131
|
+
expect(assigns[:member_docs].map(&:id)).to match_array [@asset1, @asset2, @asset3].map(&:id)
|
159
132
|
end
|
160
133
|
it "should set the breadcrumb trail" do
|
161
134
|
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
|
162
|
-
get :show, id: @collection
|
135
|
+
get :show, id: @collection
|
163
136
|
end
|
164
137
|
end
|
165
138
|
context "not signed in" do
|
166
139
|
it "should not show me files in the collection" do
|
167
|
-
get :show, id: @collection
|
168
|
-
expect(assigns[:member_docs].count).to eq
|
140
|
+
get :show, id: @collection
|
141
|
+
expect(assigns[:member_docs].count).to eq 0
|
169
142
|
end
|
170
143
|
end
|
171
144
|
end
|
@@ -178,7 +151,7 @@ describe CollectionsController, :type => :controller do
|
|
178
151
|
sign_in user
|
179
152
|
end
|
180
153
|
it "should not show flash" do
|
181
|
-
get :edit, id: @collection
|
154
|
+
get :edit, id: @collection
|
182
155
|
expect(flash[:notice]).to be_nil
|
183
156
|
end
|
184
157
|
end
|
@@ -3,56 +3,63 @@ require 'spec_helper'
|
|
3
3
|
describe DownloadsController, :type => :controller do
|
4
4
|
|
5
5
|
describe "with a file" do
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
let(:depositor) { FactoryGirl.find_or_create(:archivist) }
|
7
|
+
let(:file) do
|
8
|
+
GenericFile.new.tap do |f|
|
9
|
+
f.apply_depositor_metadata(depositor.user_key)
|
10
|
+
f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
11
|
+
f.save!
|
12
|
+
end
|
11
13
|
end
|
12
14
|
|
13
|
-
|
14
|
-
@f.delete
|
15
|
-
end
|
15
|
+
before { allow_any_instance_of(User).to receive(:groups).and_return([]) }
|
16
16
|
|
17
17
|
describe "when logged in as reader" do
|
18
18
|
before do
|
19
|
-
sign_in
|
20
|
-
allow_any_instance_of(User).to receive(:groups).and_return([])
|
21
|
-
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
19
|
+
sign_in depositor
|
22
20
|
end
|
23
21
|
describe "show" do
|
24
|
-
|
25
|
-
expect(DownloadsController.default_content_dsid).to eq("content")
|
22
|
+
before do
|
26
23
|
allow(controller).to receive(:render) # send_data calls render internally
|
27
|
-
|
24
|
+
end
|
25
|
+
let(:object) { ActiveFedora::Base.find(file.id) }
|
26
|
+
let(:expected_datastream) { object.content }
|
27
|
+
let(:expected_content) { expected_datastream.content }
|
28
|
+
|
29
|
+
it "should default to returning configured default download" do
|
30
|
+
expect(DownloadsController.default_content_dsid).to eq "content"
|
28
31
|
expect(controller).to receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
|
29
|
-
get "show", id:
|
30
|
-
expect(response.body).to eq(expected_content)
|
32
|
+
get "show", id: file
|
31
33
|
expect(response).to be_success
|
34
|
+
expect(response.body).to eq expected_content
|
32
35
|
end
|
33
|
-
|
34
|
-
|
35
|
-
expected_content
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
|
37
|
+
context "when grabbing the characterization datastream" do
|
38
|
+
let(:expected_content) { "<?xml version=\"1.0\"?>\n<fits stuff=\"yep\"/>" }
|
39
|
+
before do
|
40
|
+
file.characterization.content = expected_content
|
41
|
+
file.save!
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should return requested datastreams" do
|
45
|
+
get "show", id: file, datastream_id: "characterization"
|
46
|
+
expect(response).to be_success
|
47
|
+
expect(response.body).to eq expected_content
|
48
|
+
end
|
40
49
|
end
|
50
|
+
|
41
51
|
it "should support setting disposition to inline" do
|
42
|
-
allow(controller).to receive(:render) # send_data calls render internally
|
43
|
-
expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
|
44
52
|
expect(controller).to receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
|
45
|
-
get "show", id:
|
46
|
-
expect(response.body).to eq
|
53
|
+
get "show", id: file, disposition: "inline"
|
54
|
+
expect(response.body).to eq expected_content
|
47
55
|
expect(response).to be_success
|
48
56
|
end
|
49
57
|
|
50
58
|
it "should allow you to specify filename for download" do
|
51
|
-
allow(controller).to receive(:render) # send_data calls render internally
|
52
|
-
expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
|
53
59
|
expect(controller).to receive(:send_file_headers!).with({filename: 'my%20dog.png', disposition: 'inline', type: 'image/png' })
|
54
|
-
get "show", id:
|
55
|
-
expect(response.body).to eq
|
60
|
+
get "show", id: file, "filename" => "my%20dog.png"
|
61
|
+
expect(response.body).to eq expected_content
|
62
|
+
expect(response).to be_success
|
56
63
|
end
|
57
64
|
end
|
58
65
|
end
|
@@ -60,15 +67,13 @@ describe DownloadsController, :type => :controller do
|
|
60
67
|
describe "when not logged in as reader" do
|
61
68
|
before do
|
62
69
|
sign_in FactoryGirl.find_or_create(:jill)
|
63
|
-
allow_any_instance_of(User).to receive(:groups).and_return([])
|
64
|
-
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
65
70
|
end
|
66
71
|
|
67
72
|
describe "show" do
|
68
73
|
it "should deny access" do
|
69
|
-
get "show", id:
|
74
|
+
get "show", id: file
|
70
75
|
expect(response).to redirect_to root_path
|
71
|
-
expect(flash[:alert]).to eq
|
76
|
+
expect(flash[:alert]).to eq 'You are not authorized to access this page.'
|
72
77
|
end
|
73
78
|
end
|
74
79
|
end
|
@@ -1,295 +1,272 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe GenericFilesController
|
3
|
+
describe GenericFilesController do
|
4
|
+
let(:user) { FactoryGirl.find_or_create(:jill) }
|
4
5
|
before do
|
5
6
|
allow(controller).to receive(:has_access?).and_return(true)
|
6
|
-
|
7
|
-
sign_in @user
|
7
|
+
sign_in user
|
8
8
|
allow_any_instance_of(User).to receive(:groups).and_return([])
|
9
9
|
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
10
|
+
allow_any_instance_of(GenericFile).to receive(:characterize)
|
10
11
|
end
|
11
12
|
|
12
13
|
describe "#create" do
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
context "when uploading a file" do
|
15
|
+
let(:mock) { GenericFile.new(id: 'test123') }
|
16
|
+
let(:batch) { Batch.create }
|
17
|
+
let(:batch_id) { batch.id }
|
18
|
+
let(:file) { fixture_file_upload('/world.png','image/png') }
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
allow(GenericFile).to receive(:new).and_call_original
|
22
|
-
rescue RSpec::Mocks::MockExpectationError => e
|
20
|
+
before do
|
21
|
+
allow(GenericFile).to receive(:new).and_return(mock)
|
23
22
|
end
|
24
|
-
Batch.find("sample:batch_id").delete rescue
|
25
|
-
@mock.delete unless @mock.inner_object.class == ActiveFedora::UnsavedDigitalObject
|
26
|
-
end
|
27
|
-
|
28
|
-
it "should record on_behalf_of" do
|
29
|
-
file = fixture_file_upload('/world.png','image/png')
|
30
|
-
xhr :post, :create, files: [file], Filename: 'The world', batch_id: 'sample:batch_id', on_behalf_of: 'carolyn', terms_of_service: '1'
|
31
|
-
expect(response).to be_success
|
32
|
-
saved_file = GenericFile.find('test:123')
|
33
|
-
expect(saved_file.on_behalf_of).to eq('carolyn')
|
34
|
-
end
|
35
23
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
24
|
+
it "should record on_behalf_of" do
|
25
|
+
file = fixture_file_upload('/world.png','image/png')
|
26
|
+
xhr :post, :create, files: [file], Filename: 'The world', batch_id: batch_id, on_behalf_of: 'carolyn', terms_of_service: '1'
|
27
|
+
expect(response).to be_success
|
28
|
+
saved_file = GenericFile.find('test123')
|
29
|
+
expect(saved_file.on_behalf_of).to eq 'carolyn'
|
30
|
+
end
|
42
31
|
|
43
|
-
|
44
|
-
|
45
|
-
s1 = double('one')
|
46
|
-
allow(ContentDepositEventJob).to receive(:new).with('test:123', 'jilluser@example.com').and_return(s1)
|
47
|
-
expect(Sufia.queue).to receive(:push).with(s1).once
|
32
|
+
context "when the file submitted isn't a file" do
|
33
|
+
let(:file) { 'hello' }
|
48
34
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
35
|
+
it "should render 422 error" do
|
36
|
+
xhr :post, :create, files: [file], Filename: "The World", batch_id: 'sample_batch_id', permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
|
37
|
+
expect(response.status).to eq 422
|
38
|
+
expect(JSON.parse(response.body).first['error']).to match(/no file for upload/i)
|
39
|
+
end
|
40
|
+
end
|
55
41
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
end
|
42
|
+
context "when everything is perfect" do
|
43
|
+
it "spawns a content deposit event job" do
|
44
|
+
expect_any_instance_of(Sufia::GenericFile::Actor).to receive(:create_content).with(file, 'world.png', 'content').and_return(true)
|
45
|
+
xhr :post, :create, files: [file], 'Filename' => 'The world', batch_id: batch_id, permission: {group: { public: 'read' } }, terms_of_service: '1'
|
46
|
+
expect(flash[:error]).to be_nil
|
47
|
+
end
|
63
48
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
49
|
+
it "should create and save a file asset from the given params" do
|
50
|
+
# Now expecting iso8601 dates?
|
51
|
+
date_today = Time.now.utc.iso8601
|
52
|
+
allow(Date).to receive(:today).and_return(date_today)
|
53
|
+
expect {
|
54
|
+
xhr :post, :create, files: [file], Filename: "The world", batch_id: batch_id,
|
55
|
+
permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
|
56
|
+
}.to change { GenericFile.count }.by(1)
|
57
|
+
expect(response).to be_success
|
71
58
|
|
72
|
-
|
59
|
+
saved_file = GenericFile.find('test123')
|
73
60
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
61
|
+
# This is confirming that the correct file was attached
|
62
|
+
expect(saved_file.label).to eq 'world.png'
|
63
|
+
file.rewind
|
64
|
+
expect(saved_file.content.content).to eq (file.read)
|
65
|
+
# Confirming that date_uploaded and date_modified were set
|
66
|
+
expect(saved_file.date_uploaded).to eq date_today
|
67
|
+
expect(saved_file.date_modified).to eq date_today
|
68
|
+
end
|
78
69
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
70
|
+
it "should record what user created the first version of content" do
|
71
|
+
xhr :post, :create, files: [file], Filename: "The world", batch_id: batch_id, permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
|
72
|
+
expect(VersionCommitter.pluck(:committer_login).last).to eq user.user_key
|
73
|
+
end
|
83
74
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
saved_file = GenericFile.find('test:123')
|
88
|
-
version = saved_file.content.latest_version
|
89
|
-
expect(version.versionID).to eq("content.0")
|
90
|
-
expect(saved_file.content.version_committer(version)).to eq(@user.user_key)
|
91
|
-
end
|
75
|
+
it "should set the depositor id" do
|
76
|
+
xhr :post, :create, files: [file], Filename: "The world", batch_id: batch_id, permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
|
77
|
+
expect(response).to be_success
|
92
78
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
expect {Batch.find("sample:batch_id")}.to raise_error(ActiveFedora::ObjectNotFoundError) # The controller shouldn't actually save the Batch, but it should write the batch id to the files.
|
100
|
-
batch = Batch.create(pid: "sample:batch_id")
|
101
|
-
expect(batch.generic_files.first.pid).to eq("test:123")
|
102
|
-
end
|
103
|
-
it "should set the depositor id" do
|
104
|
-
file = fixture_file_upload('/world.png','image/png')
|
105
|
-
xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
|
106
|
-
expect(response).to be_success
|
79
|
+
saved_file = GenericFile.find('test123')
|
80
|
+
# This is confirming that apply_depositor_metadata recorded the depositor
|
81
|
+
expect(saved_file.depositor).to eq 'jilluser@example.com'
|
82
|
+
expect(saved_file.to_solr['depositor_tesim']).to eq ['jilluser@example.com']
|
83
|
+
end
|
84
|
+
end
|
107
85
|
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
expect(saved_file.properties.to_solr.keys).to include('depositor_tesim')
|
117
|
-
#TODO make sure this is moved to scholarsphere:
|
118
|
-
#saved_file.properties.to_solr['depositor_t'].should == ['jilluser']
|
119
|
-
expect(saved_file.properties.to_solr['depositor_tesim']).to eq(['jilluser@example.com'])
|
120
|
-
expect(saved_file.to_solr.keys).to include('depositor_tesim')
|
121
|
-
expect(saved_file.to_solr['depositor_tesim']).to eq(['jilluser@example.com'])
|
122
|
-
end
|
86
|
+
context "when the file has a virus" do
|
87
|
+
it "displays a flash error when file has a virus" do
|
88
|
+
expect(Sufia::GenericFile::Actor).to receive(:virus_check).with(file.path).and_raise(Sufia::VirusFoundError.new('A virus was found'))
|
89
|
+
xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample_batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
|
90
|
+
expect(flash[:error]).not_to be_blank
|
91
|
+
expect(flash[:error]).to include('A virus was found')
|
92
|
+
end
|
93
|
+
end
|
123
94
|
|
124
|
-
|
125
|
-
|
95
|
+
context "when solr continuously has errors" do
|
96
|
+
it "should error out of create and save after on continuos rsolr error" do
|
97
|
+
allow_any_instance_of(GenericFile).to receive(:save).and_raise(RSolr::Error::Http.new({},{}))
|
126
98
|
|
127
|
-
|
128
|
-
|
129
|
-
|
99
|
+
file = fixture_file_upload('/world.png','image/png')
|
100
|
+
xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample_batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
|
101
|
+
expect(response.body).to include("Error occurred while creating generic file.")
|
102
|
+
end
|
103
|
+
end
|
130
104
|
end
|
131
|
-
end
|
132
105
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
expect(ImportUrlJob).to receive(:new).twice {"ImportJob"}
|
140
|
-
expect(Sufia.queue).to receive(:push).with("ImportJob").twice
|
141
|
-
expect { post :create, selected_files: @json_from_browse_everything, batch_id: "sample:batch_id" }.to change(GenericFile, :count).by(2)
|
142
|
-
created_files = GenericFile.all
|
143
|
-
["https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf", "https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt"].each do |url|
|
144
|
-
expect(created_files.map {|f| f.import_url}).to include(url)
|
106
|
+
context "with browse-everything" do
|
107
|
+
let(:batch) { Batch.create }
|
108
|
+
let(:batch_id) { batch.id }
|
109
|
+
|
110
|
+
before do
|
111
|
+
@json_from_browse_everything = {"0"=>{"url"=>"https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt", "expires"=>"2014-03-31T20:37:36.214Z", "file_name"=>"filepicker-demo.txt.txt"}, "1"=>{"url"=>"https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf", "expires"=>"2014-03-31T20:37:36.731Z", "file_name"=>"Getting+Started.pdf"}}
|
145
112
|
end
|
146
|
-
|
147
|
-
expect(
|
113
|
+
it "should ingest files from provide URLs" do
|
114
|
+
expect(ImportUrlJob).to receive(:new).twice {"ImportJob"}
|
115
|
+
expect(Sufia.queue).to receive(:push).with("ImportJob").twice
|
116
|
+
expect { post :create, selected_files: @json_from_browse_everything, batch_id: batch_id }.to change(GenericFile, :count).by(2)
|
117
|
+
created_files = GenericFile.all
|
118
|
+
["https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf", "https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt"].each do |url|
|
119
|
+
expect(created_files.map {|f| f.import_url}).to include(url)
|
120
|
+
end
|
121
|
+
["filepicker-demo.txt.txt","Getting+Started.pdf"].each do |filename|
|
122
|
+
expect(created_files.map {|f| f.label}).to include(filename)
|
123
|
+
end
|
148
124
|
end
|
149
125
|
end
|
150
|
-
end
|
151
126
|
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
# Dir.mkdir @mock_upload_directory unless File.exists? @mock_upload_directory
|
159
|
-
FileUtils.mkdir_p([File.join(@mock_upload_directory, "import/files"),File.join(@mock_upload_directory, "import/metadata")])
|
160
|
-
FileUtils.copy(File.expand_path('../../fixtures/world.png', __FILE__), @mock_upload_directory)
|
161
|
-
FileUtils.copy(File.expand_path('../../fixtures/image.jpg', __FILE__), @mock_upload_directory)
|
162
|
-
FileUtils.copy(File.expand_path('../../fixtures/dublin_core_rdf_descMetadata.nt', __FILE__), File.join(@mock_upload_directory, "import/metadata"))
|
163
|
-
FileUtils.copy(File.expand_path('../../fixtures/icons.zip', __FILE__), File.join(@mock_upload_directory, "import/files"))
|
164
|
-
FileUtils.copy(File.expand_path('../../fixtures/Example.ogg', __FILE__), File.join(@mock_upload_directory, "import/files"))
|
165
|
-
end
|
166
|
-
after do
|
167
|
-
Sufia.config.enable_local_ingest = false
|
168
|
-
allow_any_instance_of(FileContentDatastream).to receive(:live?).and_return(true)
|
169
|
-
GenericFile.destroy_all
|
170
|
-
end
|
171
|
-
context "when User model defines a directory path" do
|
127
|
+
context "with local_file" do
|
128
|
+
let(:mock_url) {"http://example.com"}
|
129
|
+
let(:mock_upload_directory) { 'spec/mock_upload_directory' }
|
130
|
+
let(:batch) { Batch.create }
|
131
|
+
let(:batch_id) { batch.id }
|
132
|
+
|
172
133
|
before do
|
173
|
-
|
174
|
-
|
175
|
-
|
134
|
+
Sufia.config.enable_local_ingest = true
|
135
|
+
FileUtils.mkdir_p([File.join(mock_upload_directory, "import/files"), File.join(mock_upload_directory, "import/metadata")])
|
136
|
+
FileUtils.copy(File.expand_path('../../fixtures/world.png', __FILE__), mock_upload_directory)
|
137
|
+
FileUtils.copy(File.expand_path('../../fixtures/image.jpg', __FILE__), mock_upload_directory)
|
138
|
+
FileUtils.copy(File.expand_path('../../fixtures/dublin_core_rdf_descMetadata.nt', __FILE__), File.join(mock_upload_directory, "import/metadata"))
|
139
|
+
FileUtils.copy(File.expand_path('../../fixtures/icons.zip', __FILE__), File.join(mock_upload_directory, "import/files"))
|
140
|
+
FileUtils.copy(File.expand_path('../../fixtures/Example.ogg', __FILE__), File.join(mock_upload_directory, "import/files"))
|
141
|
+
end
|
142
|
+
|
143
|
+
after do
|
144
|
+
Sufia.config.enable_local_ingest = false
|
145
|
+
allow_any_instance_of(FileContentDatastream).to receive(:live?).and_return(true)
|
146
|
+
end
|
147
|
+
|
148
|
+
context "when User model defines a directory path" do
|
149
|
+
before do
|
150
|
+
allow_any_instance_of(User).to receive(:directory).and_return(mock_upload_directory)
|
176
151
|
end
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
expect(
|
152
|
+
|
153
|
+
it "should ingest files from the filesystem" do
|
154
|
+
expect {
|
155
|
+
post :create, local_file: ["world.png", "image.jpg"], batch_id: batch_id
|
156
|
+
}.to change(GenericFile, :count).by(2)
|
157
|
+
expect(response).to redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path(batch_id)
|
158
|
+
# These files should have been moved out of the upload directory
|
159
|
+
expect(File).not_to exist("#{mock_upload_directory}/image.jpg")
|
160
|
+
expect(File).not_to exist("#{mock_upload_directory}/world.png")
|
161
|
+
# And into the storage directory
|
162
|
+
files = Batch.find(batch_id).generic_files
|
163
|
+
expect(files.first.label).to eq('world.png')
|
164
|
+
expect(files.to_a.map(&:label)).to eq ['world.png', 'image.jpg']
|
165
|
+
end
|
166
|
+
|
167
|
+
it "should ingest redirect to another location" do
|
168
|
+
expect(GenericFilesController).to receive(:upload_complete_path).and_return(mock_url)
|
169
|
+
expect {
|
170
|
+
post :create, local_file: ["world.png"], batch_id: batch_id
|
171
|
+
}.to change(GenericFile, :count).by(1)
|
172
|
+
expect(response).to redirect_to mock_url
|
173
|
+
# These files should have been moved out of the upload directory
|
174
|
+
expect(File).not_to exist("#{mock_upload_directory}/world.png")
|
175
|
+
# And into the storage directory
|
176
|
+
files = Batch.find(batch_id).generic_files
|
177
|
+
expect(files.first.label).to eq 'world.png'
|
178
|
+
end
|
179
|
+
|
180
|
+
it "should ingest directories from the filesystem" do
|
181
|
+
expect {
|
182
|
+
post :create, local_file: ["world.png", "import"], batch_id: batch_id
|
183
|
+
}.to change(GenericFile, :count).by(4)
|
184
|
+
expect(response).to redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path(batch_id)
|
185
|
+
# These files should have been moved out of the upload directory
|
186
|
+
expect(File).not_to exist("#{mock_upload_directory}/import/files/icons.zip")
|
187
|
+
expect(File).not_to exist("#{mock_upload_directory}/import/metadata/dublin_core_rdf_descMetadata.nt")
|
188
|
+
expect(File).not_to exist("#{mock_upload_directory}/world.png")
|
189
|
+
# And into the storage directory
|
190
|
+
files = Batch.find(batch_id).generic_files
|
191
|
+
expect(files.first.label).to eq 'world.png'
|
192
|
+
# TODO: use files.select once projecthydra/active_fedora#609 is fixed
|
193
|
+
['icons.zip', 'Example.ogg'].each do |filename|
|
194
|
+
expect(files.map { |f| f.relative_path if f.label.match(filename) }.compact.first).to eq "import/files/#{filename}"
|
195
|
+
end
|
196
|
+
expect(files.map { |f| f.relative_path if f.label.match("dublin_core_rdf_descMetadata.nt") }.compact.first).to eq 'import/metadata/dublin_core_rdf_descMetadata.nt'
|
212
197
|
end
|
213
|
-
expect(files.select{|f| f.label == 'dublin_core_rdf_descMetadata.nt'}.first.relative_path).to eq('import/metadata/dublin_core_rdf_descMetadata.nt')
|
214
198
|
end
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
199
|
+
|
200
|
+
context "when User model does not define directory path" do
|
201
|
+
it "should return an error message and redirect to file upload page" do
|
202
|
+
expect {
|
203
|
+
post :create, local_file: ["world.png", "image.jpg"], batch_id: batch_id
|
204
|
+
}.to_not change(GenericFile, :count)
|
205
|
+
expect(response).to render_template :new
|
206
|
+
expect(flash[:alert]).to eq 'Your account is not configured for importing files from a user-directory on the server.'
|
207
|
+
end
|
221
208
|
end
|
222
209
|
end
|
223
210
|
end
|
224
211
|
|
225
212
|
describe "audit" do
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
end
|
232
|
-
after do
|
233
|
-
@generic_file.delete
|
213
|
+
let(:generic_file) do
|
214
|
+
GenericFile.create do |gf|
|
215
|
+
gf.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
216
|
+
gf.apply_depositor_metadata(user)
|
217
|
+
end
|
234
218
|
end
|
219
|
+
|
235
220
|
it "should return json with the result" do
|
236
|
-
xhr :post, :audit, id:
|
221
|
+
xhr :post, :audit, id: generic_file
|
237
222
|
expect(response).to be_success
|
238
|
-
|
239
|
-
audit_results =
|
240
|
-
expect(audit_results.reduce(true) { |sum, value| sum && value }).to
|
223
|
+
json = JSON.parse(response.body)
|
224
|
+
audit_results = json.collect { |result| result["pass"] }
|
225
|
+
expect(audit_results.reduce(true) { |sum, value| sum && value }).to eq 999 # never been audited
|
241
226
|
end
|
242
227
|
end
|
243
228
|
|
244
229
|
describe "destroy" do
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
@user = FactoryGirl.find_or_create(:jill)
|
250
|
-
sign_in @user
|
230
|
+
let(:generic_file) do
|
231
|
+
GenericFile.create do |gf|
|
232
|
+
gf.apply_depositor_metadata(user)
|
233
|
+
end
|
251
234
|
end
|
252
|
-
|
253
|
-
|
235
|
+
|
236
|
+
before do
|
237
|
+
allow(ContentDeleteEventJob).to receive(:new).with(generic_file.id, user.user_key).and_return(delete_message)
|
254
238
|
end
|
239
|
+
let(:delete_message) { double('delete message') }
|
255
240
|
it "should delete the file" do
|
256
|
-
expect(
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
it "should spawn a content delete event job" do
|
261
|
-
s1 = double('one')
|
262
|
-
expect(ContentDeleteEventJob).to receive(:new).with(@generic_file.pid, @user.user_key).and_return(s1)
|
263
|
-
expect(Sufia.queue).to receive(:push).with(s1).once
|
264
|
-
delete :destroy, id: @generic_file.pid
|
241
|
+
expect(Sufia.queue).to receive(:push).with(delete_message)
|
242
|
+
expect {
|
243
|
+
delete :destroy, id: generic_file
|
244
|
+
}.to change { GenericFile.exists?(generic_file.id) }.from(true).to(false)
|
265
245
|
end
|
266
246
|
|
267
247
|
context "when the file is featured" do
|
268
248
|
before do
|
269
|
-
FeaturedWork.create(generic_file_id:
|
249
|
+
FeaturedWork.create(generic_file_id: generic_file.id)
|
250
|
+
expect(Sufia.queue).to receive(:push).with(delete_message)
|
270
251
|
end
|
271
252
|
it "should make the file not featured" do
|
272
|
-
expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to include(
|
273
|
-
delete :destroy, id:
|
274
|
-
expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to_not include(
|
253
|
+
expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to include(generic_file.id)
|
254
|
+
delete :destroy, id: generic_file.id
|
255
|
+
expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to_not include(generic_file.id)
|
275
256
|
end
|
276
257
|
end
|
277
258
|
end
|
278
259
|
|
279
260
|
describe 'stats' do
|
280
|
-
|
281
|
-
|
282
|
-
gf.apply_depositor_metadata(
|
283
|
-
gf.save
|
261
|
+
let(:generic_file) do
|
262
|
+
GenericFile.create do |gf|
|
263
|
+
gf.apply_depositor_metadata(user)
|
284
264
|
end
|
285
265
|
end
|
286
266
|
|
287
|
-
after do
|
288
|
-
@generic_file.destroy
|
289
|
-
end
|
290
|
-
|
291
267
|
context 'when user has access to file' do
|
292
268
|
before do
|
269
|
+
sign_in user
|
293
270
|
mock_query = double('query')
|
294
271
|
allow(mock_query).to receive(:for_path).and_return([
|
295
272
|
OpenStruct.new(date: '2014-01-01', pageviews: 4),
|
@@ -304,31 +281,26 @@ describe GenericFilesController, :type => :controller do
|
|
304
281
|
|
305
282
|
download_query = double('query')
|
306
283
|
allow(download_query).to receive(:for_file).and_return([
|
307
|
-
OpenStruct.new(
|
284
|
+
OpenStruct.new(eventCategory: "Files", eventAction: "Downloaded", eventLabel: "123456789", totalEvents: "3")
|
308
285
|
])
|
309
286
|
allow(download_query).to receive(:map).and_return(download_query.for_file.map(&:marshal_dump))
|
310
287
|
allow(profile).to receive(:sufia__download).and_return(download_query)
|
311
288
|
end
|
312
289
|
|
313
290
|
it 'renders the stats view' do
|
314
|
-
|
315
|
-
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
|
316
|
-
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.my.files'), Sufia::Engine.routes.url_helpers.dashboard_files_path)
|
317
|
-
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.generic_file.browse_view'), Sufia::Engine.routes.url_helpers.generic_file_path(@generic_file.noid))
|
318
|
-
get :stats, id: @generic_file.noid
|
291
|
+
get :stats, id: generic_file
|
319
292
|
expect(response).to be_success
|
320
293
|
expect(response).to render_template(:stats)
|
321
294
|
end
|
322
295
|
|
323
296
|
context "user is not signed in but the file is public" do
|
324
297
|
before do
|
325
|
-
|
326
|
-
|
327
|
-
@generic_file.save
|
298
|
+
generic_file.read_groups = ['public']
|
299
|
+
generic_file.save
|
328
300
|
end
|
329
301
|
|
330
302
|
it 'renders the stats view' do
|
331
|
-
get :stats, id:
|
303
|
+
get :stats, id: generic_file
|
332
304
|
expect(response).to be_success
|
333
305
|
expect(response).to render_template(:stats)
|
334
306
|
end
|
@@ -337,186 +309,176 @@ describe GenericFilesController, :type => :controller do
|
|
337
309
|
|
338
310
|
context 'when user lacks access to file' do
|
339
311
|
before do
|
340
|
-
|
341
|
-
sign_in @archivist
|
312
|
+
sign_in FactoryGirl.create(:user)
|
342
313
|
end
|
343
314
|
|
344
315
|
it 'redirects to root_url' do
|
345
|
-
get :stats, id:
|
316
|
+
get :stats, id: generic_file
|
346
317
|
expect(response).to redirect_to(Sufia::Engine.routes.url_helpers.root_path)
|
347
318
|
end
|
348
319
|
end
|
349
320
|
end
|
350
321
|
|
351
|
-
describe "
|
322
|
+
describe "#edit" do
|
352
323
|
let(:generic_file) do
|
353
|
-
GenericFile.
|
354
|
-
gf.apply_depositor_metadata(
|
355
|
-
gf.save!
|
324
|
+
GenericFile.create do |gf|
|
325
|
+
gf.apply_depositor_metadata(user)
|
356
326
|
end
|
357
327
|
end
|
358
328
|
|
359
|
-
|
360
|
-
generic_file
|
361
|
-
end
|
362
|
-
|
363
|
-
it "should spawn a content update event job" do
|
364
|
-
s1 = double('one')
|
365
|
-
expect(ContentUpdateEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').and_return(s1)
|
366
|
-
expect(Sufia.queue).to receive(:push).with(s1).once
|
367
|
-
@user = FactoryGirl.find_or_create(:jill)
|
368
|
-
sign_in @user
|
369
|
-
post :update, id: generic_file, generic_file: {title: ['new_title'], tag: [''], permissions: { new_user_name: {'archivist1'=>'edit'}}}
|
370
|
-
@user.delete
|
371
|
-
end
|
372
|
-
|
373
|
-
it "spawns a content new version event job" do
|
374
|
-
s1 = double('one')
|
375
|
-
allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').and_return(s1)
|
376
|
-
expect(Sufia.queue).to receive(:push).with(s1).once
|
377
|
-
|
378
|
-
s2 = double('one')
|
379
|
-
allow(CharacterizeJob).to receive(:new).with(generic_file.pid).and_return(s2)
|
380
|
-
expect(Sufia.queue).to receive(:push).with(s2).once
|
381
|
-
@user = FactoryGirl.find_or_create(:jill)
|
382
|
-
sign_in @user
|
329
|
+
it "should set the versions presenter" do
|
330
|
+
get :edit, id: generic_file
|
383
331
|
|
384
|
-
|
385
|
-
|
386
|
-
|
332
|
+
expect(response).to be_success
|
333
|
+
expect(assigns[:generic_file]).to eq generic_file
|
334
|
+
expect(assigns[:version_list]).to be_kind_of Sufia::VersionListPresenter
|
387
335
|
end
|
388
336
|
|
389
|
-
|
390
|
-
@user = FactoryGirl.find_or_create(:jill)
|
391
|
-
sign_in @user
|
392
|
-
|
393
|
-
file = fixture_file_upload('/world.png','image/png')
|
394
|
-
post :update, id: generic_file, filedata: file, generic_file: { tag: [''], permissions: { new_user_name: { 'archivist1@example.com'=>'edit' } } }
|
395
|
-
|
396
|
-
posted_file = GenericFile.find(generic_file.pid)
|
397
|
-
version1 = posted_file.content.latest_version
|
398
|
-
expect(posted_file.content.version_committer(version1)).to eq(@user.user_key)
|
399
|
-
|
400
|
-
file = fixture_file_upload('/image.jpg','image/jpg')
|
401
|
-
post :update, id: generic_file, filedata: file, generic_file: { tag: [''], permissions: { new_user_name: { 'archivist1@example.com'=>'edit' } } }
|
402
|
-
|
403
|
-
posted_file = GenericFile.find(generic_file.pid)
|
404
|
-
version2 = posted_file.content.latest_version
|
405
|
-
expect(posted_file.content.version_committer(version2)).to eq(@user.user_key)
|
406
|
-
|
407
|
-
expect(posted_file.content.mimeType).to eq("image/jpeg")
|
408
|
-
post :update, id: generic_file, revision: 'content.0'
|
337
|
+
end
|
409
338
|
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
expect(restored_file.content.mimeType).to eq("image/png")
|
416
|
-
@user.delete
|
339
|
+
describe "update" do
|
340
|
+
let(:generic_file) do
|
341
|
+
GenericFile.create do |gf|
|
342
|
+
gf.apply_depositor_metadata(user)
|
343
|
+
end
|
417
344
|
end
|
418
345
|
|
419
|
-
context "when
|
420
|
-
let(:
|
421
|
-
let(:user) { FactoryGirl.find_or_create(:jill) }
|
422
|
-
let(:generic_file) do
|
423
|
-
GenericFile.new.tap do |gf|
|
424
|
-
gf.apply_depositor_metadata(user)
|
425
|
-
gf.edit_users = [user.user_key, archivist.user_key]
|
426
|
-
gf.save!
|
427
|
-
end
|
428
|
-
end
|
346
|
+
context "when updating metadata" do
|
347
|
+
let(:update_message) { double('content update message') }
|
429
348
|
before do
|
430
|
-
|
431
|
-
sign_in user
|
349
|
+
allow(ContentUpdateEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(update_message)
|
432
350
|
end
|
433
351
|
|
434
|
-
it "
|
435
|
-
|
436
|
-
post :update, id: generic_file,
|
437
|
-
|
438
|
-
|
439
|
-
version1 = posted_file.content.latest_version
|
440
|
-
expect(posted_file.content.version_committer(version1)).to eq(user.user_key)
|
352
|
+
it "should spawn a content update event job" do
|
353
|
+
expect(Sufia.queue).to receive(:push).with(update_message)
|
354
|
+
post :update, id: generic_file, generic_file: { title: ['new_title'], tag: [''],
|
355
|
+
permissions_attributes: [{ type: 'person', name: 'archivist1', access: 'edit'}] }
|
356
|
+
end
|
441
357
|
|
442
|
-
|
443
|
-
|
444
|
-
allow(
|
445
|
-
|
446
|
-
controller.instance_variable_set(:@actor, nil)
|
358
|
+
it "spawns a content new version event job" do
|
359
|
+
s1 = double('one')
|
360
|
+
allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(s1)
|
361
|
+
expect(Sufia.queue).to receive(:push).with(s1).once
|
447
362
|
|
448
|
-
|
363
|
+
s2 = double('one')
|
364
|
+
allow(CharacterizeJob).to receive(:new).with(generic_file.id).and_return(s2)
|
365
|
+
expect(Sufia.queue).to receive(:push).with(s2).once
|
366
|
+
file = fixture_file_upload('/world.png', 'image/png')
|
367
|
+
post :update, id: generic_file, filedata: file, generic_file: {tag: [''], permissions: { new_user_name: {archivist1: 'edit' } } }
|
368
|
+
end
|
369
|
+
end
|
449
370
|
|
371
|
+
context "when updating the attached file" do
|
372
|
+
it "spawns a content new version event job" do
|
450
373
|
s1 = double('one')
|
451
|
-
allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.
|
374
|
+
allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(s1)
|
452
375
|
expect(Sufia.queue).to receive(:push).with(s1).once
|
453
376
|
|
454
|
-
|
455
|
-
|
377
|
+
s2 = double('one')
|
378
|
+
allow(CharacterizeJob).to receive(:new).with(generic_file.id).and_return(s2)
|
379
|
+
expect(Sufia.queue).to receive(:push).with(s2).once
|
456
380
|
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
381
|
+
file = fixture_file_upload('/world.png', 'image/png')
|
382
|
+
post :update, id: generic_file, filedata: file, generic_file: {tag: [''],
|
383
|
+
permissions_attributes: [{ type: 'user', name: 'archivist1', access: 'edit'}] }
|
384
|
+
end
|
385
|
+
end
|
461
386
|
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
387
|
+
context "with two existing versions from different users" do
|
388
|
+
|
389
|
+
let(:file1) { "world.png" }
|
390
|
+
let(:file1_type) { "image/png" }
|
391
|
+
let(:file2) { "image.jpg" }
|
392
|
+
let(:file2_type) { "image/jpeg" }
|
393
|
+
let(:second_user) { FactoryGirl.create(:user) }
|
394
|
+
let(:version1) { "version1" }
|
395
|
+
let(:actor1) { Sufia::GenericFile::Actor.new(generic_file, user) }
|
396
|
+
let(:actor2) { Sufia::GenericFile::Actor.new(generic_file, second_user) }
|
469
397
|
|
470
|
-
|
471
|
-
|
398
|
+
before do
|
399
|
+
allow_any_instance_of(GenericFile).to receive(:characterize)
|
400
|
+
actor1.create_content(fixture_file_upload(file1), file1, 'content')
|
401
|
+
actor2.create_content(fixture_file_upload(file2), file2, 'content')
|
402
|
+
end
|
472
403
|
|
473
|
-
|
404
|
+
describe "restoring a previous version" do
|
405
|
+
context "as the first user" do
|
406
|
+
before do
|
407
|
+
sign_in user
|
408
|
+
post :update, id: generic_file, revision: version1
|
409
|
+
end
|
410
|
+
|
411
|
+
let(:restored_content) { generic_file.reload.content }
|
412
|
+
let(:versions) { restored_content.versions }
|
413
|
+
let(:latest_version) { restored_content.latest_version }
|
414
|
+
|
415
|
+
it "should restore the first versions's content and metadata" do
|
416
|
+
expect(restored_content.mime_type).to eq file1_type
|
417
|
+
expect(restored_content.original_name).to eq file1
|
418
|
+
expect(versions.all.count).to eq 3
|
419
|
+
expect(versions.last.label).to eq latest_version.label
|
420
|
+
expect(VersionCommitter.where(version_id: versions.last.uri).pluck(:committer_login)).to eq [user.user_key]
|
421
|
+
end
|
422
|
+
end
|
474
423
|
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
424
|
+
context "as the second user" do
|
425
|
+
before do
|
426
|
+
sign_in second_user
|
427
|
+
end
|
428
|
+
it "should not create a new version" do
|
429
|
+
post :update, id: generic_file, revision: version1
|
430
|
+
expect(response).to be_redirect
|
431
|
+
end
|
432
|
+
end
|
480
433
|
end
|
481
434
|
end
|
482
435
|
|
483
436
|
it "should add new groups and users" do
|
484
|
-
post :update, id: generic_file,
|
485
|
-
|
437
|
+
post :update, id: generic_file,
|
438
|
+
generic_file: { tag: [''],
|
439
|
+
permissions_attributes: [
|
440
|
+
{ type: 'person', name: 'user1', access: 'edit' },
|
441
|
+
{ type: 'group', name: 'group1', access: 'read' }
|
442
|
+
]
|
443
|
+
}
|
486
444
|
|
487
|
-
expect(assigns[:generic_file].read_groups).to eq
|
488
|
-
expect(assigns[:generic_file].edit_users).to include("user1",
|
445
|
+
expect(assigns[:generic_file].read_groups).to eq ["group1"]
|
446
|
+
expect(assigns[:generic_file].edit_users).to include("user1", user.user_key)
|
489
447
|
end
|
448
|
+
|
490
449
|
it "should update existing groups and users" do
|
491
|
-
generic_file.
|
450
|
+
generic_file.edit_groups = ['group3']
|
492
451
|
generic_file.save
|
493
|
-
post :update, id: generic_file,
|
494
|
-
|
452
|
+
post :update, id: generic_file,
|
453
|
+
generic_file: { tag: [''],
|
454
|
+
permissions_attributes: [
|
455
|
+
{ id: generic_file.permissions.last.id, type: 'group', name: 'group3', access: 'read'}
|
456
|
+
]
|
457
|
+
}
|
495
458
|
|
496
459
|
expect(assigns[:generic_file].read_groups).to eq(["group3"])
|
497
460
|
end
|
498
461
|
|
499
462
|
it "spawns a virus check" do
|
500
463
|
s1 = double('one')
|
501
|
-
allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.
|
464
|
+
allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(s1)
|
502
465
|
expect(Sufia.queue).to receive(:push).with(s1).once
|
503
466
|
|
504
467
|
s2 = double('one')
|
505
|
-
allow(CharacterizeJob).to receive(:new).with(generic_file.
|
506
|
-
allow(CreateDerivativesJob).to receive(:new).with(generic_file.
|
507
|
-
@user = FactoryGirl.find_or_create(:jill)
|
508
|
-
sign_in @user
|
468
|
+
allow(CharacterizeJob).to receive(:new).with(generic_file.id).and_return(s2)
|
469
|
+
allow(CreateDerivativesJob).to receive(:new).with(generic_file.id).and_return(s2)
|
509
470
|
file = fixture_file_upload('/world.png', 'image/png')
|
510
471
|
expect(Sufia::GenericFile::Actor).to receive(:virus_check).and_return(0)
|
511
472
|
expect(Sufia.queue).to receive(:push).with(s2).once
|
512
|
-
post :update, id: generic_file.
|
473
|
+
post :update, id: generic_file.id, filedata: file, 'Filename' => 'The world',
|
474
|
+
generic_file: { tag: [''],
|
475
|
+
permissions_attributes: [{ type: 'user', name: 'archivist1', access: 'edit' }] }
|
513
476
|
end
|
514
477
|
|
515
478
|
context "when there's an error saving" do
|
516
479
|
let!(:generic_file) do
|
517
|
-
GenericFile.
|
518
|
-
gf.apply_depositor_metadata(
|
519
|
-
gf.save!
|
480
|
+
GenericFile.create do |gf|
|
481
|
+
gf.apply_depositor_metadata(user)
|
520
482
|
end
|
521
483
|
end
|
522
484
|
it "redirects to edit" do
|
@@ -529,88 +491,61 @@ describe GenericFilesController, :type => :controller do
|
|
529
491
|
end
|
530
492
|
end
|
531
493
|
|
532
|
-
describe "
|
494
|
+
describe "someone elses files" do
|
533
495
|
let(:generic_file) do
|
534
|
-
GenericFile.
|
535
|
-
|
536
|
-
|
496
|
+
GenericFile.create(id: 'test5') do |f|
|
497
|
+
f.apply_depositor_metadata('archivist1@example.com')
|
498
|
+
f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
499
|
+
# grant public read access explicitly
|
500
|
+
f.read_groups = ['public']
|
537
501
|
end
|
538
502
|
end
|
539
503
|
|
540
|
-
after do
|
541
|
-
generic_file.destroy
|
542
|
-
end
|
543
|
-
|
544
|
-
it 'renders the edit view' do
|
545
|
-
allow(controller.request).to receive(:referer).and_return('foo')
|
546
|
-
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
|
547
|
-
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.my.files'), Sufia::Engine.routes.url_helpers.dashboard_files_path)
|
548
|
-
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.generic_file.browse_view'), Sufia::Engine.routes.url_helpers.generic_file_path(generic_file.noid))
|
549
|
-
get :edit, id: generic_file.noid
|
550
|
-
expect(response).to be_success
|
551
|
-
expect(response).to render_template(:edit)
|
552
|
-
end
|
553
|
-
end
|
554
|
-
describe "someone elses files" do
|
555
|
-
before do
|
556
|
-
f = GenericFile.new(pid: 'sufia:test5')
|
557
|
-
f.apply_depositor_metadata('archivist1@example.com')
|
558
|
-
f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
559
|
-
# grant public read access explicitly
|
560
|
-
f.read_groups = ['public']
|
561
|
-
f.save
|
562
|
-
@file = f
|
563
|
-
allow_any_instance_of(Sufia::GenericFile::Actor).to receive(:push_characterize_job)
|
564
|
-
end
|
565
|
-
after do
|
566
|
-
GenericFile.find('sufia:test5').destroy
|
567
|
-
end
|
568
504
|
describe "edit" do
|
569
505
|
it "should give me a flash error" do
|
570
|
-
get :edit, id:
|
506
|
+
get :edit, id: generic_file
|
571
507
|
expect(response).to redirect_to @routes.url_helpers.generic_file_path('test5')
|
572
508
|
expect(flash[:alert]).not_to be_nil
|
573
509
|
expect(flash[:alert]).not_to be_empty
|
574
510
|
expect(flash[:alert]).to include("You do not have sufficient privileges to edit this document")
|
575
511
|
end
|
576
512
|
end
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
expect(response).not_to redirect_to(action: 'show')
|
581
|
-
expect(flash[:alert]).to be_nil
|
582
|
-
end
|
583
|
-
it "should set the breadcrumbs" do
|
513
|
+
|
514
|
+
describe "#show" do
|
515
|
+
it "should show me the file and set breadcrumbs" do
|
584
516
|
expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
|
585
|
-
get :show, id:
|
517
|
+
get :show, id: generic_file
|
518
|
+
expect(response).to be_successful
|
519
|
+
expect(flash).to be_empty
|
520
|
+
expect(assigns[:events]).to be_kind_of Array
|
521
|
+
expect(assigns[:generic_file]).to eq generic_file
|
522
|
+
expect(assigns[:audit_status]).to eq 'Audits have not yet been run on this file.'
|
586
523
|
end
|
587
524
|
end
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
end
|
613
|
-
end
|
525
|
+
end
|
526
|
+
|
527
|
+
describe "flash" do
|
528
|
+
it "should not let the user submit if they logout" do
|
529
|
+
sign_out user
|
530
|
+
get :new
|
531
|
+
expect(response).to_not be_success
|
532
|
+
expect(flash[:alert]).to include("You need to sign in or sign up before continuing")
|
533
|
+
end
|
534
|
+
it "should filter flash if they signin" do
|
535
|
+
sign_in user
|
536
|
+
get :new
|
537
|
+
expect(flash[:alert]).to be_nil
|
538
|
+
end
|
539
|
+
end
|
540
|
+
|
541
|
+
describe "notifications" do
|
542
|
+
before do
|
543
|
+
User.audituser.send_message(user, "Test message", "Test subject")
|
544
|
+
end
|
545
|
+
it "should display notifications" do
|
546
|
+
get :new
|
547
|
+
expect(assigns[:notify_number]).to eq 1
|
548
|
+
expect(user.mailbox.inbox[0].messages[0].subject).to eq "Test subject"
|
614
549
|
end
|
615
550
|
end
|
616
551
|
end
|