Skip to content

Commit

Permalink
Attendees test fully passing now updated index action, simple cov 100…
Browse files Browse the repository at this point in the history
…% for attendees
  • Loading branch information
RodrigoACG committed Sep 19, 2024
1 parent b9c803b commit 79413cd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/controllers/api/v1/attendees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 #####
Expand Down
36 changes: 36 additions & 0 deletions spec/requests/api/v1/attendee_request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 79413cd

Please sign in to comment.