Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NoMethodError: undefined method `to_key' for :user:Symbol #29

Open
redox opened this issue Jul 28, 2014 · 9 comments
Open

NoMethodError: undefined method `to_key' for :user:Symbol #29

redox opened this issue Jul 28, 2014 · 9 comments

Comments

@redox
Copy link
Contributor

redox commented Jul 28, 2014

While running the tests I got this error. Any chance you understand it? (devise=3.2.4 in my Gemfile.lock)

[17/23] InvitationTest#test_user_is_not_prompted_for_token_again_after_first_login_until_remembertime_is_up = 0.02 s                        
  1) Error:
test_user_is_not_prompted_for_token_again_after_first_login_until_remembertime_is_up(InvitationTest):
NoMethodError: undefined method `to_key' for :user:Symbol
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.4/lib/devise/models/authenticatable.rb:204:in `serialize_into_session'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.4/lib/devise.rb:455:in `block (2 levels) in configure_warden!'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/warden-1.2.3/lib/warden/session_serializer.rb:26:in `store'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/devise-3.2.4/lib/devise/controllers/sign_in_out.rb:38:in `sign_in'
    /Users/redox/dev/devise_google_authenticator/app/controllers/devise/displayqr_controller.rb:9:in `show'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal/implicit_render.rb:4:in `send_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:167:in `process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal/rendering.rb:10:in `process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:18:in `block in process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:436:in `_run__2550341926883609517__process_action__2030047739189359172__callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_process_action_callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/abstract_controller/callbacks.rb:17:in `process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal/rescue.rb:29:in `process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:30:in `block in process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `block in instrument'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/notifications.rb:123:in `instrument'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal/instrumentation.rb:29:in `process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal/params_wrapper.rb:207:in `process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/railties/controller_runtime.rb:18:in `process_action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/abstract_controller/base.rb:121:in `process'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/abstract_controller/rendering.rb:45:in `process'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal.rb:203:in `dispatch'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal/rack_delegation.rb:14:in `dispatch'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_controller/metal.rb:246:in `block in action'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:73:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:73:in `dispatch'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:36:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/routing/mapper.rb:42:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/journey-1.0.4/lib/journey/router.rb:68:in `block in call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/journey-1.0.4/lib/journey/router.rb:56:in `each'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/journey-1.0.4/lib/journey/router.rb:56:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/routing/route_set.rb:612:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/warden-1.2.3/lib/warden/manager.rb:35:in `block in call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/warden-1.2.3/lib/warden/manager.rb:34:in `catch'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/warden-1.2.3/lib/warden/manager.rb:34:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/best_standards_support.rb:17:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/etag.rb:23:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/conditionalget.rb:25:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/head.rb:14:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/params_parser.rb:21:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/flash.rb:242:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:210:in `context'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/session/abstract/id.rb:205:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/cookies.rb:341:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/query_cache.rb:64:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activerecord-3.2.13/lib/active_record/connection_adapters/abstract/connection_pool.rb:479:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/callbacks.rb:28:in `block in call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `_run__4458982363860228573__call__2348933139888363517__callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_call_callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/callbacks.rb:27:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/remote_ip.rb:31:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/debug_exceptions.rb:16:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/rack/logger.rb:32:in `call_app'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/rack/logger.rb:16:in `block in call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/tagged_logging.rb:22:in `tagged'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/rack/logger.rb:16:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/request_id.rb:22:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/methodoverride.rb:21:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/runtime.rb:17:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/cache/strategy/local_cache.rb:72:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/lock.rb:15:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/actionpack-3.2.13/lib/action_dispatch/middleware/static.rb:63:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/engine.rb:479:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/railties-3.2.13/lib/rails/application.rb:223:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/builder.rb:134:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/urlmap.rb:64:in `block in call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in `each'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in `call'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-test-0.6.2/lib/rack/mock_session.rb:30:in `request'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-test-0.6.2/lib/rack/test.rb:230:in `process_request'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/rack-test-0.6.2/lib/rack/test.rb:57:in `get'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/capybara-1.1.4/lib/capybara/rack_test/browser.rb:62:in `process'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/capybara-1.1.4/lib/capybara/rack_test/browser.rb:21:in `visit'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/capybara-1.1.4/lib/capybara/rack_test/driver.rb:32:in `visit'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/capybara-1.1.4/lib/capybara/session.rb:157:in `visit'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/capybara-1.1.4/lib/capybara/dsl.rb:161:in `visit'
    /Users/redox/dev/devise_google_authenticator/test/integration_tests_helper.rb:23:in `create_and_signin_gauth_user'
    /Users/redox/dev/devise_google_authenticator/test/integration/gauth_test.rb:141:in `block in <class:InvitationTest>'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1301:in `run'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit/testcase.rb:17:in `run'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:36:in `block in run'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:447:in `_run__2705702850970494475__setup__2348933139888363517__callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:405:in `__run_callback'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:385:in `_run_setup_callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/callbacks.rb:81:in `run_callbacks'
    /Users/redox/.rvm/gems/ruby-2.0.0-p247/gems/activesupport-3.2.13/lib/active_support/testing/setup_and_teardown.rb:35:in `run'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:919:in `block in _run_suite'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:912:in `map'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:912:in `_run_suite'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:657:in `block in _run_suites'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:655:in `each'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:655:in `_run_suites'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:867:in `_run_anything'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1060:in `run_tests'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1047:in `block in _run'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1046:in `each'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1046:in `_run'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/minitest/unit.rb:1035:in `run'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:21:in `run'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:774:in `run'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:366:in `block (2 levels) in autorun'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:27:in `run_once'
    /Users/redox/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/2.0.0/test/unit.rb:365:in `block in autorun'
@xntrik
Copy link
Contributor

xntrik commented Sep 9, 2014

Hey @redox - I've had this test fail for a while, although, I couldn't figure out why. Unsure if it's session teardown issues with Capybara, or, the test rails app in /test/rails_app isn't built properly. I've been meaning to address this for a while, just, time-poor at the moment.

@redox
Copy link
Contributor Author

redox commented Sep 9, 2014

Actually, I got it twice in production as well :/

@felipecsl
Copy link
Contributor

This happens to me in production when I try to hit users/displayqr while being logged out. I'll see if I can submit a patch quickly

@xntrik
Copy link
Contributor

xntrik commented Feb 8, 2015

I've fixed the tests, but, this issue still persists. I'll pull this in

@xntrik
Copy link
Contributor

xntrik commented Feb 8, 2015

I've pulled in those changes @felipecsl - into 1070d62

@xntrik
Copy link
Contributor

xntrik commented Feb 8, 2015

I still see different errors depending on the state of the session - so I'm not going to close this entirely yet.

@pouellet
Copy link

I ran into the same problem and did some investigation. My understanding was that the intention of the following code was to ensure that if a non authenticated user call any of the actions, he would be redirected by Devise/warden to the login page:

class Devise::DisplayqrController < DeviseController
   prepend_before_filter :authenticate_scope!, :only => [:show,:update, :refresh]
   ...
   def authenticate_scope!
      send(:"authenticate_#{resource_name}!")
      self.resource = send("current_#{resource_name}")
    end
end

Unfortunately, the Devise code for authenticate_#{resource_name}! contains the following:

def authenticate_#{resource_name}!(favourite=nil, opts={})
  ...
      opts[:scope] = mapping
      warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)
  ...
end

def devise_controller?
  is_a?(::DeviseController)
end

Since the DisplayqrController inherit from DeviseController the warden.authenticate! is skipped. Maybe the authenticate_scope! should be using the force option?

class Devise::DisplayqrController < DeviseController
   ...
   def authenticate_scope!
      send(:"authenticate_#{resource_name}!", force: true)
      self.resource = send("current_#{resource_name}")
    end
end

@danielgomezrico
Copy link

Is there any update on this? 👀

@LE-HU
Copy link

LE-HU commented Jun 2, 2022

I've got that one when tried to sign_in(:user) instead of sing_in(user) in rspec request spec, which was a simple mistake.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants