Created
August 16, 2012 13:35
-
-
Save bjhaid/3370119 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Controller Method | |
def search | |
if params[:search_option] == "ink" | |
@ink = Ink.where("name LIKE ?", "%#{params[:name]}%") | |
elsif params[:search_option] == "printer" | |
@ink = Ink.where("brand_name LIKE ? AND serie_name LIKE ? AND printer_name LIKE ?", "%#{params[:brand]}%", "%#{params[:series]}%", "%#{params[:printer]}%") | |
end | |
@search = @ink | |
render :html => @search | |
end | |
Spec | |
require 'spec_helper' | |
describe BrandsController do | |
describe "GET 'search'" do | |
it "returns http success" do | |
get 'search' | |
response.should be_success | |
end | |
end | |
describe "GET 'search with search_option=ink and name=3\ Pack'" do | |
it "should assign ink" do | |
get :show, {:search_option => "ink", :name => "3"} | |
assigns(:ink).should_not be_nil | |
end | |
end | |
end | |
Failures: | |
1) BrandsController GET 'search with search_option=ink and name=3 Pack' should assign ink | |
Failure/Error: assigns(:ink).should_not be_nil | |
expected: not nil | |
got: nil | |
# ./spec/controllers/brands_controller_spec.rb:15:in `block (3 levels) in <top (required)>' | |
Finished in 0.25487 seconds | |
2 examples, 1 failure | |
Failed examples: | |
rspec ./spec/controllers/brands_controller_spec.rb:13 # BrandsController GET 'search with search_option=ink and name=3 Pack' should assign ink |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment