Skip to content

Commit

Permalink
adding limitation to not save blank email in model
Browse files Browse the repository at this point in the history
  • Loading branch information
iraline committed Jun 6, 2022
1 parent 9127e56 commit 1eb7b83
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/controllers/users/registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def new

def create
build_resource(sign_up_params)
resource.registering_from_web = true

if resource.valid?
super
else
Expand Down
3 changes: 2 additions & 1 deletion app/models/user.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -333,7 +334,7 @@ def username_required?
end

def email_required?
!erased? && unverified?
!erased? && (unverified? || registering_from_web)
end

def locale
Expand Down
14 changes: 14 additions & 0 deletions spec/system/registration_form_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down

0 comments on commit 1eb7b83

Please sign in to comment.