Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@ class User < ActiveRecord::Base
:recoverable, :rememberable, :trackable, :validatable,
:rpx_connectable

attr_accessible :email, :password, :password_confirmation, :remember_me
attr_accessible :email, :first_name, :last_name, :password, :password_confirmation, :remember_me

has_many :donations
has_many :projects, :through=>:donations

validates_presence_of :email
validates_presence_of :first_name
validates_presence_of :last_name

def projects_i_have_contributed_to
projects.uniq
end
end
def update_with_password(params={})
if params[:password].blank?
params.delete(:password)
params.delete(:password_confirmation) if params[:password_confirmation].blank?
end
update_attributes(params)
end
end
9 changes: 9 additions & 0 deletions app/views/devise/registrations/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
=resource_name.to_s.humanize
= form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put }) do |f|
= devise_error_messages!

%p
= f.label :first_name
%br/
= f.text_field :first_name
%p
= f.label :last_name
%br/
= f.text_field :last_name
%p
= f.label :email
%br/
Expand Down
8 changes: 8 additions & 0 deletions app/views/devise/registrations/new.html.haml
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
%h2=t('devise.common.sign_up')
= form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f|
= devise_error_messages!
%p
= f.label :first_name
%br/
= f.text_field :first_name
%p
= f.label :last_name
%br/
= f.text_field :last_name
%p
= f.label :email
%br/
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20101124204746_add_first_name_and_last_name_to_users.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class AddFirstNameAndLastNameToUsers < ActiveRecord::Migration
def self.up
add_column :users, :first_name, :string
add_column :users, :last_name, :string
end

def self.down
remove_column :users, :last_name
remove_column :users, :first_name
end
end
26 changes: 25 additions & 1 deletion features/sign_up.feature
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,31 @@ Feature: Sign up
Background:
Given a project exists

Scenario: User signs up with invalid data
Scenario: User signs up with invalid password
When I go to the sign up page
And I fill in "Email" with "invalidemail"
And I fill in "First name" with "firstname"
And I fill in "Last name" with "lastname"
And I fill in "Password" with "password"
And I fill in "Password confirmation" with ""
And I press "Sign up"
Then I should see error messages on the page

Scenario: User signs up with no first name
When I go to the sign up page
And I fill in "Email" with "email@person.com"
And I fill in "First name" with ""
And I fill in "Last name" with "lastname"
And I fill in "Password" with "password"
And I fill in "Password confirmation" with ""
And I press "Sign up"
Then I should see error messages on the page

Scenario: User signs up with no last name
When I go to the sign up page
And I fill in "Email" with "invalidemail"
And I fill in "First name" with "firstname"
And I fill in "Last name" with ""
And I fill in "Password" with "password"
And I fill in "Password confirmation" with ""
And I press "Sign up"
Expand All @@ -18,6 +40,8 @@ Feature: Sign up
Scenario: User signs up with valid data and confirms
When I go to the sign up page
And I fill in "Email" with "email@person.com"
And I fill in "First name" with "firstname"
And I fill in "Last name" with "lastname"
And I fill in "Password" with "password"
And I fill in "Password confirmation" with "password"
And I press "Sign up"
Expand Down
2 changes: 2 additions & 0 deletions spec/factories.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
user.email { Faker::Internet.email }
user.password { "password" }
user.password_confirmation { "password" }
user.first_name { Faker::Name.first_name }
user.last_name { Faker::Name.last_name }
end

Factory.define :email_confirmed_user, :parent => :user do |user|
Expand Down
10 changes: 10 additions & 0 deletions spec/models/user_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require 'spec_helper'

describe User do
it { should have_many(:donations) }

it { should validate_presence_of(:email) }
it { should validate_presence_of(:first_name) }
it { should validate_presence_of(:last_name) }
end