# Strange assertion problem

**URL:** <https://discuss.rubyonrails.org/t/strange-assertion-problem/505>\
**Category:** rubyonrails-talk\
**Created:** [August 25, 2006, 7:48pm UTC](https://discuss.rubyonrails.org/t/strange-assertion-problem/505 "2006-08-25T19:48:01Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bounga](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/bounga/32/650_2.png) [@Bounga](https://discuss.rubyonrails.org/u/Bounga)\
**Post date:** [August 25, 2006, 7:48pm UTC](https://discuss.rubyonrails.org/t/strange-assertion-problem/505/1 "2006-08-25T19:48:01Z")

</div>

Hello,

I'm trying to write some functionnal tests for one of my controllers and I've got a strange problem. In my test code I'm doing the following :

&nbsp;&nbsp;&nbsp;def test\_index\_user\_not\_login &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;get :index &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_response :redirect &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;assert\_redirected\_to :controller =\> "user", :action =\> "login" &nbsp;&nbsp;&nbsp;end

and when I launch the test, I've got this error :

&nbsp;&nbsp;1) Failure: test\_index\_user\_not\_login(Admin::ConfigurationControllerTest) [./test/functional/admin/configuration\_controller\_test.rb:20]: response is not a redirection to all of the options supplied (redirection is \<{:action=\>"login", :controller=\>"user"}\>), difference: \<{}\>

So if I understand, the testing tasks tells me that my redirection isn't correct (I test it by hand and it works well) and that's the difference is {}, so nothing different ... Odd.

If I change:

assert\_redirected\_to :controller =\> "user", :action =\> "login"

to:

assert\_redirected\_to :action =\> "login"

it works ...

Any clue ?

---

<div class="post-metadata">

**Author:** ![Jason\_Roelofs](https://avatars.discourse-cdn.com/v4/letter/j/e274bd/32.png) [@Jason\_Roelofs](https://discuss.rubyonrails.org/u/Jason_Roelofs)\
**Post date:** [August 25, 2006, 8:40pm UTC](https://discuss.rubyonrails.org/t/strange-assertion-problem/505/2 "2006-08-25T20:40:57Z")

</div>

What is the actual redirect\_to call? I’ve found that Rails can be quite picky with functional tests and redirect checking, so make sure that the url\_options are the exact same in both places.

Jason

---

<div class="post-metadata">

**Author:** ![Bounga](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/bounga/32/650_2.png) [@Bounga](https://discuss.rubyonrails.org/u/Bounga)\
**Post date:** [August 25, 2006, 9:06pm UTC](https://discuss.rubyonrails.org/t/strange-assertion-problem/505/3 "2006-08-25T21:06:53Z")

</div>

The redirect\_to is : redirect\_to :controller =\> 'user', :action =\> 'login'

It's the one found in authenticated\_system.rb that's ship with Acts\_as\_authenticated ...

I'm using a before\_filter with the login\_required method to ensure that the user is login to access an admin page.

---

<div class="post-metadata">

**Author:** ![jdonnell](https://avatars.discourse-cdn.com/v4/letter/j/f17d59/32.png) [@jdonnell](https://discuss.rubyonrails.org/u/jdonnell)\
**Post date:** [August 25, 2006, 11:40pm UTC](https://discuss.rubyonrails.org/t/strange-assertion-problem/505/4 "2006-08-25T23:40:44Z")

</div>

i has this exact problem and my redirect\_to did NOT have the :controller part. Are you sure yours does?

in my Post controller i can call redirect\_to :action =\> 'list'

if I then test for the following it will fail. assert\_redirected\_to :controller =\> 'post', :action =\> "list"

Double check that your not doing this.

---

<div class="post-metadata">

**Author:** ![Bounga](https://sea2.discourse-cdn.com/rubyonrails/user_avatar/discuss.rubyonrails.org/bounga/32/650_2.png) [@Bounga](https://discuss.rubyonrails.org/u/Bounga)\
**Post date:** [August 26, 2006, 10:56am UTC](https://discuss.rubyonrails.org/t/strange-assertion-problem/505/5 "2006-08-26T10:56:12Z")

</div>

Mine does yes. I'm pretty sure it's a Rails bug because if I do this:

assert\_redirected\_to @controller.url\_for(:controller =\> 'user', :action =\> 'login')

it works like a charm ...

So I'm wondering why assert\_redirected\_to :controller =\> 'user', :action =\> 'login' doesn't work ...

I'm going to check if there's a bug report for that and if it doesn't I'm going to open one.
