Commit 188a6c3f by Nguyen Hoang Mai Phuong

Merge branch 'modeling-users' into 'master'

Make a basic User model (including secure passwords)

See merge request !8
parents 9bd60698 f75cdfb6
Pipeline #1262 failed with stages
in 0 seconds
......@@ -6,11 +6,10 @@ gem 'bootstrap', '~> 5.0.1'
gem 'image_processing', '1.9.3'
gem 'mini_magick', '4.9.5'
gem 'active_storage_validations', '0.8.9'
gem 'bcrypt', '3.1.13'
gem 'bcrypt', '3.1.16'
gem 'faker', '2.11.0'
gem 'will_paginate', '3.3.0'
gem 'bootstrap-will_paginate', '1.0.0'
gem 'bootstrap-sass', '3.4.1'
gem 'puma', '5.3.1'
gem 'sass-rails', '6.0.0'
gem 'webpacker', '5.2.1'
......
......@@ -83,7 +83,7 @@ GEM
aws-sigv4 (~> 1.1)
aws-sigv4 (1.2.3)
aws-eventstream (~> 1, >= 1.0.2)
bcrypt (3.1.13)
bcrypt (3.1.16)
bindex (0.8.1)
bootsnap (1.7.2)
msgpack (~> 1.0)
......@@ -91,9 +91,6 @@ GEM
autoprefixer-rails (>= 9.1.0)
popper_js (>= 2.9.2, < 3)
sassc-rails (>= 2.0.0)
bootstrap-sass (3.4.1)
autoprefixer-rails (>= 5.2.1)
sassc (>= 2.0.0)
bootstrap-will_paginate (1.0.0)
will_paginate
builder (3.2.4)
......@@ -281,10 +278,9 @@ PLATFORMS
DEPENDENCIES
active_storage_validations (= 0.8.9)
aws-sdk-s3 (= 1.87.0)
bcrypt (= 3.1.13)
bcrypt (= 3.1.16)
bootsnap (= 1.7.2)
bootstrap (~> 5.0.1)
bootstrap-sass (= 3.4.1)
bootstrap-will_paginate (= 1.0.0)
byebug (= 11.1.3)
capybara (= 3.35.3)
......
class User < ApplicationRecord
before_save { email.downcase! }
validates :name, presence: true, length: { maximum: 50 }
VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
validates :email, presence: true, length: { maximum: 255 },
format: { with: VALID_EMAIL_REGEX },
uniqueness: true
has_secure_password
validates :password, presence: true, length: { minimum: 6 }
end
class CreateUsers < ActiveRecord::Migration[6.1]
def change
create_table :users do |t|
t.string :name
t.string :email
t.timestamps
end
end
end
class AddIndexToUsersEmail < ActiveRecord::Migration[6.1]
def change
add_index :users, :email, unique: true
end
end
class AddPasswordDigestToUsers < ActiveRecord::Migration[6.1]
def change
add_column :users, :password_digest, :string
end
end
......@@ -10,6 +10,15 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 0) do
ActiveRecord::Schema.define(version: 2021_06_09_152857) do
create_table "users", force: :cascade do |t|
t.string "name"
t.string "email"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.string "password_digest"
t.index ["email"], name: "index_users_on_email", unique: true
end
end
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
require 'test_helper'
class UserTest < ActiveSupport::TestCase
def setup
@user = User.new(name: "Example User", email: "user@example.com",
password: "foobar", password_confirmation: "foobar")
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
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment