From 1eb7b8379777f7fa330530022b80d7e88aea11d6 Mon Sep 17 00:00:00 2001 From: Iraline Date: Mon, 6 Jun 2022 10:23:52 -0300 Subject: [PATCH] adding limitation to not save blank email in model --- app/controllers/users/registrations_controller.rb | 2 ++ app/models/user.rb | 3 ++- spec/system/registration_form_spec.rb | 14 ++++++++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 4a3af5c94c98..b1c4c525ffcf 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -12,6 +12,8 @@ def new def create build_resource(sign_up_params) + resource.registering_from_web = true + if resource.valid? super else diff --git a/app/models/user.rb b/app/models/user.rb index 6933706e44cc..31d85328e2bc 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -1,5 +1,6 @@ class User < ApplicationRecord include Verification + attribute :registering_from_web, default: false devise :database_authenticatable, :registerable, :confirmable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :password_expirable, :secure_validatable, @@ -333,7 +334,7 @@ def username_required? end def email_required? - !erased? && unverified? + !erased? && (unverified? || registering_from_web) end def locale diff --git a/spec/system/registration_form_spec.rb b/spec/system/registration_form_spec.rb index cb7397be9c46..e0ca467c6699 100644 --- a/spec/system/registration_form_spec.rb +++ b/spec/system/registration_form_spec.rb @@ -23,6 +23,20 @@ expect(page).to have_content I18n.t("devise_views.users.registrations.new.username_is_available") end + scenario "do not save blank user_email" do + visit new_user_registration_path + + fill_in "user_username", with: "NewUser" + fill_in "user_password", with: "password" + fill_in "user_password_confirmation", with: "password" + + check "user_terms_of_service" + + click_button "Register" + + expect(page).to have_content "can't be blank" + end + scenario "do not save blank redeemable codes" do visit new_user_registration_path(use_redeemable_code: "true")