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

Support string cookie values in rails test cases #734

Conversation

jcw-
Copy link
Contributor

@jcw- jcw- commented Dec 21, 2020

In Authlogic v6.2, a new method cookie_enabled? started exercising cookie code in test cases in a few more places than usual, resulting in existing test code in downstream projects that included cookies with string values (rather than hash values) to start failing with:

TypeError: no implicit conversion of Symbol into Integer

This PR adds support for both, using the same approach as Rails itself.

Before:
image

After:
image

@jaredbeck
Copy link
Collaborator

Hi @jcw- thanks for the contribution.

On one hand, this seems good because it makes RailsRequestAdapter#cookies act more like an actual rails request. For completeness, MockSignedCookieJar#[]= would also need this feature, right?

On the other hand, I don't think that RailsRequestAdapter is part of the public API of Authlogic. It's part of the test suite. It seems we're talking about adding a feature that Authlogic doesn't need, to Authlogic's private test suite. Can you talk a bit more about how "test code in downstream projects" use it, and why you think RailsRequestAdapter should be public API? Thanks.

@jcw-
Copy link
Contributor Author

jcw- commented Dec 21, 2020

Hi @jaredbeck, thanks for the quick response - good point about the MockSignedCookieJar, I can look into that. Here's some more background about my intent:

After upgrading to 6.2, some of our specs started failing, they were specs that had this:

      before(:each) do
        request.cookies[:some_cookie] = "something"
      end

It didn't seem like RailsRequestAdapter -> cookies had any test coverage, so this was my attempt to surface it - I'm not intending to change anything from private to public. I was actually struggling a bit to write tests for that code, which has an entry point in activate_authlogic. Any tips on a better approach to get test coverage on that?

@jaredbeck
Copy link
Collaborator

Thanks for the clarification. I was able to reproduce the TypeError in a work project by setting a string cookie.

# spec/controllers/user_sessions_controller_spec.rb
   describe '#new' do
     it 'succeeds' do
+      request.cookies[:some_cookie] = "something"
       UserSession.create!(....) # TypeError

When I debug the issue, I arrive at the same solution you did.

Please disregard my confusion about public/private API.

Let's move forward with this, making sure that this feature (string cookies) is added consistently to all of our test classes. I think there's more than one place in test_case/mock_cookie_jar.rb, for example.

@jcw-
Copy link
Contributor Author

jcw- commented Dec 21, 2020

@jaredbeck alright added support to the cookie jars, I'm not seeing anywhere else, let me know what you think...

@jaredbeck jaredbeck merged commit 9650f9e into binarylogic:master Dec 22, 2020
jaredbeck added a commit that referenced this pull request Dec 22, 2020
jaredbeck added a commit that referenced this pull request Dec 22, 2020
jaredbeck added a commit that referenced this pull request Dec 22, 2020
@jaredbeck
Copy link
Collaborator

Released as 6.4.0

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 this pull request may close these issues.

2 participants