sufia 4.0.1 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/History.md +247 -215
  3. data/README.md +7 -3
  4. data/SUFIA_VERSION +1 -1
  5. data/app/assets/javascripts/sufia.js +5 -2
  6. data/app/assets/javascripts/sufia/proxy_rights.js +68 -0
  7. data/app/assets/javascripts/sufia/transfers.js +3 -0
  8. data/app/assets/javascripts/sufia/user_search.js +31 -0
  9. data/app/assets/stylesheets/jquery-ui.css +17 -17
  10. data/app/assets/stylesheets/sufia.css.scss +3 -2
  11. data/app/assets/stylesheets/sufia/_proxy-rights.scss +10 -0
  12. data/app/controllers/concerns/sufia/contact_form_controller_behavior.rb +22 -23
  13. data/app/controllers/concerns/sufia/depositors_controller_behavior.rb +41 -0
  14. data/app/controllers/concerns/sufia/files_controller_behavior.rb +1 -0
  15. data/app/controllers/concerns/sufia/transfers_controller_behavior.rb +76 -0
  16. data/app/controllers/concerns/sufia/users_controller_behavior.rb +9 -11
  17. data/app/controllers/depositors_controller.rb +3 -0
  18. data/app/controllers/transfers_controller.rb +3 -0
  19. data/app/helpers/sufia/dashboard_helper_behavior.rb +15 -0
  20. data/app/helpers/sufia/sufia_helper_behavior.rb +24 -2
  21. data/app/jobs/content_depositor_change_event_job.rb +50 -0
  22. data/app/views/dashboard/_index_partials/_contents.html.erb +18 -0
  23. data/app/views/dashboard/_index_partials/_proxy_rights.html.erb +23 -0
  24. data/app/views/dashboard/_index_partials/_transfers.html.erb +14 -0
  25. data/app/views/generic_files/proxy.html.erb +5 -0
  26. data/app/views/generic_files/upload/_form.html.erb +7 -2
  27. data/app/views/my/_action_menu.html.erb +3 -1
  28. data/app/views/records/edit_fields/_default.html.erb +1 -1
  29. data/app/views/transfers/_received.html.erb +58 -0
  30. data/app/views/transfers/_sent.html.erb +38 -0
  31. data/app/views/transfers/index.html.erb +7 -0
  32. data/app/views/transfers/new.html.erb +23 -0
  33. data/app/views/users/_proxies.html.erb +8 -0
  34. data/app/views/users/_user_util_links_extra.html.erb +1 -0
  35. data/app/views/users/edit.html.erb +6 -1
  36. data/config/locales/sufia.en.yml +9 -4
  37. data/config/routes.rb +14 -3
  38. data/lib/sufia.rb +7 -5
  39. data/lib/sufia/version.rb +1 -1
  40. data/spec/controllers/authorities_controller_spec.rb +6 -6
  41. data/spec/controllers/batch_controller_spec.rb +29 -29
  42. data/spec/controllers/batch_edits_controller_spec.rb +7 -7
  43. data/spec/controllers/catalog_controller_spec.rb +9 -9
  44. data/spec/controllers/collections_controller_spec.rb +28 -28
  45. data/spec/controllers/content_blocks_controller_spec.rb +3 -3
  46. data/spec/controllers/dashboard_controller_spec.rb +1 -1
  47. data/spec/controllers/depositors_controller_spec.rb +50 -0
  48. data/spec/controllers/downloads_controller_spec.rb +22 -22
  49. data/spec/controllers/featured_work_lists_controller_spec.rb +1 -1
  50. data/spec/controllers/featured_works_controller_spec.rb +1 -1
  51. data/spec/controllers/generic_files_controller_spec.rb +98 -90
  52. data/spec/controllers/homepage_controller_spec.rb +1 -1
  53. data/spec/controllers/mailbox_controller_spec.rb +10 -10
  54. data/spec/controllers/my/collections_controller_spec.rb +1 -1
  55. data/spec/controllers/my/files_controller_spec.rb +1 -1
  56. data/spec/controllers/my/highlights_controller_spec.rb +1 -1
  57. data/spec/controllers/my/shares_controller_spec.rb +1 -1
  58. data/spec/controllers/my_controller_spec.rb +1 -1
  59. data/spec/controllers/pages_controller_spec.rb +1 -1
  60. data/spec/controllers/single_use_links_controller_spec.rb +46 -50
  61. data/spec/controllers/single_use_links_viewer_controller_spec.rb +16 -16
  62. data/spec/controllers/static_controller_spec.rb +9 -9
  63. data/spec/controllers/tinymce_assets_controller_spec.rb +1 -1
  64. data/spec/controllers/transfers_controller_spec.rb +212 -0
  65. data/spec/controllers/users_controller_spec.rb +1 -1
  66. data/spec/factories/generic_files.rb +4 -4
  67. data/spec/factories/proxy_deposit_requests.rb +6 -0
  68. data/spec/features/browse_dashboard_files_spec.rb +25 -36
  69. data/spec/features/browse_files_spec.rb +18 -13
  70. data/spec/features/catalog_search_spec.rb +3 -6
  71. data/spec/features/cloud_upload_spec.rb +5 -7
  72. data/spec/features/collection_spec.rb +28 -35
  73. data/spec/features/contact_form_spec.rb +24 -24
  74. data/spec/features/display_dashboard_spec.rb +11 -11
  75. data/spec/features/ingest_upload_files_spec.rb +10 -10
  76. data/spec/features/notifications_spec.rb +11 -11
  77. data/spec/features/ownership_transfer_spec.rb +111 -0
  78. data/spec/features/proxy_spec.rb +52 -0
  79. data/spec/features/search_spec.rb +1 -1
  80. data/spec/features/single_use_links_spec.rb +28 -18
  81. data/spec/features/users_spec.rb +3 -3
  82. data/spec/helpers/batch_edits_helper_spec.rb +1 -1
  83. data/spec/helpers/content_block_helper_spec.rb +1 -1
  84. data/spec/helpers/dashboard_helper_spec.rb +1 -1
  85. data/spec/helpers/generic_file_helper_spec.rb +1 -1
  86. data/spec/helpers/records_helper_spec.rb +1 -1
  87. data/spec/helpers/sufia_helper_spec.rb +8 -8
  88. data/spec/helpers/trophy_helper_spec.rb +1 -1
  89. data/spec/jobs/audit_job_spec.rb +5 -5
  90. data/spec/jobs/batch_update_job_spec.rb +14 -14
  91. data/spec/jobs/content_depositor_change_event_job_spec.rb +22 -0
  92. data/spec/jobs/event_jobs_spec.rb +104 -104
  93. data/spec/jobs/import_url_job_spec.rb +2 -2
  94. data/spec/jobs/ingest_local_file_job_spec.rb +1 -1
  95. data/spec/lib/sufia/breadcrumbs_spec.rb +3 -3
  96. data/spec/lib/sufia/id_service_spec.rb +1 -1
  97. data/spec/lib/sufia/upload_complete_behavior_spec.rb +4 -4
  98. data/spec/models/ability_spec.rb +59 -15
  99. data/spec/models/batch_spec.rb +16 -16
  100. data/spec/models/characterization_spec.rb +1 -1
  101. data/spec/models/checksum_audit_log_spec.rb +34 -26
  102. data/spec/models/collection_spec.rb +1 -1
  103. data/spec/models/download_spec.rb +1 -1
  104. data/spec/models/featured_work_list_spec.rb +1 -1
  105. data/spec/models/featured_work_spec.rb +15 -4
  106. data/spec/models/file_content_datastream_spec.rb +14 -14
  107. data/spec/models/file_usage_spec.rb +1 -1
  108. data/spec/models/fits_datastream_spec.rb +1 -1
  109. data/spec/models/generic_file/reload_on_save_spec.rb +4 -4
  110. data/spec/models/generic_file/visibility_spec.rb +1 -1
  111. data/spec/models/generic_file/web_form_spec.rb +6 -5
  112. data/spec/models/generic_file_rdf_datastream_spec.rb +1 -1
  113. data/spec/models/generic_file_spec.rb +254 -220
  114. data/spec/models/geo_names_resource_spec.rb +2 -2
  115. data/spec/models/local_authority_spec.rb +60 -59
  116. data/spec/models/pageview_spec.rb +1 -1
  117. data/spec/models/properties_datastream_spec.rb +29 -10
  118. data/spec/models/proxy_deposit_request_spec.rb +107 -0
  119. data/spec/models/single_use_link_spec.rb +13 -13
  120. data/spec/models/solr_document_spec.rb +1 -1
  121. data/spec/models/trophy_spec.rb +6 -6
  122. data/spec/models/user_spec.rb +38 -22
  123. data/spec/routing/featured_works_route_spec.rb +1 -1
  124. data/spec/routing/ownership_transfers_route_spec.rb +45 -0
  125. data/spec/routing/route_spec.rb +42 -42
  126. data/spec/services/noid_spec.rb +2 -2
  127. data/spec/spec_helper.rb +10 -5
  128. data/spec/support/cleaner.rb +12 -0
  129. data/spec/support/features.rb +5 -0
  130. data/spec/support/features/session_helpers.rb +3 -17
  131. data/spec/support/locations.rb +36 -0
  132. data/spec/support/poltergeist.rb +11 -0
  133. data/spec/support/proxies.rb +14 -0
  134. data/spec/support/selectors.rb +122 -0
  135. data/spec/views/batch/edit.html.erb_spec.rb +1 -1
  136. data/spec/views/batch_edits/check_all_spec.rb +4 -4
  137. data/spec/views/catalog/index.html.erb_spec.rb +1 -1
  138. data/spec/views/catalog/sort_and_per_page.html.erb_spec.rb +1 -1
  139. data/spec/views/collections/_form.html.erb_spec.rb +3 -1
  140. data/spec/views/collections/_show_descriptions.html.erb_spec.rb +1 -1
  141. data/spec/views/dashboard/index_spec.rb +3 -6
  142. data/spec/views/generic_file/edit.html.erb_spec.rb +1 -1
  143. data/spec/views/generic_file/show.html.erb_spec.rb +1 -1
  144. data/spec/views/generic_file/stats.html.erb_spec.rb +1 -1
  145. data/spec/views/my/facet.html.erb_spec.rb +2 -2
  146. data/spec/views/users/_follower_modal.html.erb_spec.rb +1 -1
  147. data/spec/views/users/_following_modal.html.erb_spec.rb +1 -1
  148. data/spec/views/users/_notify_number.html.erb_spec.rb +1 -1
  149. data/spec/views/users/_user_util_links.html.erb_spec.rb +1 -1
  150. data/spec/views/users/index.html.erb_spec.rb +2 -2
  151. data/spec/views/users/show.html.erb_spec.rb +2 -2
  152. data/sufia-models/app/models/concerns/sufia/ability.rb +22 -0
  153. data/sufia-models/app/models/concerns/sufia/generic_file.rb +1 -0
  154. data/sufia-models/app/models/concerns/sufia/generic_file/proxy_deposit.rb +22 -0
  155. data/sufia-models/app/models/concerns/sufia/properties_datastream_behavior.rb +3 -0
  156. data/sufia-models/app/models/concerns/sufia/user.rb +9 -0
  157. data/sufia-models/app/models/proxy_deposit_request.rb +85 -0
  158. data/sufia-models/app/models/proxy_deposit_rights.rb +4 -0
  159. data/sufia-models/app/models/sufia/avatar_uploader.rb +2 -3
  160. data/sufia-models/lib/generators/sufia/models/install_generator.rb +9 -1
  161. data/sufia-models/lib/generators/sufia/models/proxies_generator.rb +53 -0
  162. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_proxy_deposit_requests.rb +16 -0
  163. data/sufia-models/lib/generators/sufia/models/templates/migrations/create_proxy_deposit_rights.rb +11 -0
  164. data/sufia-models/lib/sufia/models/engine.rb +1 -1
  165. data/sufia-models/lib/sufia/models/version.rb +1 -1
  166. data/sufia.gemspec +2 -1
  167. data/tasks/sufia-dev.rake +5 -0
  168. metadata +82 -6
  169. data/tasks/sufia-db.rake +0 -21
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe ContentBlocksController do
3
+ describe ContentBlocksController, :type => :controller do
4
4
  describe "#update" do
