Skip to content

Instantly share code, notes, and snippets.

@shakthimaan
Created October 26, 2012 08:56
Show Gist options
  • Save shakthimaan/3957723 to your computer and use it in GitHub Desktop.
Save shakthimaan/3957723 to your computer and use it in GitHub Desktop.
404 status in functional test
UsersRailsWeb::Application.routes.draw do
match 'users/show', :controller => 'users', :action => 'show'
end
class UsersController < ApplicationController
before_filter :params_json
def show
@users = User.all
respond_to do |format|
format.json { render :json => @users }
end
end
protected
def params_json
render :json => { :errors => "404" }, :status => 404 unless params[:format] == "json"
end
end
require 'test_helper'
class UsersControllerTest < ActionController::TestCase
test "Get users" do
# /users/show.json
get 'show', {:format => :json}
body = JSON.parse(response.body)
assert_equal "foo", body[0]["name"]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment