cleaned up craziness in users and likes routing, fixed #961

This commit is contained in:
MrZYX 2011-03-24 00:52:31 +01:00
parent 33c013633f
commit 56a6f0e43b
20 changed files with 56 additions and 60 deletions

View file

@ -22,7 +22,7 @@ class ProfilesController < ApplicationController
if params[:getting_started]
redirect_to getting_started_path(:step => params[:getting_started].to_i+1)
else
redirect_to current_user.person
redirect_to edit_profile_path
end
else
flash[:error] = I18n.t 'profiles.update.failed'

View file

@ -58,7 +58,7 @@ class UsersController < ApplicationController
render :nothing => true, :status => 204
}
format.all{
redirect_to edit_user_path(@user)
redirect_to edit_user_path
}
end
end

View file

@ -110,17 +110,6 @@ module ApplicationHelper
timeago(obj.created_at)
end
def person_url(person)
case person.class.to_s
when "User"
user_path(person)
when "Person"
person_path(person)
else
I18n.t('application.helper.unknown_person')
end
end
def profile_photo(person)
person_image_link(person, :size => :thumb_large, :to => :photos)
end

View file

@ -40,7 +40,7 @@
= owner_image_tag(:thumb_small)
= link_to current_user.name, '#'
%li= link_to t('.profile'), current_user.person
%li= link_to t('.settings'), edit_user_path(current_user)
%li= link_to t('.settings'), edit_user_path
%li= link_to t('.logout'), destroy_user_session_path
-unless @landing_page

View file

@ -8,5 +8,5 @@
= image_tag attachments['logo_caps.png'].url, :alt => "DIASPORA"
#container
= yield
%a{:href => "http://#{ AppConfig[:pod_uri].host}/users/#{@receiver.id}/edit"}
%a{:href => "#{AppConfig[:pod_uri].scheme}://#{AppConfig[:pod_uri].host}#{edit_user_path}"}
= t('notifier.manage_your_email_settings')

View file

@ -1,3 +1,3 @@
!= yield
!= t('notifier.manage_your_email_settings')
!= "www.#{ AppConfig[:pod_uri].host}/users/#{@receiver.id}/edit"
!= "#{AppConfig[:pod_uri].scheme}://#{AppConfig[:pod_uri].host}#{edit_user_path}"

View file

@ -69,9 +69,9 @@
// TODO(likes)
/- if (defined?(current_user) && !current_user.liked?(@parent))
/ %span.like_links
/ = link_to t('shared.stream_element.like'), {:controller => "likes", :action => "create", :positive => 'true', :post_id => @parent.id }, :class => "like_it", :remote => true
/ = link_to t('shared.stream_element.like'), likes_path(:positive => 'true', :post_id => @parent.id), :method => :post, :class => "like_it", :remote => true
/ |
/ = link_to t('shared.stream_element.dislike'), {:controller => "likes", :action => "create", :positive => 'false', :post_id => @parent.id }, :class => "dislike_it", :remote => true
/ = link_to t('shared.stream_element.dislike'), likes_path(:positive => 'false', :post_id => @parent.id), :method => :post, :class => "dislike_it", :remote => true
%div{:data=>{:guid=>@parent.id}}
.likes_container

View file

@ -5,7 +5,7 @@
- content_for :page_title do
= t('.edit_profile')
= form_tag profile_path(profile), :method => :put, :multipart => true, :id => 'update_profile_form' do
= form_tag profile_path, :method => :put, :multipart => true, :id => 'update_profile_form' do
= render 'profiles/edit_public', :profile => profile, :aspect => aspect, :person => person
%hr

View file

@ -6,10 +6,7 @@
#section_header
%h2
= t('settings')
%ul#settings_nav
%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
= render 'shared/settings_nav'
.span-12.prepend-5.last
- content_for :submit_block do

View file

@ -8,10 +8,7 @@
#section_header
%h2
= t('settings')
%ul#settings_nav
%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
= render 'shared/settings_nav'
.span-19.prepend-5.last
%h2

View file

@ -0,0 +1,4 @@
%ul#settings_nav
%li=link_to t('profile'), edit_profile_path
%li=link_to t('account'), edit_user_path
%li=link_to t('_services'), services_path

View file

@ -37,9 +37,9 @@
/- if (defined?(current_user) && !current_user.liked?(post))
/ %span.like_links
/ |
/ = link_to t('.like'), {:controller => "likes", :action => "create", :positive => 'true', :post_id => post.id }, :class => "like_it", :remote => true
/ = link_to t('.like'), likes_path(:positive => 'true', :post_id => post.id ), :method => :post, :class => "like_it", :remote => true
/ |
/ = link_to t('.dislike'), {:controller => "likes", :action => "create", :positive => 'false', :post_id => post.id }, :class => "dislike_it", :remote => true
/ = link_to t('.dislike'), likes_path(:positive => 'false', :post_id => post.id), :method => :post, :class => "dislike_it", :remote => true
/.likes_container
/ = render "likes/likes", :post_id => post.id, :likes => post.likes, :dislikes => post.dislikes, :current_user => current_user

View file

