Merge pull request #880 from nishanthvijayan/fix-api-serializers
Update active_model_serializers.Fix conference serializer and api tests
This commit is contained in:
commit
9656fd17c2
4 changed files with 39 additions and 35 deletions
|
|
@ -21,8 +21,8 @@ GEM
|
||||||
erubis (~> 2.7.0)
|
erubis (~> 2.7.0)
|
||||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||||
active_model_serializers (0.8.1)
|
active_model_serializers (0.9.4)
|
||||||
activemodel (>= 3.0)
|
activemodel (>= 3.2)
|
||||||
activejob (4.2.5.2)
|
activejob (4.2.5.2)
|
||||||
activesupport (= 4.2.5.2)
|
activesupport (= 4.2.5.2)
|
||||||
globalid (>= 0.3.0)
|
globalid (>= 0.3.0)
|
||||||
|
|
|
||||||
|
|
@ -4,47 +4,51 @@ class ConferenceSerializer < ActiveModel::Serializer
|
||||||
:date_range, :revision
|
:date_range, :revision
|
||||||
|
|
||||||
def difficulty_levels
|
def difficulty_levels
|
||||||
object.difficulty_levels.map do |difficulty_level| { id: difficulty_level.id,
|
object.program.difficulty_levels.map do |difficulty_level| { id: difficulty_level.id,
|
||||||
title: difficulty_level.title,
|
title: difficulty_level.title,
|
||||||
description: difficulty_level.description
|
description: difficulty_level.description
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def event_types
|
def event_types
|
||||||
object.event_types.map do |event_type| { id: event_type.id,
|
object.program.event_types.map do |event_type| { id: event_type.id,
|
||||||
title: event_type.title,
|
title: event_type.title,
|
||||||
length: event_type.length,
|
length: event_type.length,
|
||||||
description: event_type.description
|
description: event_type.description
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def rooms
|
def rooms
|
||||||
object.rooms.includes(:events).map do |room| { id: room.id,
|
if object.venue
|
||||||
size: room.size,
|
object.venue.rooms.includes(:events).map do |room| { id: room.id,
|
||||||
events: room.events.map do |event| { guid: event.title,
|
size: room.size,
|
||||||
title: event.title,
|
events: room.events.map do |event| { guid: event.title,
|
||||||
subtitle: event.subtitle,
|
title: event.title,
|
||||||
abstract: event.abstract,
|
subtitle: event.subtitle,
|
||||||
description: event.description,
|
abstract: event.abstract,
|
||||||
is_highlight: event.is_highlight,
|
description: event.description,
|
||||||
require_registration: event.require_registration,
|
is_highlight: event.is_highlight,
|
||||||
start_time: event.start_time,
|
require_registration: event.require_registration,
|
||||||
event_type_id: event.event_type.id,
|
start_time: event.start_time,
|
||||||
difficulty_level_id: event.difficulty_level_id,
|
event_type_id: event.event_type.id,
|
||||||
track_id: event.track_id,
|
difficulty_level_id: event.difficulty_level_id,
|
||||||
speaker_names: event.speaker_names
|
track_id: event.track_id,
|
||||||
}
|
speaker_names: event.speaker_names
|
||||||
end
|
}
|
||||||
}
|
end
|
||||||
|
}
|
||||||
|
end
|
||||||
|
else
|
||||||
|
[]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tracks
|
def tracks
|
||||||
object.tracks.map do |track| { 'id' => track.id,
|
object.program.tracks.map do |track| { 'id' => track.id,
|
||||||
'name' => track.name,
|
'name' => track.name,
|
||||||
'description' => track.description
|
'description' => track.description
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,12 +6,12 @@ describe Api::V1::RoomsController do
|
||||||
let!(:conference_room) { create(:room, name: 'Conference Room', venue: venue) }
|
let!(:conference_room) { create(:room, name: 'Conference Room', venue: venue) }
|
||||||
let!(:room) { create(:room, name: 'Test Room') }
|
let!(:room) { create(:room, name: 'Test Room') }
|
||||||
|
|
||||||
context 'GET #index' do
|
describe 'GET #index' do
|
||||||
context 'without conference scope' do
|
context 'without conference scope' do
|
||||||
it 'returns all rooms' do
|
it 'returns all rooms' do
|
||||||
|
|
||||||
get :index, format: :json
|
get :index, format: :json
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)['rooms']
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ describe Api::V1::RoomsController do
|
||||||
it 'returns all rooms of conference' do
|
it 'returns all rooms of conference' do
|
||||||
|
|
||||||
get :index, conference_id: conference.short_title, format: :json
|
get :index, conference_id: conference.short_title, format: :json
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)['rooms']
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,12 +5,12 @@ describe Api::V1::TracksController do
|
||||||
let!(:conference_track) { create(:track, name: 'Conference Track', program_id: conference.program.id) }
|
let!(:conference_track) { create(:track, name: 'Conference Track', program_id: conference.program.id) }
|
||||||
let!(:track) { create(:track, name: 'Test Track') }
|
let!(:track) { create(:track, name: 'Test Track') }
|
||||||
|
|
||||||
context 'GET #index' do
|
describe 'GET #index' do
|
||||||
context 'without conference scope' do
|
context 'without conference scope' do
|
||||||
it 'returns all tracks' do
|
it 'returns all tracks' do
|
||||||
|
|
||||||
get :index, format: :json
|
get :index, format: :json
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)['tracks']
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
||||||
|
|
@ -24,7 +24,7 @@ describe Api::V1::TracksController do
|
||||||
it 'returns all rooms of conference' do
|
it 'returns all rooms of conference' do
|
||||||
|
|
||||||
get :index, conference_id: conference.short_title, format: :json
|
get :index, conference_id: conference.short_title, format: :json
|
||||||
json = JSON.parse(response.body)
|
json = JSON.parse(response.body)['tracks']
|
||||||
|
|
||||||
expect(response).to be_success
|
expect(response).to be_success
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue