diff --git a/app/helpers/likes_helper.rb b/app/helpers/likes_helper.rb index 445e7eb69..03d00aa6a 100644 --- a/app/helpers/likes_helper.rb +++ b/app/helpers/likes_helper.rb @@ -4,7 +4,7 @@ module LikesHelper def likes_list(likes) - links = likes.collect { |like| link_to "#{h(like.author.name.titlecase)}", person_path(like.author) } + links = likes.collect { |like| link_to "#{h(like.author.name.titlecase)}", local_or_remote_person_path(like.author) } links.join(", ").html_safe end diff --git a/app/helpers/people_helper.rb b/app/helpers/people_helper.rb index 49e656ba8..f052e8697 100644 --- a/app/helpers/people_helper.rb +++ b/app/helpers/people_helper.rb @@ -52,17 +52,30 @@ module PeopleHelper end def person_href(person, opts={}) - if opts[:absolute] - link = "href='#{AppConfig.pod_url}" - else - link = "href='/" - end + "href=\"#{local_or_remote_person_path(person, opts)}\"" + end + + + # Rails.application.routes.url_helpers is needed since this is indirectly called from a model + def local_or_remote_person_path(person, opts={}) + opts.merge!(:protocol => AppConfig[:pod_uri].scheme, :host => AppConfig[:pod_uri].authority) + if person.local? username = person.diaspora_handle.split('@')[0] unless username.include?('.') - return link+"u/#{person.diaspora_handle.split('@')[0]}'" + opts.merge!(:username => username) + if opts[:absolute] + return Rails.application.routes.url_helpers.user_profile_url(opts) + else + return Rails.application.routes.url_helpers.user_profile_path(opts) + end end end - return link+"people/#{person.id}'" + + if opts[:absolute] + return Rails.application.routes.url_helpers.person_url(person, opts) + else + return Rails.application.routes.url_helpers.person_path(person, opts) + end end end diff --git a/app/helpers/stream_helper.rb b/app/helpers/stream_helper.rb index 5ed677a7a..83561dfb6 100644 --- a/app/helpers/stream_helper.rb +++ b/app/helpers/stream_helper.rb @@ -9,7 +9,7 @@ module StreamHelper elsif controller.instance_of?(AppsController) "/apps/1?#{{:max_time => @posts.last.created_at.to_i}.to_param}" elsif controller.instance_of?(PeopleController) - person_path(@person, :max_time => time_for_scroll(opts[:ajax_stream], @stream)) + local_or_remote_person_path(@person, :max_time => time_for_scroll(opts[:ajax_stream], @stream)) elsif controller.instance_of?(TagFollowingsController) tag_followings_path(:max_time => time_for_scroll(opts[:ajax_stream], @stream), :sort_order => session[:sort_order]) elsif controller.instance_of?(CommunitySpotlightController) diff --git a/app/mailers/notifier.rb b/app/mailers/notifier.rb index 851595084..f9c4ad044 100644 --- a/app/mailers/notifier.rb +++ b/app/mailers/notifier.rb @@ -2,6 +2,7 @@ class Notifier < ActionMailer::Base helper :application helper :markdownify helper :notifier + helper :people def self.admin(string, recipients, opts = {}) mails = [] diff --git a/app/views/aspects/index.html.haml b/app/views/aspects/index.html.haml index 61cf89b7b..52af3a682 100644 --- a/app/views/aspects/index.html.haml +++ b/app/views/aspects/index.html.haml @@ -26,7 +26,7 @@ #home_user_badge = owner_image_link %h4 - = link_to current_user.first_name, "/u/#{current_user.username}" + = link_to current_user.first_name, local_or_remote_person_path(current_user.person) .section %ul.left_nav diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml index 8776e8576..f1e3eb9d0 100644 --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -70,7 +70,7 @@ .avatar = owner_image_tag(:thumb_small) = link_to current_user.name, '#', :title => current_user.diaspora_handle - %li= link_to t('.profile'), current_user.person + %li= link_to t('.profile'), local_or_remote_person_path(current_user.person) %li= link_to t('_contacts'), contacts_link %li= link_to t('.settings'), edit_user_path -if current_user.admin? diff --git a/app/views/notifier/started_sharing.html.haml b/app/views/notifier/started_sharing.html.haml index fc46992ee..71c884d33 100644 --- a/app/views/notifier/started_sharing.html.haml +++ b/app/views/notifier/started_sharing.html.haml @@ -2,4 +2,4 @@ = @notification.sender.name = t('.sharing') %p - = link_to t('.view_profile', :name => @notification.sender.first_name), person_url(@notification.sender) + = link_to t('.view_profile', :name => @notification.sender.first_name), local_or_remote_person_path(@notification.sender, :absolute => true) diff --git a/app/views/notifier/started_sharing.text.haml b/app/views/notifier/started_sharing.text.haml index 97f1692d6..1fb5b5d61 100644 --- a/app/views/notifier/started_sharing.text.haml +++ b/app/views/notifier/started_sharing.text.haml @@ -1,4 +1,4 @@ != "#{@notification.sender.name}" != t('notifier.started_sharing.sharing') != t('.view_profile', :name => @notification.sender.first_name) -!= person_url(@notification.sender) +!= local_or_remote_person_path(@notification.sender, :absolute => true) diff --git a/app/views/people/_person.mobile.haml b/app/views/people/_person.mobile.haml index ea94b06cb..2a8b17520 100644 --- a/app/views/people/_person.mobile.haml +++ b/app/views/people/_person.mobile.haml @@ -10,4 +10,4 @@ =person_link(person) .info - = link_to person.diaspora_handle, person_path(person), :class => 'black' + = link_to person.diaspora_handle, local_or_remote_person_path(person), :class => 'black' diff --git a/app/views/profiles/edit.haml b/app/views/profiles/edit.haml index 69ccd8cca..ba18f9105 100644 --- a/app/views/profiles/edit.haml +++ b/app/views/profiles/edit.haml @@ -10,7 +10,7 @@ .span-12.prepend-5.last - content_for :submit_block do - = link_to t('cancel'), person_path(current_user.person), :class => "button" + = link_to t('cancel'), local_or_remote_person_path(current_user.person), :class => "button" = submit_tag t('.update_profile'), :class => "creation" = render :partial => 'edit', :locals => {:person => @person, :profile => @profile, :aspect => @aspect, :step => @step} diff --git a/app/views/services/_remote_friend.html.haml b/app/views/services/_remote_friend.html.haml index 4008dfc11..22e0b10e7 100644 --- a/app/views/services/_remote_friend.html.haml +++ b/app/views/services/_remote_friend.html.haml @@ -16,7 +16,7 @@ .content %span.from.name - if friend.on_diaspora? - = link_to friend.name, person_path(friend.person) + = link_to friend.name, local_or_remote_person_path(friend.person) - else = friend.name diff --git a/app/views/shared/_author_info.html.haml b/app/views/shared/_author_info.html.haml index 7e86d01fb..168107638 100644 --- a/app/views/shared/_author_info.html.haml +++ b/app/views/shared/_author_info.html.haml @@ -5,5 +5,5 @@ = person.name #person_nav_links - = link_to t('layouts.header.profile'), person_path(person) + = link_to t('layouts.header.profile'), local_or_remote_person_path(person) = link_to t('_photos'), person_photos_path(person) diff --git a/spec/helpers/people_helper_spec.rb b/spec/helpers/people_helper_spec.rb index 22a2d841d..d97038d64 100644 --- a/spec/helpers/people_helper_spec.rb +++ b/spec/helpers/people_helper_spec.rb @@ -59,10 +59,25 @@ describe PeopleHelper do end end - describe '#person_href' do + describe "#person_href" do + it "calls local_or_remote_person_path and passes through the options" do + opts = {:absolute => true} + + self.should_receive(:local_or_remote_person_path).with(@person, opts).exactly(1).times + + person_href(@person, opts) + end + + it "returns a href attribute" do + person_href(@person).should include "href=" + end + end + + describe '#local_or_remote_person_path' do before do @user = Factory(:user) end + it "links by id if there is a period in the user's username" do @user.username = "invalid.username" @user.save(:validate => false).should == true @@ -70,17 +85,16 @@ describe PeopleHelper do person.diaspora_handle = "#{@user.username}@#{AppConfig[:pod_uri].authority}" person.save! - person_href(@user.person).should include("href='/people/#{@user.person.id}'") + local_or_remote_person_path(@user.person).should == person_path(@user.person) end it 'links by username for a local user' do - person_href(@user.person).should include(@user.username) + local_or_remote_person_path(@user.person).should == user_profile_path(:username => @user.username) end + it 'links by id for a remote person' do - person = Factory(:person) - person_href(person).should include("/people/#{person.id}") + local_or_remote_person_path(@person).should == person_path(@person) end end - end