diff --git a/Gemfile.lock b/Gemfile.lock index 362eb32..c892c91 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -90,7 +90,7 @@ GEM minitest (5.16.3) msgpack (1.6.0) nio4r (2.5.8) - nokogiri (1.13.8) + nokogiri (1.13.9) mini_portile2 (~> 2.8.0) racc (~> 1.4) pg (1.4.4) @@ -135,14 +135,14 @@ GEM rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - rspec-core (3.11.0) - rspec-support (~> 3.11.0) - rspec-expectations (3.11.1) + rspec-core (3.12.0) + rspec-support (~> 3.12.0) + rspec-expectations (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) - rspec-mocks (3.11.1) + rspec-support (~> 3.12.0) + rspec-mocks (3.12.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.11.0) + rspec-support (~> 3.12.0) rspec-rails (5.1.2) actionpack (>= 5.2) activesupport (>= 5.2) @@ -151,7 +151,7 @@ GEM rspec-expectations (~> 3.10) rspec-mocks (~> 3.10) rspec-support (~> 3.10) - rspec-support (3.11.1) + rspec-support (3.12.0) shoulda-matchers (5.2.0) activesupport (>= 5.2.0) spring (2.1.1) @@ -172,7 +172,7 @@ GEM websocket-driver (0.7.5) websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) - zeitwerk (2.6.1) + zeitwerk (2.6.5) PLATFORMS ruby diff --git a/README.md b/README.md index 7db80e4..1d1bf5f 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,17 @@ -# README -This README would normally document whatever steps are necessary to get the -application up and running. +# api-postgresql -Things you may want to cover: +O projeto conta com uma api construida em Ruby on Rails para fins de desenvolvimento e aprendizado. -* Ruby version -* System dependencies +The project has an API built in Ruby on Rails for development and learning purposes. +## Tutor -* Configuration +- [Joathan](https://github.com/joathan) -* Database creation +## ReferĂȘncia -* Database initialization + - [RubyGems](https://rubygems.org/) +## 🛠 Habilidades +Ruby on Rails, HTML... -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4d064f2..b609db3 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,5 @@ class UsersController < ApplicationController + before_action :set_user, only: [:update] def create @user = User.new(user_params) @@ -10,6 +11,14 @@ def create end end + def update + if @user.update(user_params) + render json: @user, status: 200 + else + render json: @user.errors, status: :unprocessable_entity + end + end + private # Use callbacks to share common setup or constraints between actions. def set_user diff --git a/config/routes.rb b/config/routes.rb index 5981895..3da4fc9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,5 +1,5 @@ Rails.application.routes.draw do - resources :users, only: [:create] + resources :users, only: [ :create, :update ] # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html end diff --git a/spec/requests/users_spec.rb b/spec/requests/users_spec.rb new file mode 100644 index 0000000..842ce16 --- /dev/null +++ b/spec/requests/users_spec.rb @@ -0,0 +1,13 @@ +require 'rails_helper' + +RSpec.describe "Users", type: :request do + describe "PUT /users/update" do + let!(:user) { User.create(name: 'John', age: 28) } + scenario 'valid user attributes' do + put "/users/#{user.id}", params: { + user: { name: 'John', age: 28 } + } + expect(response.status).to eq(200) + end + end +end