Skip to content

Commit

Permalink
Searching works, but currently only on zones. [#2 state:open]
Browse files Browse the repository at this point in the history
  • Loading branch information
keegan committed Jul 15, 2008
1 parent aff8f8c commit 80b1d06
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 2 deletions.
12 changes: 12 additions & 0 deletions app/controllers/search_controller.rb
@@ -0,0 +1,12 @@
class SearchController < ApplicationController

def results
@search_parameter = params[:search][:parameter]
if @search_parameter.blank?
redirect_to root_path
else
@results = Zone.search(@search_parameter)
end
end

end
2 changes: 2 additions & 0 deletions app/helpers/search_helper.rb
@@ -0,0 +1,2 @@
module SearchHelper
end
4 changes: 4 additions & 0 deletions app/views/layouts/application.html.haml
Expand Up @@ -10,6 +10,10 @@
#Header
%h1
BIND DLZ on Rails
#search-bar{:style => "float: right"}
- form_for( :search, :url => { :controller => :search, :action => :results } ) do |f|
= f.text_field :parameter
= submit_tag "Search"
- if current_user
#Nav
%ul
Expand Down
4 changes: 2 additions & 2 deletions app/views/search/results.html.haml
Expand Up @@ -3,6 +3,6 @@

%h2.underline Zones

- unless @zones.blank?
- for zone in @zones do
- unless @results.blank?
- for zone in @results do
= link_to zone.name, zone_path( zone )
24 changes: 24 additions & 0 deletions spec/controllers/search_controller_spec.rb
@@ -0,0 +1,24 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe SearchController do
fixtures :all

before(:each) do
session[:user_id] = users(:admin).id
end

it "should return results when searched legally" do
post :results, :search => { :parameter => 'exa' }

assigns['results'].should_not be_nil
response.should render_template('results')
end

it "should redirect to the index page when nothing has been searched for" do
post :results, :search => { :parameter => "" }

response.should be_redirect
response.should redirect_to( root_path )
end

end
11 changes: 11 additions & 0 deletions spec/helpers/search_helper_spec.rb
@@ -0,0 +1,11 @@
require File.dirname(__FILE__) + '/../spec_helper'

describe SearchHelper do

#Delete this example and add some real ones or delete this file
it "should include the SearchHelper" do
included_modules = self.metaclass.send :included_modules
included_modules.should include(SearchHelper)
end

end

0 comments on commit 80b1d06

Please sign in to comment.