diff --git a/Gemfile b/Gemfile index 51c732110..373a51bdb 100644 --- a/Gemfile +++ b/Gemfile @@ -91,6 +91,7 @@ group :development do gem "spring" gem "spring-watcher-listen", "~> 2.0.0" gem "spring-commands-rspec" + gem "seedbank" # gem "httplog", "~> 1.0" end diff --git a/README.md b/README.md index d0861d125..778db40ea 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,16 @@ You can now point your browser to `http://localhost:8065` and use the applicatio ## Development +For basic setup one can use the following: + +```bash +bundle exec rake db:create +bundle exec rake db:schema:load +bundle exec rake db:seed:development:base +``` + +All other seed opntion can be found using rake --tasks + We use Rspec for testing: ```bash diff --git a/db/seeds/development/base.seeds.rb b/db/seeds/development/base.seeds.rb new file mode 100644 index 000000000..dd1c92b03 --- /dev/null +++ b/db/seeds/development/base.seeds.rb @@ -0,0 +1,15 @@ +require "factory_bot_rails" + +fail "Seed tasks can only be used in the development enviroment" if Rails.env.production? +fail "You need to set up a MDS_USERNAME and MDS_PASSWORD" if ENV["MDS_USERNAME"].blank? || ENV["MDS_PASSWORD"].blank? + +FactoryBot.create(:provider, symbol: "ADMIN") if Provider.where(symbol: "ADMIN").blank? +provider = Provider.where(symbol: "DATACITE").first || FactoryBot.create(:provider, symbol: "DATACITE") +client = Client.where(symbol: "DATACITE.TEST").first || FactoryBot.create(:client, provider: provider, symbol: ENV["MDS_USERNAME"], password: ENV["MDS_PASSWORD"]) +if Prefix.where(uid: "10.14454").blank? + prefix = FactoryBot.create(:prefix, uid: "10.14454") + FactoryBot.create(:client_prefix, client_id: client.id, prefix_id: prefix.id) +end +dois = FactoryBot.create_list(:doi, 10, client: client, state: "findable") +FactoryBot.create_list(:event_for_datacite_related, 3, obj_id: dois.first.doi) +FactoryBot.create_list(:event_for_datacite_usage, 2, obj_id: dois.first.doi) \ No newline at end of file diff --git a/db/seeds/development/researcher_profile.seeds.rb b/db/seeds/development/researcher_profile.seeds.rb new file mode 100644 index 000000000..05819ea0e --- /dev/null +++ b/db/seeds/development/researcher_profile.seeds.rb @@ -0,0 +1,13 @@ +require "factory_bot_rails" + +fail "Seed tasks can only be used in the development enviroment" if Rails.env.production? + +after "development:base" do + client = Client.all.first + dois = FactoryBot.create_list(:doi, 70, client: client, state: "findable") + + FactoryBot.create_list(:event_for_datacite_related, 34, obj_id: dois.first.doi) + FactoryBot.create_list(:event_for_datacite_usage, 32, obj_id: dois.first.doi) + FactoryBot.create(:event_for_datacite_orcid_auto_update, subj_id: dois.first.doi, obj_id: "http://orcid.org/0000-0003-2926-8353") + FactoryBot.create_list(:event_for_datacite_orcid_auto_update, 5, obj_id: "http://orcid.org/0000-0003-2926-8353") +end diff --git a/spec/factories/default.rb b/spec/factories/default.rb index 2a8368f13..eb6585f61 100644 --- a/spec/factories/default.rb +++ b/spec/factories/default.rb @@ -1,8 +1,8 @@ -require 'faker' +require "faker" FactoryBot.define do factory :user do - sequence(:name) { |n| "Josiah Carberry{n}" } + sequence(:name) { |_n| "Josiah Carberry{n}" } provider { "globus" } role_id { "user" } sequence(:uid) { |n| "0000-0002-1825-000#{n}" } @@ -23,12 +23,12 @@ end factory :valid_user do - uid { '0000-0001-6528-2027' } - orcid_token { ENV['ACCESS_TOKEN'] } + uid { "0000-0001-6528-2027" } + orcid_token { ENV["ACCESS_TOKEN"] } end factory :invalid_user do - uid { '0000-0001-6528-2027' } + uid { "0000-0001-6528-2027" } orcid_token { nil } end @@ -39,11 +39,13 @@ provider system_email { "josiah@example.org" } - service_contact {{ - "email": "martin@example.com", - "given_name": "Martin", - "family_name": "Fenner" - }} + service_contact do + { + "email": "martin@example.com", + "given_name": "Martin", + "family_name": "Fenner", + } + end globus_uuid { "bc7d0274-3472-4a79-b631-e4c7baccc667" } sequence(:symbol) { |n| provider.symbol + ".TEST#{n}" } name { "My data center" } @@ -65,123 +67,139 @@ doi { ("10.14454/" + Faker::Internet.password(8)).downcase } url { Faker::Internet.url } - types { { - "resourceTypeGeneral": "Dataset", - "resourceType": "DataPackage", - "schemaOrg": "Dataset", - "citeproc": "dataset", - "bibtex": "misc", - "ris": "DATA" - }} - creators { [ - { - "nameType": "Personal", - "name": "Ollomo, Benjamin", - "givenName": "Benjamin", - "familyName": "Ollomo" - }, - { - "nameType": "Personal", - "name": "Durand, Patrick", - "givenName": "Patrick", - "familyName": "Durand" - }, - { - "nameType": "Personal", - "name": "Prugnolle, Franck", - "givenName": "Franck", - "familyName": "Prugnolle" - }, + types do { - "nameType": "Personal", - "name": "Douzery, Emmanuel J. P.", - "givenName": "Emmanuel J. P.", - "familyName": "Douzery" - }, - { - "nameType": "Personal", - "name": "Arnathau, Céline", - "givenName": "Céline", - "familyName": "Arnathau" - }, - { - "nameType": "Personal", - "name": "Nkoghe, Dieudonné", - "givenName": "Dieudonné", - "familyName": "Nkoghe" - }, - { - "nameType": "Personal", - "name": "Leroy, Eric", - "givenName": "Eric", - "familyName": "Leroy" - }, - { - "nameType": "Personal", - "name": "Renaud, François", - "givenName": "François", - "familyName": "Renaud", - "nameIdentifiers": [ - { - "nameIdentifier": "https://orcid.org/0000-0003-1419-2405", - "nameIdentifierScheme": "ORCID", - "schemeUri": "https://orcid.org" - }, - ], - "affiliation": [ - { - "name": "DataCite", - "affiliationIdentifier": "https://ror.org/04wxnsj81", - "affiliationIdentifierScheme": "ROR" - }, - ] + "resourceTypeGeneral": "Dataset", + "resourceType": "DataPackage", + "schemaOrg": "Dataset", + "citeproc": "dataset", + "bibtex": "misc", + "ris": "DATA", } - ] } - titles {[ + end + creators do + [ { - "title": "Data from: A new malaria agent in African hominids." - }] } - descriptions {[ - { - "description": "Data from: A new malaria agent in African hominids." - }] } - publisher {"Dryad Digital Repository" } - subjects {[ + "nameType": "Personal", + "name": "Ollomo, Benjamin", + "givenName": "Benjamin", + "familyName": "Ollomo", + }, { - "subject": "Phylogeny" + "nameType": "Personal", + "name": "Durand, Patrick", + "givenName": "Patrick", + "familyName": "Durand", }, { - "subject": "Malaria" + "nameType": "Personal", + "name": "Prugnolle, Franck", + "givenName": "Franck", + "familyName": "Prugnolle", }, { - "subject": "Parasites" + "nameType": "Personal", + "name": "Douzery, Emmanuel J. P.", + "givenName": "Emmanuel J. P.", + "familyName": "Douzery", }, { - "subject": "Taxonomy" + "nameType": "Personal", + "name": "Arnathau, Céline", + "givenName": "Céline", + "familyName": "Arnathau", }, { - "subject": "Mitochondrial genome" + "nameType": "Personal", + "name": "Nkoghe, Dieudonné", + "givenName": "Dieudonné", + "familyName": "Nkoghe", }, { - "subject": "Africa" + "nameType": "Personal", + "name": "Leroy, Eric", + "givenName": "Eric", + "familyName": "Leroy", }, { - "subject": "Plasmodium" - } - ]} - dates { [ - { - "date": "2011", - "dateType": "Issued" - } - ]} + "nameType": "Personal", + "name": "Renaud, François", + "givenName": "François", + "familyName": "Renaud", + "nameIdentifiers": [ + { + "nameIdentifier": "https://orcid.org/0000-0003-1419-2405", + "nameIdentifierScheme": "ORCID", + "schemeUri": "https://orcid.org", + }, + ], + "affiliation": [ + { + "name": "DataCite", + "affiliationIdentifier": "https://ror.org/04wxnsj81", + "affiliationIdentifierScheme": "ROR", + }, + ], + }, + ] + end + titles do + [ + { + "title": "Data from: A new malaria agent in African hominids.", + }, + ] + end + descriptions do + [ + { + "description": "Data from: A new malaria agent in African hominids.", + }, + ] + end + publisher { "Dryad Digital Repository" } + subjects do + [ + { + "subject": "Phylogeny", + }, + { + "subject": "Malaria", + }, + { + "subject": "Parasites", + }, + { + "subject": "Taxonomy", + }, + { + "subject": "Mitochondrial genome", + }, + { + "subject": "Africa", + }, + { + "subject": "Plasmodium", + }, + ] + end + dates do + [ + { + "date": "2011", + "dateType": "Issued", + }, + ] + end publication_year { 2011 } - identifiers { [ - { - "identifierType": "citation", - "identifier": "Ollomo B, Durand P, Prugnolle F, Douzery EJP, Arnathau C, Nkoghe D, Leroy E, Renaud F (2009) A new malaria agent in African hominids. PLoS Pathogens 5(5): e1000446." - } - ]} + identifiers do + [ + { + "identifierType": "citation", + "identifier": "Ollomo B, Durand P, Prugnolle F, Douzery EJP, Arnathau C, Nkoghe D, Leroy E, Renaud F (2009) A new malaria agent in African hominids. PLoS Pathogens 5(5): e1000446.", + }, + ] + end version { "1" } rights_list {[ { @@ -257,50 +275,66 @@ password_input { "12345" } twitter_handle { "@egaTwitterlac" } ror_id { "https://ror.org/05njkjr15" } - billing_information {{ - "city": "barcelona", - "state": "cataluyna", - "department": "sales", - "country": "CN", - "organization": "testing org", - "address": Faker::Address.street_address, - "postCode": "10777" - }} - technical_contact {{ - "email": "kristian@example.com", - "given_name": "Kristian", - "family_name": "Garza" - }} - secondary_technical_contact {{ - "email": "kristian@example.com", - "given_name": "Kristian", - "family_name": "Garza" - }} - billing_contact {{ - "email": "trisha@example.com", - "given_name": "Trisha", - "family_name": "Cruse" - }} - secondary_billing_contact {{ - "email": "trisha@example.com", - "given_name": "Trisha", - "family_name": "Cruse" - }} - service_contact {{ - "email": "martin@example.com", - "given_name": "Martin", - "family_name": "Fenner" - }} - secondary_service_contact {{ - "email": "martin@example.com", - "given_name": "Martin", - "family_name": "Fenner" - }} - voting_contact {{ - "email": "robin@example.com", - "given_name": "Robin", - "family_name": "Dasler" - }} + billing_information do + { + "city": "barcelona", + "state": "cataluyna", + "department": "sales", + "country": "CN", + "organization": "testing org", + "address": Faker::Address.street_address, + "postCode": "10777", + } + end + technical_contact do + { + "email": "kristian@example.com", + "given_name": "Kristian", + "family_name": "Garza", + } + end + secondary_technical_contact do + { + "email": "kristian@example.com", + "given_name": "Kristian", + "family_name": "Garza", + } + end + billing_contact do + { + "email": "trisha@example.com", + "given_name": "Trisha", + "family_name": "Cruse", + } + end + secondary_billing_contact do + { + "email": "trisha@example.com", + "given_name": "Trisha", + "family_name": "Cruse", + } + end + service_contact do + { + "email": "martin@example.com", + "given_name": "Martin", + "family_name": "Fenner", + } + end + secondary_service_contact do + { + "email": "martin@example.com", + "given_name": "Martin", + "family_name": "Fenner", + } + end + voting_contact do + { + "email": "robin@example.com", + "given_name": "Robin", + "family_name": "Dasler", + } + end is_active { true } initialize_with { Provider.where(symbol: symbol).first_or_initialize } @@ -311,7 +345,7 @@ association :provider, factory: :provider, strategy: :create end - factory :activity do + factory :activity do association :auditable, factory: :doi, strategy: :create end @@ -321,14 +355,16 @@ source_token { "citeulike_123" } sequence(:subj_id) { |n| "http://www.citeulike.org/user/dbogartoit/#{n}" } obj_id { "http://doi.org/10.1371/journal.pmed.0030186" } - subj {{ "@id" => "http://www.citeulike.org/user/dbogartoit", - "@type" => "CreativeWork", - "uid" => "http://www.citeulike.org/user/dbogartoit", - "author" => [{ "given" => "dbogartoit" }], - "name" => "CiteULike bookmarks for user dbogartoit", - "publisher" => "CiteULike", - "datePublished" => "2006-06-13T16:14:19Z", - "url" => "http://www.citeulike.org/user/dbogartoit" }} + subj do + { "@id" => "http://www.citeulike.org/user/dbogartoit", + "@type" => "CreativeWork", + "uid" => "http://www.citeulike.org/user/dbogartoit", + "author" => [{ "given" => "dbogartoit" }], + "name" => "CiteULike bookmarks for user dbogartoit", + "publisher" => "CiteULike", + "datePublished" => "2006-06-13T16:14:19Z", + "url" => "http://www.citeulike.org/user/dbogartoit" } + end obj {} relation_type_id { "bookmarks" } updated_at { Time.zone.now } @@ -400,7 +436,7 @@ source_id { "datacite-usage" } source_token { "5348967fhdjksr3wyui325" } total { 25 } - sequence(:subj_id) { |n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } + sequence(:subj_id) { |_n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } subj { { "datePublished" => "2006-06-13T16:14:19Z" } } obj { { "date_published" => "2007-06-13T16:14:19Z" } } obj_id { "http://doi.org/10.5061/DRYAD.47SD5/1" } @@ -412,7 +448,7 @@ source_id { "datacite-usage" } source_token { "5348967fhdjksr3wyui325" } total { 10 } - sequence(:subj_id) { |n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } + sequence(:subj_id) { |_n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } subj { { "datePublished" => "2006-06-13T16:14:19Z" } } obj { { "date_published" => "2007-06-13T16:14:19Z" } } obj_id { "http://doi.org/10.5061/DRYAD.47SD5/1" } @@ -424,7 +460,7 @@ source_id { "datacite-usage" } source_token { "5348967fhdjksr3wyui325" } total { rand(1..100).to_int } - sequence(:subj_id) { |n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } + sequence(:subj_id) { |_n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } subj { { "datePublished" => "2006-06-13T16:14:19Z" } } obj {} obj_id { "http://doi.org/10.5061/DRYAD.47SD5/1" } @@ -432,6 +468,18 @@ occurred_at { "2015-06-13T16:14:19Z" } end + factory :event_for_datacite_usage do + source_id { "datacite-usage" } + source_token { "5348967fhdjksr3wyui325" } + total { rand(1..100).to_int } + sequence(:subj_id) { |_n| "https://api.test.datacite.org/report/#{SecureRandom.uuid}" } + subj { { "datePublished" => "2006-06-13T16:14:19Z" } } + obj { { "date_published" => "2007-06-13T16:14:19Z" } } + obj_id { "http://doi.org/10.5061/DRYAD.47SD5/1" } + relation_type_id { "unique-dataset-investigations-regular" } + occurred_at { "2015-06-13T16:14:19Z" } + end + factory :event_for_datacite_orcid_auto_update do source_id { "datacite-orcid-auto-update" } source_token { "5348967fhdjksr3wyui325" }