Skip to content

Commit

Permalink
Single full name form_field.
Browse files Browse the repository at this point in the history
  • Loading branch information
stantastic6 committed Jul 16, 2013
1 parent 32508d4 commit 3133f1a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class ApplicationController < ActionController::Base
protected

def configure_permitted_parameters
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :email, :password, :password_confirmation, :class_code, :school, :city, :state, :country)}
devise_parameter_sanitizer.for(:sign_up) { |u| u.permit(:first_name, :last_name, :full_name, :email, :password, :password_confirmation, :class_code, :school, :city, :state, :country)}
end

rescue_from CanCan::AccessDenied do |exception|
Expand Down
10 changes: 10 additions & 0 deletions app/models/student.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,14 @@ class Student < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable

validates_presence_of :first_name, :last_name, :password_confirmation, :class_code

def full_name
[first_name, last_name].join(' ')
end

def full_name=(name)
parts = name.split(' ', 2)
self.first_name = parts[0]
self.last_name = parts[1]
end
end
11 changes: 11 additions & 0 deletions app/models/teacher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@ class Teacher < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable

validates_presence_of :first_name, :last_name, :password_confirmation, :school, :city, :state, :country


def full_name
[first_name, last_name].join(' ')
end

def full_name=(name)
parts = name.split(' ', 2)
self.first_name = parts[0]
self.last_name = parts[1]
end
end
9 changes: 4 additions & 5 deletions app/views/devise/registrations/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
<legend>Personal Information</legend>

<div class="row-fluid">
<div class="span4">
<div class="text"><%= f.label :first_name %><%= f.text_field :first_name, :autofocus => true %></div>
</div>
<div class="span4">
<%= f.label :last_name %><%= f.text_field :last_name %>
<%= f.label :full_name %><%= f.text_field :full_name, :autofocus => true %>
<span class="help-block"><small>First and last name only</small></span>
</div>
</div>

<div class="row-fluid">
<div class="span8">
<div class="span4">
<%= f.label :email %><%= f.email_field :email %>
</div>
</div>
Expand Down
6 changes: 2 additions & 4 deletions spec/features/authentication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
let(:teacher2) {FactoryGirl.build(:teacher, email:"teacher2@email.com") }

it "should allow new teacher to sign up" do
fill_in "First name", with: teacher2.first_name
fill_in "Last name", with: teacher2.last_name
fill_in "Full name", with: [teacher2.first_name, teacher2.last_name].join(' ')
fill_in "Email", with: teacher2.email
fill_in "Password", with: teacher2.password
fill_in "Password confirmation", with: teacher2.password_confirmation
Expand Down Expand Up @@ -77,8 +76,7 @@
let(:student2) { FactoryGirl.build(:student, email: "student2@email.com") }

it "should allow a new student to sign up" do
fill_in "First name", with: student2.first_name
fill_in "Last name", with: student2.last_name
fill_in "Full name", with: [student2.first_name, student2.last_name].join(' ')
fill_in "Email", with: student2.email
fill_in "Password", with: student2.password
fill_in "Password confirmation", with: student2.password_confirmation
Expand Down

0 comments on commit 3133f1a

Please sign in to comment.