diff --git a/app/models/user.rb b/app/models/user.rb index 141a4eb..89e5309 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -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 diff --git a/app/views/devise/registrations/edit.html.haml b/app/views/devise/registrations/edit.html.haml index 0eec6eb..3b81cb5 100644 --- a/app/views/devise/registrations/edit.html.haml +++ b/app/views/devise/registrations/edit.html.haml @@ -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/ diff --git a/app/views/devise/registrations/new.html.haml b/app/views/devise/registrations/new.html.haml index 08de9bd..cdcc192 100644 --- a/app/views/devise/registrations/new.html.haml +++ b/app/views/devise/registrations/new.html.haml @@ -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/ diff --git a/db/migrate/20101124204746_add_first_name_and_last_name_to_users.rb b/db/migrate/20101124204746_add_first_name_and_last_name_to_users.rb new file mode 100644 index 0000000..e36143d --- /dev/null +++ b/db/migrate/20101124204746_add_first_name_and_last_name_to_users.rb @@ -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 diff --git a/features/sign_up.feature b/features/sign_up.feature index 464652c..c843d54 100644 --- a/features/sign_up.feature +++ b/features/sign_up.feature @@ -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" @@ -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" diff --git a/spec/factories.rb b/spec/factories.rb index 6b25d07..d44a287 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -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| diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..3706df1 --- /dev/null +++ b/spec/models/user_spec.rb @@ -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 +