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.
Files changed (244) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +1 -8
  3. data/Gemfile +3 -12
  4. data/History.md +0 -36
  5. data/LICENSE.md +14 -0
  6. data/README.md +4 -8
  7. data/SUFIA_VERSION +1 -1
  8. data/app/assets/javascripts/sufia.js +1 -17
  9. data/app/assets/javascripts/sufia/batch_edit.js +43 -28
  10. data/app/assets/javascripts/sufia/edit_metadata.js +9 -14
  11. data/app/assets/javascripts/sufia/multiForm.js +67 -0
  12. data/app/assets/javascripts/sufia/permissions.js +92 -35
  13. data/app/assets/stylesheets/sufia.css.scss +1 -6
  14. data/app/assets/stylesheets/sufia/_batch-edit.scss +0 -8
  15. data/app/assets/stylesheets/sufia/_dashboard.scss +1 -15
  16. data/app/assets/stylesheets/sufia/_file-listing.scss +1 -1
  17. data/app/assets/stylesheets/sufia/_settings.scss +0 -1
  18. data/app/controllers/concerns/sufia/batch_edits_controller_behavior.rb +3 -10
  19. data/app/controllers/concerns/sufia/breadcrumbs.rb +3 -8
  20. data/app/controllers/concerns/sufia/catalog.rb +1 -1
  21. data/app/controllers/concerns/sufia/controller.rb +3 -1
  22. data/app/controllers/concerns/sufia/downloads_controller_behavior.rb +1 -1
  23. data/app/controllers/concerns/sufia/files_controller/browse_everything.rb +1 -1
  24. data/app/controllers/concerns/sufia/files_controller_behavior.rb +16 -4
  25. data/app/controllers/concerns/sufia/homepage_controller.rb +1 -1
  26. data/app/controllers/concerns/sufia/my_controller_behavior.rb +2 -2
  27. data/app/controllers/concerns/sufia/transfers_controller_behavior.rb +3 -4
  28. data/app/controllers/concerns/sufia/users_controller_behavior.rb +2 -7
  29. data/app/controllers/my/collections_controller.rb +3 -4
  30. data/app/controllers/my/highlights_controller.rb +2 -2
  31. data/app/controllers/my/shares_controller.rb +3 -3
  32. data/app/controllers/single_use_links_controller.rb +5 -9
  33. data/app/controllers/single_use_links_viewer_controller.rb +4 -4
  34. data/app/helpers/generic_file_helper.rb +9 -0
  35. data/app/helpers/sufia/records_helper_behavior.rb +16 -0
  36. data/app/helpers/sufia/sufia_helper_behavior.rb +0 -11
  37. data/app/jobs/content_depositor_change_event_job.rb +1 -1
  38. data/app/jobs/ingest_local_file_job.rb +2 -1
  39. data/app/models/concerns/sufia/solr_document_behavior.rb +10 -10
  40. data/app/models/featured_work_list.rb +7 -9
  41. data/app/presenters/sufia/version_list_presenter.rb +15 -0
  42. data/app/presenters/sufia/version_presenter.rb +30 -0
  43. data/app/views/batch/_metadata.html.erb +51 -29
  44. data/app/views/batch/_more_metadata.html.erb +1 -1
  45. data/app/views/batch/edit.html.erb +10 -8
  46. data/app/views/batch_edits/edit.html.erb +13 -9
  47. data/app/views/collections/_edit_descriptions.html.erb +1 -1
  48. data/app/views/collections/_form.html.erb +4 -4
  49. data/app/views/collections/_form_for_select_collection.html.erb +1 -1
  50. data/app/views/collections/_show_document_list_menu.html.erb +7 -5
  51. data/app/views/collections/_show_document_list_row.html.erb +2 -2
  52. data/app/views/collections/edit.html.erb +0 -1
  53. data/app/views/collections/edit_fields/_description.html.erb +4 -0
  54. data/app/views/collections/edit_fields/_title.html.erb +3 -0
  55. data/app/views/collections/show.html.erb +0 -1
  56. data/app/views/dashboard/_index_partials/_stats.html.erb +3 -3
  57. data/app/views/generic_files/_descriptions.html.erb +9 -9
  58. data/app/views/generic_files/_field_form.html.erb +11 -25
  59. data/app/views/generic_files/_permission.html.erb +6 -4
  60. data/app/views/generic_files/_permission_form.html.erb +15 -17
  61. data/app/views/generic_files/_show_details.html.erb +1 -11
  62. data/app/views/generic_files/_versioning.html.erb +5 -5
  63. data/app/views/generic_files/edit.html.erb +5 -4
  64. data/app/views/generic_files/show.html.erb +6 -6
  65. data/app/views/homepage/_featured_fields.html.erb +2 -2
  66. data/app/views/homepage/_recent_document.html.erb +1 -1
  67. data/app/views/layouts/_head_tag_content.html.erb +0 -2
  68. data/app/views/layouts/error.html.erb +0 -1
  69. data/app/views/my/_index_partials/_default_group.html.erb +1 -1
  70. data/app/views/my/_index_partials/_list_files.html.erb +1 -1
  71. data/app/views/my/index.html.erb +2 -2
  72. data/app/views/records/_edit_field.html.erb +17 -19
  73. data/app/views/records/edit_fields/_default.html.erb +10 -12
  74. data/app/views/records/edit_fields/_description.html.erb +10 -3
  75. data/app/views/records/edit_fields/_resource_type.html.erb +4 -5
  76. data/app/views/records/edit_fields/_rights.html.erb +9 -2
  77. data/app/views/records/edit_fields/_suffix.html.erb +10 -0
  78. data/app/views/records/edit_fields/_type.html.erb +8 -2
  79. data/app/views/records/show_fields/_based_near.html.erb +1 -1
  80. data/app/views/records/show_fields/_creator.html.erb +1 -1
  81. data/app/views/records/show_fields/_language.html.erb +1 -1
  82. data/app/views/records/show_fields/_publisher.html.erb +1 -1
  83. data/app/views/records/show_fields/_resource_type.html.erb +1 -1
  84. data/app/views/records/show_fields/_subject.html.erb +1 -1
  85. data/app/views/records/show_fields/_tag.html.erb +1 -1
  86. data/app/views/single_use_links/new_download.html.erb +2 -2
  87. data/app/views/users/_profile.html.erb +2 -1
  88. data/app/views/users/_social_media_info.html.erb +20 -0
  89. data/app/views/users/_user_info.html.erb +3 -20
  90. data/app/views/users/edit.html.erb +2 -11
  91. data/app/views/users/show.html.erb +1 -1
  92. data/bin/audit_repository +1 -1
  93. data/config/initializers/sufia_events.rb +4 -4
  94. data/config/locales/sufia.en.yml +0 -5
  95. data/config/routes.rb +1 -1
  96. data/lib/generators/sufia/install_generator.rb +0 -4
  97. data/lib/generators/sufia/templates/catalog_controller.rb +59 -59
  98. data/lib/sufia.rb +1 -4
  99. data/lib/sufia/version.rb +1 -1
  100. data/spec/actors/generic_file/actor_spec.rb +67 -8
  101. data/spec/controllers/batch_controller_spec.rb +72 -86
  102. data/spec/controllers/batch_edits_controller_spec.rb +17 -19
  103. data/spec/controllers/catalog_controller_spec.rb +16 -24
  104. data/spec/controllers/collections_controller_spec.rb +47 -74
  105. data/spec/controllers/downloads_controller_spec.rb +40 -35
  106. data/spec/controllers/generic_files_controller_spec.rb +363 -428
  107. data/spec/controllers/homepage_controller_spec.rb +12 -9
  108. data/spec/controllers/mailbox_controller_spec.rb +1 -4
  109. data/spec/controllers/my/files_controller_spec.rb +0 -10
  110. data/spec/controllers/single_use_links_controller_spec.rb +28 -35
  111. data/spec/controllers/single_use_links_viewer_controller_spec.rb +27 -41
  112. data/spec/controllers/transfers_controller_spec.rb +6 -6
  113. data/spec/controllers/users_controller_spec.rb +121 -124
  114. data/spec/factories/generic_files.rb +9 -17
  115. data/spec/features/browse_dashboard_files_spec.rb +8 -10
  116. data/spec/features/browse_files_spec.rb +12 -25
  117. data/spec/features/catalog_search_spec.rb +49 -49
  118. data/spec/features/collection_spec.rb +18 -24
  119. data/spec/features/contact_form_spec.rb +26 -20
  120. data/spec/features/ingest_upload_files_spec.rb +8 -6
  121. data/spec/features/ownership_transfer_spec.rb +2 -6
  122. data/spec/features/proxy_spec.rb +1 -1
  123. data/spec/features/search_spec.rb +2 -3
  124. data/spec/features/single_use_links_spec.rb +1 -1
  125. data/spec/features/users_spec.rb +1 -1
  126. data/spec/helpers/records_helper_spec.rb +24 -10
  127. data/spec/jobs/active_fedora_pid_based_job_spec.rb +1 -5
  128. data/spec/jobs/audit_job_spec.rb +66 -21
  129. data/spec/jobs/batch_update_job_spec.rb +49 -36
  130. data/spec/jobs/content_depositor_change_event_job_spec.rb +2 -4
  131. data/spec/jobs/create_derivatives_job_spec.rb +18 -19
  132. data/spec/jobs/event_jobs_spec.rb +17 -21
  133. data/spec/jobs/import_url_job_spec.rb +1 -6
  134. data/spec/jobs/ingest_local_file_job_spec.rb +0 -4
  135. data/spec/lib/sufia/breadcrumbs_spec.rb +8 -46
  136. data/spec/lib/sufia/id_service_spec.rb +8 -3
  137. data/spec/lib/sufia/user_stat_importer_spec.rb +18 -25
  138. data/spec/lib/sufia/writable_permissions_spec.rb +0 -4
  139. data/spec/models/ability_spec.rb +25 -18
  140. data/spec/models/batch_spec.rb +16 -45
  141. data/spec/models/characterization_spec.rb +1 -1
  142. data/spec/models/checksum_audit_log_spec.rb +51 -29
  143. data/spec/models/collection_spec.rb +0 -5
  144. data/spec/models/featured_work_list_spec.rb +2 -4
  145. data/spec/models/file_content_datastream_spec.rb +27 -60
  146. data/spec/models/file_usage_spec.rb +16 -21
  147. data/spec/models/fits_datastream_spec.rb +47 -2
  148. data/spec/models/generic_file/web_form_spec.rb +1 -1
  149. data/spec/models/generic_file_spec.rb +238 -735
  150. data/spec/models/local_authority_spec.rb +8 -13
  151. data/spec/models/proxy_deposit_request_spec.rb +3 -7
  152. data/spec/models/single_use_link_spec.rb +12 -16
  153. data/spec/models/solr_document_spec.rb +1 -1
  154. data/spec/models/trophy_spec.rb +1 -3
  155. data/spec/models/user_spec.rb +47 -75
  156. data/spec/presenters/sufia/version_list_presenter_spec.rb +22 -0
  157. data/spec/presenters/sufia/version_presenter_spec.rb +51 -0
  158. data/spec/services/generic_file_audit_service_spec.rb +85 -0
  159. data/spec/services/repository_audit_service_spec.rb +18 -0
  160. data/spec/spec_helper.rb +26 -7
  161. data/spec/support/fixture_helpers.rb +2 -4
  162. data/spec/test_app_templates/lib/generators/test_app_generator.rb +0 -4
  163. data/spec/views/batch/edit.html.erb_spec.rb +17 -7
  164. data/spec/views/catalog/index.html.erb_spec.rb +8 -6
  165. data/spec/views/collections/_form.html.erb_spec.rb +4 -2
  166. data/spec/views/collections/_show_document_list.erb_spec.rb +31 -0
  167. data/spec/views/dashboard/index_spec.rb +2 -2
  168. data/spec/views/generic_file/edit.html.erb_spec.rb +20 -6
  169. data/spec/views/generic_file/show.html.erb_spec.rb +3 -3
  170. data/spec/views/users/show.html.erb_spec.rb +1 -1
  171. data/sufia-models/app/actors/sufia/generic_file/actor.rb +8 -10
  172. data/sufia-models/app/jobs/active_fedora_pid_based_job.rb +2 -3
  173. data/sufia-models/app/jobs/audit_job.rb +46 -32
  174. data/sufia-models/app/jobs/batch_update_job.rb +9 -8
  175. data/sufia-models/app/jobs/import_url_job.rb +2 -2
  176. data/sufia-models/app/models/batch.rb +11 -12
  177. data/sufia-models/app/models/checksum_audit_log.rb +12 -10
  178. data/sufia-models/app/models/concerns/sufia/ability.rb +4 -6
  179. data/sufia-models/app/models/concerns/sufia/collection.rb +4 -5
  180. data/sufia-models/app/models/concerns/sufia/generic_file.rb +3 -86
  181. data/sufia-models/app/models/concerns/sufia/generic_file/batches.rb +29 -0
  182. data/sufia-models/app/models/concerns/sufia/generic_file/characterization.rb +3 -3
  183. data/sufia-models/app/models/concerns/sufia/generic_file/content.rb +13 -0
  184. data/sufia-models/app/models/concerns/sufia/generic_file/derivatives.rb +5 -5
  185. data/sufia-models/app/models/concerns/sufia/generic_file/export.rb +4 -0
  186. data/sufia-models/app/models/concerns/sufia/generic_file/full_text_indexing.rb +2 -2
  187. data/sufia-models/app/models/concerns/sufia/generic_file/indexing.rb +23 -0
  188. data/sufia-models/app/models/concerns/sufia/generic_file/metadata.rb +80 -11
  189. data/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb +12 -3
  190. data/sufia-models/app/models/concerns/sufia/generic_file/versions.rb +4 -4
  191. data/sufia-models/app/models/concerns/sufia/generic_file/web_form.rb +14 -6
  192. data/sufia-models/app/models/concerns/sufia/model_methods.rb +11 -9
  193. data/sufia-models/app/models/concerns/sufia/user.rb +11 -33
  194. data/sufia-models/app/models/datastreams/file_content_datastream.rb +1 -1
  195. data/sufia-models/app/models/datastreams/fits_datastream.rb +1 -1
  196. data/sufia-models/app/models/file_usage.rb +3 -3
  197. data/sufia-models/app/models/local_authority.rb +2 -2
  198. data/sufia-models/app/models/proxy_deposit_request.rb +1 -1
  199. data/sufia-models/app/services/sufia/generic_file_audit_service.rb +83 -0
  200. data/sufia-models/app/services/sufia/id_service.rb +5 -5
  201. data/sufia-models/app/services/sufia/noid.rb +10 -7
  202. data/sufia-models/app/services/sufia/repository_audit_service.rb +9 -0
  203. data/sufia-models/lib/generators/sufia/models/cached_stats_generator.rb +47 -3
  204. data/sufia-models/lib/generators/sufia/models/install_generator.rb +31 -11
  205. data/sufia-models/lib/generators/sufia/models/proxies_generator.rb +31 -2
  206. data/sufia-models/lib/generators/sufia/models/templates/config/sufia.rb +10 -0
  207. data/sufia-models/lib/generators/sufia/models/upgrade400_generator.rb +33 -2
  208. data/sufia-models/lib/sufia/models/engine.rb +13 -4
  209. data/sufia-models/lib/sufia/models/file_content/versions.rb +9 -11
  210. data/sufia-models/lib/sufia/models/stats/user_stat_importer.rb +5 -9
  211. data/sufia-models/lib/sufia/models/version.rb +1 -1
  212. data/sufia-models/lib/sufia/permissions/writable.rb +34 -16
  213. data/sufia-models/sufia-models.gemspec +4 -2
  214. data/sufia.gemspec +4 -5
  215. data/tasks/jetty.rake +0 -26
  216. data/tasks/sufia-dev.rake +14 -2
  217. metadata +49 -64
  218. data/LICENSE +0 -15
  219. data/app/assets/images/orcid.png +0 -0
  220. data/app/assets/javascripts/sufia/manage_repeating_fields.js +0 -74
  221. data/app/assets/stylesheets/sufia/_multi_value_fields.css.scss +0 -67
  222. data/app/inputs/multi_value_input.rb +0 -84
  223. data/app/views/records/_rights_modal.html.erb +0 -1
  224. data/config/initializers/simple_form.rb +0 -167
  225. data/config/initializers/simple_form_bootstrap.rb +0 -137
  226. data/config/locales/simple_form.en.yml +0 -31
  227. data/fedora_conf/conf/development/fedora.fcfg +0 -946
  228. data/fedora_conf/conf/test/fedora.fcfg +0 -946
  229. data/spec/models/generic_file/reload_on_save_spec.rb +0 -25
  230. data/spec/models/generic_file_rdf_datastream_spec.rb +0 -12
  231. data/spec/models/properties_datastream_spec.rb +0 -41
  232. data/spec/views/generic_file/_permission_form.html.erb_spec.rb +0 -19
  233. data/sufia-models/app/models/concerns/sufia/generic_file/audit.rb +0 -116
  234. data/sufia-models/app/models/concerns/sufia/generic_file/reload_on_save.rb +0 -18
  235. data/sufia-models/app/models/concerns/sufia/properties_datastream_behavior.rb +0 -32
  236. data/sufia-models/app/models/datastreams/batch_rdf_datastream.rb +0 -6
  237. data/sufia-models/app/models/datastreams/generic_file_rdf_datastream.rb +0 -69
  238. data/sufia-models/app/models/datastreams/paranoid_rights_datastream.rb +0 -22
  239. data/sufia-models/app/models/datastreams/properties_datastream.rb +0 -4
  240. data/sufia-models/app/models/sufia/orcid_validator.rb +0 -8
  241. data/sufia-models/lib/generators/sufia/models/abstract_migration_generator.rb +0 -30
  242. data/sufia-models/lib/generators/sufia/models/orcid_field_generator.rb +0 -19
  243. data/sufia-models/lib/generators/sufia/models/templates/migrations/add_orcid_to_users.rb +0 -5
  244. 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 :all do
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['desc_metadata__title_tesim'][0]}
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
- after(:each) do
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 |f|
7
- f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
8
- f.apply_depositor_metadata(user)
9
- f.save
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
- before do
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
- @now = DateTime.now
31
- allow(DateTime).to receive(:now).and_return(@now)
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
- it "gets the download link" do
37
- get 'new_download', id: file.pid
38
- expect(response).to be_success
39
- expect(assigns[:link]).to eq @routes.url_helpers.download_single_use_link_path(@hash)
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
- it "gets the show link" do
43
- get 'new_show', id: file.pid
44
- expect(response).to be_success
45
- expect(assigns[:link]).to eq @routes.url_helpers.show_single_use_link_path(@hash)
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.pid
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.pid
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.pid
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.pid
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, :type => :controller do
4
- before(:all) do
5
- @user = FactoryGirl.find_or_create(:jill)
6
- @file = GenericFile.new
7
- @file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
8
- @file.apply_depositor_metadata(@user)
9
- @file.save
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: @file.pid, path: Sufia::Engine.routes.url_helpers.generic_file_path(id: @file)
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: @file.pid, path: Sufia::Engine.routes.url_helpers.download_path(id: @file)
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
- allow(controller).to receive(:render)
48
- expected_content = ActiveFedora::Base.find(@file.pid, cast: true).content.content
49
- expect(controller).to receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
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].pid).to eq(@file.pid)
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.pid)
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.pid)
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.pid)
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.id, proxy_deposit_request: {transfer_to: another_user.user_key}
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.pid)
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.id, proxy_deposit_request: {transfer_to: 'foo' }
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
- @user = FactoryGirl.find_or_create(:jill)
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: @user.user_key
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(:user) { @user }
27
- let(:file1) { GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save! } }
28
- let(:file2) { GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save! } }
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
- before do
44
- @u1 = FactoryGirl.find_or_create(:archivist)
45
- @u2 = FactoryGirl.find_or_create(:curator)
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(@u1, @u2)
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(@u1.email, @u2.email)
60
- expect(json.map{|u| u['text']}).to include(@u1.email, @u2.email)
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: @u1.email
66
- expect(assigns[:users]).to include(@u1)
67
- expect(assigns[:users]).to_not include(@u2)
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
- @u1.display_name = "Dr. Curator"
72
- @u1.save
73
- @u2.display_name = "Jr. Architect"
74
- @u2.save
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: @u1.display_name
77
- expect(assigns[:users]).to include(@u1)
78
- expect(assigns[:users]).to_not include(@u2)
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
- @u1.display_name = nil
81
- @u1.save
82
- @u2.display_name = nil
83
- @u2.save
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.find_or_create(:jill)
87
- allow(controller).to receive(:base_query).and_return(['email == "jilluser@example.com"'])
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(@u1, @u2)
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: @user.user_key
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
- it "redirects to show profile when user attempts to edit another profile" do
103
- get :edit, id: @another_user.user_key
104
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@another_user.to_param))
105
- expect(flash[:alert]).to include("Permission denied: cannot access this page.")
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(:user) { @user }
109
- let(:file1) { GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save! } }
110
- let(:file2) { GenericFile.new.tap { |f| f.apply_depositor_metadata(user); f.save! } }
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: @user.user_key
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
- it "should not allow other users to update" do
126
- post :update, id: @another_user.user_key, user: { avatar: nil }
127
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@another_user.to_param))
128
- expect(flash[:alert]).to include("Permission denied: cannot access this page.")
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(@user.avatar?).to be false
141
+ expect(user.avatar?).to be false
132
142
  s1 = double('one')
