Skip to content

Commit

Permalink
Merge pull request #406 from datacite/feature_seeds_for_tests
Browse files Browse the repository at this point in the history
Feature seeds for validating in our Development or Stage environment
  • Loading branch information
kjgarza authored Apr 22, 2020
2 parents 79707bc + 2a58ab4 commit c6a57ad
Show file tree
Hide file tree
Showing 5 changed files with 253 additions and 166 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 15 additions & 0 deletions db/seeds/development/base.seeds.rb
Original file line number Diff line number Diff line change
@@ -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)
13 changes: 13 additions & 0 deletions db/seeds/development/researcher_profile.seeds.rb
Original file line number Diff line number Diff line change
@@ -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
Loading

0 comments on commit c6a57ad

Please sign in to comment.