fdeschenes/omniauth-freshbooks — pull request #1 by cgunther (2013-10-30 16:28:33+00:00)
Title: Ensure session has keys for oauth and provider name before redirecting

When OmniAuth is in test mode, it skips calling request_phase. The omniauth-oauth strategy sets up the session with the necessary keys in the request_phase. Therefore in test mode, the session does not have an 'oauth' key or provider name key nested underneath 'oauth' as the omniauth-oauth request_phase was never run.

This could probably be avoided in the future once omniauth ships support for hooks (intridea/omniauth@67d4ccc0) as intridea/omniauth-oauth could initialize the 'oauth'/provider keys in the session in a before_request_phase hook rather than directly in the request_phase method.

Without initializing the session first here, you get an `undefined method [] for nil:NilClass` error as `session['oauth']` returns `nil`.