This repository has been archived by the owner on Apr 17, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added basic validations against registration.
- Loading branch information
1 parent
d663f67
commit 08d1286
Showing
9 changed files
with
140 additions
and
2 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 |
---|---|---|
|
@@ -12,5 +12,4 @@ | |
// | ||
//= require jquery | ||
//= require jquery_ujs | ||
//= require turbolinks | ||
//= require_tree . |
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,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 |
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,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 |
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,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 %> |
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,2 +1,4 @@ | ||
Ogre::Application.routes.draw do | ||
resources :teaching_assistants, only: [:new, :create] | ||
root to: 'teaching_assistants#new' | ||
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,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 |
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,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 |
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,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 |