curate 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +14 -0
- data/app/controllers/application_controller.rb +69 -0
- data/app/controllers/catalog_controller.rb +336 -0
- data/app/controllers/classify_concerns_controller.rb +29 -0
- data/app/controllers/common_objects_controller.rb +27 -0
- data/app/controllers/curation_concern/base_controller.rb +26 -0
- data/app/controllers/curation_concern/generic_files_controller.rb +82 -0
- data/app/controllers/dashboard_controller.rb +85 -0
- data/app/controllers/downloads_controller.rb +22 -0
- data/app/controllers/errors_controller.rb +19 -0
- data/app/controllers/help_requests_controller.rb +38 -0
- data/app/controllers/terms_of_service_agreements_controller.rb +44 -0
- data/app/controllers/welcome_controller.rb +14 -0
- data/app/helpers/application_helper.rb +89 -0
- data/app/helpers/blacklight_helper.rb +19 -0
- data/app/helpers/common_objects_helper.rb +5 -0
- data/app/inputs/multi_value_input.rb +71 -0
- data/app/models/access_right.rb +53 -0
- data/app/models/classify_concern.rb +30 -0
- data/app/models/contributor_agreement.rb +58 -0
- data/app/models/digital_object_identifier.rb +83 -0
- data/app/models/doi_config.rb +26 -0
- data/app/models/help_request.rb +34 -0
- data/app/models/mint_doi.rb +51 -0
- data/app/models/mint_purl.rb +40 -0
- data/app/models/object_access.rb +17 -0
- data/app/models/purl.rb +18 -0
- data/app/models/purl_config.rb +10 -0
- data/app/models/repo_object.rb +24 -0
- data/app/models/solr_document.rb +35 -0
- data/app/repository_datastreams/file_content_datastream.rb +36 -0
- data/app/repository_models/curation_concern/embargoable.rb +43 -0
- data/app/repository_models/curation_concern/with_access_right.rb +31 -0
- data/app/repository_models/generic_file.rb +36 -0
- data/app/services/anti_virus_scanner.rb +28 -0
- data/app/services/curation_concern.rb +22 -0
- data/app/services/curation_concern/base_actor.rb +48 -0
- data/app/services/curation_concern/generic_file_actor.rb +38 -0
- data/app/validators/future_date_validator.rb +19 -0
- data/app/views/_footer.html.erb +19 -0
- data/app/views/_ga.html.erb +6 -0
- data/app/views/_logo.html.erb +34 -0
- data/app/views/_masthead.html.erb +34 -0
- data/app/views/catalog/_bookmark_control.html.erb +25 -0
- data/app/views/catalog/_bookmark_form.html.erb +8 -0
- data/app/views/catalog/_citation.html.erb +11 -0
- data/app/views/catalog/_constraints.html.erb +6 -0
- data/app/views/catalog/_constraints_element.html.erb +20 -0
- data/app/views/catalog/_delete_partials/_default.html.erb +29 -0
- data/app/views/catalog/_did_you_mean.html.erb +10 -0
- data/app/views/catalog/_document.html.erb +19 -0
- data/app/views/catalog/_document_list.html.erb +2 -0
- data/app/views/catalog/_edit_partials/_default.html.erb +58 -0
- data/app/views/catalog/_edit_partials/_default_details.html.erb +13 -0
- data/app/views/catalog/_email_form.html.erb +11 -0
- data/app/views/catalog/_facet_layout.html.erb +12 -0
- data/app/views/catalog/_facet_limit.html.erb +19 -0
- data/app/views/catalog/_facet_selected.html.erb +12 -0
- data/app/views/catalog/_facets.html.erb +5 -0
- data/app/views/catalog/_folder_control.html.erb +12 -0
- data/app/views/catalog/_home.html.erb +2 -0
- data/app/views/catalog/_home_text.html.erb +10 -0
- data/app/views/catalog/_index_default.html.erb +11 -0
- data/app/views/catalog/_index_partials/_default_group.html.erb +37 -0
- data/app/views/catalog/_marc_view.html.erb +33 -0
- data/app/views/catalog/_opensearch_response_metadata.html.erb +2 -0
- data/app/views/catalog/_previous_next_doc.html.erb +6 -0
- data/app/views/catalog/_refworks_form.html.erb +7 -0
- data/app/views/catalog/_results_pagination.html.erb +6 -0
- data/app/views/catalog/_search_form.html.erb +20 -0
- data/app/views/catalog/_show_default.html.erb +9 -0
- data/app/views/catalog/_show_partials/_default.html.erb +22 -0
- data/app/views/catalog/_show_partials/_default_details.html.erb +15 -0
- data/app/views/catalog/_show_partials/_facets.html.erb +52 -0
- data/app/views/catalog/_show_sidebar.html.erb +1 -0
- data/app/views/catalog/_show_tools.html.erb +46 -0
- data/app/views/catalog/_sms_form.html.erb +21 -0
- data/app/views/catalog/_sort_and_per_page.html.erb +38 -0
- data/app/views/catalog/_uva_tabs.html.erb +10 -0
- data/app/views/catalog/about.html.erb +0 -0
- data/app/views/catalog/citation.html.erb +1 -0
- data/app/views/catalog/email.erb +1 -0
- data/app/views/catalog/endnote.endnote.erb +1 -0
- data/app/views/catalog/index.atom.builder +109 -0
- data/app/views/catalog/index.html.erb +55 -0
- data/app/views/catalog/index.rss.builder +19 -0
- data/app/views/catalog/librarian_view.html.erb +3 -0
- data/app/views/catalog/opensearch.json.erb +0 -0
- data/app/views/catalog/opensearch.xml.builder +10 -0
- data/app/views/catalog/send_email_record.erb +0 -0
- data/app/views/catalog/show.endnote.erb +1 -0
- data/app/views/catalog/show.html.erb +40 -0
- data/app/views/catalog/show.refworks.erb +1 -0
- data/app/views/catalog/sms.erb +1 -0
- data/app/views/classify_concerns/new.html.erb +24 -0
- data/app/views/common_objects/_generic_file.html.erb +0 -0
- data/app/views/common_objects/_senior_thesis.html.erb +2 -0
- data/app/views/common_objects/show.html.erb +11 -0
- data/app/views/common_objects/show_stub_information.html.erb +13 -0
- data/app/views/curation_concern/_content_license.html.erb +16 -0
- data/app/views/curation_concern/_contributor_agreement.html.erb +27 -0
- data/app/views/curation_concern/_doi.html.erb +43 -0
- data/app/views/curation_concern/_media_display.html.erb +1 -0
- data/app/views/curation_concern/_permission.html.erb +39 -0
- data/app/views/curation_concern/_related_files.html.erb +46 -0
- data/app/views/curation_concern/generic_files/_attributes.html.erb +63 -0
- data/app/views/curation_concern/generic_files/_form.html.erb +57 -0
- data/app/views/curation_concern/generic_files/edit.html.erb +5 -0
- data/app/views/curation_concern/generic_files/new.html.erb +5 -0
- data/app/views/curation_concern/generic_files/show.html.erb +12 -0
- data/app/views/curation_concern/senior_theses/_attributes.html.erb +13 -0
- data/app/views/curation_concern/senior_theses/_form.html.erb +88 -0
- data/app/views/curation_concern/senior_theses/edit.html.erb +15 -0
- data/app/views/curation_concern/senior_theses/new.html.erb +14 -0
- data/app/views/curation_concern/senior_theses/show.html.erb +18 -0
- data/app/views/dashboard/_constraints.html.erb +22 -0
- data/app/views/dashboard/_did_you_mean.html.erb +26 -0
- data/app/views/dashboard/_document_list.html.erb +20 -0
- data/app/views/dashboard/_facet_layout.html.erb +27 -0
- data/app/views/dashboard/_facet_limit.html.erb +35 -0
- data/app/views/dashboard/_facet_pagination.html.erb +25 -0
- data/app/views/dashboard/_facet_selected.html.erb +28 -0
- data/app/views/dashboard/_facets.html.erb +22 -0
- data/app/views/dashboard/_index_partials/_default_group.html.erb +37 -0
- data/app/views/dashboard/_index_partials/_list_files.html.erb +66 -0
- data/app/views/dashboard/_index_partials/_thumbnail_display.html.erb +0 -0
- data/app/views/dashboard/_results_pagination.html.erb +22 -0
- data/app/views/dashboard/_search_form.html.erb +36 -0
- data/app/views/dashboard/_show_partials/_default.html.erb +38 -0
- data/app/views/dashboard/_show_partials/_default_details.html.erb +31 -0
- data/app/views/dashboard/_show_partials/_facets.html.erb +103 -0
- data/app/views/dashboard/_sort_and_per_page.html.erb +18 -0
- data/app/views/dashboard/facet.html.erb +38 -0
- data/app/views/dashboard/get_related_file.html.erb +4 -0
- data/app/views/dashboard/index.html.erb +60 -0
- data/app/views/errors/401.html.erb +5 -0
- data/app/views/errors/404.html.erb +16 -0
- data/app/views/errors/500.html.erb +10 -0
- data/app/views/help_requests/new.html.erb +60 -0
- data/app/views/layouts/application.html.erb +14 -0
- data/app/views/layouts/boilerplate.html.erb +28 -0
- data/app/views/layouts/common_objects.html.erb +45 -0
- data/app/views/layouts/curate_nd.html.erb +55 -0
- data/app/views/layouts/curate_nd/1_column.html.erb +22 -0
- data/app/views/layouts/curate_nd/2_column.html.erb +26 -0
- data/app/views/layouts/curate_nd/catalog.html.erb +22 -0
- data/app/views/layouts/curate_nd/dashboard.html.erb +22 -0
- data/app/views/layouts/hydra-head.html.erb +95 -0
- data/app/views/shared/_action_bar.html.erb +30 -0
- data/app/views/shared/_flash_message.html.erb +9 -0
- data/app/views/shared/_site_search.html.erb +18 -0
- data/app/views/terms_of_service_agreements/new.html.erb +136 -0
- data/app/views/welcome/index.html.erb +21 -0
- data/app/workers/characterize_job.rb +4 -0
- data/app/workers/doi_worker.rb +16 -0
- data/config/routes.rb +35 -0
- data/lib/curate.rb +6 -0
- data/lib/curate/engine.rb +46 -0
- data/lib/curate/version.rb +1 -1
- data/spec/abilities/generic_file_abilities_spec.rb +55 -0
- data/spec/controllers/application_controller_spec.rb +38 -0
- data/spec/controllers/classify_concerns_controller_spec.rb +36 -0
- data/spec/controllers/common_objects_controller_spec.rb +112 -0
- data/spec/controllers/curation_concern/base_controller_spec.rb +14 -0
- data/spec/controllers/curation_concern/generic_files_controller_spec.rb +156 -0
- data/spec/controllers/dashboard_controller_spec.rb +85 -0
- data/spec/controllers/downloads_controller_spec.rb +42 -0
- data/spec/controllers/help_requests_controller_spec.rb +42 -0
- data/spec/controllers/terms_of_service_agreements_controller_spec.rb +30 -0
- data/spec/controllers/welcome_controller_spec.rb +10 -0
- data/spec/dummy/app/models/solr_document.rb +4 -0
- data/spec/dummy/app/models/user.rb +13 -0
- data/spec/dummy/config/application.rb +8 -1
- data/spec/dummy/config/database.yml +21 -22
- data/spec/dummy/config/doi.yml +11 -0
- data/spec/dummy/config/fedora.yml +20 -0
- data/spec/dummy/config/initializers/devise.rb +232 -0
- data/spec/dummy/config/initializers/hydra_config.rb +41 -0
- data/spec/dummy/config/initializers/mailboxer.rb +17 -0
- data/spec/dummy/config/initializers/redis_config.rb +45 -0
- data/spec/dummy/config/initializers/sufia.rb +66 -0
- data/spec/dummy/config/purl.yml +15 -0
- data/spec/dummy/config/redis.yml +6 -0
- data/spec/dummy/config/role_map_ci.yml +15 -0
- data/spec/dummy/config/role_map_cucumber.yml +10 -0
- data/spec/dummy/config/role_map_development.yml +12 -0
- data/spec/dummy/config/role_map_pre_production.yml +2 -0
- data/spec/dummy/config/role_map_production.yml +2 -0
- data/spec/dummy/config/role_map_test.yml +15 -0
- data/spec/dummy/config/routes.rb +4 -55
- data/spec/dummy/config/solr.yml +17 -0
- data/spec/dummy/db/migrate/20130130142162_create_purl.rb +55 -0
- data/spec/dummy/db/migrate/20130312135359_create_help_requests.rb +22 -0
- data/spec/dummy/db/migrate/20130408165008_create_users.rb +11 -0
- data/spec/dummy/db/migrate/20130408165009_acts_as_follower_migration.rb +31 -0
- data/spec/dummy/db/migrate/20130408165010_add_social_to_users.rb +27 -0
- data/spec/dummy/db/migrate/20130408165011_create_single_use_links.rb +12 -0
- data/spec/dummy/db/migrate/20130408165012_add_ldap_attrs_to_user.rb +41 -0
- data/spec/dummy/db/migrate/20130408165013_add_avatars_to_users.rb +23 -0
- data/spec/dummy/db/migrate/20130408165014_create_checksum_audit_logs.rb +34 -0
- data/spec/dummy/db/migrate/20130408165015_create_version_committers.rb +29 -0
- data/spec/dummy/db/migrate/20130408165016_add_groups_to_users.rb +25 -0
- data/spec/dummy/db/migrate/20130408165017_create_local_authorities.rb +64 -0
- data/spec/dummy/db/migrate/20130408165018_create_trophies.rb +10 -0
- data/spec/dummy/db/migrate/20130408165022_create_mailboxer.mailboxer_engine.rb +62 -0
- data/spec/dummy/db/migrate/20130408165023_add_notified_object.mailboxer_engine.rb +18 -0
- data/spec/dummy/db/migrate/20130408165024_add_notification_code.mailboxer_engine.rb +14 -0
- data/spec/dummy/db/migrate/20130408165025_add_attachments.mailboxer_engine.rb +10 -0
- data/spec/dummy/db/migrate/20130408165026_rename_receipts_read.mailboxer_engine.rb +10 -0
- data/spec/dummy/db/schema.rb +197 -0
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/dummy/fedora_conf/conf/development/fedora.fcfg +953 -0
- data/spec/dummy/fedora_conf/conf/test/fedora.fcfg +953 -0
- data/spec/dummy/log/development.log +1791 -0
- data/spec/dummy/log/test.log +176333 -0
- data/spec/dummy/solr_conf/conf/schema.xml +692 -0
- data/spec/dummy/solr_conf/conf/solrconfig.xml +299 -0
- data/spec/dummy/solr_conf/solr.xml +35 -0
- data/spec/factories/create_curation_concern.rb +11 -0
- data/spec/factories/create_generic_file.rb +36 -0
- data/spec/factories/help_requests.rb +10 -0
- data/spec/factories/mock_curation_concerns.rb +4 -0
- data/spec/factories/users.rb +8 -0
- data/spec/helpers/application_helper_spec.rb +139 -0
- data/spec/helpers/common_objects_helper_spec.rb +9 -0
- data/spec/models/access_right_spec.rb +47 -0
- data/spec/models/classify_concern_spec.rb +30 -0
- data/spec/models/contributor_agreement_spec.rb +45 -0
- data/spec/models/digital_object_identifier_spec.rb +50 -0
- data/spec/models/help_request_spec.rb +5 -0
- data/spec/models/mint_doi_spec.rb +79 -0
- data/spec/models/mint_purl_spec.rb +38 -0
- data/spec/models/object_access_spec.rb +24 -0
- data/spec/models/purl_spec.rb +22 -0
- data/spec/models/repo_object_spec.rb +39 -0
- data/spec/repository_models/curation_concern/embargoable_spec.rb +69 -0
- data/spec/repository_models/generic_file_spec.rb +38 -0
- data/spec/services/anti_virus_scanner_spec.rb +26 -0
- data/spec/services/curation_concern/base_actor_spec.rb +28 -0
- data/spec/services/curation_concern/generic_file_actor_spec.rb +75 -0
- data/spec/services/curation_concern_spec.rb +34 -0
- data/spec/spec_helper.rb +54 -1
- data/spec/support/environment_override.rb +17 -0
- data/spec/support/matchers/raise_rescue_response_type_matcher.rb +42 -0
- data/spec/support/mock_curation_concern.rb +61 -0
- data/spec/support/shared/shared_examples_is_embargoable.rb +9 -0
- data/spec/support/shared/shared_examples_with_access_rights.rb +33 -0
- data/spec/workers/characterize_job_spec.rb +26 -0
- metadata +686 -10
- data/MIT-LICENSE +0 -20
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
describe GenericFile do
|
3
|
+
subject { GenericFile.new }
|
4
|
+
|
5
|
+
include_examples 'with_access_rights'
|
6
|
+
include_examples 'is_embargoable'
|
7
|
+
|
8
|
+
it { should respond_to(:versions) }
|
9
|
+
it { should respond_to(:human_readable_type) }
|
10
|
+
it { should respond_to(:current_version_id) }
|
11
|
+
it { should respond_to(:file=) }
|
12
|
+
it { should respond_to(:filename) }
|
13
|
+
it { should respond_to(:visibility) }
|
14
|
+
it { should respond_to(:visibility=) }
|
15
|
+
|
16
|
+
it 'uses #noid for #to_param' do
|
17
|
+
subject.to_param.should == subject.noid
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'has no title to display' do
|
21
|
+
subject.to_s.should == "No Title"
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:user) { FactoryGirl.create(:user) }
|
25
|
+
let(:file) { Rack::Test::UploadedFile.new(__FILE__, 'text/plain', false) }
|
26
|
+
let(:persisted_generic_file) {
|
27
|
+
FactoryGirl.create_generic_file(:mock_curation_concern, user, file)
|
28
|
+
}
|
29
|
+
|
30
|
+
it 'has a current version id' do
|
31
|
+
persisted_generic_file.current_version_id.should == "content.0"
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'has file_name as its title to display' do
|
35
|
+
expect(persisted_generic_file.to_s).to eq(File.basename(__FILE__))
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe AntiVirusScanner do
|
4
|
+
let(:object) { GenericFile.new }
|
5
|
+
let(:file_path) { __FILE__ }
|
6
|
+
subject { AntiVirusScanner.new(object) }
|
7
|
+
let(:always_clean_scanner) {
|
8
|
+
lambda {|o| AntiVirusScanner::NO_VIRUS_FOUND_RETURN_VALUE }
|
9
|
+
}
|
10
|
+
let(:always_has_virus_scanner) {
|
11
|
+
lambda {|o| 'virus found' }
|
12
|
+
}
|
13
|
+
describe '#call' do
|
14
|
+
it 'returns true if anti-virus is successful' do
|
15
|
+
subject.scanner_instance = always_clean_scanner
|
16
|
+
expect(subject.call(file_path)).to eq(true)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'raise an exception if anti-virus failed' do
|
20
|
+
subject.scanner_instance = always_has_virus_scanner
|
21
|
+
expect {
|
22
|
+
subject.call(file_path)
|
23
|
+
}.to raise_error(AntiVirusScanner::VirusDetected)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurationConcern::BaseActor do
|
4
|
+
let(:user) { User.new }
|
5
|
+
let(:curation_concern) { GenericFile.new }
|
6
|
+
let(:attributes) { {visibility: visibility} }
|
7
|
+
let(:visibility) { nil }
|
8
|
+
subject { CurationConcern.actor(curation_concern, user, attributes)}
|
9
|
+
describe 'with visibility "1"' do
|
10
|
+
let(:visibility) { "1" }
|
11
|
+
it 'should have visibility' do
|
12
|
+
subject.send(:visibility).should == visibility
|
13
|
+
end
|
14
|
+
it 'should have visibility' do
|
15
|
+
subject.send(:visibility_may_have_changed?).should == true
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
describe 'with missing visibility' do
|
20
|
+
let(:visibility) { nil }
|
21
|
+
it 'should have visibility' do
|
22
|
+
subject.send(:visibility).should be_nil
|
23
|
+
end
|
24
|
+
it 'should have visibility' do
|
25
|
+
subject.send(:visibility_may_have_changed?).should == false
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurationConcern::GenericFileActor do
|
4
|
+
let(:user) { FactoryGirl.create(:user) }
|
5
|
+
let(:parent) { FactoryGirl.create_curation_concern(:mock_curation_concern, user) }
|
6
|
+
let(:file_path) { __FILE__ }
|
7
|
+
let(:file) { Rack::Test::UploadedFile.new(file_path, 'text/plain', false)}
|
8
|
+
let(:file_content) { File.read(file)}
|
9
|
+
let(:title) { Time.now.to_s }
|
10
|
+
let(:attributes) {
|
11
|
+
{ file: file, title: title, visibility: AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED }
|
12
|
+
}
|
13
|
+
|
14
|
+
subject {
|
15
|
+
CurationConcern::GenericFileActor.new(generic_file, user, attributes)
|
16
|
+
}
|
17
|
+
|
18
|
+
describe '#create!' do
|
19
|
+
let(:generic_file) { GenericFile.new.tap {|gf| gf.batch = parent } }
|
20
|
+
let(:reloaded_generic_file) {
|
21
|
+
generic_file.class.find(generic_file.pid)
|
22
|
+
}
|
23
|
+
describe 'with a file' do
|
24
|
+
it 'succeeds if attributes are given' do
|
25
|
+
expect {
|
26
|
+
subject.create!
|
27
|
+
}.to change {
|
28
|
+
parent.class.find(parent.pid).generic_files.count
|
29
|
+
}.by(1)
|
30
|
+
|
31
|
+
reloaded_generic_file.batch.should == parent
|
32
|
+
reloaded_generic_file.to_s.should == title
|
33
|
+
reloaded_generic_file.filename.should == File.basename(__FILE__)
|
34
|
+
|
35
|
+
expect(reloaded_generic_file.to_solr['read_access_group_t']).to eq(['registered'])
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'fails if no batch is provided' do
|
39
|
+
generic_file.batch = nil
|
40
|
+
expect {
|
41
|
+
expect {
|
42
|
+
subject.create!
|
43
|
+
}.to raise_error(ActiveFedora::RecordInvalid)
|
44
|
+
}.to_not change { GenericFile.count }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe 'without a file' do
|
49
|
+
let(:file) { nil }
|
50
|
+
it 'fails if no batch is provided' do
|
51
|
+
expect{
|
52
|
+
expect {
|
53
|
+
subject.create!
|
54
|
+
}.to raise_error(ActiveFedora::RecordInvalid)
|
55
|
+
}.to_not change { GenericFile.count }
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#update!' do
|
61
|
+
let(:generic_file) {
|
62
|
+
FactoryGirl.create_generic_file(parent, user)
|
63
|
+
}
|
64
|
+
it do
|
65
|
+
generic_file.title.should_not == title
|
66
|
+
generic_file.content.content.should_not == file_content
|
67
|
+
expect {
|
68
|
+
subject.update!
|
69
|
+
}.to change {generic_file.versions.count}.by(1)
|
70
|
+
generic_file.title.should == title
|
71
|
+
generic_file.to_s.should == title
|
72
|
+
generic_file.content.content.should == file_content
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CurationConcern do
|
4
|
+
subject {CurationConcern}
|
5
|
+
it 'can mint_a_pid' do
|
6
|
+
subject.should respond_to(:mint_a_pid)
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '.actor' do
|
10
|
+
it 'finds an actor by for a GenericFile' do
|
11
|
+
subject.actor(GenericFile.new, User.new, {}).should(
|
12
|
+
be_kind_of(CurationConcern::GenericFileActor)
|
13
|
+
)
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'raise an exception if there is no actor' do
|
17
|
+
expect {
|
18
|
+
subject.actor("", User.new, {})
|
19
|
+
}.to raise_error(NameError)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe '.attach_file' do
|
24
|
+
let(:file) { Rack::Test::UploadedFile.new(__FILE__, 'text/plain', false) }
|
25
|
+
let(:user) { FactoryGirl.create(:user) }
|
26
|
+
let(:generic_file) { GenericFile.new }
|
27
|
+
let(:curation_concern) { FactoryGirl.create_curation_concern(:mock_curation_concern, user) }
|
28
|
+
it 'works with a string' do
|
29
|
+
actor = CurationConcern.actor(generic_file, user, {batch_id: curation_concern.pid, file: file})
|
30
|
+
actor.create!
|
31
|
+
generic_file.content.content.should == file.read
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,23 @@
|
|
1
1
|
# Configure Rails Environment
|
2
|
-
ENV["RAILS_ENV"]
|
2
|
+
ENV["RAILS_ENV"] ||= 'test'
|
3
|
+
|
4
|
+
if ENV['COVERAGE']
|
5
|
+
require 'simplecov'
|
6
|
+
SimpleCov.start 'rails'
|
7
|
+
SimpleCov.command_name "spec"
|
8
|
+
end
|
3
9
|
|
4
10
|
require File.expand_path("../dummy/config/environment.rb", __FILE__)
|
5
11
|
require "rails/test_help"
|
12
|
+
require 'rspec/rails'
|
13
|
+
require 'webmock/rspec'
|
14
|
+
require 'rspec-html-matchers'
|
15
|
+
require 'rspec/autorun'
|
16
|
+
require 'database_cleaner'
|
17
|
+
require 'factory_girl'
|
18
|
+
|
19
|
+
Dir["#{File.dirname(__FILE__)}/factories/**/*.rb"].each { |f| require f }
|
20
|
+
|
6
21
|
|
7
22
|
Rails.backtrace_cleaner.remove_silencers!
|
8
23
|
|
@@ -13,3 +28,41 @@ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
|
13
28
|
if ActiveSupport::TestCase.method_defined?(:fixture_path=)
|
14
29
|
ActiveSupport::TestCase.fixture_path = File.expand_path("../fixtures", __FILE__)
|
15
30
|
end
|
31
|
+
|
32
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
33
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
34
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
35
|
+
# loaded once.
|
36
|
+
#
|
37
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
38
|
+
RSpec.configure do |config|
|
39
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
40
|
+
config.run_all_when_everything_filtered = true
|
41
|
+
|
42
|
+
# Run specs in random order to surface order dependencies. If you find an
|
43
|
+
# order dependency and want to debug it, you can fix the order by providing
|
44
|
+
# the seed, which is printed after each run.
|
45
|
+
# --seed 1234
|
46
|
+
config.order = 'random'
|
47
|
+
|
48
|
+
config.include Devise::TestHelpers, type: :controller
|
49
|
+
|
50
|
+
config.use_transactional_fixtures = false
|
51
|
+
|
52
|
+
config.before(:all) do
|
53
|
+
WebMock.allow_net_connect!
|
54
|
+
end
|
55
|
+
|
56
|
+
config.before(:suite) do
|
57
|
+
DatabaseCleaner.strategy = :truncation
|
58
|
+
DatabaseCleaner.clean_with(:truncation)
|
59
|
+
end
|
60
|
+
|
61
|
+
config.before(:each) do
|
62
|
+
DatabaseCleaner.start
|
63
|
+
end
|
64
|
+
|
65
|
+
config.after(:each) do
|
66
|
+
DatabaseCleaner.clean
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module EnvironmentOverride
|
2
|
+
module_function
|
3
|
+
def with_anti_virus_scanner(success = true)
|
4
|
+
if ! Rails.configuration.respond_to?(:default_antivirus_instance)
|
5
|
+
raise RuntimeError, "Undefined Rails.configuration.default_antivirus_instance"
|
6
|
+
end
|
7
|
+
before_override = Rails.configuration.default_antivirus_instance
|
8
|
+
|
9
|
+
instance = success ? lambda {|f| 0 } : lambda {|f| 1 }
|
10
|
+
Rails.configuration.default_antivirus_instance = instance
|
11
|
+
yield
|
12
|
+
ensure
|
13
|
+
if Rails.configuration.respond_to?(:default_antivirus_instance)
|
14
|
+
Rails.configuration.default_antivirus_instance = before_override
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# RSpec matcher to spec delegations.
|
2
|
+
|
3
|
+
RSpec::Matchers.define :raise_rescue_response_type do |expected_rescue_response|
|
4
|
+
match do |response|
|
5
|
+
@expected_rescue_response = expected_rescue_response.to_sym
|
6
|
+
@exception = nil
|
7
|
+
|
8
|
+
begin
|
9
|
+
@status = response.call.status
|
10
|
+
rescue Exception => e
|
11
|
+
@exception = e
|
12
|
+
end
|
13
|
+
|
14
|
+
if @exception.nil?
|
15
|
+
@actual_rescue_response = @status
|
16
|
+
@status == Rack::Utils.status_code(@expected_rescue_response)
|
17
|
+
else
|
18
|
+
response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name]
|
19
|
+
@actual_rescue_response = ActionDispatch::ExceptionWrapper.rescue_responses[@exception.class.name].to_sym
|
20
|
+
@actual_rescue_response == @expected_rescue_response
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
description do
|
25
|
+
"expected to raise an exception with rescue_response #{@expected_rescue_response.inspect}"
|
26
|
+
end
|
27
|
+
|
28
|
+
failure_message_for_should do |text|
|
29
|
+
text = "expected to raise an exception with rescue_response"
|
30
|
+
text << " #{@expected_rescue_response.inspect} instead got #{@actual_rescue_response.inspect}"
|
31
|
+
text << " (Exception #{@exception.class}: #{@exception})" if @exception
|
32
|
+
text
|
33
|
+
end
|
34
|
+
|
35
|
+
failure_message_for_should_not do |text|
|
36
|
+
text = "expected to NOT raise an exception with rescue_response"
|
37
|
+
text << " #{@expected_rescue_response.inspect} but got #{@actual_rescue_response.inspect}"
|
38
|
+
text << " (Exception #{@exception.class}: #{@exception})" if @exception
|
39
|
+
text
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
class MockCurationConcern < ActiveFedora::Base
|
2
|
+
class MetadataDatastream < ActiveFedora::NtriplesRDFDatastream
|
3
|
+
map_predicates do |map|
|
4
|
+
map.title(in: RDF::DC) do |index|
|
5
|
+
index.as :searchable, :displayable
|
6
|
+
end
|
7
|
+
map.created(in: RDF::DC)
|
8
|
+
map.creator(in: RDF::DC) do |index|
|
9
|
+
index.as :searchable, :facetable, :displayable
|
10
|
+
end
|
11
|
+
map.date_uploaded(to: "dateSubmitted", in: RDF::DC) do |index|
|
12
|
+
index.type :date
|
13
|
+
index.as :searchable, :displayable, :sortable
|
14
|
+
end
|
15
|
+
map.date_modified(to: "modified", in: RDF::DC) do |index|
|
16
|
+
index.type :date
|
17
|
+
index.as :searchable, :displayable, :sortable
|
18
|
+
end
|
19
|
+
map.part(:to => "hasPart", in: RDF::DC)
|
20
|
+
map.identifier({in: RDF::DC})
|
21
|
+
end
|
22
|
+
end
|
23
|
+
include Hydra::ModelMixins::CommonMetadata
|
24
|
+
include Sufia::ModelMethods
|
25
|
+
include Sufia::Noid
|
26
|
+
include Sufia::GenericFile::Permissions
|
27
|
+
include CurationConcern::Embargoable
|
28
|
+
include CurationConcern::WithAccessRight
|
29
|
+
|
30
|
+
has_metadata name: "properties", type: PropertiesDatastream, control_group: 'M'
|
31
|
+
delegate_to :properties, [:relative_path, :depositor], unique: true
|
32
|
+
|
33
|
+
has_metadata name: "descMetadata", type: MockCurationConcern::MetadataDatastream, control_group: 'M'
|
34
|
+
|
35
|
+
delegate_to(
|
36
|
+
:descMetadata,
|
37
|
+
[
|
38
|
+
:title,
|
39
|
+
:date_uploaded,
|
40
|
+
:date_modified,
|
41
|
+
:creator,
|
42
|
+
:identifier,
|
43
|
+
],
|
44
|
+
unique: true
|
45
|
+
)
|
46
|
+
|
47
|
+
has_many :generic_files, property: :is_part_of
|
48
|
+
|
49
|
+
after_destroy :after_destroy_cleanup
|
50
|
+
def after_destroy_cleanup
|
51
|
+
generic_files.each(&:destroy)
|
52
|
+
end
|
53
|
+
|
54
|
+
def human_readable_type
|
55
|
+
self.class.to_s.demodulize.titleize
|
56
|
+
end
|
57
|
+
def to_param
|
58
|
+
pid.split(':').last
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
shared_examples 'with_access_rights' do
|
3
|
+
|
4
|
+
it "has an under_embargo?" do
|
5
|
+
expect {
|
6
|
+
subject.under_embargo?
|
7
|
+
}.to_not raise_error(NoMethodError)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "has a visibility attribute" do
|
11
|
+
expect(subject).to respond_to(:visibility)
|
12
|
+
expect(subject).to respond_to(:visibility=)
|
13
|
+
end
|
14
|
+
|
15
|
+
it "has an open_access?" do
|
16
|
+
expect {
|
17
|
+
subject.open_access?
|
18
|
+
}.to_not raise_error(NoMethodError)
|
19
|
+
end
|
20
|
+
|
21
|
+
it "has an authenticated_only_access?" do
|
22
|
+
expect {
|
23
|
+
subject.authenticated_only_access?
|
24
|
+
}.to_not raise_error(NoMethodError)
|
25
|
+
end
|
26
|
+
|
27
|
+
it "has an private_access?" do
|
28
|
+
expect {
|
29
|
+
subject.private_access?
|
30
|
+
}.to_not raise_error(NoMethodError)
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CharacterizeJob do
|
4
|
+
|
5
|
+
# I'm not entirely certain where I want to put this. Given that it is
|
6
|
+
# leaning on an actor, I'd like to put it there. But actors are going to
|
7
|
+
# push to a queue, so it is the worker that should choke.
|
8
|
+
describe '#run' do
|
9
|
+
let(:user) { FactoryGirl.create(:user) }
|
10
|
+
let(:curation_concern) {
|
11
|
+
MockCurationConcern.new.tap(&:save)
|
12
|
+
}
|
13
|
+
let(:generic_file) {
|
14
|
+
FactoryGirl.create_generic_file(curation_concern, user)
|
15
|
+
}
|
16
|
+
subject { CharacterizeJob.new(generic_file.pid) }
|
17
|
+
|
18
|
+
it 'deletes the generic file when I upload a virus' do
|
19
|
+
EnvironmentOverride.with_anti_virus_scanner(false) do
|
20
|
+
expect {
|
21
|
+
subject.run
|
22
|
+
}.to raise_error(AntiVirusScanner::VirusDetected)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|