Skip to content

Commit

Permalink
Merge pull request hotsh#569 from mathias/empty_search_for_authors
Browse files Browse the repository at this point in the history
Short circuit empty search query to show all users
  • Loading branch information
carols10cents committed Aug 17, 2012
2 parents 46a7615 + 2e6a913 commit 671cf2c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 14 additions & 9 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ class UsersController < ApplicationController
def index
@title = "users"
set_params_page
begin
@authors = Author.search(params)
rescue RegexpError
flash[:error] = "Please enter a valid search term"
redirect_to users_path and return
end
unless @authors.empty?
@authors = @authors.paginate(:page => params[:page], :per_page => params[:per_page])
set_pagination_buttons(@authors, :search => params[:search])
if params[:search].blank?
@authors = Author.paginate(:page => params[:page], :per_page => params[:per_page])
else
begin
@authors = Author.search(params)
rescue RegexpError
flash[:error] = "Please enter a valid search term"
redirect_to users_path and return
end

unless @authors.empty?
@authors = @authors.paginate(:page => params[:page], :per_page => params[:per_page])
set_pagination_buttons(@authors, :search => params[:search])
end
end
end

Expand Down
8 changes: 7 additions & 1 deletion test/acceptance/user_search_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
assert has_content?("Sorry, no users that match.")
end

it "displays all users if there is no search query" do
visit "/users?search="
assert_equal 200, page.status_code
assert has_content?("zebra")
end

it "finds users by substring regex match (do we want this?)" do
visit "/users?search=ebr"
assert has_content?("zebra")
Expand Down Expand Up @@ -94,4 +100,4 @@
end
end

end
end

0 comments on commit 671cf2c

Please sign in to comment.