Add specs for api/v1/rooms_controller & api/v1/tracks_controller

and cleanup api/v1/tracks and api/v1/rooms controllers
This commit is contained in:
Nishanth Vijayan 2016-03-14 04:02:15 +05:30
parent 55cfc8ff60
commit 864245fec2
4 changed files with 77 additions and 5 deletions

View file

@ -5,12 +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.venue ? (rooms = @conference.venue.rooms) : (rooms = [])
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.program.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