* allow user model to permit null first/last on administrative signup
This commit is contained in:
parent
c229405069
commit
88136c06c7
|
|
@ -2,7 +2,7 @@ module JamRuby
|
||||||
class User < ActiveRecord::Base
|
class User < ActiveRecord::Base
|
||||||
|
|
||||||
attr_accessible :first_name, :last_name, :email, :password, :password_confirmation, :city, :state, :country
|
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'
|
self.primary_key = 'id'
|
||||||
|
|
||||||
|
|
@ -89,8 +89,8 @@ module JamRuby
|
||||||
before_save { |user| user.email = email.downcase }
|
before_save { |user| user.email = email.downcase }
|
||||||
before_save :create_remember_token, :if => :should_validate_password?
|
before_save :create_remember_token, :if => :should_validate_password?
|
||||||
|
|
||||||
validates :first_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}
|
validates :last_name, presence: true, length: {maximum: 50}, :if => :end_user_created?
|
||||||
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
|
||||||
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX},
|
validates :email, presence: true, format: {with: VALID_EMAIL_REGEX},
|
||||||
uniqueness: {case_sensitive: false}
|
uniqueness: {case_sensitive: false}
|
||||||
|
|
@ -123,7 +123,11 @@ module JamRuby
|
||||||
end
|
end
|
||||||
|
|
||||||
def should_validate_password?
|
def should_validate_password?
|
||||||
updating_password || new_record?
|
!administratively_created && (updating_password || new_record?)
|
||||||
|
end
|
||||||
|
|
||||||
|
def end_user_created?
|
||||||
|
return !administratively_created
|
||||||
end
|
end
|
||||||
|
|
||||||
def friends?(user)
|
def friends?(user)
|
||||||
|
|
|
||||||
|
|
@ -126,6 +126,11 @@ describe User do
|
||||||
it { should be_invalid }
|
it { should be_invalid }
|
||||||
end
|
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
|
describe "set_password" do
|
||||||
before do
|
before do
|
||||||
@user.confirm_email!
|
@user.confirm_email!
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue