curation_concerns 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +8 -0
  4. data/Gemfile +1 -2
  5. data/README.md +1 -1
  6. data/Rakefile +1 -1
  7. data/VERSION +1 -1
  8. data/app/assets/javascripts/curation_concerns/curation_concerns.js +2 -0
  9. data/app/assets/javascripts/curation_concerns/uploader.js +4 -4
  10. data/app/assets/stylesheets/curation_concerns/_modules.scss +1 -0
  11. data/app/assets/stylesheets/curation_concerns/_positioning.scss +3 -0
  12. data/app/assets/stylesheets/curation_concerns/modules/icons.scss +11 -0
  13. data/app/controllers/concerns/curation_concerns/api.rb +1 -12
  14. data/app/controllers/concerns/curation_concerns/application_controller_behavior.rb +20 -6
  15. data/app/controllers/concerns/curation_concerns/curation_concern_controller.rb +44 -25
  16. data/app/controllers/concerns/curation_concerns/file_sets_controller_behavior.rb +32 -23
  17. data/app/controllers/concerns/curation_concerns/parent_container.rb +0 -11
  18. data/app/controllers/concerns/curation_concerns/single_use_links_controller_behavior.rb +1 -1
  19. data/app/controllers/concerns/curation_concerns/single_use_links_viewer_controller_behavior.rb +7 -1
  20. data/app/controllers/concerns/curation_concerns/upload_sets_controller_behavior.rb +19 -7
  21. data/app/controllers/curation_concerns/permissions_controller.rb +1 -1
  22. data/app/forms/curation_concerns/forms/collection_edit_form.rb +6 -2
  23. data/app/forms/curation_concerns/forms/work_form.rb +14 -3
  24. data/app/forms/curation_concerns/upload_set_form.rb +43 -0
  25. data/app/helpers/curation_concerns/ability_helper.rb +12 -18
  26. data/app/helpers/curation_concerns/file_set_helper.rb +1 -1
  27. data/app/helpers/curation_concerns/main_app_helpers.rb +1 -0
  28. data/app/helpers/curation_concerns/permissions_helper.rb +20 -0
  29. data/app/helpers/curation_concerns/url_helper.rb +3 -11
  30. data/app/inputs/multi_value_with_help_input.rb +8 -0
  31. data/app/inputs/select_with_help_input.rb +3 -0
  32. data/app/inputs/select_with_modal_help_input.rb +36 -0
  33. data/app/inputs/with_help_icon.rb +34 -0
  34. data/app/presenters/curation_concerns/collection_presenter.rb +9 -0
  35. data/app/presenters/curation_concerns/file_set_presenter.rb +2 -1
  36. data/app/presenters/curation_concerns/presents_attributes.rb +16 -0
  37. data/app/presenters/curation_concerns/work_show_presenter.rb +3 -2
  38. data/app/renderers/curation_concerns/attribute_renderer.rb +22 -4
  39. data/app/renderers/curation_concerns/configured_microdata.rb +40 -0
  40. data/app/services/curation_concerns/parent_service.rb +1 -1
  41. data/app/views/catalog/_action_menu_partials/_default.html.erb +2 -2
  42. data/app/views/collections/_form.html.erb +8 -9
  43. data/app/views/collections/_sort_and_per_page.html.erb +25 -23
  44. data/app/views/collections/show.html.erb +1 -1
  45. data/app/views/curation_concerns/base/_attributes.html.erb +1 -1
  46. data/app/views/curation_concerns/base/_form.html.erb +6 -7
  47. data/app/views/curation_concerns/base/_form_permission.html.erb +3 -0
  48. data/app/views/curation_concerns/base/_multiple_upload.html.erb +3 -0
  49. data/app/views/curation_concerns/base/_show_actions.html.erb +2 -2
  50. data/app/views/curation_concerns/base/_versioning.html.erb +1 -1
  51. data/app/views/curation_concerns/base/_visibility.html.erb +17 -0
  52. data/app/views/curation_concerns/base/show.html.erb +1 -1
  53. data/app/views/curation_concerns/classify_concerns/new.html.erb +1 -1
  54. data/app/views/curation_concerns/file_sets/_actions.html.erb +2 -2
  55. data/app/views/curation_concerns/file_sets/_form.html.erb +1 -1
  56. data/app/views/curation_concerns/file_sets/_rights_modal.html.erb +41 -0
  57. data/app/views/curation_concerns/file_sets/media_display/_default.html.erb +4 -1
  58. data/app/views/curation_concerns/file_sets/media_display/_image.html.erb +9 -8
  59. data/app/views/curation_concerns/file_sets/media_display/_office_document.html.erb +9 -7
  60. data/app/views/curation_concerns/file_sets/media_display/_pdf.html.erb +7 -5
  61. data/app/views/curation_concerns/file_sets/show.html.erb +2 -2
  62. data/app/views/curation_concerns/file_sets/upload/_alerts.html.erb +3 -3
  63. data/app/views/curation_concerns/file_sets/upload/_form.html.erb +1 -1
  64. data/app/views/curation_concerns/file_sets/upload/_script_templates.html.erb +1 -1
  65. data/app/views/curation_concerns/permissions/confirm.html.erb +1 -1
  66. data/app/views/curation_concerns/single_use_links_viewer/show.html.erb +1 -1
  67. data/app/views/embargoes/edit.html.erb +4 -4
  68. data/app/views/layouts/curation_concerns.html.erb +1 -1
  69. data/app/views/leases/edit.html.erb +3 -3
  70. data/app/views/shared/_add_works.html.erb +6 -3
  71. data/app/views/upload_sets/_base_metadata.html.erb +12 -0
  72. data/app/views/upload_sets/_metadata.html.erb +3 -13
  73. data/app/views/upload_sets/edit.html.erb +1 -1
  74. data/config/locales/curation_concerns.en.yml +46 -0
  75. data/curation_concerns.gemspec +5 -4
  76. data/lib/curation_concerns/engine.rb +5 -0
  77. data/lib/curation_concerns/form_builder.rb +16 -0
  78. data/lib/curation_concerns/rails/routes.rb +7 -5
  79. data/lib/generators/curation_concerns/install_generator.rb +1 -1
  80. data/lib/generators/curation_concerns/work/work_generator.rb +1 -1
  81. data/spec/actors/curation_concerns/file_set_actor_spec.rb +26 -16
  82. data/spec/controllers/curation_concerns/file_sets_controller_json_spec.rb +14 -4
  83. data/spec/controllers/curation_concerns/file_sets_controller_spec.rb +3 -3
  84. data/spec/controllers/curation_concerns/generic_works_controller_json_spec.rb +4 -4
  85. data/spec/controllers/curation_concerns/generic_works_controller_spec.rb +21 -0
  86. data/spec/controllers/curation_concerns/single_use_links_controller_spec.rb +2 -2
  87. data/spec/controllers/curation_concerns/single_use_links_viewer_controller_spec.rb +1 -1
  88. data/spec/controllers/upload_sets_controller_spec.rb +20 -27
  89. data/spec/factories/file_sets.rb +1 -0
  90. data/spec/factories/generic_works.rb +1 -0
  91. data/spec/factories/users.rb +0 -12
  92. data/spec/features/collection_spec.rb +1 -3
  93. data/spec/forms/collection_edit_form_spec.rb +16 -1
  94. data/spec/forms/upload_set_form_spec.rb +55 -0
  95. data/spec/forms/work_form_spec.rb +68 -3
  96. data/spec/helpers/curation_concerns/ability_helper_spec.rb +45 -0
  97. data/spec/helpers/curation_concerns/permissions_helper_spec.rb +12 -0
  98. data/spec/helpers/url_helper_spec.rb +0 -3
  99. data/spec/indexers/collection_indexer_spec.rb +5 -0
  100. data/spec/indexers/{file_set_indexing_service_spec.rb → file_set_indexer_spec.rb} +40 -2
  101. data/spec/indexers/{generic_work_indexing_service_spec.rb → work_indexer_spec.rb} +1 -1
  102. data/spec/inputs/multi_value_with_help_input_spec.rb +32 -0
  103. data/spec/inputs/select_with_help_input_spec.rb +43 -0
  104. data/spec/inputs/select_with_modal_help_input_spec.rb +21 -0
  105. data/spec/jobs/import_url_job_spec.rb +33 -1
  106. data/spec/jobs/ingest_file_job_spec.rb +29 -16
  107. data/spec/jobs/upload_set_update_job_spec.rb +24 -11
  108. data/spec/lib/curation_concerns/messages_spec.rb +2 -2
  109. data/spec/lib/curation_concerns/name_spec.rb +20 -0
  110. data/spec/lib/curation_concerns/null_logger_spec.rb +10 -0
  111. data/spec/models/curation_concerns/collection_behavior_spec.rb +41 -10
  112. data/spec/models/curation_concerns/work_behavior_spec.rb +1 -13
  113. data/spec/models/file_set_spec.rb +19 -4
  114. data/spec/models/generic_work_spec.rb +7 -2
  115. data/spec/models/quick_classification_query_spec.rb +35 -0
  116. data/spec/models/upload_set_spec.rb +5 -7
  117. data/spec/presenters/curation_concerns/collection_presenter_spec.rb +20 -0
  118. data/spec/presenters/curation_concerns/file_set_presenter_spec.rb +10 -3
  119. data/spec/presenters/curation_concerns/work_show_presenter_spec.rb +13 -1
  120. data/spec/renderers/curation_concerns/attribute_renderer_spec.rb +41 -8
  121. data/spec/routing/curation_concerns/routes_spec.rb +2 -2
  122. data/spec/routing/route_spec.rb +1 -1
  123. data/spec/services/file_set_audit_service_spec.rb +46 -4
  124. data/spec/spec_helper.rb +5 -7
  125. data/spec/views/collections/_sort_and_per_page.html.erb_spec.rb +32 -0
  126. data/spec/views/curation_concerns/base/_attributes.html.erb_spec.rb +8 -1
  127. data/spec/views/curation_concerns/base/show.html.erb_spec.rb +36 -2
  128. data/spec/views/curation_concerns/file_sets/_file_set.html.erb_spec.rb +3 -2
  129. data/spec/views/curation_concerns/file_sets/show.html.erb_spec.rb +56 -0
  130. data/spec/views/curation_concerns/single_use_links_viewer/show.html.erb_spec.rb +19 -0
  131. data/spec/views/shared/_add_content.html.erb_spec.rb +3 -3
  132. data/spec/views/single_use_links/new_download.html.erb_spec.rb +1 -1
  133. data/spec/views/upload_sets/_metadata.html.erb_spec.rb +28 -0
  134. metadata +80 -50
  135. data/app/assets/stylesheets/curation_concerns/help_requests.scss +0 -3
  136. data/app/controllers/concerns/curation_concerns/without_namespace.rb +0 -16
  137. data/app/controllers/registrations_controller.rb +0 -19
  138. data/app/controllers/sessions_controller.rb +0 -4
  139. data/app/views/curation_concerns/file_sets/_multiple_upload.html.erb +0 -3
  140. data/spec/fixtures/Example.ogg +0 -0
  141. data/spec/fixtures/charter.docx +0 -0
  142. data/spec/fixtures/countdown.avi +0 -0
  143. data/spec/fixtures/curation_concerns_generic_stub.txt +0 -1
  144. data/spec/fixtures/empty_file.txt +0 -0
  145. data/spec/fixtures/files/image.png +0 -0
  146. data/spec/fixtures/image.jp2 +0 -0
  147. data/spec/fixtures/image.jpg +0 -0
  148. data/spec/fixtures/piano_note.wav +0 -0
  149. data/spec/fixtures/sample_mpeg4.mp4 +0 -0
  150. data/spec/fixtures/small_file.txt +0 -1
  151. data/spec/fixtures/spoken-text.m4a +0 -0
  152. data/spec/fixtures/test.pdf +0 -0
  153. data/spec/fixtures/test4.pdf +0 -0
  154. data/spec/fixtures/test5.mp3 +0 -0
  155. data/spec/fixtures/world.png +0 -0
