All I want to do is set a session variable when I make a request.
Here''s my code:
class ProjectIntegrationTest < ActionController::IntegrationTest
def test_truth
user = user_for_test
user.access_project_index_page
end
def user_for_test
open_session do |thing|
def user.access_project_index_page
session[:user_id] = ''someid''
get project_index_path
assert_response :success
end
end
end
end
I''m getting this error:
test_truth(ProjectIntegrationTest):
NoMethodError: undefined method `user'' for
#<ActionController::Integration::Session:0x21d7c50>
method method_missing in test_process.rb at line 464
method send! in integration.rb at line 448
method method_missing in integration.rb at line 448
method user_for_test in project_integration_test.rb at line 11
Line 11 is the line where "session[:user_id] =
''someid''" is being set.
What am I doing wrong for setting the session?
-Kyle
--
Posted via http://www.ruby-forum.com/.
On 7 May 2009, at 11:26, Kyle Peyton <rails-mailing-list@andreas- s.net> wrote:> > All I want to do is set a session variable when I make a request. > Here''s my code: > > class ProjectIntegrationTest < ActionController::IntegrationTest > def test_truth > user = user_for_test > user.access_project_index_page > end > > def user_for_test > open_session do |thing| > def user.access_project_index_pageActually it is the above line that is raising the exception - there is no user variable / method in scope here. This code lois pretty strange - are you really trying to define singleton methods on users? Fred> > session[:user_id] = ''someid'' > get project_index_path > assert_response :success > end > end > end > end > > I''m getting this error: > > test_truth(ProjectIntegrationTest): > NoMethodError: undefined method `user'' for > #<ActionController::Integration::Session:0x21d7c50> > method method_missing in test_process.rb at line 464 > method send! in integration.rb at line 448 > method method_missing in integration.rb at line 448 > method user_for_test in project_integration_test.rb at line 11 > > Line 11 is the line where "session[:user_id] = ''someid''" is being set. > What am I doing wrong for setting the session? > > -Kyle > -- > Posted via http://www.ruby-forum.com/. > > >
I''m pretty new to integration testing and I''m not sure how to define tests. I saw an example of someone doing it this way, so that''s the way I formed mine. What is the best way to write a normal test that allows me to set the "user_id" session variable so that the "get" can successfully happen? -Kyle Frederick Cheung wrote:> On 7 May 2009, at 11:26, Kyle Peyton <rails-mailing-list@andreas- > s.net> wrote: > >> def user_for_test >> open_session do |thing| >> def user.access_project_index_page > > Actually it is the above line that is raising the exception - there is > no user variable / method in scope here. > This code lois pretty strange - are you really trying to define > singleton methods on users? > > Fred-- Posted via http://www.ruby-forum.com/.