Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions app/controllers/admin/talks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,18 @@ def update_talks

def start_on_air
@talk = Talk.find(params[:talk][:id])
on_air_talks_of_other_days = @talk.track.talks.includes([:conference_day, :video]).accepted_and_intermission.reject { |t| t.conference_day.id == @talk.conference_day.id }.select { |t| t.video.on_air? }
on_air_talks_of_other_days = @talk.track.talks
.includes([:conference_day, :video])
.accepted_and_intermission
.where.not(conference_days: { id: @talk.conference_day.id })
.joins(:video)
.where(videos: { on_air: true })


if on_air_talks_of_other_days.size.positive?
@talks = @conference.talks.accepted_and_intermission.order('conference_day_id ASC, start_time ASC, track_id ASC')
flash.now.alert = "Talk id=#{on_air_talks_of_other_days.map(&:id).join(',')} are already on_air."
render(:index, status: :unprocessable_entity)
flash.now.alert = "別日(#{on_air_talks_of_other_days.map(&:conference_day).map(&:date).join(',')})にオンエアのセッションが残っています: #{on_air_talks_of_other_days.map(&:id).join(',')}"
else
@current_on_air_videos = Video.includes(talk: :conference).where(talks: { conference_id: conference.id }, on_air: true)
@current_on_air_videos = @talk.track.talks.includes([:track, :video, :speakers, :conference_day]).where.not(id: @talk.id).map(&:video)
ActiveRecord::Base.transaction do
# Disable onair of all talks that are onair
@current_on_air_videos.each do |video|
Expand Down
54 changes: 44 additions & 10 deletions spec/requests/admin/talks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@
describe Admin::SpeakersController, type: :request do
subject(:session) { { userinfo: { info: { email: 'alice@example.com', extra: { sub: 'alice' } }, extra: { raw_info: { sub: 'alice', 'https://cloudnativedays.jp/roles' => roles } } } } }
let(:roles) { [] }

before do
create(:cndt2020)
end
let!(:event) { create(:cndt2020) }

describe 'GET :event/admin/talks#index' do
context "user doesn't logged in" do
Expand Down Expand Up @@ -100,10 +97,10 @@

it 'can not to change to start on air' do
post admin_start_on_air_path(event: 'cndt2020'), params: { talk: { id: talk2.id } }.to_json, headers: { "Content-Type": 'application/json' }, as: :turbo_stream
expect(response).to_not(be_successful)
expect(response).to(have_http_status('422'))
expect(response).to(be_successful)
expect(response).to(have_http_status('200'))
expect(Video.find(talk2.video.id).on_air).to(be_falsey)
expect(flash.now[:alert]).to(include("Talk id=#{talk1.id} are already on_air."))
expect(flash.now[:alert]).to(include("別日(#{event.conference_days[0].date})にオンエアのセッションが残っています: #{talk1.id}"))
end
end
end
Expand All @@ -130,12 +127,49 @@

it 'can not to change to start on air' do
post admin_start_on_air_path(event: 'cndt2020'), params: { talk: { id: intermission2.id } }.to_json, headers: { "Content-Type": 'application/json' }, as: :turbo_stream
expect(response).to_not(be_successful)
expect(response).to(have_http_status('422'))
expect(response).to(be_successful)
expect(response).to(have_http_status('200'))
expect(Video.find(intermission2.video.id).on_air).to(be_falsey)
expect(flash[:alert]).to(include("Talk id=#{intermission1.id} are already on_air."))
expect(flash.now[:alert]).to(include("別日(#{event.conference_days[0].date})にオンエアのセッションが残っています: #{intermission1.id}"))
end
end
end
end

describe 'POST :event/admin/talks#start_on_air with different tracks' do
let(:roles) { ['CNDT2020-Admin'] }

before do
ActionDispatch::Request::Session.define_method(:original, ActionDispatch::Request::Session.instance_method(:[]))
allow_any_instance_of(ActionDispatch::Request::Session).to(receive(:[]) do |*arg|
if arg[1] == :userinfo
session[:userinfo]
else
arg[0].send(:original, arg[1])
end
end)
end

describe 'when sessions exist in different tracks' do
let!(:talk_track1) { create(:talk1, :accepted, track_id: 1, conference_day_id: 1) }
let!(:talk_track2) { create(:talk2, :accepted, track_id: 2, conference_day_id: 1) }
let!(:video_track1) { create(:video, talk: talk_track1, on_air: true) }
let!(:video_track2) { create(:video, talk: talk_track2, on_air: false) }

it 'does not affect on_air status of sessions in other tracks' do
# Start on_air for talk in track 2
post admin_start_on_air_path(event: 'cndt2020'), params: { talk: { id: talk_track2.id } }.to_json, headers: { "Content-Type": 'application/json' }, as: :turbo_stream

# Verify response
expect(response).to(be_successful)
expect(response).to(have_http_status('200'))

# Verify that talk in track 1 is still on_air
expect(Video.find(talk_track1.video.id).on_air).to(be_truthy)

# Verify that talk in track 2 is now on_air
expect(Video.find(talk_track2.video.id).on_air).to(be_truthy)
end
end
end
end
Loading