Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#74 Add Handle to Events #94

Merged
merged 9 commits into from
Oct 17, 2021
2 changes: 1 addition & 1 deletion app/controllers/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,6 @@ def set_event

# Only allow a list of trusted parameters through.
def event_params
params.require(:event).permit(:name, :description, :start_at, :end_at)
params.require(:event).permit(:name, :handle, :description, :start_at, :end_at)
end
end
3 changes: 3 additions & 0 deletions app/models/event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ class Event < ApplicationRecord
has_many :attendees, through: :event_attendees, source: :profile

validates :start_at, :end_at, presence: true
validates :handle, presence: true,
format: { with: /\A[a-zA-Z0-9]+\z/, message: "Only letters and numbers are allowed" },
yagosansz marked this conversation as resolved.
Show resolved Hide resolved
uniqueness: { case_sensitive: true }

scope :ongoing_or_upcoming, -> { where("end_at >= ?", Time.zone.now) }

Expand Down
1 change: 1 addition & 0 deletions app/views/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<%= render "layouts/errors", resource: @event %>

<%= form.labelled_text_field :name %>
<%= form.labelled_text_field :handle %>
<%= form.labelled_text_area :description %>
<div class="field">
<label class="label">Date</label>
Expand Down
10 changes: 10 additions & 0 deletions db/migrate/20211017005416_add_index_to_events.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

# Add a handle column to events table.
# Add index and unique to handle attribute in the events table.
class AddIndexToEvents < ActiveRecord::Migration[6.1]
def change
add_column :events, :handle, :string
add_index :events, :handle, unique: true
end
end
4 changes: 3 additions & 1 deletion db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions spec/factories/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
FactoryBot.define do
factory :event do
name { "RubyConf" }
sequence(:handle) { |n| "RubyConf#{n}" }
description { "[RubyConf 2020](https://rubyconf.org/) will be held in `Denver`." }
start_at { "2021-11-08 00:00:00" }
end_at { "2021-11-10 00:00:00" }

trait :one_day do
name { "HexDevs Open-Source" }
sequence(:handle) { |n| "HexDevs#{n}" }
start_at { "2021-08-05 21:00:00" }
end_at { "2021-08-05 23:59:00" }
end

trait :past_event do
name { "PastConf" }
sequence(:handle) { |n| "PastConf#{n}" }
description { "The conference you always miss by a few days." }
start_at { 3.days.ago }
end_at { 1.day.ago }
Expand Down