[close #23] Changed searching.

This commit is contained in:
George Vinogradov 2011-12-16 04:33:44 +04:00
parent 88ea7110f3
commit a946349bb4
2 changed files with 16 additions and 1 deletions

View File

@ -19,7 +19,7 @@ class ProjectsController < ApplicationController
end.accessible_by(current_ability)
@projects = if params[:query]
@projects.where(["name LIKE ?", "%#{params[:query]}%"])
@projects.by_name(params[:query]).order("CHAR_LENGTH(name) ASC")
else
@projects
end.paginate(:page => params[:project_page])

View File

@ -104,4 +104,19 @@ describe ProjectsController do
it_should_behave_like 'projects user with writer rights'
it_should_behave_like 'projects user with reader rights'
end
context 'search projects' do
before(:each) do
@admin = Factory(:admin)
@project1 = Factory(:project, :name => 'perl-debug')
@project2 = Factory(:project, :name => 'perl')
set_session_for(@admin)
end
it 'should return projects in right order' do
get :index, :query => 'per'
assigns(:projects).should eq([@project2, @project1])
end
end
end