5
5
  let(:content_block) { FactoryGirl.create(:content_block) }
6
6
  before { request.env["HTTP_REFERER"] = "whence_i_came" }
@@ -14,10 +14,10 @@ describe ContentBlocksController do
14
14
 
15
15
  context "when logged in" do
16
16
  let(:user) { FactoryGirl.create(:user) }
17
- before { controller.stub(current_user: user) }
17
+ before { allow(controller).to receive_messages(current_user: user) }
18
18
 
19
19
  context "as a user in the admin group" do
20
- before { user.should_receive(:groups).and_return( ['admin', 'registered']) }
20
+ before { expect(user).to receive(:groups).and_return( ['admin', 'registered']) }
21
21
 
22
22
  it "should save" do
23
23
  patch :update, id: content_block, content_block: { value: 'foo' }
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe DashboardController do
3
+ describe DashboardController, :type => :controller do
4
4
 
5
5
  context "with an unauthenticated user" do
6
6
 
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ describe DepositorsController, :type => :controller do
4
+ let (:user) { FactoryGirl.find_or_create(:jill) }
5
+ let (:grantee) { FactoryGirl.find_or_create(:archivist) }
6
+
7
+ describe "as a logged in user" do
8
+ before do
9
+ sign_in user
10
+ end
11
+
12
+ describe "create" do
13
+ it "should be successful" do
14
+ expect { post :create, user_id: user.user_key, grantee_id: grantee.user_key, format: 'json' }.to change{ ProxyDepositRights.count }.by(1)
15
+ expect(response).to be_success
16
+ end
17
+
18
+ it "should not add current user" do
19
+ expect { post :create, user_id: user.user_key, grantee_id: user.user_key, format: 'json' }.to change{ ProxyDepositRights.count }.by(0)
20
+ expect(response).to be_success
21
+ expect(response.body).to be_blank
22
+ end
23
+ end
24
+
25
+ describe "destroy" do
26
+ before do
27
+ user.can_receive_deposits_from << grantee
28
+ end
29
+ it "should be successful" do
30
+ expect { delete :destroy, user_id: user.user_key, id: grantee.user_key, format: 'json' }.to change{ ProxyDepositRights.count }.by(-1)
31
+ end
32
+ end
33
+ end
34
+
35
+ describe "as a user without access" do
36
+ before do
37
+ sign_in FactoryGirl.create(:curator)
38
+ end
39
+ describe "create" do
40
+ it "should not be successful" do
41
+ expect { post :create, user_id: user, grantee_id: grantee, format: 'json' }.to raise_error
42
+ end
43
+ end
44
+ describe "destroy" do
45
+ it "should not be successful" do
46
+ expect { delete :destroy, user_id: user, id: grantee, format: 'json' }.to raise_error
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe DownloadsController do
3
+ describe DownloadsController, :type => :controller do
4
4
 
