* allow user model to permit null first/last on administrative signup

This commit is contained in:
Seth Call 2013-03-01 07:35:50 -06:00
parent c229405069
commit 88136c06c7
2 changed files with 13 additions and 4 deletions

View File

@ -2,7 +2,7 @@ module JamRuby
class User < ActiveRecord::Base
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :city, :state, :country
attr_accessor :updating_password
attr_accessor :updating_password, :administratively_created
self.primary_key = 'id'
@ -89,8 +89,8 @@ module JamRuby
before_save { |user| user.email = email.downcase }
before_save :create_remember_token, :if => :should_validate_password?
validates :first_name, presence: true, length: {maximum: 50}
validates :last_name, presence: true, length: {maximum: 50}
validates :first_name, presence: true, length: {maximum: 50}, :if => :end_user_created?
validates :last_name, presence: true, length: {maximum: 50}, :if => :end_user_created?
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX},
uniqueness: {case_sensitive: false}
@ -123,7 +123,11 @@ module JamRuby
end
def should_validate_password?
updating_password || new_record?
!administratively_created && (updating_password || new_record?)
end
def end_user_created?
return !administratively_created
end
def friends?(user)

View File

@ -126,6 +126,11 @@ describe User do
it { should be_invalid }
end
describe "when password and password digest are not present, but admininstrator created it" do
before { @user.password = @user.password_confirmation = nil; @user.administratively_created = true }
it { should be_valid }
end
describe "set_password" do
before do
@user.confirm_email!