Merge pull request #875 from nishanthvijayan/fix-api-rooms

Fix API endpoints conferences/id/rooms/ & tracks/ issue
This commit is contained in:
Christian Bruckmayer 2016-03-14 13:45:35 -06:00
commit d2cfb56ea5
4 changed files with 77 additions and 6 deletions

View file

@ -5,13 +5,11 @@ module Api
respond_to :json
def index
if params[:conference_id].blank?
rooms = Room.all
if @conference
respond_with @conference.venue ? @conference.venue.rooms : Room.none
else
conference = Conference.find_by_guid(params[:conference_id])
rooms = conference.venue.rooms if conference.venue
respond_with Room.all
end
respond_with rooms
end
end
end

View file

@ -5,7 +5,7 @@ module Api
respond_to :json
def index
@conference ? (tracks = @conference.tracks) : (tracks = Track.all)
tracks = @conference ? @conference.program.tracks : Track.all
respond_with tracks
end

View file

@ -0,0 +1,37 @@
require 'spec_helper'
describe Api::V1::RoomsController do
let!(:conference) { create(:conference) }
let!(:venue) { create(:venue, conference: conference) }
let!(:conference_room) { create(:room, name: 'Conference Room', venue: venue) }
let!(:room) { create(:room, name: 'Test Room') }
context 'GET #index' do
context 'without conference scope' do
it 'returns all rooms' do
get :index, format: :json
json = JSON.parse(response.body)
expect(response).to be_success
expect(json.length).to eq(2)
expect(json[0]['name']).to eq('Conference Room')
expect(json[1]['name']).to eq('Test Room')
end
end
context 'with conference scope' do
it 'returns all rooms of conference' do
get :index, conference_id: conference.short_title, format: :json
json = JSON.parse(response.body)
expect(response).to be_success
expect(json.length).to eq(1)
expect(json[0]['name']).to eq('Conference Room')
end
end
end
end

View file

@ -0,0 +1,36 @@
require 'spec_helper'
describe Api::V1::TracksController do
let!(:conference) { create(:conference) }
let!(:conference_track) { create(:track, name: 'Conference Track', program_id: conference.program.id) }
let!(:track) { create(:track, name: 'Test Track') }
context 'GET #index' do
context 'without conference scope' do
it 'returns all tracks' do
get :index, format: :json
json = JSON.parse(response.body)
expect(response).to be_success
expect(json.length).to eq(2)
expect(json[0]['name']).to eq('Conference Track')
expect(json[1]['name']).to eq('Test Track')
end
end
context 'with conference scope' do
it 'returns all rooms of conference' do
get :index, conference_id: conference.short_title, format: :json
json = JSON.parse(response.body)
expect(response).to be_success
expect(json.length).to eq(1)
expect(json[0]['name']).to eq('Conference Track')
end
end
end
end