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
@@ -1,22 +1,15 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe CollectionsController, :type => :controller do
4
- before(:each) { @routes = Hydra::Collections::Engine.routes }
3
+ describe CollectionsController do
4
+ routes { Hydra::Collections::Engine.routes }
5
5
  before do
6
- allow(controller).to receive(:has_access?).and_return(true)
7
6
  allow_any_instance_of(User).to receive(:groups).and_return([])
8
7
  end
9
8
 
10
9
  let(:user) { FactoryGirl.create(:user) }
11
10
 
12
- after (:all) do
13
- Collection.destroy_all
14
- GenericFile.destroy_all
15
- User.destroy_all
16
- end
17
-
18
11
  describe '#new' do
19
- before do
12
+ before do
20
13
  sign_in user
21
14
  end
22
15
 
@@ -27,16 +20,16 @@ describe CollectionsController, :type => :controller do
27
20
  end
28
21
 
29
22
  describe '#create' do
30
- before do
23
+ before do
31
24
  sign_in user
32
25
  end
33
26
 
34
27
  it "should create a Collection" do
35
- expect(controller).to receive(:has_access?).and_return(true)
36
- old_count = Collection.count
37
- post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
38
- expect(Collection.count).to eq(old_count+1)
28
+ expect {
29
+ post :create, collection: {title: "My First Collection ", description: "The Description\r\n\r\nand more"}
30
+ }.to change{ Collection.count }.by(1)
39
31
  end
32
+
40
33
  it "should create a Collection with files I can access" do
41
34
  @asset1 = GenericFile.new(title: ["First of the Assets"])
42
35
  @asset1.apply_depositor_metadata(user.user_key)
@@ -47,18 +40,12 @@ describe CollectionsController, :type => :controller do
47
40
  @asset3 = GenericFile.new(title: ["Third of the Assets"], depositor:'abc')
48
41
  @asset3.apply_depositor_metadata('abc')
49
42
  @asset3.save
50
- expect(controller).to receive(:has_access?).and_return(true)
51
- old_count = Collection.count
52
- post :create, collection: { title: "My own Collection", description: "The Description\r\n\r\nand more" },
53
- batch_document_ids: [@asset1.id, @asset2.id, @asset3.id]
54
- expect(Collection.count).to eq(old_count+1)
43
+ expect {
44
+ post :create, collection: { title: "My own Collection", description: "The Description\r\n\r\nand more" },
45
+ batch_document_ids: [@asset1.id, @asset2.id, @asset3.id]
46
+ }.to change{ Collection.count }.by(1)
55
47
  collection = assigns(:collection)
56
- expect(collection.members).to include (@asset1)
57
- expect(collection.members).to include (@asset2)
58
- expect(collection.members.to_a).not_to include (@asset3) # .to_a to avoid a call to any? which doesn't exist in AF::HABTM
59
- @asset1.destroy
60
- @asset2.destroy
61
- @asset3.destroy
48
+ expect(collection.members).to match_array [@asset1, @asset2]
62
49
  end
63
50
 
64
51
  it "should add docs to collection if batch ids provided and add the collection id to the documents int he colledction" do
@@ -67,22 +54,22 @@ describe CollectionsController, :type => :controller do
67
54
  @asset1.save
68
55
  post :create, batch_document_ids: [@asset1.id],
69
56
  collection: { title: "My Secong Collection ", description: "The Description\r\n\r\nand more" }
70
- expect(assigns[:collection].members).to eq([@asset1])
57
+ expect(assigns[:collection].members).to eq [@asset1]
71
58
  asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset1.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
72
- expect(asset_results["response"]["numFound"]).to eq(1)
59
+ expect(asset_results["response"]["numFound"]).to eq 1
73
60
  doc = asset_results["response"]["docs"].first
74
- expect(doc["id"]).to eq(@asset1.id)
75
- afterupdate = GenericFile.find(@asset1.pid)
76
- expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
61
+ expect(doc["id"]).to eq @asset1.id
62
+ afterupdate = GenericFile.find(@asset1.id)
63
+ expect(doc[Solrizer.solr_name(:collection)]).to eq afterupdate.to_solr[Solrizer.solr_name(:collection)]
77
64
  end
78
65
 
79
66
  end
80
67
 
81
68
  describe "#update" do
82
69
  before do
83
- @collection = Collection.new(title: "Collection Title")
84
- @collection.apply_depositor_metadata(user.user_key)
85
- @collection.save
70
+ @collection = Collection.create(title: "Collection Title") do |collection|
71
+ collection.apply_depositor_metadata(user.user_key)
72
+ end
86
73
  @asset1 = GenericFile.new(title: ["First of the Assets"])
87
74
  @asset1.apply_depositor_metadata(user.user_key)
88
75
  @asset1.save
@@ -94,29 +81,23 @@ describe CollectionsController, :type => :controller do
94
81
  @asset3.save
95
82
  sign_in user
96
83
  end
97
- after do
98
- @collection.destroy
99
- @asset1.destroy
100
- @asset2.destroy
101
- @asset3.destroy
102
- end
103
84
 
104
85
  it "should set collection on members" do
105
- put :update, id: @collection.id, collection: {members:"add"}, batch_document_ids: [@asset3.pid, @asset1.pid, @asset2.pid]
106
- expect(response).to redirect_to Hydra::Collections::Engine.routes.url_helpers.collection_path(@collection.noid)
107
- expect(assigns[:collection].members.map{|m| m.pid}.sort).to eq([@asset2, @asset3, @asset1].map {|m| m.pid}.sort)
108
- asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
109
- expect(asset_results["response"]["numFound"]).to eq(1)
86
+ put :update, id: @collection, collection: {members:"add"}, batch_document_ids: [@asset3.id, @asset1.id, @asset2.id]
87
+ expect(response).to redirect_to routes.url_helpers.collection_path(@collection.noid)
88
+ expect(assigns[:collection].members).to match_array [@asset2, @asset3, @asset1]
89
+ asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
90
+ expect(asset_results["response"]["numFound"]).to eq 1
110
91
  doc = asset_results["response"]["docs"].first
111
- expect(doc["id"]).to eq(@asset2.id)
112
- afterupdate = GenericFile.find(@asset2.pid)
113
- expect(doc[Solrizer.solr_name(:collection)]).to eq(afterupdate.to_solr[Solrizer.solr_name(:collection)])
114
- put :update, id: @collection.id, collection: {members:"remove"}, batch_document_ids: [@asset2]
115
- asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.pid}\""],fl:['id',Solrizer.solr_name(:collection)]}
116
- expect(asset_results["response"]["numFound"]).to eq(1)
92
+ expect(doc["id"]).to eq @asset2.id
93
+ afterupdate = GenericFile.find(@asset2.id)
94
+ expect(doc[Solrizer.solr_name(:collection)]).to eq afterupdate.to_solr[Solrizer.solr_name(:collection)]
95
+ put :update, id: @collection, collection: {members:"remove"}, batch_document_ids: [@asset2]
96
+ asset_results = ActiveFedora::SolrService.instance.conn.get "select", params:{fq:["id:\"#{@asset2.id}\""],fl:['id',Solrizer.solr_name(:collection)]}
97
+ expect(asset_results["response"]["numFound"]).to eq 1
117
98
  doc = asset_results["response"]["docs"].first
118
- expect(doc["id"]).to eq(@asset2.pid)
119
- afterupdate = GenericFile.find(@asset2.pid)
99
+ expect(doc["id"]).to eq @asset2.id
100
+ afterupdate = GenericFile.find(@asset2.id)
120
101
  expect(doc[Solrizer.solr_name(:collection)]).to be_nil
121
102
  end
122
103
  end
@@ -125,47 +106,39 @@ describe CollectionsController, :type => :controller do
125
106
  before do
126
107
  @asset1 = GenericFile.new(title: ["First of the Assets"])
127
108
  @asset1.apply_depositor_metadata(user.user_key)
128
- @asset1.save!
129
109
  @asset2 = GenericFile.new(title: ["Second of the Assets"], depositor:user.user_key)
