Skip to content

Commit

Permalink
WIP Add usernames
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardloveall committed Jan 21, 2019
1 parent a6c54a0 commit b0a42e0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 2 deletions.
13 changes: 13 additions & 0 deletions db/migrations/20190120112946_add_username_to_user.cr
@@ -0,0 +1,13 @@
class AddUsernameToUser::V20190120112946 < LuckyRecord::Migrator::Migration::V1
def migrate
alter :users do
add username : String?, fill_existing_with: :nothing, unique: true
end
end

def rollback
alter :users do
remove :username
end
end
end
18 changes: 18 additions & 0 deletions db/migrations/20190120141952_generate_usernames_for_users.cr
@@ -0,0 +1,18 @@
class GenerateUsernamesForUsers::V20190120141952 < LuckyRecord::Migrator::Migration::V1
class User < BaseModel
table :users do
column username : String?
end
end

def migrate
UserQuery.all.each do |user|
new_username = user.email.split("@").first
User::BaseForm.update!(user, username: new_username)
puts "Generated username #{new_username} for #{user.email}"
end
end

def rollback
end
end
9 changes: 9 additions & 0 deletions db/migrations/20190120142017_require_username_on_user.cr
@@ -0,0 +1,9 @@
class RequireUsernameOnUser::V20190120142017 < LuckyRecord::Migrator::Migration::V1
def migrate
execute "ALTER TABLE users ALTER COLUMN username SET NOT NULL"
end

def rollback
execute "ALTER TABLE users ALTER COLUMN username DROP NOT NULL"
end
end
4 changes: 3 additions & 1 deletion spec/support/flows/authentication_flow.cr
@@ -1,12 +1,14 @@
class AuthenticationFlow < BaseFlow
private getter email
private getter username

def initialize(@email : String)
def initialize(@email : String, @username : String)
end

def sign_up(password)
visit SignUps::New
fill_form SignUpForm,
username: username,
email: email,
password: password,
password_confirmation: password
Expand Down
5 changes: 4 additions & 1 deletion spec/support/flows/reset_password_flow.cr
Expand Up @@ -5,7 +5,10 @@ class ResetPasswordFlow < BaseFlow
delegate email, to: user

def initialize(@user : User)
@authentication_flow = AuthenticationFlow.new(user.email)
@authentication_flow = AuthenticationFlow.new(
email: user.email,
username: user.username
)
end

def request_password_reset
Expand Down

0 comments on commit b0a42e0

Please sign in to comment.