@@ -1,28 +1,26 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe UploadSet do
4
- let(:user) { FactoryGirl.find_or_create(:jill) }
5
- let(:upload_set) { described_class.create(title: ["test collection"], creator: [user.user_key]) }
4
+ let(:user) { create(:user) }
5
+ let(:upload_set) { described_class.create(title: ["test collection"]) }
6
6
  subject { upload_set }
7
7
 
8
8
  it "has dc metadata" do
9
- expect(subject.creator).to eq [user.user_key]
10
9
  expect(subject.title).to eq ["test collection"]
11
10
  end
12
11
 
13
- it "responds to .file_sets" do
14
- expect(subject).to respond_to(:file_sets)
12
+ it "responds to #works" do
13
+ expect(subject).to respond_to(:works)
15
14
  end
16
15
 
17
16
  it "supports to_solr" do
18
17
  expect(subject.to_solr).to_not be_nil
19
18
  expect(subject.to_solr["upload_set__title_t"]).to be_nil
20
- expect(subject.to_solr["upload_set__creator_t"]).to be_nil
21
19
  end
22
20
 
23
21
  describe "find_or_create" do
24
22
  describe "when the object exists" do
25
- let!(:upload_set) { described_class.create(title: ["test collection"], creator: [user.user_key]) }
23
+ let!(:upload_set) { described_class.create(title: ["test collection"]) }
26
24
  it "finds upload_set instead of creating" do
