Skip to content

Commit

Permalink
mock omniauth, complete user in seed db to be admin and editor, updat…
Browse files Browse the repository at this point in the history
…e seed entries to upsert instead of error if they already exist
  • Loading branch information
sneakers-the-rat committed Oct 12, 2024
1 parent 04ea430 commit ada4bbe
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 7 deletions.
21 changes: 21 additions & 0 deletions config/environments/development.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

config.log_level = :debug

# In the development environment your application's code is reloaded any time
# it changes. This slows down response time but is perfect for development
# since you don't have to restart the web server when you make code changes.
Expand Down Expand Up @@ -78,4 +80,23 @@

# Raise error when a before_action's only/except options reference missing actions.
config.action_controller.raise_on_missing_callback_actions = true

# Mock the OmniAuth provider for orcid in dev environment
# Rather than actually pinging orcid, auto-login as a
# test user that is an editor and admin (see db/seed.rb)
# the uid and provider need to match in order for
# a new account to not be created (and use the one in db/seed.rb)
OmniAuth.config.test_mode = true
OmniAuth.config.mock_auth[:orcid] = OmniAuth::AuthHash.new({
:provider => 'orcid',
:uid => '12345',
:info => {
:name => 'Lord Fakington',
:email => 'lordfake@example.com'
},
:credentials => {
:token => '56789',
:expires_at => 10.years.since
}
})
end
40 changes: 33 additions & 7 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -357,21 +357,34 @@

case Rails.env
when "development"
aeic = Editor.create!(
aeic = Editor.find_or_initialize_by(login: "aeicfake")
aeic.update(
kind: "board",
first_name: "Editor In Chief",
last_name: "Fakington",
login: "aeicfake",
email: "aeicfake@example.com",
categories: ["Astronomy"]
)
track = Track.create!(
code: 0,
aeic.save

track = Track.find_or_initialize_by(code: 0)
track.update(
name: "Railroad",
short_name: "rail",
aeics: [aeic]
)
editor = Editor.create!(
track.save

subject = Subject.find_or_initialize_by(name: "Trains")
subject.update(
track: track,
created_at: 10.minutes.ago,
updated_at: Time.now
)
subject.save

editor = Editor.find_or_initialize_by(login: 'lordfake')
editor.update(
kind: "topic",
first_name: "Lord",
last_name: "Fakington",
Expand All @@ -380,13 +393,26 @@
categories: ["Astronomy"],
tracks: [track]
)
user = User.create!(
editor.save

editor_user = User.find_or_initialize_by(uid: 12345)
editor_user.update(
name: 'Lord Fakington',
email: 'lordfake@example.com',
admin: true,
provider: 'orcid',
github_username: 'lordfake_namedoesnt_exist',
editor: editor
)
editor_user.save

user = User.create(
name: "Sneakers T. Rat",
email: "sneakers@example.com",
github_username: "fakeuser_namedoesnt_exist"
)

paper = Paper.create!(
paper = Paper.create(
editor: editor,
submitting_author: user,
title: "On the mysteries of draperies and various such textiles",
Expand Down

0 comments on commit ada4bbe

Please sign in to comment.