From 985d79acb5b3a7f790b6551a7e8731d66088fbcb Mon Sep 17 00:00:00 2001 From: MrZYX Date: Sat, 26 Mar 2011 17:11:25 +0100 Subject: [PATCH] some more refactoring to routes.rb --- app/helpers/requests_helper.rb | 2 +- app/views/aspects/_aspect_listings.haml | 2 +- app/views/conversations/_show.haml | 2 +- app/views/notifications/index.html.haml | 2 +- app/views/photos/show.html.haml | 2 +- app/views/users/edit.html.haml | 4 +- config/routes.rb | 174 +++++++++++-------- features/accepts_invitation.feature | 2 +- features/connects_users.feature | 14 +- features/disconnects_users.feature | 10 +- features/manages_contact_requests.feature | 2 +- spec/controllers/services_controller_spec.rb | 8 +- 12 files changed, 126 insertions(+), 98 deletions(-) diff --git a/app/helpers/requests_helper.rb b/app/helpers/requests_helper.rb index 7cb57dd13..d54a29de2 100644 --- a/app/helpers/requests_helper.rb +++ b/app/helpers/requests_helper.rb @@ -10,7 +10,7 @@ module RequestsHelper def new_request_link(request_count) if request_count > 0 - link_to t('requests.helper.new_requests', :count => @request_count), aspects_manage_path + link_to t('requests.helper.new_requests', :count => @request_count), manage_aspects_path end end end diff --git a/app/views/aspects/_aspect_listings.haml b/app/views/aspects/_aspect_listings.haml index a739a0eb9..0ca141cbe 100644 --- a/app/views/aspects/_aspect_listings.haml +++ b/app/views/aspects/_aspect_listings.haml @@ -6,7 +6,7 @@ %h4 .right - = link_to t('contacts', :count => @contact_count), aspects_manage_path, :title => t('aspects.manage.manage_aspects') + = link_to t('contacts', :count => @contact_count), manage_aspects_path, :title => t('aspects.manage.manage_aspects') = t('aspects', :count => aspects.count) diff --git a/app/views/conversations/_show.haml b/app/views/conversations/_show.haml index 0d7e7c187..76c7ccadd 100644 --- a/app/views/conversations/_show.haml +++ b/app/views/conversations/_show.haml @@ -11,7 +11,7 @@ .conversation_controls = link_to (image_tag('reply.png', :height => 14, :width => 14) + ' ' + t('.reply')), '#', :id => 'reply_to_conversation' - = link_to (image_tag('deletelabel.png') + ' ' + t('.delete').downcase), conversation_conversation_visibility_path(conversation), :method => 'delete', :confirm => t('are_you_sure') + = link_to (image_tag('deletelabel.png') + ' ' + t('.delete').downcase), conversation_visibility_path(conversation), :method => 'delete', :confirm => t('are_you_sure') .span-6.avatars.last - for participant in conversation.participants diff --git a/app/views/notifications/index.html.haml b/app/views/notifications/index.html.haml index 02f189bb3..4cc038c02 100644 --- a/app/views/notifications/index.html.haml +++ b/app/views/notifications/index.html.haml @@ -34,7 +34,7 @@ %h2 = t('.notifications') .span-13.last.left - = link_to t('.mark_all_as_read'), notifications_read_all_path, :class => 'button' + = link_to t('.mark_all_as_read'), read_all_notifications_path, :class => 'button' .span-24.last %ul.stream.notifications diff --git a/app/views/photos/show.html.haml b/app/views/photos/show.html.haml index 559fc0d3f..274fbcfb8 100644 --- a/app/views/photos/show.html.haml +++ b/app/views/photos/show.html.haml @@ -29,7 +29,7 @@ - if @ownership .photo_options{:data=>{:actor=>"#{@photo.author.owner.id}", :actor_person => "#{@photo.author.id}", :image_url => "#{@photo.url(:thumb_large)}"}} - = link_to t('.make_profile_photo'), {:controller => "photos", :action => "make_profile_photo", :photo_id => @photo.id}, :remote => true, :class => 'make_profile_photo' + = link_to t('.make_profile_photo'), {:controller => "photos", :action => "make_profile_photo", :photo_id => @photo.id}, :class => 'make_profile_photo' | = link_to t('.edit'), '#', :id => "edit_photo_toggle" %br diff --git a/app/views/users/edit.html.haml b/app/views/users/edit.html.haml index 2124c4d39..929f9122c 100644 --- a/app/views/users/edit.html.haml +++ b/app/views/users/edit.html.haml @@ -117,9 +117,9 @@ #account_data.span-5.append-2 %h3 = t('.export_data') - = link_to t('.download_xml'), users_export_path, :class => "button" + = link_to t('.download_xml'), export_user_path, :class => "button" %br - = link_to t('.download_photos'), users_export_photos_path, :class => "button" + = link_to t('.download_photos'), export_photos_user_path, :class => "button" .span-5.last %h3 diff --git a/config/routes.rb b/config/routes.rb index ad2ebf585..2390049e7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,101 +3,129 @@ # the COPYRIGHT file. Diaspora::Application.routes.draw do + + # Posting and Reading + + resources :aspects do + collection do + match 'move_contact' => :move_contact + match 'add_to_aspect' => :add_to_aspect + match 'remove_from_aspect' => :remove_from_aspect + match 'manage' => :manage + end + match 'toggle_contact_visibility' => :toggle_contact_visibility + end + resources :status_messages, :only => [:new, :create, :destroy, :show] - resources :comments, :only => [:create, :destroy] - resources :requests, :only => [:destroy, :create] - resource :likes, :only => [:create] - - match 'tags/:name' => 'tags#show' - resources :tags, :only => [:show] - - resource :profile - match 'services/inviter/:provider' => 'services#inviter', :as => 'service_inviter' - match 'services/finder/:provider' => 'services#finder', :as => 'friend_finder' - resources :services - - match 'admins/user_search' => 'admins#user_search' - match 'admins/admin_inviter' => 'admins#admin_inviter' - - match 'notifications/read_all' => 'notifications#read_all' - resources :notifications, :only => [:index, :update] - resources :posts, :only => [:show], :path => '/p/' - - resources :contacts - resources :aspect_memberships, :only => [:destroy, :create] - - - resources :conversations do - resources :messages, :only => [:create, :show] - resource :conversation_visibility, :only => [:destroy], :path => '/visibility/' - end - - resources :people, :except => [:edit, :update] do - resources :status_messages - resources :photos - end - - match '/people/by_handle' => 'people#retrieve_remote', :as => 'person_by_handle' - match '/auth/:provider/callback' => 'services#create' - match '/auth/failure' => 'services#failure' + get 'p/:id' => 'posts#show', :as => 'post' match 'photos/make_profile_photo' => 'photos#make_profile_photo' resources :photos, :except => [:index] - resource :user, :only => [:edit, :update, :destroy] + resources :comments, :only => [:create, :destroy] + + get 'tags/:name' => 'tags#show', :as => 'tag' + + resource :like, :only => [:create] + + resources :conversations do + resources :messages, :only => [:create, :show] + delete 'visibility' => 'conversation_visibilities#destroy' + end + + resources :notifications, :only => [:index, :update] do + get 'read_all' => :read_all, :on => :collection + end + + + # Users and people + + resource :user, :only => [:edit, :update, :destroy], :shallow => true do + get :export + get :export_photos + end + + controller :users do + get 'public/:username' => :public, :as => 'users_public' + match 'getting_started' => :getting_started, :as => 'getting_started' + get 'getting_started_completed' => :getting_started_completed + end # 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') + match 'users/edit' => redirect('/user/edit') devise_for :users, :controllers => {:registrations => "registrations", :password => "devise/passwords", :sessions => "sessions", :invitations => "invitations"} do - get 'invitations/resend/:id' => 'invitations#resend', :as => 'invitation_resend' - end + end + get 'login' => redirect('/users/sign_in') - - # added public route to user - match 'public/:username', :to => 'users#public', :as => 'users_public' - match 'getting_started', :to => 'users#getting_started', :as => 'getting_started' - match 'getting_started_completed', :to => 'users#getting_started_completed' - match 'users/export', :to => 'users#export' - match 'users/export_photos', :to => 'users#export_photos' - match 'login' => redirect('/users/sign_in') - - 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' - match 'aspects/remove_from_aspect',:to => 'aspects#remove_from_aspect', :as => 'remove_from_aspect' - match 'aspects/manage', :to => 'aspects#manage' - resources :aspects do - match '/toggle_contact_visibility', :to => 'aspects#toggle_contact_visibility' + scope 'admins' do + match 'user_search' => 'admins#user_search' + match 'admin_inviter' => 'admins#admin_inviter' end - #public routes - match 'webfinger', :to => 'publics#webfinger' - match 'hcard/users/:guid', :to => 'publics#hcard' - match '.well-known/host-meta',:to => 'publics#host_meta' - match 'receive/users/:guid', :to => 'publics#receive' - match 'hub', :to => 'publics#hub' + resource :profile - scope '/api/v0' do - match '/statuses/public_timeline', :to => 'apis#public_timeline' - match '/statuses/home_timeline', :to => 'apis#home_timeline' - match '/statuses/show/:guid', :to => 'apis#statuses' - match '/statuses/user_timeline', :to => 'apis#user_timeline' + resources :requests, :only => [:destroy, :create] - match '/users/show', :to => 'apis#users' - match '/users/search', :to => 'apis#users_search' - match '/users/profile_image', :to => 'apis#users_profile_image' + resources :contacts, :except => [:index, :update] + resources :aspect_memberships, :only => [:destroy, :create] - match '/tags_posts/:tag', :to => 'apis#tag_posts' - match '/tags_people/:tag', :to => 'apis#tag_people' + resources :people, :except => [:edit, :update] do + resources :status_messages + resources :photos + end + match 'people/by_handle' => 'people#retrieve_remote', :as => 'person_by_handle' + + + # Federation + + controller :publics do + get 'webfinger' => :webfinger + get 'hcard/users/:guid' => :hcard + get '.well-known/host-meta' => :host_meta + get 'receive/users/:guid' => :receive + get 'hub' => :hub end - match'localize', :to => "localize#show" + + # External + + resources :services, :only => [:index, :destroy] + controller :services do + match '/auth/:provider/callback' => :create + match '/auth/failure' => :failure + scope 'services' do + match 'inviter/:provider' => :inviter, :as => 'service_inviter' + match 'finder/:provider' => :finder, :as => 'friend_finder' + end + end + + scope 'api/v0', :controller => :apis do + match 'statuses/public_timeline' => :public_timeline + match 'statuses/home_timeline' => :home_timeline + match 'statuses/show/:guid' => :statuses + match 'statuses/user_timeline' => :user_timeline + + match 'users/show' => :users + match 'users/search' => :users_search + match 'users/profile_image' => :users_profile_image + + match 'tags_posts/:tag' => :tag_posts + match 'tags_people/:tag' => :tag_people + end + + + # Mobile site + match 'mobile/toggle', :to => 'home#toggle_mobile', :as => 'toggle_mobile' - #root + + + # Startpage + root :to => 'home#show' end diff --git a/features/accepts_invitation.feature b/features/accepts_invitation.feature index 6bc449742..acec36611 100644 --- a/features/accepts_invitation.feature +++ b/features/accepts_invitation.feature @@ -44,7 +44,7 @@ Feature: invitation acceptance And I wait for the ajax to finish When I go to the home page - Then I go to the aspects manage page + Then I go to the manage aspects page Then I should see 1 contact in "Family" diff --git a/features/connects_users.feature b/features/connects_users.feature index 596fccc26..9d0b7c262 100644 --- a/features/connects_users.feature +++ b/features/connects_users.feature @@ -12,19 +12,19 @@ Feature: sending and receiving requests Scenario: accepting a contact request When I sign in as "alice@alice.alice" - And I am on the aspects manage page + And I am on the manage aspects page Then I should see 1 contact request When I drag the contact request to the "Besties" aspect And I wait for the ajax to finish Then I should see 1 contact in "Besties" When I go to the home page - Then I go to the aspects manage page + Then I go to the manage aspects page Then I should see 1 contact in "Besties" Then I go to the destroy user session page When I sign in as "bob@bob.bob" - And I am on the aspects manage page + And I am on the manage aspects page Then I should see 1 contact in "Besties" Scenario: accepting a contact request to multiple aspects @@ -37,14 +37,14 @@ Feature: sending and receiving requests And I wait for the ajax to finish When I go to the home page - Then I go to the aspects manage page + Then I go to the manage aspects page Then I should see 1 contact in "Unicorns" Then I should see 1 contact in "Besties" Then I go to the destroy user session page When I sign in as "bob@bob.bob" - And I am on the aspects manage page + And I am on the manage aspects page Then I should see 1 contact in "Besties" @@ -58,11 +58,11 @@ Feature: sending and receiving requests And I wait for the ajax to finish When I go to the home page - Then I go to the aspects manage page + Then I go to the manage aspects page Then I should see 1 contact in "Super People" Then I go to the destroy user session page When I sign in as "bob@bob.bob" - And I am on the aspects manage page + And I am on the manage aspects page Then I should see 1 contact in "Besties" diff --git a/features/disconnects_users.feature b/features/disconnects_users.feature index d1dc36b8d..68516074d 100644 --- a/features/disconnects_users.feature +++ b/features/disconnects_users.feature @@ -9,7 +9,7 @@ Feature: disconnecting users And a user with email "alice@alice.alice" And a user with email "bob@bob.bob" is connected with "alice@alice.alice" When I sign in as "bob@bob.bob" - And I am on the aspects manage page + And I am on the manage aspects page Then I should see 1 contact in "Besties" @@ -20,7 +20,7 @@ Feature: disconnecting users And I follow "remove contact" in the modal window And I wait for the ajax to finish - And I am on the aspects manage page + And I am on the manage aspects page Then I should see in "Besties" Examples: @@ -35,7 +35,7 @@ Feature: disconnecting users And I press the first ".added" within "#facebox #aspects_list ul > li:first-child" And I wait for the ajax to finish - And I am on the aspects manage page + And I am on the manage aspects page Then I should see in "Besties" Examples: @@ -52,7 +52,7 @@ Feature: disconnecting users And I press the first ".added" within "#facebox .contact_list ul > li:first-child" And I wait for the ajax to finish - And I am on the aspects manage page + And I am on the manage aspects page Then I should see no contacts in "Besties" Scenario: cancel removing contact from the contact show page @@ -64,6 +64,6 @@ Feature: disconnecting users And I press the first ".added" within "#facebox .contact_list ul > li:first-child" And I wait for the ajax to finish - And I am on the aspects manage page + And I am on the manage aspects page Then I should see 1 contact in "Besties" diff --git a/features/manages_contact_requests.feature b/features/manages_contact_requests.feature index cd8272a61..390b579f1 100644 --- a/features/manages_contact_requests.feature +++ b/features/manages_contact_requests.feature @@ -14,7 +14,7 @@ Feature: managing contact requests @javascript Scenario: viewing a requests profile - When I am on the aspects manage page + When I am on the manage aspects page When I click on the contact request And I wait for "the requestors profile" to load Then I should be on the requestors profile diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 8d952b1c0..1c50558b6 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -42,21 +42,21 @@ describe ServicesController do it 'creates a new OmniauthService' do request.env['omniauth.auth'] = omniauth_auth lambda{ - post :create + post :create, :provider => 'twitter' }.should change(@user.services, :count).by(1) end it 'redirects to getting started if the user is getting started' do @user.getting_started = true request.env['omniauth.auth'] = omniauth_auth - post :create + post :create, :provider => 'twitter' response.should redirect_to getting_started_path(:step => 3) end it 'redirects to services url' do @user.getting_started = false request.env['omniauth.auth'] = omniauth_auth - post :create + post :create, :provider => 'twitter' response.should redirect_to services_url end @@ -65,7 +65,7 @@ describe ServicesController do Service.delete_all @user.getting_started = false request.env['omniauth.auth'] = omniauth_auth - post :create + post :create, :provider => 'twitter' @user.reload.services.first.class.name.should == "Services::Twitter" end end