Initial version of user_profiles in place
This commit is contained in:
parent
6d6738b0e8
commit
f8905f1f0c
12 changed files with 249 additions and 118 deletions
5
Gemfile
5
Gemfile
|
|
@ -5,13 +5,14 @@ git_source(:github) do |repo_name|
|
|||
"https://github.com/#{repo_name}.git"
|
||||
end
|
||||
|
||||
ruby '2.5.1'
|
||||
|
||||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
|
||||
gem 'rails', '~> 5.1.5'
|
||||
gem 'rails', '~> 5.2.2'
|
||||
# Use sqlite3 as the database for Active Record
|
||||
gem 'mysql2', '>= 0.4.10'
|
||||
# Use Puma as the app server
|
||||
gem 'puma', '~> 3.7'
|
||||
gem 'puma', '~> 3.11'
|
||||
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
|
||||
# gem 'jbuilder', '~> 2.5'
|
||||
# Use Redis adapter to run Action Cable in production
|
||||
|
|
|
|||
201
Gemfile.lock
201
Gemfile.lock
|
|
@ -1,182 +1,184 @@
|
|||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
actioncable (5.1.5)
|
||||
actionpack (= 5.1.5)
|
||||
actioncable (5.2.2)
|
||||
actionpack (= 5.2.2)
|
||||
nio4r (~> 2.0)
|
||||
websocket-driver (~> 0.6.1)
|
||||
actionmailer (5.1.5)
|
||||
actionpack (= 5.1.5)
|
||||
actionview (= 5.1.5)
|
||||
activejob (= 5.1.5)
|
||||
websocket-driver (>= 0.6.1)
|
||||
actionmailer (5.2.2)
|
||||
actionpack (= 5.2.2)
|
||||
actionview (= 5.2.2)
|
||||
activejob (= 5.2.2)
|
||||
mail (~> 2.5, >= 2.5.4)
|
||||
rails-dom-testing (~> 2.0)
|
||||
actionpack (5.1.5)
|
||||
actionview (= 5.1.5)
|
||||
activesupport (= 5.1.5)
|
||||
actionpack (5.2.2)
|
||||
actionview (= 5.2.2)
|
||||
activesupport (= 5.2.2)
|
||||
rack (~> 2.0)
|
||||
rack-test (>= 0.6.3)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
actionview (5.1.5)
|
||||
activesupport (= 5.1.5)
|
||||
actionview (5.2.2)
|
||||
activesupport (= 5.2.2)
|
||||
builder (~> 3.1)
|
||||
erubi (~> 1.4)
|
||||
rails-dom-testing (~> 2.0)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.3)
|
||||
activejob (5.1.5)
|
||||
activesupport (= 5.1.5)
|
||||
activejob (5.2.2)
|
||||
activesupport (= 5.2.2)
|
||||
globalid (>= 0.3.6)
|
||||
activemodel (5.1.5)
|
||||
activesupport (= 5.1.5)
|
||||
activerecord (5.1.5)
|
||||
activemodel (= 5.1.5)
|
||||
activesupport (= 5.1.5)
|
||||
arel (~> 8.0)
|
||||
activesupport (5.1.5)
|
||||
activemodel (5.2.2)
|
||||
activesupport (= 5.2.2)
|
||||
activerecord (5.2.2)
|
||||
activemodel (= 5.2.2)
|
||||
activesupport (= 5.2.2)
|
||||
arel (>= 9.0)
|
||||
activestorage (5.2.2)
|
||||
actionpack (= 5.2.2)
|
||||
activerecord (= 5.2.2)
|
||||
marcel (~> 0.3.1)
|
||||
activesupport (5.2.2)
|
||||
concurrent-ruby (~> 1.0, >= 1.0.2)
|
||||
i18n (~> 0.7)
|
||||
i18n (>= 0.7, < 2)
|
||||
minitest (~> 5.1)
|
||||
tzinfo (~> 1.1)
|
||||
airbrussh (1.3.0)
|
||||
airbrussh (1.3.1)
|
||||
sshkit (>= 1.6.1, != 1.7.0)
|
||||
arel (8.0.0)
|
||||
bcrypt (3.1.11)
|
||||
arel (9.0.0)
|
||||
bcrypt (3.1.12)
|
||||
builder (3.2.3)
|
||||
byebug (10.0.0)
|
||||
byebug (10.0.2)
|
||||
capistrano (3.10.1)
|
||||
airbrussh (>= 1.0.0)
|
||||
i18n
|
||||
rake (>= 10.0.0)
|
||||
sshkit (>= 1.9.0)
|
||||
capistrano-bundler (1.3.0)
|
||||
capistrano-bundler (1.5.0)
|
||||
capistrano (~> 3.1)
|
||||
sshkit (~> 1.2)
|
||||
capistrano-passenger (0.2.0)
|
||||
capistrano (~> 3.0)
|
||||
capistrano-rails (1.3.1)
|
||||
capistrano-rails (1.4.0)
|
||||
capistrano (~> 3.1)
|
||||
capistrano-bundler (~> 1.1)
|
||||
capistrano-rbenv (2.1.3)
|
||||
capistrano-rbenv (2.1.4)
|
||||
capistrano (~> 3.1)
|
||||
sshkit (~> 1.3)
|
||||
concurrent-ruby (1.0.5)
|
||||
crass (1.0.3)
|
||||
database_cleaner (1.6.2)
|
||||
concurrent-ruby (1.1.4)
|
||||
crass (1.0.4)
|
||||
database_cleaner (1.7.0)
|
||||
diff-lcs (1.3)
|
||||
erubi (1.7.0)
|
||||
erubi (1.8.0)
|
||||
factory_girl (4.9.0)
|
||||
activesupport (>= 3.0.0)
|
||||
factory_girl_rails (4.9.0)
|
||||
factory_girl (~> 4.9.0)
|
||||
railties (>= 3.0.0)
|
||||
faker (1.8.7)
|
||||
faker (1.9.2)
|
||||
i18n (>= 0.7)
|
||||
fast_jsonapi (1.0.17)
|
||||
activerecord (~> 5.0)
|
||||
activesupport (~> 5.0)
|
||||
multi_json (~> 1.12)
|
||||
oj (~> 3.3)
|
||||
ffi (1.9.23)
|
||||
globalid (0.4.1)
|
||||
fast_jsonapi (1.5)
|
||||
activesupport (>= 4.2)
|
||||
ffi (1.10.0)
|
||||
globalid (0.4.2)
|
||||
activesupport (>= 4.2.0)
|
||||
i18n (0.9.5)
|
||||
i18n (1.5.3)
|
||||
concurrent-ruby (~> 1.0)
|
||||
jwt (2.1.0)
|
||||
listen (3.1.5)
|
||||
rb-fsevent (~> 0.9, >= 0.9.4)
|
||||
rb-inotify (~> 0.9, >= 0.9.7)
|
||||
ruby_dep (~> 1.2)
|
||||
loofah (2.2.0)
|
||||
loofah (2.2.3)
|
||||
crass (~> 1.0.2)
|
||||
nokogiri (>= 1.5.9)
|
||||
mail (2.7.0)
|
||||
mail (2.7.1)
|
||||
mini_mime (>= 0.1.1)
|
||||
method_source (0.9.0)
|
||||
mini_mime (1.0.0)
|
||||
mini_portile2 (2.3.0)
|
||||
marcel (0.3.3)
|
||||
mimemagic (~> 0.3.2)
|
||||
method_source (0.9.2)
|
||||
mimemagic (0.3.3)
|
||||
mini_mime (1.0.1)
|
||||
mini_portile2 (2.4.0)
|
||||
minitest (5.11.3)
|
||||
multi_json (1.13.1)
|
||||
mysql2 (0.4.10)
|
||||
mysql2 (0.5.2)
|
||||
net-scp (1.2.1)
|
||||
net-ssh (>= 2.6.5)
|
||||
net-ssh (4.2.0)
|
||||
nio4r (2.2.0)
|
||||
nokogiri (1.8.2)
|
||||
mini_portile2 (~> 2.3.0)
|
||||
oj (3.4.0)
|
||||
puma (3.11.2)
|
||||
rack (2.0.4)
|
||||
net-ssh (5.1.0)
|
||||
nio4r (2.3.1)
|
||||
nokogiri (1.10.1)
|
||||
mini_portile2 (~> 2.4.0)
|
||||
puma (3.12.0)
|
||||
rack (2.0.6)
|
||||
rack-cors (1.0.2)
|
||||
rack-test (0.8.3)
|
||||
rack-test (1.1.0)
|
||||
rack (>= 1.0, < 3)
|
||||
rails (5.1.5)
|
||||
actioncable (= 5.1.5)
|
||||
actionmailer (= 5.1.5)
|
||||
actionpack (= 5.1.5)
|
||||
actionview (= 5.1.5)
|
||||
activejob (= 5.1.5)
|
||||
activemodel (= 5.1.5)
|
||||
activerecord (= 5.1.5)
|
||||
activesupport (= 5.1.5)
|
||||
rails (5.2.2)
|
||||
actioncable (= 5.2.2)
|
||||
actionmailer (= 5.2.2)
|
||||
actionpack (= 5.2.2)
|
||||
actionview (= 5.2.2)
|
||||
activejob (= 5.2.2)
|
||||
activemodel (= 5.2.2)
|
||||
activerecord (= 5.2.2)
|
||||
activestorage (= 5.2.2)
|
||||
activesupport (= 5.2.2)
|
||||
bundler (>= 1.3.0)
|
||||
railties (= 5.1.5)
|
||||
railties (= 5.2.2)
|
||||
sprockets-rails (>= 2.0.0)
|
||||
rails-dom-testing (2.0.3)
|
||||
activesupport (>= 4.2.0)
|
||||
nokogiri (>= 1.6)
|
||||
rails-html-sanitizer (1.0.3)
|
||||
loofah (~> 2.0)
|
||||
railties (5.1.5)
|
||||
actionpack (= 5.1.5)
|
||||
activesupport (= 5.1.5)
|
||||
rails-html-sanitizer (1.0.4)
|
||||
loofah (~> 2.2, >= 2.2.2)
|
||||
railties (5.2.2)
|
||||
actionpack (= 5.2.2)
|
||||
activesupport (= 5.2.2)
|
||||
method_source
|
||||
rake (>= 0.8.7)
|
||||
thor (>= 0.18.1, < 2.0)
|
||||
rake (12.3.0)
|
||||
rb-fsevent (0.10.2)
|
||||
rb-inotify (0.9.10)
|
||||
ffi (>= 0.5.0, < 2)
|
||||
rspec-core (3.7.1)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-expectations (3.7.0)
|
||||
thor (>= 0.19.0, < 2.0)
|
||||
rake (12.3.2)
|
||||
rb-fsevent (0.10.3)
|
||||
rb-inotify (0.10.0)
|
||||
ffi (~> 1.0)
|
||||
rspec-core (3.8.0)
|
||||
rspec-support (~> 3.8.0)
|
||||
rspec-expectations (3.8.2)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-mocks (3.7.0)
|
||||
rspec-support (~> 3.8.0)
|
||||
rspec-mocks (3.8.0)
|
||||
diff-lcs (>= 1.2.0, < 2.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-rails (3.7.2)
|
||||
rspec-support (~> 3.8.0)
|
||||
rspec-rails (3.8.2)
|
||||
actionpack (>= 3.0)
|
||||
activesupport (>= 3.0)
|
||||
railties (>= 3.0)
|
||||
rspec-core (~> 3.7.0)
|
||||
rspec-expectations (~> 3.7.0)
|
||||
rspec-mocks (~> 3.7.0)
|
||||
rspec-support (~> 3.7.0)
|
||||
rspec-support (3.7.1)
|
||||
rspec-core (~> 3.8.0)
|
||||
rspec-expectations (~> 3.8.0)
|
||||
rspec-mocks (~> 3.8.0)
|
||||
rspec-support (~> 3.8.0)
|
||||
rspec-support (3.8.0)
|
||||
ruby_dep (1.5.0)
|
||||
shoulda-matchers (3.1.2)
|
||||
shoulda-matchers (3.1.3)
|
||||
activesupport (>= 4.0.0)
|
||||
spring (2.0.2)
|
||||
activesupport (>= 4.2)
|
||||
spring-watcher-listen (2.0.1)
|
||||
listen (>= 2.7, < 4.0)
|
||||
spring (>= 1.2, < 3.0)
|
||||
sprockets (3.7.1)
|
||||
sprockets (3.7.2)
|
||||
concurrent-ruby (~> 1.0)
|
||||
rack (> 1, < 3)
|
||||
sprockets-rails (3.2.1)
|
||||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
sshkit (1.16.0)
|
||||
sshkit (1.18.2)
|
||||
net-scp (>= 1.1.2)
|
||||
net-ssh (>= 2.8.0)
|
||||
thor (0.20.0)
|
||||
thor (0.20.3)
|
||||
thread_safe (0.3.6)
|
||||
tzinfo (1.2.5)
|
||||
thread_safe (~> 0.1)
|
||||
websocket-driver (0.6.5)
|
||||
websocket-driver (0.7.0)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.3)
|
||||
will_paginate (3.1.6)
|
||||
|
|
@ -199,9 +201,9 @@ DEPENDENCIES
|
|||
jwt
|
||||
listen (>= 3.0.5, < 3.2)
|
||||
mysql2 (>= 0.4.10)
|
||||
puma (~> 3.7)
|
||||
puma (~> 3.11)
|
||||
rack-cors
|
||||
rails (~> 5.1.5)
|
||||
rails (~> 5.2.2)
|
||||
rspec-rails (~> 3.5)
|
||||
shoulda-matchers (~> 3.1)
|
||||
spring
|
||||
|
|
@ -209,5 +211,8 @@ DEPENDENCIES
|
|||
tzinfo-data
|
||||
will_paginate
|
||||
|
||||
RUBY VERSION
|
||||
ruby 2.5.1p57
|
||||
|
||||
BUNDLED WITH
|
||||
1.16.1
|
||||
1.16.2
|
||||
|
|
|
|||
51
app/controllers/user_profiles_controller.rb
Normal file
51
app/controllers/user_profiles_controller.rb
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
class UserProfilesController < ApplicationController
|
||||
before_action :set_user_profile, only: [:show, :update, :destroy]
|
||||
|
||||
# GET /user_profiles
|
||||
def index
|
||||
@user_profiles = UserProfile.all
|
||||
|
||||
render json: @user_profiles
|
||||
end
|
||||
|
||||
# GET /user_profiles/1
|
||||
def show
|
||||
render json: @user_profile
|
||||
end
|
||||
|
||||
# POST /user_profiles
|
||||
def create
|
||||
@user_profile = UserProfile.new(user_profile_params)
|
||||
|
||||
if @user_profile.save
|
||||
render json: @user_profile, status: :created, location: @user_profile
|
||||
else
|
||||
render json: @user_profile.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# PATCH/PUT /user_profiles/1
|
||||
def update
|
||||
if @user_profile.update(user_profile_params)
|
||||
render json: @user_profile
|
||||
else
|
||||
render json: @user_profile.errors, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
|
||||
# DELETE /user_profiles/1
|
||||
def destroy
|
||||
@user_profile.destroy
|
||||
end
|
||||
|
||||
private
|
||||
# Use callbacks to share common setup or constraints between actions.
|
||||
def set_user_profile
|
||||
@user_profile = UserProfile.find(params[:id])
|
||||
end
|
||||
|
||||
# Only allow a trusted parameter "white list" through.
|
||||
def user_profile_params
|
||||
params.require(:user_profile).permit(:avatar, :tagline, :dob, :role, :user_id)
|
||||
end
|
||||
end
|
||||
|
|
@ -5,6 +5,8 @@ class User < ApplicationRecord
|
|||
has_many :articles
|
||||
has_many :comments
|
||||
|
||||
has_one :user_profile
|
||||
|
||||
validates_presence_of :name, :email, :password_digest
|
||||
validates_uniqueness_of :email
|
||||
end
|
||||
|
|
|
|||
3
app/models/user_profile.rb
Normal file
3
app/models/user_profile.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
class UserProfile < ApplicationRecord
|
||||
belongs_to :user, :dependent => :destroy
|
||||
end
|
||||
|
|
@ -10,7 +10,7 @@ default: &default
|
|||
timeout: 5000
|
||||
host: localhost
|
||||
username: root
|
||||
password: SuperSecret
|
||||
password: <%= ENV.fetch("LOCAL_DB_PASS") %>
|
||||
socket: /var/run/mysqld/mysqld.sock
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
Rails.application.routes.draw do
|
||||
resources :user_profiles
|
||||
resources :comments
|
||||
# For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html
|
||||
|
||||
|
|
|
|||
13
db/migrate/20190214142704_create_user_profiles.rb
Normal file
13
db/migrate/20190214142704_create_user_profiles.rb
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
class CreateUserProfiles < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :user_profiles do |t|
|
||||
t.string :avatar
|
||||
t.string :tagline
|
||||
t.date :dob
|
||||
t.string :role
|
||||
t.references :user, foreign_key: true
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
29
db/schema.rb
29
db/schema.rb
|
|
@ -10,9 +10,9 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 20180222154430) do
|
||||
ActiveRecord::Schema.define(version: 2019_02_14_142704) do
|
||||
|
||||
create_table "articles", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
create_table "articles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.string "title"
|
||||
t.text "post"
|
||||
t.bigint "user_id"
|
||||
|
|
@ -21,7 +21,7 @@ ActiveRecord::Schema.define(version: 20180222154430) do
|
|||
t.index ["user_id"], name: "index_articles_on_user_id"
|
||||
end
|
||||
|
||||
create_table "comments", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
create_table "comments", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.text "content"
|
||||
t.bigint "article_id"
|
||||
t.bigint "user_id"
|
||||
|
|
@ -31,23 +31,18 @@ ActiveRecord::Schema.define(version: 20180222154430) do
|
|||
t.index ["user_id"], name: "index_comments_on_user_id"
|
||||
end
|
||||
|
||||
create_table "items", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
t.string "name"
|
||||
t.boolean "done"
|
||||
t.bigint "todo_id"
|
||||
create_table "user_profiles", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.string "avatar"
|
||||
t.string "tagline"
|
||||
t.date "dob"
|
||||
t.string "role"
|
||||
t.bigint "user_id"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["todo_id"], name: "index_items_on_todo_id"
|
||||
t.index ["user_id"], name: "index_user_profiles_on_user_id"
|
||||
end
|
||||
|
||||
create_table "todos", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
t.string "title"
|
||||
t.string "created_by"
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
end
|
||||
|
||||
create_table "users", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8" do |t|
|
||||
create_table "users", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8", force: :cascade do |t|
|
||||
t.string "name"
|
||||
t.string "email"
|
||||
t.string "password_digest"
|
||||
|
|
@ -58,5 +53,5 @@ ActiveRecord::Schema.define(version: 20180222154430) do
|
|||
add_foreign_key "articles", "users"
|
||||
add_foreign_key "comments", "articles"
|
||||
add_foreign_key "comments", "users"
|
||||
add_foreign_key "items", "todos"
|
||||
add_foreign_key "user_profiles", "users"
|
||||
end
|
||||
|
|
|
|||
38
test/controllers/user_profiles_controller_test.rb
Normal file
38
test/controllers/user_profiles_controller_test.rb
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
require 'test_helper'
|
||||
|
||||
class UserProfilesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@user_profile = user_profiles(:one)
|
||||
end
|
||||
|
||||
test "should get index" do
|
||||
get user_profiles_url, as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create user_profile" do
|
||||
assert_difference('UserProfile.count') do
|
||||
post user_profiles_url, params: { user_profile: { avatar: @user_profile.avatar, dob: @user_profile.dob, role: @user_profile.role, tagline: @user_profile.tagline, user_id: @user_profile.user_id } }, as: :json
|
||||
end
|
||||
|
||||
assert_response 201
|
||||
end
|
||||
|
||||
test "should show user_profile" do
|
||||
get user_profile_url(@user_profile), as: :json
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update user_profile" do
|
||||
patch user_profile_url(@user_profile), params: { user_profile: { avatar: @user_profile.avatar, dob: @user_profile.dob, role: @user_profile.role, tagline: @user_profile.tagline, user_id: @user_profile.user_id } }, as: :json
|
||||
assert_response 200
|
||||
end
|
||||
|
||||
test "should destroy user_profile" do
|
||||
assert_difference('UserProfile.count', -1) do
|
||||
delete user_profile_url(@user_profile), as: :json
|
||||
end
|
||||
|
||||
assert_response 204
|
||||
end
|
||||
end
|
||||
15
test/fixtures/user_profiles.yml
vendored
Normal file
15
test/fixtures/user_profiles.yml
vendored
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# Read about fixtures at http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||
|
||||
one:
|
||||
avatar: MyString
|
||||
tagline: MyString
|
||||
dob: 2019-02-14
|
||||
role: MyString
|
||||
user: one
|
||||
|
||||
two:
|
||||
avatar: MyString
|
||||
tagline: MyString
|
||||
dob: 2019-02-14
|
||||
role: MyString
|
||||
user: two
|
||||
7
test/models/user_profile_test.rb
Normal file
7
test/models/user_profile_test.rb
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
require 'test_helper'
|
||||
|
||||
class UserProfileTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue