diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 05ff9a2fa..ad88aea26 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -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 diff --git a/app/models/person.rb b/app/models/person.rb index 982f579da..99925857f 100644 --- a/app/models/person.rb +++ b/app/models/person.rb @@ -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 diff --git a/spec/controllers/tags_controller_spec.rb b/spec/controllers/tags_controller_spec.rb index 0fcc167fa..81d49f255 100644 --- a/spec/controllers/tags_controller_spec.rb +++ b/spec/controllers/tags_controller_spec.rb @@ -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