Skip to content

Instantly share code, notes, and snippets.

@bjhaid
Created August 16, 2012 13:35
Show Gist options
  • Save bjhaid/3370119 to your computer and use it in GitHub Desktop.
Save bjhaid/3370119 to your computer and use it in GitHub Desktop.
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