Skip to content

Commit

Permalink
Treat blank parent email as nil (and valid)
Browse files Browse the repository at this point in the history
  • Loading branch information
islemaster committed Jul 26, 2018
1 parent ec1e031 commit b6f92d3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
5 changes: 5 additions & 0 deletions dashboard/app/models/user.rb
Expand Up @@ -247,6 +247,7 @@ class User < ActiveRecord::Base

has_many :user_geos, -> {order 'updated_at desc'}

before_validation :normalize_parent_email
validate :validate_parent_email

after_create :associate_with_potential_pd_enrollments
Expand Down Expand Up @@ -2080,6 +2081,10 @@ def get_student_hidden_ids(assign_id, hidden_stages)
end
end

def normalize_parent_email
self.parent_email = nil if parent_email.blank?
end

# Parent email is not required, but if it is present, it must be a
# well-formed email address.
def validate_parent_email
Expand Down
16 changes: 16 additions & 0 deletions dashboard/test/controllers/registrations_controller/update_test.rb
Expand Up @@ -223,6 +223,22 @@ class UpdateTest < ActionDispatch::IntegrationTest
assert_nil student.parent_email
end

test "single-auth student can update with a blank parent email without password" do
student = create :student, :unmigrated_clever_sso
assert_nil student.hashed_email
assert_nil student.parent_email

sign_in student
put '/users', params: {
format: 'json',
user: {parent_email: '', age: '9'}
}
assert_response :no_content

student.reload
assert_nil student.parent_email
end

# The next several tests explore profile changes for users with or without
# passwords. Examples of users without passwords are users that authenticate
# via oauth (a third-party account), or students with a picture password.
Expand Down

0 comments on commit b6f92d3

Please sign in to comment.