Hello I'm new to Hobo and I have some with writing tests with users.
I took a look at
http://groups.google.com/group/hobousers/browse_thread/thread/d4adeff2882b3e43/879ec17315a33307?lnk=gst&q=test+acting_user#879ec17315a33307
and wanted to do as suggested. It worked for unit tests, but with
functional tests I can't get it working.
I want logged in users to be able to view their friends and guests to be
redirected to login page. I wrote tests and fixtures ( attached), but it
apparently doesn't work I get
---
1) Failure:
test_logged_in_can_access(FriendsControllerTest)
[/test/functional/friends_controller_test.rb:23]:
Expected response to be a <:success>, but was <302>
---
When I check it manually it works as expected. Do you know what I'm
doing wrong ( login?)?
Joachim
--
You received this message because you are subscribed to the Google Groups "Hobo
Users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/hobousers?hl=en.
Alice:
id: 1
name: Alice Zero
email: [email protected]
balance: 0
user_id: 1
Alfred:
id: 2
name: Alfred Debt
email: [email protected]
balance: -10
user_id: 1
Ann:
id: 3
name: Ann Plus
email: [email protected]
balance: 10
user_id: 1
Urshula:
id: 4
name: Urshula Zero
email: [email protected]
balance: 0
user_id: 2
Octavia:
id: 5
name: Octavia Plus
email: [email protected]
balance: 1000
user_id: 3
<% SALT = "Natrium Chloride"%>
<% PASS = "pass"%>
Admin:
id: 1
name: Abraham
email_address: [email protected]
administrator: true
salt: <%= SALT %>
crypted_password: <%= User.encrypt( PASS, SALT)%>
Uriael:
id: 2
name: Uriael
email_address: [email protected]
administrator: false
Olga:
id: 3
name: Olga
email_address: [email protected]
administrator: false
require File.dirname(__FILE__) + '/../test_helper'
class FriendsControllerTest < ActionController::TestCase
fixtures :users, :friends
def setup
@pages = [:index, :show, :new, :create, :edit, :update, :destroy]
end
def test_guest_redirect_to_login
for page in @pages
get page
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login
end
end
def test_logged_in_can_access
log_in('Abraham', 'pass')
get :index
assert_response :redirect
assert_redirected_to :controller => :users, :action => :login
assert_response :success
end
private
def log_in(uname, pass)
post :controller => :users, :action => :login, :login => uname, :password
=> pass
end
end