NoBrainerORM / nobrainer

Ruby ORM for RethinkDB
http://nobrainer.io/
Other
387 stars 49 forks source link

rails test issue with devise #163

Closed modosc closed 8 years ago

modosc commented 8 years ago

(this is a weird and probably rare occurrence so i'm just logging it for posterity)

i have a controller setup with devise and mounted like so in my routes:

devise_for :users, :controllers => { sessions: 'users' }

if i setup a functional test for this like so:

it 'works with a valid password' do
  # have to do this (or write an integration test) since devise does stuff
  # from inside of the router and blows up otherwise
  @request.env["devise.mapping"] = Devise.mappings[:user]
  post :create, user: { email: user.email, password: user.password }, access_token: access_token, format: :json
  expect(response).to have_http_status(:created)
end

it 'fails with an invalid password' do
  @request.env["devise.mapping"] = Devise.mappings[:user]
  post :create, user: { email: user.email, password: 'asdfasdfisdf8981u23123' }, access_token: access_token, format: :json
  expect(response).to have_http_status(:unauthorized)
end

the positive case passes, but on the failure case i get this nobrainer error:

 NoMethodError:
   undefined method `total_duration' for nil:NilClass
 # /Users/jon/.rvm/gems/ruby-2.2.3@proj/gems/nobrainer-0.29.0/lib/no_brainer/profiler/controller_runtime.rb:50:in `cleanup_view_runtime'
 # /Users/jon/.rvm/gems/ruby-2.2.3@proj/gems/activerecord-4.2.4/lib/active_record/railties/controller_runtime.rb:25:in `cleanup_view_runtime'
 # /Users/jon/.rvm/gems/ruby-2.2.3@proj/gems/actionpack-4.2.4/lib/action_controller/metal/instrumentation.rb:43:in `render'
 # /Users/jon/.rvm/gems/ruby-2.2.3@proj/gems/devise-3.5.2/lib/devise/test_helpers.rb:112:in `_process_unauthenticated'
 # /Users/jon/.rvm/gems/ruby-2.2.3@proj/gems/devise-3.5.2/lib/devise/test_helpers.rb:88:in `_catch_warden'
 # /Users/jon/.rvm/gems/ruby-2.2.3@proj/gems/devise-3.5.2/lib/devise/test_helpers.rb:19:in `process'
 # /Users/jon/.rvm/gems/ruby-2.2.3@proj/gems/actionpack-4.2.4/lib/action_controller/test_case.rb:518:in `post'
 # ./spec/controllers/users_controller_spec.rb:17:in `block (3 levels) in <top (required)>'

note that nobrainer isn't being used at all in this test.

writing the same test as an integration test works fine and doesn't result in the error, i expect it's got something to do with devise and the router but i don't have the time to dig too deep right now.

nviennot commented 8 years ago

that should be fixed :)

modosc commented 8 years ago

thanks!