# Ruby on Rails \> test:integration Expected response to be a \<:redirect\>, but was \<404\>

**URL:** <https://www.ruby-forum.com/t/ruby-on-rails-test-integration-expected-response-to-be-a-redirect-but-was-404/174384>\
**Category:** Rails\
**Created:** [August 26, 2009, 3:59am UTC](https://www.ruby-forum.com/t/ruby-on-rails-test-integration-expected-response-to-be-a-redirect-but-was-404/174384 "2009-08-26T03:59:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![fireflyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/43a26b/32.png) [@fireflyman](https://www.ruby-forum.com/u/fireflyman)\
**Post date:** [August 26, 2009, 3:59am UTC](https://www.ruby-forum.com/t/ruby-on-rails-test-integration-expected-response-to-be-a-redirect-but-was-404/174384/1 "2009-08-26T03:59:40Z")

</div>

Hello,

I’m trying to write some tests and I get a failure error on one test,  
which I am not sure why or where is my mistake.

In my test/integration/product\_test.rb I have:

require ‘test\_helper’

class ProductTest \< ActionController::IntegrationTest  
fixtures :all

test “product\_administartion\_by\_admin” do  
category = Category.create(:name =\> ‘Parts’)

```
quentin = new_session_as(:quentin)
product = quentin.add_product :product => {
  :title => 'Clip',
  :category_id => category.id,
  :sku => 54321,
  :desctription => 'some text',
  :price => 8.71
}

```

end

private

module ProductTestDSL  
attr\_writer :name

```
def add_product(parameters)
  post "/product/create", parameters
  assert_response :redirect
  follow_redirect!
  assert_response :success
  assert_template "/product/show"
  return Product.find_by_title(parameters[:product][:title])
end

```

end

## def new\_session\_as(name) open\_session do |session| session.extend(ProductTestDSL) session.name = name yield session if block\_given? end end end

The error I get is:

1. Failure:  
test\_product\_administartion\_by\_admin(ProductTest)  
[/test/integration/product\_test.rb:26:in `add_product' /test/integration/product_test.rb:10:in`test\_product\_administartion\_by\_admin’]:  
Expected response to be a \<:redirect\>, but was \<404\>

## 1 tests, 1 assertions, 1 failures, 0 errors rake aborted!

Looking around – someone had a problem that the new object was not  
created or saved. One of the tests in products\_controller\_test.rb has  
no problem creating a new product.

What am I missing?

---

<div class="post-metadata">

**Author:** ![fireflyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/43a26b/32.png) [@fireflyman](https://www.ruby-forum.com/u/fireflyman)\
**Post date:** [August 26, 2009, 8:16am UTC](https://www.ruby-forum.com/t/ruby-on-rails-test-integration-expected-response-to-be-a-redirect-but-was-404/174384/2 "2009-08-26T08:16:17Z")

</div>

> Looking around – someone had a problem that the new object was not  
> created or saved. One of the tests in products\_controller\_test.rb has  
> no problem creating a new product.
> 
> What am I missing?

try this…  
this may work

test “product\_administartion\_by\_admin” do  
category = Category.create(:name =\> ‘Parts’)  
quentin = new\_session\_as(:quentin)  
quentin.add\_product

end

private

module ProductTestDSL  
attr\_writer :name

```
 def add_product
    params ={:product => {
            :title => 'Clip',
            :category_id => category.id,
            :sku => 54321,
            :desctription => 'some text',
            :price => 8.71}}
   post "/product/create", params
   assert_response :redirect
   follow_redirect!
   assert_response :success
   assert_template "/product/show"
   return Product.find_by_title(parameters[:product][:title])
 end

```

end

def new\_session\_as(name)  
open\_session do |session|  
session.extend(ProductTestDSL)  
session.name = name  
yield session if block\_given?  
end  
end  
end

---

<div class="post-metadata">

**Author:** ![fireflyman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/43a26b/32.png) [@fireflyman](https://www.ruby-forum.com/u/fireflyman)\
**Post date:** [August 26, 2009, 11:59am UTC](https://www.ruby-forum.com/t/ruby-on-rails-test-integration-expected-response-to-be-a-redirect-but-was-404/174384/3 "2009-08-26T11:59:03Z")

</div>

Thanks!

2009/8/26 Nik C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