130
110
  @asset2.apply_depositor_metadata(user.user_key)
131
- @asset2.save!
132
111
  @asset3 = GenericFile.new(title: ["Third of the Assets"], depositor:user.user_key)
133
112
  @asset3.apply_depositor_metadata(user.user_key)
134
- @asset3.save!
135
113
  @asset4 = GenericFile.new(title: ["Third of the Assets"], depositor:user.user_key)
136
114
  @asset4.apply_depositor_metadata(user.user_key)
137
- @asset4.save!
138
- @collection = Collection.new
139
- @collection.title = "My collection"
140
- @collection.description = "My incredibly detailed description of the collection"
141
- @collection.apply_depositor_metadata(user.user_key)
142
- @collection.members = [@asset1,@asset2,@asset3]
143
- @collection.save!
115
+ @collection = Collection.create(title: "My collection",
116
+ description: "My incredibly detailed description of the collection",
117
+ members: [@asset1,@asset2,@asset3]) do |collection|
118
+ collection.apply_depositor_metadata(user)
119
+ end
144
120
  allow(controller).to receive(:authorize!).and_return(true)
145
- allow(controller).to receive(:apply_gated_search)
146
121
  end
147
122
  context "when signed in" do
148
- before do
123
+ before do
149
124
  sign_in user
150
125
  end
151
126
 
152
127
  it "should return the collection and its members" do
153
- get :show, id: @collection.id
128
+ get :show, id: @collection
154
129
  expect(response).to be_successful
155
- expect(assigns[:collection].title).to eq(@collection.title)
156
- ids = assigns[:member_docs].map(&:id)
157
- expect(ids).to include @asset1.pid, @asset2.pid, @asset3.pid
158
- expect(ids).to_not include @asset4.pid
130
+ expect(assigns[:collection].title).to eq @collection.title
131
+ expect(assigns[:member_docs].map(&:id)).to match_array [@asset1, @asset2, @asset3].map(&:id)
159
132
  end
160
133
  it "should set the breadcrumb trail" do
161
134
  expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
162
- get :show, id: @collection.id
135
+ get :show, id: @collection
163
136
  end
164
137
  end
165
138
  context "not signed in" do
166
139
  it "should not show me files in the collection" do
167
- get :show, id: @collection.id
168
- expect(assigns[:member_docs].count).to eq(0)
140
+ get :show, id: @collection
141
+ expect(assigns[:member_docs].count).to eq 0
169
142
  end
170
143
  end
171
144
  end
@@ -178,7 +151,7 @@ describe CollectionsController, :type => :controller do
178
151
  sign_in user
179
152
  end
180
153
  it "should not show flash" do
181
- get :edit, id: @collection.id
154
+ get :edit, id: @collection
182
155
  expect(flash[:notice]).to be_nil
183
156
  end
184
157
  end
@@ -3,56 +3,63 @@ require 'spec_helper'
3
3
  describe DownloadsController, :type => :controller do
4
4
 
5
5
  describe "with a file" do
6
- before do
7
- @f = GenericFile.new(pid: 'sufia:test1')
8
- @f.apply_depositor_metadata('archivist1@example.com')
9
- @f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
10
- @f.save!
6
+ let(:depositor) { FactoryGirl.find_or_create(:archivist) }
7
+ let(:file) do
8
+ GenericFile.new.tap do |f|
9
+ f.apply_depositor_metadata(depositor.user_key)
10
+ f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
11
+ f.save!
12
+ end
11
13
  end
12
14
 
13
- after do
14
- @f.delete
15
- end
15
+ before { allow_any_instance_of(User).to receive(:groups).and_return([]) }
16
16
 
17
17
  describe "when logged in as reader" do
18
18
  before do
19
- sign_in FactoryGirl.find_or_create(:archivist)
20
- allow_any_instance_of(User).to receive(:groups).and_return([])
21
- allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
19
+ sign_in depositor
22
20
  end
23
21
  describe "show" do
24
- it "should default to returning configured default download" do
25
- expect(DownloadsController.default_content_dsid).to eq("content")
22
+ before do
26
23
  allow(controller).to receive(:render) # send_data calls render internally
27
- expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
24
+ end
25
+ let(:object) { ActiveFedora::Base.find(file.id) }
26
+ let(:expected_datastream) { object.content }
27
+ let(:expected_content) { expected_datastream.content }
28
+
29
+ it "should default to returning configured default download" do
30
+ expect(DownloadsController.default_content_dsid).to eq "content"
28
31
  expect(controller).to receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
29
- get "show", id: "test1"
30
- expect(response.body).to eq(expected_content)
32
+ get "show", id: file
31
33
  expect(response).to be_success
34
+ expect(response.body).to eq expected_content
32
35
  end
33
- it "should return requested datastreams" do
34
- allow(controller).to receive(:render) # send_data calls render internally
35
- expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).descMetadata.content
36
- expect(controller).to receive(:send_file_headers!).with(filename: 'descMetadata', disposition: 'inline', type: 'application/n-triples')
37
- get "show", id: "test1", datastream_id: "descMetadata"
38
- expect(response.body).to eq(expected_content)
39
- expect(response).to be_success
36
+
37
+ context "when grabbing the characterization datastream" do
38
+ let(:expected_content) { "<?xml version=\"1.0\"?>\n<fits stuff=\"yep\"/>" }
39
+ before do
40
+ file.characterization.content = expected_content
41
+ file.save!
42
+ end
43
+
44
+ it "should return requested datastreams" do
45
+ get "show", id: file, datastream_id: "characterization"
46
+ expect(response).to be_success
47
+ expect(response.body).to eq expected_content
48
+ end
40
49
  end
50
+
41
51
  it "should support setting disposition to inline" do
42
- allow(controller).to receive(:render) # send_data calls render internally
43
- expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
44
52
  expect(controller).to receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
45
- get "show", id: "test1", disposition: "inline"
46
- expect(response.body).to eq(expected_content)
53
+ get "show", id: file, disposition: "inline"
54
+ expect(response.body).to eq expected_content
47
55
  expect(response).to be_success
48
56
  end
49
57
 
50
58
  it "should allow you to specify filename for download" do
51
- allow(controller).to receive(:render) # send_data calls render internally
52
- expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
53
59
  expect(controller).to receive(:send_file_headers!).with({filename: 'my%20dog.png', disposition: 'inline', type: 'image/png' })
54
- get "show", id: "test1", "filename" => "my%20dog.png"
55
- expect(response.body).to eq(expected_content)
60
+ get "show", id: file, "filename" => "my%20dog.png"
61
+ expect(response.body).to eq expected_content
62
+ expect(response).to be_success
56
63
  end
57
64
  end
58
65
  end
@@ -60,15 +67,13 @@ describe DownloadsController, :type => :controller do
60
67
  describe "when not logged in as reader" do
61
68
  before do
62
69
  sign_in FactoryGirl.find_or_create(:jill)
63
- allow_any_instance_of(User).to receive(:groups).and_return([])
64
- allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
65
70
  end
66
71
 
67
72
  describe "show" do
68
73
  it "should deny access" do
69
- get "show", id: "test1"
74
+ get "show", id: file
70
75
  expect(response).to redirect_to root_path
71
- expect(flash[:alert]).to eq('You are not authorized to access this page.')
76
+ expect(flash[:alert]).to eq 'You are not authorized to access this page.'
72
77
  end
73
78
  end
74
79
  end
@@ -1,295 +1,272 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe GenericFilesController, :type => :controller do
3
+ describe GenericFilesController do
4
+ let(:user) { FactoryGirl.find_or_create(:jill) }
4
5
  before do
5
6
  allow(controller).to receive(:has_access?).and_return(true)
6
- @user = FactoryGirl.find_or_create(:jill)
7
- sign_in @user
7
+ sign_in user
8
8
  allow_any_instance_of(User).to receive(:groups).and_return([])
9
9
  allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
