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
@@ -4,8 +4,7 @@ describe HomepageController, :type => :controller do
|
|
4
4
|
routes { Rails.application.class.routes }
|
5
5
|
|
6
6
|
describe "#index" do
|
7
|
-
before
|
8
|
-
GenericFile.delete_all
|
7
|
+
before do
|
9
8
|
@gf1 = GenericFile.new(title:['Test Document PDF'], filename:['test.pdf'], tag:['rocks'], read_groups:['public'])
|
10
9
|
@gf1.apply_depositor_metadata('mjg36')
|
11
10
|
@gf1.save
|
@@ -14,11 +13,6 @@ describe HomepageController, :type => :controller do
|
|
14
13
|
@gf2.save
|
15
14
|
end
|
16
15
|
|
17
|
-
after :all do
|
18
|
-
@gf1.delete
|
19
|
-
@gf2.delete
|
20
|
-
end
|
21
|
-
|
22
16
|
let(:user) { FactoryGirl.find_or_create(:jill) }
|
23
17
|
before do
|
24
18
|
sign_in user
|
@@ -45,9 +39,16 @@ describe HomepageController, :type => :controller do
|
|
45
39
|
it "should not include other user's private documents in recent documents" do
|
46
40
|
get :index
|
47
41
|
expect(response).to be_success
|
48
|
-
titles = assigns(:recent_documents).map {|d| d['
|
42
|
+
titles = assigns(:recent_documents).map {|d| d['title_tesim'][0]}
|
49
43
|
expect(titles).to_not include('Test Private Document')
|
50
|
-
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "should include only GenericFile objects in recent documents" do
|
47
|
+
get :index
|
48
|
+
assigns(:recent_documents).each do |doc|
|
49
|
+
expect(doc[Solrizer.solr_name("has_model", :symbol)]).to eql ["GenericFile"]
|
50
|
+
end
|
51
|
+
end
|
51
52
|
|
52
53
|
context "with a document not created this second" do
|
53
54
|
before do
|
@@ -70,6 +71,8 @@ describe HomepageController, :type => :controller do
|
|
70
71
|
create_times = assigns(:recent_documents).map{|d| d['system_create_dtsi']}
|
71
72
|
expect(create_times).to eq create_times.sort.reverse
|
72
73
|
end
|
74
|
+
|
75
|
+
|
73
76
|
end
|
74
77
|
|
75
78
|
context "with featured works" do
|
@@ -11,10 +11,7 @@ describe MailboxController, :type => :controller do
|
|
11
11
|
allow_any_instance_of(MailboxController).to receive(:authenticate_user!).and_return(true)
|
12
12
|
sign_in @user
|
13
13
|
end
|
14
|
-
|
15
|
-
@rec1.delete
|
16
|
-
@rec2.delete
|
17
|
-
end
|
14
|
+
|
18
15
|
describe "#index" do
|
19
16
|
it "should show message" do
|
20
17
|
get :index
|
@@ -2,16 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe My::FilesController, :type => :controller do
|
4
4
|
|
5
|
-
before :all do
|
6
|
-
GenericFile.destroy_all
|
7
|
-
Collection.destroy_all
|
8
|
-
end
|
9
|
-
|
10
|
-
after :all do
|
11
|
-
GenericFile.destroy_all
|
12
|
-
Collection.destroy_all
|
13
|
-
end
|
14
|
-
|
15
5
|
let(:my_collection) do
|
16
6
|
Collection.new(title: 'test collection').tap do |c|
|
17
7
|
c.apply_depositor_metadata(user.user_key)
|
@@ -2,53 +2,46 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe SingleUseLinksController, :type => :controller do
|
4
4
|
let(:user) { FactoryGirl.find_or_create(:jill) }
|
5
|
+
|
5
6
|
let(:file) do
|
6
|
-
GenericFile.new.tap do |
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
end
|
11
|
-
end
|
12
|
-
let(:file2) do
|
13
|
-
GenericFile.new.tap do |f|
|
14
|
-
f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
15
|
-
f.apply_depositor_metadata('mjg36')
|
16
|
-
f.save
|
7
|
+
GenericFile.new.tap do |file|
|
8
|
+
file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
9
|
+
file.apply_depositor_metadata(user)
|
10
|
+
file.save
|
17
11
|
end
|
18
12
|
end
|
19
|
-
|
20
|
-
allow(controller).to receive(:has_access?).and_return(true)
|
21
|
-
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
22
|
-
end
|
23
|
-
after(:all) do
|
24
|
-
ActiveFedora::Base.destroy_all
|
25
|
-
SingleUseLink.destroy_all
|
26
|
-
end
|
13
|
+
|
27
14
|
describe "logged in user with edit permission" do
|
15
|
+
let(:hash) { "some-dummy-sha2-hash" }
|
16
|
+
|
28
17
|
before do
|
29
18
|
sign_in user
|
30
|
-
|
31
|
-
|
32
|
-
@hash = "some-dummy-sha2-hash"
|
33
|
-
allow(Digest::SHA2).to receive(:new).and_return(@hash)
|
19
|
+
allow(DateTime).to receive(:now).and_return(DateTime.now)
|
20
|
+
expect(Digest::SHA2).to receive(:new).and_return(hash)
|
34
21
|
end
|
35
22
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
describe "GET 'download'" do
|
24
|
+
it "and_return http success" do
|
25
|
+
get 'new_download', id: file
|
26
|
+
expect(response).to be_success
|
27
|
+
expect(assigns[:link]).to eq routes.url_helpers.download_single_use_link_path(hash)
|
28
|
+
end
|
40
29
|
end
|
41
30
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
31
|
+
describe "GET 'show'" do
|
32
|
+
it "and_return http success" do
|
33
|
+
get 'new_show', id: file
|
34
|
+
expect(response).to be_success
|
35
|
+
expect(assigns[:link]).to eq routes.url_helpers.show_single_use_link_path(hash)
|
36
|
+
end
|
46
37
|
end
|
47
38
|
end
|
48
39
|
|
49
40
|
describe "logged in user without edit permission" do
|
50
41
|
before do
|
51
42
|
@other_user = FactoryGirl.find_or_create(:archivist)
|
43
|
+
file.read_users << @other_user
|
44
|
+
file.save
|
52
45
|
sign_in @other_user
|
53
46
|
file.read_users << @other_user
|
54
47
|
file.save
|
@@ -56,7 +49,7 @@ describe SingleUseLinksController, :type => :controller do
|
|
56
49
|
|
57
50
|
describe "GET 'download'" do
|
58
51
|
it "and_return http success" do
|
59
|
-
get 'new_download', id: file
|
52
|
+
get 'new_download', id: file
|
60
53
|
expect(response).not_to be_success
|
61
54
|
end
|
62
55
|
|
@@ -64,7 +57,7 @@ describe SingleUseLinksController, :type => :controller do
|
|
64
57
|
|
65
58
|
describe "GET 'show'" do
|
66
59
|
it "and_return http success" do
|
67
|
-
get 'new_show', id: file
|
60
|
+
get 'new_show', id: file
|
68
61
|
expect(response).not_to be_success
|
69
62
|
end
|
70
63
|
|
@@ -74,14 +67,14 @@ describe SingleUseLinksController, :type => :controller do
|
|
74
67
|
describe "unknown user" do
|
75
68
|
describe "GET 'download'" do
|
76
69
|
it "and_return http failure" do
|
77
|
-
get 'new_download', id: file
|
70
|
+
get 'new_download', id: file
|
78
71
|
expect(response).not_to be_success
|
79
72
|
end
|
80
73
|
end
|
81
74
|
|
82
75
|
describe "GET 'show'" do
|
83
76
|
it "and_return http failure" do
|
84
|
-
get 'new_show', id: file
|
77
|
+
get 'new_show', id: file
|
85
78
|
expect(response).not_to be_success
|
86
79
|
end
|
87
80
|
end
|
@@ -1,34 +1,21 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
|
-
describe SingleUseLinksViewerController
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
@file2 = GenericFile.new
|
11
|
-
@file2.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
12
|
-
@file2.apply_depositor_metadata('mjg36')
|
13
|
-
@file2.save
|
14
|
-
end
|
15
|
-
after(:all) do
|
16
|
-
@file.delete
|
17
|
-
@file2.delete
|
18
|
-
SingleUseLink.delete_all
|
19
|
-
end
|
20
|
-
before do
|
21
|
-
allow(controller).to receive(:has_access?).and_return(true)
|
22
|
-
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
3
|
+
describe SingleUseLinksViewerController do
|
4
|
+
let(:file) do
|
5
|
+
GenericFile.new.tap do |file|
|
6
|
+
file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
|
7
|
+
file.apply_depositor_metadata('mjg')
|
8
|
+
file.save!
|
9
|
+
end
|
23
10
|
end
|
24
|
-
|
11
|
+
|
25
12
|
describe "retrieval links" do
|
26
13
|
let :show_link do
|
27
|
-
SingleUseLink.create itemId:
|
14
|
+
SingleUseLink.create itemId: file.id, path: routes.url_helpers.generic_file_path(id: file)
|
28
15
|
end
|
29
16
|
|
30
17
|
let :download_link do
|
31
|
-
SingleUseLink.create itemId:
|
18
|
+
SingleUseLink.create itemId: file.id, path: routes.url_helpers.download_path(id: file)
|
32
19
|
end
|
33
20
|
|
34
21
|
let :show_link_hash do
|
@@ -39,26 +26,25 @@ describe SingleUseLinksViewerController, :type => :controller do
|
|
39
26
|
download_link.downloadKey
|
40
27
|
end
|
41
28
|
|
42
|
-
before (:each) do
|
43
|
-
@user.delete
|
44
|
-
end
|
45
29
|
describe "GET 'download'" do
|
30
|
+
let(:expected_content) { ActiveFedora::Base.find(file.id).content.content }
|
31
|
+
|
46
32
|
it "and_return http success" do
|
47
|
-
|
48
|
-
|
49
|
-
expect(
|
50
|
-
get :download, id:download_link_hash
|
51
|
-
expect(response.body).to eq(expected_content)
|
33
|
+
expect(controller).to receive(:send_file_headers!).with(filename: 'world.png', disposition: 'inline', type: 'image/png')
|
34
|
+
get :download, id: download_link_hash
|
35
|
+
expect(response.body).to eq expected_content
|
52
36
|
expect(response).to be_success
|
53
37
|
end
|
38
|
+
|
54
39
|
it "and_return 404 on second attempt" do
|
55
|
-
get :download, id:download_link_hash
|
40
|
+
get :download, id: download_link_hash
|
56
41
|
expect(response).to be_success
|
57
|
-
get :download, id:download_link_hash
|
58
|
-
expect(response).to render_template('error/single_use_error')
|
42
|
+
get :download, id: download_link_hash
|
43
|
+
expect(response).to render_template('error/single_use_error')
|
59
44
|
end
|
45
|
+
|
60
46
|
it "and_return 404 on attempt to get download with show" do
|
61
|
-
get :download, id:download_link_hash
|
47
|
+
get :download, id: download_link_hash
|
62
48
|
expect(response).to be_success
|
63
49
|
get :show, id:download_link_hash
|
64
50
|
expect(response).to render_template('error/single_use_error')
|
@@ -67,19 +53,19 @@ describe SingleUseLinksViewerController, :type => :controller do
|
|
67
53
|
|
68
54
|
describe "GET 'show'" do
|
69
55
|
it "and_return http success" do
|
70
|
-
|
71
|
-
get 'show', id:show_link_hash
|
56
|
+
get 'show', id: show_link_hash
|
72
57
|
expect(response).to be_success
|
73
|
-
expect(assigns[:asset].
|
58
|
+
expect(assigns[:asset].id).to eq file.id
|
74
59
|
end
|
60
|
+
|
75
61
|
it "and_return 404 on second attempt" do
|
76
|
-
get :show, id:show_link_hash
|
62
|
+
get :show, id: show_link_hash
|
77
63
|
expect(response).to be_success
|
78
|
-
get :show, id:show_link_hash
|
64
|
+
get :show, id: show_link_hash
|
79
65
|
expect(response).to render_template('error/single_use_error')
|
80
66
|
end
|
81
67
|
it "and_return 404 on attempt to get show path with download hash" do
|
82
|
-
get :show, id:download_link_hash
|
68
|
+
get :show, id: download_link_hash
|
83
69
|
expect(response).to render_template('error/single_use_error')
|
84
70
|
end
|
85
71
|
end
|
@@ -29,9 +29,9 @@ describe TransfersController, :type => :controller do
|
|
29
29
|
get :index
|
30
30
|
expect(response).to be_success
|
31
31
|
expect(assigns[:incoming].first).to be_kind_of ProxyDepositRequest
|
32
|
-
expect(assigns[:incoming].first.pid).to eq(incoming_file.
|
32
|
+
expect(assigns[:incoming].first.pid).to eq(incoming_file.id)
|
33
33
|
expect(assigns[:outgoing].first).to be_kind_of ProxyDepositRequest
|
34
|
-
expect(assigns[:outgoing].first.pid).to eq(outgoing_file.
|
34
|
+
expect(assigns[:outgoing].first.pid).to eq(outgoing_file.id)
|
35
35
|
end
|
36
36
|
|
37
37
|
describe "When the incoming request is for a deleted file" do
|
@@ -60,7 +60,7 @@ describe TransfersController, :type => :controller do
|
|
60
60
|
expect(response).to be_success
|
61
61
|
expect(assigns[:generic_file]).to eq(file)
|
62
62
|
expect(assigns[:proxy_deposit_request]).to be_kind_of ProxyDepositRequest
|
63
|
-
expect(assigns[:proxy_deposit_request].pid).to eq(file.
|
63
|
+
expect(assigns[:proxy_deposit_request].pid).to eq(file.id)
|
64
64
|
end
|
65
65
|
end
|
66
66
|
end
|
@@ -75,12 +75,12 @@ describe TransfersController, :type => :controller do
|
|
75
75
|
it "should be successful" do
|
76
76
|
allow_any_instance_of(User).to receive(:display_name).and_return("Jill Z. User")
|
77
77
|
expect {
|
78
|
-
post :create, id: file
|
78
|
+
post :create, id: file, proxy_deposit_request: {transfer_to: another_user.user_key}
|
79
79
|
}.to change(ProxyDepositRequest, :count).by(1)
|
80
80
|
expect(response).to redirect_to @routes.url_helpers.transfers_path
|
81
81
|
expect(flash[:notice]).to eq('Transfer request created')
|
82
82
|
proxy_request = another_user.proxy_deposit_requests.first
|
83
|
-
expect(proxy_request.pid).to eq(file.
|
83
|
+
expect(proxy_request.pid).to eq(file.id)
|
84
84
|
expect(proxy_request.sending_user).to eq(user)
|
85
85
|
# AND A NOTIFICATION SHOULD HAVE BEEN CREATED
|
86
86
|
notification = another_user.reload.mailbox.inbox[0].messages[0]
|
@@ -89,7 +89,7 @@ describe TransfersController, :type => :controller do
|
|
89
89
|
end
|
90
90
|
it "should give an error if the user is not found" do
|
91
91
|
expect {
|
92
|
-
post :create, id: file
|
92
|
+
post :create, id: file, proxy_deposit_request: {transfer_to: 'foo' }
|
93
93
|
}.not_to change(ProxyDepositRequest, :count)
|
94
94
|
expect(assigns[:proxy_deposit_request].errors[:transfer_to]).to eq(['must be an existing user'])
|
95
95
|
expect(response).to redirect_to(root_path)
|
@@ -1,17 +1,16 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe UsersController, :type => :controller do
|
4
|
+
let(:user) { FactoryGirl.create(:user) }
|
4
5
|
before(:each) do
|
5
|
-
|
6
|
-
@another_user = FactoryGirl.find_or_create(:archivist)
|
7
|
-
sign_in @user
|
6
|
+
sign_in user
|
8
7
|
allow_any_instance_of(User).to receive(:groups).and_return([])
|
9
8
|
allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
|
10
9
|
end
|
11
10
|
|
12
11
|
describe "#show" do
|
13
12
|
it "show the user profile if user exists" do
|
14
|
-
get :show, id:
|
13
|
+
get :show, id: user.user_key
|
15
14
|
expect(response).to be_success
|
16
15
|
expect(response).to_not redirect_to(root_path)
|
17
16
|
expect(flash[:alert]).to be_nil
|
@@ -23,10 +22,9 @@ describe UsersController, :type => :controller do
|
|
23
22
|
end
|
24
23
|
|
25
24
|
describe "when the user has trophies" do
|
26
|
-
let(:
|
27
|
-
let(:
|
28
|
-
let(:
|
29
|
-
let(:file3) { GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save! } }
|
25
|
+
let(:file1) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
26
|
+
let(:file2) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
27
|
+
let(:file3) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
30
28
|
let!(:trophy1) { user.trophies.create!(generic_file_id: file1.noid) }
|
31
29
|
let!(:trophy2) { user.trophies.create!(generic_file_id: file2.noid) }
|
32
30
|
let!(:trophy3) { user.trophies.create!(generic_file_id: file3.noid) }
|
@@ -40,14 +38,13 @@ describe UsersController, :type => :controller do
|
|
40
38
|
end
|
41
39
|
end
|
42
40
|
describe "#index" do
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
end
|
41
|
+
let!(:u1) { FactoryGirl.create(:user) }
|
42
|
+
let!(:u2) { FactoryGirl.create(:user) }
|
43
|
+
|
47
44
|
describe "requesting html" do
|
48
45
|
it "should test users" do
|
49
46
|
get :index
|
50
|
-
expect(assigns[:users]).to include(
|
47
|
+
expect(assigns[:users]).to include(u1, u2)
|
51
48
|
expect(response).to be_successful
|
52
49
|
end
|
53
50
|
end
|
@@ -56,154 +53,159 @@ describe UsersController, :type => :controller do
|
|
56
53
|
get :index, format: :json
|
57
54
|
expect(response).to be_successful
|
58
55
|
json = JSON.parse(response.body)
|
59
|
-
expect(json.map{|u| u['id']}).to include(
|
60
|
-
expect(json.map{|u| u['text']}).to include(
|
56
|
+
expect(json.map{|u| u['id']}).to include(u1.email, u2.email)
|
57
|
+
expect(json.map{|u| u['text']}).to include(u1.email, u2.email)
|
61
58
|
end
|
62
59
|
end
|
60
|
+
|
63
61
|
describe "query users" do
|
64
62
|
it "finds the expected user via email" do
|
65
|
-
get :index, uq:
|
66
|
-
expect(assigns[:users]).to include(
|
67
|
-
expect(assigns[:users]).to_not include(
|
63
|
+
get :index, uq: u1.email
|
64
|
+
expect(assigns[:users]).to include(u1)
|
65
|
+
expect(assigns[:users]).to_not include(u2)
|
68
66
|
expect(response).to be_successful
|
69
67
|
end
|
68
|
+
|
70
69
|
it "finds the expected user via display name" do
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
70
|
+
u1.display_name = "Dr. Curator"
|
71
|
+
u1.save
|
72
|
+
u2.display_name = "Jr. Architect"
|
73
|
+
u2.save
|
75
74
|
allow_any_instance_of(User).to receive(:display_name).and_return("Dr. Curator", "Jr.Archivist")
|
76
|
-
get :index, uq:
|
77
|
-
expect(assigns[:users]).to include(
|
78
|
-
expect(assigns[:users]).to_not include(
|
75
|
+
get :index, uq: u1.display_name
|
76
|
+
expect(assigns[:users]).to include(u1)
|
77
|
+
expect(assigns[:users]).to_not include(u2)
|
79
78
|
expect(response).to be_successful
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
79
|
+
u1.display_name = nil
|
80
|
+
u1.save
|
81
|
+
u2.display_name = nil
|
82
|
+
u2.save
|
84
83
|
end
|
84
|
+
|
85
85
|
it "uses the base query" do
|
86
|
-
u3 = FactoryGirl.
|
87
|
-
allow(controller).to receive(:base_query).and_return([
|
86
|
+
u3 = FactoryGirl.create(:user)
|
87
|
+
allow(controller).to receive(:base_query).and_return(["email == \"#{u3.email}\""])
|
88
88
|
get :index
|
89
89
|
expect(assigns[:users]).to include(u3)
|
90
|
-
expect(assigns[:users]).to_not include(
|
90
|
+
expect(assigns[:users]).to_not include(u1, u2)
|
91
91
|
u3.destroy
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
95
95
|
describe "#edit" do
|
96
|
+
|
96
97
|
it "show edit form when user edits own profile" do
|
97
|
-
get :edit, id:
|
98
|
+
get :edit, id: user.user_key
|
98
99
|
expect(response).to be_success
|
99
100
|
expect(response).to render_template('users/edit')
|
100
101
|
expect(flash[:alert]).to be_nil
|
101
102
|
end
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
|
104
|
+
context "when user attempts to edit another profile" do
|
105
|
+
let(:another_user) { FactoryGirl.create(:user) }
|
106
|
+
it "redirects to show profile" do
|
107
|
+
get :edit, id: another_user.user_key
|
108
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(another_user.to_param))
|
109
|
+
expect(flash[:alert]).to include("Permission denied: cannot access this page.")
|
110
|
+
end
|
106
111
|
end
|
112
|
+
|
107
113
|
describe "when the user has trophies" do
|
108
|
-
let(:
|
109
|
-
let(:
|
110
|
-
let(:
|
111
|
-
let(:file3) { GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save! } }
|
114
|
+
let(:file1) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
115
|
+
let(:file2) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
116
|
+
let(:file3) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
112
117
|
let!(:trophy1) { user.trophies.create!(generic_file_id: file1.noid) }
|
113
118
|
let!(:trophy2) { user.trophies.create!(generic_file_id: file2.noid) }
|
114
119
|
let!(:trophy3) { user.trophies.create!(generic_file_id: file3.noid) }
|
115
120
|
|
116
121
|
it "show the user profile if user exists" do
|
117
|
-
get :edit, id:
|
122
|
+
get :edit, id: user.user_key
|
118
123
|
expect(response).to be_success
|
119
124
|
expect(assigns[:trophies]).to match_array([file1, file2, file3])
|
120
125
|
end
|
121
126
|
|
122
127
|
end
|
123
128
|
end
|
129
|
+
|
124
130
|
describe "#update" do
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
131
|
+
context "the profile of another user" do
|
132
|
+
let(:another_user) { FactoryGirl.create(:user) }
|
133
|
+
it "should not allow other users to update" do
|
134
|
+
post :update, id: another_user.user_key, user: { avatar: nil }
|
135
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(another_user.to_param))
|
136
|
+
expect(flash[:alert]).to include("Permission denied: cannot access this page.")
|
137
|
+
end
|
129
138
|
end
|
139
|
+
|
130
140
|
it "should set an avatar and redirect to profile" do
|
131
|
-
expect(
|
141
|
+
expect(user.avatar?).to be false
|
132
142
|
s1 = double('one')
|
133
|
-
expect(UserEditProfileEventJob).to receive(:new).with(
|
143
|
+
expect(UserEditProfileEventJob).to receive(:new).with(user.user_key).and_return(s1)
|
134
144
|
expect(Sufia.queue).to receive(:push).with(s1).once
|
135
145
|
f = fixture_file_upload('/1.5mb-avatar.jpg', 'image/jpg')
|
136
|
-
post :update, id:
|
137
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
146
|
+
post :update, id: user.user_key, user: { avatar: f }
|
147
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(user.to_param))
|
138
148
|
expect(flash[:notice]).to include("Your profile has been updated")
|
139
|
-
expect(User.find_by_user_key(
|
149
|
+
expect(User.find_by_user_key(user.user_key).avatar?).to be true
|
140
150
|
end
|
141
151
|
it "should validate the content type of an avatar" do
|
142
152
|
expect(Sufia.queue).to receive(:push).never
|
143
153
|
f = fixture_file_upload('/image.jp2', 'image/jp2')
|
144
|
-
post :update, id:
|
145
|
-
expect(response).to redirect_to(@routes.url_helpers.edit_profile_path(
|
154
|
+
post :update, id: user.user_key, user: { avatar: f }
|
155
|
+
expect(response).to redirect_to(@routes.url_helpers.edit_profile_path(user.to_param))
|
146
156
|
expect(flash[:alert]).to include("Avatar You are not allowed to upload \"jp2\" files, allowed types: jpg, jpeg, png, gif, bmp, tif, tiff")
|
147
157
|
end
|
148
158
|
it "should validate the size of an avatar" do
|
149
159
|
f = fixture_file_upload('/4-20.png', 'image/png')
|
150
160
|
expect(Sufia.queue).to receive(:push).never
|
151
|
-
post :update, id:
|
152
|
-
expect(response).to redirect_to(@routes.url_helpers.edit_profile_path(
|
161
|
+
post :update, id: user.user_key, user: { avatar: f }
|
162
|
+
expect(response).to redirect_to(@routes.url_helpers.edit_profile_path(user.to_param))
|
153
163
|
expect(flash[:alert]).to include("Avatar file size must be less than 2MB")
|
154
164
|
end
|
165
|
+
|
155
166
|
context "user with existing avatar" do
|
156
167
|
before do
|
157
168
|
f = fixture_file_upload('/world.png', 'image/png')
|
158
|
-
|
159
|
-
@user.save
|
169
|
+
user.update(avatar: f)
|
160
170
|
end
|
171
|
+
|
161
172
|
it "should delete an avatar" do
|
162
173
|
s1 = double('one')
|
163
|
-
expect(UserEditProfileEventJob).to receive(:new).with(
|
174
|
+
expect(UserEditProfileEventJob).to receive(:new).with(user.user_key).and_return(s1)
|
164
175
|
expect(Sufia.queue).to receive(:push).with(s1).once
|
165
|
-
post :update, id:
|
166
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
176
|
+
post :update, id: user.user_key, user: { remove_avatar: true }
|
177
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(user.to_param))
|
167
178
|
expect(flash[:notice]).to include("Your profile has been updated")
|
168
|
-
expect(User.find_by_user_key(
|
179
|
+
expect(User.find_by_user_key(user.user_key).avatar?).to be false
|
169
180
|
end
|
170
181
|
end
|
182
|
+
|
171
183
|
it "should refresh directory attributes" do
|
172
184
|
s1 = double('one')
|
173
|
-
expect(UserEditProfileEventJob).to receive(:new).with(
|
185
|
+
expect(UserEditProfileEventJob).to receive(:new).with(user.user_key).and_return(s1)
|
174
186
|
expect(Sufia.queue).to receive(:push).with(s1).once
|
175
|
-
expect_any_instance_of(User).to receive(:populate_attributes).once
|
176
|
-
post :update, id:
|
177
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
187
|
+
expect_any_instance_of(User).to receive(:populate_attributes).once
|
188
|
+
post :update, id: user.user_key, user: { update_directory: true }
|
189
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(user.to_param))
|
178
190
|
expect(flash[:notice]).to include("Your profile has been updated")
|
179
191
|
end
|
180
|
-
|
181
192
|
it "should set an social handles" do
|
182
|
-
expect(
|
183
|
-
expect(
|
184
|
-
expect(
|
185
|
-
expect(
|
186
|
-
|
187
|
-
|
188
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(@user.to_param))
|
193
|
+
expect(user.twitter_handle).to be_blank
|
194
|
+
expect(user.facebook_handle).to be_blank
|
195
|
+
expect(user.googleplus_handle).to be_blank
|
196
|
+
expect(user.linkedin_handle).to be_blank
|
197
|
+
post :update, id: user.user_key, user: { twitter_handle: 'twit', facebook_handle: 'face', googleplus_handle: 'goo', linkedin_handle:"link" }
|
198
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(user.to_param))
|
189
199
|
expect(flash[:notice]).to include("Your profile has been updated")
|
190
|
-
u = User.find_by_user_key(
|
200
|
+
u = User.find_by_user_key(user.user_key)
|
191
201
|
expect(u.twitter_handle).to eq 'twit'
|
192
202
|
expect(u.facebook_handle).to eq 'face'
|
193
203
|
expect(u.googleplus_handle).to eq 'goo'
|
194
204
|
expect(u.linkedin_handle).to eq 'link'
|
195
|
-
expect(u.orcid).to eq 'http://orcid.org/0000-0000-1111-2222'
|
196
|
-
end
|
197
|
-
it 'displays a flash when invalid ORCID is entered' do
|
198
|
-
expect(@user.orcid).to be_blank
|
199
|
-
post :update, id: @user.user_key, user: { orcid: 'foobar' }
|
200
|
-
expect(response).to redirect_to(@routes.url_helpers.edit_profile_path(@user.to_param))
|
201
|
-
expect(flash[:alert]).to include('Orcid must be a string of 19 characters, e.g., "0000-0000-0000-0000"')
|
202
205
|
end
|
203
206
|
|
204
207
|
context "when removing a trophy" do
|
205
|
-
let(:
|
206
|
-
let(:file) { GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save! } }
|
208
|
+
let(:file) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
207
209
|
before do
|
208
210
|
user.trophies.create!(generic_file_id: file.noid)
|
209
211
|
end
|
@@ -218,80 +220,75 @@ describe UsersController, :type => :controller do
|
|
218
220
|
end
|
219
221
|
|
220
222
|
describe "#follow" do
|
221
|
-
|
222
|
-
@user.unfollow(@another_user) rescue nil
|
223
|
-
end
|
223
|
+
let(:another_user) { FactoryGirl.create(:user) }
|
224
224
|
it "should follow another user if not already following, and log an event" do
|
225
|
-
expect(
|
225
|
+
expect(user.following?(another_user)).to be false
|
226
226
|
s1 = double('one')
|
227
|
-
expect(UserFollowEventJob).to receive(:new).with(
|
227
|
+
expect(UserFollowEventJob).to receive(:new).with(user.user_key, another_user.user_key).and_return(s1)
|
228
228
|
expect(Sufia.queue).to receive(:push).with(s1).once
|
229
|
-
post :follow, id:
|
230
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
231
|
-
expect(flash[:notice]).to include("You are following #{
|
229
|
+
post :follow, id: another_user.user_key
|
230
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(another_user.to_param))
|
231
|
+
expect(flash[:notice]).to include("You are following #{another_user.user_key}")
|
232
232
|
end
|
233
233
|
it "should redirect to profile if already following and not log an event" do
|
234
|
-
allow_any_instance_of(User).to receive(:following?).with(
|
234
|
+
allow_any_instance_of(User).to receive(:following?).with(another_user).and_return(true)
|
235
235
|
expect(Sufia.queue).to receive(:push).never
|
236
|
-
post :follow, id:
|
237
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
238
|
-
expect(flash[:notice]).to include("You are following #{
|
236
|
+
post :follow, id: another_user.user_key
|
237
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(another_user.to_param))
|
238
|
+
expect(flash[:notice]).to include("You are following #{another_user.user_key}")
|
239
239
|
end
|
240
240
|
it "should redirect to profile if user attempts to self-follow and not log an event" do
|
241
241
|
expect(Sufia.queue).to receive(:push).never
|
242
|
-
post :follow, id:
|
243
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
242
|
+
post :follow, id: user.user_key
|
243
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(user.to_param))
|
244
244
|
expect(flash[:alert]).to include("You cannot follow or unfollow yourself")
|
245
245
|
end
|
246
246
|
end
|
247
|
+
|
247
248
|
describe "#unfollow" do
|
249
|
+
let(:another_user) { FactoryGirl.create(:user) }
|
248
250
|
it "should unfollow another user if already following, and log an event" do
|
249
|
-
allow_any_instance_of(User).to receive(:following?).with(
|
251
|
+
allow_any_instance_of(User).to receive(:following?).with(another_user).and_return(true)
|
250
252
|
s1 = double('one')
|
251
|
-
expect(UserUnfollowEventJob).to receive(:new).with(
|
253
|
+
expect(UserUnfollowEventJob).to receive(:new).with(user.user_key, another_user.user_key).and_return(s1)
|
252
254
|
expect(Sufia.queue).to receive(:push).with(s1).once
|
253
|
-
post :unfollow, id:
|
254
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
255
|
-
expect(flash[:notice]).to include("You are no longer following #{
|
255
|
+
post :unfollow, id: another_user.user_key
|
256
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(another_user.to_param))
|
257
|
+
expect(flash[:notice]).to include("You are no longer following #{another_user.user_key}")
|
256
258
|
end
|
257
259
|
it "should redirect to profile if not following and not log an event" do
|
258
|
-
allow(
|
260
|
+
allow(user).to receive(:following?).with(another_user).and_return(false)
|
259
261
|
expect(Sufia.queue).to receive(:push).never
|
260
|
-
post :unfollow, id:
|
261
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
262
|
-
expect(flash[:notice]).to include("You are no longer following #{
|
262
|
+
post :unfollow, id: another_user.user_key
|
263
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(another_user.to_param))
|
264
|
+
expect(flash[:notice]).to include("You are no longer following #{another_user.user_key}")
|
263
265
|
end
|
264
266
|
it "should redirect to profile if user attempts to self-follow and not log an event" do
|
265
267
|
expect(Sufia.queue).to receive(:push).never
|
266
|
-
post :unfollow, id:
|
267
|
-
expect(response).to redirect_to(@routes.url_helpers.profile_path(
|
268
|
+
post :unfollow, id: user.user_key
|
269
|
+
expect(response).to redirect_to(@routes.url_helpers.profile_path(user.to_param))
|
268
270
|
expect(flash[:alert]).to include("You cannot follow or unfollow yourself")
|
269
271
|
end
|
270
272
|
end
|
273
|
+
|
271
274
|
describe "#toggle_trophy" do
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
@file_id = @file.pid.split(":").last
|
277
|
-
end
|
278
|
-
after do
|
279
|
-
@file.delete
|
280
|
-
end
|
275
|
+
let(:file) { GenericFile.create { |f| f.apply_depositor_metadata(user) } }
|
276
|
+
let(:file_id) { file.id }
|
277
|
+
let(:another_user) { FactoryGirl.create(:user) }
|
278
|
+
|
281
279
|
it "should trophy a file" do
|
282
|
-
post :toggle_trophy, {id:
|
280
|
+
post :toggle_trophy, {id: user.user_key, file_id: file_id}
|
283
281
|
json = JSON.parse(response.body)
|
284
|
-
expect(json['user_id']).to eq
|
285
|
-
expect(json['generic_file_id']).to eq
|
282
|
+
expect(json['user_id']).to eq user.id
|
283
|
+
expect(json['generic_file_id']).to eq file_id
|
286
284
|
end
|
287
285
|
it "should not trophy a file for a different user" do
|
288
|
-
post :toggle_trophy, {id:
|
286
|
+
post :toggle_trophy, {id: another_user.user_key, file_id: file_id}
|
289
287
|
expect(response).to_not be_success
|
290
288
|
end
|
291
289
|
it "should not trophy a file with no edit privs" do
|
292
|
-
|
293
|
-
|
294
|
-
post :toggle_trophy, {id: @another_user.user_key, file_id: @file_id}
|
290
|
+
sign_in another_user
|
291
|
+
post :toggle_trophy, {id: another_user.user_key, file_id: file_id}
|
295
292
|
expect(response).to_not be_success
|
296
293
|
end
|
297
294
|
end
|