event: refactor as_json method and add a test
This commit is contained in:
parent
80f8bba951
commit
82edf7870a
2 changed files with 26 additions and 17 deletions
|
|
@ -99,23 +99,9 @@ class Event < ActiveRecord::Base
|
|||
def as_json(options)
|
||||
json = super(options)
|
||||
|
||||
if room.nil?
|
||||
json[:room_guid] = nil
|
||||
else
|
||||
json[:room_guid] = room.guid
|
||||
end
|
||||
|
||||
if track.nil?
|
||||
json[:track_color] = '#ffffff'
|
||||
else
|
||||
json[:track_color] = track.color
|
||||
end
|
||||
|
||||
if event_type.nil?
|
||||
json[:length] = 25
|
||||
else
|
||||
json[:length] = event_type.length
|
||||
end
|
||||
json[:room_guid] = room.try(:guid)
|
||||
json[:track_color] = track.try(:color) || '#ffffff'
|
||||
json[:length] = event_type.try(:length) || 25
|
||||
|
||||
json
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue