From d1b91e1eacb13744f2057cd3ed542d45962be581 Mon Sep 17 00:00:00 2001 From: maxwell Date: Tue, 15 Feb 2011 14:17:08 -0800 Subject: [PATCH] wip, profiles controller and specs, with cucumber failures --- app/controllers/people_controller.rb | 26 ------ app/controllers/profiles_controller.rb | 33 +++++++ app/views/layouts/_header.html.haml | 2 +- app/views/layouts/application.mobile.haml | 2 +- app/views/people/_edit.html.haml | 51 ----------- app/views/people/_profile_sidebar.html.haml | 2 +- app/views/photos/_new_profile_photo.haml | 4 +- app/views/profiles/_edit.html.haml | 52 +++++++++++ app/views/{people => profiles}/edit.html.haml | 5 +- app/views/services/index.html.haml | 2 +- app/views/users/edit.html.haml | 2 +- .../users/getting_started/_step_1.html.haml | 3 +- config/locales/diaspora/en.yml | 34 ++++---- config/routes.rb | 3 +- features/support/paths.rb | 2 +- spec/controllers/people_controller_spec.rb | 45 ---------- spec/controllers/profiles_controller_spec.rb | 86 +++++++++++++++++++ 17 files changed, 204 insertions(+), 150 deletions(-) create mode 100644 app/controllers/profiles_controller.rb delete mode 100644 app/views/people/_edit.html.haml create mode 100644 app/views/profiles/_edit.html.haml rename app/views/{people => profiles}/edit.html.haml (73%) create mode 100644 spec/controllers/profiles_controller_spec.rb diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 677f3bc25..69e8dff6b 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -81,32 +81,6 @@ class PeopleController < ApplicationController redirect_to root_url end - def edit - @aspect = :person_edit - @person = current_user.person - @profile = @person.profile - end - - def update - # upload and set new profile photo - params[:profile] ||= {} - params[:profile][:searchable] ||= false - params[:profile][:photo] = Photo.where(:person_id => current_user.person.id, - :id => params[:photo_id]).first if params[:photo_id] - - if current_user.update_profile params[:profile] - flash[:notice] = I18n.t 'people.update.updated' - else - flash[:error] = I18n.t 'people.update.failed' - end - - if params[:getting_started] - redirect_to getting_started_path(:step => params[:getting_started].to_i+1) - else - redirect_to edit_person_path - end - end - def retrieve_remote if params[:diaspora_handle] webfinger(params[:diaspora_handle], :single_aspect_form => true) diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb new file mode 100644 index 000000000..54c892a9a --- /dev/null +++ b/app/controllers/profiles_controller.rb @@ -0,0 +1,33 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + +class ProfilesController < ApplicationController + before_filter :authenticate_user! + def edit + @person = current_user.person + @aspect = :person_edit + @profile = @person.profile + end + + def update + # upload and set new profile photo + params[:profile] ||= {} + params[:profile][:searchable] ||= false + params[:profile][:photo] = Photo.where(:person_id => current_user.person.id, + :id => params[:photo_id]).first if params[:photo_id] + + if current_user.update_profile params[:profile] + flash[:notice] = I18n.t 'profiles.update.updated' + else + flash[:error] = I18n.t 'profiles.update.failed' + end + + if params[:getting_started] + redirect_to getting_started_path(:step => params[:getting_started].to_i+1) + else + redirect_to edit_profile_path + end + + end +end diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index fd8dabc99..fbfb06819 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -35,7 +35,7 @@ = owner_image_tag(:thumb_small) = link_to current_user.name, '#' %li= link_to t('.view_profile'), current_user.person - %li= link_to t('.edit_profile'), edit_person_path(current_user.person) + %li= link_to t('.edit_profile'), edit_profile_path %li= link_to t('.account_settings'), edit_user_path(current_user) %li= link_to t('.logout'), destroy_user_session_path diff --git a/app/views/layouts/application.mobile.haml b/app/views/layouts/application.mobile.haml index 55611c1c8..000aea90a 100644 --- a/app/views/layouts/application.mobile.haml +++ b/app/views/layouts/application.mobile.haml @@ -101,7 +101,7 @@ %ul{:data => {:role => 'listview', :inset => 'true'}} %li - = link_to t('people.edit.your_profile'), person_path(current_user.person) + = link_to t('profiles.edit.your_profile'), edit_profile_path %li = link_to t('notifications.index.notifications'), notifications_path .ui-li-count diff --git a/app/views/people/_edit.html.haml b/app/views/people/_edit.html.haml deleted file mode 100644 index d44dfc17e..000000000 --- a/app/views/people/_edit.html.haml +++ /dev/null @@ -1,51 +0,0 @@ --# Copyright (c) 2010, Diaspora Inc. This file is --# licensed under the Affero General Public License version 3 or later. See --# the COPYRIGHT file. - -- content_for :page_title do - = t('.edit_profile') - -= form_tag person_path(@person), :method => :put, :multipart => true, :id => 'update_profile_form' do - %h3 - = t('people.edit.your_profile') - .description - = t('people.edit.info_available_to') - - = error_messages_for @person - - %h4 - = t('people.edit.your_name') - = text_field_tag 'profile[first_name]', @profile.first_name, :placeholder => t('people.edit.first_name') - = text_field_tag 'profile[last_name]', @profile.last_name, :placeholder => t('people.edit.last_name') - - %h4 - = t('people.edit.your_gender') - %br - = text_field_tag 'profile[gender]', @profile.gender, :placeholder => t("fill_me_out") - - %h4 - = t('people.edit.your_birthday') - %br - = select_date @person.profile.birthday, :prompt => true, - :default => true, :order => t('date.order'), :start_year => 2000, :end_year => 1930, :prefix => 'profile[date]' - - %h4 - = t('people.edit.your_bio') - = text_area_tag 'profile[bio]', @profile.bio, :rows => 5, :placeholder => t('fill_me_out') - - %h4 - = t('people.edit.your_photo') - = render 'photos/new_profile_photo' - %br - - %h4 - = t('search') - %p{:class=>"checkbox_select"} - = label_tag 'profile[searchable]', t('people.edit.allow_search') - = check_box_tag 'profile[searchable]', true, @person.profile.searchable - - = hidden_field_tag :getting_started, @step if @step - - .submit_block - =yield(:submit_block) - diff --git a/app/views/people/_profile_sidebar.html.haml b/app/views/people/_profile_sidebar.html.haml index d22ac25c7..48bcd5b5a 100644 --- a/app/views/people/_profile_sidebar.html.haml +++ b/app/views/people/_profile_sidebar.html.haml @@ -20,7 +20,7 @@ - if person == current_user.person %p - = link_to t('people.profile_sidebar.edit_my_profile'), edit_person_path(person) + = link_to t('people.profile_sidebar.edit_my_profile'), edit_profile_path %hr{:style=>"width:300px;"} diff --git a/app/views/photos/_new_profile_photo.haml b/app/views/photos/_new_profile_photo.haml index 60ea01ec6..08e97b0ec 100644 --- a/app/views/photos/_new_profile_photo.haml +++ b/app/views/photos/_new_profile_photo.haml @@ -9,12 +9,12 @@ #file-upload.button =t('.upload') - -if !@aspect.nil? && @aspect != :getting_started + -if !aspect.nil? && aspect != :getting_started %br %br %p \...#{t('.or_select_one')} - = link_to t('_photos'), person_photos_path(@person) + = link_to t('_photos'), person_photos_path(person) #publisher_photo_upload :javascript diff --git a/app/views/profiles/_edit.html.haml b/app/views/profiles/_edit.html.haml new file mode 100644 index 000000000..33ebf82f5 --- /dev/null +++ b/app/views/profiles/_edit.html.haml @@ -0,0 +1,52 @@ +-# Copyright (c) 2010, Diaspora Inc. This file is +-# licensed under the Affero General Public License version 3 or later. See +-# the COPYRIGHT file. + +- content_for :page_title do + = t('.edit_profile') + += form_tag profile_path(profile), :method => :put, :multipart => true, :id => 'update_profile_form' do + %h3 + = t('profiles.edit.your_profile') + .description + = t('profiles.edit.info_available_to') + + = error_messages_for profile + + %h4 + = t('profiles.edit.your_name') + = text_field_tag 'profile[first_name]', profile.first_name, :placeholder => t('profiles.edit.first_name') + = text_field_tag 'profile[last_name]', profile.last_name, :placeholder => t('profiles.edit.last_name') + + %h4 + = t('profiles.edit.your_gender') + %br + = text_field_tag 'profile[gender]', profile.gender, :placeholder => t("fill_me_out") + + %h4 + = t('profiles.edit.your_birthday') + %br + = select_date profile.birthday, :prompt => true, + :default => true, :order => t('date.order'), :start_year => 2000, :end_year => 1930, :prefix => 'profile[date]' + + %h4 + = t('profiles.edit.your_bio') + = text_area_tag 'profile[bio]', profile.bio, :rows => 5, :placeholder => t('fill_me_out') + + %h4 + = t('profiles.edit.your_photo') + = render 'photos/new_profile_photo', :aspect => aspect, :person => person + %b + + %h4 + = t('search') + %p{:class=>"checkbox_select"} + = label_tag 'profile[searchable]', t('profiles.edit.allow_search') + = check_box_tag 'profile[searchable]', true, profile.searchable + + = hidden_field_tag :getting_started, step if step + + .submit_block + =yield(:submit_block) + + diff --git a/app/views/people/edit.html.haml b/app/views/profiles/edit.html.haml similarity index 73% rename from app/views/people/edit.html.haml rename to app/views/profiles/edit.html.haml index 73b8105fc..f3752c692 100644 --- a/app/views/people/edit.html.haml +++ b/app/views/profiles/edit.html.haml @@ -7,7 +7,7 @@ %h2 = t('settings') %ul#settings_nav - %li=link_to t('profile'), edit_person_path(current_user.person) + %li=link_to t('profile'), edit_profile_path %li=link_to t('account'), edit_user_path(current_user) %li=link_to t('_services'), services_path @@ -16,5 +16,6 @@ = link_to t('cancel'), edit_user_path(current_user) = t('or') = submit_tag t('.update_profile') - = render :partial => 'people/edit' + = render :partial => 'edit', :locals => {:person => @person, + :profile => @profile, :aspect => @aspect, :step => @step} diff --git a/app/views/services/index.html.haml b/app/views/services/index.html.haml index f0b606e07..107767fdc 100644 --- a/app/views/services/index.html.haml +++ b/app/views/services/index.html.haml @@ -9,7 +9,7 @@ %h2 = t('settings') %ul#settings_nav - %li=link_to t('profile'), edit_person_path(current_user.person) + %li=link_to t('profile'), edit_profile_path %li=link_to t('account'), edit_user_path(current_user) %li=link_to t('_services'), services_path diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index e5de660d6..aa0f5bbd5 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -21,7 +21,7 @@ %h2 = t('settings') %ul#settings_nav - %li=link_to t('profile'), edit_person_path(current_user.person) + %li=link_to t('profile'), edit_profile_path %li=link_to t('account'), edit_user_path(current_user) %li=link_to t('_services'), services_path diff --git a/app/views/users/getting_started/_step_1.html.haml b/app/views/users/getting_started/_step_1.html.haml index fc786edca..45a665254 100644 --- a/app/views/users/getting_started/_step_1.html.haml +++ b/app/views/users/getting_started/_step_1.html.haml @@ -4,5 +4,6 @@ - content_for :submit_block do = submit_tag "#{t('users.getting_started.save_and_continue')} →" -= render :partial => 'people/edit' += render :partial => 'profiles/edit', :locals => {:person => @person, + :profile => @profile, :aspect => @aspect, :step => @step} diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 1143759c1..5b284a9b3 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -344,6 +344,23 @@ en: no_message_to_display: "No message to display." destroy: failure: "Failed to delete post" + profiles: + edit: + info_available_to: "This info will be available to whomever you connect with on Diaspora." + your_profile: "Your profile" + your_name: "Your name" + first_name: "First name" + last_name: "Last name" + your_gender: "Your gender" + your_birthday: "Your birthday" + your_bio: "Your bio" + your_photo: "Your photo" + update_profile: "Update Profile" + allow_search: "Allow for people to search for you within Diaspora" + edit_profile: "Edit profile" + update: + updated: "Profile updated" + failed: "Failed to update profile" people: person: pending_request: "pending request" @@ -368,22 +385,7 @@ en: recent_public_posts: "Recent Public Posts" similar_contacts: "similar contacts" start_sharing: "start sharing" - edit: - info_available_to: "This info will be available to whomever you connect with on Diaspora." - your_profile: "Your profile" - your_name: "Your name" - first_name: "First name" - last_name: "Last name" - your_gender: "Your gender" - your_birthday: "Your birthday" - your_bio: "Your bio" - your_photo: "Your photo" - update_profile: "Update Profile" - allow_search: "Allow for people to search for you within Diaspora" - edit_profile: "Edit profile" - update: - updated: "Profile updated" - failed: "Failed to update profile" + profile_sidebar: remove_contact: "remove contact" edit_my_profile: "Edit my profile" diff --git a/config/routes.rb b/config/routes.rb index 505642ec7..391fee21c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,7 @@ Diaspora::Application.routes.draw do resources :comments, :only => [:create] resources :requests, :only => [:destroy, :create] + resource :profile match 'services/inviter/:provider' => 'services#inviter', :as => 'service_inviter' match 'services/finder/:provider' => 'services#finder', :as => 'friend_finder' resources :services @@ -19,7 +20,7 @@ Diaspora::Application.routes.draw do resources :posts, :only => [:show], :path => '/p/' match '/people/share_with' => 'people#share_with', :as => 'share_with' - resources :people do + resources :people, :except => [:edit, :update] do resources :status_messages resources :photos end diff --git a/features/support/paths.rb b/features/support/paths.rb index ed078dfa4..d36004a33 100644 --- a/features/support/paths.rb +++ b/features/support/paths.rb @@ -14,7 +14,7 @@ module NavigationHelpers when /^the ([\w ]+) page$/ send("#{$1.gsub(/\W+/, '_')}_path") when /^my edit profile page$/ - edit_person_path(@me.person) + edit_profile_path when /^my acceptance form page$/ accept_user_invitation_path(:invitation_token => @me.invitation_token) when /^the requestors profile$/ diff --git a/spec/controllers/people_controller_spec.rb b/spec/controllers/people_controller_spec.rb index dd305f184..341be3e18 100644 --- a/spec/controllers/people_controller_spec.rb +++ b/spec/controllers/people_controller_spec.rb @@ -155,49 +155,4 @@ describe PeopleController do get :retrieve_remote, :diaspora_handle => @user.diaspora_handle end end - - describe '#update' do - it "sets the flash" do - put :update, :id => @user.person.id, - :profile => { - :image_url => "", - :first_name => "Will", - :last_name => "Smith" - } - flash[:notice].should_not be_empty - end - - context 'with a profile photo set' do - before do - @params = { :id => @user.person.id, - :profile => - {:image_url => "", - :last_name => @user.person.profile.last_name, - :first_name => @user.person.profile.first_name }} - - @user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" - @user.person.profile.save - end - it "doesn't overwrite the profile photo when an empty string is passed in" do - image_url = @user.person.profile.image_url - put :update, @params - - Person.find(@user.person.id).profile.image_url.should == image_url - end - end - it 'does not allow mass assignment' do - person = @user.person - new_user = Factory.create(:user) - person.owner_id.should == @user.id - put :update, :id => @user.person.id, :owner_id => new_user.id - Person.find(person.id).owner_id.should == @user.id - end - - it 'does not overwrite the profile diaspora handle' do - handle_params = {:id => @user.person.id, - :profile => {:diaspora_handle => 'abc@a.com'} } - put :update, handle_params - Person.find(@user.person.id).profile[:diaspora_handle].should_not == 'abc@a.com' - end - end end diff --git a/spec/controllers/profiles_controller_spec.rb b/spec/controllers/profiles_controller_spec.rb new file mode 100644 index 000000000..28461e091 --- /dev/null +++ b/spec/controllers/profiles_controller_spec.rb @@ -0,0 +1,86 @@ +# Copyright (c) 2010, Diaspora Inc. This file is +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. + + +require 'spec_helper' + +describe ProfilesController do + render_views + before do + @user = eve + sign_in :user, @user + end + + describe '#edit' do + it 'succeeds' do + get :edit + response.should be_success + end + + it 'sets the profile to the current users profile' do + get :edit + assigns[:profile].should == @user.person.profile + end + + it 'sets the aspect to "person_edit" ' do + get :edit + assigns[:aspect].should == :person_edit + end + + it 'sets the person to the current users person' do + get :edit + assigns[:person].should == @user.person + end + end + + + describe '#update' do + it "sets the flash" do + put :update, :profile => { + :image_url => "", + :first_name => "Will", + :last_name => "Smith" + } + flash[:notice].should_not be_empty + end + + context 'with a profile photo set' do + before do + @params = { :id => @user.person.id, + :profile => + {:image_url => "", + :last_name => @user.person.profile.last_name, + :first_name => @user.person.profile.first_name }} + + @user.person.profile.image_url = "http://tom.joindiaspora.com/images/user/tom.jpg" + @user.person.profile.save + end + it "doesn't overwrite the profile photo when an empty string is passed in" do + image_url = @user.person.profile.image_url + put :update, @params + + Person.find(@user.person.id).profile.image_url.should == image_url + end + end + + context 'mass assignment' do + before do + new_person = Factory(:person) + @profile_params = {:profile =>{ :person_id => new_person.id, + :diaspora_handle => 'abc@a.com'}} + end + it 'person_id' do + person = @user.person + profile = person.profile + put :update, @profile_params + profile.reload.person_id.should == person.id + end + + it 'diaspora handle' do + put :update, @profile_params + Person.find(@user.person.id).profile[:diaspora_handle].should_not == 'abc@a.com' + end + end + end +end