mirror of
https://github.com/openSUSE/osem.git
synced 2026-02-01 09:41:10 -05:00
Use JSON date serializer
Effective API changes:
- nil serializes to null, not empty string
- dates serialize to IETF RFC 3339 with millisecond precision, not
second precision surrounded by spaces
This commit is contained in:
@@ -3,12 +3,8 @@
|
||||
class EventScheduleSerializer < ActiveModel::Serializer
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
attributes :date, :room
|
||||
|
||||
def date
|
||||
t = object.start_time
|
||||
t.blank? ? '' : %( #{I18n.l t, format: :short}#{t.formatted_offset(false)} )
|
||||
end
|
||||
attribute :start_time, key: :date
|
||||
attributes :room
|
||||
|
||||
def room
|
||||
object.room.guid
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
class EventSerializer < ActiveModel::Serializer
|
||||
include ActionView::Helpers::TextHelper
|
||||
|
||||
attributes :guid, :title, :length, :scheduled_date, :language, :abstract, :speaker_ids, :type, :room, :track
|
||||
|
||||
def scheduled_date
|
||||
t = object.time
|
||||
t.blank? ? '' : %( #{I18n.l t, format: :short}#{t.formatted_offset(false)} )
|
||||
end
|
||||
attributes :guid, :title, :length
|
||||
attribute :time, key: :scheduled_date
|
||||
attributes :language, :abstract, :speaker_ids, :type, :room, :track
|
||||
|
||||
def speaker_ids
|
||||
speakers = object.event_users.select { |i| i.event_role == 'speaker' }
|
||||
|
||||
@@ -12,7 +12,7 @@ describe EventScheduleSerializer, type: :serializer do
|
||||
|
||||
it 'sets date and room' do
|
||||
expected_json = {
|
||||
date: ' 2000-01-02T03:04:05+0000 ',
|
||||
date: '2000-01-02T03:04:05.000Z',
|
||||
room: event_schedule.room.guid
|
||||
}.to_json
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ describe EventSerializer, type: :serializer do
|
||||
guid: event.guid,
|
||||
title: 'Some Talk',
|
||||
length: 30,
|
||||
scheduled_date: '',
|
||||
scheduled_date: nil,
|
||||
language: nil,
|
||||
abstract: 'Lorem ipsum dolor sit amet',
|
||||
speaker_ids: event.speaker_ids,
|
||||
@@ -41,7 +41,7 @@ describe EventSerializer, type: :serializer do
|
||||
guid: event.guid,
|
||||
title: 'Some Talk',
|
||||
length: 30,
|
||||
scheduled_date: ' 2014-03-04T09:00:00+0000 ',
|
||||
scheduled_date: '2014-03-04T09:00:00.000Z',
|
||||
language: 'English',
|
||||
abstract: 'Lorem ipsum dolor sit amet',
|
||||
speaker_ids: [speaker.id],
|
||||
|
||||
Reference in New Issue
Block a user