chequear el perfil propio closes #1
This commit is contained in:
parent
d4a7a2466a
commit
064794f6a6
8 changed files with 43 additions and 1 deletions
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Las piratas son las que activan el Miniloom
|
||||
class PiratasController < ApplicationController
|
||||
# Todo necesita autenticación salvo la creación de cuentas
|
||||
before_action :authenticate!, except: %i[create]
|
||||
# POST /piratas
|
||||
#
|
||||
# Registra una cuenta
|
||||
|
@ -19,4 +21,13 @@ class PiratasController < ApplicationController
|
|||
render json: { errors: @pirata.errors.messages },
|
||||
status: :unprocessable_entity
|
||||
end
|
||||
|
||||
# GET /piratas/yo
|
||||
#
|
||||
# Obtener el perfil propio
|
||||
#
|
||||
# @return [Hash] { id: @int, nick: @string, email: @string }
|
||||
def yo
|
||||
@pirata = current_pirata
|
||||
end
|
||||
end
|
||||
|
|
3
app/views/piratas/_pirata.json.jbuilder
Normal file
3
app/views/piratas/_pirata.json.jbuilder
Normal file
|
@ -0,0 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
json.call(pirata, :id, :nick, :email)
|
|
@ -1,3 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
json.call(@pirata, :id, :nick, :email)
|
||||
json.partial! @pirata, as: :pirata
|
||||
|
|
3
app/views/piratas/yo.json.jbuilder
Normal file
3
app/views/piratas/yo.json.jbuilder
Normal file
|
@ -0,0 +1,3 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
json.partial! @pirata, as: :pirata
|
|
@ -8,6 +8,8 @@
|
|||
ActiveSupport::Inflector.inflections(:en) do |inflect|
|
||||
inflect.plural 'posicion', 'posiciones'
|
||||
inflect.singular 'posiciones', 'posicion'
|
||||
inflect.plural 'pirata', 'piratas'
|
||||
inflect.singular 'piratas', 'pirata'
|
||||
end
|
||||
|
||||
# These inflection rules are supported but not enabled by default:
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
Rails.application.routes.draw do
|
||||
get '/piratas/yo', to: 'piratas#yo'
|
||||
# No queremos un índice de piratas
|
||||
resources :piratas, only: %i[create]
|
||||
# Podemos crear consensos pero no modificarlos
|
||||
|
|
8
db/migrate/20190421001841_rename_pirata.rb
Normal file
8
db/migrate/20190421001841_rename_pirata.rb
Normal file
|
@ -0,0 +1,8 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
# Renombrar la tabla porque nos olvidamos de las inflexiones
|
||||
class RenamePirata < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
rename_table :pirata, :piratas
|
||||
end
|
||||
end
|
|
@ -30,4 +30,18 @@ class PiratasControllerTest < ActionDispatch::IntegrationTest
|
|||
body = JSON.parse @response.body
|
||||
assert_equal %w[errors], body.keys
|
||||
end
|
||||
|
||||
test 'puedo ver mi perfil' do
|
||||
pirata = create :pirata
|
||||
|
||||
get piratas_yo_url, as: :json, headers: {
|
||||
Authorization: ActionController::HttpAuthentication::Basic
|
||||
.encode_credentials(pirata.email, pirata.password)
|
||||
}
|
||||
|
||||
body = JSON.parse @response.body
|
||||
assert_equal pirata.id, body['id']
|
||||
assert_equal pirata.email, body['email']
|
||||
assert_equal pirata.nick, body['nick']
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue