chequear el perfil propio closes #1

This commit is contained in:
fauno 2019-04-20 23:25:39 -03:00
parent d4a7a2466a
commit 064794f6a6
No known key found for this signature in database
GPG key ID: 456032D717A4CD9C
8 changed files with 43 additions and 1 deletions

View file

@ -2,6 +2,8 @@
# Las piratas son las que activan el Miniloom # Las piratas son las que activan el Miniloom
class PiratasController < ApplicationController class PiratasController < ApplicationController
# Todo necesita autenticación salvo la creación de cuentas
before_action :authenticate!, except: %i[create]
# POST /piratas # POST /piratas
# #
# Registra una cuenta # Registra una cuenta
@ -19,4 +21,13 @@ class PiratasController < ApplicationController
render json: { errors: @pirata.errors.messages }, render json: { errors: @pirata.errors.messages },
status: :unprocessable_entity status: :unprocessable_entity
end end
# GET /piratas/yo
#
# Obtener el perfil propio
#
# @return [Hash] { id: @int, nick: @string, email: @string }
def yo
@pirata = current_pirata
end
end end

View file

@ -0,0 +1,3 @@
# frozen_string_literal: true
json.call(pirata, :id, :nick, :email)

View file

@ -1,3 +1,3 @@
# frozen_string_literal: true # frozen_string_literal: true
json.call(@pirata, :id, :nick, :email) json.partial! @pirata, as: :pirata

View file

@ -0,0 +1,3 @@
# frozen_string_literal: true
json.partial! @pirata, as: :pirata

View file

@ -8,6 +8,8 @@
ActiveSupport::Inflector.inflections(:en) do |inflect| ActiveSupport::Inflector.inflections(:en) do |inflect|
inflect.plural 'posicion', 'posiciones' inflect.plural 'posicion', 'posiciones'
inflect.singular 'posiciones', 'posicion' inflect.singular 'posiciones', 'posicion'
inflect.plural 'pirata', 'piratas'
inflect.singular 'piratas', 'pirata'
end end
# These inflection rules are supported but not enabled by default: # These inflection rules are supported but not enabled by default:

View file

@ -1,6 +1,7 @@
# frozen_string_literal: true # frozen_string_literal: true
Rails.application.routes.draw do Rails.application.routes.draw do
get '/piratas/yo', to: 'piratas#yo'
# No queremos un índice de piratas # No queremos un índice de piratas
resources :piratas, only: %i[create] resources :piratas, only: %i[create]
# Podemos crear consensos pero no modificarlos # Podemos crear consensos pero no modificarlos

View 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

View file

@ -30,4 +30,18 @@ class PiratasControllerTest < ActionDispatch::IntegrationTest
body = JSON.parse @response.body body = JSON.parse @response.body
assert_equal %w[errors], body.keys assert_equal %w[errors], body.keys
end 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 end