Wednesday, April 08, 2009

Cucumber and restful_authentication

I have started to use Cucumber.
But I'm using restful_authentication for the Ruby on Rails application I'm working on and I had to deal with it.
It turned out that all I have to do was to add a step like the following (My actual code has a role parameter - e.g. admin - but I omitted it here for simplicity):

Given /^I am logged in$/ do
User.create!( :first_name => 'quire',
:last_name => 'smith',
:login => 'quire',
:email => 'quire@example.com',
:password => 'test',
:password_confirmation => 'test' )
post "/login", :login => 'quire', :password => 'test'
end


By the way, in routes.rb, I'm setting the following as described in restful_authentication:

map.login '/login', :controller => 'sessions', :action => 'new'


P.S. Actually, it didn't work quite well in the steps later on. I will do more investigation.

No comments: