From 79413cd15280d8cf3831ccfa7c0bf67b612b54bf Mon Sep 17 00:00:00 2001 From: Rodrigo Chavez Date: Wed, 18 Sep 2024 18:48:36 -0600 Subject: [PATCH] Attendees test fully passing now updated index action, simple cov 100% for attendees --- .../api/v1/attendees_controller.rb | 2 +- spec/requests/api/v1/attendee_request_spec.rb | 36 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/v1/attendees_controller.rb b/app/controllers/api/v1/attendees_controller.rb index 3687f66..2d96eaa 100644 --- a/app/controllers/api/v1/attendees_controller.rb +++ b/app/controllers/api/v1/attendees_controller.rb @@ -21,7 +21,7 @@ def destroy end def index - attendees = Attendee.where(event_id: params[:event_id]) + attendees = Attendee.all render json: AttendeeSerializer.new(attendees), status: :ok end ##### NEED TO SQUARE AWAY JSON RENDERING WITH SERIALIZERS FOR ALL ACTIONS ##### diff --git a/spec/requests/api/v1/attendee_request_spec.rb b/spec/requests/api/v1/attendee_request_spec.rb index bc212e6..c122267 100644 --- a/spec/requests/api/v1/attendee_request_spec.rb +++ b/spec/requests/api/v1/attendee_request_spec.rb @@ -116,4 +116,40 @@ expect(attendee[:errors]).to be_a(String) expect(attendee[:errors]).to eq("Attendee not found") end + + + describe 'index' do + + it 'returns attendees' do + get '/api/v1/attendees' + + expect(response).to be_successful + expect(response.status).to eq(200) + + attendees = JSON.parse(response.body, symbolize_names: true) + expect(attendees).to have_key(:data) + expect(attendees).to be_a(Hash) + expect(attendees.count).to eq(1) + expect(attendees).to have_key(:data) + + expect(attendees[:data]).to be_a(Array) + expect(attendees[:data].first).to have_key(:id) + expect(attendees[:data].first[:id]).to be_a(String) + expect(attendees[:data].first[:id]).to eq("#{attendees[:data].first[:id]}") + + expect(attendees[:data].first).to have_key(:type) + expect(attendees[:data].first[:type]).to be_a(String) + expect(attendees[:data].first[:type]).to eq("attendee") + + expect(attendees[:data].first).to have_key(:attributes) + expect(attendees[:data].first[:attributes]).to be_a(Hash) + + # require 'pry'; binding.pry + expect(attendees[:data].first[:attributes][:user_id]).to be_a(Integer) + expect(attendees[:data].first[:attributes][:user_id]).to eq(attendees[:data].first[:attributes][:user_id]) + + expect(attendees[:data].first[:attributes][:event_id]).to be_a(Integer) + expect(attendees[:data].first[:attributes][:event_id]).to eq(attendees[:data].first[:attributes][:event_id]) + end + end end \ No newline at end of file