wardencommunity/warden

Warden 1.2.5 breaks Rails/RSpec tests

lowjoel opened this issue · 20 comments

Hi there,

A bundle update was run by deppbot today and we found that just changing from 1.2.4 to 1.2.5 seems to have broken our specs: Coursemology/coursemology2#757 I ran the specs locally with 1.2.4 and they pass.

The errors all seem incredibly strange, to the tune of:

     Failure/Error:
       get root_path, 'user_email' => user.email,
                      'user_token' => user.authentication_token

     NameError:
       undefined local variable or method `root_path' for #<RSpec::ExampleGroups::UsersSignInWithToken::WithTenantInstance::WhenAUserTokenIsSpecifiedAsAParameter:0x0000864d7d2f98>

I did a diff between 1.2.4 and 1.2.5, but I don't see anything which can possibly be the culprit. Any ideas?

Thanks!

I have the same issue, I receive 'You Win' as request body
https://github.com/hassox/warden/blob/master/lib/warden/test/helpers.rb#L72

+1

same "You Win" issue

This config fix it. I told them in a PR to lock down version ;) @lowjoel change rack 1.3 to 1.6. It is lock down in gemfile! Does it solve your issue?

    diff-lcs (1.2.5)
    rack (1.6.4)
    rack-test (0.6.3)
      rack (>= 1.0)
    rake (10.5.0)
    rspec (3.4.0)
      rspec-core (~> 3.4.0)
      rspec-expectations (~> 3.4.0)
      rspec-mocks (~> 3.4.0)
    rspec-core (3.4.1)
      rspec-support (~> 3.4.0)
    rspec-expectations (3.4.0)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.4.0)
    rspec-mocks (3.4.1)
      diff-lcs (>= 1.2.0, < 2.0)
      rspec-support (~> 3.4.0)
    rspec-support (3.4.1)

@lowjoel finally, it might be the last PR. We need a way to get the warden object in test helpers. Do you use the test helpers in a controller tests? It create a fake app and env so it must override your tests. We need your help to solve this! Maybe separate the test helpers? @hassox make two classes of helpers so one ssume you know that it will ovverride.

I am not directly using warden, I think it's being pulled in by Devise.

My Gemfile lock is already on Rack 1.6.4

@lowjoel before closing the issue, use the last version of devise and force warden 1.2.4 if Devise permits it (not lock down on their side). Is the issue still there? and @giannileggio and @rilian might be a real issue from the PR

Sorry. Closing issue was fat finger on phone >.<

@lowjoel haha I was on my iPad trying to put a block of code earlier...

@lowjoel I think I might break down the helper into two files because I need warden object for a gem that do like Devise. I need the object to test it directly like they do in their own test helpers (Warden). I had no problem on my side with the tests helper, but it's not the case for everyone! I'll do a pull request to fix that

@acaron I took that PR I linked and reverted to 1.2.4, the tests pass.

I am honestly also pretty intrigued how this seemingly harmless change seems to have pretty nasty side effects.

@lowjoel it is not harmless, it use the same name: env and app. Which means that something does the same. If you are using Devise, it is bind a lot to Rails app so a lot of coupling brings a lot of problems. That is why I chose my gems carefully: no Rails binding. It might not come from there, but this must be fix! I'll push a branch into my forked repository. Can you try it when it's done?

hi, i have already locked warden to 1.2.4 in my project
the gem is a devise dependency.
i will try your branch later today. thank you for a quick response!

@rilian it might be Devise that need env and app oh well... so much coupling! Hope it will solve your case!

@acaron that seems to work, yes. I presume because you're not including those helper methods by default?

Unfortunately app and env are incredibly common variable/method names since so many things are middleware of some sort.

@lowjoel yes, exactly! I'll send the branch as a PR then

+1, I'm using devise (3.5.5), with bundle update, warden goes fom 1.2.4 to 1.2.5, now the following method returns nil for env['warden']:

def warden
  request.env['warden']
end

This value is used by Devise to call .authenticate, so we have the following error there:

# NoMethodError:
#   undefined method `authenticate' for nil:NilClass
#   /Users/wbotelhos/.rvm/gems/ruby-2.2.3@danca/gems/devise-3.5.5/lib/devise/controllers/helpers.rb:125:in `current_user'

i have tried

gem 'warden', github: 'acaron/warden', branch: 'fix-test-helpers'

and it's working well 👍

ps: this is how we attach devise to our rails test suite

RSpec.configure do |config|
  config.include Devise::TestHelpers, type: :controller
end

A new version has been pushed up at 1.2.6. Please upgrade. Sorry for the inconvenience folks.

thanks! 1.2.6 is working fine