133
- expect(UserEditProfileEventJob).to receive(:new).with(@user.user_key).and_return(s1)
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: @user.user_key, user: { avatar: f }
137
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@user.to_param))
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(@user.user_key).avatar?).to be true
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: @user.user_key, user: { avatar: f }
145
- expect(response).to redirect_to(@routes.url_helpers.edit_profile_path(@user.to_param))
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: @user.user_key, user: { avatar: f }
152
- expect(response).to redirect_to(@routes.url_helpers.edit_profile_path(@user.to_param))
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
- @user.avatar = f
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(@user.user_key).and_return(s1)
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: @user.user_key, user: { remove_avatar: 'true' }
166
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@user.to_param))
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(@user.user_key).avatar?).to be false
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(@user.user_key).and_return(s1)
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.and_call_original
176
- post :update, id: @user.user_key, user: { update_directory: 'true' }
177
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@user.to_param))
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(@user.twitter_handle).to be_blank
183
- expect(@user.facebook_handle).to be_blank
184
- expect(@user.googleplus_handle).to be_blank
185
- expect(@user.linkedin_handle).to be_blank
186
- expect(@user.orcid).to be_blank
187
- post :update, id: @user.user_key, user: { twitter_handle: 'twit', facebook_handle: 'face', googleplus_handle: 'goo', linkedin_handle: "link", orcid: '0000-0000-1111-2222' }
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(@user.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(:user) { @user }
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
- after(:all) do
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(@user.following?(@another_user)).to be false
225
+ expect(user.following?(another_user)).to be false
226
226
  s1 = double('one')
227
- expect(UserFollowEventJob).to receive(:new).with(@user.user_key, @another_user.user_key).and_return(s1)
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: @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}")
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(@another_user).and_return(true)
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: @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}")
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: @user.user_key
243
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@user.to_param))
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(@another_user).and_return(true)
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(@user.user_key, @another_user.user_key).and_return(s1)
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: @another_user.user_key
254
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@another_user.to_param))
255
- expect(flash[:notice]).to include("You are no longer following #{@another_user.user_key}")
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(@user).to receive(:following?).with(@another_user).and_return(false)
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: @another_user.user_key
261
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@another_user.to_param))
262
- expect(flash[:notice]).to include("You are no longer following #{@another_user.user_key}")
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: @user.user_key
267
- expect(response).to redirect_to(@routes.url_helpers.profile_path(@user.to_param))
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
- before do
273
- @file = GenericFile.new()
274
- @file.apply_depositor_metadata(@user)
275
- @file.save
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: @user.user_key, file_id: @file_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 @user.id
285
- expect(json['generic_file_id']).to eq @file_id
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: @another_user.user_key, file_id: @file_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
- sign_out @user
293
- sign_in @another_user
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