jarkko - we could debate the value of encapsulation and loose coupling
in tests, but, regardless, what about more complex scenarios, such as:
Add item to cart, update quantity (2 requests, spans a session, may
involve 2 controllers)
Add items to cart, clear cart
Multipage form (wizards)
etc. etc. etc.
jarkko wrote:
On 22.11.2005, at 23.38, List R. wrote:
technoweenie wrote:
You can set the session yourself:
@request.session[:user] = users(:bob)
I thought of doing that, but it couples the test to the session
implentation, which I’d rather not do. Is there a better way?
Why? You are testing your login functionality. Your login system has
some way to make sure that a user is logged in. Normally it depends
on sessions. So why not depend on that in your tests, it’s after all
an integrated part of your login system.
If you think you might change the system later on, just create a
method for authorizing a user and use that method in both your
controllers and tests.
I thought of doing that, but it couples the test to the session
implentation, which I’d rather not do. Is there a better way?
Why? You are testing your login functionality. Your login system has
some way to make sure that a user is logged in. Normally it depends
on sessions. So why not depend on that in your tests, it’s after all
an integrated part of your login system.
If you think you might change the system later on, just create a
method for authorizing a user and use that method in both your
controllers and tests.
//jarkko
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.