Steak with Session Example

37 views
Skip to first unread message

Tanner Donovan

unread,
Feb 22, 2011, 10:53:14 PM2/22/11
to ste...@googlegroups.com
Maybe this is more a Capybara question, but I am wondering if someone could provide me with an example of using Steak with sessions. I'm trying achieve something like https://gist.github.com/839970 which tests a user sign in form into a protected area. Thanks in advance.

Jaime Iniesta

unread,
Feb 23, 2011, 8:07:17 AM2/23/11
to ste...@googlegroups.com
Hi Tanner, what's exactly the problem you're facing?

I have a similar setup and I do just like you, visit the sign in form,
fill it and click the button. No special setup needed.

2011/2/23 Tanner Donovan <ttdo...@gmail.com>:

--
Jaime Iniesta, freelance web developer
http://jaimeiniesta.com
http://prorubyteam.com

Tanner Donovan

unread,
Feb 23, 2011, 3:26:49 PM2/23/11
to Steak
The scenario is failing at expected: "/account", got: "/" (using ==).
I'm trying to use ruby-debug to step through the scenario and
inspecting the page (Capybara::Session) object and use Rails logger,
but my controller's logger.info is not showing up in the log/test.log.
Any suggestions on how I can capture logger messaging from within the
Rails app?

Tanner

On Feb 23, 5:07 am, Jaime Iniesta <jaimeinie...@gmail.com> wrote:
> Hi Tanner, what's exactly the problem you're facing?
>
> I have a similar setup and I do just like you, visit the sign in form,
> fill it and click the button. No special setup needed.
>
> 2011/2/23 Tanner Donovan <ttdono...@gmail.com>:

Luismi Cavallé

unread,
Feb 23, 2011, 3:59:33 PM2/23/11
to ste...@googlegroups.com
Sorry if this is too obvious but, are you sure you should be redirected to "/account" right after being logged in? Is this how is implemented? What happen when log in manually using your browser?

-- Luismi

Tanner Donovan

unread,
Feb 23, 2011, 4:03:21 PM2/23/11
to Steak
After further investigation I think my issue might be with routes and
SSL. The Rails app is using the 'ssl_requirement' plugin. Watching the
log/test.log file more closely I see:

Processing ApplicationController#redirect_to_root_url (for 127.0.0.1
at 2011-02-23 12:42:33) [GET]
Parameters: {"url"=>["account", "session"],
"action"=>"redirect_to_root_url", "controller"=>"application"}
Redirected to http://www.example.com/account/session
Filter chain halted as [:ensure_proper_protocol]
rendered_or_redirected.
Completed in 1ms (DB: 0) | 302 Found [https://www.example.com/account/
session]

routes.rb includes:

map.namespace :account, :requirements => {:protocol =>
ROUTES_PROTOCOL} do |a|
a.resource :session, :controller => 'sessions', :only => :create
a.resource :profile, :controller => 'profiles', :only => :show
end

rake routes shows:

account_session POST /account/session(.:format)
{:action=>"create", :protocol=>"https", :controller=>"account/
sessions"}

Anyone have suggestions how I can ensure my Capybara::Session is using
SSL?

Tanner Donovan

unread,
Feb 23, 2011, 5:42:25 PM2/23/11
to Steak
I've finally figured it out. There appears to be an issue with
Capybara and switching between HTTP and HTTPS requests. I included
this gist (https://gist.github.com/466411) in a the ./spec/acceptance/
support/capybara_fix_ssl.rb and my specs started passing. I'm not
sure I entirely understand the issue but I'm going to run with it for
now. Thanks to everyone who took the time to read and reply to my
post.

Tanner

On Feb 23, 1:03 pm, Tanner Donovan <ttdono...@gmail.com> wrote:
> After further investigation I think my issue might be with routes and
> SSL. The Rails app is using the 'ssl_requirement' plugin. Watching the
> log/test.log file more closely I see:
>
> Processing ApplicationController#redirect_to_root_url (for 127.0.0.1
> at 2011-02-23 12:42:33) [GET]
>   Parameters: {"url"=>["account", "session"],
> "action"=>"redirect_to_root_url", "controller"=>"application"}
> Redirected tohttp://www.example.com/account/session
Reply all
Reply to author
Forward
0 new messages