5
5
  describe "with a file" do
6
6
  before do
@@ -17,42 +17,42 @@ describe DownloadsController do
17
17
  describe "when logged in as reader" do
18
18
  before do
19
19
  sign_in FactoryGirl.find_or_create(:archivist)
20
- User.any_instance.stub(:groups).and_return([])
21
- controller.stub(:clear_session_user) ## Don't clear out the authenticated session
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
22
22
  end
23
23
  describe "show" do
24
24
  it "should default to returning configured default download" do
25
- DownloadsController.default_content_dsid.should == "content"
26
- controller.stub(:render) # send_data calls render internally
25
+ expect(DownloadsController.default_content_dsid).to eq("content")
26
+ allow(controller).to receive(:render) # send_data calls render internally
27
27
  expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
28
- controller.should_receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
28
+ expect(controller).to receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
29
29
  get "show", id: "test1"
30
- response.body.should == expected_content
31
- response.should be_success
30
+ expect(response.body).to eq(expected_content)
31
+ expect(response).to be_success
32
32
  end
33
33
  it "should return requested datastreams" do
34
- controller.stub(:render) # send_data calls render internally
34
+ allow(controller).to receive(:render) # send_data calls render internally
35
35
  expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).descMetadata.content
36
36
  expect(controller).to receive(:send_file_headers!).with(filename: 'descMetadata', disposition: 'inline', type: 'application/n-triples')