10
+ allow_any_instance_of(GenericFile).to receive(:characterize)
10
11
  end
11
12
 
12
13
  describe "#create" do
13
- before do
14
- @file_count = GenericFile.count
15
- @mock = GenericFile.new({ pid: 'test:123' })
16
- allow(GenericFile).to receive(:new).and_return(@mock)
17
- end
14
+ context "when uploading a file" do
15
+ let(:mock) { GenericFile.new(id: 'test123') }
16
+ let(:batch) { Batch.create }
17
+ let(:batch_id) { batch.id }
18
+ let(:file) { fixture_file_upload('/world.png','image/png') }
18
19
 
19
- after do
20
- begin
21
- allow(GenericFile).to receive(:new).and_call_original
22
- rescue RSpec::Mocks::MockExpectationError => e
20
+ before do
21
+ allow(GenericFile).to receive(:new).and_return(mock)
23
22
  end
24
- Batch.find("sample:batch_id").delete rescue
25
- @mock.delete unless @mock.inner_object.class == ActiveFedora::UnsavedDigitalObject
26
- end
27
-
28
- it "should record on_behalf_of" do
29
- file = fixture_file_upload('/world.png','image/png')
30
- xhr :post, :create, files: [file], Filename: 'The world', batch_id: 'sample:batch_id', on_behalf_of: 'carolyn', terms_of_service: '1'
31
- expect(response).to be_success
32
- saved_file = GenericFile.find('test:123')
33
- expect(saved_file.on_behalf_of).to eq('carolyn')
34
- end
35
23
 
36
- it "should render error the file wasn't actually a file" do
37
- file = 'hello'
38
- xhr :post, :create, files: [file], Filename: "The World", batch_id: 'sample:batch_id', permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
39
- expect(response.status).to eq(422)
40
- expect(JSON.parse(response.body).first['error']).to match(/no file for upload/i)
41
- end
24
+ it "should record on_behalf_of" do
25
+ file = fixture_file_upload('/world.png','image/png')
26
+ xhr :post, :create, files: [file], Filename: 'The world', batch_id: batch_id, on_behalf_of: 'carolyn', terms_of_service: '1'
27
+ expect(response).to be_success
28
+ saved_file = GenericFile.find('test123')
29
+ expect(saved_file.on_behalf_of).to eq 'carolyn'
30
+ end
42
31
 
43
- it "spawns a content deposit event job" do
44
- file = fixture_file_upload('/world.png','image/png')
45
- s1 = double('one')
46
- allow(ContentDepositEventJob).to receive(:new).with('test:123', 'jilluser@example.com').and_return(s1)
47
- expect(Sufia.queue).to receive(:push).with(s1).once
32
+ context "when the file submitted isn't a file" do
33
+ let(:file) { 'hello' }
48
34
 
49
- s2 = double('one')
50
- allow(CharacterizeJob).to receive(:new).with('test:123').and_return(s2)
51
- expect(Sufia.queue).to receive(:push).with(s2).once
52
- xhr :post, :create, files: [file], 'Filename' => 'The world', batch_id: 'sample:batch_id', permission: {group: { public: 'read' } }, terms_of_service: '1'
53
- expect(flash[:error]).to be_nil
54
- end
35
+ it "should render 422 error" do
36
+ xhr :post, :create, files: [file], Filename: "The World", batch_id: 'sample_batch_id', permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
37
+ expect(response.status).to eq 422
38
+ expect(JSON.parse(response.body).first['error']).to match(/no file for upload/i)
39
+ end
40
+ end
55
41
 
56
- it "displays a flash error when file has a virus" do
57
- file = fixture_file_upload('/world.png', 'image/png')
58
- expect(Sufia::GenericFile::Actor).to receive(:virus_check).with(file.path).and_raise(Sufia::VirusFoundError.new('A virus was found'))
59
- xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
60
- expect(flash[:error]).not_to be_blank
61
- expect(flash[:error]).to include('A virus was found')
62
- end
42
+ context "when everything is perfect" do
43
+ it "spawns a content deposit event job" do
44
+ expect_any_instance_of(Sufia::GenericFile::Actor).to receive(:create_content).with(file, 'world.png', 'content').and_return(true)
45
+ xhr :post, :create, files: [file], 'Filename' => 'The world', batch_id: batch_id, permission: {group: { public: 'read' } }, terms_of_service: '1'
46
+ expect(flash[:error]).to be_nil
47
+ end
63
48
 
64
- it "should create and save a file asset from the given params" do
65
- date_today = Date.today
66
- allow(Date).to receive(:today).and_return(date_today)
67
- file = fixture_file_upload('/world.png','image/png')
68
- xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
69
- expect(response).to be_success
70
- expect(GenericFile.count).to eq(@file_count + 1)
49
+ it "should create and save a file asset from the given params" do
50
+ # Now expecting iso8601 dates?
51
+ date_today = Time.now.utc.iso8601
52
+ allow(Date).to receive(:today).and_return(date_today)
53
+ expect {
54
+ xhr :post, :create, files: [file], Filename: "The world", batch_id: batch_id,
55
+ permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
56
+ }.to change { GenericFile.count }.by(1)
57
+ expect(response).to be_success
71
58
 
72
- saved_file = GenericFile.find('test:123')
59
+ saved_file = GenericFile.find('test123')
73
60
 
74
- # This is confirming that the correct file was attached
75
- expect(saved_file.label).to eq('world.png')
76
- expect(saved_file.content.checksum).to eq('f794b23c0c6fe1083d0ca8b58261a078cd968967')
77
- expect(saved_file.content.dsChecksumValid).to be true
61
+ # This is confirming that the correct file was attached
62
+ expect(saved_file.label).to eq 'world.png'
63
+ file.rewind
64
+ expect(saved_file.content.content).to eq (file.read)
65
+ # Confirming that date_uploaded and date_modified were set
66
+ expect(saved_file.date_uploaded).to eq date_today
67
+ expect(saved_file.date_modified).to eq date_today
68
+ end
78
69
 
79
- # Confirming that date_uploaded and date_modified were set
80
- expect(saved_file.date_uploaded).to eq(date_today)
81
- expect(saved_file.date_modified).to eq(date_today)
82
- end
70
+ it "should record what user created the first version of content" do
71
+ xhr :post, :create, files: [file], Filename: "The world", batch_id: batch_id, permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
72
+ expect(VersionCommitter.pluck(:committer_login).last).to eq user.user_key
73
+ end
83
74
 
84
- it "should record what user created the first version of content" do
85
- file = fixture_file_upload('/world.png','image/png')
86
- xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
87
- saved_file = GenericFile.find('test:123')
88
- version = saved_file.content.latest_version
89
- expect(version.versionID).to eq("content.0")
90
- expect(saved_file.content.version_committer(version)).to eq(@user.user_key)
91
- end
75
+ it "should set the depositor id" do
76
+ xhr :post, :create, files: [file], Filename: "The world", batch_id: batch_id, permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
77
+ expect(response).to be_success
92
78
 
93
- it "should create batch associations from batch_id" do
94
- allow(Sufia.config).to receive(:id_namespace).and_return('sample')
95
- file = fixture_file_upload('/world.png','image/png')
96
- allow(controller).to receive(:add_posted_blob_to_asset)
97
- xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
98
- allow(GenericFile).to receive(:new).and_call_original
99
- expect {Batch.find("sample:batch_id")}.to raise_error(ActiveFedora::ObjectNotFoundError) # The controller shouldn't actually save the Batch, but it should write the batch id to the files.
100
- batch = Batch.create(pid: "sample:batch_id")
101
- expect(batch.generic_files.first.pid).to eq("test:123")
102
- end
103
- it "should set the depositor id" do
104
- file = fixture_file_upload('/world.png','image/png')
105
- xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
106
- expect(response).to be_success
79
+ saved_file = GenericFile.find('test123')
80
+ # This is confirming that apply_depositor_metadata recorded the depositor
81
+ expect(saved_file.depositor).to eq 'jilluser@example.com'
82
+ expect(saved_file.to_solr['depositor_tesim']).to eq ['jilluser@example.com']
83
+ end
84
+ end
107
85
 
