-
Notifications
You must be signed in to change notification settings - Fork 24
Split dev-only user variations into db:seed:users #1574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,198 @@ | ||
| # Dev-only user variations - run on their own via `rake db:seed:users`, or as | ||
| # part of `rake db:seed:dev`. These exercise login/invite/lock edge cases and | ||
| # must never run in production, so they live here rather than in `db/seeds.rb` | ||
| # (which seeds only the required base users: Umberto, Amy, Aisha, Orphaned). | ||
|
|
||
| puts "Seeding dev user variations (invite/lock/confirmation states)…" | ||
|
|
||
| # created_by/updated_by point at the base admin, seeded by `db:seed` first. | ||
| admin = User.find_by!(email: "umberto.user@example.com") | ||
|
|
||
| # Invited but hasn't clicked the link yet | ||
| invited = User.find_or_create_by!(email: "invited.pending@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = Time.current | ||
| end | ||
| unless invited.welcome_instructions_token.present? | ||
| invited.update_columns( | ||
| confirmed_at: nil, | ||
| welcome_instructions_token: Devise.friendly_token, | ||
| welcome_instructions_created_at: 3.days.ago, | ||
| welcome_instructions_sent_at: 3.days.ago | ||
| ) | ||
| end | ||
| unless invited.person.present? | ||
| person = Person.create!( | ||
| first_name: "Invited", | ||
| last_name: "Pending", | ||
| email: invited.email, | ||
| created_by: admin, | ||
| updated_by: admin, | ||
| profile_is_searchable: true | ||
| ) | ||
| invited.update!(person: person) | ||
| end | ||
|
|
||
| # Clicked confirmation link but didn't set password | ||
| confirmed_no_pw = User.find_or_create_by!(email: "confirmed.nopassword@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = Time.current | ||
| end | ||
| unless confirmed_no_pw.welcome_instructions_token.present? | ||
| token = Devise.friendly_token | ||
| confirmed_no_pw.update_columns( | ||
| confirmed_at: 2.days.ago, | ||
| welcome_instructions_token: token, | ||
| welcome_instructions_created_at: 5.days.ago, | ||
| welcome_instructions_sent_at: 5.days.ago | ||
| ) | ||
| end | ||
| unless confirmed_no_pw.person.present? | ||
| person = Person.create!( | ||
| first_name: "Confirmed", | ||
| last_name: "NoPassword", | ||
| email: confirmed_no_pw.email, | ||
| created_by: admin, | ||
| updated_by: admin, | ||
| profile_is_searchable: true | ||
| ) | ||
| confirmed_no_pw.update!(person: person) | ||
| end | ||
|
|
||
| # Locked account (too many failed attempts) | ||
| locked = User.find_or_create_by!(email: "locked.user@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = 1.month.ago | ||
| end | ||
| unless locked.locked_at.present? | ||
| locked.update_columns( | ||
| locked_at: 1.day.ago, | ||
| failed_attempts: Devise.maximum_attempts | ||
| ) | ||
| end | ||
| unless locked.person.present? | ||
| person = Person.create!( | ||
| first_name: "Locked", | ||
| last_name: "User", | ||
| email: locked.email, | ||
| created_by: admin, | ||
| updated_by: admin, | ||
| profile_is_searchable: true | ||
| ) | ||
| locked.update!(person: person) | ||
| end | ||
|
|
||
| # Never invited (created but no confirmation sent) | ||
| never_invited = User.find_or_create_by!(email: "never.invited@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = Time.current | ||
| end | ||
| unless never_invited.welcome_instructions_sent_at.present? | ||
| never_invited.update_columns(confirmed_at: nil) | ||
| end | ||
| unless never_invited.person.present? | ||
| person = Person.create!( | ||
| first_name: "Never", | ||
| last_name: "Invited", | ||
| email: never_invited.email, | ||
| created_by: admin, | ||
| updated_by: admin, | ||
| profile_is_searchable: true | ||
| ) | ||
| never_invited.update!(person: person) | ||
| end | ||
|
|
||
| # Invited a while ago, never clicked (stale invite) | ||
| stale_invited = User.find_or_create_by!(email: "stale.invite@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = Time.current | ||
| end | ||
| unless stale_invited.welcome_instructions_token.present? | ||
| stale_invited.update_columns( | ||
| confirmed_at: nil, | ||
| welcome_instructions_token: Devise.friendly_token, | ||
| welcome_instructions_created_at: 45.days.ago, | ||
| welcome_instructions_sent_at: 45.days.ago | ||
| ) | ||
| end | ||
| unless stale_invited.person.present? | ||
| person = Person.create!( | ||
| first_name: "Stale", | ||
| last_name: "Invite", | ||
| email: stale_invited.email, | ||
| created_by: admin, | ||
| updated_by: admin, | ||
| profile_is_searchable: true | ||
| ) | ||
| stale_invited.update!(person: person) | ||
| end | ||
|
|
||
| # Invited yesterday | ||
| recent_invited = User.find_or_create_by!(email: "recent.invite@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = Time.current | ||
| end | ||
| unless recent_invited.welcome_instructions_token.present? | ||
| recent_invited.update_columns( | ||
| confirmed_at: nil, | ||
| welcome_instructions_token: Devise.friendly_token, | ||
| welcome_instructions_created_at: 1.day.ago, | ||
| welcome_instructions_sent_at: 1.day.ago | ||
| ) | ||
| end | ||
| unless recent_invited.person.present? | ||
| person = Person.create!( | ||
| first_name: "Recent", | ||
| last_name: "Invite", | ||
| email: recent_invited.email, | ||
| created_by: admin, | ||
| updated_by: admin, | ||
| profile_is_searchable: true | ||
| ) | ||
| recent_invited.update!(person: person) | ||
| end | ||
|
|
||
| # Never invited, no person record either | ||
| User.find_or_create_by!(email: "orphan.uninvited@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = Time.current | ||
| end.tap do |u| | ||
| u.update_columns(confirmed_at: nil) unless u.welcome_instructions_sent_at.present? | ||
| end | ||
|
|
||
| # Invited, no person record | ||
| invited_no_person = User.find_or_create_by!(email: "invited.noperson@example.com") do |user| | ||
| user.password = "password" | ||
| user.super_user = false | ||
| user.confirmed_at = Time.current | ||
| end | ||
| unless invited_no_person.welcome_instructions_token.present? | ||
| invited_no_person.update_columns( | ||
| confirmed_at: nil, | ||
| welcome_instructions_token: Devise.friendly_token, | ||
| welcome_instructions_created_at: 10.days.ago, | ||
| welcome_instructions_sent_at: 10.days.ago | ||
| ) | ||
| end | ||
|
|
||
| # Reset only these dev users' passwords (mirrors the base seed reset), so they | ||
| # stay loggable-in after a reseed without touching any other user. | ||
| dev_user_emails = %w[ | ||
| invited.pending@example.com | ||
| confirmed.nopassword@example.com | ||
| locked.user@example.com | ||
| never.invited@example.com | ||
| stale.invite@example.com | ||
| recent.invite@example.com | ||
| orphan.uninvited@example.com | ||
| invited.noperson@example.com | ||
| ] | ||
| dev_user_password = Devise::Encryptor.digest(User, "password") | ||
| User.where(email: dev_user_emails).update_all(encrypted_password: dev_user_password) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,12 @@ | ||
| namespace :db do | ||
| namespace :seed do | ||
| desc "Generate representative sample data for development" | ||
| task dev: [ :environment, "db:seed", "db:seed:dummy", "db:seed:payments" ] | ||
| task dev: [ :environment, "db:seed", "db:seed:users", "db:seed:dummy", "db:seed:payments" ] | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤖 From Claude: Correction — placement of |
||
|
|
||
| desc "Seed dev-only user variations (invite/lock/confirmation states)" | ||
| task users: :environment do | ||
| load Rails.root.join("db/seeds/dev/users.rb") | ||
| end | ||
|
Comment on lines
+6
to
+9
|
||
|
|
||
| desc "Seed generic dummy dev data (workshops, people, stories, etc.)" | ||
| task dummy: :environment do | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤖 From Claude: Guard keys on
welcome_instructions_token, notconfirmed_at—find_or_create_by!just setconfirmed_attoTime.current, so the oldunless confirmed_at.present?never fired and these "stale/pending invite" users ended up confirmed. Token presence is the real "invite already set up" marker, so this runs once and stays idempotent.