mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
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)
|
||||
rails-dom-testing (~> 1.0, >= 1.0.5)
|
||||
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
||||
active_model_serializers (0.8.1)
|
||||
activemodel (>= 3.0)
|
||||
active_model_serializers (0.9.4)
|
||||
activemodel (>= 3.2)
|
||||
activejob (4.2.5.2)
|
||||
activesupport (= 4.2.5.2)
|
||||
globalid (>= 0.3.0)
|
||||
|
|
|
|||
|
|
@ -4,47 +4,51 @@ class ConferenceSerializer < ActiveModel::Serializer
|
|||
:date_range, :revision
|
||||
|
||||
def difficulty_levels
|
||||
object.difficulty_levels.map do |difficulty_level| { id: difficulty_level.id,
|
||||
title: difficulty_level.title,
|
||||
description: difficulty_level.description
|
||||
object.program.difficulty_levels.map do |difficulty_level| { id: difficulty_level.id,
|
||||
title: difficulty_level.title,
|
||||
description: difficulty_level.description
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def event_types
|
||||
object.event_types.map do |event_type| { id: event_type.id,
|
||||
title: event_type.title,
|
||||
length: event_type.length,
|
||||
description: event_type.description
|
||||
object.program.event_types.map do |event_type| { id: event_type.id,
|
||||
title: event_type.title,
|
||||
length: event_type.length,
|
||||
description: event_type.description
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def rooms
|
||||
object.rooms.includes(:events).map do |room| { id: room.id,
|
||||
size: room.size,
|
||||
events: room.events.map do |event| { guid: event.title,
|
||||
title: event.title,
|
||||
subtitle: event.subtitle,
|
||||
abstract: event.abstract,
|
||||
description: event.description,
|
||||
is_highlight: event.is_highlight,
|
||||
require_registration: event.require_registration,
|
||||
start_time: event.start_time,
|
||||
event_type_id: event.event_type.id,
|
||||
difficulty_level_id: event.difficulty_level_id,
|
||||
track_id: event.track_id,
|
||||
speaker_names: event.speaker_names
|
||||
}
|
||||
end
|
||||
}
|
||||
if object.venue
|
||||
object.venue.rooms.includes(:events).map do |room| { id: room.id,
|
||||
size: room.size,
|
||||
events: room.events.map do |event| { guid: event.title,
|
||||
title: event.title,
|
||||
subtitle: event.subtitle,
|
||||
abstract: event.abstract,
|
||||
description: event.description,
|
||||
is_highlight: event.is_highlight,
|
||||
require_registration: event.require_registration,
|
||||
start_time: event.start_time,
|
||||
event_type_id: event.event_type.id,
|
||||
difficulty_level_id: event.difficulty_level_id,
|
||||
track_id: event.track_id,
|
||||
speaker_names: event.speaker_names
|
||||
}
|
||||
end
|
||||
}
|
||||
end
|
||||
else
|
||||
[]
|
||||
end
|
||||
end
|
||||
|
||||
def tracks
|
||||
object.tracks.map do |track| { 'id' => track.id,
|
||||
'name' => track.name,
|
||||
'description' => track.description
|
||||
object.program.tracks.map do |track| { 'id' => track.id,
|
||||
'name' => track.name,
|
||||
'description' => track.description
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ describe Api::V1::RoomsController do
|
|||
let!(:conference_room) { create(:room, name: 'Conference Room', venue: venue) }
|
||||
let!(:room) { create(:room, name: 'Test Room') }
|
||||
|
||||
context 'GET #index' do
|
||||
describe 'GET #index' do
|
||||
context 'without conference scope' do
|
||||
it 'returns all rooms' do
|
||||
|
||||
get :index, format: :json
|
||||
json = JSON.parse(response.body)
|
||||
json = JSON.parse(response.body)['rooms']
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
|
|
@ -25,7 +25,7 @@ describe Api::V1::RoomsController do
|
|||
it 'returns all rooms of conference' do
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
|
|
@ -5,12 +5,12 @@ describe Api::V1::TracksController do
|
|||
let!(:conference_track) { create(:track, name: 'Conference Track', program_id: conference.program.id) }
|
||||
let!(:track) { create(:track, name: 'Test Track') }
|
||||
|
||||
context 'GET #index' do
|
||||
describe 'GET #index' do
|
||||
context 'without conference scope' do
|
||||
it 'returns all tracks' do
|
||||
|
||||
get :index, format: :json
|
||||
json = JSON.parse(response.body)
|
||||
json = JSON.parse(response.body)['tracks']
|
||||
|
||||
expect(response).to be_success
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ describe Api::V1::TracksController do
|
|||
it 'returns all rooms of conference' do
|
||||
|
||||
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue