This test of my signups controller fails on the last line: it gets
redirected to the account/login page.
get :signup, :id => 1 # must be logged in to view this page
assert_redirected_to :action => ''login''
login_as :quentin
post :create, :form_data => {:first_name => "joe",
:last_name =>
"bob", :form_type_id => 1}
assert_redirected_to :controller => ''signups'', :action
=> ''select''
The create action does require login, but if I comment out the first two
lines, then it passes, so the login seems to work. Somehow the first get
request is changing what happens when i call login_as and then post to
signups/create. I assume I just don''t understand something about why
that would change some important state. Maybe I''m only supposed to have
one get or post per test? Can someone explain it?
I also tried this and it passes:
login_as :quentin
get :signup, :id => 1
post :create, :form_data => {:first_name => "joe",
:last_name =>
"bob", :form_type_id => 1}
assert_redirected_to :controller => ''signups'', :action
=> ''select''
So the problem is due to being redirected to another controller, I
guess.
- Elliot
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Functional test you will only deal with testing one action. In integration tests you can test across different controllers and action. On 10/14/07, Elliot Temple <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > This test of my signups controller fails on the last line: it gets > redirected to the account/login page. > > get :signup, :id => 1 # must be logged in to view this page > assert_redirected_to :action => ''login'' > login_as :quentin > post :create, :form_data => {:first_name => "joe", :last_name => > "bob", :form_type_id => 1} > assert_redirected_to :controller => ''signups'', :action => ''select'' > > The create action does require login, but if I comment out the first two > lines, then it passes, so the login seems to work. Somehow the first get > request is changing what happens when i call login_as and then post to > signups/create. I assume I just don''t understand something about why > that would change some important state. Maybe I''m only supposed to have > one get or post per test? Can someone explain it? > > I also tried this and it passes: > > login_as :quentin > get :signup, :id => 1 > post :create, :form_data => {:first_name => "joe", :last_name => > "bob", :form_type_id => 1} > assert_redirected_to :controller => ''signups'', :action => ''select'' > > So the problem is due to being redirected to another controller, I > guess. >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Bala Paranj wrote:> Functional test you will only deal with testing one action. In > integration tests you can test across different controllers and > action.I thought functional tests were supposed to focus on individual controllers, not individual actions. This test does not touch multiple controllers except that some actions redirect elsewhere and you can make assertions about where it''s redirected. Are you saying you can''t use get or post twice in one functional test, or what did I do wrong? What if they were both for the same action? - Elliot -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
in your test_helper.rb
def login_as(user)
@request.session[:user] = user ? users(user).id : nil
end
then in your whatever_controller_test.rb, here I use the
tasks_controller ( new and create..)
user the login_as.... and don''t forget the fixtures
fixtures :tasks, :users
def test_should_get_new
login_as(:quentin)
get :new
assert_response :success
end
def test_should_create_task
login_as(:quentin)
old_count = Task.count
post :create, :task => {:user_id => 1, :category => 1, :title
=>
''cut the flowers'',
:description => "lorem ipsum...", :should_start_at =>
5.days.from_now.utc, :should_end_at => 15.days.from_now.utc }
assert_equal old_count+1, Task.count
assert_redirected_to task_path(assigns(:task))
end
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---