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/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def update

def open_cfp
authorize_update
if @event.update(state: Event::STATUSES[:open])
if @event.update(state: :open)
flash[:info] = "Your CFP was successfully opened."
else
flash['danger alert-confirm'] = "There was a problem opening your CFP: #{@event.errors.full_messages.to_sentence}"
Expand Down
28 changes: 9 additions & 19 deletions app/models/event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Event < ApplicationRecord
attribute :state, :string, default: 'draft'
enum :state, {draft: 'draft', open: 'open', closed: 'closed'}, default: :draft

has_many :teammates, dependent: :destroy
has_many :staff, through: :teammates, source: :user
Expand Down Expand Up @@ -30,8 +30,7 @@ class Event < ApplicationRecord
store_accessor :speaker_notification_emails, :waitlist

scope :a_to_z, -> { order('name ASC') }
scope :live, -> { where("state = 'open' and (closes_at is null or closes_at > ?)", Time.current) }
scope :not_draft, -> { where "state != 'draft'"}
scope :live, -> { open.where('closes_at is null or closes_at > ?', Time.current) }

validates :name, presence: true
validates :slug, presence: true, uniqueness: true
Expand All @@ -40,16 +39,11 @@ class Event < ApplicationRecord
before_validation :generate_slug
before_save :update_closes_at_if_manually_closed

STATUSES = { draft: 'draft',
open: 'open',
closed: 'closed' }

def to_param
slug
end

validate :checklist_complete?, on: :update,
if: Proc.new { |e| e.state == STATUSES[:open] }
validate :checklist_complete?, on: :update, if: -> { state == Event.states[:open] }

def initialize_speaker_emails
SpeakerEmailTemplate::TYPES.each do |type|
Expand Down Expand Up @@ -120,29 +114,25 @@ def to_s
name
end

def draft?
state == STATUSES[:draft]
end

def open?
state == STATUSES[:open] && (closes_at.nil? || closes_at > Time.current)
state == Event.states[:open] && (closes_at.nil? || closes_at > Time.current)
end

def closed?
!open? && !draft?
end

def past_open?
state == STATUSES[:open] && closes_at < Time.current
state == Event.states[:open] && closes_at < Time.current
end

def status
if open?
STATUSES[:open]
Event.states[:open]
elsif draft?
STATUSES[:draft]
Event.states[:draft]
else
STATUSES[:closed]
Event.states[:closed]
end
end

Expand Down Expand Up @@ -231,7 +221,7 @@ def mention_names
private

def update_closes_at_if_manually_closed
if changes.key?(:state) && changes[:state] == [STATUSES[:open], STATUSES[:closed]]
if changes.key?(:state) && changes[:state] == [Event.states[:open], Event.states[:closed]]
self.closes_at = Time.current
end
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/staff/events/info.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
= link_to "Change Status", '#', class: "btn btn-primary", data: {action: 'click->status-toggle#show'}
.status-dropdown.float-end{data: {status_toggle_target: 'dropdown'}}
= form_for(event, url: update_status_event_staff_path(event)) do |f|
= f.select(:state, options_for_select(Event::STATUSES.values, f.object.state))
= f.select(:state, options_for_select(Event.states.keys, f.object.state))
= link_to "Cancel", '#', class: "btn btn-danger", data: {action: 'click->status-toggle#hide'}
= f.submit "Update Status", class: "btn btn-success"
%h1 Event Info
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/event_stats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

context 'closed event' do
before { event.update(state: Event::STATUSES[:closed]) }
before { event.update(state: :closed) }

it 'includes no track stats' do
expect(subject.program).to have_key Track::NO_TRACK
Expand Down
2 changes: 1 addition & 1 deletion spec/support/shared_examples/an_open_event.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
RSpec.shared_examples_for 'an open event' do
let(:event) { create :event, name: 'Best Event', state: Event::STATUSES[:open] }
let(:event) { create :event, name: 'Best Event', state: :open }

let(:withdrawn) { Proposal::State::WITHDRAWN }
let(:accepted) { Proposal::State::ACCEPTED }
Expand Down