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
2 changes: 1 addition & 1 deletion app/controllers/staff/program_sessions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def new
def create
@program_session = current_event.program_sessions.build(program_session_params)
authorize @program_session
@program_session.state = ProgramSession::DRAFT
@program_session.state = :draft
@program_session.speakers.each { |speaker| speaker.event_id = current_event.id }
if @program_session.save
redirect_to event_staff_program_session_path(current_event, @program_session)
Expand Down
28 changes: 11 additions & 17 deletions app/decorators/staff/program_session_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def state_label(large: false, state: nil)
classes = "label #{state_class(state)}"
classes += ' label-large' if large

h.content_tag :span, state, class: classes
h.content_tag :span, object.state_before_type_cast, class: classes
end

def confirmation_notes_link
Expand All @@ -19,23 +19,17 @@ def confirmation_notes_link
end
end

STATE_CLASSES = {
live: 'label-success',
draft: 'label-default',
unconfirmed_accepted: 'label-info',
unconfirmed_waitlisted: 'label-warning',
confirmed_waitlisted: 'label-warning',
declined: 'label-danger'
}.with_indifferent_access

def state_class(state)
case state
when ProgramSession::LIVE
'label-success'
when ProgramSession::DRAFT
'label-default'
when ProgramSession::UNCONFIRMED_ACCEPTED
'label-info'
when ProgramSession::UNCONFIRMED_WAITLISTED
'label-warning'
when ProgramSession::CONFIRMED_WAITLISTED
'label-warning'
when ProgramSession::DECLINED
'label-danger'
else
'label-default'
end
STATE_CLASSES[state] || 'label-default'
end

def track_name
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/program_session_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module ProgramSessionHelper
def session_states_collection
ProgramSession::STATES.map { |state| [state.titleize, state] }
ProgramSession.states.values.map { |state| [state.titleize, state] }
end

def speakers_emails(session)
Expand Down
76 changes: 29 additions & 47 deletions app/models/program_session.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,32 @@
class ProgramSession < ApplicationRecord
LIVE = 'live' # confirmed accepted
DRAFT = 'draft' # created by organizer, not ready to be published (live)
UNCONFIRMED_ACCEPTED = 'unconfirmed accepted' # accepted, to be confirmed by speaker
UNCONFIRMED_WAITLISTED = 'unconfirmed waitlisted'
CONFIRMED_WAITLISTED = 'confirmed waitlisted'
DECLINED = 'declined'

STATES = [
LIVE,
DRAFT,
UNCONFIRMED_ACCEPTED,
UNCONFIRMED_WAITLISTED,
CONFIRMED_WAITLISTED,
DECLINED
]
enum :state, {
live: 'live',
draft: 'draft',
unconfirmed_accepted: 'unconfirmed accepted',
unconfirmed_waitlisted: 'unconfirmed waitlisted',
confirmed_waitlisted: 'confirmed waitlisted',
declined: 'declined'
}, default: :draft

STATE_GROUPS = {
LIVE => "program",
DRAFT => "program",
UNCONFIRMED_ACCEPTED => "program",
UNCONFIRMED_WAITLISTED => "waitlist",
CONFIRMED_WAITLISTED => "waitlist",
DECLINED => "declined"
}
live: 'program',
draft: 'program',
unconfirmed_accepted: 'program',
unconfirmed_waitlisted: 'waitlist',
confirmed_waitlisted: 'waitlist',
declined: 'declined'
}.with_indifferent_access

PROMOTIONS = {
DRAFT => LIVE,
UNCONFIRMED_WAITLISTED => UNCONFIRMED_ACCEPTED,
CONFIRMED_WAITLISTED => LIVE
}
draft: :live,
unconfirmed_waitlisted: :unconfirmed_accepted,
confirmed_waitlisted: :live
}.with_indifferent_access

CONFIRMATIONS = {
UNCONFIRMED_WAITLISTED => CONFIRMED_WAITLISTED,
UNCONFIRMED_ACCEPTED => LIVE
}
unconfirmed_waitlisted: :confirmed_waitlisted,
unconfirmed_accepted: :live
}.with_indifferent_access

belongs_to :event
belongs_to :proposal, optional: true
Expand All @@ -47,21 +40,14 @@ class ProgramSession < ApplicationRecord

validates :event, :session_format, :title, :state, presence: true

validates_inclusion_of :state, in: STATES

serialize :info, type: Hash, coder: YAML

after_destroy :destroy_speakers

scope :unscheduled, -> do
where(state: LIVE).where.not(id: TimeSlot.pluck(:program_session_id))
end
scope :sorted_by_title, -> { order(:title)}
scope :live, -> { where(state: LIVE) }
scope :draft, -> { where(state: DRAFT) }
scope :waitlisted, -> { where(state: [CONFIRMED_WAITLISTED, UNCONFIRMED_WAITLISTED]) }
scope :program, -> { where(state: [LIVE, DRAFT, UNCONFIRMED_ACCEPTED]) }
scope :declined, -> { where(state: DECLINED) }
scope :unscheduled, -> { live.where.not(id: TimeSlot.pluck(:program_session_id)) }
scope :sorted_by_title, -> { order(:title) }
scope :waitlisted, -> { where(state: [:confirmed_waitlisted, :unconfirmed_waitlisted]) }
scope :program, -> { where(state: [:live, :draft, :unconfirmed_accepted]) }
scope :without_proposal, -> { where(proposal: nil) }
scope :in_track, ->(track) do
track = nil if track.try(:strip).blank?
Expand All @@ -81,7 +67,7 @@ def self.create_from_proposal(proposal)
abstract: proposal.abstract,
track_id: proposal.track_id,
session_format_id: proposal.session_format_id,
state: proposal.waitlisted? ? UNCONFIRMED_WAITLISTED : UNCONFIRMED_ACCEPTED
state: proposal.waitlisted? ? :unconfirmed_waitlisted : :unconfirmed_accepted
)

#attach proposal speakers to new program session
Expand All @@ -97,15 +83,15 @@ def self.create_from_proposal(proposal)
end

def can_confirm?
CONFIRMATIONS.keys.include?(state)
CONFIRMATIONS.key?(state)
end

def confirm
update(state: CONFIRMATIONS[state]) if can_confirm?
end

def can_promote?
PROMOTIONS.keys.include?(state)
PROMOTIONS.key?(state)
end

def promote
Expand All @@ -115,10 +101,6 @@ def promote
update(state: PROMOTIONS[state])
end

def live?
state == LIVE
end

def multiple_speakers?
speakers.count > 1
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/proposal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def promote

def decline
update(state: WITHDRAWN, confirmed_at: Time.current)
program_session.update(state: ProgramSession::DECLINED)
program_session.update(state: :declined)
end

