Hi all,
functional test help please,
http://pastie.org/1049300
lines 5 to 8 simulate a login; all fine, but after line 56 I’d like to
test the reverse that everything is blocked when the user is not logged
in. So the question is how could I not do that setup routine after line
56, or is there a better way ?
On Jul 18, 2:40 pm, bingo bob [email protected] wrote:
Hi all,
functional test help please,
http://pastie.org/1049300
lines 5 to 8 simulate a login; all fine, but after line 56 I’d like to
test the reverse that everything is blocked when the user is not logged
in. So the question is how could I not do that setup routine after line
56, or is there a better way ?
You could just have two separate test files, or you might want to look
at shoulda
Fred
Thanks Fred.
I actually did it like this in the end, I put this in test_helper
Add more helper methods to be used by all tests here…
def login
@request.env[‘HTTP_AUTHORIZATION’] = 'Basic ’ +
Base64::encode64(“foo:bar”)
end
and then in the tests like this
test “should destroy item” do
login
assert_difference(‘Item.count’, -1) do
delete :destroy, :id => items(:one).to_param
end
assert_redirected_to items_path
end
##########################
test “should not get index” do
# don’t login in this test.
get :index
assert_response :unauthorized
assert_nil assigns(:items)
end
Would appreciate any comments on this approach.
Is my approach a reasonable way to go? I only ask as it’s a problem I’ve
come up against a few times (how to login in tests) - whether it’s via
authlogic or basic http auth as in this case. Realising that I can add
other methods to test_helper.rb that could help me out in a similar way!
bingo bob wrote:
Hi all,
functional test help please,
http://pastie.org/1049300
lines 5 to 8 simulate a login; all fine, but after line 56 I’d like to
test the reverse that everything is blocked when the user is not logged
in. So the question is how could I not do that setup routine after line
56, or is there a better way ?
There is a better way: use Cucumber. Functional tests basically suck.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]
bingo bob wrote:
why?
Why what? Please quote when replying so we know what you’re replying
to.
Best,
Marnen Laibow-Koser
http://www.marnen.org
[email protected]