From 05c5e770eee422c75cd6d244fb487ff52a588dfa Mon Sep 17 00:00:00 2001 From: danielvincent Date: Wed, 27 Oct 2010 16:25:22 -0700 Subject: [PATCH] removed real name from signup process. --- app/controllers/aspects_controller.rb | 2 +- app/models/person.rb | 6 ++- app/models/profile.rb | 1 - app/models/user.rb | 7 ++-- app/views/registrations/new.html.haml | 8 ---- app/views/users/getting_started.html.haml | 2 +- public/stylesheets/sass/application.sass | 1 - .../registrations_controller_spec.rb | 8 +--- spec/models/person_spec.rb | 37 +++++++++++-------- spec/models/profile_spec.rb | 20 ---------- spec/models/user_spec.rb | 2 +- 11 files changed, 34 insertions(+), 60 deletions(-) diff --git a/app/controllers/aspects_controller.rb b/app/controllers/aspects_controller.rb index 71927046c..2cb295f21 100644 --- a/app/controllers/aspects_controller.rb +++ b/app/controllers/aspects_controller.rb @@ -13,7 +13,7 @@ class AspectsController < ApplicationController @aspect = :all if current_user.getting_started == true - redirect_to getting_started_path(1) + redirect_to getting_started_path end end diff --git a/app/models/person.rb b/app/models/person.rb index 5a1486653..b794c8811 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -58,7 +58,11 @@ class Person end def real_name - "#{profile.first_name.to_s} #{profile.last_name.to_s}" + if profile.first_name.nil? || profile.first_name.empty? + self.diaspora_handle + else + "#{profile.first_name.to_s} #{profile.last_name.to_s}" + end end def owns?(post) diff --git a/app/models/profile.rb b/app/models/profile.rb index 544277ce7..7258c4bfd 100644 --- a/app/models/profile.rb +++ b/app/models/profile.rb @@ -19,7 +19,6 @@ class Profile key :image_url, String key :bio, String - validates_presence_of :first_name, :last_name after_validation :strip_names before_save :strip_names diff --git a/app/models/user.rb b/app/models/user.rb index fa245c290..eb50ff8e8 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -89,10 +89,6 @@ class User self.person.send(method, *args) end - def real_name - "#{person.profile.first_name.to_s} #{person.profile.last_name.to_s}" - end - ######### Aspects ###################### def aspect(opts = {}) aspect = Aspect.new(opts) @@ -405,12 +401,15 @@ class User ###Helpers############ def self.build(opts = {}) + opts[:person] = {} opts[:person][:diaspora_handle] = "#{opts[:username]}@#{APP_CONFIG[:terse_pod_url]}" opts[:person][:url] = APP_CONFIG[:pod_url] opts[:serialized_private_key] = generate_key opts[:person][:serialized_public_key] = opts[:serialized_private_key].public_key + opts[:person][:profile] = Profile.new + u = User.new(opts) u end diff --git a/app/views/registrations/new.html.haml b/app/views/registrations/new.html.haml index 191f885e6..ea0be2b75 100644 --- a/app/views/registrations/new.html.haml +++ b/app/views/registrations/new.html.haml @@ -17,14 +17,6 @@ = f.label :password_confirmation = f.password_field :password_confirmation - = f.fields_for :person do |p| - = p.fields_for :profile do |pr| - %p - = pr.label :first_name - = pr.text_field :first_name - %p - = pr.label :last_name - = pr.text_field :last_name = f.submit t('.sign_up') diff --git a/app/views/users/getting_started.html.haml b/app/views/users/getting_started.html.haml index 71bc63dd0..da1b6c40f 100644 --- a/app/views/users/getting_started.html.haml +++ b/app/views/users/getting_started.html.haml @@ -30,7 +30,7 @@ %br .span-15.last - .floating + .floating{:style=>"min-height:500px;"} = render "users/getting_started/step_#{@step}", :current_user => current_user - if @step > 1 diff --git a/public/stylesheets/sass/application.sass b/public/stylesheets/sass/application.sass index 315b8a41f..61794ba0f 100644 --- a/public/stylesheets/sass/application.sass +++ b/public/stylesheets/sass/application.sass @@ -1293,7 +1293,6 @@ ul.aspects :border :bottom 1px solid #ccc :top 1px solid #fff - :min-height 500px .submit_block :position absolute diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb index 3c9bbde07..942e8f5c9 100644 --- a/spec/controllers/registrations_controller_spec.rb +++ b/spec/controllers/registrations_controller_spec.rb @@ -14,11 +14,7 @@ describe RegistrationsController do @valid_params = {"user" => {"username" => "jdoe", "email" => "jdoe@example.com", "password" => "password", - "password_confirmation" => "password", - "person" => { - "profile" => { - "first_name" => "John", - "last_name" => "Doe"}}}} + "password_confirmation" => "password"}} end describe "#create" do @@ -41,7 +37,7 @@ describe RegistrationsController do end context "with invalid parameters" do before do - @valid_params["user"]["person"]["profile"].delete("first_name") + @valid_params["user"]["password_confirmation"] = "baddword" @invalid_params = @valid_params end it "does not create a user" do diff --git a/spec/models/person_spec.rb b/spec/models/person_spec.rb index fa89610af..afbf41d8d 100644 --- a/spec/models/person_spec.rb +++ b/spec/models/person_spec.rb @@ -13,22 +13,6 @@ describe Person do @aspect2 = @user2.aspect(:name => "Abscence of Babes") end - describe "validation" do - describe "of associated profile" do - it "fails if the profile isn't valid" do - person = Factory.build(:person) - person.should be_valid - - person.profile.update_attribute(:first_name, nil) - person.profile.should_not be_valid - person.should_not be_valid - - person.errors.count.should == 1 - person.errors.full_messages.first.should =~ /first name/i - end - end - end - describe '#diaspora_handle' do context 'local people' do it 'uses the pod config url to set the diaspora_handle' do @@ -54,6 +38,27 @@ describe Person do end end + context '#real_name' do + let!(:user) { Factory(:user) } + let!(:person) { user.person } + let!(:profile) { person.profile } + + context 'with first name' do + it 'should return their name for real name' do + person.real_name.should match /#{profile.first_name}|#{profile.last_name}/ + end + end + + context 'without first name' do + it 'should display their diaspora handle' do + person.profile.first_name = nil + person.profile.last_name = nil + person.save! + person.real_name.should == person.diaspora_handle + end + end + end + describe 'xml' do before do @xml = @person.to_xml.to_s diff --git a/spec/models/profile_spec.rb b/spec/models/profile_spec.rb index de2eb6955..fed124726 100644 --- a/spec/models/profile_spec.rb +++ b/spec/models/profile_spec.rb @@ -7,16 +7,6 @@ require 'spec_helper' describe Profile do describe 'validation' do describe "of first_name" do - it "requires first name" do - profile = Factory.build(:profile, :first_name => nil) - profile.should_not be_valid - profile.first_name = "Hortense" - profile.should be_valid - end - it "requires non-empty first name" do - profile = Factory.build(:profile, :first_name => " ") - profile.should_not be_valid - end it "strips leading and trailing whitespace" do profile = Factory.build(:profile, :first_name => " Shelly ") profile.should be_valid @@ -24,16 +14,6 @@ describe Profile do end end describe "of last_name" do - it "requires a last name" do - profile = Factory.build(:profile, :last_name => nil) - profile.should_not be_valid - profile.last_name = "Shankar" - profile.should be_valid - end - it "requires non-empty last name" do - profile = Factory.build(:profile, :last_name => " ") - profile.should_not be_valid - end it "strips leading and trailing whitespace" do profile = Factory.build(:profile, :last_name => " Ohba ") profile.should be_valid diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index 351d5347c..dfb5995c0 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -124,7 +124,7 @@ describe User do :username => "ohai", :email => "ohai@example.com", :password => "password", - :password_confirmation => "password", + :password_confirmation => "wrongpasswordz", :person => {:profile => {:first_name => "", :last_name => ""}}} end it "raises no error" do