37
37
  get "show", id: "test1", datastream_id: "descMetadata"
38
- response.body.should == expected_content
39
- response.should be_success
38
+ expect(response.body).to eq(expected_content)
39
+ expect(response).to be_success
40
40
  end
41
41
  it "should support setting disposition to inline" do
42
- controller.stub(:render) # send_data calls render internally
42
+ allow(controller).to receive(:render) # send_data calls render internally
43
43
  expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
44
- controller.should_receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
44
+ expect(controller).to receive(:send_file_headers!).with({filename: 'world.png', disposition: 'inline', type: 'image/png' })
45
45
  get "show", id: "test1", disposition: "inline"
46
- response.body.should == expected_content
47
- response.should be_success
46
+ expect(response.body).to eq(expected_content)
47
+ expect(response).to be_success
48
48
  end
49
49
 
50
50
  it "should allow you to specify filename for download" do
51
- controller.stub(:render) # send_data calls render internally
51
+ allow(controller).to receive(:render) # send_data calls render internally
52
52
  expected_content = ActiveFedora::Base.find("sufia:test1", cast: true).content.content
53
- controller.should_receive(:send_file_headers!).with({filename: 'my%20dog.png', disposition: 'inline', type: 'image/png' })
53
+ expect(controller).to receive(:send_file_headers!).with({filename: 'my%20dog.png', disposition: 'inline', type: 'image/png' })
54
54
  get "show", id: "test1", "filename" => "my%20dog.png"
55
- response.body.should == expected_content
55
+ expect(response.body).to eq(expected_content)
56
56
  end
57
57
  end
58
58
  end
@@ -60,15 +60,15 @@ describe DownloadsController do
60
60
  describe "when not logged in as reader" do
61
61
  before do
62
62
  sign_in FactoryGirl.find_or_create(:jill)
63
- User.any_instance.stub(:groups).and_return([])
64
- controller.stub(:clear_session_user) ## Don't clear out the authenticated session
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
65
  end
66
66
 
67
67
  describe "show" do
68
68
  it "should deny access" do
69
69
  get "show", id: "test1"
70
- response.should redirect_to root_path
71
- flash[:alert].should == 'You are not authorized to access this page.'
70
+ expect(response).to redirect_to root_path
71
+ expect(flash[:alert]).to eq('You are not authorized to access this page.')
72
72
  end
73
73
  end
74
74
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FeaturedWorkListsController do
3
+ describe FeaturedWorkListsController, :type => :controller do
4
4
  describe "#create" do
5
5
  before do
6
6
  expect(controller).to receive(:authorize!).with(:update, FeaturedWork)
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe FeaturedWorksController do
3
+ describe FeaturedWorksController, :type => :controller do
4
4
  describe "#create" do
5
5
  before do
6
6
  sign_in FactoryGirl.create(:user)
@@ -1,35 +1,43 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe GenericFilesController do
3
+ describe GenericFilesController, :type => :controller do
4
4
  before do
5
- controller.stub(:has_access?).and_return(true)
5
+ allow(controller).to receive(:has_access?).and_return(true)
6
6
  @user = FactoryGirl.find_or_create(:jill)
7
7
  sign_in @user
8
- User.any_instance.stub(:groups).and_return([])
9
- controller.stub(:clear_session_user) ## Don't clear out the authenticated session
8
+ allow_any_instance_of(User).to receive(:groups).and_return([])
9
+ allow(controller).to receive(:clear_session_user) ## Don't clear out the authenticated session
10
10
  end
11
11
 
12
12
  describe "#create" do
13
13
  before do
14
14
  @file_count = GenericFile.count
15
- @mock = GenericFile.new({pid: 'test:123'})
16
- GenericFile.stub(:new).and_return(@mock)
15
+ @mock = GenericFile.new({ pid: 'test:123' })
16
+ allow(GenericFile).to receive(:new).and_return(@mock)
17
17
  end
18
18
 
19
19
  after do
20
20
  begin
21
- GenericFile.unstub(:new)
21
+ allow(GenericFile).to receive(:new).and_call_original
22
22
  rescue RSpec::Mocks::MockExpectationError => e
23
23
  end
24
24
  Batch.find("sample:batch_id").delete rescue
25
25
  @mock.delete unless @mock.inner_object.class == ActiveFedora::UnsavedDigitalObject
26
26
  end
27
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
+
28
36
  it "should render error the file wasn't actually a file" do
29
37
  file = 'hello'
30
38
  xhr :post, :create, files: [file], Filename: "The World", batch_id: 'sample:batch_id', permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
31
- response.status.should == 422
32
- JSON.parse(response.body).first['error'].should match(/no file for upload/i)
39
+ expect(response.status).to eq(422)
40
+ expect(JSON.parse(response.body).first['error']).to match(/no file for upload/i)
33
41
  end
34
42
 
35
43
  it "spawns a content deposit event job" do
@@ -47,30 +55,30 @@ describe GenericFilesController do
47
55
 
48
56
  it "displays a flash error when file has a virus" do
49
57
  file = fixture_file_upload('/world.png', 'image/png')
50
- Sufia::GenericFile::Actor.should_receive(:virus_check).with(file.path).and_raise(Sufia::VirusFoundError.new('A virus was found'))
58
+ expect(Sufia::GenericFile::Actor).to receive(:virus_check).with(file.path).and_raise(Sufia::VirusFoundError.new('A virus was found'))
51
59
  xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
52
- flash[:error].should_not be_blank
53
- flash[:error].should include('A virus was found')
60
+ expect(flash[:error]).not_to be_blank
61
+ expect(flash[:error]).to include('A virus was found')
54
62
  end
55
63
 
56
64
  it "should create and save a file asset from the given params" do
57
65
  date_today = Date.today
58
- Date.stub(:today).and_return(date_today)
66
+ allow(Date).to receive(:today).and_return(date_today)
59
67
  file = fixture_file_upload('/world.png','image/png')
60
68
  xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: '1'
61
- response.should be_success
62
- GenericFile.count.should == @file_count + 1
69
+ expect(response).to be_success
70
+ expect(GenericFile.count).to eq(@file_count + 1)
63
71
 
64
72
  saved_file = GenericFile.find('test:123')
65
73
 
66
74
  # This is confirming that the correct file was attached
67
- saved_file.label.should == 'world.png'
68
- saved_file.content.checksum.should == 'f794b23c0c6fe1083d0ca8b58261a078cd968967'
75
+ expect(saved_file.label).to eq('world.png')
76
+ expect(saved_file.content.checksum).to eq('f794b23c0c6fe1083d0ca8b58261a078cd968967')
69
77
  expect(saved_file.content.dsChecksumValid).to be true
70
78
 
71
79
  # Confirming that date_uploaded and date_modified were set
72
- saved_file.date_uploaded.should == date_today
73
- saved_file.date_modified.should == date_today
80
+ expect(saved_file.date_uploaded).to eq(date_today)
81
+ expect(saved_file.date_modified).to eq(date_today)
74
82
  end
75
83
 
76
84
  it "should record what user created the first version of content" do
@@ -78,47 +86,47 @@ describe GenericFilesController do
78
86
  xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
79
87
  saved_file = GenericFile.find('test:123')
80
88
  version = saved_file.content.latest_version
81
- version.versionID.should == "content.0"
82
- saved_file.content.version_committer(version).should == @user.user_key
89
+ expect(version.versionID).to eq("content.0")
90
+ expect(saved_file.content.version_committer(version)).to eq(@user.user_key)
83
91
  end
84
92
 
85
93
  it "should create batch associations from batch_id" do
86
- Sufia.config.stub(:id_namespace).and_return('sample')
94
+ allow(Sufia.config).to receive(:id_namespace).and_return('sample')
87
95
  file = fixture_file_upload('/world.png','image/png')
88
- controller.stub(:add_posted_blob_to_asset)
96
+ allow(controller).to receive(:add_posted_blob_to_asset)
89
97
  xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
90
- GenericFile.unstub(:new)
91
- lambda {Batch.find("sample:batch_id")}.should raise_error(ActiveFedora::ObjectNotFoundError) # The controller shouldn't actually save the Batch, but it should write the batch id to the files.
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.
92
100
  batch = Batch.create(pid: "sample:batch_id")
93
- batch.generic_files.first.pid.should == "test:123"
101
+ expect(batch.generic_files.first.pid).to eq("test:123")
94
102
  end
95
103
  it "should set the depositor id" do
96
104
  file = fixture_file_upload('/world.png','image/png')
97
105
  xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
98
- response.should be_success
106
+ expect(response).to be_success
99
107
 
100
108
  saved_file = GenericFile.find('test:123')
101
109
  # This is confirming that apply_depositor_metadata recorded the depositor
102
110
  #TODO make sure this is moved to scholarsphere:
103
111
  #saved_file.properties.depositor.should == ['jilluser']
104
- saved_file.properties.depositor.should == ['jilluser@example.com']
112
+ expect(saved_file.properties.depositor).to eq(['jilluser@example.com'])
105
113
  #TODO make sure this is moved to scholarsphere:
106
114
  #saved_file.depositor.should == 'jilluser'
107
- saved_file.depositor.should == 'jilluser@example.com'
108
- saved_file.properties.to_solr.keys.should include('depositor_tesim')
115
+ expect(saved_file.depositor).to eq('jilluser@example.com')
116
+ expect(saved_file.properties.to_solr.keys).to include('depositor_tesim')
109
117
  #TODO make sure this is moved to scholarsphere:
