-
-
Save thewatts/41ec273cc5d8e02c9d022c2d149c3821 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RSpec.describe 'Listing Events', type: :request do | |
def response_data | |
JSON.parse(response.body).deep_symbolize_keys | |
end | |
before(:context) do | |
@breakfast_at_tiffanys = create(:event, name: "Breakfast at Tiffany's") | |
@coffee_with_karl = create(:event, name: 'Coffee with Karl') | |
@mid_afternoon_nap = create(:event, name: 'Mid Afternoon Siesta', important: true) | |
end | |
after(:context) do | |
@breakfast_at_tiffanys.destroy | |
@coffee_with_karl.destroy | |
@mid_afternoon_nap.destroy | |
end | |
context 'listing all events' do | |
before(:context) do | |
params = {} | |
get '/api/events', params | |
end | |
it 'returns a 200 with the correct schema' do | |
expect(response.status).to eq 200 | |
expect(response).to match_response_schema('events-list') | |
end | |
it 'returns the correct events' do | |
event_ids = response_data[:events].map { |event| event[:id] } | |
expect(event_ids).to include @breakfast_at_tiffanys.id | |
expect(event_ids).to include @coffee_with_karl.id | |
expect(event_ids).to include @mid_afternoon_nap.id | |
end | |
end | |
context 'listing important events' do | |
before(:context) do | |
params = { important: true } | |
get '/api/events', params | |
end | |
it 'returns a 200 with the correct schema' do | |
expect(response.status).to eq 200 | |
expect(response).to match_response_schema('events-list') | |
end | |
it 'returns the correct events' do | |
event_ids = response_data[:events].map { |event| event[:id] } | |
expect(event_ids).not_to include @breakfast_at_tiffanys.id | |
expect(event_ids).not_to include @coffee_with_karl.id | |
expect(event_ids).to include @mid_afternoon_nap.id | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment