# REST API makes tests failed

**URL:** <https://www.ruby-forum.com/t/rest-api-makes-tests-failed/128517>\
**Category:** Rails\
**Created:** [February 8, 2008, 11:37am UTC](https://www.ruby-forum.com/t/rest-api-makes-tests-failed/128517 "2008-02-08T11:37:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![MohsinHijazee](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e68b1a/32.png) [@MohsinHijazee](https://www.ruby-forum.com/u/MohsinHijazee)\
**Post date:** [February 8, 2008, 11:37am UTC](https://www.ruby-forum.com/t/rest-api-makes-tests-failed/128517/1 "2008-02-08T11:37:14Z")

</div>

I am building REST API on top of a rails application. Consider the  
following lines:

respond\_to do |format|

respond\_to do |format|  
if entity.details.collect{|d| d.detail\_id.to\_i}.include?  
params[“detail\_id”].to\_i  
flash[“error”]=t(“error\_incorrect\_data”)

```
    format.html { redirect_to :action => "show", :id

```

=\>params[“id”] and return}  
format.json { render :json =\> ‘Bad Request’, :status =\> 400  
and return}

```
  end

```

end

That is, if the request format is html(means we are being accessed  
through Interface), we simply redirect he user to other action and if  
the format is JSON, we simply return the status code along with a  
short message. This works as expected when accessed through cURL or  
any browser. But when it comes to the tests, the format.html block  
does not executes and as a results some of the tests start to fail.  
Even if you include the format parameter along with the request in the  
tests, even then that does not work. How should I get around it?

Regards,  
Mohsin