108
- saved_file = GenericFile.find('test:123')
109
- # This is confirming that apply_depositor_metadata recorded the depositor
110
- #TODO make sure this is moved to scholarsphere:
111
- #saved_file.properties.depositor.should == ['jilluser']
112
- expect(saved_file.properties.depositor).to eq(['jilluser@example.com'])
113
- #TODO make sure this is moved to scholarsphere:
114
- #saved_file.depositor.should == 'jilluser'
115
- expect(saved_file.depositor).to eq('jilluser@example.com')
116
- expect(saved_file.properties.to_solr.keys).to include('depositor_tesim')
117
- #TODO make sure this is moved to scholarsphere:
118
- #saved_file.properties.to_solr['depositor_t'].should == ['jilluser']
119
- expect(saved_file.properties.to_solr['depositor_tesim']).to eq(['jilluser@example.com'])
120
- expect(saved_file.to_solr.keys).to include('depositor_tesim')
121
- expect(saved_file.to_solr['depositor_tesim']).to eq(['jilluser@example.com'])
122
- end
86
+ context "when the file has a virus" do
87
+ it "displays a flash error when file has a virus" do
88
+ expect(Sufia::GenericFile::Actor).to receive(:virus_check).with(file.path).and_raise(Sufia::VirusFoundError.new('A virus was found'))
89
+ xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample_batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
90
+ expect(flash[:error]).not_to be_blank
91
+ expect(flash[:error]).to include('A virus was found')
92
+ end
93
+ end
123
94
 
124
- it "should error out of create and save after on continuos rsolr error" do
125
- allow_any_instance_of(GenericFile).to receive(:save).and_raise(RSolr::Error::Http.new({},{}))
95
+ context "when solr continuously has errors" do
96
+ it "should error out of create and save after on continuos rsolr error" do
97
+ allow_any_instance_of(GenericFile).to receive(:save).and_raise(RSolr::Error::Http.new({},{}))
126
98
 
127
- file = fixture_file_upload('/world.png','image/png')
128
- xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
129
- expect(response.body).to include("Error occurred while creating generic file.")
99
+ file = fixture_file_upload('/world.png','image/png')
100
+ xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample_batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
101
+ expect(response.body).to include("Error occurred while creating generic file.")
102
+ end
103
+ end
130
104
  end
131
- end
132
105
 
133
- describe "#create with browse-everything" do
134
- before do
135
- GenericFile.delete_all
136
- @json_from_browse_everything = {"0"=>{"url"=>"https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt", "expires"=>"2014-03-31T20:37:36.214Z", "file_name"=>"filepicker-demo.txt.txt"}, "1"=>{"url"=>"https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf", "expires"=>"2014-03-31T20:37:36.731Z", "file_name"=>"Getting+Started.pdf"}}
137
- end
138
- it "should ingest files from provide URLs" do
139
- expect(ImportUrlJob).to receive(:new).twice {"ImportJob"}
140
- expect(Sufia.queue).to receive(:push).with("ImportJob").twice
141
- expect { post :create, selected_files: @json_from_browse_everything, batch_id: "sample:batch_id" }.to change(GenericFile, :count).by(2)
142
- created_files = GenericFile.all
143
- ["https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf", "https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt"].each do |url|
144
- expect(created_files.map {|f| f.import_url}).to include(url)
106
+ context "with browse-everything" do
107
+ let(:batch) { Batch.create }
108
+ let(:batch_id) { batch.id }
109
+
110
+ before do
111
+ @json_from_browse_everything = {"0"=>{"url"=>"https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt", "expires"=>"2014-03-31T20:37:36.214Z", "file_name"=>"filepicker-demo.txt.txt"}, "1"=>{"url"=>"https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf", "expires"=>"2014-03-31T20:37:36.731Z", "file_name"=>"Getting+Started.pdf"}}
145
112
  end
146
- ["filepicker-demo.txt.txt","Getting+Started.pdf"].each do |filename|
147
- expect(created_files.map {|f| f.label}).to include(filename)
113
+ it "should ingest files from provide URLs" do
114
+ expect(ImportUrlJob).to receive(:new).twice {"ImportJob"}
115
+ expect(Sufia.queue).to receive(:push).with("ImportJob").twice
116
+ expect { post :create, selected_files: @json_from_browse_everything, batch_id: batch_id }.to change(GenericFile, :count).by(2)
117
+ created_files = GenericFile.all
118
+ ["https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf", "https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt"].each do |url|
119
+ expect(created_files.map {|f| f.import_url}).to include(url)
120
+ end
121
+ ["filepicker-demo.txt.txt","Getting+Started.pdf"].each do |filename|
122
+ expect(created_files.map {|f| f.label}).to include(filename)
123
+ end
148
124
  end
149
125
  end
150
- end
151
126
 
152
- describe "#create with local_file" do
153
- let (:mock_url) {"http://example.com"}
154
- before do
155
- Sufia.config.enable_local_ingest = true
156
- GenericFile.delete_all
157
- @mock_upload_directory = 'spec/mock_upload_directory'
158
- # Dir.mkdir @mock_upload_directory unless File.exists? @mock_upload_directory
159
- FileUtils.mkdir_p([File.join(@mock_upload_directory, "import/files"),File.join(@mock_upload_directory, "import/metadata")])
160
- FileUtils.copy(File.expand_path('../../fixtures/world.png', __FILE__), @mock_upload_directory)
161
- FileUtils.copy(File.expand_path('../../fixtures/image.jpg', __FILE__), @mock_upload_directory)
162
- FileUtils.copy(File.expand_path('../../fixtures/dublin_core_rdf_descMetadata.nt', __FILE__), File.join(@mock_upload_directory, "import/metadata"))
163
- FileUtils.copy(File.expand_path('../../fixtures/icons.zip', __FILE__), File.join(@mock_upload_directory, "import/files"))
164
- FileUtils.copy(File.expand_path('../../fixtures/Example.ogg', __FILE__), File.join(@mock_upload_directory, "import/files"))
165
- end
166
- after do
167
- Sufia.config.enable_local_ingest = false
168
- allow_any_instance_of(FileContentDatastream).to receive(:live?).and_return(true)
169
- GenericFile.destroy_all
170
- end
171
- context "when User model defines a directory path" do
127
+ context "with local_file" do
128
+ let(:mock_url) {"http://example.com"}
129
+ let(:mock_upload_directory) { 'spec/mock_upload_directory' }
130
+ let(:batch) { Batch.create }
131
+ let(:batch_id) { batch.id }
132
+
172
133
  before do
173
- if $in_travis
174
- # In order to avoid an invalid derivative creation, just stub out the derivatives.
175
- allow_any_instance_of(GenericFile).to receive(:create_derivatives)
134
+ Sufia.config.enable_local_ingest = true
135
+ FileUtils.mkdir_p([File.join(mock_upload_directory, "import/files"), File.join(mock_upload_directory, "import/metadata")])
136
+ FileUtils.copy(File.expand_path('../../fixtures/world.png', __FILE__), mock_upload_directory)
137
+ FileUtils.copy(File.expand_path('../../fixtures/image.jpg', __FILE__), mock_upload_directory)
138
+ FileUtils.copy(File.expand_path('../../fixtures/dublin_core_rdf_descMetadata.nt', __FILE__), File.join(mock_upload_directory, "import/metadata"))
139
+ FileUtils.copy(File.expand_path('../../fixtures/icons.zip', __FILE__), File.join(mock_upload_directory, "import/files"))
140
+ FileUtils.copy(File.expand_path('../../fixtures/Example.ogg', __FILE__), File.join(mock_upload_directory, "import/files"))
141
+ end
142
+
143
+ after do
144
+ Sufia.config.enable_local_ingest = false
145
+ allow_any_instance_of(FileContentDatastream).to receive(:live?).and_return(true)
146
+ end
147
+
148
+ context "when User model defines a directory path" do
149
+ before do
150
+ allow_any_instance_of(User).to receive(:directory).and_return(mock_upload_directory)
176
151
  end
