Created
October 26, 2012 08:56
-
-
Save shakthimaan/3957723 to your computer and use it in GitHub Desktop.
404 status in functional test
This file contains 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
UsersRailsWeb::Application.routes.draw do | |
match 'users/show', :controller => 'users', :action => 'show' | |
end |
This file contains 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
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 |
This file contains 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
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