def draft?
Expand Down
8 changes: 4 additions & 4 deletions db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ def create_seed_data
program_session_1 = seed_event.program_sessions.where(
event: seed_event,
proposal: accepted_proposal_1,
state: ProgramSession::LIVE,
state: :live,
title: accepted_proposal_1.title,
abstract: accepted_proposal_1.abstract,
track: accepted_proposal_1.track,
Expand All @@ -349,7 +349,7 @@ def create_seed_data
program_session_2 = seed_event.program_sessions.where(
event: seed_event,
proposal: accepted_proposal_2,
state: ProgramSession::LIVE,
state: :live,
title: accepted_proposal_2.title,
abstract: accepted_proposal_2.abstract,
track: accepted_proposal_2.track,
Expand All @@ -358,7 +358,7 @@ def create_seed_data

program_session_3 = seed_event.program_sessions.where(
event: seed_event,
state: ProgramSession::LIVE,
state: :live,
title: "Keynote Session",
abstract: "The keynote session will kick off the conference for all attendees.",
session_format: internal_session
Expand Down Expand Up @@ -510,7 +510,7 @@ def create_seed_data

program_session = schedule_event.program_sessions.create!({
proposal: accepted_proposal,
state: ProgramSession::LIVE,
state: :live,
title: accepted_proposal.title,
abstract: accepted_proposal.abstract,
track: accepted_proposal.track,
Expand Down
2 changes: 1 addition & 1 deletion spec/controllers/staff/proposals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
it "creates a draft program session" do
proposal = create(:proposal_with_track, event: event, state: Proposal::State::SOFT_ACCEPTED)
post :finalize, params: {event_slug: event, proposal_uuid: proposal.uuid}
expect(proposal.program_session.state).to eq(ProgramSession::UNCONFIRMED_ACCEPTED)
expect(proposal.program_session).to be_unconfirmed_accepted
end

it "sends appropriate emails" do
Expand Down
2 changes: 1 addition & 1 deletion spec/factories/program_sessions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
factory :program_session do
sequence(:title) { |i| "Default Session #{i}" }
abstract { "Just some abstract" }
state { ProgramSession::LIVE }
state { :live }
session_format
event

Expand Down
24 changes: 12 additions & 12 deletions spec/models/program_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@
end

it "creates a program session that is a draft" do
expect(session.state).to eq("unconfirmed accepted")
expect(session).to be_unconfirmed_accepted
end

it "creates a program session that is waitlisted" do
waitlisted_session = ProgramSession.create_from_proposal(waitlisted_proposal)
expect(waitlisted_session.state).to eq("unconfirmed waitlisted")
expect(waitlisted_session).to be_unconfirmed_waitlisted
end

it "sets program session id for all speakers" do
Expand Down Expand Up @@ -168,24 +168,24 @@

describe "#promote" do
it "promotes a draft to accepted_confirmed" do
ps = create(:program_session, state: "draft", proposal: proposal, track: proposal.track)
ps = create(:program_session, state: :draft, proposal: proposal, track: proposal.track)
ps.promote

expect(ps.reload.state).to eq("live")
expect(ps.reload).to be_live
end

it "promotes an unconfirmed waitlisted to unconfirmed_accepted" do
ps = create(:program_session, state: "unconfirmed waitlisted", proposal: proposal, track: proposal.track)
ps = create(:program_session, state: :unconfirmed_waitlisted, proposal: proposal, track: proposal.track)
ps.promote

expect(ps.reload.state).to eq("unconfirmed accepted")
expect(ps.reload).to be_unconfirmed_accepted
end

it "promotes a confirmed_waitlisted to live" do
ps = create(:program_session, state: "confirmed waitlisted", proposal: proposal, track: proposal.track)
ps = create(:program_session, state: :confirmed_waitlisted, proposal: proposal, track: proposal.track)
ps.promote

expect(ps.reload.state).to eq("live")
expect(ps.reload).to be_live
end

it "promotes it's proposal" do
Expand Down Expand Up @@ -220,19 +220,19 @@

describe "#confirm" do
it "confirms an unconfirmed_waitlisted session" do
ps = create(:program_session, state: "unconfirmed waitlisted", proposal: proposal, track: proposal.track)
ps = create(:program_session, state: :unconfirmed_waitlisted, proposal: proposal, track: proposal.track)

ps.confirm

expect(ps.reload.state).to eq("confirmed waitlisted")
expect(ps.reload).to be_confirmed_waitlisted
end

it "confirms an unconfirmed_accepted session" do
ps = create(:program_session, state: "unconfirmed accepted", proposal: proposal, track: proposal.track)
ps = create(:program_session, state: :unconfirmed_accepted, proposal: proposal, track: proposal.track)

ps.confirm

expect(ps.reload.state).to eq("live")
expect(ps.reload).to be_live
end
end

Expand Down
4 changes: 2 additions & 2 deletions spec/models/proposal_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@
prop.finalize
end

expect(waitlisted_proposal.reload.program_session.state).to eq('unconfirmed waitlisted')
expect(accepted_proposal.reload.program_session.state).to eq('unconfirmed accepted')
expect(waitlisted_proposal.reload.program_session).to be_unconfirmed_waitlisted
expect(accepted_proposal.reload.program_session).to be_unconfirmed_accepted
expect(rejected_proposal.reload.program_session).to be_nil
expect(submitted_proposal.reload.program_session).to be_nil
end
Expand Down
Loading