forked from openstreetmap/openstreetmap-website
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add events and event organizers including tests.
- Loading branch information
Showing
15 changed files
with
459 additions
and
1 deletion.
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
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,40 @@ | ||
class EventAttendancesController < ApplicationController | ||
layout "site" | ||
before_action :authorize_web | ||
before_action :set_event_attendance, :only => [:update] | ||
|
||
authorize_resource | ||
|
||
def create | ||
attendance = EventAttendance.new(event_attendance_params) | ||
if attendance.save | ||
redirect_to event_path(attendance.event), :notice => t(".success") | ||
else | ||
redirect_to event_path(attendance.event), :alert => t(".failure") | ||
end | ||
end | ||
|
||
def update | ||
respond_to do |format| | ||
if @event_attendance.update(update_params) | ||
format.html { redirect_to @event_attendance.event, :notice => t(".success") } | ||
else | ||
format.html { redirect_to :edit, :alert => t(".failure") } | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def set_event_attendance | ||
@event_attendance = EventAttendance.find(params[:id]) | ||
end | ||
|
||
def event_attendance_params | ||
params.require(:event_attendance).permit(:event_id, :user_id, :intention) | ||
end | ||
|
||
def update_params | ||
params.require(:event_attendance).permit(:intention) | ||
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
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,35 @@ | ||
# == Schema Information | ||
# | ||
# Table name: event_attendances | ||
# | ||
# id :bigint(8) not null, primary key | ||
# user_id :bigint(8) not null | ||
# event_id :bigint(8) not null | ||
# intention :enum not null | ||
# created_at :datetime not null | ||
# updated_at :datetime not null | ||
# | ||
# Indexes | ||
# | ||
# index_event_attendances_on_event_id (event_id) | ||
# index_event_attendances_on_user_id (user_id) | ||
# index_event_attendances_on_user_id_and_event_id (user_id,event_id) UNIQUE | ||
# | ||
# Foreign Keys | ||
# | ||
# fk_rails_... (event_id => events.id) | ||
# fk_rails_... (user_id => users.id) | ||
# | ||
|
||
class EventAttendance < ApplicationRecord | ||
module Intentions | ||
YES = "Yes".freeze | ||
NO = "No".freeze | ||
MAYBE = "Maybe".freeze | ||
ALL_INTENTIONS = [YES, NO, MAYBE].freeze | ||
end | ||
validates :intention, :inclusion => { :in => Intentions::ALL_INTENTIONS } | ||
|
||
belongs_to :event | ||
belongs_to :user | ||
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
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,18 @@ | ||
class CreateEventAttendances < ActiveRecord::Migration[7.0] | ||
def up | ||
create_enum :event_attendances_intention_enum, %w[Maybe No Yes] | ||
create_table :event_attendances do |t| | ||
t.references :user, :foreign_key => true, :null => false, :index => true | ||
t.references :event, :foreign_key => true, :null => false, :index => true | ||
t.column :intention, :event_attendances_intention_enum, :null => false | ||
|
||
t.timestamps | ||
end | ||
add_index :event_attendances, [:user_id, :event_id], :unique => true | ||
end | ||
|
||
def down | ||
drop_table :event_attendances | ||
drop_enum :event_attendances_intention_enum | ||
end | ||
end |
Oops, something went wrong.