sufia 6.3.0 → 6.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +1 -2
- data/.rubocop.yml +10 -0
- data/Gemfile +16 -7
- data/History.md +43 -0
- data/README.md +26 -19
- data/SUFIA_VERSION +1 -1
- data/app/assets/javascripts/notifications_check.js.erb +46 -0
- data/app/assets/javascripts/sufia.js +1 -2
- data/app/assets/javascripts/sufia/uploader.js +3 -3
- data/app/assets/stylesheets/sufia/_collections.scss +5 -0
- data/app/assets/stylesheets/sufia/_dashboard.scss +6 -1
- data/app/assets/stylesheets/sufia/_file-listing.scss +44 -6
- data/app/assets/stylesheets/sufia/_file-show.scss +4 -0
- data/app/assets/stylesheets/sufia/_settings.scss +3 -0
- data/app/controllers/api/items_controller.rb +7 -3
- data/app/controllers/concerns/sufia/admin/depositor_stats.rb +1 -1
- data/app/controllers/concerns/sufia/admin/stats_behavior.rb +6 -76
- data/app/controllers/concerns/sufia/batch_controller_behavior.rb +10 -2
- data/app/controllers/concerns/sufia/contact_form_controller_behavior.rb +1 -0
- data/app/controllers/concerns/sufia/files_controller_behavior.rb +11 -1
- data/app/controllers/concerns/sufia/homepage_controller.rb +1 -1
- data/app/controllers/concerns/sufia/my_controller_behavior.rb +2 -0
- data/app/controllers/concerns/sufia/users_controller_behavior.rb +2 -2
- data/app/helpers/generic_file_helper.rb +8 -5
- data/app/jobs/content_delete_event_job.rb +16 -11
- data/app/jobs/content_deposit_event_job.rb +4 -16
- data/app/jobs/content_depositor_change_event_job.rb +32 -20
- data/app/jobs/content_event_job.rb +39 -0
- data/app/jobs/content_new_version_event_job.rb +4 -16
- data/app/jobs/content_restored_version_event_job.rb +6 -19
- data/app/jobs/content_update_event_job.rb +4 -16
- data/app/jobs/event_job.rb +48 -4
- data/app/jobs/user_edit_profile_event_job.rb +4 -17
- data/app/jobs/user_follow_event_job.rb +10 -12
- data/app/jobs/user_unfollow_event_job.rb +10 -15
- data/app/models/concerns/sufia/solr_document_behavior.rb +11 -1
- data/app/models/system_stats.rb +108 -0
- data/app/presenters/sufia/admin_stats_presenter.rb +49 -0
- data/app/views/_controls.html.erb +1 -1
- data/app/views/_footer.html.erb +1 -1
- data/app/views/_logo.html.erb +1 -3
- data/app/views/admin/stats/_date_form.html.erb +8 -0
- data/app/views/admin/stats/_deposits.html.erb +2 -10
- data/app/views/admin/stats/_files.html.erb +6 -14
- data/app/views/admin/stats/_new_users.html.erb +7 -14
- data/app/views/admin/stats/_stats_by_date.html.erb +8 -0
- data/app/views/admin/stats/_top_data.html.erb +24 -0
- data/app/views/admin/stats/index.html.erb +5 -31
- data/app/views/collections/_form_for_select_collection.html.erb +5 -4
- data/app/views/collections/_show_actions.html.erb +7 -2
- data/app/views/collections/_show_document_list_row.html.erb +1 -9
- data/app/views/generic_files/_browse_everything.html.erb +3 -0
- data/app/views/generic_files/_descriptions.html.erb +1 -1
- data/app/views/generic_files/_generic_file.html.erb +1 -1
- data/app/views/generic_files/_local_file_import.html.erb +3 -0
- data/app/views/generic_files/_show_actions.html.erb +4 -0
- data/app/views/generic_files/upload/_form.html.erb +3 -0
- data/app/views/generic_files/upload/_to_collection.html.erb +5 -0
- data/app/views/homepage/_recent_document.html.erb +1 -7
- data/app/views/my/_index_partials/_default_group.html.erb +1 -1
- data/app/views/my/_index_partials/_list_collections.html.erb +3 -10
- data/app/views/my/_index_partials/_list_files.html.erb +13 -22
- data/app/views/my/_sort_and_per_page.html.erb +3 -3
- data/app/views/records/edit_fields/_rights.html.erb +2 -1
- data/app/views/static/terms.html.erb +1 -1
- data/config/locales/sufia.en.yml +13 -0
- data/lib/generators/sufia/templates/catalog_controller.rb +2 -2
- data/lib/sufia/version.rb +1 -1
- data/spec/actors/generic_file/actor_spec.rb +35 -0
- data/spec/controllers/admin_stats_controller_spec.rb +53 -23
- data/spec/controllers/api/items_controller_spec.rb +47 -41
- data/spec/controllers/batch_controller_spec.rb +1 -0
- data/spec/controllers/generic_files_controller_spec.rb +35 -1
- data/spec/controllers/my/files_controller_spec.rb +5 -0
- data/spec/factories/generic_files.rb +3 -0
- data/spec/features/collection_spec.rb +91 -0
- data/spec/features/contact_form_spec.rb +1 -0
- data/spec/forms/collection_edit_form_spec.rb +3 -3
- data/spec/forms/generic_file_edit_form_spec.rb +1 -1
- data/spec/jobs/create_derivatives_job_spec.rb +6 -0
- data/spec/models/file_content_datastream_spec.rb +1 -1
- data/spec/models/file_download_stat_spec.rb +4 -4
- data/spec/models/file_usage_spec.rb +2 -2
- data/spec/models/file_view_stat_spec.rb +4 -4
- data/spec/models/generic_file_spec.rb +15 -3
- data/spec/models/geo_names_resource_spec.rb +10 -0
- data/spec/models/solr_document_spec.rb +28 -0
- data/spec/models/system_stats_spec.rb +184 -0
- data/spec/models/user_spec.rb +1 -1
- data/spec/models/user_usage_stats_spec.rb +1 -1
- data/spec/services/generic_file_csv_service_spec.rb +66 -0
- data/spec/services/generic_file_indexing_service_spec.rb +35 -0
- data/spec/services/lock_manager_spec.rb +12 -0
- data/spec/spec_helper.rb +2 -1
- data/spec/views/admin/stats/index.html.erb_spec.rb +11 -10
- data/spec/views/catalog/sort_and_per_page.html.erb_spec.rb +1 -1
- data/spec/views/collections/_form_for_select_collection.html.erb_spec.rb +51 -0
- data/spec/views/generic_file/_browse_everything.html.erb_spec.rb +4 -0
- data/spec/views/generic_file/edit.html.erb_spec.rb +31 -24
- data/spec/views/generic_file/new.html.erb_spec.rb +70 -0
- data/spec/views/generic_file/show.html.erb_spec.rb +23 -0
- data/sufia.gemspec +3 -2
- data/tasks/sufia-dev.rake +2 -0
- metadata +42 -9
- data/lib/sufia/role_mapper.rb +0 -7
data/spec/models/user_spec.rb
CHANGED
|
@@ -189,7 +189,7 @@ describe User, type: :model do
|
|
|
189
189
|
end
|
|
190
190
|
|
|
191
191
|
context "when has start and end date" do
|
|
192
|
-
subject { described_class.recent_users(Date.today - 2.days, Date.today - 1.
|
|
192
|
+
subject { described_class.recent_users(Date.today - 2.days, Date.today - 1.day) }
|
|
193
193
|
it "returns valid data" do
|
|
194
194
|
expect(subject.count).to eq 1
|
|
195
195
|
is_expected.to include(new_users[1])
|
|
@@ -4,7 +4,7 @@ describe Sufia::UserUsageStats do
|
|
|
4
4
|
subject { FactoryGirl.create(:user) }
|
|
5
5
|
|
|
6
6
|
describe 'with cached stats' do
|
|
7
|
-
let!(:stat_1_day_ago) { UserStat.create!(user_id: subject.id, date: 1.
|
|
7
|
+
let!(:stat_1_day_ago) { UserStat.create!(user_id: subject.id, date: 1.day.ago, file_views: 3, file_downloads: 2) }
|
|
8
8
|
let!(:stat_2_days_ago) { UserStat.create!(user_id: subject.id, date: 2.days.ago, file_views: 2, file_downloads: 1) }
|
|
9
9
|
|
|
10
10
|
let!(:someone_elses_user_id) { subject.id + 1 }
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Sufia::GenericFileCSVService do
|
|
4
|
+
let(:file) do
|
|
5
|
+
GenericFile.new(id: '123abc', title: ['My Title'], creator: ['Von, Creator'],
|
|
6
|
+
resource_type: ['Book', 'Other'], rights: ['Mine'], mime_type: 'application/pdf') do |f|
|
|
7
|
+
f.apply_depositor_metadata('jilluser@example.com')
|
|
8
|
+
end
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
context "when using the defaults" do
|
|
12
|
+
let(:csv_service) { described_class.new(file) }
|
|
13
|
+
|
|
14
|
+
describe "csv" do
|
|
15
|
+
subject { csv_service.csv }
|
|
16
|
+
|
|
17
|
+
it { is_expected.to eq "123abc,My Title,jilluser@example.com,\"Von, Creator\",restricted,Book|Other,Mine,pdf\n" }
|
|
18
|
+
it "parses as valid csv" do
|
|
19
|
+
expect(CSV.parse(subject)).to eq([["123abc", "My Title", "jilluser@example.com", "Von, Creator", "restricted", "Book|Other", "Mine", "pdf"]])
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
describe "csv_header" do
|
|
24
|
+
subject { csv_service.csv_header }
|
|
25
|
+
it { is_expected.to eq "id,title,depositor,creator,visibility,resource_type,rights,file_format\n" }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "when specifying terms" do
|
|
30
|
+
let(:csv_service) { described_class.new(file, [:id, :title, :resource_type]) }
|
|
31
|
+
describe "csv" do
|
|
32
|
+
subject { csv_service.csv }
|
|
33
|
+
it { is_expected.to eq "123abc,My Title,Book|Other\n" }
|
|
34
|
+
end
|
|
35
|
+
describe "csv_header" do
|
|
36
|
+
subject { csv_service.csv_header }
|
|
37
|
+
it { is_expected.to eq "id,title,resource_type\n" }
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
context "when specifying separator" do
|
|
42
|
+
let(:csv_service) { described_class.new(file, nil, '&&') }
|
|
43
|
+
describe "csv" do
|
|
44
|
+
subject { csv_service.csv }
|
|
45
|
+
|
|
46
|
+
it { is_expected.to eq "123abc,My Title,jilluser@example.com,\"Von, Creator\",restricted,Book&&Other,Mine,pdf\n" }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
describe "csv_header" do
|
|
50
|
+
subject { csv_service.csv_header }
|
|
51
|
+
it { is_expected.to eq "id,title,depositor,creator,visibility,resource_type,rights,file_format\n" }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "when specifying terms and separator" do
|
|
56
|
+
let(:csv_service) { described_class.new(file, [:id, :title, :resource_type], '*$*') }
|
|
57
|
+
describe "csv" do
|
|
58
|
+
subject { csv_service.csv }
|
|
59
|
+
it { is_expected.to eq "123abc,My Title,Book*$*Other\n" }
|
|
60
|
+
end
|
|
61
|
+
describe "csv_header" do
|
|
62
|
+
subject { csv_service.csv_header }
|
|
63
|
+
it { is_expected.to eq "id,title,resource_type\n" }
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Sufia::GenericFileIndexingService do
|
|
4
|
+
let(:indexer) { described_class.new(object) }
|
|
5
|
+
let(:object) do
|
|
6
|
+
GenericFile.create do |f|
|
|
7
|
+
f.add_file(File.open(fixture_path + '/world.png'), path: 'content', original_name: 'world.png')
|
|
8
|
+
f.apply_depositor_metadata('mjg36')
|
|
9
|
+
end
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe '#generate_solr_document' do
|
|
13
|
+
context 'when GenericFile has no content' do
|
|
14
|
+
it 'does not try to index Fedora-generated SHA1 digests' do
|
|
15
|
+
expect(indexer).to receive(:digest_from_content) { nil }
|
|
16
|
+
indexer.generate_solr_document
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
context 'when GenericFile has content' do
|
|
20
|
+
subject { indexer.generate_solr_document }
|
|
21
|
+
it 'indexes the Fedora-generated SHA1 digest' do
|
|
22
|
+
expect(subject[Solrizer.solr_name('digest', :symbol)]).to eq 'urn:sha1:f794b23c0c6fe1083d0ca8b58261a078cd968967'
|
|
23
|
+
end
|
|
24
|
+
context 'when a subsequent version is uploaded' do
|
|
25
|
+
before do
|
|
26
|
+
object.add_file(File.open(fixture_path + '/xml_fits.xml'), path: 'content', original_name: 'xml_fits.xml')
|
|
27
|
+
object.save!
|
|
28
|
+
end
|
|
29
|
+
it 'reindexes the Fedora-generated SHA1 digest' do
|
|
30
|
+
expect(object.to_solr[Solrizer.solr_name('digest', :symbol)]).to eq 'urn:sha1:15fa208cb92483eca11253a56e370d96fbced075'
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe Sufia::LockManager do
|
|
4
|
+
subject { described_class.new(Sufia.config.lock_time_to_live,
|
|
5
|
+
Sufia.config.lock_retry_count,
|
|
6
|
+
Sufia.config.lock_retry_delay) }
|
|
7
|
+
describe "lock", unless: $in_travis do
|
|
8
|
+
it "calls the block" do
|
|
9
|
+
expect { |probe| subject.lock('foobar', &probe) }.to yield_with_no_args
|
|
10
|
+
end
|
|
11
|
+
end
|
|
12
|
+
end
|
data/spec/spec_helper.rb
CHANGED
|
@@ -37,7 +37,7 @@ end
|
|
|
37
37
|
|
|
38
38
|
Capybara.default_driver = :rack_test # This is a faster driver
|
|
39
39
|
Capybara.javascript_driver = :poltergeist # This is slower
|
|
40
|
-
Capybara.
|
|
40
|
+
Capybara.default_max_wait_time = ENV['TRAVIS'] ? 30 : 15
|
|
41
41
|
# HttpLogger.logger = Logger.new(STDOUT)
|
|
42
42
|
# HttpLogger.ignore = [/localhost:8983\/solr/]
|
|
43
43
|
# HttpLogger.colorize = false
|
|
@@ -100,6 +100,7 @@ module EngineRoutes
|
|
|
100
100
|
def self.included(base)
|
|
101
101
|
base.routes { Sufia::Engine.routes }
|
|
102
102
|
end
|
|
103
|
+
|
|
103
104
|
def main_app
|
|
104
105
|
Rails.application.class.routes.url_helpers
|
|
105
106
|
end
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe "admin/stats/index.html.erb" do
|
|
4
|
+
let(:presenter) do
|
|
5
|
+
Sufia::AdminStatsPresenter.new({}, 5).tap do |p|
|
|
6
|
+
p.deposit_stats = {}
|
|
7
|
+
p.depositors = []
|
|
8
|
+
end
|
|
9
|
+
end
|
|
4
10
|
before do
|
|
5
|
-
assign(:
|
|
6
|
-
assign(:top_formats, [])
|
|
7
|
-
assign(:users_stats, {})
|
|
8
|
-
assign(:recent_users, [])
|
|
9
|
-
assign(:deposit_stats, {})
|
|
10
|
-
assign(:depositors, [])
|
|
11
|
+
assign(:presenter, presenter)
|
|
11
12
|
end
|
|
12
13
|
|
|
13
14
|
context "default depositors" do
|
|
@@ -17,12 +18,12 @@ describe "admin/stats/index.html.erb" do
|
|
|
17
18
|
users
|
|
18
19
|
end
|
|
19
20
|
before do
|
|
20
|
-
|
|
21
|
+
allow(presenter).to receive(:active_users).and_return(top_5_active_users)
|
|
21
22
|
render
|
|
22
23
|
end
|
|
23
24
|
it "shows top 5 depositors and option to view more" do
|
|
24
25
|
expect(rendered).to have_content("(top 5)")
|
|
25
|
-
expect(rendered).to
|
|
26
|
+
expect(rendered).to have_link("View top 20", href: "/admin/stats?limit=20")
|
|
26
27
|
end
|
|
27
28
|
end
|
|
28
29
|
|
|
@@ -33,8 +34,8 @@ describe "admin/stats/index.html.erb" do
|
|
|
33
34
|
users
|
|
34
35
|
end
|
|
35
36
|
before do
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
allow(presenter).to receive(:active_users).and_return(top_20_active_users)
|
|
38
|
+
allow(presenter).to receive(:limit).and_return(20)
|
|
38
39
|
render
|
|
39
40
|
end
|
|
40
41
|
it "shows top 20 depositors, without an option to view more" do
|
|
@@ -24,6 +24,6 @@ describe 'catalog/_sort_and_per_page.html.erb', type: :view do
|
|
|
24
24
|
|
|
25
25
|
it 'displays the relevance option for sorting' do
|
|
26
26
|
render
|
|
27
|
-
expect(rendered).to include("<li><a href=\"/catalog?sort=score+desc%2C+
|
|
27
|
+
expect(rendered).to include("<li><a href=\"/catalog?sort=score+desc%2C+system_create_dtsi+desc\">relevance</a></li>")
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'collections/_form_for_select_collection.html.erb' do
|
|
4
|
+
let(:collections) {
|
|
5
|
+
[
|
|
6
|
+
Collection.new(id: '1234', title: 'collection 1', create_date: DateTime.parse('Thu, 13 Aug 2015 14:20:22 +0100')),
|
|
7
|
+
Collection.new(id: '1235', title: 'collection 2', create_date: DateTime.parse('Thu, 13 Aug 2015 14:18:22 +0100')),
|
|
8
|
+
Collection.new(id: '1236', title: 'collection 3', create_date: DateTime.parse('Thu, 13 Aug 2015 14:16:22 +0100')),
|
|
9
|
+
Collection.new(id: '1237', title: 'collection 4', create_date: DateTime.parse('Thu, 13 Aug 2015 14:29:22 +0100'))
|
|
10
|
+
]
|
|
11
|
+
}
|
|
12
|
+
let(:solr_collections) {
|
|
13
|
+
collections.map do |c|
|
|
14
|
+
SolrDocument.new(c.to_solr).tap do |sd|
|
|
15
|
+
sd['system_create_dtsi'] = c.create_date.to_s
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
let(:doc) {
|
|
21
|
+
Nokogiri::HTML(rendered)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
before do
|
|
25
|
+
allow(view).to receive(:user_collections).and_return(solr_collections)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
it "sorts the collections" do
|
|
29
|
+
render
|
|
30
|
+
collection_ids = doc.xpath("//input[@class='collection-selector']/@id").map(&:to_s)
|
|
31
|
+
expect(collection_ids).to eql(["id_1237", "id_1234", "id_1235", "id_1236"])
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
it "selects the right collection when instructed to do so" do
|
|
35
|
+
assign(:add_files_to_collection, collections[2].id)
|
|
36
|
+
render
|
|
37
|
+
expect(rendered).not_to have_selector "#id_#{collections[0].id}[checked='checked']"
|
|
38
|
+
expect(rendered).not_to have_selector "#id_#{collections[1].id}[checked='checked']"
|
|
39
|
+
expect(rendered).not_to have_selector "#id_#{collections[3].id}[checked='checked']"
|
|
40
|
+
expect(rendered).to have_selector "#id_#{collections[2].id}[checked='checked']"
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
it "selects the first collection when nothing else specified" do
|
|
44
|
+
# first when sorted by create date, so not index 0
|
|
45
|
+
render
|
|
46
|
+
expect(rendered).not_to have_selector "#id_#{collections[0].id}[checked='checked']"
|
|
47
|
+
expect(rendered).not_to have_selector "#id_#{collections[1].id}[checked='checked']"
|
|
48
|
+
expect(rendered).not_to have_selector "#id_#{collections[2].id}[checked='checked']"
|
|
49
|
+
expect(rendered).to have_selector "#id_#{collections[3].id}[checked='checked']"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -1,6 +1,35 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe 'generic_files/edit.html.erb', :no_clean do
|
|
4
|
+
let(:content) { double('content', mimeType: 'application/pdf') }
|
|
5
|
+
|
|
6
|
+
let(:generic_file) do
|
|
7
|
+
stub_model(GenericFile, id: '123',
|
|
8
|
+
depositor: 'bob',
|
|
9
|
+
resource_type: ['Book', 'Dataset'])
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
let(:form) do
|
|
13
|
+
Sufia::Forms::GenericFileEditForm.new(generic_file)
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
let(:page) do
|
|
17
|
+
render
|
|
18
|
+
Capybara::Node::Simple.new(rendered)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
subject { page }
|
|
22
|
+
|
|
23
|
+
before do
|
|
24
|
+
allow(generic_file).to receive(:content).and_return(content)
|
|
25
|
+
allow(controller).to receive(:current_user).and_return(stub_model(User))
|
|
26
|
+
assign(:generic_file, generic_file)
|
|
27
|
+
assign(:form, form)
|
|
28
|
+
assign(:version_list, [])
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
it { is_expected.to have_button('Save Descriptions') }
|
|
32
|
+
|
|
4
33
|
describe 'when the file has two or more resource types' do
|
|
5
34
|
let(:resource_version) do
|
|
6
35
|
ActiveFedora::VersionsGraph::ResourceVersion.new.tap do |v|
|
|
@@ -9,34 +38,12 @@ describe 'generic_files/edit.html.erb', :no_clean do
|
|
|
9
38
|
v.created = '2014-12-09T02:03:18.296Z'
|
|
10
39
|
end
|
|
11
40
|
end
|
|
41
|
+
|
|
12
42
|
let(:version_list) { Sufia::VersionListPresenter.new([resource_version]) }
|
|
13
43
|
let(:versions_graph) { double(all: [version1]) }
|
|
14
|
-
let(:content) { double('content', mimeType: 'application/pdf') }
|
|
15
|
-
|
|
16
|
-
let(:generic_file) do
|
|
17
|
-
stub_model(GenericFile, id: '123',
|
|
18
|
-
depositor: 'bob',
|
|
19
|
-
resource_type: ['Book', 'Dataset'])
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
let(:form) do
|
|
23
|
-
Sufia::Forms::GenericFileEditForm.new(generic_file)
|
|
24
|
-
end
|
|
25
44
|
|
|
26
|
-
|
|
27
|
-
allow(generic_file).to receive(:content).and_return(content)
|
|
28
|
-
allow(controller).to receive(:current_user).and_return(stub_model(User))
|
|
29
|
-
assign(:generic_file, generic_file)
|
|
30
|
-
assign(:form, form)
|
|
45
|
+
it "only draws one resource_type multiselect" do
|
|
31
46
|
assign(:version_list, version_list)
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
let(:page) do
|
|
35
|
-
render
|
|
36
|
-
Capybara::Node::Simple.new(rendered)
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
it "onlies draw one resource_type multiselect" do
|
|
40
47
|
expect(page).to have_selector("select#generic_file_resource_type", count: 1)
|
|
41
48
|
end
|
|
42
49
|
end
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe 'generic_files/new.html.erb', type: :view do
|
|
4
|
+
let(:user_collections) do
|
|
5
|
+
default_option = SolrDocument.new(id: -1, title_tesim: 'Select collection...')
|
|
6
|
+
col1 = SolrDocument.new(id: 'c1', title_tesim: 'col1')
|
|
7
|
+
col2 = SolrDocument.new(id: 'c2', title_tesim: 'col2')
|
|
8
|
+
[default_option, col1, col2]
|
|
9
|
+
end
|
|
10
|
+
let(:generic_file) { stub_model(GenericFile, id: '123') }
|
|
11
|
+
let(:batch_id) { 'bi1' }
|
|
12
|
+
|
|
13
|
+
describe 'upload_to_collection' do
|
|
14
|
+
before do
|
|
15
|
+
assign(:generic_file, generic_file)
|
|
16
|
+
assign(:batch_id, batch_id)
|
|
17
|
+
assign(:user_collections, user_collections)
|
|
18
|
+
allow(controller).to receive(:current_user).and_return(stub_model(User))
|
|
19
|
+
Sufia.config.upload_to_collection = upload_to_collection
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
context 'when enabled' do
|
|
23
|
+
let(:upload_to_collection) { true }
|
|
24
|
+
|
|
25
|
+
it 'appears on page' do
|
|
26
|
+
render
|
|
27
|
+
page = Capybara::Node::Simple.new(rendered)
|
|
28
|
+
expect(page).to have_selector('select#collection', count: 2) # one per tab
|
|
29
|
+
expect(page).to have_select('collection', options: ['Select collection...', 'col1', 'col2'])
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
context 'and passed a default collection' do
|
|
33
|
+
context "and the collection is on the user's list of editable collections" do
|
|
34
|
+
before do
|
|
35
|
+
assign(:collection_id, 'c2')
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
it 'has default collection selected' do
|
|
39
|
+
render
|
|
40
|
+
page = Capybara::Node::Simple.new(rendered)
|
|
41
|
+
expect(page).to have_select('collection', options: ['Select collection...', 'col1', 'col2'], selected: 'col2')
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
context "and the collection is NOT on the user's list of editable collections" do
|
|
46
|
+
before do
|
|
47
|
+
assign(:collection_id, 'c3_noedit')
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
it 'has instructions selected' do
|
|
51
|
+
render
|
|
52
|
+
page = Capybara::Node::Simple.new(rendered)
|
|
53
|
+
expect(page).to have_select('collection', options: ['Select collection...', 'col1', 'col2'])
|
|
54
|
+
expect(page).not_to have_select('collection', selected: 'col3_noedit')
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
context 'when disabled' do
|
|
61
|
+
let(:upload_to_collection) { false }
|
|
62
|
+
|
|
63
|
+
it 'does not appear on page' do
|
|
64
|
+
render
|
|
65
|
+
page = Capybara::Node::Simple.new(rendered)
|
|
66
|
+
expect(page).to have_no_selector('select#collection')
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
@@ -216,6 +216,29 @@ describe 'generic_files/show.html.erb', type: :view do
|
|
|
216
216
|
end
|
|
217
217
|
end
|
|
218
218
|
|
|
219
|
+
describe 'citations' do
|
|
220
|
+
let(:page) { Capybara::Node::Simple.new(rendered) }
|
|
221
|
+
before do
|
|
222
|
+
Sufia.config.citations = citations
|
|
223
|
+
render
|
|
224
|
+
end
|
|
225
|
+
context 'when enabled' do
|
|
226
|
+
let(:citations) { true }
|
|
227
|
+
|
|
228
|
+
it 'appears on page' do
|
|
229
|
+
expect(page).to have_selector('a#citations', count: 1)
|
|
230
|
+
end
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
context 'when disabled' do
|
|
234
|
+
let(:citations) { false }
|
|
235
|
+
|
|
236
|
+
it 'does not appear on page' do
|
|
237
|
+
expect(page).to have_no_selector('a#citations')
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
end
|
|
241
|
+
|
|
219
242
|
describe 'featured' do
|
|
220
243
|
before do
|
|
221
244
|
allow(generic_file).to receive(:public?).and_return(public)
|