27
25
  expect(described_class).to_not receive(:create)
28
26
  described_class.find_or_create(subject.id)
@@ -2,10 +2,14 @@ require 'spec_helper'
2
2
 
3
3
  describe CurationConcerns::CollectionPresenter do
4
4
  let(:collection) { Collection.new(id: 'adc12v', description: 'a nice collection', title: 'A clever title') }
5
+ let(:work) { FactoryGirl.build(:work, title: ['unimaginitive title']) }
5
6
  let(:solr_document) { SolrDocument.new(collection.to_solr) }
6
7
  let(:ability) { double }
7
8
  let(:presenter) { described_class.new(solr_document, ability) }
8
9
 
10
+ # Mock bytes so collection does not have to be saved.
11
+ before { allow(collection).to receive(:bytes).and_return(0) }
12
+
9
13
  describe '#title' do
10
14
  subject { presenter.title }
11
15
  it { is_expected.to eq 'A clever title' }
@@ -15,4 +19,20 @@ describe CurationConcerns::CollectionPresenter do
15
19
  subject { presenter.to_key }
16
20
  it { is_expected.to eq ['adc12v'] }
17
21
  end
22
+
23
+ describe "#size" do
24
+ subject { presenter.size }
25
+ it { is_expected.to eq '0 Bytes' }
26
+ end
27
+
28
+ describe "#total_items" do
29
+ subject { presenter.total_items }
30
+ context "empty collection" do
31
+ it { is_expected.to eq 0 }
32
+ end
33
+ context "collection with work" do
34
+ before { collection.members << work }
35
+ it { is_expected.to eq 1 }
36
+ end
37
+ end
18
38
  end