177
- allow_any_instance_of(User).to receive(:directory).and_return(@mock_upload_directory)
178
- end
179
- it "should ingest files from the filesystem" do
180
- expect { post :create, local_file: ["world.png", "image.jpg"], batch_id: "xw42n7934"}.to change(GenericFile, :count).by(2)
181
- expect(response).to redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path('xw42n7934')
182
- # These files should have been moved out of the upload directory
183
- expect(File).not_to exist("#{@mock_upload_directory}/image.jpg")
184
- expect(File).not_to exist("#{@mock_upload_directory}/world.png")
185
- # And into the storage directory
186
- files = GenericFile.find(Solrizer.solr_name("is_part_of",:symbol) => 'info:fedora/sufia:xw42n7934')
187
- expect(files.first.label).to eq('world.png')
188
- expect(files.last.label).to eq('image.jpg')
189
- end
190
- it "should ingest redirect to another location" do
191
- expect(GenericFilesController).to receive(:upload_complete_path).and_return(mock_url)
192
- expect { post :create, local_file: ["world.png"], batch_id: "xw42n7934"}.to change(GenericFile, :count).by(1)
193
- expect(response).to redirect_to mock_url
194
- # These files should have been moved out of the upload directory
195
- expect(File).not_to exist("#{@mock_upload_directory}/world.png")
196
- # And into the storage directory
197
- files = GenericFile.find(Solrizer.solr_name("is_part_of",:symbol) => 'info:fedora/sufia:xw42n7934')
198
- expect(files.first.label).to eq('world.png')
199
- end
200
- it "should ingest directories from the filesystem" do
201
- expect { post :create, local_file: ["world.png", "import"], batch_id: "xw42n7934"}.to change(GenericFile, :count).by(4)
202
- expect(response).to redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path('xw42n7934')
203
- # These files should have been moved out of the upload directory
204
- expect(File).not_to exist("#{@mock_upload_directory}/import/files/icons.zip")
205
- expect(File).not_to exist("#{@mock_upload_directory}/import/metadata/dublin_core_rdf_descMetadata.nt")
206
- expect(File).not_to exist("#{@mock_upload_directory}/world.png")
207
- # And into the storage directory
208
- files = GenericFile.find(Solrizer.solr_name("is_part_of",:symbol) => 'info:fedora/sufia:xw42n7934')
209
- expect(files.first.label).to eq('world.png')
210
- ['icons.zip', 'Example.ogg'].each do |filename|
211
- expect(files.select{|f| f.label == filename}.first.relative_path).to eq("import/files/#{filename}")
152
+
153
+ it "should ingest files from the filesystem" do
154
+ expect {
155
+ post :create, local_file: ["world.png", "image.jpg"], batch_id: batch_id
156
+ }.to change(GenericFile, :count).by(2)
157
+ expect(response).to redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path(batch_id)
158
+ # These files should have been moved out of the upload directory
159
+ expect(File).not_to exist("#{mock_upload_directory}/image.jpg")
160
+ expect(File).not_to exist("#{mock_upload_directory}/world.png")
161
+ # And into the storage directory
162
+ files = Batch.find(batch_id).generic_files
163
+ expect(files.first.label).to eq('world.png')
164
+ expect(files.to_a.map(&:label)).to eq ['world.png', 'image.jpg']
165
+ end
166
+
167
+ it "should ingest redirect to another location" do
168
+ expect(GenericFilesController).to receive(:upload_complete_path).and_return(mock_url)
169
+ expect {
170
+ post :create, local_file: ["world.png"], batch_id: batch_id
171
+ }.to change(GenericFile, :count).by(1)
172
+ expect(response).to redirect_to mock_url
173
+ # These files should have been moved out of the upload directory
174
+ expect(File).not_to exist("#{mock_upload_directory}/world.png")
175
+ # And into the storage directory
176
+ files = Batch.find(batch_id).generic_files
177
+ expect(files.first.label).to eq 'world.png'
178
+ end
179
+
180
+ it "should ingest directories from the filesystem" do
181
+ expect {
182
+ post :create, local_file: ["world.png", "import"], batch_id: batch_id
183
+ }.to change(GenericFile, :count).by(4)
184
+ expect(response).to redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path(batch_id)
185
+ # These files should have been moved out of the upload directory
186
+ expect(File).not_to exist("#{mock_upload_directory}/import/files/icons.zip")
187
+ expect(File).not_to exist("#{mock_upload_directory}/import/metadata/dublin_core_rdf_descMetadata.nt")
188
+ expect(File).not_to exist("#{mock_upload_directory}/world.png")
189
+ # And into the storage directory
190
+ files = Batch.find(batch_id).generic_files
191
+ expect(files.first.label).to eq 'world.png'
192
+ # TODO: use files.select once projecthydra/active_fedora#609 is fixed
193
+ ['icons.zip', 'Example.ogg'].each do |filename|
194
+ expect(files.map { |f| f.relative_path if f.label.match(filename) }.compact.first).to eq "import/files/#{filename}"
195
+ end
196
+ expect(files.map { |f| f.relative_path if f.label.match("dublin_core_rdf_descMetadata.nt") }.compact.first).to eq 'import/metadata/dublin_core_rdf_descMetadata.nt'
212
197
  end
213
- expect(files.select{|f| f.label == 'dublin_core_rdf_descMetadata.nt'}.first.relative_path).to eq('import/metadata/dublin_core_rdf_descMetadata.nt')
214
198
  end
215
- end
216
- context "when User model does not define directory path" do
217
- it "should return an error message and redirect to file upload page" do
218
- expect { post :create, local_file: ["world.png", "image.jpg"], batch_id: "xw42n7934"}.not_to change(GenericFile, :count)
219
- expect(response).to render_template :new
220
- expect(flash[:alert]).to eq('Your account is not configured for importing files from a user-directory on the server.')
199
+
200
+ context "when User model does not define directory path" do
201
+ it "should return an error message and redirect to file upload page" do
202
+ expect {
203
+ post :create, local_file: ["world.png", "image.jpg"], batch_id: batch_id
204
+ }.to_not change(GenericFile, :count)
205
+ expect(response).to render_template :new
206
+ expect(flash[:alert]).to eq 'Your account is not configured for importing files from a user-directory on the server.'
207
+ end
221
208
  end
222
209
  end
223
210
  end
224
211
 
225
212
  describe "audit" do
226
- before do
227
- @generic_file = GenericFile.new
228
- @generic_file.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
229
- @generic_file.apply_depositor_metadata('mjg36')
230
- @generic_file.save
231
- end
232
- after do
233
- @generic_file.delete
213
+ let(:generic_file) do
214
+ GenericFile.create do |gf|
215
+ gf.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
216
+ gf.apply_depositor_metadata(user)
217
+ end
234
218
  end
219
+
235
220
  it "should return json with the result" do
236
- xhr :post, :audit, id: @generic_file.pid
221
+ xhr :post, :audit, id: generic_file
237
222
  expect(response).to be_success
238
- expect { JSON.parse(response.body) }.not_to raise_error
239
- audit_results = JSON.parse(response.body).collect { |result| result["pass"] }
240
- expect(audit_results.reduce(true) { |sum, value| sum && value }).to be_truthy
223
+ json = JSON.parse(response.body)
224
+ audit_results = json.collect { |result| result["pass"] }
225
+ expect(audit_results.reduce(true) { |sum, value| sum && value }).to eq 999 # never been audited
241
226
  end
242
227
  end
243
228
 
244
229
  describe "destroy" do
245
- before(:each) do
246
- @generic_file = GenericFile.new
247
- @generic_file.apply_depositor_metadata(@user)
248
- @generic_file.save
249
- @user = FactoryGirl.find_or_create(:jill)
250
- sign_in @user
230
+ let(:generic_file) do
231
+ GenericFile.create do |gf|
232
+ gf.apply_depositor_metadata(user)
233
+ end
251
234
  end
252
- after do
253
- @user.delete
235
+
236
+ before do
237
+ allow(ContentDeleteEventJob).to receive(:new).with(generic_file.id, user.user_key).and_return(delete_message)
254
238
  end
239
+ let(:delete_message) { double('delete message') }
255
240
  it "should delete the file" do
256
- expect(GenericFile.find(@generic_file.pid)).not_to be_nil
257
- delete :destroy, id: @generic_file.pid
258
- expect { GenericFile.find(@generic_file.pid) }.to raise_error(ActiveFedora::ObjectNotFoundError)
259
- end
260
- it "should spawn a content delete event job" do
261
- s1 = double('one')
262
- expect(ContentDeleteEventJob).to receive(:new).with(@generic_file.pid, @user.user_key).and_return(s1)
263
- expect(Sufia.queue).to receive(:push).with(s1).once
264
- delete :destroy, id: @generic_file.pid
241
+ expect(Sufia.queue).to receive(:push).with(delete_message)
242
+ expect {
243
+ delete :destroy, id: generic_file
244
+ }.to change { GenericFile.exists?(generic_file.id) }.from(true).to(false)
265
245
  end
266
246
 
267
247
  context "when the file is featured" do
268
248
  before do
269
- FeaturedWork.create(generic_file_id: @generic_file.pid)
249
+ FeaturedWork.create(generic_file_id: generic_file.id)
250
+ expect(Sufia.queue).to receive(:push).with(delete_message)
270
251
  end
271
252
  it "should make the file not featured" do
272
- expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to include(@generic_file.pid)
273
- delete :destroy, id: @generic_file.pid
274
- expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to_not include(@generic_file.pid)
253
+ expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to include(generic_file.id)
254
+ delete :destroy, id: generic_file.id
255
+ expect(FeaturedWorkList.new.featured_works.map(&:generic_file_id)).to_not include(generic_file.id)
275
256
  end
276
257
  end
277
258
  end
278
259
 
279
260
  describe 'stats' do
280
- before do
281
- @generic_file = GenericFile.new.tap do |gf|
282
- gf.apply_depositor_metadata(@user)
283
- gf.save
261
+ let(:generic_file) do
262
+ GenericFile.create do |gf|
263
+ gf.apply_depositor_metadata(user)
284
264
  end
285
265
  end
286
266
 
287
- after do
288
- @generic_file.destroy
289
- end
290
-
291
267
  context 'when user has access to file' do
292
268
  before do
269
+ sign_in user
293
270
  mock_query = double('query')
