How does Webrat work with the a session and/or cookie object?
I'm attempting to test that i can log in as a user and then travel to
a nested resource for that user...
the two applicable step definitions i've defined are:
Given /^I am (.+) (.+) and I am on the account_(.+) page$/ do |
first_name, last_name, route_frag|
@current_account = Account.create!(:first_name =>
first_name, :last_name => last_name, :email =>
"
te...@ttkb.net", :password => "tpass123", :title => "Ms.", :login =>
"
te...@ttkb.net")
visit new_session_path
fill_in :email, @current_account.email
fill_in :password, @current_account.password
click_button 'Adult Login'
s = "/accounts/" + @current_account.id.to_s + "/#{route_frag}"
visit s
end
Given /^I am (.+) (.+) and I am on the new_account_(.+) page$/ do |
first_name, last_name, route_frag|
@current_account = Account.create!(:first_name =>
first_name, :last_name => last_name, :email =>
"
te...@ttkb.net", :password => "tpass123", :title => "Ms.", :login =>
"
te...@ttkb.net")
visit new_session_path
fill_in :email, @current_account.email
fill_in :password, @current_account.password
check :remember_me
click_button 'Adult Login'
s = "/accounts/" + @current_account.id.to_s + "/#{route_frag}/new"
visit s
end
But when I am not clear how Webrat handles logins, or if it persists a
session between scenarios...
when i try to use these step definitions i get:
You have a nil object when you didn't expect it!
The error occurred while evaluating nil.has_role? (NoMethodError)
which is basically throwing an error when it comes across the variable
"current_account" which gets defined as AuthenticatedSystem.rb:
def current_account
@current_account ||= (login_from_session || login_from_cookie)
unless @current_account == false
end
What am I doing wrong?