diff options
| author | mo khan <mo@mokhan.ca> | 2014-09-17 21:30:57 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2014-09-17 21:30:57 -0600 |
| commit | 0cc3de2769769be786a679975ae329e98462fcc4 (patch) | |
| tree | 88824cf1c9757f26e52ed8d6bed28e6bf4baad4c | |
| parent | cda9d573bf273eaafa213c06543c071841041306 (diff) | |
add password validation.
| -rw-r--r-- | app/models/user.rb | 3 | ||||
| -rw-r--r-- | spec/models/user_spec.rb | 6 |
2 files changed, 8 insertions, 1 deletions
diff --git a/app/models/user.rb b/app/models/user.rb index 30b3fecd..c455162a 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -16,6 +16,7 @@ class User < ActiveRecord::Base validates :name, :presence => true validates :email, presence: true, uniqueness: true, email: true validates :website, :format => URI::regexp(%w(http https)), :allow_blank => true + validates :password, length: { in: 6..20 } #devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :token_authenticatable has_many :creations, :dependent => :destroy @@ -47,7 +48,7 @@ class User < ActiveRecord::Base end def password - @password ||= Password.new(password_hash) + @password ||= Password.new(encrypted_password) end def password=(new_password) diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 14f32a3d..5a7e95de 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -32,6 +32,12 @@ describe User do expect(subject.valid?).to be_falsey expect(subject.errors[:email]).to_not be_empty end + + it 'validates the presence of a password' do + subject.password = nil + expect(subject.valid?).to be_falsey + expect(subject.errors[:password]).to_not be_empty + end end describe "when a website url is supplied" do |