110
118
  #saved_file.properties.to_solr['depositor_t'].should == ['jilluser']
111
- saved_file.properties.to_solr['depositor_tesim'].should == ['jilluser@example.com']
112
- saved_file.to_solr.keys.should include('depositor_tesim')
113
- saved_file.to_solr['depositor_tesim'].should == ['jilluser@example.com']
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'])
114
122
  end
115
123
 
116
124
  it "should error out of create and save after on continuos rsolr error" do
117
- GenericFile.any_instance.stub(:save).and_raise(RSolr::Error::Http.new({},{}))
125
+ allow_any_instance_of(GenericFile).to receive(:save).and_raise(RSolr::Error::Http.new({},{}))
118
126
 
119
127
  file = fixture_file_upload('/world.png','image/png')
120
128
  xhr :post, :create, files: [file], Filename: "The world", batch_id: "sample:batch_id", permission: {"group"=>{"public"=>"read"} }, terms_of_service: "1"
121
- response.body.should include("Error occurred while creating generic file.")
129
+ expect(response.body).to include("Error occurred while creating generic file.")
122
130
  end
123
131
  end
124
132
 
@@ -128,8 +136,8 @@ describe GenericFilesController do
128
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"}}
129
137
  end
130
138
  it "should ingest files from provide URLs" do
131
- ImportUrlJob.should_receive(:new).twice {"ImportJob"}
132
- Sufia.queue.should_receive(:push).with("ImportJob").twice
139
+ expect(ImportUrlJob).to receive(:new).twice {"ImportJob"}
140
+ expect(Sufia.queue).to receive(:push).with("ImportJob").twice
133
141
  expect { post :create, selected_files: @json_from_browse_everything, batch_id: "sample:batch_id" }.to change(GenericFile, :count).by(2)
134
142
  created_files = GenericFile.all
135
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|
@@ -157,59 +165,59 @@ describe GenericFilesController do
157
165
  end
158
166
  after do
159
167
  Sufia.config.enable_local_ingest = false
160
- FileContentDatastream.any_instance.stub(:live?).and_return(true)
168
+ allow_any_instance_of(FileContentDatastream).to receive(:live?).and_return(true)
161
169
  GenericFile.destroy_all
162
170
  end
163
171
  context "when User model defines a directory path" do
164
172
  before do
165
173
  if $in_travis
166
174
  # In order to avoid an invalid derivative creation, just stub out the derivatives.
167
- GenericFile.any_instance.stub(:create_derivatives)
175
+ allow_any_instance_of(GenericFile).to receive(:create_derivatives)
168
176
  end
169
- User.any_instance.stub(:directory).and_return(@mock_upload_directory)
177
+ allow_any_instance_of(User).to receive(:directory).and_return(@mock_upload_directory)
170
178
  end
171
179
  it "should ingest files from the filesystem" do
172
- lambda { post :create, local_file: ["world.png", "image.jpg"], batch_id: "xw42n7934"}.should change(GenericFile, :count).by(2)
173
- response.should redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path('xw42n7934')
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')
174
182
  # These files should have been moved out of the upload directory
175
183
  expect(File).not_to exist("#{@mock_upload_directory}/image.jpg")
176
184
  expect(File).not_to exist("#{@mock_upload_directory}/world.png")
177
185
  # And into the storage directory
178
186
  files = GenericFile.find(Solrizer.solr_name("is_part_of",:symbol) => 'info:fedora/sufia:xw42n7934')
179
- files.first.label.should == 'world.png'
180
- files.last.label.should == 'image.jpg'
187
+ expect(files.first.label).to eq('world.png')
188
+ expect(files.last.label).to eq('image.jpg')
181
189
  end
182
190
  it "should ingest redirect to another location" do
183
- GenericFilesController.should_receive(:upload_complete_path).and_return(mock_url)
184
- lambda { post :create, local_file: ["world.png"], batch_id: "xw42n7934"}.should change(GenericFile, :count).by(1)
185
- response.should redirect_to mock_url
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
186
194
  # These files should have been moved out of the upload directory
187
195
  expect(File).not_to exist("#{@mock_upload_directory}/world.png")
188
196
  # And into the storage directory
189
197
  files = GenericFile.find(Solrizer.solr_name("is_part_of",:symbol) => 'info:fedora/sufia:xw42n7934')
190
- files.first.label.should == 'world.png'
198
+ expect(files.first.label).to eq('world.png')
191
199
  end
192
200
  it "should ingest directories from the filesystem" do
193
- lambda { post :create, local_file: ["world.png", "import"], batch_id: "xw42n7934"}.should change(GenericFile, :count).by(4)
194
- response.should redirect_to Sufia::Engine.routes.url_helpers.batch_edit_path('xw42n7934')
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')
195
203
  # These files should have been moved out of the upload directory
196
204
  expect(File).not_to exist("#{@mock_upload_directory}/import/files/icons.zip")
197
205
  expect(File).not_to exist("#{@mock_upload_directory}/import/metadata/dublin_core_rdf_descMetadata.nt")
198
206
  expect(File).not_to exist("#{@mock_upload_directory}/world.png")
199
207
  # And into the storage directory
200
208
  files = GenericFile.find(Solrizer.solr_name("is_part_of",:symbol) => 'info:fedora/sufia:xw42n7934')
