Fixes #2713 - searching for punctuation now doesn't throw a 500. Refactored people#index specs.
This commit is contained in:
parent
7d4a81560d
commit
d40746bff7
4 changed files with 101 additions and 87 deletions
|
|
@ -46,6 +46,7 @@ class PeopleController < ApplicationController
|
|||
else
|
||||
people = Person.search(params[:q], current_user)
|
||||
end
|
||||
@normalized_tag_for_query = ActsAsTaggableOn::Tag.normalize(params[:q])
|
||||
@people = people.paginate( :page => params[:page], :per_page => 15)
|
||||
@hashes = hashes_for_people(@people, @aspects)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
# Copyright (c) 2010-2011, Diaspora Inc. This file is
|
||||
# licensed under the Affero General Public License version 3 or later. See
|
||||
# the COPYRIGHT file.
|
||||
|
||||
module TagsHelper
|
||||
def tag_page_link(tag)
|
||||
tag_name = ActsAsTaggableOn::Tag.normalize(tag)
|
||||
link_to("##{tag_name}", tag_path(:name => tag_name))
|
||||
end
|
||||
end
|
||||
|
|
@ -18,9 +18,10 @@
|
|||
=t('.results_for')
|
||||
%span.term
|
||||
= params[:q]
|
||||
%h4
|
||||
%small
|
||||
= t('.looking_for', :tag_link => tag_page_link(params[:q])).html_safe
|
||||
- if @normalized_tag_for_query.present?
|
||||
%h4
|
||||
%small
|
||||
= t('.looking_for', :tag_link => link_to("##{@normalized_tag_for_query}", tag_path(:name => @normalized_tag_for_query))).html_safe
|
||||
.span-15
|
||||
%hr
|
||||
.clearfix
|
||||
|
|
|
|||
|
|
@ -14,92 +14,114 @@ describe PeopleController do
|
|||
describe '#index (search)' do
|
||||
before do
|
||||
@eugene = Factory(:person,
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene", :last_name => "w"))
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene", :last_name => "w"))
|
||||
@korth = Factory(:person,
|
||||
:profile => Factory.build(:profile, :first_name => "Evan", :last_name => "Korth"))
|
||||
:profile => Factory.build(:profile, :first_name => "Evan", :last_name => "Korth"))
|
||||
end
|
||||
|
||||
it 'responds with json' do
|
||||
get :index, :q => "Korth", :format => 'json'
|
||||
response.body.should == [@korth].to_json
|
||||
describe 'via json' do
|
||||
it 'succeeds' do
|
||||
get :index, :q => "Korth", :format => 'json'
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'responds with json' do
|
||||
get :index, :q => "Korth", :format => 'json'
|
||||
response.body.should == [@korth].to_json
|
||||
end
|
||||
|
||||
it 'does not assign hashes' do
|
||||
get :index, :q => "Korth", :format => 'json'
|
||||
assigns[:hashes].should be_nil
|
||||
end
|
||||
end
|
||||
|
||||
it 'does not set @hashes in a json request' do
|
||||
get :index, :q => "Korth", :format => 'json'
|
||||
assigns[:hashes].should be_nil
|
||||
end
|
||||
describe 'via html' do
|
||||
context 'query is a diaspora ID' do
|
||||
before do
|
||||
@unsearchable_eugene = Factory(:person, :diaspora_handle => "eugene@example.org",
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
:last_name => "w", :searchable => false))
|
||||
end
|
||||
it 'finds people even if they have searchable off' do
|
||||
get :index, :q => "eugene@example.org"
|
||||
assigns[:people][0].id.should == @unsearchable_eugene.id
|
||||
end
|
||||
|
||||
it 'sets @hashes in an html request' do
|
||||
get :index, :q => "Korth"
|
||||
assigns[:hashes].should_not be_nil
|
||||
end
|
||||
it 'downcases the query term' do
|
||||
get :index, :q => "Eugene@Example.ORG"
|
||||
assigns[:people][0].id.should == @unsearchable_eugene.id
|
||||
end
|
||||
end
|
||||
|
||||
it "assigns people" do
|
||||
eugene2 = Factory(:person,
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
:last_name => "w"))
|
||||
get :index, :q => "Eug"
|
||||
assigns[:people].map{|x| x.id}.should =~ [@eugene.id, eugene2.id]
|
||||
end
|
||||
context 'query is a tag' do
|
||||
it 'goes to a tag page' do
|
||||
get :index, :q => '#babies'
|
||||
response.should redirect_to(tag_path('babies', :q => '#babies'))
|
||||
end
|
||||
|
||||
it "excludes people that are not searchable" do
|
||||
eugene2 = Factory(:person,
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
:last_name => "w", :searchable => false))
|
||||
get :index, :q => "Eug"
|
||||
assigns[:people].should_not =~ [eugene2]
|
||||
end
|
||||
it 'removes dots from the query' do
|
||||
get :index, :q => '#babi.es'
|
||||
response.should redirect_to(tag_path('babies', :q => '#babi.es'))
|
||||
end
|
||||
|
||||
it "allows unsearchable people to be found by handle" do
|
||||
eugene2 = Factory(:person, :diaspora_handle => "eugene@example.org",
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
:last_name => "w", :searchable => false))
|
||||
get :index, :q => "eugene@example.org"
|
||||
assigns[:people][0].id.should == eugene2.id
|
||||
end
|
||||
it 'stay on the page if you search for the empty hash' do
|
||||
get :index, :q => '#'
|
||||
flash[:error].should be_present
|
||||
end
|
||||
end
|
||||
|
||||
it "allows unsearchable people to be found by handle" do
|
||||
d_id = "eugene@example.org"
|
||||
@controller.should_receive(:diaspora_id?).with(d_id)
|
||||
get :index, :q => d_id
|
||||
end
|
||||
context 'query is not a tag or a diaspora ID' do
|
||||
it 'assigns hashes' do
|
||||
get :index, :q => "Korth"
|
||||
assigns[:hashes].should_not be_nil
|
||||
end
|
||||
|
||||
it "downcases the handle before trying to find someone by it" do
|
||||
eugene2 = Factory(:person, :diaspora_handle => "eugene@example.org",
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
:last_name => "w", :searchable => false))
|
||||
get :index, :q => "Eugene@Example.ORG"
|
||||
assigns[:people][0].id.should == eugene2.id
|
||||
end
|
||||
it "assigns people" do
|
||||
eugene2 = Factory(:person,
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
:last_name => "w"))
|
||||
get :index, :q => "Eug"
|
||||
assigns[:people].map { |x| x.id }.should =~ [@eugene.id, eugene2.id]
|
||||
end
|
||||
|
||||
it "does not redirect to person page if there is exactly one match" do
|
||||
get :index, :q => "Korth"
|
||||
response.should_not redirect_to @korth
|
||||
end
|
||||
it "assigns a normalized tag" do
|
||||
get :index, :q => "foo"
|
||||
assigns[:normalized_tag_for_query].should == "foo"
|
||||
end
|
||||
|
||||
it "does not redirect if there are no matches" do
|
||||
get :index, :q => "Korthsauce"
|
||||
response.should_not be_redirect
|
||||
end
|
||||
it "succeeds if there is exactly one match" do
|
||||
get :index, :q => "Korth"
|
||||
assigns[:people].length.should == 1
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'goes to a tag page if you search for a hash' do
|
||||
get :index, :q => '#babies'
|
||||
response.should redirect_to(tag_path('babies', :q => '#babies'))
|
||||
end
|
||||
it "succeeds if there are no matches" do
|
||||
get :index, :q => "Korthsauce"
|
||||
assigns[:people].length.should == 0
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'goes to a tag page if you search for a hash with dots' do
|
||||
get :index, :q => '#babi.es'
|
||||
response.should redirect_to(tag_path('babies', :q => '#babi.es'))
|
||||
end
|
||||
it 'succeeds if you search for the empty term' do
|
||||
get :index, :q => ''
|
||||
assigns[:normalized_tag_for_query].should be_empty
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'stay on the page if you search for the empty hash' do
|
||||
get :index, :q => '#'
|
||||
flash[:error].should be_present
|
||||
end
|
||||
it 'succeeds if you search for punctuation' do
|
||||
get :index, :q => '+'
|
||||
assigns[:normalized_tag_for_query].should be_empty
|
||||
response.should be_success
|
||||
end
|
||||
|
||||
it 'does not fails if you search for the empty term' do
|
||||
get :index, :q => ''
|
||||
response.should be_success
|
||||
it "excludes people who have searchable off" do
|
||||
eugene2 = Factory(:person,
|
||||
:profile => Factory.build(:profile, :first_name => "Eugene",
|
||||
:last_name => "w", :searchable => false))
|
||||
get :index, :q => "Eug"
|
||||
assigns[:people].should_not =~ [eugene2]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -243,7 +265,7 @@ describe PeopleController do
|
|||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||
get :show, :id => @user.person.to_param
|
||||
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
|
||||
assigns[:stream].posts.map { |x| x.id }.should include(reshare.id)
|
||||
end
|
||||
|
||||
it "assigns only public posts" do
|
||||
|
|
@ -253,7 +275,7 @@ describe PeopleController do
|
|||
|
||||
it 'is sorted by created_at desc' do
|
||||
get :show, :id => @person.to_param
|
||||
assigns[:stream].stream_posts.should == @public_posts.sort_by{|p| p.created_at}.reverse
|
||||
assigns[:stream].stream_posts.should == @public_posts.sort_by { |p| p.created_at }.reverse
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -298,7 +320,7 @@ describe PeopleController do
|
|||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||
get :show, :id => @user.person.to_param
|
||||
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
|
||||
assigns[:stream].posts.map { |x| x.id }.should include(reshare.id)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -331,7 +353,7 @@ describe PeopleController do
|
|||
it "posts include reshares" do
|
||||
reshare = @user.post(:reshare, :public => true, :root_guid => Factory(:status_message, :public => true).guid, :to => alice.aspects)
|
||||
get :show, :id => @user.person.to_param
|
||||
assigns[:stream].posts.map{|x| x.id}.should include(reshare.id)
|
||||
assigns[:stream].posts.map { |x| x.id }.should include(reshare.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue