From be4a7eaa414c8899f015b4b8d2c32fafbe42be15 Mon Sep 17 00:00:00 2001 From: Ian Young Date: Thu, 16 Apr 2015 17:24:31 -0700 Subject: [PATCH] Fix error when email missing from registration --- .../registrations_controller.rb | 2 +- .../registrations_controller_test.rb | 29 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/app/controllers/devise_token_auth/registrations_controller.rb b/app/controllers/devise_token_auth/registrations_controller.rb index 988296eb1..ce00da197 100644 --- a/app/controllers/devise_token_auth/registrations_controller.rb +++ b/app/controllers/devise_token_auth/registrations_controller.rb @@ -11,7 +11,7 @@ def create # honor devise configuration for case_insensitive_keys if resource_class.case_insensitive_keys.include?(:email) - @resource.email = sign_up_params[:email].downcase + @resource.email = sign_up_params[:email].try :downcase else @resource.email = sign_up_params[:email] end diff --git a/test/controllers/devise_token_auth/registrations_controller_test.rb b/test/controllers/devise_token_auth/registrations_controller_test.rb index 069628146..4ed02e52d 100644 --- a/test/controllers/devise_token_auth/registrations_controller_test.rb +++ b/test/controllers/devise_token_auth/registrations_controller_test.rb @@ -297,6 +297,35 @@ class DeviseTokenAuth::RegistrationsControllerTest < ActionDispatch::Integration end end + describe 'missing email' do + before do + post '/auth', { + password: "secret123", + password_confirmation: "secret123", + confirm_success_url: Faker::Internet.url + } + + @resource = assigns(:resource) + @data = JSON.parse(response.body) + end + + test "request should not be successful" do + assert_equal 403, response.status + end + + test "user should not have been created" do + assert_nil @resource.id + end + + test "error should be returned in the response" do + assert @data['errors'].length + end + + test "full_messages should be included in error hash" do + assert @data['errors']['full_messages'].length + end + end + describe "Mismatched passwords" do before do post '/auth', {