@@ -43,10 +43,17 @@ describe CurationConcerns::FileSetPresenter do
43
43
  it { is_expected.to eq 'File Set' }
44
44
  end
45
45
 
46
- describe "date_uploaded" do
46
+ describe "properties delegated to solr_document" do
47
+ let(:solr_properties) do
48
+ ["date_uploaded", "depositor", "tags", "title_or_label",
49
+ "contributor", "creator", "title", "description", "publisher",
50
+ "subject", "language", "rights"]
51
+ end
47
52
  it "delegates to the solr_document" do
48
- expect(solr_document).to receive(:date_uploaded)
49
- presenter.date_uploaded
53
+ solr_properties.each do |property|
54
+ expect(solr_document).to receive(property.to_sym)
55
+ presenter.send(property)
56
+ end
50
57
  end
51
58
  end
52
59
 
@@ -2,10 +2,15 @@ require 'spec_helper'
2
2
 
3
3
  describe CurationConcerns::WorkShowPresenter do
4
4
  let(:solr_document) { SolrDocument.new(attributes) }
5
+ let(:date_value) { Date.today }
6
+ let(:date_index) { date_value.to_s }
5
7
  let(:attributes) do
6
8
  { "title_tesim" => ["foo bar"],
7
9
  "human_readable_type_tesim" => ["Generic Work"],
8
- "has_model_ssim" => ["GenericWork"] }
10
+ "has_model_ssim" => ["GenericWork"],
11
+ "date_created_dtsi" => date_index,
12
+ "date_modified_dtsi" => date_index,
13
+ "date_uploaded_dtsi" => date_index }
9
14
  end
10
15
 
11
16
  let(:ability) { nil }
@@ -26,6 +31,13 @@ describe CurationConcerns::WorkShowPresenter do
26
31
  it { is_expected.to be_kind_of ActiveModel::Name }
27
32
  end
28
33
 
34
+ [:date_created, :date_modified, :date_uploaded].each do |date_field|
35
+ describe "##{date_field}" do
36
+ subject { presenter.send date_field }
37
+ it { is_expected.to eq date_value.to_formatted_s(:standard) }
38
+ end
39
+ end
40
+
29
41
  describe "#permission_badge" do
30
42
  it "calls the PermissionBadge object" do
31
43
  expect_any_instance_of(CurationConcerns::PermissionBadge).to receive(:render)
@@ -1,14 +1,47 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe CurationConcerns::AttributeRenderer do
4
- let(:renderer) { described_class.new(:name, ['Bob', 'Jessica']) }
5
-
4
+ let(:field) { :name }
5
+ let(:renderer) { described_class.new(field, ['Bob', 'Jessica']) }
6
+ let(:yml_path) { File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'locales', '*.{rb,yml}') }
7
+ before do
8
+ I18n.load_path += Dir[File.join(yml_path)]
9
+ I18n.reload!
10
+ end
11
+ after do
12
+ I18n.load_path -= Dir[File.join(yml_path)]
13
+ I18n.reload!
14
+ end
6
15
  describe "#attribute_to_html" do
7
- subject { renderer.render }
8
-
9
- it { is_expected.to eq "<tr><th>Name</th>\n" \
10
- "<td><ul class='tabular'><li class=\"attribute name\">Bob</li>\n" \
11
- "<li class=\"attribute name\">Jessica</li>\n" \
12
- "</ul></td></tr>" }
16
+ subject { Nokogiri::HTML(renderer.render) }
17
+ let(:expected) { Nokogiri::HTML(tr_content) }
18
+ context 'without microdata enabled' do
19
+ before do
20
+ CurationConcerns.config.display_microdata = false
21
+ end
22
+ let(:tr_content) {
23
+ "<tr><th>Name</th>\n" \
24
+ "<td><ul class='tabular'><li class=\"attribute name\"><span>Bob</span></li>\n" \
25
+ "<li class=\"attribute name\"><span>Jessica</span></li>\n" \
26
+ "</ul></td></tr>"
27
+ }
28
+ it { expect(renderer).not_to be_microdata(field) }
29
+ it { expect(subject).to be_equivalent_to(expected) }
30
+ end
31
+ context 'with microdata enabled' do
32
+ before do
33
+ CurationConcerns.config.display_microdata = true
34
+ end
35
+ let(:tr_content) {
36
+ "<tr><th>Name</th>\n" \
37
+ "<td><ul class='tabular'><li class=\"attribute name\" itemscope itemtype=\"http://schema.org/Person\" itemprop=\"name\">" \
38
+ "<span itemprop=\"firstName\">Bob</span></li>\n" \
39
+ "<li class=\"attribute name\" itemscope itemtype=\"http://schema.org/Person\" itemprop=\"name\">" \
40
+ "<span itemprop=\"firstName\">Jessica</span></li>\n" \
41
+ "</ul></td></tr>"
42
+ }
43
+ it { expect(renderer).to be_microdata(field) }
44
+ it { expect(subject).to be_equivalent_to(expected) }
45
+ end
13
46
  end