201
- files.first.label.should == 'world.png'
209
+ expect(files.first.label).to eq('world.png')
202
210
  ['icons.zip', 'Example.ogg'].each do |filename|
203
- files.select{|f| f.label == filename}.first.relative_path.should == "import/files/#{filename}"
211
+ expect(files.select{|f| f.label == filename}.first.relative_path).to eq("import/files/#{filename}")
204
212
  end
205
- files.select{|f| f.label == 'dublin_core_rdf_descMetadata.nt'}.first.relative_path.should == 'import/metadata/dublin_core_rdf_descMetadata.nt'
213
+ expect(files.select{|f| f.label == 'dublin_core_rdf_descMetadata.nt'}.first.relative_path).to eq('import/metadata/dublin_core_rdf_descMetadata.nt')
206
214
  end
207
215
  end
208
216
  context "when User model does not define directory path" do
209
217
  it "should return an error message and redirect to file upload page" do
210
- lambda { post :create, local_file: ["world.png", "image.jpg"], batch_id: "xw42n7934"}.should_not change(GenericFile, :count)
211
- response.should render_template :new
212
- flash[:alert].should == 'Your account is not configured for importing files from a user-directory on the server.'
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.')
213
221
  end
214
222
  end
215
223
  end
@@ -226,8 +234,8 @@ describe GenericFilesController do
226
234
  end
227
235
  it "should return json with the result" do
228
236
  xhr :post, :audit, id: @generic_file.pid
229
- response.should be_success
230
- lambda { JSON.parse(response.body) }.should_not raise_error
237
+ expect(response).to be_success
238
+ expect { JSON.parse(response.body) }.not_to raise_error
231
239
  audit_results = JSON.parse(response.body).collect { |result| result["pass"] }
232
240
  expect(audit_results.reduce(true) { |sum, value| sum && value }).to be_truthy
233
241
  end
@@ -245,14 +253,14 @@ describe GenericFilesController do
245
253
  @user.delete
246
254
  end
247
255
  it "should delete the file" do
248
- GenericFile.find(@generic_file.pid).should_not be_nil
256
+ expect(GenericFile.find(@generic_file.pid)).not_to be_nil
249
257
  delete :destroy, id: @generic_file.pid
250
- lambda { GenericFile.find(@generic_file.pid) }.should raise_error(ActiveFedora::ObjectNotFoundError)
258
+ expect { GenericFile.find(@generic_file.pid) }.to raise_error(ActiveFedora::ObjectNotFoundError)
251
259
  end
252
260
  it "should spawn a content delete event job" do
253
261
  s1 = double('one')
254
- ContentDeleteEventJob.should_receive(:new).with(@generic_file.pid, @user.user_key).and_return(s1)
255
- Sufia.queue.should_receive(:push).with(s1).once
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
256
264
  delete :destroy, id: @generic_file.pid
257
265
  end
258
266
 
@@ -350,8 +358,8 @@ describe GenericFilesController do
350
358
 
351
359
  it "should spawn a content update event job" do
352
360
  s1 = double('one')
353
- ContentUpdateEventJob.should_receive(:new).with(generic_file.pid, 'jilluser@example.com').and_return(s1)
354
- Sufia.queue.should_receive(:push).with(s1).once
361
+ expect(ContentUpdateEventJob).to receive(:new).with(generic_file.pid, 'jilluser@example.com').and_return(s1)
362
+ expect(Sufia.queue).to receive(:push).with(s1).once
355
363
  @user = FactoryGirl.find_or_create(:jill)
356
364
  sign_in @user
357
365
  post :update, id: generic_file, generic_file: {title: ['new_title'], tag: [''], permissions: { new_user_name: {'archivist1'=>'edit'}}}
@@ -383,24 +391,24 @@ describe GenericFilesController do
383
391
 
384
392
  posted_file = GenericFile.find(generic_file.pid)
385
393
  version1 = posted_file.content.latest_version
386
- posted_file.content.version_committer(version1).should == @user.user_key
394
+ expect(posted_file.content.version_committer(version1)).to eq(@user.user_key)
387
395
 
388
396
  file = fixture_file_upload('/image.jpg','image/jpg')
389
397
  post :update, id: generic_file, filedata: file, generic_file: { tag: [''], permissions: { new_user_name: { 'archivist1@example.com'=>'edit' } } }
390
398
 
391
399
  posted_file = GenericFile.find(generic_file.pid)
392
400
  version2 = posted_file.content.latest_version
393
- posted_file.content.version_committer(version2).should == @user.user_key
401
+ expect(posted_file.content.version_committer(version2)).to eq(@user.user_key)
394
402
 
395
- posted_file.content.mimeType.should == "image/jpeg"
403
+ expect(posted_file.content.mimeType).to eq("image/jpeg")
396
404
  post :update, id: generic_file, revision: 'content.0'
397
405
 
398
406
  restored_file = GenericFile.find(generic_file.pid)
399
407
  version3 = restored_file.content.latest_version
400
- version3.versionID.should_not == version2.versionID
401
- version3.versionID.should_not == version1.versionID
402
- restored_file.content.version_committer(version3).should == @user.user_key
403
- restored_file.content.mimeType.should == "image/png"
408
+ expect(version3.versionID).not_to eq(version2.versionID)
409
+ expect(version3.versionID).not_to eq(version1.versionID)
410
+ expect(restored_file.content.version_committer(version3)).to eq(@user.user_key)
411
+ expect(restored_file.content.mimeType).to eq("image/png")
404
412
  @user.delete
