-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bugfix: canonicalize emails for users
This allows us to reliably search out user emails for login, and should reduce some of the oddities of logins. Fixes #133
- Loading branch information
Showing
8 changed files
with
73 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,3 @@ | ||
ActiveRecord::Type.register(:email_address, EmailAddress::EmailAddressType) | ||
ActiveRecord::Type.register(:canonical_email_address, | ||
EmailAddress::CanonicalEmailAddressType) |
This file contains 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,17 @@ | ||
class CanonicalizeEmail < ActiveRecord::Migration[6.1] | ||
def up | ||
add_column :users, :user_provided_email, :string | ||
execute "UPDATE users SET user_provided_email = email" | ||
|
||
User.all.each do |user| | ||
curr_email = user.user_provided_email | ||
user.email = curr_email | ||
user.save | ||
end | ||
end | ||
|
||
def down | ||
execute "UPDATE users SET email = user_provided_email" | ||
remove_column :users, :user_provided_email | ||
end | ||
end |
This file contains 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 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 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 |
---|---|---|
|
@@ -25,6 +25,14 @@ | |
expect(build(:user, email: "harry/[email protected]")).to_not be_valid | ||
end | ||
|
||
it "should canonicalize the provided email" do | ||
expect(build(:user, email: "[email protected]").email).to eq("[email protected]") | ||
end | ||
|
||
it "should retain the user provided email" do | ||
expect(build(:user, email: "[email protected]").user_provided_email).to eq("[email protected]") | ||
end | ||
|
||
# I felt the need to do this because factory code gets quite hairy, especially with factories calling factories from | ||
# the :with_reservation trait. | ||
describe "user factory links" do | ||
|