14
47
  end
@@ -50,12 +50,12 @@ module CurationConcerns
50
50
  it 'routes to #show' do
51
51
  expect(curation_concerns_generic_work_path(generic_work)).to eq "/concern/generic_works/#{generic_work.id}"
52
52
  expect(get("/concern/generic_works/#{generic_work.id}")).to route_to(controller: 'curation_concerns/generic_works', action: 'show', id: generic_work.id)
53
- expect(url_for([:curation_concerns, generic_work, only_path: true])).to eq "/concern/generic_works/#{generic_work.id}"
53
+ expect(url_for([generic_work, only_path: true])).to eq "/concern/generic_works/#{generic_work.id}"
54
54
  end
55
55
  it 'routes to #edit' do
56
56
  expect(edit_curation_concerns_generic_work_path(generic_work)).to eq "/concern/generic_works/#{generic_work.id}/edit"
57
57
  expect(get("/concern/generic_works/#{generic_work.id}/edit")).to route_to(controller: 'curation_concerns/generic_works', action: 'edit', id: generic_work.id)
58
- expect(url_for([:edit, :curation_concerns, generic_work, only_path: true])).to eq "/concern/generic_works/#{generic_work.id}/edit"
58
+ expect(url_for([:edit, generic_work, only_path: true])).to eq "/concern/generic_works/#{generic_work.id}/edit"
59
59
  end
60
60
  end
61
61
  end
@@ -47,7 +47,7 @@ describe 'Routes', type: :routing do
47
47
  end
48
48
  end
49
49
 
50
- describe 'GenericFile' do
50
+ describe 'FileSet' do
51
51
  it 'routes to create' do
52
52
  expect(post: 'concern/container/1/file_sets').to route_to(controller: 'curation_concerns/file_sets', action: 'create', parent_id: '1')
53
53
  end
@@ -53,19 +53,61 @@ describe CurationConcerns::FileSetAuditService do
53
53
  end
54
54
 
55
55
  describe '#human_readable_audit_status' do
56
+ before do
57
+ CurationConcerns::VersioningService.create(f.original_file)
58
+ ChecksumAuditLog.create!(pass: 1, file_set_id: f.id, version: f.original_file.versions.first.uri, file_id: 'original_file')
59
+ end
60
+ subject { service.human_readable_audit_status }
61
+ it { is_expected.to eq 'Some audits have not been run, but the ones run were passing.' }
62
+ end
63
+
64
+ describe '#logged_audit_status' do
65
+ subject { service.logged_audit_status }
66
+
67
+ it "doesn't trigger audits" do
68
+ expect(service).not_to receive(:audit_file)
69
+ expect(subject).to eq "Audits have not yet been run on this file."
70
+ end
71
+
72
+ context "when no audit is passing" do
73
+ before do
74
+ ChecksumAuditLog.create!(pass: 1, file_set_id: f.id, version: f.original_file.versions.first.label, file_id: 'original_file')
75
+ end
76
+
77
+ it "reports the audit result" do
78
+ expect(subject).to eq 'passing'
79
+ end
80
+ end
81
+
82
+ context "when one audit is passing" do
83
+ before do
84
+ ChecksumAuditLog.create!(pass: 0, file_set_id: f.id, version: f.original_file.versions.first.label, file_id: 'original_file')
85
+ ChecksumAuditLog.create!(pass: 1, file_set_id: f.id, version: f.original_file.versions.first.label, file_id: 'original_file')
86
+ end
87
+
88
+ it "reports the audit result" do
89
+ expect(subject).to eq 'failing'
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '#stat_to_string' do
95
+ subject { service.send(:stat_to_string, val) }
56
96
  context 'when audit_stat is 0' do
57
- subject { service.human_readable_audit_status 0 }
97
+ let(:val) { 0 }
58
98
  it { is_expected.to eq 'failing' }
59
99
  end
60
100
 
61
101
  context 'when audit_stat is 1' do
62
- subject { service.human_readable_audit_status 1 }
102
+ let(:val) { 1 }
63
103
  it { is_expected.to eq 'passing' }
64
104
  end
65
105
 
66
106
  context 'when audit_stat is something else' do
67
- subject { service.human_readable_audit_status 'something else' }
68
- it { is_expected.to eq 'something else' }
107
+ let(:val) { 'something else' }
108
+ it "fails" do
109
+ expect { subject }.to raise_error ArgumentError, "Unknown status `something else'"
110
+ end
69
111
  end
70
112
  end
71
113
  end
data/spec/spec_helper.rb CHANGED
@@ -10,7 +10,10 @@ require 'database_cleaner'
10
10
  require 'engine_cart'
11
11
  EngineCart.load_application!
12
12
  require 'devise'
13
+ require 'mida'
13
14
 
15
+ require 'rspec/matchers'
16
+ require 'equivalent-xml/rspec_matchers'
14
17
  require 'rspec/its'
