Hey i am new to testing on rails and i have the following test written
describe 'GET search' do
it 'finds a named account directly' do
get :search, name: 'test'
expect(response).to redirect_to(account_path('test'))
end
I have been getting the following error
SystemAccountsController GET search finds a named account directly
Failure/Error: expect(response).to
redirect_to(account_path('test'))
Expected response to be a <:redirect>, but was <200>
# ./spec/controllers/account_controller_spec.rb:21:in `block (3
levels) in <top (required)>'
I however get a response status of 200. I am not sure what i am doing
wrong cause all my links however work correctly. Is there a way to debug
this or find where the actual response is headed to ?
Hey i am new to testing on rails and i have the following test written
describe 'GET search' do
it 'finds a named account directly' do
get :search, name: 'test'
expect(response).to redirect_to(account_path('test'))
end
I have been getting the following error
AccountsController GET search finds a named account directly
Failure/Error: expect(response).to
redirect_to(account_path('test'))
Expected response to be a <:redirect>, but was <200>
# ./spec/controllers/account_controller_spec.rb:21:in `block (3
levels) in <top (required)>'
I however get a response status of 200. I am not sure what i am doing
wrong cause all my links however work correctly. Is there a way to debug
this or find where the actual response is headed to ?
Your spec clearly indicates that you expect the "search" action to
respond with a redirect (status 301 or 302), but the response is
actually 200 - SUCCESS.
I don't see your controller action code posted here, but I can guess
from the spec failure that it is not performing a redirect.
It's pretty easy to confirm whether a redirect is occurring with curl...
Example:
$ curl -v http://example.com
* About to connect() to example.com port 80 (#0)
* Trying 192.0.43.10... connected
* Connected to example.com (192.0.43.10) port 80 (#0)
GET / HTTP/1.1
User-Agent: curl/7.21.4 (universal-apple-darwin11.0) libcurl/7.21.4
OpenSSL/0.9.8r zlib/1.2.5
Host: example.com
Accept: */*
* HTTP 1.0, assume close after body
< HTTP/1.0 302 Found
< Location: Example Domains
< Server: BigIP
* HTTP/1.0 connection set to keep alive!
< Connection: Keep-Alive
< Content-Length: 0
<
* Connection #0 to host example.com left intact
* Closing connection #0
def search
@accounts =
client = AccountsClient.new
if params[:name]
response = client.query_account(CGI.escape(params[:name]))
if response.is_a?(Net::HTTPSuccess)
account = JSON.parse(response.body)
unless account.empty?
session[:account] = account
redirect_to account_path(params[:name])
end
end
limit=100
limit = params[:limit].to_i if
params[:limit].to_i.between?(1,100)
offset = ''
offset_param = params[:offset]
if is_integer?(offset_param)
offset = "&offset=#{params[:offset]}" if
offset_param.to_i.between?(0, 2**16)
end