From 4313b1f8487eda6c0b6fada66fde976cbd1e93c9 Mon Sep 17 00:00:00 2001 From: "jordan@futurefridays.com" Date: Wed, 24 Nov 2010 15:52:20 -0500 Subject: [PATCH 1/7] Created a Rails migration to add First Name and Last Name to users table. Added formtastic fields inside the devise registrations new.haml.html and edit.haml.html. Users will now be prompted to enter a first and last name when registering. --- app/views/devise/registrations/edit.html.haml | 9 +++++++++ app/views/devise/registrations/new.html.haml | 8 ++++++++ ...124204746_add_first_name_and_last_name_to_users.rb | 11 +++++++++++ 3 files changed, 28 insertions(+) create mode 100644 db/migrate/20101124204746_add_first_name_and_last_name_to_users.rb 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 From 2f992bbccd7393a9529231dcafd90851db03a9ee Mon Sep 17 00:00:00 2001 From: "jordan@futurefridays.com" Date: Tue, 30 Nov 2010 12:27:44 -0500 Subject: [PATCH 2/7] added 'details' to user model --- app/models/user.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/user.rb b/app/models/user.rb index 141a4eb..9a9e3cf 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -11,4 +11,8 @@ class User < ActiveRecord::Base def projects_i_have_contributed_to projects.uniq end -end + + def details + [:first_name, :last_name, :email, :password].map {|field| self.send(field) }.reject(&:blank?).join(', ') + end +end \ No newline at end of file From a458dbcf6307da9b54007385f8e802c53ea5677c Mon Sep 17 00:00:00 2001 From: "jordan@futurefridays.com" Date: Tue, 30 Nov 2010 12:28:16 -0500 Subject: [PATCH 3/7] created spec file for users and appended details that must exist for each user. --- spec/models/user_spec.rb | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 spec/models/user_spec.rb diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb new file mode 100644 index 0000000..25bf0af --- /dev/null +++ b/spec/models/user_spec.rb @@ -0,0 +1,16 @@ +require 'spec_helper' + +describe User do + it { should have_many(:donations) } +end + +describe User, 'details' do + subject { Factory.build :user, + :first_name => 'Stevie', + :last_name => 'Wonder', + :email => 'steviewonder@gmail.com', + :password => 'stevieisthebest1' + } + + its(:details) { should == 'Stevie, Wonder, steviewonder@gmail.com, stevieisthebest1' } +end \ No newline at end of file From cebb2beea7ec15a542c73fbd262864cf1c027236 Mon Sep 17 00:00:00 2001 From: James McElhiney Date: Tue, 30 Nov 2010 15:37:57 -0500 Subject: [PATCH 4/7] add validations and fixing specs --- app/models/user.rb | 8 ++++---- features/sign_up.feature | 2 +- spec/factories.rb | 2 ++ spec/models/user_spec.rb | 14 ++++---------- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 9a9e3cf..cec9cb4 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -7,12 +7,12 @@ class User < ActiveRecord::Base 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 - - def details - [:first_name, :last_name, :email, :password].map {|field| self.send(field) }.reject(&:blank?).join(', ') - end end \ No newline at end of file diff --git a/features/sign_up.feature b/features/sign_up.feature index 464652c..c053990 100644 --- a/features/sign_up.feature +++ b/features/sign_up.feature @@ -21,5 +21,5 @@ Feature: Sign up And I fill in "Password" with "password" And I fill in "Password confirmation" with "password" And I press "Sign up" - Then I should see "You have signed up" + Then I should see error messages on the page 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 index 25bf0af..3706df1 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -2,15 +2,9 @@ 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 -describe User, 'details' do - subject { Factory.build :user, - :first_name => 'Stevie', - :last_name => 'Wonder', - :email => 'steviewonder@gmail.com', - :password => 'stevieisthebest1' - } - - its(:details) { should == 'Stevie, Wonder, steviewonder@gmail.com, stevieisthebest1' } -end \ No newline at end of file From 4cc38ce89645614c555e76cb4cd17d2775f731ae Mon Sep 17 00:00:00 2001 From: James McElhiney Date: Tue, 30 Nov 2010 16:03:05 -0500 Subject: [PATCH 5/7] added more scenarios --- features/sign_up.feature | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/features/sign_up.feature b/features/sign_up.feature index c053990..2045dd1 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" From dd342c4822eda68c19e291d4c502f03fee811bee Mon Sep 17 00:00:00 2001 From: "jordan@futurefridays.com" Date: Tue, 30 Nov 2010 16:54:41 -0500 Subject: [PATCH 6/7] Added :first_name, :last_name to User.rb model, ensured database capture of each field, restored validations, corrected sign_up feature. --- app/models/user.rb | 2 +- features/sign_up.feature | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index cec9cb4..9f12ab8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -3,7 +3,7 @@ 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 diff --git a/features/sign_up.feature b/features/sign_up.feature index 2045dd1..c843d54 100644 --- a/features/sign_up.feature +++ b/features/sign_up.feature @@ -45,5 +45,5 @@ Feature: Sign up And I fill in "Password" with "password" And I fill in "Password confirmation" with "password" And I press "Sign up" - Then I should see error messages on the page + Then I should see "You have signed up" From c68530fdb44cc6a16b2ffb78b429d8d6b3d13888 Mon Sep 17 00:00:00 2001 From: "jordan@futurefridays.com" Date: Tue, 30 Nov 2010 18:18:43 -0500 Subject: [PATCH 7/7] Added code to allow users to edit first_name, last_name, and email without entering a password. Also permits users using Janrain to add their first_name, last_name to their "account" along with creating a site-side password. --- app/models/user.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/models/user.rb b/app/models/user.rb index 9f12ab8..89e5309 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -14,5 +14,12 @@ class User < ActiveRecord::Base def projects_i_have_contributed_to projects.uniq - end -end \ No newline at end of file + 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