Skip to content
Closed
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
7 changes: 3 additions & 4 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ class User < ActiveRecord::Base
is_gravtastic default: "retro"

PERMITTED_ATTRS = [
:bio,
:email,
:handle,
:hide_email,
:location,
:password,
:website,
:twitter_username
:twitter_username,
:email_confirmation
].freeze

has_many :rubygems, through: :ownerships
Expand Down Expand Up @@ -40,6 +38,7 @@ class User < ActiveRecord::Base

validates :twitter_username, length: { within: 0..20 }, allow_nil: true
validates :password, length: { within: 10..200 }, allow_nil: true, unless: :skip_password_validation?
validates :email, confirmation: true, if: :email_changed?

def self.authenticate(who, password)
user = find_by(email: who.downcase) || find_by(handle: who)
Expand Down
5 changes: 5 additions & 0 deletions app/views/profiles/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<%= form.email_field :email, :class => 'form__input' %>
</div>

<div class="text_field">
<%= form.label :email_confirmation, :class => 'form__label' %>
<%= form.email_field :email_confirmation, :class => 'form__input' %>
</div>

<p class='form__field__instructions'>
<%= t('.enter_password') %>
</p>
Expand Down
4 changes: 4 additions & 0 deletions app/views/users/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
<%= form.label :email, :class => 'form__label' %>
<%= form.email_field :email, :class => 'form__input' %>
</div>
<div class="text_field">
<%= form.label :email_confirmation, :class => 'form__label' %>
<%= form.email_field :email_confirmation, :class => 'form__input' %>
</div>
<div class="text_field">
<%= form.label :handle, :class => 'form__label' %>
<%= form.text_field :handle, :class => 'form__input' %>
Expand Down
1 change: 1 addition & 0 deletions test/integration/profile_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def sign_in
click_link "Edit Profile"

fill_in "Email address", with: "nick2@example.com"
fill_in "Email confirmation", with: "nick2@example.com"
fill_in "Password", with: "password12345"
click_button "Update"

Expand Down
3 changes: 2 additions & 1 deletion test/integration/sign_in_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class SignInTest < SystemTest
test "signing in with unconfirmed email" do
visit sign_up_path

fill_in "Email", with: "email@person.com"
fill_in "Email address", with: "email@person.com"
fill_in "Email confirmation", with: "email@person.com"
fill_in "Handle", with: "nick"
fill_in "Password", with: "secretpassword"
click_button "Sign up"
Expand Down
40 changes: 34 additions & 6 deletions test/integration/sign_up_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class SignUpTest < SystemTest
test "sign up" do
visit sign_up_path

fill_in "Email", with: "email@person.com"
fill_in "Email address", with: "email@person.com"
fill_in "Email confirmation", with: "email@person.com"
fill_in "Handle", with: "nick"
fill_in "Password", with: "secretpassword"
click_button "Sign up"
Expand All @@ -15,7 +16,8 @@ class SignUpTest < SystemTest
test "sign up with no handle" do
visit sign_up_path

fill_in "Email", with: "email@person.com"
fill_in "Email address", with: "email@person.com"
fill_in "Email confirmation", with: "email@person.com"
fill_in "Password", with: "password"
click_button "Sign up"

Expand All @@ -25,7 +27,8 @@ class SignUpTest < SystemTest
test "sign up with bad handle" do
visit sign_up_path

fill_in "Email", with: "email@person.com"
fill_in "Email address", with: "email@person.com"
fill_in "Email confirmation", with: "email@person.com"
fill_in "Handle", with: "thisusernameiswaytoolongseriouslywaytoolong"
fill_in "Password", with: "secretpassword"
click_button "Sign up"
Expand All @@ -37,7 +40,8 @@ class SignUpTest < SystemTest
create(:user, handle: "nick")
visit sign_up_path

fill_in "Email", with: "email@person.com"
fill_in "Email address", with: "email@person.com"
fill_in "Email confirmation", with: "email@person.com"
fill_in "Handle", with: "nick"
fill_in "Password", with: "secretpassword"
click_button "Sign up"
Expand All @@ -56,10 +60,34 @@ class SignUpTest < SystemTest
assert page.has_content? "Sign up is temporarily disabled."
end

test "email confirmation" do
test "sign up with no email confirmation" do
visit sign_up_path

fill_in "Email", with: "email@person.com"
fill_in "Email address", with: "email@person.com"
fill_in "Handle", with: "nick"
fill_in "Password", with: "secretpassword"
click_button "Sign up"

assert page.has_content? "Email confirmation doesn't match Email address"
end

test "sign up with mismatched email confirmation" do
visit sign_up_path

fill_in "Email address", with: "email@person.com"
fill_in "Email confirmation", with: "email1@person.com"
fill_in "Handle", with: "nick"
fill_in "Password", with: "secretpassword"
click_button "Sign up"

assert page.has_content? "Email confirmation doesn't match Email address"
end

test "email verification" do
visit sign_up_path

fill_in "Email address", with: "email@person.com"
fill_in "Email confirmation", with: "email@person.com"
fill_in "Handle", with: "nick"
fill_in "Password", with: "secretpassword"
click_button "Sign up"
Expand Down