Commit 0cc3de27
Changed files (2)
app
models
spec
models
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)
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