Fix 500 on tags index

This commit is contained in:
Raphael Sofaer 2011-03-30 12:43:44 -07:00
parent d97939a18f
commit 5c7bd6298a
3 changed files with 21 additions and 10 deletions

View file

@ -10,14 +10,14 @@ class TagsController < ApplicationController
respond_to :html, :only => [:show]
respond_to :json, :only => [:index]
def index
params[:q].gsub!("#", "")
params[:limit] = !params[:limit].blank? ? params[:limit].to_i : 10
if params[:q].length > 1
if params[:q] && params[:q].length > 1
params[:q].gsub!("#", "")
params[:limit] = !params[:limit].blank? ? params[:limit].to_i : 10
@tags = ActsAsTaggableOn::Tag.named_like(params[:q]).limit(params[:limit] - 1)
@array = []
@tags.each do |obj|
@tags.each do |obj|
@array << { :name => ("#"+obj.name),
:value => ("#"+obj.name)}
end
@ -31,7 +31,10 @@ class TagsController < ApplicationController
}
end
else
render :nothing => true
respond_to do |format|
format.json{ render :nothing => true, :status => 422 }
format.html{ redirect_to tag_path('partytimeexcellent') }
end
end
end

View file

@ -63,9 +63,9 @@ class Person < ActiveRecord::Base
tokens.concat([token, token, token])
tokens.concat([up_token, up_token])
end
[sql, tokens]
[sql, tokens]
end
def self.search(query, user)
return [] if query.to_s.blank? || query.to_s.length < 3

View file

@ -10,7 +10,7 @@ describe TagsController do
before do
@user = alice
end
describe '#index (search)' do
before do
sign_in :user, @user
@ -30,8 +30,16 @@ describe TagsController do
get :index, :q => "c", :format => 'json'
response.body.should_not include("#cats")
end
it 'redirects the aimless to excellent parties' do
get :index
response.should redirect_to tag_path('partytimeexcellent')
end
it 'does not allow json requestors to party' do
get :index, :format => :json
response.status.should == 422
end
end
describe '#show' do