From 5eb2dc5a9cd6667b969ac07e87f8ba730ab0cb22 Mon Sep 17 00:00:00 2001 From: Iraline Date: Tue, 7 Jun 2022 14:17:37 -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 | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/controllers/users/registrations_controller.rb b/app/controllers/users/registrations_controller.rb index 4a3af5c94..a5f2e9cac 100644 --- a/app/controllers/users/registrations_controller.rb +++ b/app/controllers/users/registrations_controller.rb @@ -12,6 +12,8 @@ class Users::RegistrationsController < Devise::RegistrationsController 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 6933706e4..31d85328e 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 @@ class User < ApplicationRecord 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 cb7397be9..a9e018ee1 100644 --- a/spec/system/registration_form_spec.rb +++ b/spec/system/registration_form_spec.rb @@ -23,6 +23,21 @@ describe "Registration form" do expect(page).to have_content I18n.t("devise_views.users.registrations.new.username_is_available") end + scenario "do not save blank user_email" do + Setting["feature.user.skip_verification"] = true + 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")