diff --git a/Gemfile b/Gemfile index 070493b..364e8ba 100644 --- a/Gemfile +++ b/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 diff --git a/Gemfile.lock b/Gemfile.lock index 0f1a699..065ba42 100644 --- a/Gemfile.lock +++ b/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 diff --git a/app/controllers/user_profiles_controller.rb b/app/controllers/user_profiles_controller.rb new file mode 100644 index 0000000..7d01956 --- /dev/null +++ b/app/controllers/user_profiles_controller.rb @@ -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 diff --git a/app/models/user.rb b/app/models/user.rb index 2652094..1ac51a2 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/models/user_profile.rb b/app/models/user_profile.rb new file mode 100644 index 0000000..9d09ae9 --- /dev/null +++ b/app/models/user_profile.rb @@ -0,0 +1,3 @@ +class UserProfile < ApplicationRecord + belongs_to :user, :dependent => :destroy +end diff --git a/config/database.yml b/config/database.yml index b72514e..1e7b8b3 100644 --- a/config/database.yml +++ b/config/database.yml @@ -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 diff --git a/config/routes.rb b/config/routes.rb index 494982d..b9a7a6f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/db/migrate/20190214142704_create_user_profiles.rb b/db/migrate/20190214142704_create_user_profiles.rb new file mode 100644 index 0000000..3f1e2d0 --- /dev/null +++ b/db/migrate/20190214142704_create_user_profiles.rb @@ -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 diff --git a/db/schema.rb b/db/schema.rb index 191dea4..525777d 100644 --- a/db/schema.rb +++ b/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 diff --git a/test/controllers/user_profiles_controller_test.rb b/test/controllers/user_profiles_controller_test.rb new file mode 100644 index 0000000..c50ce70 --- /dev/null +++ b/test/controllers/user_profiles_controller_test.rb @@ -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 diff --git a/test/fixtures/user_profiles.yml b/test/fixtures/user_profiles.yml new file mode 100644 index 0000000..64f75c8 --- /dev/null +++ b/test/fixtures/user_profiles.yml @@ -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 diff --git a/test/models/user_profile_test.rb b/test/models/user_profile_test.rb new file mode 100644 index 0000000..cdb1790 --- /dev/null +++ b/test/models/user_profile_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class UserProfileTest < ActiveSupport::TestCase + # test "the truth" do + # assert true + # end +end