Merge pull request #1038 from differentreality/xml_export

XML export
This commit is contained in:
Henne Vogelsang 2016-06-20 15:01:12 +02:00 committed by GitHub
commit b1b8703753
5 changed files with 77 additions and 1 deletions

View file

@ -14,6 +14,7 @@ class ConferenceController < ApplicationController
def schedule
@rooms = @conference.venue.rooms if @conference.venue
@events = @conference.program.events
@events_xml = @events.scheduled.group_by{ |event| event.start_time.to_date }
@dates = @conference.start_date..@conference.end_date
if @dates == Date.current

View file

@ -1,4 +1,14 @@
module ApplicationHelper
##
# Gets an EventType object, and returns its length in timestamp format (HH:MM)
# ====Gets
# * +Integer+ -> 30
# ====Returns
# * +String+ -> "00:30"
def length_timestamp(length)
[length / 60, length % 60].map { |t| t.to_s.rjust(2, '0') }.join(':')
end
##
# ====Returns
# * +String+ -> number of registrations / max allowed registrations

View file

@ -0,0 +1,35 @@
%schedule
%version= @conference.revision
%conference
%acronym= @conference.short_title
%title= @conference.title
%start= @conference.start_date
%end= @conference.end_date
%days= (@conference.end_date - @conference.start_date).to_i + 1
%timeslot_duration= length_timestamp(EventType::LENGTH_STEP)
- if @events_xml.any?
- @events_xml.keys.each.with_index(1) do |day, index|
%day{ date: day, index: index }
- events_in_rooms = @events_xml[day].group_by(&:room)
- events_in_rooms.keys.each do |room|
%room{ name: room.name }
- events_in_rooms[room].each do |event|
%event{ guid: event.guid, id: event.id }
%date= event.start_time.iso8601
%start= event.start_time.strftime('%H:%M')
%duration= length_timestamp(event.event_type.length)
%room= event.room.name
%type= event.event_type.name
%language= ISO_639.find_by_english_name(event.language).third if event.language
%slug= "#{event.id} #{event.title}".parameterize
%title= event.title
%subtitle= event.subtitle
%track= event.track.name if event.track
%abstract= event.abstract
%recording
%license/
%optout=false #FIXME
%persons
- event.speakers.uniq.each do |speaker|
%person{ id: speaker.id }= speaker.name

View file

@ -1,7 +1,7 @@
require 'spec_helper'
describe ConferenceController do
let(:conference) { create(:conference, splashpage: create(:splashpage, public: true)) }
let(:conference) { create(:full_conference, splashpage: create(:splashpage, public: true)) }
describe 'GET #index' do
it 'Response code is 200' do
@ -24,6 +24,29 @@ describe ConferenceController do
end
end
describe 'GET #schedule' do
context 'XML' do
before :each do
conference.program.schedule_public = true
conference.program.save!
create(:event_scheduled, program: conference.program)
create(:event_scheduled, program: conference.program)
get :schedule, id: conference.short_title, format: :xml
end
it 'assigns variables' do
expect(assigns(:conference)).to eq conference
expect(assigns(:events_xml)).to eq conference.program.events.scheduled.
group_by{ |event| event.start_time.to_date }
end
it 'renders successfully' do
expect(response).to be_success
end
end
end
describe 'OPTIONS #index' do
it 'Response code is 200' do
process :index, 'OPTIONS'

View file

@ -29,6 +29,13 @@ FactoryGirl.define do
event.room = build(:room, venue: venue)
event.comment_threads << build(:comment, commentable: event)
end
factory :event_scheduled do
after(:build) do |event|
event.state = 'confirmed'
event.start_time = event.program.conference.start_date.to_time
end
end
end
end
end