users: move emails to separate table.

* Move emails from users table to email_addresses table.
* Validate that addresses are formatted correctly and are unique across
  users. Existing invalid emails are grandfathered in.
* Add is_verified flag (the address has been confirmed by the user).
* Add is_deliverable flag (an undeliverable address is an address that bounces).
* Normalize addresses to prevent registering multiple accounts with the
  same email address (using tricks like Gmail's plus addressing).
This commit is contained in:
evazion
2020-03-10 21:36:16 -05:00
parent 41304d6add
commit 258f4a8b95
22 changed files with 285 additions and 36 deletions

View File

@@ -114,8 +114,28 @@ class UsersControllerTest < ActionDispatch::IntegrationTest
context "create action" do
should "create a user" do
assert_difference("User.count", 1) do
post users_path, params: {:user => {:name => "xxx", :password => "xxxxx1", :password_confirmation => "xxxxx1"}}
user_params = { name: "xxx", password: "xxxxx1", password_confirmation: "xxxxx1" }
post users_path, params: { user: user_params }
assert_redirected_to User.last
assert_equal("xxx", User.last.name)
end
should "create a user with a valid email" do
user_params = { name: "xxx", password: "xxxxx1", password_confirmation: "xxxxx1", email_address_attributes: { address: "test@gmail.com" } }
post users_path, params: { user: user_params }
assert_redirected_to User.last
assert_equal("xxx", User.last.name)
assert_equal("test@gmail.com", User.last.email_address.address)
end
should "not create a user with an invalid email" do
user_params = { name: "xxx", password: "xxxxx1", password_confirmation: "xxxxx1", email_address_attributes: { address: "test" } }
assert_no_difference("User.count") do
post users_path, params: { user: user_params }
assert_response :success
end
end