405
413
  end
406
414
 
@@ -472,8 +480,8 @@ describe GenericFilesController do
472
480
  post :update, id: generic_file, generic_file: { tag: [''], permissions:
473
481
  { new_group_name: { 'group1' => 'read' }, new_user_name: { 'user1' => 'edit' }}}
474
482
 
475
- assigns[:generic_file].read_groups.should == ["group1"]
476
- assigns[:generic_file].edit_users.should include("user1", @user.user_key)
483
+ expect(assigns[:generic_file].read_groups).to eq(["group1"])
484
+ expect(assigns[:generic_file].edit_users).to include("user1", @user.user_key)
477
485
  end
478
486
  it "should update existing groups and users" do
479
487
  generic_file.read_groups = ['group3']
@@ -481,7 +489,7 @@ describe GenericFilesController do
481
489
  post :update, id: generic_file, generic_file: { tag: [''], permissions:
482
490
  { new_group_name: '', new_group_permission: '', new_user_name: '', new_user_permission: '', group: { 'group3' => 'read' }}}
483
491
 
484
- assigns[:generic_file].read_groups.should == ["group3"]
492
+ expect(assigns[:generic_file].read_groups).to eq(["group3"])
485
493
  end
486
494
 
487
495
  it "spawns a virus check" do
@@ -508,10 +516,10 @@ describe GenericFilesController do
508
516
  end
509
517
  end
510
518
  it "redirects to edit" do
511
- GenericFile.any_instance.should_receive(:valid?).and_return(false)
519
+ expect_any_instance_of(GenericFile).to receive(:valid?).and_return(false)
512
520
  post :update, id: generic_file, generic_file: {:tag=>['']}
513
- response.should be_successful
514
- response.should render_template('edit')
521
+ expect(response).to be_successful
522
+ expect(response).to render_template('edit')
515
523
  expect(assigns[:generic_file]).to eq generic_file
516
524
  end
517
525
  end
@@ -534,17 +542,17 @@ describe GenericFilesController do
534
542
  describe "edit" do
535
543
  it "should give me a flash error" do
536
544
  get :edit, id: "test5"
537
- response.should redirect_to @routes.url_helpers.generic_file_path('test5')
538
- flash[:alert].should_not be_nil
539
- flash[:alert].should_not be_empty
540
- flash[:alert].should include("You do not have sufficient privileges to edit this document")
545
+ expect(response).to redirect_to @routes.url_helpers.generic_file_path('test5')
546
+ expect(flash[:alert]).not_to be_nil
547
+ expect(flash[:alert]).not_to be_empty
548
+ expect(flash[:alert]).to include("You do not have sufficient privileges to edit this document")
541
549
  end
542
550
  end
543
551
  describe "view" do
544
552
  it "should show me the file" do
545
553
  get :show, id: "test5"
546
- response.should_not redirect_to(action: 'show')
547
- flash[:alert].should be_nil
554
+ expect(response).not_to redirect_to(action: 'show')
555
+ expect(flash[:alert]).to be_nil
548
556
  end
549
557
  it "should set the breadcrumbs" do
550
558
  expect(controller).to receive(:add_breadcrumb).with(I18n.t('sufia.dashboard.title'), Sufia::Engine.routes.url_helpers.dashboard_index_path)
@@ -555,26 +563,26 @@ describe GenericFilesController do
555
563
  it "should not let the user submit if they logout" do
556
564
  sign_out @user
557
565
  get :new
558
- response.should_not be_success
559
- flash[:alert].should_not be_nil
560
- flash[:alert].should include("You need to sign in or sign up before continuing")
566
+ expect(response).not_to be_success
567
+ expect(flash[:alert]).not_to be_nil
568
+ expect(flash[:alert]).to include("You need to sign in or sign up before continuing")
561
569
  end
562
570
  it "should filter flash if they signin" do
563
571
  sign_in @user
564
572
  get :show, id: "test5"
565
- flash[:alert].should be_nil
573
+ expect(flash[:alert]).to be_nil
566
574
  end
567
575
  describe "failing audit" do
568
576
  before do
569
- ActiveFedora::RelsExtDatastream.any_instance.stub(:dsChecksumValid).and_return(false)
577
+ allow_any_instance_of(ActiveFedora::RelsExtDatastream).to receive(:dsChecksumValid).and_return(false)
570
578
  @archivist = FactoryGirl.find_or_create(:archivist)
571
579
  end
572
580
  it "should display failing audits" do
573
581
  sign_in @archivist
574
582
  AuditJob.new(@file.pid, "RELS-EXT", @file.rels_ext.versionID).run
575
583
  get :show, id: "test5"
576
- assigns[:notify_number].should == 1
577
- @archivist.mailbox.inbox[0].messages[0].subject.should == "Failing Audit Run"
584
+ expect(assigns[:notify_number]).to eq(1)
585
+ expect(@archivist.mailbox.inbox[0].messages[0].subject).to eq("Failing Audit Run")
578
586
  end
579
587
  end
580
588
  end