Skip to content

Commit

Permalink
user validations complete
Browse files Browse the repository at this point in the history
  • Loading branch information
jackrim1 committed Jan 4, 2019
1 parent 3d46e82 commit 26aa575
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 2 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.5.0'

gem 'bcrypt'
gem 'rails-controller-testing'
gem 'bootstrap-sass'
gem 'guard'
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ GEM
arel (9.0.0)
autoprefixer-rails (9.3.1)
execjs
bcrypt (3.1.12)
bindex (0.5.0)
bootsnap (1.3.2)
msgpack (~> 1.0)
Expand Down Expand Up @@ -243,6 +244,7 @@ PLATFORMS
ruby

DEPENDENCIES
bcrypt
bootsnap (>= 1.1.0)
bootstrap-sass
byebug
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,7 @@ class User < ApplicationRecord
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX},
uniqueness: { case_sensitive: false }
has_secure_password
validates :password, presence: true, length: { minimum: 6 }

end
5 changes: 5 additions & 0 deletions db/migrate/20190104060108_add_password_digest_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPasswordDigestToUsers < ActiveRecord::Migration[5.2]
def change
add_column :users, :password_digest, :string
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2019_01_04_054255) do
ActiveRecord::Schema.define(version: 2019_01_04_060108) do

create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "password_digest"
t.index ["email"], name: "index_users_on_email", unique: true
end

Expand Down
12 changes: 11 additions & 1 deletion test/models/user_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
class UserTest < ActiveSupport::TestCase

def setup
@user = User.new(name: "Example User", email: "[email protected]")
@user = User.new(name: "Example User", email: "[email protected]",
password: "foobar", password_confirmation: "foobar")
end

test "should be valid" do
Expand Down Expand Up @@ -53,6 +54,15 @@ def setup
assert_not duplicate_user.valid?
end

test "password should be present (nonblank)" do
@user.password = @user.password_confirmation = " " * 6
assert_not @user.valid?
end

test "password should have a minimum length" do
@user.password = @user.password_confirmation = "a" * 5
assert_not @user.valid?
end
end


Expand Down

0 comments on commit 26aa575

Please sign in to comment.