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: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ gem 'omniauth-github'
gem 'omniauth-twitter'
gem "omniauth-rails_csrf_protection", "~> 2.0"

gem 'stateful_enum'

gem 'actionview-encoded_mail_to'
gem 'active_model_serializers', '~> 0.10.16'
gem 'bootsnap', '~> 1.20', require: false
Expand Down
2 changes: 2 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,7 @@ GEM
snaky_hash (2.0.1)
hashie
version_gem (~> 1.1, >= 1.1.1)
stateful_enum (0.7.0)
stringio (3.2.0)
temple (0.10.4)
thor (1.4.0)
Expand Down Expand Up @@ -508,6 +509,7 @@ DEPENDENCIES
sendgrid-ruby
sidekiq
simple_form
stateful_enum
turbo-rails

RUBY VERSION
Expand Down
9 changes: 1 addition & 8 deletions app/models/invitation.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
class Invitation < ApplicationRecord
enum :state, {pending: 'pending', accepted: 'accepted', declined: 'declined'}
enum :state, {pending: 'pending', accepted: 'accepted', declined: 'declined'}, default: :pending

belongs_to :proposal
belongs_to :user, optional: true

scope :not_accepted, -> { where(state: [:pending, :declined]) }

before_create :set_default_state
before_create :set_slug

validates :email, presence: true
Expand All @@ -30,10 +27,6 @@ def decline
def set_slug
self.slug = Digest::SHA1.hexdigest([email, rand(1000)].map(&:to_s).join('-'))[0, 10]
end

def set_default_state
self.state = :pending if state.nil?
end
end

# == Schema Information
Expand Down
46 changes: 16 additions & 30 deletions app/models/program_session.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,22 @@ class ProgramSession < ApplicationRecord
unconfirmed_waitlisted: 'unconfirmed waitlisted',
confirmed_waitlisted: 'confirmed waitlisted',
declined: 'declined'
}, default: :draft
}, default: :draft do
event :confirm do
transition :unconfirmed_waitlisted => :confirmed_waitlisted
transition :unconfirmed_accepted => :live
end

event :promote do
before do
proposal.promote if proposal
end

transition :draft => :live
transition :unconfirmed_waitlisted => :unconfirmed_accepted
transition :confirmed_waitlisted => :live
end
end

STATE_GROUPS = {
live: 'program',
Expand All @@ -17,16 +32,6 @@ class ProgramSession < ApplicationRecord
declined: 'declined'
}.with_indifferent_access

PROMOTIONS = {
draft: :live,
unconfirmed_waitlisted: :unconfirmed_accepted,
confirmed_waitlisted: :live
}.with_indifferent_access

CONFIRMATIONS = {
unconfirmed_waitlisted: :confirmed_waitlisted,
unconfirmed_accepted: :live
}.with_indifferent_access

belongs_to :event
belongs_to :proposal, optional: true
Expand Down Expand Up @@ -82,25 +87,6 @@ def self.create_from_proposal(proposal)
end
end

def can_confirm?
CONFIRMATIONS.key?(state)
end

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

def can_promote?
PROMOTIONS.key?(state)
end

def promote
if proposal.present?
proposal.promote
end
update(state: PROMOTIONS[state])
end

def multiple_speakers?
speakers.count > 1
end
Expand Down
3 changes: 1 addition & 2 deletions spec/models/program_session_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,7 @@
end

it "promotes it's proposal" do
ps = create(:program_session, proposal: proposal, track: proposal.track)
proposal = create(:proposal_with_track, program_session: ps)
ps = create(:program_session, state: :draft, proposal: proposal, track: proposal.track)

expect(proposal).to receive(:promote)
ps.promote
Expand Down