15
18
  require 'rspec/rails'
16
19
  require 'rspec/active_model/mocks'
@@ -29,6 +32,8 @@ if ENV['COVERAGE'] || $in_travis
29
32
  SimpleCov.formatter = Coveralls::SimpleCov::Formatter
30
33
  SimpleCov.start('rails') do
31
34
  add_filter '/spec'
35
+ add_filter '/lib/generators/curation_concerns/templates'
36
+ add_filter '/.internal_test_app'
32
37
  end
33
38
  SimpleCov.command_name('spec')
34
39
  end
@@ -79,13 +84,6 @@ RSpec.configure do |config|
79
84
  config.deprecation_stream
80
85
  end
81
86
 
82
- module FactoryGirl
83
- def self.find_or_create(handle, by = :email)
84
- tmpl = FactoryGirl.build(handle)
85
- tmpl.class.send("find_by_#{by}".to_sym, tmpl.send(by)) || FactoryGirl.create(handle)
86
- end
87
- end
88
-
89
87
  if defined?(ClamAV)
90
88
  ClamAV.instance.loaddb
91
89
  else
@@ -0,0 +1,32 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'collections/_sort_and_per_page.html.erb' do
4
+ let(:collection) { double }
5
+ let(:response) { double(response: { 'numFound' => 3 }) }
6
+
7
+ before do
8
+ allow(view).to receive(:sort_fields).and_return(['title_sort', 'date_sort'])
9
+ allow(view).to receive(:document_index_views).and_return(list: Blacklight::Configuration::ViewConfig.new)
10
+ assign(:response, response)
11
+ end
12
+
13
+ context "when the action is edit" do
14
+ before do
15
+ controller.action_name = "edit"
16
+ end
17
+ it "renders the form with a button" do
18
+ expect(view).to receive(:button_for_remove_selected_from_collection).with(collection)
19
+ render 'collections/sort_and_per_page', collection: collection
20
+ end
21
+ end
22
+
23
+ context "when the action is show" do
24
+ before do
25
+ controller.action_name = "show"
26
+ end
27
+ it "renders the form without a button" do
28
+ expect(view).not_to receive(:button_for_remove_selected_from_collection)
29
+ render 'collections/sort_and_per_page', collection: collection
30
+ end
31
+ end
32
+ end
@@ -4,14 +4,17 @@ describe 'curation_concerns/base/_attributes.html.erb' do
4
4
  let(:creator) { 'Bilbo' }
5
5
  let(:contributor) { 'Frodo' }
6
6
  let(:subject) { 'history' }
7
+ let(:description) { ['Lorem ipsum lorem ipsum. http://my.link.com'] }
7
8
 
8
9
  let(:solr_document) { SolrDocument.new(subject_tesim: subject,
9
10
  contributor_tesim: contributor,
10
- creator_tesim: creator) }
11
+ creator_tesim: creator,
12
+ description_tesim: description) }
11
13
  let(:ability) { nil }
12
14
  let(:presenter) do
13
15
  CurationConcerns::WorkShowPresenter.new(solr_document, ability)
14
16
  end
17
+ let(:doc) { Nokogiri::HTML(rendered) }
15
18
 
16
19
  before do
17
20
  allow(view).to receive(:dom_class) { '' }
@@ -25,4 +28,8 @@ describe 'curation_concerns/base/_attributes.html.erb' do
25
28
  expect(rendered).to have_link(contributor, href: catalog_index_path(search_field: 'contributor', q: contributor))
26
29
  expect(rendered).to have_link(subject, href: catalog_index_path(search_field: 'subject', q: subject))
27
30
  end
31
+ it 'shows links in the description' do
32
+ a1 = doc.xpath("//li[@class='attribute description']/span/a").text
33
+ expect(a1).to start_with 'http://my.link.com'
34
+ end
28
35
  end
@@ -2,7 +2,7 @@ require 'spec_helper'
2
2
 
3
3
  describe 'curation_concerns/base/show.html.erb' do
4
4
  let(:object_profile) { ["{\"id\":\"999\"}"] }
5
- let(:contributor) { 'Frodo' }
5
+ let(:contributor) { ['Frodo', 'Sam'] }
6
6
  let(:creator) { 'Bilbo' }
7
7
  let(:solr_document) {
8
8
  SolrDocument.new(
@@ -12,6 +12,7 @@ describe 'curation_concerns/base/show.html.erb' do
12
12
  human_readable_type_tesim: ['Generic Work'],
13
13
  contributor_tesim: contributor,
14
14
  creator_tesim: creator,
15
+ language_tesim: 'Hobbish',
15
16
  rights_tesim: ['http://creativecommons.org/licenses/by/3.0/us/']
16
17
  )
17
18
  }
@@ -31,7 +32,7 @@ describe 'curation_concerns/base/show.html.erb' do
31
32
 
32
33
  it 'draws the page' do
33
34
  expect(rendered).to have_link 'Attribution 3.0 United States', href: 'http://creativecommons.org/licenses/by/3.0/us/'
