Skip to content
This repository has been archived by the owner on Apr 17, 2018. It is now read-only.

Commit

Permalink
Add ability for TAs to register.
Browse files Browse the repository at this point in the history
* Added basic validations against registration.
  • Loading branch information
drapergeek committed Jul 21, 2013
1 parent d663f67 commit 08d1286
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 2 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@
//
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
38 changes: 38 additions & 0 deletions app/controllers/teaching_assistants_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
class TeachingAssistantsController < ApplicationController
def new
@teaching_assistant = TeachingAssistant.new
end

def create
teaching_assistant = TeachingAssistant.new(teaching_assistant_params)

if teaching_assistant.save
flash[:notice] = 'Thank you for signing up to be a Teaching Assistant!'
redirect_to root_path
else
@teaching_assistant = teaching_assistant

flash[:error] = 'Your form submission had errors.'
render :new
end
end

private

def teaching_assistant_params
params.require(:teaching_assistant).permit(allowed_attributes)
end

def allowed_attributes
[:name,
:email,
:gender,
:experience,
:bio,
:company,
:operating_system,
:company,
:other_information,
:past_experience]
end
end
9 changes: 9 additions & 0 deletions app/models/teaching_assistant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class TeachingAssistant < ActiveRecord::Base
OPERATING_SYSTEMS = ['Linux', 'Microsoft Windows', 'Mac OS X']
EXPERIENCES = ['No Past Experience',
'Attended Previous Workshop',
'Assisted at Previous Workshop']
validates :name, presence: true
validates :email, presence: true
validates :bio, presence: true
end
14 changes: 14 additions & 0 deletions app/views/teaching_assistants/new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<%= simple_form_for @teaching_assistant do |form| %>
<%= form.input :name %>
<%= form.input :email %>
<%= form.input :gender %>
<%= form.input :experience %>
<%= form.input :bio %>
<%= form.input :company %>
<%= form.input :operating_systems, as: :check_boxes,
collection: TeachingAssistant::OPERATING_SYSTEMS %>
<%= form.input :other_information %>
<%= form.input :past_experience, as: :select,
collection: TeachingAssistant::EXPERIENCES %>
<%= form.button :submit, 'Submit Application' %>
<% end %>
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
Ogre::Application.routes.draw do
resources :teaching_assistants, only: [:new, :create]
root to: 'teaching_assistants#new'
end
17 changes: 17 additions & 0 deletions db/migrate/20130721224231_create_teaching_assistants.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class CreateTeachingAssistants < ActiveRecord::Migration
def change
create_table :teaching_assistants do |t|
t.string :name
t.string :email
t.string :gender
t.string :experience
t.text :bio
t.string :company
t.string :operating_systems
t.text :other_information
t.string :past_experience

t.timestamps
end
end
end
16 changes: 15 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20130721215245) do
ActiveRecord::Schema.define(version: 20130721224231) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand All @@ -32,4 +32,18 @@

add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree

create_table "teaching_assistants", force: true do |t|
t.string "name"
t.string "email"
t.string "gender"
t.string "experience"
t.text "bio"
t.string "company"
t.string "operating_systems"
t.text "other_information"
t.string "past_experience"
t.datetime "created_at"
t.datetime "updated_at"
end

end
38 changes: 38 additions & 0 deletions spec/features/tas/ta_registration_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
require 'spec_helper'


feature 'ta signs up' do
scenario 'with valid information' do
visit new_teaching_assistant_path

submit_valid_registration

expect(page).
to have_content 'Thank you for signing up to be a Teaching Assistant!'
end

scenario 'with invalid information' do
visit new_teaching_assistant_path

submit_invalid_registration

expect(page).to have_content 'Your form submission had errors.'
end

def submit_valid_registration
fill_in 'Name', with: 'Peter Parker'
fill_in 'Email', with: '[email protected]'
fill_in 'Gender', with: 'Male'
fill_in 'Experience', with: 'I have a lot of it'
fill_in 'Bio', with: 'is awesome.'
fill_in 'Company', with: 'Oscorp'
check 'Linux'
fill_in 'Other', with: 'All good.'
select 'Attended Previous Workshop', from: 'Past experience'
click_button 'Submit Application'
end

def submit_invalid_registration
click_button 'Submit Application'
end
end
7 changes: 7 additions & 0 deletions spec/models/teaching_assistant_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

describe TeachingAssistant do
it { expect(subject).to validate_presence_of(:name) }
it { expect(subject).to validate_presence_of(:email) }
it { expect(subject).to validate_presence_of(:bio) }
end

0 comments on commit 08d1286

Please sign in to comment.