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

allow is_crawler? & crawler_name to be called outside of rack #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

rgraff
Copy link

@rgraff rgraff commented Aug 3, 2020

When is_crawler? is called outside the context of a rack request--for example in specs--it will raise an error. This prevents that.

     NoMethodError:
       undefined method `[]' for nil:NilClass
     # /usr/local/bundle/gems/crawler_detect-1.0.1/lib/rack/crawler_detect.rb:11:in `is_crawler?'

When `is_crawler?` is called outside the content of a rack request--for example in specs--it will raise an error. This prevents that.
@loadkpi
Copy link
Owner

loadkpi commented Nov 4, 2020

hello Robert,

in this case is_crawler? will return nil that can be misinterpreted

@rgraff
Copy link
Author

rgraff commented Nov 5, 2020

@loadkpi good catch. updated.

@Jandrov
Copy link

Jandrov commented Dec 23, 2021

Is this going to be taken into account? I am facing the error in specs @rgraff @loadkpi

@rgraff
Copy link
Author

rgraff commented Dec 23, 2021

@Jandrov I don't know the status of getting this merged. In the meantime, you can fork my branch if you want to get your specs passing.

@loadkpi
Copy link
Owner

loadkpi commented Dec 23, 2021

hello guys!

could you provide the example of how it can be used outside of rack? I don't really understand

this PR makes possible to use these methods when they can't be used. In this case the result of them doesn't make sense. And it's probably better to raise exception instead of return incorrect values.

@rgraff
Copy link
Author

rgraff commented Dec 23, 2021

Here are two examples:

When writing unit test or specs, you'll often call methods outside the context of a rack request. Without this change, you need to mock the helper methods or setup the env variables. It's a little tedious.

When the helpers are used in views and those the views are used in out-of-band jobs too. For example, you may have a footer partial that calls is_crawler?. If that footer is then used in an email template asynchronously, it will raise an error. The work around is then write your own helpers which call is_crawler? and then rescue the errors.

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.

3 participants