From 532054de112f45eb3bc7e9f7f73284eeb838b028 Mon Sep 17 00:00:00 2001 From: fauno Date: Sat, 3 Aug 2019 15:25:11 -0300 Subject: [PATCH] distinguir entre todas las barcas y solo en las que estamos --- app/controllers/barcas_controller.rb | 9 ++++++++- app/views/barcas/todas.json.jbuilder | 3 +++ config/routes.rb | 1 + test/controllers/barcas_controller_test.rb | 17 +++++++++++++++++ 4 files changed, 29 insertions(+), 1 deletion(-) create mode 100644 app/views/barcas/todas.json.jbuilder diff --git a/app/controllers/barcas_controller.rb b/app/controllers/barcas_controller.rb index 277ae45..7b76404 100644 --- a/app/controllers/barcas_controller.rb +++ b/app/controllers/barcas_controller.rb @@ -6,10 +6,17 @@ class BarcasController < ApplicationController # GET /barcas # - # Devuelve todas las barcas + # Devuelve todas las barcas abordadas # # @return Array [ barcas ] def index + @barcas = current_pirata.barcas + end + + # GET /barcas/todas + # + # Ver todas las barcas + def todas @barcas = Barca.all end diff --git a/app/views/barcas/todas.json.jbuilder b/app/views/barcas/todas.json.jbuilder new file mode 100644 index 0000000..26d5433 --- /dev/null +++ b/app/views/barcas/todas.json.jbuilder @@ -0,0 +1,3 @@ +# frozen_string_literal: true + +json.barcas @barcas, partial: 'barcas/barca', as: :barca diff --git a/config/routes.rb b/config/routes.rb index 4411cf1..fab4ab7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ Rails.application.routes.draw do # Solo se pueden crear suscripciones resources :webpush_subscriptions, only: %i[create] # Podemos crear barcas y dentro de ellas consensos + get 'barcas/todas', to: 'barcas#todas' resources :barcas, only: %i[index show create update destroy] do put 'abordar', to: 'barcas#abordar' delete 'abandonar', to: 'barcas#abandonar' diff --git a/test/controllers/barcas_controller_test.rb b/test/controllers/barcas_controller_test.rb index b6e19c1..839c150 100644 --- a/test/controllers/barcas_controller_test.rb +++ b/test/controllers/barcas_controller_test.rb @@ -7,11 +7,28 @@ class BarcasControllerTest < ActionDispatch::IntegrationTest .encode_credentials(@pirata.email, @pirata.password) } end + test 'se pueden ver todas-todas' do + 2.times do + create :barca + end + + create :barca, piratas: [@pirata] + + get barcas_todas_url, as: :json, headers: @auth + + body = JSON.parse(@response.body) + + assert_equal 200, @response.status + assert_equal 3, body['barcas'].size + end + test 'se pueden ver todas' do 2.times do create :barca, piratas: [@pirata] end + create :barca + get barcas_url, as: :json, headers: @auth body = JSON.parse(@response.body)