34
- expect(rendered).to have_link 'Edit This Generic Work', href: edit_polymorphic_path([:curation_concerns, presenter])
35
+ expect(rendered).to have_link 'Edit This Generic Work', href: edit_polymorphic_path(presenter)
35
36
  end
36
37
  end
37
38
 
@@ -46,4 +47,37 @@ describe 'curation_concerns/base/show.html.erb' do
46
47
  expect(rendered).not_to have_content('Edit this Generic Work')
47
48
  end
48
49
  end
50
+
51
+ describe 'schema.org' do
52
+ before do
53
+ assign(:presenter, presenter)
54
+ allow(view).to receive(:can?).with(:edit, String).and_return(false)
55
+ allow(view).to receive(:can?).with(:collect, String).and_return(false)
56
+ render
57
+ end
58
+ let(:item) { Mida::Document.new("<html>#{rendered}</html>").items.first }
59
+ describe 'descriptive metadata' do
60
+ it 'draws schema.org fields' do
61
+ # default itemtype to CreativeWork
62
+ expect(item.type).to eq('http://schema.org/CreativeWork')
63
+
64
+ contributors = item.properties['contributor']
65
+ expect(contributors.count).to eq(2)
66
+ contributor = contributors.last
67
+ expect(contributor.type).to eq('http://schema.org/Person')
68
+ expect(contributor.properties['name'].first).to eq('Sam')
69
+
70
+ creators = item.properties['creator']
71
+ expect(creators.count).to eq(1)
72
+ creator = creators.first
73
+ expect(creator.type).to eq('http://schema.org/Person')
74
+ expect(creator.properties['name'].first).to eq('Bilbo')
75
+
76
+ languages = item.properties['inLanguage']
77
+ expect(languages.count).to eq(1)
78
+ language = languages.first
79
+ expect(language).to eq('Hobbish')
80
+ end
81
+ end
82
+ end
49
83
  end
@@ -3,6 +3,7 @@ require 'spec_helper'
3
3
  describe 'curation_concerns/file_sets/_file_set.html.erb' do
4
4
  let(:solr_document) { SolrDocument.new(id: '999',
5
5
  has_model_ssim: ['FileSet'],
6
+ active_fedora_model_ssi: 'FileSet',
6
7
  thumbnail_path_ss: '/downloads/999?file=thumbnail',
7
8
  representative_tesim: ["999"],
8
9
  title_tesim: ["My File"]) }
@@ -28,9 +29,9 @@ describe 'curation_concerns/file_sets/_file_set.html.erb' do
28
29
  expect(rendered).to have_selector ".thumbnail img[src='#{download_path(presenter, file: 'thumbnail')}']"
29
30
 
30
31
  # Action buttons
31
- expect(rendered).to have_selector "a[title=\"Edit My File\"][href='#{edit_polymorphic_path([:curation_concerns, presenter])}']", text: 'Edit'
32
+ expect(rendered).to have_selector "a[title=\"Edit My File\"][href='#{edit_polymorphic_path(presenter)}']", text: 'Edit'
32
33
  expect(rendered).to have_selector "a[title=\"Rollback to previous version\"][href='#{versions_curation_concerns_file_set_path(presenter)}']", text: 'Rollback'
33
- expect(rendered).to have_selector "a[title=\"Delete My File\"][data-method='delete'][href='#{polymorphic_path([:curation_concerns, presenter])}']", text: 'Delete'
34
+ expect(rendered).to have_selector "a[title=\"Delete My File\"][data-method='delete'][href='#{polymorphic_path(presenter)}']", text: 'Delete'
34
35
  expect(rendered).to have_link('Download')
35
36
  expect(rendered).to have_selector "a[title='Download \"My File\"'][href='#{download_path(presenter)}']", text: 'Download'
36
37
  end
@@ -0,0 +1,56 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'curation_concerns/file_sets/show.html.erb', type: :view do
4
+ before do
5
+ allow(view).to receive(:parent).and_return(parent)
6
+ end
7
+
8
+ let(:parent) { stub_model(GenericWork) }
9
+
10
+ let(:depositor) do
11
+ stub_model(User,
12
+ user_key: 'bob',
13
+ twitter_handle: 'bot4lib')
14
+ end
15
+
16
+ let(:content) do
17
+ double('content', versions: [], mimeType: 'application/pdf')
18
+ end
19
+
20
+ let(:file_set) do
21
+ stub_model(FileSet, id: '123',
22
+ depositor: depositor.user_key,
23
+ audit_stat: 1,
24
+ title: ['My Title'],
25
+ description: ['Lorem ipsum lorem ipsum. http://my.link.com']
26
+ )
27
+ end
28
+
29
+ let(:ability) { double }
30
+ let(:solr_doc) { SolrDocument.new(file_set.to_solr) }
31
+ let(:presenter) { CurationConcerns::FileSetPresenter.new(solr_doc, ability) }
32
+
33
+ before do
34
+ view.lookup_context.view_paths.push CurationConcerns::Engine.root + 'app/views/curation_concerns/base'
35
+ allow(view).to receive(:can?).with(:edit, String).and_return(true)
36
+ assign(:presenter, presenter)
37
+ end
38
+
39
+ describe 'title heading' do
40
+ before do
41
+ stub_template 'shared/_title_bar.html.erb' => 'Title Bar'
42
+ render template: 'curation_concerns/file_sets/show.html.erb', layout: 'layouts/curation_concerns'
43
+ end
44
+ it 'shows the title' do
45
+ expect(rendered).to have_selector 'h1 > small', text: 'My Title'
46
+ end
47
+ end
48
+
49
+ describe 'attributes' do
50
+ before { render }
51
+
52
+ it 'shows the description' do
53
+ expect(rendered).to have_selector '.attribute.description', text: 'Lorem ipsum'
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'curation_concerns/single_use_links_viewer/show.html.erb' do
4
+ let(:ability) { double }
5
+ let(:model) { stub_model(FileSet, title: ['world.png']) }
6
+ let(:solr_document) { SolrDocument.new(model.to_solr) }
7
+ let(:presenter) { CurationConcerns::FileSetPresenter.new(solr_document, ability) }
8
+ let(:download_link) { '/a_path' }
9
+ before do
10
+ assign(:presenter, presenter)
11
+ assign(:download_link, download_link)
12
+ view.lookup_context.view_paths.push 'app/views/curation_concerns/base'
13
+ render
14
+ end
15
+
16
+ it "renders the page" do
17
+ expect(rendered).to have_selector 'h1', text: 'world.png'
18
+ end
19
+ end
@@ -14,7 +14,7 @@ describe 'shared/_add_content.html.erb' do
14
14
 
15
15
  it 'has links to create works and collections' do
16
16
  CurationConcerns.config.curation_concerns.each do |curation_concern_type|
17
- expect(rendered).to have_link("New #{curation_concern_type.human_readable_type}", href: new_polymorphic_path([:curation_concerns, curation_concern_type]))
17
+ expect(rendered).to have_link("New #{curation_concern_type.human_readable_type}", href: new_polymorphic_path(curation_concern_type))
18
18
  end
19
19
  expect(rendered).to have_link('Add a Collection', href: collections.new_collection_path)
20
20
  end
@@ -30,7 +30,7 @@ describe 'shared/_add_content.html.erb' do
30
30
 
31
31
  it 'has links to add collections but not to add works' do
32
32
  CurationConcerns.config.curation_concerns.each do |curation_concern_type|
33
- expect(rendered).not_to have_link("New #{curation_concern_type.human_readable_type}", href: new_polymorphic_path([:curation_concerns, curation_concern_type]))
33
+ expect(rendered).not_to have_link("New #{curation_concern_type.human_readable_type}", href: new_polymorphic_path(curation_concern_type))
34
34
  end
35
35
  expect(rendered).to have_link('Add a Collection', href: collections.new_collection_path)
36
36
  end
@@ -47,7 +47,7 @@ describe 'shared/_add_content.html.erb' do
47
47
  expect(rendered).not_to have_text('Add')
48
48
  expect(rendered).not_to have_text('Admin')
49
49
  CurationConcerns.config.curation_concerns.each do |curation_concern_type|
50
- expect(rendered).not_to have_link("New #{curation_concern_type.human_readable_type}", href: new_polymorphic_path([:curation_concerns, curation_concern_type]))
50
+ expect(rendered).not_to have_link("New #{curation_concern_type.human_readable_type}", href: new_polymorphic_path(curation_concern_type))
51
51
  end
52
52
  expect(rendered).not_to have_link('Add a Collection', href: collections.new_collection_path)
53
53
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe 'curation_concerns/single_use_links/new_download.html.erb' do
4
- let(:user) { FactoryGirl.find_or_create(:jill) }
4
+ let(:user) { create(:user) }
5
5
 
6
6
  let(:f) do
7
7
  file = FileSet.create do |gf|
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'upload_sets/_metadata.html.erb' do
4
+ let(:user) { build(:user) }
5
+ let(:ability) { Ability.new(user) }
6
+ let(:upload_set) { UploadSet.create }
7
+ let(:form) { CurationConcerns::UploadSetForm.new(upload_set, ability) }
8
+ let(:work1) { build(:work, id: 'work1', title: ['First work']) }
9
+ let(:work2) { build(:work, id: 'work2', title: ['Second work']) }
10
+
11
+ let(:f) do
12
+ allow(upload_set).to receive(:works).and_return([work1, work2])
13
+ view.simple_form_for(form, url: '/update', builder: CurationConcerns::FormBuilder) do |fs_form|
14
+ return fs_form
15
+ end
16
+ end
17
+
18
+ before do
19
+ allow(view).to receive(:f).and_return(f)
20
+ render
21
+ end
22
+
23
+ it "draws the form" do
24
+ expect(rendered).to have_text 'Applies to all files just uploaded'
25
+ expect(rendered).to have_css 'input[name="title[work1][]"][value="First work"]'
26
+ expect(rendered).to have_css 'input[name="title[work2][]"][value="Second work"]'
27
+ end
28
+ end