294
271
  allow(mock_query).to receive(:for_path).and_return([
295
272
  OpenStruct.new(date: '2014-01-01', pageviews: 4),
@@ -304,31 +281,26 @@ describe GenericFilesController, :type => :controller do
304
281
 
305
282
  download_query = double('query')
306
283
  allow(download_query).to receive(:for_file).and_return([
307
- OpenStruct.new(date: Date.today.strftime("%Y%m%d"), eventCategory: "Files", eventAction: "Downloaded", eventLabel: "sufia:123456789", totalEvents: "3")
284
+ OpenStruct.new(eventCategory: "Files", eventAction: "Downloaded", eventLabel: "123456789", totalEvents: "3")
308
285
  ])
309
286
  allow(download_query).to receive(:map).and_return(download_query.for_file.map(&:marshal_dump))
310
287
  allow(profile).to receive(:sufia__download).and_return(download_query)
311
288
  end
312
289
 
313
290
  it 'renders the stats view' do
314
- allow(controller.request).to receive(:referer).and_return('foo')
315
- expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
316
- expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.my.files'), Sufia::Engine.routes.url_helpers.dashboard_files_path)
317
- expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.generic_file.browse_view'), Sufia::Engine.routes.url_helpers.generic_file_path(@generic_file.noid))
318
- get :stats, id: @generic_file.noid
291
+ get :stats, id: generic_file
319
292
  expect(response).to be_success
320
293
  expect(response).to render_template(:stats)
321
294
  end
322
295
 
323
296
  context "user is not signed in but the file is public" do
324
297
  before do
325
- sign_out @user
326
- @generic_file.read_groups = ['public']
327
- @generic_file.save
298
+ generic_file.read_groups = ['public']
299
+ generic_file.save
328
300
  end
329
301
 
330
302
  it 'renders the stats view' do
331
- get :stats, id: @generic_file.noid
303
+ get :stats, id: generic_file
332
304
  expect(response).to be_success
333
305
  expect(response).to render_template(:stats)
334
306
  end
@@ -337,186 +309,176 @@ describe GenericFilesController, :type => :controller do
337
309
 
338
310
  context 'when user lacks access to file' do
339
311
  before do
340
- @archivist = FactoryGirl.find_or_create(:archivist)
341
- sign_in @archivist
312
+ sign_in FactoryGirl.create(:user)
342
313
  end
343
314
 
344
315
  it 'redirects to root_url' do
345
- get :stats, id: @generic_file.pid
316
+ get :stats, id: generic_file
346
317
  expect(response).to redirect_to(Sufia::Engine.routes.url_helpers.root_path)
347
318
  end
348
319
  end
349
320
  end
350
321
 
351
- describe "update" do
322
+ describe "#edit" do
352
323
  let(:generic_file) do
353
- GenericFile.new.tap do |gf|
354
- gf.apply_depositor_metadata(@user)
355
- gf.save!
324
+ GenericFile.create do |gf|
325
+ gf.apply_depositor_metadata(user)
356
326
  end
357
327
  end
358
328
 
359
- after do
360
- generic_file.destroy
361
- end
362
-
363
- it "should spawn a content update event job" do
364
- s1 = double('one')
365
- expect(ContentUpdateEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').and_return(s1)
366
- expect(Sufia.queue).to receive(:push).with(s1).once
367
- @user = FactoryGirl.find_or_create(:jill)
368
- sign_in @user
369
- post :update, id: generic_file, generic_file: {title: ['new_title'], tag: [''], permissions: { new_user_name: {'archivist1'=>'edit'}}}
370
- @user.delete
371
- end
372
-
373
- it "spawns a content new version event job" do
374
- s1 = double('one')
375
- allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').and_return(s1)
376
- expect(Sufia.queue).to receive(:push).with(s1).once
377
-
378
- s2 = double('one')
379
- allow(CharacterizeJob).to receive(:new).with(generic_file.pid).and_return(s2)
380
- expect(Sufia.queue).to receive(:push).with(s2).once
381
- @user = FactoryGirl.find_or_create(:jill)
382
- sign_in @user
329
+ it "should set the versions presenter" do
330
+ get :edit, id: generic_file
383
331
 
384
- file = fixture_file_upload('/world.png', 'image/png')
385
- post :update, id: generic_file, filedata: file, generic_file: {tag: [''], permissions: { new_user_name: {archivist1: 'edit' } } }
386
- @user.destroy
332
+ expect(response).to be_success
333
+ expect(assigns[:generic_file]).to eq generic_file
334
+ expect(assigns[:version_list]).to be_kind_of Sufia::VersionListPresenter
387
335
  end
388
336
 
389
- it "should change mime type when restoring a revision with a different mime type" do
390
- @user = FactoryGirl.find_or_create(:jill)
391
- sign_in @user
392
-
393
- file = fixture_file_upload('/world.png','image/png')
394
- post :update, id: generic_file, filedata: file, generic_file: { tag: [''], permissions: { new_user_name: { 'archivist1@example.com'=>'edit' } } }
395
-
396
- posted_file = GenericFile.find(generic_file.pid)
397
- version1 = posted_file.content.latest_version
398
- expect(posted_file.content.version_committer(version1)).to eq(@user.user_key)
399
-
400
- file = fixture_file_upload('/image.jpg','image/jpg')
401
- post :update, id: generic_file, filedata: file, generic_file: { tag: [''], permissions: { new_user_name: { 'archivist1@example.com'=>'edit' } } }
402
-
403
- posted_file = GenericFile.find(generic_file.pid)
404
- version2 = posted_file.content.latest_version
405
- expect(posted_file.content.version_committer(version2)).to eq(@user.user_key)
406
-
407
- expect(posted_file.content.mimeType).to eq("image/jpeg")
408
- post :update, id: generic_file, revision: 'content.0'
337
+ end
409
338
 
410
- restored_file = GenericFile.find(generic_file.pid)
411
- version3 = restored_file.content.latest_version
412
- expect(version3.versionID).not_to eq(version2.versionID)
413
- expect(version3.versionID).not_to eq(version1.versionID)
414
- expect(restored_file.content.version_committer(version3)).to eq(@user.user_key)
415
- expect(restored_file.content.mimeType).to eq("image/png")
416
- @user.delete
339
+ describe "update" do
340
+ let(:generic_file) do
341
+ GenericFile.create do |gf|
342
+ gf.apply_depositor_metadata(user)
343
+ end
417
344
  end
418
345
 
419
- context "when two users edit a file" do
420
- let(:archivist) { FactoryGirl.find_or_create(:archivist) }
421
- let(:user) { FactoryGirl.find_or_create(:jill) }
422
- let(:generic_file) do
423
- GenericFile.new.tap do |gf|
424
- gf.apply_depositor_metadata(user)
425
- gf.edit_users = [user.user_key, archivist.user_key]
426
- gf.save!
427
- end
428
- end
346
+ context "when updating metadata" do
347
+ let(:update_message) { double('content update message') }
429
348
  before do
430
- allow_any_instance_of(Sufia::GenericFile::Actor).to receive(:push_characterize_job)
431
- sign_in user
349
+ allow(ContentUpdateEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(update_message)
432
350
  end
433
351
 
434
- it "records which user added a new version" do
435
- file = fixture_file_upload('/world.png','image/png')
436
- post :update, id: generic_file, filedata: file
437
-
438
- posted_file = GenericFile.find(generic_file.pid)
439
- version1 = posted_file.content.latest_version
440
- expect(posted_file.content.version_committer(version1)).to eq(user.user_key)
352
+ it "should spawn a content update event job" do
353
+ expect(Sufia.queue).to receive(:push).with(update_message)
354
+ post :update, id: generic_file, generic_file: { title: ['new_title'], tag: [''],
355
+ permissions_attributes: [{ type: 'person', name: 'archivist1', access: 'edit'}] }
356
+ end
441
357
 
442
- # other user uploads new version
443
- # TODO this should be a separate test
444
- allow(controller).to receive(:current_user).and_return(archivist)
445
- # reset controller:
446
- controller.instance_variable_set(:@actor, nil)
358
+ it "spawns a content new version event job" do
359
+ s1 = double('one')
360
+ allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(s1)
361
+ expect(Sufia.queue).to receive(:push).with(s1).once
447
362
 
448
- expect(ContentUpdateEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').never
363
+ s2 = double('one')
364
+ allow(CharacterizeJob).to receive(:new).with(generic_file.id).and_return(s2)
365
+ expect(Sufia.queue).to receive(:push).with(s2).once
366
+ file = fixture_file_upload('/world.png', 'image/png')
367
+ post :update, id: generic_file, filedata: file, generic_file: {tag: [''], permissions: { new_user_name: {archivist1: 'edit' } } }
368
+ end
369
+ end
449
370
 
371
+ context "when updating the attached file" do
372
+ it "spawns a content new version event job" do
450
373
  s1 = double('one')
451
- allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.pid, archivist.user_key).and_return(s1)
374
+ allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(s1)
452
375
  expect(Sufia.queue).to receive(:push).with(s1).once
453
376
 
454
- file = fixture_file_upload('/image.jpg', 'image/jpg')
455
- post :update, id: generic_file, filedata: file
377
+ s2 = double('one')
378
+ allow(CharacterizeJob).to receive(:new).with(generic_file.id).and_return(s2)
379
+ expect(Sufia.queue).to receive(:push).with(s2).once
456
380
 
457
- edited_file = generic_file.reload
458
- version2 = edited_file.content.latest_version
459
- expect(version2.versionID).not_to eq(version1.versionID)
460
- expect(edited_file.content.version_committer(version2)).to eq(archivist.user_key)
381
+ file = fixture_file_upload('/world.png', 'image/png')
382
+ post :update, id: generic_file, filedata: file, generic_file: {tag: [''],
383
+ permissions_attributes: [{ type: 'user', name: 'archivist1', access: 'edit'}] }
384
+ end
385
+ end
461
386
 
462
- # original user restores his or her version
463
- allow(controller).to receive(:current_user).and_return(user)
464
- sign_in user
465
- expect(ContentUpdateEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').never
466
- s1 = double('one')
467
- allow(ContentRestoredVersionEventJob).to receive(:new).with(generic_file.pid, user.user_key, 'content.0').and_return(s1)
468
- expect(Sufia.queue).to receive(:push).with(s1).once
387
+ context "with two existing versions from different users" do
388
+
389
+ let(:file1) { "world.png" }
390
+ let(:file1_type) { "image/png" }
391
+ let(:file2) { "image.jpg" }
392
+ let(:file2_type) { "image/jpeg" }
393
+ let(:second_user) { FactoryGirl.create(:user) }
394
+ let(:version1) { "version1" }
395
+ let(:actor1) { Sufia::GenericFile::Actor.new(generic_file, user) }
396
+ let(:actor2) { Sufia::GenericFile::Actor.new(generic_file, second_user) }
469
397
 
470
- # reset controller:
471
- controller.instance_variable_set(:@actor, nil)
398
+ before do
399
+ allow_any_instance_of(GenericFile).to receive(:characterize)
400
+ actor1.create_content(fixture_file_upload(file1), file1, 'content')
401
+ actor2.create_content(fixture_file_upload(file2), file2, 'content')
402
+ end
472
403
 
473
- post :update, id: generic_file, revision: 'content.0'
404
+ describe "restoring a previous version" do
405
+ context "as the first user" do
406
+ before do
407
+ sign_in user
408
+ post :update, id: generic_file, revision: version1
409
+ end
410
+
411
+ let(:restored_content) { generic_file.reload.content }
412
+ let(:versions) { restored_content.versions }
413
+ let(:latest_version) { restored_content.latest_version }
414
+
415
+ it "should restore the first versions's content and metadata" do
416
+ expect(restored_content.mime_type).to eq file1_type
417
+ expect(restored_content.original_name).to eq file1
418
+ expect(versions.all.count).to eq 3
419
+ expect(versions.last.label).to eq latest_version.label
420
+ expect(VersionCommitter.where(version_id: versions.last.uri).pluck(:committer_login)).to eq [user.user_key]
421
+ end
422
+ end
474
423
 
475
- restored_file = generic_file.reload
476
- version3 = restored_file.content.latest_version
477
- expect(version3.versionID).not_to eq(version2.versionID)
478
- expect(version3.versionID).not_to eq(version1.versionID)
479
- expect(restored_file.content.version_committer(version3)).to eq(user.user_key)
424
+ context "as the second user" do
425
+ before do
426
+ sign_in second_user
427
+ end
428
+ it "should not create a new version" do
429
+ post :update, id: generic_file, revision: version1
430
+ expect(response).to be_redirect
431
+ end
432
+ end
480
433
  end
481
434
  end
482
435
 
483
436
  it "should add new groups and users" do
484
- post :update, id: generic_file, generic_file: { tag: [''], permissions:
485
- { new_group_name: { 'group1' => 'read' }, new_user_name: { 'user1' => 'edit' }}}
437
+ post :update, id: generic_file,
438
+ generic_file: { tag: [''],
439
+ permissions_attributes: [
440
+ { type: 'person', name: 'user1', access: 'edit' },
441
+ { type: 'group', name: 'group1', access: 'read' }
442
+ ]
443
+ }
486
444
 
487
- expect(assigns[:generic_file].read_groups).to eq(["group1"])
488
- expect(assigns[:generic_file].edit_users).to include("user1", @user.user_key)
445
+ expect(assigns[:generic_file].read_groups).to eq ["group1"]
446
+ expect(assigns[:generic_file].edit_users).to include("user1", user.user_key)
489
447
  end
448
+
490
449
  it "should update existing groups and users" do
491
- generic_file.read_groups = ['group3']
450
+ generic_file.edit_groups = ['group3']
492
451
  generic_file.save
493
- post :update, id: generic_file, generic_file: { tag: [''], permissions:
494
- { new_group_name: '', new_group_permission: '', new_user_name: '', new_user_permission: '', group: { 'group3' => 'read' }}}
452
+ post :update, id: generic_file,
453
+ generic_file: { tag: [''],
454
+ permissions_attributes: [
455
+ { id: generic_file.permissions.last.id, type: 'group', name: 'group3', access: 'read'}
456
+ ]
457
+ }
495
458
 
496
459
  expect(assigns[:generic_file].read_groups).to eq(["group3"])
497
460
  end
498
461
 
499
462
  it "spawns a virus check" do
500
463
  s1 = double('one')
501
- allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').and_return(s1)
464
+ allow(ContentNewVersionEventJob).to receive(:new).with(generic_file.id, 'jilluser@example.com').and_return(s1)
502
465
  expect(Sufia.queue).to receive(:push).with(s1).once
503
466
 
504
467
  s2 = double('one')
505
- allow(CharacterizeJob).to receive(:new).with(generic_file.pid).and_return(s2)
506
- allow(CreateDerivativesJob).to receive(:new).with(generic_file.pid).and_return(s2)
507
- @user = FactoryGirl.find_or_create(:jill)
508
- sign_in @user
468
+ allow(CharacterizeJob).to receive(:new).with(generic_file.id).and_return(s2)
469
+ allow(CreateDerivativesJob).to receive(:new).with(generic_file.id).and_return(s2)
509
470
  file = fixture_file_upload('/world.png', 'image/png')
510
471
  expect(Sufia::GenericFile::Actor).to receive(:virus_check).and_return(0)
511
472
  expect(Sufia.queue).to receive(:push).with(s2).once
512
- post :update, id: generic_file.pid, filedata: file, 'Filename' => 'The world', generic_file: { tag: [''], permissions: { new_user_name: { archivist1: 'edit' } } }
473
+ post :update, id: generic_file.id, filedata: file, 'Filename' => 'The world',
474
+ generic_file: { tag: [''],
475
+ permissions_attributes: [{ type: 'user', name: 'archivist1', access: 'edit' }] }
513
476
  end
514
477
 
515
478
  context "when there's an error saving" do
516
479
  let!(:generic_file) do
517
- GenericFile.new.tap do |gf|
518
- gf.apply_depositor_metadata(@user)
519
- gf.save!
480
+ GenericFile.create do |gf|
481
+ gf.apply_depositor_metadata(user)
520
482
  end
521
483
  end
522
484
  it "redirects to edit" do
@@ -529,88 +491,61 @@ describe GenericFilesController, :type => :controller do
529
491
  end
530
492
  end
531
493
 
532
- describe "edit" do
494
+ describe "someone elses files" do
533
495
  let(:generic_file) do
534
- GenericFile.new.tap do |gf|
535
- gf.apply_depositor_metadata(@user)
536
- gf.save!
496
+ GenericFile.create(id: 'test5') do |f|
497
+ f.apply_depositor_metadata('archivist1@example.com')
498
+ f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
499
+ # grant public read access explicitly
500
+ f.read_groups = ['public']
537
501
  end
538
502
  end
539
503
 
540
- after do
541
- generic_file.destroy
542
- end
543
-
544
- it 'renders the edit view' do
545
- allow(controller.request).to receive(:referer).and_return('foo')
546
- expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
547
- expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.my.files'), Sufia::Engine.routes.url_helpers.dashboard_files_path)
548
- expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.generic_file.browse_view'), Sufia::Engine.routes.url_helpers.generic_file_path(generic_file.noid))
549
- get :edit, id: generic_file.noid
550
- expect(response).to be_success
551
- expect(response).to render_template(:edit)
552
- end
553
- end
554
- describe "someone elses files" do
555
- before do
556
- f = GenericFile.new(pid: 'sufia:test5')
557
- f.apply_depositor_metadata('archivist1@example.com')
558
- f.add_file(File.open(fixture_path + '/world.png'), 'content', 'world.png')
559
- # grant public read access explicitly
560
- f.read_groups = ['public']
561
- f.save
562
- @file = f
563
- allow_any_instance_of(Sufia::GenericFile::Actor).to receive(:push_characterize_job)
564
- end
565
- after do
566
- GenericFile.find('sufia:test5').destroy
567
- end
568
504
  describe "edit" do
569
505
  it "should give me a flash error" do
570
- get :edit, id: "test5"
506
+ get :edit, id: generic_file
571
507
  expect(response).to redirect_to @routes.url_helpers.generic_file_path('test5')
572
508
  expect(flash[:alert]).not_to be_nil
573
509
  expect(flash[:alert]).not_to be_empty
574
510
  expect(flash[:alert]).to include("You do not have sufficient privileges to edit this document")
575
511
  end
576
512
  end
577
- describe "view" do
578
- it "should show me the file" do
579
- get :show, id: "test5"
580
- expect(response).not_to redirect_to(action: 'show')
581
- expect(flash[:alert]).to be_nil
582
- end
583
- it "should set the breadcrumbs" do
513
+
514
+ describe "#show" do
515
+ it "should show me the file and set breadcrumbs" do
584
516
  expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
585
- get :show, id: "test5"
517
+ get :show, id: generic_file
518
+ expect(response).to be_successful
519
+ expect(flash).to be_empty
520
+ expect(assigns[:events]).to be_kind_of Array
521
+ expect(assigns[:generic_file]).to eq generic_file
522
+ expect(assigns[:audit_status]).to eq 'Audits have not yet been run on this file.'
586
523
  end
587
524
  end
588
- describe "flash" do
589
- it "should not let the user submit if they logout" do
590
- sign_out @user
591
- get :new
592
- expect(response).not_to be_success
593
- expect(flash[:alert]).not_to be_nil
594
- expect(flash[:alert]).to include("You need to sign in or sign up before continuing")
595
- end
596
- it "should filter flash if they signin" do
597
- sign_in @user
598
- get :show, id: "test5"
599
- expect(flash[:alert]).to be_nil
600
- end
601
- describe "failing audit" do
602
- before do
603
- allow_any_instance_of(ActiveFedora::RelsExtDatastream).to receive(:dsChecksumValid).and_return(false)
604
- @archivist = FactoryGirl.find_or_create(:archivist)
605
- end
606
- it "should display failing audits" do
607
- sign_in @archivist
608
- AuditJob.new(@file.pid, "RELS-EXT", @file.rels_ext.versionID).run
609
- get :show, id: "test5"
610
- expect(assigns[:notify_number]).to eq(1)
611
- expect(@archivist.mailbox.inbox[0].messages[0].subject).to eq("Failing Audit Run")
612
- end
613
- end
525
+ end
526
+
527
+ describe "flash" do
528
+ it "should not let the user submit if they logout" do
529
+ sign_out user
530
+ get :new
531
+ expect(response).to_not be_success
532
+ expect(flash[:alert]).to include("You need to sign in or sign up before continuing")
533
+ end
534
+ it "should filter flash if they signin" do
535
+ sign_in user
536
+ get :new
537
+ expect(flash[:alert]).to be_nil
538
+ end
539
+ end
540
+
541
+ describe "notifications" do
542
+ before do
543
+ User.audituser.send_message(user, "Test message", "Test subject")
544
+ end
545
+ it "should display notifications" do
546
+ get :new
547
+ expect(assigns[:notify_number]).to eq 1
548
+ expect(user.mailbox.inbox[0].messages[0].subject).to eq "Test subject"
614
549
  end
615
550
  end
616
551
  end