-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Events have the capacity for multiple years
- Event Model, which previously had all info about the event occurence, becomes EventInstance - a new Event model now contains event identity - event creation workflow happens thorugh the instance--an event should not exist unless we have a record of one of its instances - update specs for changed models and controllers - update feature specs to reflect new workflows - update factories - update related Submission model to communicate with EventInstance instead of Event
- Loading branch information
1 parent
c7dbbc7
commit 01ca04f
Showing
43 changed files
with
529 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
/tmp/* | ||
!/log/.keep | ||
!/tmp/.keep | ||
examples.txt | ||
|
||
# Ignore Byebug command history file. | ||
.byebug_history | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
class EventInstancesController < ApplicationController | ||
def new | ||
@event_instance = EventInstance.new | ||
end | ||
|
||
def create | ||
@event_instance = EventInstance.new(event_instance_params) | ||
if verify_recaptcha(model: @event_instance) && @event_instance.save | ||
redirect_to speakers_path | ||
else | ||
flash[:alert] = 'Failed to save event' | ||
redirect_to new_event_instance_path | ||
end | ||
end | ||
|
||
def show | ||
@event_instance = EventInstance.find(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def event_instance_params | ||
params.require(:event_instance).permit(:event_id, :new_parent_event_name, :year) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,10 @@ | ||
class EventsController < ApplicationController | ||
def new | ||
@event = Event.new | ||
end | ||
|
||
def create | ||
@event = Event.new(event_params) | ||
if verify_recaptcha(model: @event) && @event.save | ||
redirect_to speakers_path | ||
else | ||
flash[:alert] = 'Failed to save event' | ||
redirect_to new_event_path | ||
end | ||
end | ||
|
||
def index | ||
@events = Event.all.order('name ASC, year ASC') | ||
@events = Event.all.order('name ASC') | ||
end | ||
|
||
def show | ||
@event = Event.find(params[:id]) | ||
end | ||
|
||
private | ||
|
||
def event_params | ||
params.require(:event).permit(:name, :year) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,8 @@ | ||
class Event < ApplicationRecord | ||
validates_presence_of :name | ||
validates_presence_of :year | ||
validates_numericality_of :year, only_integer: true | ||
validates_uniqueness_of :name, scope: :year | ||
validates :name, presence: true, uniqueness: { case_insensitive: true } | ||
|
||
has_many :submissions | ||
|
||
def name_and_year | ||
"#{name} #{year}" | ||
end | ||
has_many :instances, foreign_key: :event_id, | ||
class_name: 'EventInstance', | ||
dependent: :destroy | ||
has_many :submissions, through: :instances | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
class EventInstance < ApplicationRecord | ||
# Virtual attribute for the parent event's name in case it is new | ||
attr_accessor :new_parent_event_name | ||
|
||
belongs_to :event | ||
has_many :submissions | ||
|
||
default_scope { order :year } | ||
|
||
before_validation :set_parent_event | ||
|
||
validates :event, presence: true | ||
validates :year, uniqueness: { scope: :event, message: 'should happen once per year' }, | ||
numericality: { only_integer: true } | ||
|
||
def name_and_year | ||
"#{event.name} #{year}" | ||
end | ||
|
||
private | ||
|
||
def set_parent_event | ||
if received_bad_event_params | ||
errors.add(:base, 'choose either an existing event or to create a new one') | ||
else | ||
event || create_event!(name: new_parent_event_name) | ||
end | ||
end | ||
|
||
def received_bad_event_params | ||
received_both_new_and_existing_events || received_neither_new_nor_existing_events | ||
end | ||
|
||
def received_both_new_and_existing_events | ||
event && new_parent_event_name.present? | ||
end | ||
|
||
def received_neither_new_nor_existing_events | ||
event.nil? && new_parent_event_name.blank? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<h3>Add an event</h3> | ||
|
||
<%= form_for @event_instance do |f| %> | ||
|
||
<div class="row"> | ||
<fieldset class="fieldset"> | ||
<legend>Event</legend> | ||
<%= f.label :event, "Choose an existing event" %> | ||
<%= f.collection_select(:event_id, Event.all, :id, :name, prompt: "Add year to an existing event") %> | ||
|
||
<p>— or —</p> | ||
|
||
<%= f.label :new_parent_event_name, 'Name a new event' %> | ||
<%= f.text_field :new_parent_event_name %> | ||
</fieldset> | ||
</div> | ||
|
||
<div class="row"> | ||
<%= f.label :year %> | ||
<%= f.text_field :year %> | ||
</div> | ||
|
||
<div class="row"> | ||
<%= recaptcha_tags %> | ||
</div> | ||
|
||
<div class="row"> | ||
<%= f.submit 'Add event' %> | ||
</div> | ||
<% end %> | ||
|
||
<p><%= link_to 'Back to Speaker Directory', speakers_path %></p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<h3><%= link_to @event_instance.event.name, @event_instance.event %> <%= @event_instance.year %></h3> | ||
|
||
<h5>Proposals</h5> | ||
<%= render partial: 'shared/instance_submissions', locals: { instance: @event_instance } %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
<h3>Conferences</h3> | ||
|
||
<% @events.each do |event| %> | ||
<p><%= link_to event.name_and_year, event %></p> | ||
<p><%= link_to event.name, event %></p> | ||
<% end %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
<h3><%= @event.name_and_year %></h3> | ||
<h3><%= @event.name %></h3> | ||
|
||
<h5>Proposals</h5> | ||
<% @event.submissions.each do |submission| %> | ||
<p> | ||
<%= link_to submission.proposal.title, submission.proposal %> - | ||
<%= link_to submission.proposal.speaker.name, submission.proposal.speaker %> - | ||
<%= submission.result.capitalize %> | ||
</p> | ||
|
||
<%-# Output instances, with the most recent first -%> | ||
<% instances = @event.instances.sort_by { |i| -i.year } %> | ||
<% instances.each do |instance| %> | ||
<div id="<%= @event.name.parameterize %>-<%= instance.year %>"> | ||
<h6><%= instance.year %></h6> | ||
<%= render partial: 'shared/instance_submissions', locals: { instance: instance } %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%-# Sort submissions by title before sorting by result -%> | ||
<% submissions = instance.submissions.sort_by { |s| s.proposal.title } %> | ||
<% submissions.sort_by(&:result).each do |submission| %> | ||
<p> | ||
<%= link_to submission.proposal.title, submission.proposal %> - | ||
<%= link_to submission.proposal.speaker.name, submission.proposal.speaker %> - | ||
<%= submission.result.capitalize %> | ||
</p> | ||
<% end %> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.