Q:

my before_create isn't working even though my method returns nil.

This is my user class:
class User < ActiveRecord::Base
  has_secure_password

  before_save :valid_email?

  validates :username, presence: true,
                       uniqueness: true
  validates :first_name, presence: true

  enum role: [ :flyer, :admin ]

  def valid_email?
    email_checker
  end

  private

  def email_checker
    self.email.match(/^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-.]+$/)
  end

end

This is my test:
test "if a user has an invalid email, cannot be saved" do
    user = build(:user)
    user1 = build(:user, email: "here@here@here")
    user2 = build(:user, email: "here.here@here")

    assert user.save
    refute user1.save
    refute user2.save
  end

The email_checker method does return nil if email is either here@here@here or here.here@here. So what is going on?

A:

Because you just call self.email.match method. If you want to validate filed you should use or create validator. 
In your case you can create own custom validator or use e-mail validator from gems (i.e email_validator). 