@ -8,10 +8,7 @@
#section_header
%h2
= t('settings')
%ul#settings_nav
%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
= render 'shared/settings_nav'
.span-12.prepend-5.last
%h2
@ -35,7 +32,7 @@
%h3
= t('.change_password')
= form_for @user do |f|
= form_for 'user', :url => user_path, :html => { :method => :put } do |f|
= f.error_messages
%p
@ -49,7 +46,7 @@
= f.password_field :password_confirmation
.submit_block
= link_to t('cancel'), edit_user_path(current_user)
= link_to t('cancel'), edit_user_path
= t('or')
= f.submit t('.change_password')
@ -60,7 +57,7 @@
%h3
= t('.change_language')
= form_for @user do |f|
= form_for 'user', :url => user_path, :html => { :method => :put } do |f|
= f.error_messages
%p
@ -74,7 +71,7 @@
%h3
= t('.receive_email_notifications')
= form_for @user do |f|
= form_for 'user', :url => user_path, :html => { :method => :put } do |f|
= f.error_messages
= f.fields_for :email_preferences do |type|
@ -127,6 +124,6 @@
.span-5.last
%h3
= t('.close_account')
= link_to t('.close_account'), current_user,
= link_to t('.close_account'), user_path,
:confirm => t('are_you_sure'), :method => :delete,
:class => "button"

View file

@ -6,8 +6,7 @@ Diaspora::Application.routes.draw do
resources :status_messages, :only => [:new, :create, :destroy, :show]
resources :comments, :only => [:create]
resources :requests, :only => [:destroy, :create]
match '/likes' => 'likes#create'
resources :likes, :only => [:create]
resource :likes, :only => [:create]
match 'tags/:name' => 'tags#show'
resources :tags, :only => [:show]
@ -45,6 +44,12 @@ Diaspora::Application.routes.draw do
match 'photos/make_profile_photo' => 'photos#make_profile_photo'
resources :photos, :except => [:index]
resource :user, :only => [:edit, :update, :destroy]
# This is a hack to overide a route created by devise.
# I couldn't find anything in devise to skip that route, see Bug #961
match '/users/edit' => redirect('/user/edit')
devise_for :users, :controllers => {:registrations => "registrations",
:password => "devise/passwords",
:sessions => "sessions",
@ -61,7 +66,6 @@ Diaspora::Application.routes.draw do
match 'users/export', :to => 'users#export'
match 'users/export_photos', :to => 'users#export_photos'
match 'login' => redirect('/users/sign_in')
resources :users, :except => [:create, :new, :show]
match 'aspects/move_contact', :to => 'aspects#move_contact', :as => 'move_contact'
match 'aspects/add_to_aspect', :to => 'aspects#add_to_aspect', :as => 'add_to_aspect'

View file

@ -11,22 +11,23 @@ Feature: editing your profile
Scenario: editing gender with a textbox
When I fill in "profile_gender" with "Fearless"
And I press "Update Profile"
Then I should be on my profile page
Then I should be on my edit profile page
And I should see "Profile updated"
And I should see "Fearless"
And the "profile_gender" field should contain "Fearless"
Scenario: editing name
When I fill in "profile_first_name" with "Boba"
And I fill in "profile_last_name" with "Fett"
And I press "Update Profile"
Then I should be on my profile page
Then I should be on my edit profile page
And I should see "Profile updated"
And I should see "Boba Fett"
And the "profile_first_name" field should contain "Boba"
And the "profile_last_name" field should contain "Fett"
Scenario: edit bio
When I fill in "profile_bio" with "This is a bio"
And I press "Update Profile"
Then I should be on my profile page
Then I should be on my edit profile page
And I should see "Profile updated"
And I should see "This is a bio"
@ -35,6 +36,8 @@ Feature: editing your profile
And I select "November" from "profile_date_month"
And I select "30" from "profile_date_day"
And I press "Update Profile"
Then I should be on my profile page
Then I should be on my edit profile page
And I should see "Profile updated"
Then I should see "November 30 1986"
And the "profile_date_year" field should be filled with "1986"
And the "profile_date_month" field should be filled with "November"
And the "profile_date_day" field should be filled with "30"

View file

@ -165,4 +165,17 @@ end
When /^I click on the add contact button$/ do
page.execute_script("$('.add_contact a').click();")
end
end
Then /^the "([^"]*)" field(?: within "([^"]*)")? should be filled with "([^"]*)"$/ do |field, selector, value|
with_scope(selector) do
field = find_field(field)
field_value = (field.tag_name == 'textarea') ? field.text : field.value
field_value = field_value.first if field_value.is_a? Array
if field_value.respond_to? :should
field_value.should == value
else
assert_equal(value, field_value)
end
end
end

View file

@ -26,7 +26,7 @@ module NavigationHelpers
when /^"([^\"]*)"'s page$/
person_path(User.find_by_email($1).person)
when /^my account settings page$/
edit_user_path(@me)
edit_user_path
when /^the photo page for "([^\"]*)"'s post "([^\"]*)"$/
photo_path(User.find_by_email($1).posts.find_by_text($2))
when /^"(\/.*)"/

View file

@ -107,7 +107,7 @@ $(document).ready(function(){
function performAspectUpdate(home){
// update the open aspects in the user
updateURL = "/users/me";
updateURL = "/user";
updateURL += '?';
if(home == 'home'){
updateURL += 'user[a_ids][]=home';

View file

@ -50,7 +50,7 @@ describe UsersController do
it 'redirects to the user edit page' do
put :update, @params
response.should redirect_to edit_user_path(@user)
response.should redirect_to edit_user_path
end
it 'responds with a 204 on a js request' do

View file

@ -10,14 +10,6 @@ describe ApplicationHelper do
@person = Factory.create(:person)
end
it "should provide a correct show path for a given person" do
person_url(@person).should == "/people/#{@person.id}"
end
it "should provide a correct show path for a given user" do
person_url(@user).should == "/users/#{@user.id}"
end
describe "#object_path" do
it "returns an empty string if object is nil" do
object_path(nil).should == ""