Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 4 additions & 15 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,18 +232,7 @@
# Seed Demo Users
puts "Seeding demo users..."

demo_users = [
{ username: "admin", password: "admin123", user_type: :admin },
{ username: "curator", password: "curator123", user_type: :curator },
{ username: "user", password: "user123", user_type: :basic }
]

demo_users.each do |user_data|
User.find_or_create_by!(username: user_data[:username]) do |user|
user.password = user_data[:password]
user.user_type = user_data[:user_type]
end
end
load Rails.root.join("db/seeds/demo_users.rb")

puts "Created #{User.count} users"

Expand Down Expand Up @@ -946,7 +935,7 @@ def download_sample_audio
puts "Seeding complete!"
puts ""
puts "=== Demo Accounts ==="
puts "Admin: username: admin, password: admin123"
puts "Curator: username: curator, password: curator123"
puts "User: username: user, password: user123"
puts "Admin: email: admin@usput.local, password: admin123"
puts "Curator: email: curator@usput.local, password: curator123"
puts "User: email: user@usput.local, password: user123"
puts "====================="
20 changes: 20 additions & 0 deletions db/seeds/demo_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# frozen_string_literal: true

# Demo accounts for development, one per role. Accounts sign in by email, and
# these are confirmed up front so nobody waits for a mail that never comes.
# Loaded by db/seeds.rb, and on its own by test/db/demo_users_seed_test.rb.

demo_users = [
{ username: "admin", email: "admin@usput.local", password: "admin123", user_type: :admin },
{ username: "curator", email: "curator@usput.local", password: "curator123", user_type: :curator },
{ username: "user", email: "user@usput.local", password: "user123", user_type: :basic }
]

demo_users.each do |user_data|
User.find_or_create_by!(username: user_data[:username]) do |user|
user.email = user_data[:email]
user.password = user_data[:password]
user.user_type = user_data[:user_type]
user.skip_confirmation!
end
end
36 changes: 36 additions & 0 deletions test/db/demo_users_seed_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

require "test_helper"

class DemoUsersSeedTest < ActionDispatch::IntegrationTest
def load_demo_users
silence_warnings { load Rails.root.join("db/seeds/demo_users.rb") }
end

test "seeds one confirmed account per role" do
load_demo_users

{ "admin" => "admin", "curator" => "curator", "user" => "basic" }.each do |username, role|
user = User.find_by!(username: username)
assert_equal role, user.user_type
assert_equal "#{username}@usput.local", user.email
assert user.confirmed?, "#{username} should be confirmed"
end
end

test "a demo account signs in with its email and password" do
load_demo_users

post user_session_path, params: { user: { email: "admin@usput.local", password: "admin123" } }

assert_signed_in
end

test "loading twice creates no duplicates" do
load_demo_users

assert_no_difference -> { User.count } do
load_demo_users
end
end
end
Loading