[
  {
    "path": ".devcontainer/devcontainer.json",
    "content": "// For format details, see https://aka.ms/devcontainer.json. For config options, see the\n// README at: https://github.com/devcontainers/templates/tree/main/src/ruby\n{\n\t\"name\": \"Ruby\",\n\t// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile\n\t\"image\": \"mcr.microsoft.com/devcontainers/ruby:0-3-bullseye\",\n\t\"features\": {\n\t\t\"ghcr.io/devcontainers/features/github-cli:1\": {}\n\t},\n\n\t// Features to add to the dev container. More info: https://containers.dev/features.\n\t// \"features\": {},\n\n\t// Use 'forwardPorts' to make a list of ports inside the container available locally.\n\t// \"forwardPorts\": [],\n\n\t// Use 'postCreateCommand' to run commands after the container is created.\n\t\"postCreateCommand\": \"bundle install\",\n\n\t// Configure tool-specific properties.\n\t// \"customizations\": {},\n\n\t// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.\n\t// \"remoteUser\": \"root\"\n}\n"
  },
  {
    "path": ".github/code-scanning.yml",
    "content": "paths-ignore:\n  - test/**\n"
  },
  {
    "path": ".github/dependabot.yml",
    "content": "version: 2\nupdates:\n  - package-ecosystem: \"github-actions\"\n    directory: \"/\"\n    schedule:\n      interval: \"weekly\"\n"
  },
  {
    "path": ".github/workflows/test.yml",
    "content": "name: Test\n\npermissions:\n  contents: read\non:\n  push:\n    branches:\n      - main\n  pull_request:\n  workflow_dispatch:\njobs:\n  test:\n    strategy:\n      fail-fast: false\n      matrix:\n        gemfile:\n          - Gemfile\n          - gemfiles/Gemfile-rails-main\n          - gemfiles/Gemfile-rails-7-0\n          - gemfiles/Gemfile-rails-7-1\n          - gemfiles/Gemfile-rails-7-2\n          - gemfiles/Gemfile-rails-8-0\n        ruby:\n          - '4.0'\n          - '3.4'\n          - '3.3'\n          - '3.2'\n          - '3.1'\n          - '3.0'\n          - '2.7'\n        orm:\n          - active_record\n          - mongoid\n        exclude:\n          - gemfile: Gemfile\n            ruby: '3.1'\n          - gemfile: Gemfile\n            ruby: '3.0'\n          - gemfile: Gemfile\n            ruby: '2.7'\n          - gemfile: gemfiles/Gemfile-rails-main\n            ruby: '3.2'\n          - gemfile: gemfiles/Gemfile-rails-main\n            ruby: '3.1'\n          - gemfile: gemfiles/Gemfile-rails-main\n            ruby: '3.0'\n          - gemfile: gemfiles/Gemfile-rails-main\n            ruby: '2.7'\n          - gemfile: gemfiles/Gemfile-rails-8-0\n            ruby: '3.1'\n          - gemfile: gemfiles/Gemfile-rails-8-0\n            ruby: '3.0'\n          - gemfile: gemfiles/Gemfile-rails-8-0\n            ruby: '2.7'\n          - gemfile: gemfiles/Gemfile-rails-7-2\n            ruby: '3.0'\n          - gemfile: gemfiles/Gemfile-rails-7-2\n            ruby: '2.7'\n    runs-on: ubuntu-latest\n    env: # $BUNDLE_GEMFILE must be set at the job level, so it is set for all steps\n      BUNDLE_GEMFILE: ${{ matrix.gemfile }}\n      DEVISE_ORM: ${{ matrix.orm }}\n    steps:\n      - uses: actions/checkout@v6\n      - uses: ruby/setup-ruby@v1\n        with:\n          ruby-version: ${{ matrix.ruby }}\n          bundler-cache: true # runs bundle install and caches installed gems automatically\n      - uses: supercharge/mongodb-github-action@1.12.1\n        if: ${{ matrix.orm == 'mongoid' }}\n      - run: bundle exec rake\n"
  },
  {
    "path": ".gitignore",
    "content": "test/rails_app/log/*\ntest/rails_app/tmp/*\n*~\ncoverage/*\n*.sqlite3\n.bundle\nrdoc/*\npkg\nlog\ntest/tmp/*\ngemfiles/*.lock\n"
  },
  {
    "path": ".yardopts",
    "content": "--protected\n--no-private\n--embed-mixin ClassMethods\n-\nREADME.md\nCHANGELOG.rdoc\nCONTRIBUTING.md\nMIT-LICENSE\n\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "### 5.0.3 - 2026-03-16\n\n* security fixes\n  * Fix race condition vulnerability on confirmable \"change email\" which would allow confirming an email they don't own CVE-2026-32700 [#5783](https://github.com/heartcombo/devise/pull/5783) [#5784](https://github.com/heartcombo/devise/pull/5784)\n\n### 5.0.2 - 2026-02-18\n\n* enhancements\n  * Allow resource class scopes to override the global configuration for `sign_in_after_change_password` behaviour. [#5825](https://github.com/heartcombo/devise/pull/5825)\n    * _Note_: some users ran into an issue with this change because `RegistrationsController` now relies on a setting from the `:registerable` module. These users were configuring their own routes pointing to the `RegistrationsController` for resource edit/update actions mostly, without relying on the other registration actions (e.g. user sign up.), so they omitted `:registerable` from the model declaration. While using just a portion of the controller functionality is a valid use for `:registerable` (or any module really), the module must still be declared in the model, much like the other modules must be declared if you plan on using just a portion of their behavior. Please check [this issue](https://github.com/heartcombo/devise/pull/5828#issuecomment-3926822788) for more info.\n  * Add `sign_in_after_reset_password?` check hook to passwords controller, to allow it to be customized by users. [#5826](https://github.com/heartcombo/devise/pull/5826)\n\n### 5.0.1 - 2026-02-13\n\n* bug fixes\n  * Fix translation issue with German `E-Mail` on invalid authentication messages caused by previous fix for incorrect grammar [#5822](https://github.com/heartcombo/devise/pull/5822)\n\n### 5.0.0 - 2026-01-23\n\nno changes\n\n### 5.0.0.rc - 2025-12-31\n\n* breaking changes\n  * Drop support to Ruby < 2.7\n  * Drop support to Rails < 7.0\n  * Remove deprecated `:bypass` option from `sign_in` helper, use `bypass_sign_in` instead. [#5803](https://github.com/heartcombo/devise/pull/5803)\n  * Remove deprecated `devise_error_messages!` helper, use `render \"devise/shared/error_messages\", resource: resource` instead. [#5803](https://github.com/heartcombo/devise/pull/5803)\n  * Remove deprecated `scope` second argument from `sign_in(resource, :admin)` controller test helper, use `sign_in(resource, scope: :admin)` instead. [#5803](https://github.com/heartcombo/devise/pull/5803)\n  * Remove deprecated `Devise::TestHelpers`, use `Devise::Test::ControllerHelpers` instead. [#5803](https://github.com/heartcombo/devise/pull/5803)\n  * Remove deprecated `Devise::Models::Authenticatable::BLACKLIST_FOR_SERIALIZATION` [#5598](https://github.com/heartcombo/devise/pull/5598)\n  * Remove deprecated `Devise.activerecord51?` method.\n  * Remove `SecretKeyFinder` and use `app.secret_key_base` as the default secret key for `Devise.secret_key` if a custom `Devise.secret_key` is not provided.\n\n    This is potentially a breaking change because Devise previously used the following order to find a secret key:\n\n    ```\n    app.credentials.secret_key_base > app.secrets.secret_key_base > application.config.secret_key_base > application.secret_key_base\n    ```\n\n    Now, it always uses `application.secret_key_base`. Make sure you're using the same secret key after the upgrade; otherwise, previously generated tokens for `recoverable`, `lockable`, and `confirmable` will be invalid.\n    [#5645](https://github.com/heartcombo/devise/pull/5645)\n  * Change password instructions button label on devise view from `Send me reset password instructions` to `Send me password reset instructions` [#5515](https://github.com/heartcombo/devise/pull/5515)\n  * Change `<br>` tags separating form elements to wrapping them in `<p>` tags [#5494](https://github.com/heartcombo/devise/pull/5494)\n  * Replace `[data-turbo-cache=false]` with `[data-turbo-temporary]` on `devise/shared/error_messages` partial. This has been [deprecated by Turbo since v7.3.0 (released on Mar 1, 2023)](https://github.com/hotwired/turbo/releases/tag/v7.3.0).\n\n    If you are using an older version of Turbo and the default devise template, you'll need to copy it over to your app and change that back to `[data-turbo-cache=false]`.\n\n* enhancements\n  * Add Rails 8 support.\n    - Routes are lazy-loaded by default in test and development environments now so Devise loads them before `Devise.mappings` call. [#5728](https://github.com/heartcombo/devise/pull/5728)\n  * New apps using Rack 3.1+ will be generated using `config.responder.error_status = :unprocessable_content`, since [`:unprocessable_entity` has been deprecated by Rack](https://github.com/rack/rack/pull/2137).\n\n    Latest versions of [Rails transparently convert `:unprocessable_entity` -> `:unprocessable_content`](https://github.com/rails/rails/pull/53383), and Devise will use that in the failure app to avoid Rack deprecation warnings for apps that are configured with `:unprocessable_entity`. They can also simply change their `error_status` to `:unprocessable_content` in latest Rack versions to avoid the warning.\n  * Add Ruby 3.4 and 4.0 support.\n  * Reenable Mongoid test suite across all Rails 7+ versions, to ensure we continue supporting it. Changes to dirty tracking to support Mongoid 8.0+. [#5568](https://github.com/heartcombo/devise/pull/5568)\n  * Password length validator is changed from\n\n    ```\n    validates_length_of :password, within: password_length, allow_blank: true`\n    ```\n\n    to\n\n    ```\n    validates_length_of :password, minimum: proc { password_length.min }, maximum: proc { password_length.max }, allow_blank: true\n    ```\n\n    so it's possible to override `password_length` at runtime. [#5734](https://github.com/heartcombo/devise/pull/5734)\n\n* bug fixes\n  * Make `Devise` work without `ActionMailer` when `Zeitwerk` autoloader is used. [#5731](https://github.com/heartcombo/devise/pull/5731)\n  * Handle defaults `:from` and `:reply_to` as procs correctly by delegating to Rails [#5595](https://github.com/heartcombo/devise/pull/5595)\n  * Use `OmniAuth.config.allowed_request_methods` as routing verbs for the auth path [#5508](https://github.com/heartcombo/devise/pull/5508)\n  * Handle `on` and `ON` as true values to check params [#5514](https://github.com/heartcombo/devise/pull/5514)\n  * Fix passing `format` option to `devise_for` [#5732](https://github.com/heartcombo/devise/pull/5732)\n  * Use `ActiveRecord::SecurityUtils.secure_compare` in `Devise.secure_compare` to match two empty strings correctly. [#4829](https://github.com/heartcombo/devise/pull/4829)\n  * Respond with `401 Unauthorized` for non-navigational requests to destroy the session when there is no authenticated resource. [#4878](https://github.com/heartcombo/devise/pull/4878)\n  * Fix incorrect grammar of invalid authentication message with capitalized attributes, e.g.: \"Invalid Email or password\" => \"Invalid email or password\". (originally introduced by [#4014](https://github.com/heartcombo/devise/pull/4014), released on v4.1.0) [#4834](https://github.com/heartcombo/devise/pull/4834)\n\n\nPlease check [4-stable](https://github.com/heartcombo/devise/blob/4-stable/CHANGELOG.md)\nfor previous changes.\n"
  },
  {
    "path": "CODE_OF_CONDUCT.md",
    "content": "# Contributor Code of Conduct\n\nAs contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.\n\nWe are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.\n\nExamples of unacceptable behavior by participants include:\n\n* The use of sexualized language or imagery\n* Personal attacks\n* Trolling or insulting/derogatory comments\n* Public or private harassment\n* Publishing other's private information, such as physical or electronic addresses, without explicit permission\n* Other unethical or unprofessional conduct.\n\nProject maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.\n\nThis code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.\n\nInstances of abusive, harassing, or otherwise unacceptable behavior may be reported by sending an email to [heartcombo.oss@gmail.com](heartcombo.oss@gmail.com) or contacting one or more of the project maintainers.\n\nThis Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)\n"
  },
  {
    "path": "CONTRIBUTING.md",
    "content": "# How to contribute to Devise\n\nThanks for your interest on contributing to Devise! Here are a few general\nguidelines on contributing and reporting bugs to Devise that we ask you to\ntake a look first. Notice that all of your interactions in the project are\nexpected to follow our [Code of Conduct](CODE_OF_CONDUCT.md).\n\n## Reporting Issues\n\nBefore reporting a new issue, please be sure that the issue wasn't already\nreported or fixed by searching on GitHub through our [issues](https://github.com/heartcombo/devise/issues).\n\nWhen creating a new issue, be sure to include a **title and clear description**,\nas much relevant information as possible, and either a test case example or\neven better a **sample Rails app that replicates the issue** - Devise has a lot\nof moving parts and it's functionality can be affected by third party gems, so\nwe need as much context and details as possible to identify what might be broken\nfor you. We have a [test case template](guides/bug_report_templates/integration_test.rb)\nthat can be used to replicate issues with minimal setup.\n\nPlease do not attempt to translate Devise built in views. The views are meant\nto be a starting point for fresh apps and not production material - eventually\nall applications will require custom views where you can write your own copy and\ntranslate it if the application requires it . For historical references, please look into closed\n[Issues/Pull Requests](https://github.com/heartcombo/devise/issues?q=i18n) regarding\ninternationalization.\n\nAvoid opening new issues to ask questions in our issues tracker. Please go through\nthe project wiki, documentation and source code first, or try to ask your question\non [Stack Overflow](http://stackoverflow.com/questions/tagged/devise).\n\n**If you find a security bug, do not report it through GitHub. Please send an\ne-mail to [heartcombo.oss@gmail.com](mailto:heartcombo.oss@gmail.com)\ninstead.**\n\n## Sending Pull Requests\n\nBefore sending a new Pull Request, take a look on existing Pull Requests and Issues\nto see if the proposed change or fix has been discussed in the past, or if the\nchange was already implemented but not yet released.\n\nWe expect new Pull Requests to include enough tests for new or changed behavior,\nand we aim to maintain everything as most backwards compatible as possible,\nreserving breaking changes to be ship in major releases when necessary - you\ncan wrap the new code path with a setting toggle from the `Devise` module defined\nas `false` by default to require developers to opt-in for the new behavior.\n\nIf your Pull Request includes new or changed behavior, be sure that the changes\nare beneficial to a wide range of use cases or it's an application specific change\nthat might not be so valuable to other applications. Some changes can be introduced\nas a new `devise-something` gem instead of belonging to the main codebase.\n\nWhen adding new settings, you can take advantage of the [`Devise::Models.config`](https://github.com/heartcombo/devise/blob/245b1f9de0b3386b7913e14b60ea24f43b77feb0/lib/devise/models.rb#L13-L50) method to add class and instance level fallbacks\nto the new setting.\n\nWe also welcome Pull Requests that improve our existing documentation (both our\n`README.md` and the RDoc sections in the source code) or improve existing rough\nedges in our API that might be blocking existing integrations or 3rd party gems.\n\n## Other ways to contribute\n\nWe welcome anyone that wants to contribute to Devise to triage and reply to\nopen issues to help troubleshoot and fix existing bugs on Devise. Here is what\nyou can do:\n\n* Help ensure that existing issues follows the recommendations from the\n_[Reporting Issues](#reporting-issues)_ section, providing feedback to the issue's\nauthor on what might be missing.\n* Review and update the existing content of our [Wiki](https://github.com/heartcombo/devise/wiki)\nwith up to date instructions and code samples - the wiki was grown with several\ndifferent tutorials and references that we can't keep track of everything, so if\nthere is a page that showcases an integration or customization that you are\nfamiliar with feel free to update it as necessary.\n* Review existing Pull Requests, and testing patches against real existing\napplications that use Devise.\n\nThanks again for your interest on contributing to the project!\n\n:heart:\n"
  },
  {
    "path": "Gemfile",
    "content": "# frozen_string_literal: true\n\nsource \"https://rubygems.org\"\n\ngemspec\n\ngem \"omniauth\"\ngem \"omniauth-oauth2\"\ngem \"rails\", \"~> 8.1.0\"\ngem \"rdoc\"\n\ngem \"rails-controller-testing\"\n\ngem \"responders\", \"~> 3.1\"\n\ngroup :test do\n  gem \"minitest\", \"< 6\"\n  gem \"mocha\", \"~> 2.1\", require: false\n  gem \"omniauth-facebook\"\n  gem \"omniauth-openid\"\n  gem \"rexml\"\n  gem \"timecop\"\n  gem \"webrat\"\n  gem \"ostruct\"\nend\n\nplatforms :ruby do\n  gem \"sqlite3\"\nend\n\ngroup :mongoid do\n  gem \"mongoid\", \"~> 9.0\", github: \"mongodb/mongoid\", branch: \"9.0-stable\"\nend\n"
  },
  {
    "path": "ISSUE_TEMPLATE.md",
    "content": "## Pre-check\n\n- Do not use the issues tracker for help or support, try Stack Overflow.\n- For bugs, do a quick search and make sure the bug has not yet been reported\n- If you found a security bug, do not report it through GitHub. Please send an e-mail to heartcombo.oss@gmail.com instead.\n- Finally, be nice and have fun!\n\n## Environment\n\n- Ruby **[version]**\n- Rails **[version]**\n- Devise **[version]**\n\n## Current behavior\n\nInclude code samples, errors, steps to reproduce the error and stack traces if appropriate.\n\nWill be even more helpful if you provide a sample application or a test case that reproduces the error.\n\n## Expected behavior\n"
  },
  {
    "path": "MIT-LICENSE",
    "content": "Copyright (c) 2020-CURRENT Rafael França, Carlos Antonio da Silva\nCopyright (c) 2009-2019 Plataformatec\n\nPermission is hereby granted, free of charge, to any person obtaining\na copy of this software and associated documentation files (the\n\"Software\"), to deal in the Software without restriction, including\nwithout limitation the rights to use, copy, modify, merge, publish,\ndistribute, sublicense, and/or sell copies of the Software, and to\npermit persons to whom the Software is furnished to do so, subject to\nthe following conditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n"
  },
  {
    "path": "README.md",
    "content": "![Devise Logo](https://raw.github.com/heartcombo/devise/main/devise.png)\n\nDevise is a flexible authentication solution for Rails based on Warden. It:\n\n* Is Rack based;\n* Is a complete MVC solution based on Rails engines;\n* Allows you to have multiple models signed in at the same time;\n* Is based on a modularity concept: use only what you really need.\n\nIt's composed of 10 modules:\n\n* [Database Authenticatable](https://www.rubydoc.info/gems/devise/Devise/Models/DatabaseAuthenticatable): hashes and stores a password in the database to validate the authenticity of a user while signing in. The authentication can be done both through POST requests or HTTP Basic Authentication.\n* [Omniauthable](https://www.rubydoc.info/gems/devise/Devise/Models/Omniauthable): adds OmniAuth (https://github.com/omniauth/omniauth) support.\n* [Confirmable](https://www.rubydoc.info/gems/devise/Devise/Models/Confirmable): sends emails with confirmation instructions and verifies whether an account is already confirmed during sign in.\n* [Recoverable](https://www.rubydoc.info/gems/devise/Devise/Models/Recoverable): resets the user password and sends reset instructions.\n* [Registerable](https://www.rubydoc.info/gems/devise/Devise/Models/Registerable): handles signing up users through a registration process, also allowing them to edit and destroy their account.\n* [Rememberable](https://www.rubydoc.info/gems/devise/Devise/Models/Rememberable): manages generating and clearing a token for remembering the user from a saved cookie.\n* [Trackable](https://www.rubydoc.info/gems/devise/Devise/Models/Trackable): tracks sign in count, timestamps and IP address.\n* [Timeoutable](https://www.rubydoc.info/gems/devise/Devise/Models/Timeoutable): expires sessions that have not been active in a specified period of time.\n* [Validatable](https://www.rubydoc.info/gems/devise/Devise/Models/Validatable): provides validations of email and password. It's optional and can be customized, so you're able to define your own validations.\n* [Lockable](https://www.rubydoc.info/gems/devise/Devise/Models/Lockable): locks an account after a specified number of failed sign-in attempts. Can unlock via email or after a specified time period.\n\n## Table of Contents\n\n<!-- TOC depthFrom:1 depthTo:6 withLinks:1 orderedList:0 -->\n\n- [Information](#information)\n\t- [The Devise wiki](#the-devise-wiki)\n\t- [Bug reports](#bug-reports)\n\t- [StackOverflow and Mailing List](#stackoverflow-and-mailing-list)\n\t- [RDocs](#rdocs)\n\t- [Example applications](#example-applications)\n\t- [Extensions](#extensions)\n\t- [Supported Ruby / Rails versions](#supported-ruby--rails-versions)\n\t- [Contributing](#contributing)\n- [Starting with Rails?](#starting-with-rails)\n- [Getting started](#getting-started)\n\t- [Controller filters and helpers](#controller-filters-and-helpers)\n\t- [Configuring Models](#configuring-models)\n\t- [Strong Parameters](#strong-parameters)\n\t- [Configuring views](#configuring-views)\n\t- [Configuring controllers](#configuring-controllers)\n\t- [Configuring routes](#configuring-routes)\n\t- [I18n](#i18n)\n\t- [Test helpers](#test-helpers)\n\t- [Controller tests](#controller-tests)\n\t- [Integration tests](#integration-tests)\n\t- [OmniAuth](#omniauth)\n\t- [Configuring multiple models](#configuring-multiple-models)\n\t- [Active Job Integration](#active-job-integration)\n\t- [Password reset tokens and Rails logs](#password-reset-tokens-and-rails-logs)\n\t- [Other ORMs](#other-orms)\n\t- [Rails API mode](#rails-api-mode)\n- [Additional information](#additional-information)\n\t- [Warden](#warden)\n- [License](#license)\n\n<!-- /TOC -->\n\n\n\n## Information\n\n### The Devise wiki\n\nThe Devise Wiki has lots of additional information about Devise including many \"how-to\" articles and answers to the most frequently asked questions. Please browse the Wiki after finishing this README:\n\nhttps://github.com/heartcombo/devise/wiki\n\n### Bug reports\n\nIf you discover a problem with Devise, we would like to know about it. However, we ask that you please review these guidelines before submitting a bug report:\n\nhttps://github.com/heartcombo/devise/wiki/Bug-reports\n\nIf you have discovered a security related bug, please do *NOT* use the GitHub issue tracker. Send an email to heartcombo.oss@gmail.com.\n\n### StackOverflow and Mailing List\n\nIf you have any questions, comments, or concerns, please use StackOverflow instead of the GitHub issue tracker:\n\nhttp://stackoverflow.com/questions/tagged/devise\n\nThe deprecated mailing lists can still be read on:\n\nhttps://groups.google.com/group/plataformatec-devise\nhttps://groups.google.com/group/heartcombo\n\n### RDocs\n\nYou can view the Devise documentation in RDoc format here:\n\nhttp://rubydoc.info/github/heartcombo/devise/main/frames\n\nIf you need to use Devise with previous versions of Rails, you can always run \"gem server\" from the command line after you install the gem to access the old documentation.\n\n### Example applications\n\nThere are a few example applications available on GitHub that demonstrate various features of Devise with different versions of Rails. You can view them here:\n\nhttps://github.com/heartcombo/devise/wiki/Example-Applications\n\n### Extensions\n\nOur community has created a number of extensions that add functionality above and beyond what is included with Devise. You can view a list of available extensions and add your own here:\n\nhttps://github.com/heartcombo/devise/wiki/Extensions\n\n### Supported Ruby / Rails versions\n\nWe intend to maintain support for all Ruby / Rails versions that haven't reached end-of-life.\n\nFor more information about specific versions please check [Ruby](https://www.ruby-lang.org/en/downloads/branches/)\nand [Rails](https://guides.rubyonrails.org/maintenance_policy.html) maintenance policies, and our test matrix.\n\n### Contributing\n\nWe hope that you will consider contributing to Devise. Please read this short overview for some information about how to get started:\n\nhttps://github.com/heartcombo/devise/wiki/Contributing\n\nYou will usually want to write tests for your changes.  To run the test suite, go into Devise's top-level directory and run `bundle install` and `bin/test`.\nDevise works with multiple Ruby and Rails versions, and ActiveRecord and Mongoid ORMs, which means you can run the test suite with some modifiers: `DEVISE_ORM` and `BUNDLE_GEMFILE`.\n\n#### DEVISE_ORM\nSince Devise supports both Mongoid and ActiveRecord, we rely on this variable to run specific code for each ORM.\nThe default value of `DEVISE_ORM` is `active_record`. To run the tests for Mongoid, you can pass `mongoid`:\n```\nDEVISE_ORM=mongoid bin/test\n\n==> Devise.orm = :mongoid\n```\nWhen running the tests for Mongoid, you will need to have a MongoDB server (version 2.0 or newer) running on your system.\n\nPlease note that the command output will show the variable value being used.\n\n#### BUNDLE_GEMFILE\nWe can use this variable to tell bundler what Gemfile it should use (instead of the one in the current directory).\nInside the [gemfiles](https://github.com/heartcombo/devise/tree/main/gemfiles) directory, we have one for each version of Rails we support. When you send us a pull request, it may happen that the test suite breaks using some of them. If that's the case, you can simulate the same environment using the `BUNDLE_GEMFILE` variable.\nFor example, if the tests broke using Ruby 3.4 and Rails 8.0, you can do the following:\n```bash\nchruby 3.4.0 # or rbenv shell 3.4.0, or rvm use 3.4.0, etc.\nBUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 bundle install\nBUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 bin/test\n```\n\nYou can also combine both of them if the tests broke for Mongoid:\n```bash\nBUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 bundle install\nBUNDLE_GEMFILE=gemfiles/Gemfile-rails-8-0 DEVISE_ORM=mongoid bin/test\n```\n\n### Running tests\nDevise uses [minitest](https://github.com/seattlerb/minitest) as test framework.\n\n* Running all tests:\n```bash\nbin/test\n```\n\n* Running tests for an specific file:\n```bash\nbin/test test/models/trackable_test.rb\n```\n\n* Running a specific test given a line number or a regex:\n```bash\nbin/test test/models/trackable_test.rb:16\nbin/test test/models/trackable_test.rb -n '/update.*record/'\n```\n\n## Starting with Rails?\n\nIf you are building your first Rails application, we recommend you *do not* use Devise. Devise requires a good understanding of the Rails Framework. In such cases, we advise you to start a simple authentication system from scratch. Here's a few resources that should help you get started:\n\n* Michael Hartl's online book: https://www.railstutorial.org/book/modeling_users\n* Ryan Bates' Railscasts: http://railscasts.com/episodes/250-authentication-from-scratch and http://railscasts.com/episodes/250-authentication-from-scratch-revised\n* Codecademy's Ruby on Rails: Authentication and Authorization: https://www.codecademy.com/learn/rails-auth\n\nOnce you have solidified your understanding of Rails and authentication mechanisms, we assure you Devise will be very pleasant to work with. :smiley:\n\n## Getting started\n\nDevise 5 works with Rails 7 onwards. Run:\n\n```sh\nbundle add devise\n```\n\nNext, you need to run the generator:\n\n```console\nrails generate devise:install\n```\n\nAt this point, a number of instructions will appear in the console. Among these instructions, you'll need to set up the default URL options for the Devise mailer in each environment. Here is a possible configuration for `config/environments/development.rb`:\n\n```ruby\nconfig.action_mailer.default_url_options = { host: 'localhost', port: 3000 }\n```\n\nThe generator will install an initializer which describes ALL of Devise's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add Devise to any of your models using the generator.\n\n\nIn the following command you will replace `MODEL` with the class name used for the application’s users (it’s frequently `User` but could also be `Admin`). This will create a model (if one does not exist) and configure it with the default Devise modules. The generator also configures your `config/routes.rb` file to point to the Devise controller.\n\n```console\nrails generate devise MODEL\n```\n\nNext, check the MODEL for any additional configuration options you might want to add, such as confirmable or lockable. If you add an option, be sure to inspect the migration file (created by the generator if your ORM supports them) and uncomment the appropriate section.  For example, if you add the confirmable option in the model, you'll need to uncomment the Confirmable section in the migration.\n\nThen run `rails db:migrate`\n\nYou should restart your application after changing Devise's configuration options (this includes stopping spring). Otherwise, you will run into strange errors, for example, users being unable to login and route helpers being undefined.\n\n### Controller filters and helpers\n\nDevise will create some helpers to use inside your controllers and views. To set up a controller with user authentication, just add this before_action (assuming your devise model is 'User'):\n\n```ruby\nbefore_action :authenticate_user!\n```\n\nFor Rails 5, note that `protect_from_forgery` is no longer prepended to the `before_action` chain, so if you have set `authenticate_user` before `protect_from_forgery`, your request will result in \"Can't verify CSRF token authenticity.\" To resolve this, either change the order in which you call them, or use `protect_from_forgery prepend: true`.\n\nIf your devise model is something other than User, replace \"_user\" with \"_yourmodel\". The same logic applies to the instructions below.\n\nTo verify if a user is signed in, use the following helper:\n\n```ruby\nuser_signed_in?\n```\n\nFor the current signed-in user, this helper is available:\n\n```ruby\ncurrent_user\n```\n\nYou can access the session for this scope:\n\n```ruby\nuser_session\n```\n\nAfter signing in a user, confirming the account or updating the password, Devise will look for a scoped root path to redirect to. For instance, when using a `:user` resource, the `user_root_path` will be used if it exists; otherwise, the default `root_path` will be used. This means that you need to set the root inside your routes:\n\n```ruby\nroot to: 'home#index'\n```\n\nYou can also override `after_sign_in_path_for` and `after_sign_out_path_for` to customize your redirect hooks.\n\nNotice that if your Devise model is called `Member` instead of `User`, for example, then the helpers available are:\n\n```ruby\nbefore_action :authenticate_member!\n\nmember_signed_in?\n\ncurrent_member\n\nmember_session\n```\n\n### Configuring Models\n\nThe Devise method in your models also accepts some options to configure its modules. For example, you can choose the cost of the hashing algorithm with:\n\n```ruby\ndevise :database_authenticatable, :registerable, :confirmable, :recoverable, stretches: 13\n```\n\nBesides `:stretches`, you can define `:pepper`, `:encryptor`, `:confirm_within`, `:remember_for`, `:timeout_in`, `:unlock_in` among other options. For more details, see the initializer file that was created when you invoked the \"devise:install\" generator described above. This file is usually located at `/config/initializers/devise.rb`.\n\n### Strong Parameters\n\nThe Parameter Sanitizer API has changed for Devise 4 :warning:\n\n*For previous Devise versions see https://github.com/heartcombo/devise/tree/3-stable#strong-parameters*\n\nWhen you customize your own views, you may end up adding new attributes to forms. Rails 4 moved the parameter sanitization from the model to the controller, causing Devise to handle this concern at the controller as well.\n\nThere are just three actions in Devise that allow any set of parameters to be passed down to the model, therefore requiring sanitization. Their names and default permitted parameters are:\n\n* `sign_in` (`Devise::SessionsController#create`) - Permits only the authentication keys (like `email`)\n* `sign_up` (`Devise::RegistrationsController#create`) - Permits authentication keys plus `password` and `password_confirmation`\n* `account_update` (`Devise::RegistrationsController#update`) - Permits authentication keys plus `password`, `password_confirmation` and `current_password`\n\nIn case you want to permit additional parameters (the lazy way™), you can do so using a simple before action in your `ApplicationController`:\n\n```ruby\nclass ApplicationController < ActionController::Base\n  before_action :configure_permitted_parameters, if: :devise_controller?\n\n  protected\n\n  def configure_permitted_parameters\n    devise_parameter_sanitizer.permit(:sign_up, keys: [:username])\n  end\nend\n```\n\nThe above works for any additional fields where the parameters are simple scalar types. If you have nested attributes (say you're using `accepts_nested_attributes_for`), then you will need to tell devise about those nestings and types:\n\n```ruby\nclass ApplicationController < ActionController::Base\n  before_action :configure_permitted_parameters, if: :devise_controller?\n\n  protected\n\n  def configure_permitted_parameters\n    devise_parameter_sanitizer.permit(:sign_up, keys: [:first_name, :last_name, address_attributes: [:country, :state, :city, :area, :postal_code]])\n  end\nend\n```\n\nDevise allows you to completely change Devise defaults or invoke custom behavior by passing a block:\n\nTo permit simple scalar values for username and email, use this\n\n```ruby\ndef configure_permitted_parameters\n  devise_parameter_sanitizer.permit(:sign_in) do |user_params|\n    user_params.permit(:username, :email)\n  end\nend\n```\n\nIf you have some checkboxes that express the roles a user may take on registration, the browser will send those selected checkboxes as an array. An array is not one of Strong Parameters' permitted scalars, so we need to configure Devise in the following way:\n\n```ruby\ndef configure_permitted_parameters\n  devise_parameter_sanitizer.permit(:sign_up) do |user_params|\n    user_params.permit({ roles: [] }, :email, :password, :password_confirmation)\n  end\nend\n```\nFor the list of permitted scalars, and how to declare permitted keys in nested hashes and arrays, see\n\nhttps://github.com/rails/strong_parameters#nested-parameters\n\nIf you have multiple Devise models, you may want to set up a different parameter sanitizer per model. In this case, we recommend inheriting from `Devise::ParameterSanitizer` and adding your own logic:\n\n```ruby\nclass User::ParameterSanitizer < Devise::ParameterSanitizer\n  def initialize(*)\n    super\n    permit(:sign_up, keys: [:username, :email])\n  end\nend\n```\n\nAnd then configure your controllers to use it:\n\n```ruby\nclass ApplicationController < ActionController::Base\n  protected\n\n  def devise_parameter_sanitizer\n    if resource_class == User\n      User::ParameterSanitizer.new(User, :user, params)\n    else\n      super # Use the default one\n    end\n  end\nend\n```\n\nThe example above overrides the permitted parameters for the user to be both `:username` and `:email`. The non-lazy way to configure parameters would be by defining the before filter above in a custom controller. We detail how to configure and customize controllers in some sections below.\n\n### Configuring views\n\nWe built Devise to help you quickly develop an application that uses authentication. However, we don't want to be in your way when you need to customize it.\n\nSince Devise is an engine, all its views are packaged inside the gem. These views will help you get started, but after some time you may want to change them. If this is the case, you just need to invoke the following generator, and it will copy all views to your application:\n\n```console\nrails generate devise:views\n```\n\nIf you have more than one Devise model in your application (such as `User` and `Admin`), you will notice that Devise uses the same views for all models. Fortunately, Devise offers an easy way to customize views. All you need to do is set `config.scoped_views = true` inside the `config/initializers/devise.rb` file.\n\nAfter doing so, you will be able to have views based on the role like `users/sessions/new` and `admins/sessions/new`. If no view is found within the scope, Devise will use the default view at `devise/sessions/new`. You can also use the generator to generate scoped views:\n\n```console\nrails generate devise:views users\n```\n\nIf you would like to generate only a few sets of views, like the ones for the `registerable` and `confirmable` module,\nyou can pass a list of views to the generator with the `-v` flag.\n\n```console\nrails generate devise:views -v registrations confirmations\n```\n\n### Configuring controllers\n\nIf the customization at the views level is not enough, you can customize each controller by following these steps:\n\n1. Create your custom controllers using the generator which requires a scope:\n\n    ```console\n    rails generate devise:controllers [scope]\n    ```\n\n    If you specify `users` as the scope, controllers will be created in `app/controllers/users/`.\n    And the sessions controller will look like this:\n\n    ```ruby\n    class Users::SessionsController < Devise::SessionsController\n      # GET /resource/sign_in\n      # def new\n      #   super\n      # end\n      ...\n    end\n    ```\n    Use the `-c` flag to specify one or more controllers, for example: `rails generate devise:controllers users -c sessions`\n\n2. Tell the router to use this controller:\n\n    ```ruby\n    devise_for :users, controllers: { sessions: 'users/sessions' }\n    ```\n\n3. Recommended but not required: copy (or move) the views from `devise/sessions` to `users/sessions`. Rails will continue using the views from `devise/sessions` due to inheritance if you skip this step, but having the views matching the controller(s) keeps things consistent.\n\n4. Finally, change or extend the desired controller actions.\n\n    You can completely override a controller action:\n\n    ```ruby\n    class Users::SessionsController < Devise::SessionsController\n      def create\n        # custom sign-in code\n      end\n    end\n    ```\n\n    Or you can simply add new behavior to it:\n\n    ```ruby\n    class Users::SessionsController < Devise::SessionsController\n      def create\n        super do |resource|\n          BackgroundWorker.trigger(resource)\n        end\n      end\n    end\n    ```\n\n    This is useful for triggering background jobs or logging events during certain actions.\n\nRemember that Devise uses flash messages to let users know if sign in was successful or unsuccessful. Devise expects your application to call `flash[:notice]` and `flash[:alert]` as appropriate. Do not print the entire flash hash, print only specific keys. In some circumstances, Devise adds a `:timedout` key to the flash hash, which is not meant for display. Remove this key from the hash if you intend to print the entire hash.\n\n### Configuring routes\n\nDevise also ships with default routes. If you need to customize them, you should probably be able to do it through the devise_for method. It accepts several options like :class_name, :path_prefix and so on, including the possibility to change path names for I18n:\n\n```ruby\ndevise_for :users, path: 'auth', path_names: { sign_in: 'login', sign_out: 'logout', password: 'secret', confirmation: 'verification', unlock: 'unblock', registration: 'register', sign_up: 'cmon_let_me_in' }\n```\n\nBe sure to check `devise_for` [documentation](https://www.rubydoc.info/gems/devise/ActionDispatch/Routing/Mapper#devise_for-instance_method) for details.\n\nIf you have the need for more deep customization, for instance to also allow \"/sign_in\" besides \"/users/sign_in\", all you need to do is create your routes normally and wrap them in a `devise_scope` block in the router:\n\n```ruby\ndevise_scope :user do\n  get 'sign_in', to: 'devise/sessions#new'\nend\n```\n\nThis way, you tell Devise to use the scope `:user` when \"/sign_in\" is accessed. Notice `devise_scope` is also aliased as `as` in your router.\n\nPlease note: You will still need to add `devise_for` in your routes in order to use helper methods such as `current_user`.\n\n```ruby\ndevise_for :users, skip: :all\n```\n\n### Hotwire/Turbo\n\nDevise integrates with Hotwire/Turbo by treating such requests as navigational, and configuring certain responses for errors and redirects to match the expected behavior. New apps are generated with the following response configuration by default, and existing apps may opt-in by adding the config to their Devise initializers:\n\n```ruby\nDevise.setup do |config|\n  # ...\n  # When using Devise with Hotwire/Turbo, the http status for error responses\n  # and some redirects must match the following. The default in Devise for existing\n  # apps is `200 OK` and `302 Found` respectively, but new apps are generated with\n  # these new defaults that match Hotwire/Turbo behavior.\n  # Note: These might become the new default in future versions of Devise.\n  config.responder.error_status = :unprocessable_content # for Rack 3.1 or higher\n  # config.responder.error_status = :unprocessable_entity # for Rack 3.0 or lower\n  config.responder.redirect_status = :see_other\nend\n```\n\n**Important**: these custom responses require the `responders` gem version to be `3.1.0` or higher, please make sure you update it if you're going to use this configuration. Check [this upgrade guide](https://github.com/heartcombo/devise/wiki/How-To:-Upgrade-to-Devise-4.9.0-[Hotwire-Turbo-integration]) for more info.\n\n_Note_: the above statuses configuration may become the default for Devise in a future release.\n\nThere are a couple other changes you might need to make in your app to work with Hotwire/Turbo, if you're migrating from rails-ujs:\n\n* The `data-confirm` option that adds a confirmation modal to buttons/forms before submission needs to change to `data-turbo-confirm`, so that Turbo handles those appropriately.\n* The `data-method` option that sets the request method for link submissions needs to change to `data-turbo-method`. This is not necessary for `button_to` or `form`s since Turbo can handle those.\n\nIf you're setting up Devise to sign out via `:delete`, and you're using links (instead of buttons wrapped in a form) to sign out with the `method: :delete` option, they will need to be updated as described above. (Devise does not provide sign out links/buttons in its shared views.)\n\nMake sure to inspect your views looking for those, and change appropriately.\n\n### I18n\n\nDevise uses flash messages with I18n, in conjunction with the flash keys :notice and :alert. To customize your app, you can set up your locale file:\n\n```yaml\nen:\n  devise:\n    sessions:\n      signed_in: 'Signed in successfully.'\n```\n\nYou can also create distinct messages based on the resource you've configured using the singular name given in routes:\n\n```yaml\nen:\n  devise:\n    sessions:\n      user:\n        signed_in: 'Welcome user, you are signed in.'\n      admin:\n        signed_in: 'Hello admin!'\n```\n\nThe Devise mailer uses a similar pattern to create subject messages:\n\n```yaml\nen:\n  devise:\n    mailer:\n      confirmation_instructions:\n        subject: 'Hello everybody!'\n        user_subject: 'Hello User! Please confirm your email'\n      reset_password_instructions:\n        subject: 'Reset instructions'\n```\n\nTake a look at our locale file to check all available messages. You may also be interested in one of the many translations that are available on our wiki:\n\nhttps://github.com/heartcombo/devise/wiki/I18n\n\nCaution: Devise Controllers inherit from ApplicationController. If your app uses multiple locales, you should be sure to set I18n.locale in ApplicationController.\n\n### Test helpers\n\nDevise includes some test helpers for controller and integration tests.\nIn order to use them, you need to include the respective module in your test\ncases/specs.\n\n### Controller tests\n\nController tests require that you include `Devise::Test::IntegrationHelpers` on\nyour test case or its parent `ActionController::TestCase` superclass.\nFor Rails versions prior to 5, include `Devise::Test::ControllerHelpers` instead, since the superclass\nfor controller tests was changed to ActionDispatch::IntegrationTest\n(for more details, see the [Integration tests](#integration-tests) section).\n\n```ruby\nclass PostsControllerTest < ActionController::TestCase\n  include Devise::Test::IntegrationHelpers # Rails >= 5\nend\n```\n\n```ruby\nclass PostsControllerTest < ActionController::TestCase\n  include Devise::Test::ControllerHelpers # Rails < 5\nend\n```\n\nIf you're using RSpec, you can put the following inside a file named\n`spec/support/devise.rb` or in your `spec/spec_helper.rb` (or\n`spec/rails_helper.rb` if you are using `rspec-rails`):\n\n```ruby\nRSpec.configure do |config|\n  config.include Devise::Test::ControllerHelpers, type: :controller\n  config.include Devise::Test::ControllerHelpers, type: :view\nend\n```\n\nJust be sure that this inclusion is made *after* the `require 'rspec/rails'` directive.\n\nNow you are ready to use the `sign_in` and `sign_out` methods on your controller\ntests:\n\n```ruby\nsign_in @user\nsign_in @user, scope: :admin\n```\n\nIf you are testing Devise internal controllers or a controller that inherits\nfrom Devise's, you need to tell Devise which mapping should be used before a\nrequest. This is necessary because Devise gets this information from the router,\nbut since controller tests do not pass through the router, it needs to be stated\nexplicitly. For example, if you are testing the user scope, simply use:\n\n```ruby\ntest 'GET new' do\n  # Mimic the router behavior of setting the Devise scope through the env.\n  @request.env['devise.mapping'] = Devise.mappings[:user]\n\n  # Use the sign_in helper to sign in a fixture `User` record.\n  sign_in users(:alice)\n\n  get :new\n\n  # assert something\nend\n```\n\n### Integration tests\n\nIntegration test helpers are available by including the\n`Devise::Test::IntegrationHelpers` module.\n\n```ruby\nclass PostsTests < ActionDispatch::IntegrationTest\n  include Devise::Test::IntegrationHelpers\nend\n```\n\nNow you can use the following `sign_in` and `sign_out` methods in your integration\ntests:\n\n```ruby\nsign_in users(:bob)\nsign_in users(:bob), scope: :admin\n\nsign_out :user\n```\n\nRSpec users can include the `IntegrationHelpers` module on their `:feature` specs.\n\n```ruby\nRSpec.configure do |config|\n  config.include Devise::Test::IntegrationHelpers, type: :feature\nend\n```\n\nUnlike controller tests, integration tests do not need to supply the\n`devise.mapping` `env` value, as the mapping can be inferred by the routes that\nare executed in your tests.\n\nYou can read more about testing your Rails controllers with RSpec in the wiki:\n\n* https://github.com/heartcombo/devise/wiki/How-To:-Test-controllers-with-Rails-(and-RSpec)\n\n### OmniAuth\n\nDevise comes with OmniAuth support out of the box to authenticate with other providers. To use it, simply specify your OmniAuth configuration in `config/initializers/devise.rb`:\n\n```ruby\nconfig.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'\n```\n\nYou can read more about OmniAuth support in the wiki:\n\n* https://github.com/heartcombo/devise/wiki/OmniAuth:-Overview\n\n### Configuring multiple models\n\nDevise allows you to set up as many Devise models as you want. If you want to have an Admin model with just authentication and timeout features, in addition to the User model above, just run:\n\n```ruby\n# Create a migration with the required fields\ncreate_table :admins do |t|\n  t.string :email\n  t.string :encrypted_password\n  t.timestamps null: false\nend\n\n# Inside your Admin model\ndevise :database_authenticatable, :timeoutable\n\n# Inside your routes\ndevise_for :admins\n\n# Inside your protected controller\nbefore_action :authenticate_admin!\n\n# Inside your controllers and views\nadmin_signed_in?\ncurrent_admin\nadmin_session\n```\n\nAlternatively, you can simply run the Devise generator.\n\nKeep in mind that those models will have completely different routes. They **do not** and **cannot** share the same controller for sign in, sign out and so on. In case you want to have different roles sharing the same actions, we recommend that you use a role-based approach, by either providing a role column or using a dedicated gem for authorization.\n\n### Active Job Integration\n\nIf you are using Active Job to deliver Action Mailer messages in the\nbackground through a queuing back-end, you can send Devise emails through your\nexisting queue by overriding the `send_devise_notification` method in your model.\n\n```ruby\ndef send_devise_notification(notification, *args)\n  devise_mailer.send(notification, self, *args).deliver_later\nend\n```\n\n### Password reset tokens and Rails logs\n\nIf you enable the [Recoverable](https://www.rubydoc.info/gems/devise/Devise/Models/Recoverable) module, note that a stolen password reset token could give an attacker access to your application. Devise takes effort to generate random, secure tokens, and stores only token digests in the database, never plaintext. However the default logging behavior in Rails can cause plaintext tokens to leak into log files:\n\n1. Action Mailer logs the entire contents of all outgoing emails to the DEBUG level. Password reset tokens delivered to users in email will be leaked.\n2. Active Job logs all arguments to every enqueued job at the INFO level. If you configure Devise to use `deliver_later` to send password reset emails, password reset tokens will be leaked.\n\nRails sets the production logger level to INFO by default. Consider changing your production logger level to WARN if you wish to prevent tokens from being leaked into your logs. In `config/environments/production.rb`:\n\n```ruby\nconfig.log_level = :warn\n```\n\n\n### Other ORMs\n\nDevise supports ActiveRecord (default) and Mongoid. To select another ORM, simply require it in the initializer file.\n\n### Rails API Mode\n\nRails 5+ has a built-in [API Mode](https://edgeguides.rubyonrails.org/api_app.html) which optimizes Rails for use as an API (only). Devise is _somewhat_ able to handle applications that are built in this mode without additional modifications in the sense that it should not raise exceptions and the like. But some issues may still arise during `development`/`testing`, as we still don't know the full extent of this compatibility. (For more information, see [issue #4947](https://github.com/heartcombo/devise/issues/4947/))\n\n#### Supported Authentication Strategies\nAPI-only applications don't support browser-based authentication via cookies, which is devise's default. Yet, devise can still provide authentication out of the box in those cases with the `http_authenticatable` strategy, which uses HTTP Basic Auth and authenticates the user on each request. (For more info, see this wiki article for [How To: Use HTTP Basic Authentication](https://github.com/heartcombo/devise/wiki/How-To:-Use-HTTP-Basic-Authentication))\n\nThe devise default for HTTP Auth is disabled, so it will need to be enabled in the devise initializer for the database strategy:\n\n```ruby\nconfig.http_authenticatable = [:database]\n```\n\nThis restriction does not limit you from implementing custom warden strategies, either in your application or via gem-based extensions for devise.\nA common authentication strategy for APIs is token-based authentication. For more information on extending devise to support this type of authentication and others, see the wiki article for [Simple Token Authentication Examples and alternatives](https://github.com/heartcombo/devise/wiki/How-To:-Simple-Token-Authentication-Example#alternatives) or this blog post on [Custom authentication methods with Devise](http://blog.plataformatec.com.br/2019/01/custom-authentication-methods-with-devise/).\n\n#### Testing\nAPI Mode changes the order of the middleware stack, and this can cause problems for `Devise::Test::IntegrationHelpers`. This problem usually surfaces as an ```undefined method `[]=' for nil:NilClass``` error when using integration test helpers, such as `#sign_in`. The solution is simply to reorder the middlewares by adding the following to test.rb:\n\n```ruby\nRails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Cookies\nRails.application.config.middleware.insert_before Warden::Manager, ActionDispatch::Session::CookieStore\n```\n\nFor a deeper understanding of this, review [this issue](https://github.com/heartcombo/devise/issues/4696).\n\nAdditionally be mindful that without views supported, some email-based flows from Confirmable, Recoverable and Lockable are not supported directly at this time.\n\n## Additional information\n\n### Warden\n\nDevise is based on Warden, which is a general Rack authentication framework created by Daniel Neighman. We encourage you to read more about Warden here:\n\nhttps://github.com/wardencommunity/warden\n\n## License\n\nMIT License.\nCopyright 2020-CURRENT Rafael França, Carlos Antonio da Silva.\nCopyright 2009-2019 Plataformatec.\n\nThe Devise logo is licensed under [Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License](https://creativecommons.org/licenses/by-nc-nd/4.0/).\n"
  },
  {
    "path": "Rakefile",
    "content": "# encoding: UTF-8\n# frozen_string_literal: true\n\nrequire 'bundler/gem_tasks'\nrequire 'rake/testtask'\nrequire 'rdoc/task'\n\ndesc 'Default: run tests for all ORMs.'\ntask default: :test\n\ndesc 'Run Devise tests for all ORMs.'\ntask :pre_commit do\n  Dir[File.join(File.dirname(__FILE__), 'test', 'orm', '*.rb')].each do |file|\n    orm = File.basename(file).split(\".\").first\n    # \"Some day, my son, rake's inner wisdom will reveal itself.  Until then,\n    # take this `system` -- may its brute force protect you well.\"\n    exit 1 unless system \"rake test DEVISE_ORM=#{orm}\"\n  end\nend\n\ndesc 'Run Devise unit tests.'\nRake::TestTask.new(:test) do |t|\n  t.libs << 'lib'\n  t.libs << 'test'\n  t.pattern = 'test/**/*_test.rb'\n  t.verbose = true\n  t.warning = false\nend\n\ndesc 'Generate documentation for Devise.'\nRake::RDocTask.new(:rdoc) do |rdoc|\n  rdoc.rdoc_dir = 'rdoc'\n  rdoc.title    = 'Devise'\n  rdoc.options << '--line-numbers' << '--inline-source'\n  rdoc.rdoc_files.include('README.md')\n  rdoc.rdoc_files.include('lib/**/*.rb')\nend\n"
  },
  {
    "path": "app/controllers/devise/confirmations_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Devise::ConfirmationsController < DeviseController\n  # GET /resource/confirmation/new\n  def new\n    self.resource = resource_class.new\n  end\n\n  # POST /resource/confirmation\n  def create\n    self.resource = resource_class.send_confirmation_instructions(resource_params)\n    yield resource if block_given?\n\n    if successfully_sent?(resource)\n      respond_with({}, location: after_resending_confirmation_instructions_path_for(resource_name))\n    else\n      respond_with(resource)\n    end\n  end\n\n  # GET /resource/confirmation?confirmation_token=abcdef\n  def show\n    self.resource = resource_class.confirm_by_token(params[:confirmation_token])\n    yield resource if block_given?\n\n    if resource.errors.empty?\n      set_flash_message!(:notice, :confirmed)\n      respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }\n    else\n      # TODO: use `error_status` when the default changes to `:unprocessable_entity` / `:unprocessable_content`.\n      respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }\n    end\n  end\n\n  protected\n\n    # The path used after resending confirmation instructions.\n    def after_resending_confirmation_instructions_path_for(resource_name)\n      is_navigational_format? ? new_session_path(resource_name) : '/'\n    end\n\n    # The path used after confirmation.\n    def after_confirmation_path_for(resource_name, resource)\n      if signed_in?(resource_name)\n        signed_in_root_path(resource)\n      else\n        new_session_path(resource_name)\n      end\n    end\n\n    def translation_scope\n      'devise.confirmations'\n    end\nend\n"
  },
  {
    "path": "app/controllers/devise/omniauth_callbacks_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Devise::OmniauthCallbacksController < DeviseController\n  prepend_before_action { request.env[\"devise.skip_timeout\"] = true }\n\n  def passthru\n    render status: 404, plain: \"Not found. Authentication passthru.\"\n  end\n\n  def failure\n    set_flash_message! :alert, :failure, kind: OmniAuth::Utils.camelize(failed_strategy.name), reason: failure_message\n    redirect_to after_omniauth_failure_path_for(resource_name)\n  end\n\n  protected\n\n  def failed_strategy\n    request.respond_to?(:get_header) ? request.get_header(\"omniauth.error.strategy\") : request.env[\"omniauth.error.strategy\"]\n  end\n\n  def failure_message\n    exception = request.respond_to?(:get_header) ? request.get_header(\"omniauth.error\") : request.env[\"omniauth.error\"]\n    error   = exception.error_reason if exception.respond_to?(:error_reason)\n    error ||= exception.error        if exception.respond_to?(:error)\n    error ||= (request.respond_to?(:get_header) ? request.get_header(\"omniauth.error.type\") : request.env[\"omniauth.error.type\"]).to_s\n    error.to_s.humanize if error\n  end\n\n  def after_omniauth_failure_path_for(scope)\n    new_session_path(scope)\n  end\n\n  def translation_scope\n    'devise.omniauth_callbacks'\n  end\nend\n"
  },
  {
    "path": "app/controllers/devise/passwords_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Devise::PasswordsController < DeviseController\n  prepend_before_action :require_no_authentication\n  # Render the #edit only if coming from a reset password email link\n  append_before_action :assert_reset_token_passed, only: :edit\n\n  # GET /resource/password/new\n  def new\n    self.resource = resource_class.new\n  end\n\n  # POST /resource/password\n  def create\n    self.resource = resource_class.send_reset_password_instructions(resource_params)\n    yield resource if block_given?\n\n    if successfully_sent?(resource)\n      respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))\n    else\n      respond_with(resource)\n    end\n  end\n\n  # GET /resource/password/edit?reset_password_token=abcdef\n  def edit\n    self.resource = resource_class.new\n    set_minimum_password_length\n    resource.reset_password_token = params[:reset_password_token]\n  end\n\n  # PUT /resource/password\n  def update\n    self.resource = resource_class.reset_password_by_token(resource_params)\n    yield resource if block_given?\n\n    if resource.errors.empty?\n      resource.unlock_access! if unlockable?(resource)\n      if sign_in_after_reset_password?\n        flash_message = resource.active_for_authentication? ? :updated : :updated_not_active\n        set_flash_message!(:notice, flash_message)\n        resource.after_database_authentication\n        sign_in(resource_name, resource)\n      else\n        set_flash_message!(:notice, :updated_not_active)\n      end\n      respond_with resource, location: after_resetting_password_path_for(resource)\n    else\n      set_minimum_password_length\n      respond_with resource\n    end\n  end\n\n  protected\n    def after_resetting_password_path_for(resource)\n      sign_in_after_reset_password? ? after_sign_in_path_for(resource) : new_session_path(resource_name)\n    end\n\n    # The path used after sending reset password instructions\n    def after_sending_reset_password_instructions_path_for(resource_name)\n      new_session_path(resource_name) if is_navigational_format?\n    end\n\n    # Check if a reset_password_token is provided in the request\n    def assert_reset_token_passed\n      if params[:reset_password_token].blank?\n        set_flash_message(:alert, :no_token)\n        redirect_to new_session_path(resource_name)\n      end\n    end\n\n    # Check if the user should be signed in automatically after resetting the password.\n    def sign_in_after_reset_password?\n      resource_class.sign_in_after_reset_password\n    end\n\n    # Check if proper Lockable module methods are present & unlock strategy\n    # allows to unlock resource on password reset\n    def unlockable?(resource)\n      resource.respond_to?(:unlock_access!) &&\n        resource.respond_to?(:unlock_strategy_enabled?) &&\n        resource.unlock_strategy_enabled?(:email)\n    end\n\n    def translation_scope\n      'devise.passwords'\n    end\nend\n"
  },
  {
    "path": "app/controllers/devise/registrations_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Devise::RegistrationsController < DeviseController\n  prepend_before_action :require_no_authentication, only: [:new, :create, :cancel]\n  prepend_before_action :authenticate_scope!, only: [:edit, :update, :destroy]\n  prepend_before_action :set_minimum_password_length, only: [:new, :edit]\n\n  # GET /resource/sign_up\n  def new\n    build_resource\n    yield resource if block_given?\n    respond_with resource\n  end\n\n  # POST /resource\n  def create\n    build_resource(sign_up_params)\n\n    resource.save\n    yield resource if block_given?\n    if resource.persisted?\n      if resource.active_for_authentication?\n        set_flash_message! :notice, :signed_up\n        sign_up(resource_name, resource)\n        respond_with resource, location: after_sign_up_path_for(resource)\n      else\n        set_flash_message! :notice, :\"signed_up_but_#{resource.inactive_message}\"\n        expire_data_after_sign_in!\n        respond_with resource, location: after_inactive_sign_up_path_for(resource)\n      end\n    else\n      clean_up_passwords resource\n      set_minimum_password_length\n      respond_with resource\n    end\n  end\n\n  # GET /resource/edit\n  def edit\n    render :edit\n  end\n\n  # PUT /resource\n  # We need to use a copy of the resource because we don't want to change\n  # the current user in place.\n  def update\n    self.resource = resource_class.to_adapter.get!(send(:\"current_#{resource_name}\").to_key)\n    prev_unconfirmed_email = resource.unconfirmed_email if resource.respond_to?(:unconfirmed_email)\n\n    resource_updated = update_resource(resource, account_update_params)\n    yield resource if block_given?\n    if resource_updated\n      set_flash_message_for_update(resource, prev_unconfirmed_email)\n      bypass_sign_in resource, scope: resource_name if sign_in_after_change_password?\n\n      respond_with resource, location: after_update_path_for(resource)\n    else\n      clean_up_passwords resource\n      set_minimum_password_length\n      respond_with resource\n    end\n  end\n\n  # DELETE /resource\n  def destroy\n    resource.destroy\n    Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name)\n    set_flash_message! :notice, :destroyed\n    yield resource if block_given?\n    respond_with_navigational(resource){ redirect_to after_sign_out_path_for(resource_name), status: Devise.responder.redirect_status }\n  end\n\n  # GET /resource/cancel\n  # Forces the session data which is usually expired after sign\n  # in to be expired now. This is useful if the user wants to\n  # cancel oauth signing in/up in the middle of the process,\n  # removing all OAuth session data.\n  def cancel\n    expire_data_after_sign_in!\n    redirect_to new_registration_path(resource_name)\n  end\n\n  protected\n\n  # By default we want to require a password checks on update.\n  # You can overwrite this method in your own RegistrationsController.\n  def update_resource(resource, params)\n    resource.update_with_password(params)\n  end\n\n  # Build a devise resource passing in the session. Useful to move\n  # temporary session data to the newly created user.\n  def build_resource(hash = {})\n    self.resource = resource_class.new_with_session(hash, session)\n  end\n\n  # Signs in a user on sign up. You can overwrite this method in your own\n  # RegistrationsController.\n  def sign_up(resource_name, resource)\n    sign_in(resource_name, resource)\n  end\n\n  # The path used after sign up. You need to overwrite this method\n  # in your own RegistrationsController.\n  def after_sign_up_path_for(resource)\n    after_sign_in_path_for(resource) if is_navigational_format?\n  end\n\n  # The path used after sign up for inactive accounts. You need to overwrite\n  # this method in your own RegistrationsController.\n  def after_inactive_sign_up_path_for(resource)\n    scope = Devise::Mapping.find_scope!(resource)\n    router_name = Devise.mappings[scope].router_name\n    context = router_name ? send(router_name) : self\n    context.respond_to?(:root_path) ? context.root_path : \"/\"\n  end\n\n  # The default url to be used after updating a resource. You need to overwrite\n  # this method in your own RegistrationsController.\n  def after_update_path_for(resource)\n    sign_in_after_change_password? ? signed_in_root_path(resource) : new_session_path(resource_name)\n  end\n\n  # Authenticates the current scope and gets the current resource from the session.\n  def authenticate_scope!\n    send(:\"authenticate_#{resource_name}!\", force: true)\n    self.resource = send(:\"current_#{resource_name}\")\n  end\n\n  # Check if the user should be signed in automatically after updating the password.\n  def sign_in_after_change_password?\n    return true if account_update_params[:password].blank?\n\n    resource_class.sign_in_after_change_password\n  end\n\n  def sign_up_params\n    devise_parameter_sanitizer.sanitize(:sign_up)\n  end\n\n  def account_update_params\n    devise_parameter_sanitizer.sanitize(:account_update)\n  end\n\n  def translation_scope\n    'devise.registrations'\n  end\n\n  private\n\n  def set_flash_message_for_update(resource, prev_unconfirmed_email)\n    return unless is_flashing_format?\n\n    flash_key = if update_needs_confirmation?(resource, prev_unconfirmed_email)\n                  :update_needs_confirmation\n                elsif sign_in_after_change_password?\n                  :updated\n                else\n                  :updated_but_not_signed_in\n                end\n    set_flash_message :notice, flash_key\n  end\n\n  def update_needs_confirmation?(resource, previous)\n    resource.respond_to?(:pending_reconfirmation?) &&\n      resource.pending_reconfirmation? &&\n      previous != resource.unconfirmed_email\n  end\nend\n"
  },
  {
    "path": "app/controllers/devise/sessions_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Devise::SessionsController < DeviseController\n  prepend_before_action :require_no_authentication, only: [:new, :create]\n  prepend_before_action :allow_params_authentication!, only: :create\n  prepend_before_action :verify_signed_out_user, only: :destroy\n  prepend_before_action(only: [:create, :destroy]) { request.env[\"devise.skip_timeout\"] = true }\n\n  # GET /resource/sign_in\n  def new\n    self.resource = resource_class.new(sign_in_params)\n    clean_up_passwords(resource)\n    yield resource if block_given?\n    respond_with(resource, serialize_options(resource))\n  end\n\n  # POST /resource/sign_in\n  def create\n    self.resource = warden.authenticate!(auth_options)\n    set_flash_message!(:notice, :signed_in)\n    sign_in(resource_name, resource)\n    yield resource if block_given?\n    respond_with resource, location: after_sign_in_path_for(resource)\n  end\n\n  # DELETE /resource/sign_out\n  def destroy\n    signed_out = (Devise.sign_out_all_scopes ? sign_out : sign_out(resource_name))\n    set_flash_message! :notice, :signed_out if signed_out\n    yield if block_given?\n    respond_to_on_destroy(non_navigational_status: :no_content)\n  end\n\n  protected\n\n  def sign_in_params\n    devise_parameter_sanitizer.sanitize(:sign_in)\n  end\n\n  def serialize_options(resource)\n    methods = resource_class.authentication_keys.dup\n    methods = methods.keys if methods.is_a?(Hash)\n    methods << :password if resource.respond_to?(:password)\n    { methods: methods, only: [:password] }\n  end\n\n  def auth_options\n    { scope: resource_name, recall: \"#{controller_path}#new\", locale: I18n.locale }\n  end\n\n  def translation_scope\n    'devise.sessions'\n  end\n\n  private\n\n  # Check if there is no signed in user before doing the sign out.\n  #\n  # If there is no signed in user, it will set the flash message and redirect\n  # to the after_sign_out path.\n  def verify_signed_out_user\n    if all_signed_out?\n      set_flash_message! :notice, :already_signed_out\n\n      respond_to_on_destroy(non_navigational_status: :unauthorized)\n    end\n  end\n\n  def all_signed_out?\n    users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }\n\n    users.all?(&:blank?)\n  end\n\n  def respond_to_on_destroy(non_navigational_status: :no_content)\n    # We actually need to hardcode this as Rails default responder doesn't\n    # support returning empty response on GET request\n    respond_to do |format|\n      format.all { head non_navigational_status }\n      format.any(*navigational_formats) { redirect_to after_sign_out_path_for(resource_name), status: Devise.responder.redirect_status }\n    end\n  end\nend\n"
  },
  {
    "path": "app/controllers/devise/unlocks_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Devise::UnlocksController < DeviseController\n  prepend_before_action :require_no_authentication\n\n  # GET /resource/unlock/new\n  def new\n    self.resource = resource_class.new\n  end\n\n  # POST /resource/unlock\n  def create\n    self.resource = resource_class.send_unlock_instructions(resource_params)\n    yield resource if block_given?\n\n    if successfully_sent?(resource)\n      respond_with({}, location: after_sending_unlock_instructions_path_for(resource))\n    else\n      respond_with(resource)\n    end\n  end\n\n  # GET /resource/unlock?unlock_token=abcdef\n  def show\n    self.resource = resource_class.unlock_access_by_token(params[:unlock_token])\n    yield resource if block_given?\n\n    if resource.errors.empty?\n      set_flash_message! :notice, :unlocked\n      respond_with_navigational(resource){ redirect_to after_unlock_path_for(resource) }\n    else\n      # TODO: use `error_status` when the default changes to `:unprocessable_entity` / `:unprocessable_content`.\n      respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }\n    end\n  end\n\n  protected\n\n    # The path used after sending unlock password instructions\n    def after_sending_unlock_instructions_path_for(resource)\n      new_session_path(resource) if is_navigational_format?\n    end\n\n    # The path used after unlocking the resource\n    def after_unlock_path_for(resource)\n      new_session_path(resource)  if is_navigational_format?\n    end\n\n    def translation_scope\n      'devise.unlocks'\n    end\nend\n"
  },
  {
    "path": "app/controllers/devise_controller.rb",
    "content": "# frozen_string_literal: true\n\n# All Devise controllers are inherited from here.\nclass DeviseController < Devise.parent_controller.constantize\n  include Devise::Controllers::ScopedViews\n\n  if respond_to?(:helper)\n    helper DeviseHelper\n  end\n\n  if respond_to?(:helper_method)\n    helpers = %w(resource scope_name resource_name signed_in_resource\n                 resource_class resource_params devise_mapping)\n    helper_method(*helpers)\n  end\n\n  prepend_before_action :assert_is_devise_resource!\n  self.responder = Devise.responder\n  respond_to :html if mimes_for_respond_to.empty?\n\n  # Override prefixes to consider the scoped view.\n  # Notice we need to check for the request due to a bug in\n  # Action Controller tests that forces _prefixes to be\n  # loaded before even having a request object.\n  #\n  # This method should be public as it is in ActionPack\n  # itself. Changing its visibility may break other gems.\n  def _prefixes #:nodoc:\n    @_prefixes ||= if self.class.scoped_views? && request && devise_mapping\n      [\"#{devise_mapping.scoped_path}/#{controller_name}\"] + super\n    else\n      super\n    end\n  end\n\n  # Override internal methods to exclude `_prefixes` from action methods since\n  # we override it above.\n  #\n  # There was an intentional change in Rails 7.1 that will allow it to become\n  # an action method because it's a public method of a non-abstract controller,\n  # but we also can't make this abstract because it can affect potential actions\n  # defined in the parent controller, so instead we ensure `_prefixes` is going\n  # to be considered internal. (and thus, won't become an action method.)\n  # Ref: https://github.com/rails/rails/pull/48699\n  def self.internal_methods #:nodoc:\n    super << :_prefixes\n  end\n\n  protected\n\n  # Gets the actual resource stored in the instance variable\n  def resource\n    instance_variable_get(:\"@#{resource_name}\")\n  end\n\n  # Proxy to devise map name\n  def resource_name\n    devise_mapping.name\n  end\n  alias :scope_name :resource_name\n\n  # Proxy to devise map class\n  def resource_class\n    devise_mapping.to\n  end\n\n  # Returns a signed in resource from session (if one exists)\n  def signed_in_resource\n    warden.authenticate(scope: resource_name)\n  end\n\n  # Attempt to find the mapped route for devise based on request path\n  def devise_mapping\n    @devise_mapping ||= request.env[\"devise.mapping\"]\n  end\n\n  # Checks whether it's a devise mapped resource or not.\n  def assert_is_devise_resource! #:nodoc:\n    unknown_action! <<-MESSAGE unless devise_mapping\nCould not find devise mapping for path #{request.fullpath.inspect}.\nThis may happen for two reasons:\n\n1) You forgot to wrap your route inside the scope block. For example:\n\n  devise_scope :user do\n    get \"/some/route\" => \"some_devise_controller\"\n  end\n\n2) You are testing a Devise controller bypassing the router.\n   If so, you can explicitly tell Devise which mapping to use:\n\n   @request.env[\"devise.mapping\"] = Devise.mappings[:user]\n\nMESSAGE\n  end\n\n  # Returns real navigational formats which are supported by Rails\n  def navigational_formats\n    @navigational_formats ||= Devise.navigational_formats.select { |format| Mime::EXTENSION_LOOKUP[format.to_s] }\n  end\n\n  def unknown_action!(msg)\n    logger.debug \"[Devise] #{msg}\" if logger\n    raise AbstractController::ActionNotFound, msg\n  end\n\n  # Sets the resource creating an instance variable\n  def resource=(new_resource)\n    instance_variable_set(:\"@#{resource_name}\", new_resource)\n  end\n\n  # Helper for use in before_actions where no authentication is required.\n  #\n  # Example:\n  #   before_action :require_no_authentication, only: :new\n  def require_no_authentication\n    assert_is_devise_resource!\n    return unless is_navigational_format?\n    no_input = devise_mapping.no_input_strategies\n\n    authenticated = if no_input.present?\n      args = no_input.dup.push scope: resource_name\n      warden.authenticate?(*args)\n    else\n      warden.authenticated?(resource_name)\n    end\n\n    if authenticated && resource = warden.user(resource_name)\n      set_flash_message(:alert, 'already_authenticated', scope: 'devise.failure')\n      redirect_to after_sign_in_path_for(resource)\n    end\n  end\n\n  # Helper for use after calling send_*_instructions methods on a resource.\n  # If we are in paranoid mode, we always act as if the resource was valid\n  # and instructions were sent.\n  def successfully_sent?(resource)\n    notice = if Devise.paranoid\n      resource.errors.clear\n      :send_paranoid_instructions\n    elsif resource.errors.empty?\n      :send_instructions\n    end\n\n    if notice\n      set_flash_message! :notice, notice\n      true\n    end\n  end\n\n  # Sets the flash message with :key, using I18n. By default you are able\n  # to set up your messages using specific resource scope, and if no message is\n  # found we look to the default scope. Set the \"now\" options key to a true\n  # value to populate the flash.now hash in lieu of the default flash hash (so\n  # the flash message will be available to the current action instead of the\n  # next action).\n  # Example (i18n locale file):\n  #\n  #   en:\n  #     devise:\n  #       passwords:\n  #         #default_scope_messages - only if resource_scope is not found\n  #         user:\n  #           #resource_scope_messages\n  #\n  # Please refer to README or en.yml locale file to check what messages are\n  # available.\n  def set_flash_message(key, kind, options = {})\n    message = find_message(kind, options)\n    if options[:now]\n      flash.now[key] = message if message.present?\n    else\n      flash[key] = message if message.present?\n    end\n  end\n\n  # Sets flash message if is_flashing_format? equals true\n  def set_flash_message!(key, kind, options = {})\n    if is_flashing_format?\n      set_flash_message(key, kind, options)\n    end\n  end\n\n  # Sets minimum password length to show to user\n  def set_minimum_password_length\n    if devise_mapping.validatable?\n      @minimum_password_length = resource_class.password_length.min\n    end\n  end\n\n  def devise_i18n_options(options)\n    options\n  end\n\n  # Get message for given\n  def find_message(kind, options = {})\n    options[:scope] ||= translation_scope\n    options[:default] = Array(options[:default]).unshift(kind.to_sym)\n    options[:resource_name] = resource_name\n    options = devise_i18n_options(options)\n    I18n.t(\"#{options[:resource_name]}.#{kind}\", **options)\n  end\n\n  # Controllers inheriting DeviseController are advised to override this\n  # method so that other controllers inheriting from them would use\n  # existing translations.\n  def translation_scope\n    \"devise.#{controller_name}\"\n  end\n\n  def clean_up_passwords(object)\n    object.clean_up_passwords if object.respond_to?(:clean_up_passwords)\n  end\n\n  def respond_with_navigational(*args, &block)\n    respond_with(*args) do |format|\n      format.any(*navigational_formats, &block)\n    end\n  end\n\n  def resource_params\n    params.fetch(resource_name, {})\n  end\n\n  ActiveSupport.run_load_hooks(:devise_controller, self)\nend\n"
  },
  {
    "path": "app/helpers/devise_helper.rb",
    "content": "# frozen_string_literal: true\n\n# Keeping the helper around for backward compatibility.\nmodule DeviseHelper\nend\n"
  },
  {
    "path": "app/mailers/devise/mailer.rb",
    "content": "# frozen_string_literal: true\n\nif defined?(ActionMailer)\n  class Devise::Mailer < Devise.parent_mailer.constantize\n    include Devise::Mailers::Helpers\n\n    def confirmation_instructions(record, token, opts = {})\n      @token = token\n      devise_mail(record, :confirmation_instructions, opts)\n    end\n\n    def reset_password_instructions(record, token, opts = {})\n      @token = token\n      devise_mail(record, :reset_password_instructions, opts)\n    end\n\n    def unlock_instructions(record, token, opts = {})\n      @token = token\n      devise_mail(record, :unlock_instructions, opts)\n    end\n\n    def email_changed(record, opts = {})\n      devise_mail(record, :email_changed, opts)\n    end\n\n    def password_change(record, opts = {})\n      devise_mail(record, :password_change, opts)\n    end\n  end\nend\n"
  },
  {
    "path": "app/views/devise/confirmations/new.html.erb",
    "content": "<h2>Resend confirmation instructions</h2>\n\n<%= form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>\n  <%= render \"devise/shared/error_messages\", resource: resource %>\n\n  <div class=\"field\">\n    <p><%= f.label :email %></p>\n    <p><%= f.email_field :email, autofocus: true, autocomplete: \"email\", value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email) %></p>\n  </div>\n\n  <div class=\"actions\">\n    <%= f.submit \"Resend confirmation instructions\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "app/views/devise/mailer/confirmation_instructions.html.erb",
    "content": "<p>Welcome <%= @email %>!</p>\n\n<p>You can confirm your account email through the link below:</p>\n\n<p><%= link_to 'Confirm my account', confirmation_url(@resource, confirmation_token: @token) %></p>\n"
  },
  {
    "path": "app/views/devise/mailer/email_changed.html.erb",
    "content": "<p>Hello <%= @email %>!</p>\n\n<% if @resource.try(:unconfirmed_email?) %>\n  <p>We're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.</p>\n<% else %>\n  <p>We're contacting you to notify you that your email has been changed to <%= @resource.email %>.</p>\n<% end %>\n"
  },
  {
    "path": "app/views/devise/mailer/password_change.html.erb",
    "content": "<p>Hello <%= @resource.email %>!</p>\n\n<p>We're contacting you to notify you that your password has been changed.</p>\n"
  },
  {
    "path": "app/views/devise/mailer/reset_password_instructions.html.erb",
    "content": "<p>Hello <%= @resource.email %>!</p>\n\n<p>Someone has requested a link to change your password. You can do this through the link below.</p>\n\n<p><%= link_to 'Change my password', edit_password_url(@resource, reset_password_token: @token) %></p>\n\n<p>If you didn't request this, please ignore this email.</p>\n<p>Your password won't change until you access the link above and create a new one.</p>\n"
  },
  {
    "path": "app/views/devise/mailer/unlock_instructions.html.erb",
    "content": "<p>Hello <%= @resource.email %>!</p>\n\n<p>Your account has been locked due to an excessive number of unsuccessful sign in attempts.</p>\n\n<p>Click the link below to unlock your account:</p>\n\n<p><%= link_to 'Unlock my account', unlock_url(@resource, unlock_token: @token) %></p>\n"
  },
  {
    "path": "app/views/devise/passwords/edit.html.erb",
    "content": "<h2>Change your password</h2>\n\n<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>\n  <%= render \"devise/shared/error_messages\", resource: resource %>\n  <%= f.hidden_field :reset_password_token %>\n\n  <div class=\"field\">\n    <p><%= f.label :password, \"New password\" %></p>\n    <% if @minimum_password_length %>\n      <p><em>(<%= @minimum_password_length %> characters minimum)</em></p>\n    <% end %>\n    <p><%= f.password_field :password, autofocus: true, autocomplete: \"new-password\" %></p>\n  </div>\n\n  <div class=\"field\">\n    <p><%= f.label :password_confirmation, \"Confirm new password\" %></p>\n    <p><%= f.password_field :password_confirmation, autocomplete: \"new-password\" %></p>\n  </div>\n\n  <div class=\"actions\">\n    <%= f.submit \"Change my password\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "app/views/devise/passwords/new.html.erb",
    "content": "<h2>Forgot your password?</h2>\n\n<%= form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>\n  <%= render \"devise/shared/error_messages\", resource: resource %>\n\n  <div class=\"field\">\n    <p><%= f.label :email %></p>\n    <p><%= f.email_field :email, autofocus: true, autocomplete: \"email\" %></p>\n  </div>\n\n  <div class=\"actions\">\n    <%= f.submit \"Send me password reset instructions\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "app/views/devise/registrations/edit.html.erb",
    "content": "<h2>Edit <%= resource_name.to_s.humanize %></h2>\n\n<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>\n  <%= render \"devise/shared/error_messages\", resource: resource %>\n\n  <div class=\"field\">\n    <p><%= f.label :email %></p>\n    <p><%= f.email_field :email, autofocus: true, autocomplete: \"email\" %></p>\n  </div>\n\n  <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>\n    <div>Currently waiting confirmation for: <%= resource.unconfirmed_email %></div>\n  <% end %>\n\n  <div class=\"field\">\n    <p><%= f.label :password %> <i>(leave blank if you don't want to change it)</i></p>\n    <p><%= f.password_field :password, autocomplete: \"new-password\" %></p>\n    <% if @minimum_password_length %>\n      <p><em><%= @minimum_password_length %> characters minimum</em></p>\n    <% end %>\n  </div>\n\n  <div class=\"field\">\n    <p><%= f.label :password_confirmation %></p>\n    <p><%= f.password_field :password_confirmation, autocomplete: \"new-password\" %></p>\n  </div>\n\n  <div class=\"field\">\n    <p><%= f.label :current_password %> <i>(we need your current password to confirm your changes)</i></p>\n    <p><%= f.password_field :current_password, autocomplete: \"current-password\" %></p>\n  </div>\n\n  <div class=\"actions\">\n    <%= f.submit \"Update\" %>\n  </div>\n<% end %>\n\n<h3>Cancel my account</h3>\n\n<div>Unhappy? <%= button_to \"Cancel my account\", registration_path(resource_name), data: { confirm: \"Are you sure?\", turbo_confirm: \"Are you sure?\" }, method: :delete %></div>\n\n<%= link_to \"Back\", :back %>\n"
  },
  {
    "path": "app/views/devise/registrations/new.html.erb",
    "content": "<h2>Sign up</h2>\n\n<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>\n  <%= render \"devise/shared/error_messages\", resource: resource %>\n\n  <div class=\"field\">\n    <p><%= f.label :email %></p>\n    <p><%= f.email_field :email, autofocus: true, autocomplete: \"email\" %></p>\n  </div>\n\n  <div class=\"field\">\n    <p><%= f.label :password %></p>\n    <% if @minimum_password_length %>\n      <p><em>(<%= @minimum_password_length %> characters minimum)</em></p>\n    <% end %>\n    <p><%= f.password_field :password, autocomplete: \"new-password\" %></p>\n  </div>\n\n  <div class=\"field\">\n    <p><%= f.label :password_confirmation %></p>\n    <p><%= f.password_field :password_confirmation, autocomplete: \"new-password\" %></p>\n  </div>\n\n  <div class=\"actions\">\n    <%= f.submit \"Sign up\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "app/views/devise/sessions/new.html.erb",
    "content": "<h2>Log in</h2>\n\n<%= form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>\n  <div class=\"field\">\n    <p><%= f.label :email %></p>\n    <p><%= f.email_field :email, autofocus: true, autocomplete: \"email\" %></p>\n  </div>\n\n  <div class=\"field\">\n    <p><%= f.label :password %></p>\n    <p><%= f.password_field :password, autocomplete: \"current-password\" %></p>\n  </div>\n\n  <% if devise_mapping.rememberable? %>\n    <div class=\"field\">\n      <p><%= f.check_box :remember_me %></p>\n      <p><%= f.label :remember_me %></p>\n    </div>\n  <% end %>\n\n  <div class=\"actions\">\n    <%= f.submit \"Log in\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "app/views/devise/shared/_error_messages.html.erb",
    "content": "<% if resource.errors.any? %>\n  <div id=\"error_explanation\" data-turbo-temporary>\n    <h2>\n      <%= I18n.t(\"errors.messages.not_saved\",\n                 count: resource.errors.count,\n                 resource: resource.class.model_name.human.downcase)\n       %>\n    </h2>\n    <ul>\n      <% resource.errors.full_messages.each do |message| %>\n        <li><%= message %></li>\n      <% end %>\n    </ul>\n  </div>\n<% end %>\n"
  },
  {
    "path": "app/views/devise/shared/_links.html.erb",
    "content": "<%- if controller_name != 'sessions' %>\n  <p><%= link_to \"Log in\", new_session_path(resource_name) %></p>\n<% end %>\n\n<%- if devise_mapping.registerable? && controller_name != 'registrations' %>\n  <p><%= link_to \"Sign up\", new_registration_path(resource_name) %></p>\n<% end %>\n\n<%- if devise_mapping.recoverable? && controller_name != 'passwords' && controller_name != 'registrations' %>\n  <p><%= link_to \"Forgot your password?\", new_password_path(resource_name) %></p>\n<% end %>\n\n<%- if devise_mapping.confirmable? && controller_name != 'confirmations' %>\n  <p><%= link_to \"Didn't receive confirmation instructions?\", new_confirmation_path(resource_name) %></p>\n<% end %>\n\n<%- if devise_mapping.lockable? && resource_class.unlock_strategy_enabled?(:email) && controller_name != 'unlocks' %>\n  <p><%= link_to \"Didn't receive unlock instructions?\", new_unlock_path(resource_name) %></p>\n<% end %>\n\n<%- if devise_mapping.omniauthable? %>\n  <%- resource_class.omniauth_providers.each do |provider| %>\n    <p><%= button_to \"Sign in with #{OmniAuth::Utils.camelize(provider)}\", omniauth_authorize_path(resource_name, provider), data: { turbo: false } %></p>\n  <% end %>\n<% end %>\n"
  },
  {
    "path": "app/views/devise/unlocks/new.html.erb",
    "content": "<h2>Resend unlock instructions</h2>\n\n<%= form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>\n  <%= render \"devise/shared/error_messages\", resource: resource %>\n\n  <div class=\"field\">\n    <p><%= f.label :email %></p>\n    <p><%= f.email_field :email, autofocus: true, autocomplete: \"email\" %></p>\n  </div>\n\n  <div class=\"actions\">\n    <%= f.submit \"Resend unlock instructions\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "bin/test",
    "content": "#!/usr/bin/env ruby\n$: << File.expand_path(File.expand_path('../../test', __FILE__))\n\nrequire 'bundler/setup'\nrequire 'rails/test_unit/runner'\nrequire 'rails/test_unit/reporter'\nrequire 'rails/test_unit/line_filtering'\n\nRails::TestUnitReporter.executable = 'bin/test'\n\nRails::TestUnit::Runner.parse_options(ARGV)\nRails::TestUnit::Runner.run(ARGV)\n"
  },
  {
    "path": "config/locales/en.yml",
    "content": "# Additional translations at https://github.com/heartcombo/devise/wiki/I18n\n\nen:\n  devise:\n    confirmations:\n      confirmed: \"Your email address has been successfully confirmed.\"\n      send_instructions: \"You will receive an email with instructions for how to confirm your email address in a few minutes.\"\n      send_paranoid_instructions: \"If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes.\"\n    failure:\n      already_authenticated: \"You are already signed in.\"\n      inactive: \"Your account is not activated yet.\"\n      invalid: \"Invalid %{authentication_keys} or password.\"\n      locked: \"Your account is locked.\"\n      last_attempt: \"You have one more attempt before your account is locked.\"\n      not_found_in_database: \"Invalid %{authentication_keys} or password.\"\n      timeout: \"Your session expired. Please sign in again to continue.\"\n      unauthenticated: \"You need to sign in or sign up before continuing.\"\n      unconfirmed: \"You have to confirm your email address before continuing.\"\n    mailer:\n      confirmation_instructions:\n        subject: \"Confirmation instructions\"\n      reset_password_instructions:\n        subject: \"Reset password instructions\"\n      unlock_instructions:\n        subject: \"Unlock instructions\"\n      email_changed:\n        subject: \"Email Changed\"\n      password_change:\n        subject: \"Password Changed\"\n    omniauth_callbacks:\n      failure: \"Could not authenticate you from %{kind} because \\\"%{reason}\\\".\"\n      success: \"Successfully authenticated from %{kind} account.\"\n    passwords:\n      no_token: \"You can't access this page without coming from a password reset email. If you do come from a password reset email, please make sure you used the full URL provided.\"\n      send_instructions: \"You will receive an email with instructions on how to reset your password in a few minutes.\"\n      send_paranoid_instructions: \"If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes.\"\n      updated: \"Your password has been changed successfully. You are now signed in.\"\n      updated_not_active: \"Your password has been changed successfully.\"\n    registrations:\n      destroyed: \"Bye! Your account has been successfully cancelled. We hope to see you again soon.\"\n      signed_up: \"Welcome! You have signed up successfully.\"\n      signed_up_but_inactive: \"You have signed up successfully. However, we could not sign you in because your account is not yet activated.\"\n      signed_up_but_locked: \"You have signed up successfully. However, we could not sign you in because your account is locked.\"\n      signed_up_but_unconfirmed: \"A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.\"\n      update_needs_confirmation: \"You updated your account successfully, but we need to verify your new email address. Please check your email and follow the confirmation link to confirm your new email address.\"\n      updated: \"Your account has been updated successfully.\"\n      updated_but_not_signed_in: \"Your account has been updated successfully, but since your password was changed, you need to sign in again.\"\n    sessions:\n      signed_in: \"Signed in successfully.\"\n      signed_out: \"Signed out successfully.\"\n      already_signed_out: \"Signed out successfully.\"\n    unlocks:\n      send_instructions: \"You will receive an email with instructions for how to unlock your account in a few minutes.\"\n      send_paranoid_instructions: \"If your account exists, you will receive an email with instructions for how to unlock it in a few minutes.\"\n      unlocked: \"Your account has been unlocked successfully. Please sign in to continue.\"\n  errors:\n    messages:\n      already_confirmed: \"was already confirmed, please try signing in\"\n      confirmation_period_expired: \"needs to be confirmed within %{period}, please request a new one\"\n      expired: \"has expired, please request a new one\"\n      not_found: \"not found\"\n      not_locked: \"was not locked\"\n      not_saved:\n        one: \"1 error prohibited this %{resource} from being saved:\"\n        other: \"%{count} errors prohibited this %{resource} from being saved:\"\n"
  },
  {
    "path": "devise.gemspec",
    "content": "# -*- encoding: utf-8 -*-\n# frozen_string_literal: true\n\n$:.push File.expand_path(\"../lib\", __FILE__)\nrequire \"devise/version\"\n\nGem::Specification.new do |s|\n  s.name        = \"devise\"\n  s.version     = Devise::VERSION.dup\n  s.platform    = Gem::Platform::RUBY\n  s.licenses    = [\"MIT\"]\n  s.summary     = \"Flexible authentication solution for Rails with Warden\"\n  s.email       = \"heartcombo.oss@gmail.com\"\n  s.homepage    = \"https://github.com/heartcombo/devise\"\n  s.description = \"Flexible authentication solution for Rails with Warden\"\n  s.authors     = ['José Valim', 'Carlos Antônio']\n  s.metadata    = {\n    \"homepage_uri\"      => \"https://github.com/heartcombo/devise\",\n    \"documentation_uri\" => \"https://rubydoc.info/github/heartcombo/devise\",\n    \"changelog_uri\"     => \"https://github.com/heartcombo/devise/blob/main/CHANGELOG.md\",\n    \"source_code_uri\"   => \"https://github.com/heartcombo/devise\",\n    \"bug_tracker_uri\"   => \"https://github.com/heartcombo/devise/issues\",\n    \"wiki_uri\"          => \"https://github.com/heartcombo/devise/wiki\"\n  }\n\n  s.files         = Dir[\"{app,config,lib}/**/*\", \"CHANGELOG.md\", \"MIT-LICENSE\", \"README.md\"]\n  s.require_paths = [\"lib\"]\n  s.required_ruby_version = '>= 2.7.0'\n\n  s.add_dependency(\"warden\", \"~> 1.2.3\")\n  s.add_dependency(\"orm_adapter\", \"~> 0.1\")\n  s.add_dependency(\"bcrypt\", \"~> 3.0\")\n  s.add_dependency(\"railties\", \">= 7.0\")\n  s.add_dependency(\"responders\")\nend\n"
  },
  {
    "path": "gemfiles/Gemfile-rails-7-0",
    "content": "source \"https://rubygems.org\"\n\ngemspec path: \"..\"\n\ngem \"rails\", \"~> 7.0.0\"\ngem \"omniauth\"\ngem \"omniauth-oauth2\"\ngem \"rdoc\"\n\ngem \"rails-controller-testing\"\n\ngem \"responders\", \"~> 3.1\"\n\ngroup :test do\n  gem \"omniauth-facebook\"\n  gem \"omniauth-openid\"\n  gem \"rexml\"\n  gem \"timecop\"\n  gem \"webrat\", \"0.7.3\", require: false\n  gem \"mocha\", \"~> 2.1\", require: false\n  gem \"minitest\", \"< 6\"\n  gem \"ostruct\"\nend\n\nplatforms :ruby do\n  gem \"sqlite3\", \"~> 1.4\"\nend\n\ngroup :mongoid do\n  gem \"mongoid\", \"~> 7.5\"\nend\n"
  },
  {
    "path": "gemfiles/Gemfile-rails-7-1",
    "content": "source \"https://rubygems.org\"\n\ngemspec path: \"..\"\n\ngem \"rails\", \"~> 7.1.0\"\ngem \"omniauth\"\ngem \"omniauth-oauth2\"\ngem \"rdoc\"\n\ngem \"rails-controller-testing\"\n\ngem \"responders\", \"~> 3.1\"\n\ngroup :test do\n  gem \"omniauth-facebook\"\n  gem \"omniauth-openid\"\n  gem \"rexml\"\n  gem \"timecop\"\n  gem \"webrat\"\n  gem \"mocha\", \"~> 2.1\", require: false\n  gem \"minitest\", \"< 6\"\n  gem \"ostruct\"\nend\n\nplatforms :ruby do\n  gem \"sqlite3\", \"~> 1.4\"\nend\n\ngroup :mongoid do\n  gem \"mongoid\", \"~> 8.1\"\nend\n"
  },
  {
    "path": "gemfiles/Gemfile-rails-7-2",
    "content": "source \"https://rubygems.org\"\n\ngemspec path: \"..\"\n\ngem \"rails\", \"~> 7.2.0\"\ngem \"omniauth\"\ngem \"omniauth-oauth2\"\ngem \"rdoc\"\n\ngem \"rails-controller-testing\"\n\ngem \"responders\", \"~> 3.1\"\n\ngroup :test do\n  gem \"omniauth-facebook\"\n  gem \"omniauth-openid\"\n  gem \"rexml\"\n  gem \"timecop\"\n  gem \"webrat\", require: false\n  gem \"mocha\", \"~> 2.1\", require: false\n  gem \"minitest\", \"< 6\"\n  gem \"ostruct\"\nend\n\nplatforms :ruby do\n  gem \"sqlite3\"\nend\n\ngroup :mongoid do\n  gem \"mongoid\", \"~> 8.1\"\nend\n"
  },
  {
    "path": "gemfiles/Gemfile-rails-8-0",
    "content": "source \"https://rubygems.org\"\n\ngemspec path: \"..\"\n\ngem \"rails\", \"~> 8.0.0\"\ngem \"omniauth\"\ngem \"omniauth-oauth2\"\ngem \"rdoc\"\n\ngem \"rails-controller-testing\"\n\ngem \"responders\", \"~> 3.1\"\n\ngroup :test do\n  gem \"omniauth-facebook\"\n  gem \"omniauth-openid\"\n  gem \"rexml\"\n  gem \"timecop\"\n  gem 'webrat'\n  gem \"mocha\", \"~> 2.1\", require: false\n  gem \"minitest\", \"< 6\"\n  gem \"ostruct\"\nend\n\nplatforms :ruby do\n  gem \"sqlite3\"\nend\n\ngroup :mongoid do\n  gem \"mongoid\", \"~> 8.1\"\nend\n"
  },
  {
    "path": "gemfiles/Gemfile-rails-main",
    "content": "source \"https://rubygems.org\"\n\ngemspec path: \"..\"\n\ngem \"rails\", github: \"rails/rails\", branch: \"main\"\ngem \"omniauth\"\ngem \"omniauth-oauth2\"\ngem \"rdoc\"\n\ngem \"rails-controller-testing\"\n\ngem \"responders\", \"~> 3.1\"\n\ngroup :test do\n  gem \"omniauth-facebook\"\n  gem \"omniauth-openid\"\n  gem \"rexml\"\n  gem \"timecop\"\n  gem \"webrat\", \"0.7.3\", require: false\n  gem \"mocha\", \"~> 2.1\", require: false\n  gem \"minitest\", \"< 6\"\n  gem \"ostruct\"\nend\n\nplatforms :ruby do\n  gem \"sqlite3\"\nend\n\ngroup :mongoid do\n  gem \"mongoid\", github: \"mongodb/mongoid\", branch: \"master\"\nend\n"
  },
  {
    "path": "guides/bug_report_templates/integration_test.rb",
    "content": "# frozen_string_literal: true\n\nbegin\n  require 'bundler/inline'\nrescue LoadError => e\n  $stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'\n  raise e\nend\n\ngemfile(true) do\n  source 'https://rubygems.org'\n  # Activate the gem you are reporting the issue against.\n  gem 'rails', '~> 4.2.0'\n  gem 'devise', '~> 4.0'\n  gem 'sqlite3'\n  gem 'byebug'\nend\n\nrequire 'rack/test'\nrequire 'action_controller/railtie'\nrequire 'active_record'\nrequire 'devise/rails/routes'\nrequire 'devise/rails/warden_compat'\n\nActiveRecord::Base.establish_connection( adapter: :sqlite3, database:  ':memory:')\n\nclass DeviseCreateUsers < ActiveRecord::Migration\n  def change\n    create_table(:users) do |t|\n      t.string :email,              null: false\n      t.string :encrypted_password, null: true\n      t.timestamps null: false\n    end\n\n  end\nend\n\nDevise.setup do |config|\n  require 'devise/orm/active_record'\n  config.secret_key = 'secret_key_base'\nend\n\nclass TestApp < Rails::Application\n  config.root = File.dirname(__FILE__)\n  config.session_store :cookie_store, key: 'cookie_store_key'\n  secrets.secret_token    = 'secret_token'\n  secrets.secret_key_base = 'secret_key_base'\n  config.eager_load = false\n\n  config.middleware.use Warden::Manager do |config|\n    Devise.warden_config = config\n  end\n\n  config.logger = Logger.new($stdout)\n  Rails.logger  = config.logger\n\nend\n\nRails.application.initialize!\n\nDeviseCreateUsers.migrate(:up)\n\nclass User < ActiveRecord::Base\n  devise :database_authenticatable\nend\n\nRails.application.routes.draw do\n  devise_for :users\n\n  get '/' => 'test#index'\nend\n\nclass ApplicationController < ActionController::Base\nend\n\nclass TestController < ApplicationController\n  include Rails.application.routes.url_helpers\n\n  before_action :authenticate_user!\n\n  def index\n    render plain: 'Home'\n  end\nend\n\nrequire 'minitest/autorun'\n\nclass BugTest < ActionDispatch::IntegrationTest\n  include Rack::Test::Methods\n  include Warden::Test::Helpers\n\n  def test_returns_success\n    Warden.test_mode!\n\n    login_as User.create!(email: 'test@test.com', password: 'test123456', password_confirmation: 'test123456')\n\n    get '/'\n    assert last_response.ok?\n  end\n\n  private\n\n  def app\n    Rails.application\n  end\nend\n"
  },
  {
    "path": "lib/devise/controllers/helpers.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Controllers\n    # Those helpers are convenience methods added to ApplicationController.\n    module Helpers\n      extend ActiveSupport::Concern\n      include Devise::Controllers::SignInOut\n      include Devise::Controllers::StoreLocation\n\n      included do\n        if respond_to?(:helper_method)\n          helper_method :warden, :signed_in?, :devise_controller?\n        end\n      end\n\n      module ClassMethods\n        # Define authentication filters and accessor helpers for a group of mappings.\n        # These methods are useful when you are working with multiple mappings that\n        # share some functionality. They are pretty much the same as the ones\n        # defined for normal mappings.\n        #\n        # Example:\n        #\n        #   inside BlogsController (or any other controller, it doesn't matter which):\n        #     devise_group :blogger, contains: [:user, :admin]\n        #\n        #   Generated methods:\n        #     authenticate_blogger!  # Redirects unless user or admin are signed in\n        #     blogger_signed_in?     # Checks whether there is either a user or an admin signed in\n        #     current_blogger        # Currently signed in user or admin\n        #     current_bloggers       # Currently signed in user and admin\n        #\n        #   Use:\n        #     before_action :authenticate_blogger!              # Redirects unless either a user or an admin are authenticated\n        #     before_action ->{ authenticate_blogger! :admin }  # Redirects to the admin login page\n        #     current_blogger :user                             # Preferably returns a User if one is signed in\n        #\n        def devise_group(group_name, opts = {})\n          mappings = \"[#{ opts[:contains].map { |m| \":#{m}\" }.join(',') }]\"\n\n          class_eval <<-METHODS, __FILE__, __LINE__ + 1\n            def authenticate_#{group_name}!(favorite = nil, opts = {})\n              unless #{group_name}_signed_in?\n                mappings = #{mappings}\n                mappings.unshift mappings.delete(favorite.to_sym) if favorite\n                mappings.each do |mapping|\n                  opts[:scope] = mapping\n                  opts[:locale] = I18n.locale\n                  warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)\n                end\n              end\n            end\n\n            def #{group_name}_signed_in?\n              #{mappings}.any? do |mapping|\n                warden.authenticate?(scope: mapping)\n              end\n            end\n\n            def current_#{group_name}(favorite = nil)\n              mappings = #{mappings}\n              mappings.unshift mappings.delete(favorite.to_sym) if favorite\n              mappings.each do |mapping|\n                current = warden.authenticate(scope: mapping)\n                return current if current\n              end\n              nil\n            end\n\n            def current_#{group_name.to_s.pluralize}\n              #{mappings}.map do |mapping|\n                warden.authenticate(scope: mapping)\n              end.compact\n            end\n\n            if respond_to?(:helper_method)\n              helper_method \"current_#{group_name}\", \"current_#{group_name.to_s.pluralize}\", \"#{group_name}_signed_in?\"\n            end\n          METHODS\n        end\n\n        def log_process_action(payload)\n          payload[:status] ||= 401 unless payload[:exception]\n          super\n        end\n      end\n\n      # Define authentication filters and accessor helpers based on mappings.\n      # These filters should be used inside the controllers as before_actions,\n      # so you can control the scope of the user who should be signed in to\n      # access that specific controller/action.\n      # Example:\n      #\n      #   Roles:\n      #     User\n      #     Admin\n      #\n      #   Generated methods:\n      #     authenticate_user!  # Signs user in or redirect\n      #     authenticate_admin! # Signs admin in or redirect\n      #     user_signed_in?     # Checks whether there is a user signed in or not\n      #     admin_signed_in?    # Checks whether there is an admin signed in or not\n      #     current_user        # Current signed in user\n      #     current_admin       # Current signed in admin\n      #     user_session        # Session data available only to the user scope\n      #     admin_session       # Session data available only to the admin scope\n      #\n      #   Use:\n      #     before_action :authenticate_user!  # Tell devise to use :user map\n      #     before_action :authenticate_admin! # Tell devise to use :admin map\n      #\n      def self.define_helpers(mapping) #:nodoc:\n        mapping = mapping.name\n\n        class_eval <<-METHODS, __FILE__, __LINE__ + 1\n          def authenticate_#{mapping}!(opts = {})\n            opts[:scope] = :#{mapping}\n            opts[:locale] = I18n.locale\n            warden.authenticate!(opts) if !devise_controller? || opts.delete(:force)\n          end\n\n          def #{mapping}_signed_in?\n            !!current_#{mapping}\n          end\n\n          def current_#{mapping}\n            @current_#{mapping} ||= warden.authenticate(scope: :#{mapping})\n          end\n\n          def #{mapping}_session\n            current_#{mapping} && warden.session(:#{mapping})\n          end\n        METHODS\n\n        ActiveSupport.on_load(:action_controller) do\n          if respond_to?(:helper_method)\n            helper_method \"current_#{mapping}\", \"#{mapping}_signed_in?\", \"#{mapping}_session\"\n          end\n        end\n      end\n\n      # The main accessor for the warden proxy instance\n      def warden\n        request.env['warden'] or raise MissingWarden\n      end\n\n      # Return true if it's a devise_controller. false to all controllers unless\n      # the controllers defined inside devise. Useful if you want to apply a before\n      # filter to all controllers, except the ones in devise:\n      #\n      #   before_action :my_filter, unless: :devise_controller?\n      def devise_controller?\n        is_a?(::DeviseController)\n      end\n\n      # Set up a param sanitizer to filter parameters using strong_parameters. See\n      # lib/devise/parameter_sanitizer.rb for more info. Override this\n      # method in your application controller to use your own parameter sanitizer.\n      def devise_parameter_sanitizer\n        @devise_parameter_sanitizer ||= Devise::ParameterSanitizer.new(resource_class, resource_name, params)\n      end\n\n      # Tell warden that params authentication is allowed for that specific page.\n      def allow_params_authentication!\n        request.env[\"devise.allow_params_authentication\"] = true\n      end\n\n      # The scope root url to be used when they're signed in. By default, it first\n      # tries to find a resource_root_path, otherwise it uses the root_path.\n      def signed_in_root_path(resource_or_scope)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        router_name = Devise.mappings[scope].router_name\n\n        home_path = \"#{scope}_root_path\"\n\n        context = router_name ? send(router_name) : self\n\n        if context.respond_to?(home_path, true)\n          context.send(home_path)\n        elsif context.respond_to?(:root_path)\n          context.root_path\n        elsif respond_to?(:root_path)\n          root_path\n        else\n          \"/\"\n        end\n      end\n\n      # The default url to be used after signing in. This is used by all Devise\n      # controllers and you can overwrite it in your ApplicationController to\n      # provide a custom hook for a custom resource.\n      #\n      # By default, it first tries to find a valid resource_return_to key in the\n      # session, then it fallbacks to resource_root_path, otherwise it uses the\n      # root path. For a user scope, you can define the default url in\n      # the following way:\n      #\n      #   get '/users' => 'users#index', as: :user_root # creates user_root_path\n      #\n      #   namespace :user do\n      #     root 'users#index' # creates user_root_path\n      #   end\n      #\n      # If the resource root path is not defined, root_path is used. However,\n      # if this default is not enough, you can customize it, for example:\n      #\n      #   def after_sign_in_path_for(resource)\n      #     stored_location_for(resource) ||\n      #       if resource.is_a?(User) && resource.can_publish?\n      #         publisher_url\n      #       else\n      #         super\n      #       end\n      #   end\n      #\n      def after_sign_in_path_for(resource_or_scope)\n        stored_location_for(resource_or_scope) || signed_in_root_path(resource_or_scope)\n      end\n\n      # Method used by sessions controller to sign out a user. You can overwrite\n      # it in your ApplicationController to provide a custom hook for a custom\n      # scope. Notice that differently from +after_sign_in_path_for+ this method\n      # receives a symbol with the scope, and not the resource.\n      #\n      # By default it is the root_path.\n      def after_sign_out_path_for(resource_or_scope)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        router_name = Devise.mappings[scope].router_name\n        context = router_name ? send(router_name) : self\n        context.respond_to?(:root_path) ? context.root_path : \"/\"\n      end\n\n      # Sign in a user and tries to redirect first to the stored location and\n      # then to the url specified by after_sign_in_path_for. It accepts the same\n      # parameters as the sign_in method.\n      def sign_in_and_redirect(resource_or_scope, *args)\n        options  = args.extract_options!\n        scope    = Devise::Mapping.find_scope!(resource_or_scope)\n        resource = args.last || resource_or_scope\n        sign_in(scope, resource, options)\n        redirect_to after_sign_in_path_for(resource)\n      end\n\n      # Sign out a user and tries to redirect to the url specified by\n      # after_sign_out_path_for.\n      def sign_out_and_redirect(resource_or_scope)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        redirect_path = after_sign_out_path_for(scope)\n        Devise.sign_out_all_scopes ? sign_out : sign_out(scope)\n        redirect_to redirect_path\n      end\n\n      # Overwrite Rails' handle unverified request to sign out all scopes,\n      # clear run strategies and remove cached variables.\n      def handle_unverified_request\n        super # call the default behavior which resets/nullifies/raises\n        request.env[\"devise.skip_storage\"] = true\n        sign_out_all_scopes(false)\n      end\n\n      def request_format\n        @request_format ||= request.format.try(:ref)\n      end\n\n      def is_navigational_format?\n        Devise.navigational_formats.include?(request_format)\n      end\n\n      # Check if flash messages should be emitted. Default is to do it on\n      # navigational formats\n      def is_flashing_format?\n        request.respond_to?(:flash) && is_navigational_format?\n      end\n\n      private\n\n      def expire_data_after_sign_out!\n        Devise.mappings.each { |_,m| instance_variable_set(\"@current_#{m.name}\", nil) }\n        super\n      end\n    end\n  end\n\n  class MissingWarden < StandardError\n    def initialize\n      super \"Devise could not find the `Warden::Proxy` instance on your request environment.\\n\" + \\\n        \"Make sure that your application is loading Devise and Warden as expected and that \" + \\\n        \"the `Warden::Manager` middleware is present in your middleware stack.\\n\" + \\\n        \"If you are seeing this on one of your tests, ensure that your tests are either \" + \\\n        \"executing the Rails middleware stack or that your tests are using the `Devise::Test::ControllerHelpers` \" + \\\n        \"module to inject the `request.env['warden']` object for you.\"\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/controllers/rememberable.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Controllers\n    # A module that may be optionally included in a controller in order\n    # to provide remember me behavior. Useful when signing in is done\n    # through a callback, like in OmniAuth.\n    module Rememberable\n      # Return default cookie values retrieved from session options.\n      def self.cookie_values\n        Rails.configuration.session_options.slice(:path, :domain, :secure)\n      end\n\n      def remember_me_is_active?(resource)\n        return false unless resource.respond_to?(:remember_me)\n        scope = Devise::Mapping.find_scope!(resource)\n        _, token, generated_at = cookies.signed[remember_key(resource, scope)]\n        resource.remember_me?(token, generated_at)\n      end\n\n      # Remembers the given resource by setting up a cookie\n      def remember_me(resource)\n        return if request.env[\"devise.skip_storage\"]\n        scope = Devise::Mapping.find_scope!(resource)\n        resource.remember_me!\n        cookies.signed[remember_key(resource, scope)] = remember_cookie_values(resource)\n      end\n\n      # Forgets the given resource by deleting a cookie\n      def forget_me(resource)\n        scope = Devise::Mapping.find_scope!(resource)\n        resource.forget_me!\n        cookies.delete(remember_key(resource, scope), forget_cookie_values(resource))\n      end\n\n      protected\n\n      def forget_cookie_values(resource)\n        Devise::Controllers::Rememberable.cookie_values.merge!(resource.rememberable_options)\n      end\n\n      def remember_cookie_values(resource)\n        options = { httponly: true }\n        options.merge!(forget_cookie_values(resource))\n        options.merge!(\n          value: resource.class.serialize_into_cookie(resource),\n          expires: resource.remember_expires_at\n        )\n      end\n\n      def remember_key(resource, scope)\n        resource.rememberable_options.fetch(:key, \"remember_#{scope}_token\")\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/controllers/responder.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Controllers\n    # Custom Responder to configure default statuses that only apply to Devise,\n    # and allow to integrate more easily with Hotwire/Turbo.\n    class Responder < ActionController::Responder\n      if respond_to?(:error_status=) && respond_to?(:redirect_status=)\n        self.error_status = :ok\n        self.redirect_status = :found\n      else\n        # TODO: remove this support for older Rails versions, which aren't supported by Turbo\n        # and/or responders. It won't allow configuring a custom response, but it allows Devise\n        # to use these methods and defaults across the implementation more easily.\n        def self.error_status\n          :ok\n        end\n\n        def self.redirect_status\n          :found\n        end\n\n        def self.error_status=(*)\n          warn \"[DEVISE] Setting the error status on the Devise responder has no effect with this \" \\\n            \"version of `responders`, please make sure you're using a newer version. Check the changelog for more info.\"\n        end\n\n        def self.redirect_status=(*)\n          warn \"[DEVISE] Setting the redirect status on the Devise responder has no effect with this \" \\\n            \"version of `responders`, please make sure you're using a newer version. Check the changelog for more info.\"\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/controllers/scoped_views.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Controllers\n    module ScopedViews\n      extend ActiveSupport::Concern\n\n      module ClassMethods\n        def scoped_views?\n          defined?(@scoped_views) ? @scoped_views : Devise.scoped_views\n        end\n\n        def scoped_views=(value)\n          @scoped_views = value\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/controllers/sign_in_out.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Controllers\n    # Provide sign in and sign out functionality.\n    # Included by default in all controllers.\n    module SignInOut\n      # Return true if the given scope is signed in session. If no scope given, return\n      # true if any scope is signed in. This will run authentication hooks, which may\n      # cause exceptions to be thrown from this method; if you simply want to check\n      # if a scope has already previously been authenticated without running\n      # authentication hooks, you can directly call `warden.authenticated?(scope: scope)`\n      def signed_in?(scope = nil)\n        [scope || Devise.mappings.keys].flatten.any? do |_scope|\n          warden.authenticate?(scope: _scope)\n        end\n      end\n\n      # Sign in a user that already was authenticated. This helper is useful for logging\n      # users in after sign up. All options given to sign_in is passed forward\n      # to the set_user method in warden.\n      # If you are using a custom warden strategy and the timeoutable module, you have to\n      # set `env[\"devise.skip_timeout\"] = true` in the request to use this method, like we do\n      # in the sessions controller: https://github.com/heartcombo/devise/blob/main/app/controllers/devise/sessions_controller.rb#L7\n      #\n      # Examples:\n      #\n      #   sign_in :user, @user                      # sign_in(scope, resource)\n      #   sign_in @user                             # sign_in(resource)\n      #   sign_in @user, event: :authentication     # sign_in(resource, options)\n      #   sign_in @user, store: false               # sign_in(resource, options)\n      #\n      def sign_in(resource_or_scope, *args)\n        options  = args.extract_options!\n        scope    = Devise::Mapping.find_scope!(resource_or_scope)\n        resource = args.last || resource_or_scope\n\n        expire_data_after_sign_in!\n\n        if warden.user(scope) == resource && !options.delete(:force)\n          # Do nothing. User already signed in and we are not forcing it.\n          true\n        else\n          warden.set_user(resource, options.merge!(scope: scope))\n        end\n      end\n\n      # Sign in a user bypassing the warden callbacks and stores the user\n      # straight in session. This option is useful in cases the user is already\n      # signed in, but we want to refresh the credentials in session.\n      #\n      # Examples:\n      #\n      #   bypass_sign_in @user, scope: :user\n      #   bypass_sign_in @user\n      def bypass_sign_in(resource, scope: nil)\n        scope ||= Devise::Mapping.find_scope!(resource)\n        expire_data_after_sign_in!\n        warden.session_serializer.store(resource, scope)\n      end\n\n      # Sign out a given user or scope. This helper is useful for signing out a user\n      # after deleting accounts. Returns true if there was a logout and false if there\n      # is no user logged in on the referred scope\n      #\n      # Examples:\n      #\n      #   sign_out :user     # sign_out(scope)\n      #   sign_out @user     # sign_out(resource)\n      #\n      def sign_out(resource_or_scope = nil)\n        return sign_out_all_scopes unless resource_or_scope\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        user = warden.user(scope: scope, run_callbacks: false) # If there is no user\n\n        warden.logout(scope)\n        warden.clear_strategies_cache!(scope: scope)\n        instance_variable_set(:\"@current_#{scope}\", nil)\n\n        !!user\n      end\n\n      # Sign out all active users or scopes. This helper is useful for signing out all roles\n      # in one click. This signs out ALL scopes in warden. Returns true if there was at least one logout\n      # and false if there was no user logged in on all scopes.\n      def sign_out_all_scopes(lock = true)\n        users = Devise.mappings.keys.map { |s| warden.user(scope: s, run_callbacks: false) }\n\n        warden.logout\n        expire_data_after_sign_out!\n        warden.clear_strategies_cache!\n        warden.lock! if lock\n\n        users.any?\n      end\n\n      private\n\n      def expire_data_after_sign_in!\n        session.keys.grep(/^devise\\./).each { |k| session.delete(k) }\n      end\n\n      alias :expire_data_after_sign_out! :expire_data_after_sign_in!\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/controllers/store_location.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"uri\"\n\nmodule Devise\n  module Controllers\n    # Provide the ability to store a location.\n    # Used to redirect back to a desired path after sign in.\n    # Included by default in all controllers.\n    module StoreLocation\n      # Returns and delete (if it's navigational format) the url stored in the session for\n      # the given scope. Useful for giving redirect backs after sign up:\n      #\n      # Example:\n      #\n      #   redirect_to stored_location_for(:user) || root_path\n      #\n      def stored_location_for(resource_or_scope)\n        session_key = stored_location_key_for(resource_or_scope)\n\n        if is_navigational_format?\n          session.delete(session_key)\n        else\n          session[session_key]\n        end\n      end\n\n      # Stores the provided location to redirect the user after signing in.\n      # Useful in combination with the `stored_location_for` helper.\n      #\n      # Example:\n      #\n      #   store_location_for(:user, dashboard_path)\n      #   redirect_to user_facebook_omniauth_authorize_path\n      #\n      def store_location_for(resource_or_scope, location)\n        session_key = stored_location_key_for(resource_or_scope)\n        \n        path = extract_path_from_location(location)\n        session[session_key] = path if path\n      end\n\n      private\n\n      def parse_uri(location)\n        location && URI.parse(location)\n      rescue URI::InvalidURIError\n        nil\n      end\n\n      def stored_location_key_for(resource_or_scope)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        \"#{scope}_return_to\"\n      end\n\n      def extract_path_from_location(location)\n        uri = parse_uri(location)\n\n        if uri \n          path = remove_domain_from_uri(uri)\n          path = add_fragment_back_to_path(uri, path)\n\n          path\n        end\n      end\n\n      def remove_domain_from_uri(uri)\n        [uri.path.sub(/\\A\\/+/, '/'), uri.query].compact.join('?')\n      end\n\n      def add_fragment_back_to_path(uri, path)\n        [path, uri.fragment].compact.join('#')\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/controllers/url_helpers.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Controllers\n    # Create url helpers to be used with resource/scope configuration. Acts as\n    # proxies to the generated routes created by devise.\n    # Resource param can be a string or symbol, a class, or an instance object.\n    # Example using a :user resource:\n    #\n    #   new_session_path(:user)      => new_user_session_path\n    #   session_path(:user)          => user_session_path\n    #   destroy_session_path(:user)  => destroy_user_session_path\n    #\n    #   new_password_path(:user)     => new_user_password_path\n    #   password_path(:user)         => user_password_path\n    #   edit_password_path(:user)    => edit_user_password_path\n    #\n    #   new_confirmation_path(:user) => new_user_confirmation_path\n    #   confirmation_path(:user)     => user_confirmation_path\n    #\n    # Those helpers are included by default to ActionController::Base.\n    #\n    # In case you want to add such helpers to another class, you can do\n    # that as long as this new class includes both url_helpers and\n    # mounted_helpers. Example:\n    #\n    #     include Rails.application.routes.url_helpers\n    #     include Rails.application.routes.mounted_helpers\n    #\n    module UrlHelpers\n      def self.remove_helpers!\n        self.instance_methods.map(&:to_s).grep(/_(url|path)$/).each do |method|\n          remove_method method\n        end\n      end\n\n      def self.generate_helpers!(routes = nil)\n        routes ||= begin\n          mappings = Devise.mappings.values.map(&:used_helpers).flatten.uniq\n          Devise::URL_HELPERS.slice(*mappings)\n        end\n\n        routes.each do |module_name, actions|\n          [:path, :url].each do |path_or_url|\n            actions.each do |action|\n              action = action ? \"#{action}_\" : \"\"\n              method = :\"#{action}#{module_name}_#{path_or_url}\"\n\n              define_method method do |resource_or_scope, *args|\n                scope = Devise::Mapping.find_scope!(resource_or_scope)\n                router_name = Devise.mappings[scope].router_name\n                context = router_name ? send(router_name) : _devise_route_context\n                context.send(\"#{action}#{scope}_#{module_name}_#{path_or_url}\", *args)\n              end\n            end\n          end\n        end\n      end\n\n      generate_helpers!(Devise::URL_HELPERS)\n\n      private\n\n      def _devise_route_context\n        @_devise_route_context ||= send(Devise.available_router_name)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/delegator.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  # Checks the scope in the given environment and returns the associated failure app.\n  class Delegator\n    def call(env)\n      failure_app(env).call(env)\n    end\n\n    def failure_app(env)\n      app = env[\"warden.options\"] &&\n        (scope = env[\"warden.options\"][:scope]) &&\n        Devise.mappings[scope.to_sym].failure_app\n\n      app || Devise::FailureApp\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/encryptor.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'bcrypt'\n\nmodule Devise\n  module Encryptor\n    def self.digest(klass, password)\n      if klass.pepper.present?\n        password = \"#{password}#{klass.pepper}\"\n      end\n      ::BCrypt::Password.create(password, cost: klass.stretches).to_s\n    end\n\n    def self.compare(klass, hashed_password, password)\n      return false if hashed_password.blank?\n      bcrypt   = ::BCrypt::Password.new(hashed_password)\n      if klass.pepper.present?\n        password = \"#{password}#{klass.pepper}\"\n      end\n      password = ::BCrypt::Engine.hash_secret(password, bcrypt.salt)\n      Devise.secure_compare(password, hashed_password)\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/failure_app.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"action_controller/metal\"\n\nmodule Devise\n  # Failure application that will be called every time :warden is thrown from\n  # any strategy or hook. It is responsible for redirecting the user to the sign\n  # in page based on current scope and mapping. If no scope is given, it\n  # redirects to the default_url.\n  class FailureApp < ActionController::Metal\n    include ActionController::UrlFor\n    include ActionController::Redirecting\n\n    include Rails.application.routes.url_helpers\n    include Rails.application.routes.mounted_helpers\n\n    include Devise::Controllers::StoreLocation\n\n    delegate :flash, to: :request\n\n    include AbstractController::Callbacks\n    around_action do |failure_app, action|\n      I18n.with_locale(failure_app.i18n_locale, &action)\n    end\n\n    def self.call(env)\n      @respond ||= action(:respond)\n      @respond.call(env)\n    end\n\n    # Try retrieving the URL options from the parent controller (usually\n    # ApplicationController). Instance methods are not supported at the moment,\n    # so only the class-level attribute is used.\n    def self.default_url_options(*args)\n      if defined?(Devise.parent_controller.constantize)\n        Devise.parent_controller.constantize.try(:default_url_options) || {}\n      else\n        {}\n      end\n    end\n\n    def respond\n      if http_auth?\n        http_auth\n      elsif warden_options[:recall]\n        recall\n      else\n        redirect\n      end\n    end\n\n    def http_auth\n      self.status = 401\n      self.headers[\"WWW-Authenticate\"] = %(Basic realm=#{Devise.http_authentication_realm.inspect}) if http_auth_header?\n      self.content_type = request.format.to_s\n      self.response_body = http_auth_body\n    end\n\n    def recall\n      header_info = if relative_url_root?\n        base_path = Pathname.new(relative_url_root)\n        full_path = Pathname.new(attempted_path)\n\n        { \"SCRIPT_NAME\" => relative_url_root,\n          \"PATH_INFO\" => '/' + full_path.relative_path_from(base_path).to_s }\n      else\n        { \"PATH_INFO\" => attempted_path }\n      end\n\n      header_info.each do | var, value|\n        if request.respond_to?(:set_header)\n          request.set_header(var, value)\n        else\n          request.env[var]  = value\n        end\n      end\n\n      flash.now[:alert] = i18n_message(:invalid) if is_flashing_format?\n      self.response = recall_app(warden_options[:recall]).call(request.env).tap { |response|\n        status = response[0].in?(300..399) ? Devise.responder.redirect_status : Devise.responder.error_status\n        # Avoid warnings translating status to code using Rails if available (e.g. `unprocessable_entity` => `unprocessable_content`)\n        response[0] = ActionDispatch::Response.try(:rack_status_code, status) || Rack::Utils.status_code(status)\n      }\n    end\n\n    def redirect\n      store_location!\n      if is_flashing_format?\n        if flash[:timedout] && flash[:alert]\n          flash.keep(:timedout)\n          flash.keep(:alert)\n        else\n          flash[:alert] = i18n_message\n        end\n      end\n      redirect_to redirect_url\n    end\n\n  protected\n\n    def i18n_options(options)\n      options\n    end\n\n    def i18n_message(default = nil)\n      message = warden_message || default || :unauthenticated\n\n      if message.is_a?(Symbol)\n        options = {}\n        options[:resource_name] = scope\n        options[:scope] = \"devise.failure\"\n        options[:default] = [message]\n        auth_keys = scope_class.authentication_keys\n        human_keys = (auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys).map { |key|\n          # TODO: Remove the fallback and just use `downcase_first` once we drop support for Rails 7.0.\n          human_key = scope_class.human_attribute_name(key)\n          human_key.respond_to?(:downcase_first) ? human_key.downcase_first : human_key[0].downcase + human_key[1..]\n        }\n        options[:authentication_keys] = human_keys.join(I18n.t(:\"support.array.words_connector\"))\n        options = i18n_options(options)\n\n        I18n.t(:\"#{scope}.#{message}\", **options).then { |msg|\n          # Ensure that auth keys at the start of the translated string are properly cased.\n          msg.start_with?(human_keys.first) ? msg.upcase_first : msg\n        }\n      else\n        message.to_s\n      end\n    end\n\n    def i18n_locale\n      warden_options[:locale]\n    end\n\n    def redirect_url\n      if warden_message == :timeout\n        flash[:timedout] = true if is_flashing_format?\n\n        path = if request.get?\n          attempted_path\n        else\n          request.referrer\n        end\n\n        path || scope_url\n      else\n        scope_url\n      end\n    end\n\n    def route(scope)\n      :\"new_#{scope}_session_url\"\n    end\n\n    def scope_url\n      opts  = {}\n\n      # Initialize script_name with nil to prevent infinite loops in\n      # authenticated mounted engines\n      opts[:script_name] = nil\n\n      route = route(scope)\n\n      opts[:format] = request_format unless skip_format?\n\n      router_name = Devise.mappings[scope].router_name || Devise.available_router_name\n      context = send(router_name)\n\n      if relative_url_root?\n        opts[:script_name] = relative_url_root\n      end\n\n      if context.respond_to?(route)\n        context.send(route, opts)\n      elsif respond_to?(:root_url)\n        root_url(opts)\n      else\n        \"/\"\n      end\n    end\n\n    def skip_format?\n      %w(html */* turbo_stream).include? request_format.to_s\n    end\n\n    # Choose whether we should respond in an HTTP authentication fashion,\n    # including 401 and optional headers.\n    #\n    # This method allows the user to explicitly disable HTTP authentication\n    # on AJAX requests in case they want to redirect on failures instead of\n    # handling the errors on their own. This is useful in case your AJAX API\n    # is the same as your public API and uses a format like JSON (so you\n    # cannot mark JSON as a navigational format).\n    def http_auth?\n      if request.xhr?\n        Devise.http_authenticatable_on_xhr\n      else\n        !(request_format && is_navigational_format?)\n      end\n    end\n\n    # It doesn't make sense to send authenticate headers in AJAX requests\n    # or if the user disabled them.\n    def http_auth_header?\n      scope_class.http_authenticatable && !request.xhr?\n    end\n\n    def http_auth_body\n      return i18n_message unless request_format\n      method = \"to_#{request_format}\"\n      if method == \"to_xml\"\n        { error: i18n_message }.to_xml(root: \"errors\")\n      elsif {}.respond_to?(method)\n        { error: i18n_message }.send(method)\n      else\n        i18n_message\n      end\n    end\n\n    def recall_app(app)\n      controller, action = app.split(\"#\")\n      controller_name  = ActiveSupport::Inflector.camelize(controller)\n      controller_klass = ActiveSupport::Inflector.constantize(\"#{controller_name}Controller\")\n      controller_klass.action(action)\n    end\n\n    def warden\n      request.respond_to?(:get_header) ? request.get_header(\"warden\") : request.env[\"warden\"]\n    end\n\n    def warden_options\n      request.respond_to?(:get_header) ? request.get_header(\"warden.options\") : request.env[\"warden.options\"]\n    end\n\n    def warden_message\n      @message ||= warden.message || warden_options[:message]\n    end\n\n    def scope\n      @scope ||= warden_options[:scope] || Devise.default_scope\n    end\n\n    def scope_class\n      @scope_class ||= Devise.mappings[scope].to\n    end\n\n    def attempted_path\n      warden_options[:attempted_path]\n    end\n\n    # Stores requested URI to redirect the user after signing in. We can't use\n    # the scoped session provided by warden here, since the user is not\n    # authenticated yet, but we still need to store the URI based on scope, so\n    # different scopes would never use the same URI to redirect.\n    def store_location!\n      store_location_for(scope, attempted_path) if request.get? && !http_auth?\n    end\n\n    def is_navigational_format?\n      Devise.navigational_formats.include?(request_format)\n    end\n\n    # Check if flash messages should be emitted. Default is to do it on\n    # navigational formats\n    def is_flashing_format?\n      request.respond_to?(:flash) && is_navigational_format?\n    end\n\n    def request_format\n      @request_format ||= request.format.try(:ref)\n    end\n\n    def relative_url_root\n      @relative_url_root ||= begin\n        config = Rails.application.config\n\n        config.try(:relative_url_root) || config.action_controller.try(:relative_url_root)\n      end\n    end\n\n    def relative_url_root?\n      relative_url_root.present?\n    end\n\n    ActiveSupport.run_load_hooks(:devise_failure_app, self)\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/activatable.rb",
    "content": "# frozen_string_literal: true\n\n# Deny user access whenever their account is not active yet.\n# We need this as hook to validate the user activity on each request\n# and in case the user is using other strategies beside Devise ones.\nWarden::Manager.after_set_user do |record, warden, options|\n  if record && record.respond_to?(:active_for_authentication?) && !record.active_for_authentication?\n    scope = options[:scope]\n    warden.logout(scope)\n    throw :warden, scope: scope, message: record.inactive_message, locale: options.fetch(:locale, I18n.locale)\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/csrf_cleaner.rb",
    "content": "# frozen_string_literal: true\n\nWarden::Manager.after_authentication do |record, warden, options|\n  clean_up_for_winning_strategy = !warden.winning_strategy.respond_to?(:clean_up_csrf?) ||\n    warden.winning_strategy.clean_up_csrf?\n  if Devise.clean_up_csrf_token_on_authentication && clean_up_for_winning_strategy\n    if warden.request.respond_to?(:reset_csrf_token)\n      # Rails 7.1+\n      warden.request.reset_csrf_token\n    else\n      warden.request.session.try(:delete, :_csrf_token)\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/forgetable.rb",
    "content": "# frozen_string_literal: true\n\n# Before logout hook to forget the user in the given scope, if it responds\n# to forget_me! Also clear remember token to ensure the user won't be\n# remembered again. Notice that we forget the user unless the record is not persisted.\n# This avoids forgetting deleted users.\nWarden::Manager.before_logout do |record, warden, options|\n  if record.respond_to?(:forget_me!)\n    Devise::Hooks::Proxy.new(warden).forget_me(record)\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/lockable.rb",
    "content": "# frozen_string_literal: true\n\n# After each sign in, if resource responds to failed_attempts, sets it to 0\n# This is only triggered when the user is explicitly set (with set_user)\nWarden::Manager.after_set_user except: :fetch do |record, warden, options|\n  if record.respond_to?(:reset_failed_attempts!) && warden.authenticated?(options[:scope])\n    record.reset_failed_attempts!\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/proxy.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Hooks\n    # A small warden proxy so we can remember, forget and\n    # sign out users from hooks.\n    class Proxy #:nodoc:\n      include Devise::Controllers::Rememberable\n      include Devise::Controllers::SignInOut\n\n      attr_reader :warden\n      delegate :cookies, :request, to: :warden\n\n      def initialize(warden)\n        @warden = warden\n      end\n\n      def session\n        warden.request.session\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/rememberable.rb",
    "content": "# frozen_string_literal: true\n\nWarden::Manager.after_set_user except: :fetch do |record, warden, options|\n  scope = options[:scope]\n  if record.respond_to?(:remember_me) && options[:store] != false &&\n     record.remember_me && warden.authenticated?(scope)\n    Devise::Hooks::Proxy.new(warden).remember_me(record)\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/timeoutable.rb",
    "content": "# frozen_string_literal: true\n\n# Each time a record is set we check whether its session has already timed out\n# or not, based on last request time. If so, the record is logged out and\n# redirected to the sign in page. Also, each time the request comes and the\n# record is set, we set the last request time inside its scoped session to\n# verify timeout in the following request.\nWarden::Manager.after_set_user do |record, warden, options|\n  scope = options[:scope]\n  env   = warden.request.env\n\n  if record && record.respond_to?(:timedout?) && warden.authenticated?(scope) &&\n     options[:store] != false && !env['devise.skip_timeoutable']\n    last_request_at = warden.session(scope)['last_request_at']\n\n    if last_request_at.is_a? Integer\n      last_request_at = Time.at(last_request_at).utc\n    elsif last_request_at.is_a? String\n      last_request_at = Time.parse(last_request_at)\n    end\n\n    proxy = Devise::Hooks::Proxy.new(warden)\n\n    if !env['devise.skip_timeout'] &&\n        record.timedout?(last_request_at) &&\n        !proxy.remember_me_is_active?(record)\n      Devise.sign_out_all_scopes ? proxy.sign_out : proxy.sign_out(scope)\n      throw :warden, scope: scope, message: :timeout, locale: options.fetch(:locale, I18n.locale)\n    end\n\n    unless env['devise.skip_trackable']\n      warden.session(scope)['last_request_at'] = Time.now.utc.to_i\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/hooks/trackable.rb",
    "content": "# frozen_string_literal: true\n\n# After each sign in, update sign in time, sign in count and sign in IP.\n# This is only triggered when the user is explicitly set (with set_user)\n# and on authentication. Retrieving the user from session (:fetch) does\n# not trigger it.\nWarden::Manager.after_set_user except: :fetch do |record, warden, options|\n  if record.respond_to?(:update_tracked_fields!) && warden.authenticated?(options[:scope]) && !warden.request.env['devise.skip_trackable']\n    record.update_tracked_fields!(warden.request)\n  end\nend\n"
  },
  {
    "path": "lib/devise/mailers/helpers.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Mailers\n    module Helpers\n      extend ActiveSupport::Concern\n\n      included do\n        include Devise::Controllers::ScopedViews\n      end\n\n      protected\n\n      attr_reader :scope_name, :resource\n\n      # Configure default email options\n      def devise_mail(record, action, opts = {}, &block)\n        initialize_from_record(record)\n        mail headers_for(action, opts), &block\n      end\n\n      def initialize_from_record(record)\n        @scope_name = Devise::Mapping.find_scope!(record)\n        @resource   = instance_variable_set(\"@#{devise_mapping.name}\", record)\n      end\n\n      def devise_mapping\n        @devise_mapping ||= Devise.mappings[scope_name]\n      end\n\n      def headers_for(action, opts)\n        headers = {\n          subject: subject_for(action),\n          to: resource.email,\n          from: mailer_sender(devise_mapping),\n          reply_to: mailer_sender(devise_mapping),\n          template_path: template_paths,\n          template_name: action\n        }\n        # Give priority to the mailer's default if they exists.\n        headers.delete(:from) if default_params[:from]\n        headers.delete(:reply_to) if default_params[:reply_to]\n\n        headers.merge!(opts)\n\n        @email = headers[:to]\n        headers\n      end\n\n      def mailer_sender(mapping)\n        if Devise.mailer_sender.is_a?(Proc)\n          Devise.mailer_sender.call(mapping.name)\n        else\n          Devise.mailer_sender\n        end\n      end\n\n      def template_paths\n        template_path = _prefixes.dup\n        template_path.unshift \"#{@devise_mapping.scoped_path}/mailer\" if self.class.scoped_views?\n        template_path\n      end\n\n      # Set up a subject doing an I18n lookup. At first, it attempts to set a subject\n      # based on the current mapping:\n      #\n      #   en:\n      #     devise:\n      #       mailer:\n      #         confirmation_instructions:\n      #           user_subject: '...'\n      #\n      # If one does not exist, it fallbacks to ActionMailer default:\n      #\n      #   en:\n      #     devise:\n      #       mailer:\n      #         confirmation_instructions:\n      #           subject: '...'\n      #\n      def subject_for(key)\n        I18n.t(:\"#{devise_mapping.name}_subject\", scope: [:devise, :mailer, key],\n          default: [:subject, key.to_s.humanize])\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/mapping.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  # Responsible for handling devise mappings and routes configuration. Each\n  # resource configured by devise_for in routes is actually creating a mapping\n  # object. You can refer to devise_for in routes for usage options.\n  #\n  # The required value in devise_for is actually not used internally, but it's\n  # inflected to find all other values.\n  #\n  #   map.devise_for :users\n  #   mapping = Devise.mappings[:user]\n  #\n  #   mapping.name #=> :user\n  #   # is the scope used in controllers and warden, given in the route as :singular.\n  #\n  #   mapping.as   #=> \"users\"\n  #   # how the mapping should be search in the path, given in the route as :as.\n  #\n  #   mapping.to   #=> User\n  #   # is the class to be loaded from routes, given in the route as :class_name.\n  #\n  #   mapping.modules  #=> [:authenticatable]\n  #   # is the modules included in the class\n  #\n  class Mapping #:nodoc:\n    attr_reader :singular, :scoped_path, :path, :controllers, :path_names,\n                :class_name, :sign_out_via, :format, :used_routes, :used_helpers,\n                :failure_app, :router_name\n\n    alias :name :singular\n\n    # Receives an object and finds a scope for it. If a scope cannot be found,\n    # raises an error. If a symbol is given, it's considered to be the scope.\n    def self.find_scope!(obj)\n      obj = obj.devise_scope if obj.respond_to?(:devise_scope)\n      case obj\n      when String, Symbol\n        return obj.to_sym\n      when Class\n        Devise.mappings.each_value { |m| return m.name if obj <= m.to }\n      else\n        Devise.mappings.each_value { |m| return m.name if obj.is_a?(m.to) }\n      end\n\n      raise \"Could not find a valid mapping for #{obj.inspect}\"\n    end\n\n    def self.find_by_path!(path, path_type = :fullpath)\n      Devise.mappings.each_value { |m| return m if path.include?(m.send(path_type)) }\n      raise \"Could not find a valid mapping for path #{path.inspect}\"\n    end\n\n    def initialize(name, options) #:nodoc:\n      @scoped_path = options[:as] ? \"#{options[:as]}/#{name}\" : name.to_s\n      @singular = (options[:singular] || @scoped_path.tr('/', '_').singularize).to_sym\n\n      @class_name = (options[:class_name] || name.to_s.classify).to_s\n      @klass = Devise.ref(@class_name)\n\n      @path = (options[:path] || name).to_s\n      @path_prefix = options[:path_prefix]\n\n      @sign_out_via = options[:sign_out_via] || Devise.sign_out_via\n      @format = options[:format]\n\n      @router_name = options[:router_name]\n\n      default_failure_app(options)\n      default_controllers(options)\n      default_path_names(options)\n      default_used_route(options)\n      default_used_helpers(options)\n    end\n\n    # Return modules for the mapping.\n    def modules\n      @modules ||= to.respond_to?(:devise_modules) ? to.devise_modules : []\n    end\n\n    # Gives the class the mapping points to.\n    def to\n      @klass.get\n    end\n\n    def strategies\n      @strategies ||= STRATEGIES.values_at(*self.modules).compact.uniq.reverse\n    end\n\n    def no_input_strategies\n      self.strategies & Devise::NO_INPUT\n    end\n\n    def routes\n      @routes ||= ROUTES.values_at(*self.modules).compact.uniq\n    end\n\n    def authenticatable?\n      @authenticatable ||= self.modules.any? { |m| m.to_s =~ /authenticatable/ }\n    end\n\n    def fullpath\n      \"/#{@path_prefix}/#{@path}\".squeeze(\"/\")\n    end\n\n    # Create magic predicates for verifying what module is activated by this map.\n    # Example:\n    #\n    #   def confirmable?\n    #     self.modules.include?(:confirmable)\n    #   end\n    #\n    def self.add_module(m)\n      class_eval <<-METHOD, __FILE__, __LINE__ + 1\n        def #{m}?\n          self.modules.include?(:#{m})\n        end\n      METHOD\n    end\n\n    private\n\n    def default_failure_app(options)\n      @failure_app = options[:failure_app] || Devise::FailureApp\n      if @failure_app.is_a?(String)\n        ref = Devise.ref(@failure_app)\n        @failure_app = lambda { |env| ref.get.call(env) }\n      end\n    end\n\n    def default_controllers(options)\n      mod = options[:module] || \"devise\"\n      @controllers = Hash.new { |h,k| h[k] = \"#{mod}/#{k}\" }\n      @controllers.merge!(options[:controllers]) if options[:controllers]\n      @controllers.each { |k,v| @controllers[k] = v.to_s }\n    end\n\n    def default_path_names(options)\n      @path_names = Hash.new { |h,k| h[k] = k.to_s }\n      @path_names[:registration] = \"\"\n      @path_names.merge!(options[:path_names]) if options[:path_names]\n    end\n\n    def default_constraints(options)\n      @constraints = Hash.new\n      @constraints.merge!(options[:constraints]) if options[:constraints]\n    end\n\n    def default_defaults(options)\n      @defaults = Hash.new\n      @defaults.merge!(options[:defaults]) if options[:defaults]\n    end\n\n    def default_used_route(options)\n      singularizer = lambda { |s| s.to_s.singularize.to_sym }\n\n      if options.has_key?(:only)\n        @used_routes = self.routes & Array(options[:only]).map(&singularizer)\n      elsif options[:skip] == :all\n        @used_routes = []\n      else\n        @used_routes = self.routes - Array(options[:skip]).map(&singularizer)\n      end\n    end\n\n    def default_used_helpers(options)\n      singularizer = lambda { |s| s.to_s.singularize.to_sym }\n\n      if options[:skip_helpers] == true\n        @used_helpers = @used_routes\n      elsif skip = options[:skip_helpers]\n        @used_helpers = self.routes - Array(skip).map(&singularizer)\n      else\n        @used_helpers = self.routes\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/authenticatable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/hooks/activatable'\nrequire 'devise/hooks/csrf_cleaner'\n\nmodule Devise\n  module Models\n    # Authenticatable module. Holds common settings for authentication.\n    #\n    # == Options\n    #\n    # Authenticatable adds the following options to +devise+:\n    #\n    #   * +authentication_keys+: parameters used for authentication. By default [:email].\n    #\n    #   * +http_authentication_key+: map the username passed via HTTP Auth to this parameter. Defaults to\n    #     the first element in +authentication_keys+.\n    #\n    #   * +request_keys+: parameters from the request object used for authentication.\n    #     By specifying a symbol (which should be a request method), it will automatically be\n    #     passed to find_for_authentication method and considered in your model lookup.\n    #\n    #     For instance, if you set :request_keys to [:subdomain], :subdomain will be considered\n    #     as key on authentication. This can also be a hash where the value is a boolean specifying\n    #     if the value is required or not.\n    #\n    #   * +http_authenticatable+: if this model allows http authentication. By default false.\n    #     It also accepts an array specifying the strategies that should allow http.\n    #\n    #   * +params_authenticatable+: if this model allows authentication through request params. By default true.\n    #     It also accepts an array specifying the strategies that should allow params authentication.\n    #\n    #   * +skip_session_storage+: By default Devise will store the user in session.\n    #     By default is set to skip_session_storage: [:http_auth].\n    #\n    # == active_for_authentication?\n    #\n    # After authenticating a user and in each request, Devise checks if your model is active by\n    # calling model.active_for_authentication?. This method is overwritten by other devise modules. For instance,\n    # :confirmable overwrites .active_for_authentication? to only return true if your model was confirmed.\n    #\n    # You can overwrite this method yourself, but if you do, don't forget to call super:\n    #\n    #   def active_for_authentication?\n    #     super && special_condition_is_valid?\n    #   end\n    #\n    # Whenever active_for_authentication? returns false, Devise asks the reason why your model is inactive using\n    # the inactive_message method. You can overwrite it as well:\n    #\n    #   def inactive_message\n    #     special_condition_is_valid? ? super : :special_condition_is_not_valid\n    #   end\n    #\n    module Authenticatable\n      extend ActiveSupport::Concern\n\n      UNSAFE_ATTRIBUTES_FOR_SERIALIZATION = [:encrypted_password, :reset_password_token, :reset_password_sent_at,\n        :remember_created_at, :sign_in_count, :current_sign_in_at, :last_sign_in_at, :current_sign_in_ip,\n        :last_sign_in_ip, :password_salt, :confirmation_token, :confirmed_at, :confirmation_sent_at,\n        :remember_token, :unconfirmed_email, :failed_attempts, :unlock_token, :locked_at]\n\n      included do\n        class_attribute :devise_modules, instance_writer: false\n        self.devise_modules ||= []\n\n        before_validation :downcase_keys\n        before_validation :strip_whitespace\n      end\n\n      def self.required_fields(klass)\n        []\n      end\n\n      # Check if the current object is valid for authentication. This method and\n      # find_for_authentication are the methods used in a Warden::Strategy to check\n      # if a model should be signed in or not.\n      #\n      # However, you should not overwrite this method, you should overwrite active_for_authentication?\n      # and inactive_message instead.\n      def valid_for_authentication?\n        block_given? ? yield : true\n      end\n\n      def unauthenticated_message\n        :invalid\n      end\n\n      def active_for_authentication?\n        true\n      end\n\n      def inactive_message\n        :inactive\n      end\n\n      def authenticatable_salt\n      end\n\n      # Redefine serializable_hash in models for more secure defaults.\n      # By default, it removes from the serializable model all attributes that\n      # are *not* accessible. You can remove this default by using :force_except\n      # and passing a new list of attributes you want to exempt. All attributes\n      # given to :except will simply add names to exempt to Devise internal list.\n      def serializable_hash(options = nil)\n        options = options.try(:dup) || {}\n        options[:except] = Array(options[:except]).dup\n\n        if options[:force_except]\n          options[:except].concat Array(options[:force_except])\n        else\n          options[:except].concat UNSAFE_ATTRIBUTES_FOR_SERIALIZATION\n        end\n\n        super(options)\n      end\n\n      # Redefine inspect using serializable_hash, to ensure we don't accidentally\n      # leak passwords into exceptions.\n      def inspect\n        inspection = serializable_hash.collect do |k,v|\n          \"#{k}: #{respond_to?(:attribute_for_inspect) ? attribute_for_inspect(k) : v.inspect}\"\n        end\n        \"#<#{self.class} #{inspection.join(\", \")}>\"\n      end\n\n      protected\n\n      def devise_mailer\n        Devise.mailer\n      end\n\n      # This is an internal method called every time Devise needs\n      # to send a notification/mail. This can be overridden if you\n      # need to customize the e-mail delivery logic. For instance,\n      # if you are using a queue to deliver e-mails (active job, delayed\n      # job, sidekiq, resque, etc), you must add the delivery to the queue\n      # just after the transaction was committed. To achieve this,\n      # you can override send_devise_notification to store the\n      # deliveries until the after_commit callback is triggered.\n      #\n      # The following example uses Active Job's `deliver_later` :\n      #\n      #     class User\n      #       devise :database_authenticatable, :confirmable\n      #\n      #       after_commit :send_pending_devise_notifications\n      #\n      #       protected\n      #\n      #       def send_devise_notification(notification, *args)\n      #         # If the record is new or changed then delay the\n      #         # delivery until the after_commit callback otherwise\n      #         # send now because after_commit will not be called.\n      #         # For Rails < 6 use `changed?` instead of `saved_changes?`.\n      #         if new_record? || saved_changes?\n      #           pending_devise_notifications << [notification, args]\n      #         else\n      #           render_and_send_devise_message(notification, *args)\n      #         end\n      #       end\n      #\n      #       private\n      #\n      #       def send_pending_devise_notifications\n      #         pending_devise_notifications.each do |notification, args|\n      #           render_and_send_devise_message(notification, *args)\n      #         end\n      #\n      #         # Empty the pending notifications array because the\n      #         # after_commit hook can be called multiple times which\n      #         # could cause multiple emails to be sent.\n      #         pending_devise_notifications.clear\n      #       end\n      #\n      #       def pending_devise_notifications\n      #         @pending_devise_notifications ||= []\n      #       end\n      #\n      #       def render_and_send_devise_message(notification, *args)\n      #         message = devise_mailer.send(notification, self, *args)\n      #\n      #         # Deliver later with Active Job's `deliver_later`\n      #         if message.respond_to?(:deliver_later)\n      #           message.deliver_later\n      #         else\n      #           message.deliver_now\n      #         end\n      #       end\n      #\n      #     end\n      #\n      def send_devise_notification(notification, *args)\n        message = devise_mailer.send(notification, self, *args)\n        message.deliver_now\n      end\n\n      def downcase_keys\n        self.class.case_insensitive_keys.each { |k| apply_to_attribute_or_variable(k, :downcase) }\n      end\n\n      def strip_whitespace\n        self.class.strip_whitespace_keys.each { |k| apply_to_attribute_or_variable(k, :strip) }\n      end\n\n      def apply_to_attribute_or_variable(attr, method)\n        if self[attr]\n          self[attr] = self[attr].try(method)\n\n        # Use respond_to? here to avoid a regression where globally\n        # configured strip_whitespace_keys or case_insensitive_keys were\n        # attempting to strip or downcase when a model didn't have the\n        # globally configured key.\n        elsif respond_to?(attr) && respond_to?(\"#{attr}=\")\n          new_value = send(attr).try(method)\n          send(\"#{attr}=\", new_value)\n        end\n      end\n\n      module ClassMethods\n        Devise::Models.config(self, :authentication_keys, :request_keys, :strip_whitespace_keys,\n          :case_insensitive_keys, :http_authenticatable, :params_authenticatable, :skip_session_storage,\n          :http_authentication_key)\n\n        def serialize_into_session(record)\n          [record.to_key, record.authenticatable_salt]\n        end\n\n        def serialize_from_session(key, salt)\n          record = to_adapter.get(key)\n          record if record && record.authenticatable_salt == salt\n        end\n\n        def params_authenticatable?(strategy)\n          params_authenticatable.is_a?(Array) ?\n            params_authenticatable.include?(strategy) : params_authenticatable\n        end\n\n        def http_authenticatable?(strategy)\n          http_authenticatable.is_a?(Array) ?\n            http_authenticatable.include?(strategy) : http_authenticatable\n        end\n\n        # Find first record based on conditions given (ie by the sign in form).\n        # This method is always called during an authentication process but\n        # it may be wrapped as well. For instance, database authenticatable\n        # provides a `find_for_database_authentication` that wraps a call to\n        # this method. This allows you to customize both database authenticatable\n        # or the whole authenticate stack by customize `find_for_authentication.`\n        #\n        # Overwrite to add customized conditions, create a join, or maybe use a\n        # namedscope to filter records while authenticating.\n        # Example:\n        #\n        #   def self.find_for_authentication(tainted_conditions)\n        #     find_first_by_auth_conditions(tainted_conditions, active: true)\n        #   end\n        #\n        # Finally, notice that Devise also queries for users in other scenarios\n        # besides authentication, for example when retrieving a user to send\n        # an e-mail for password reset. In such cases, find_for_authentication\n        # is not called.\n        def find_for_authentication(tainted_conditions)\n          find_first_by_auth_conditions(tainted_conditions)\n        end\n\n        def find_first_by_auth_conditions(tainted_conditions, opts = {})\n          to_adapter.find_first(devise_parameter_filter.filter(tainted_conditions).merge(opts))\n        end\n\n        # Find or initialize a record setting an error if it can't be found.\n        def find_or_initialize_with_error_by(attribute, value, error = :invalid) #:nodoc:\n          find_or_initialize_with_errors([attribute], { attribute => value }, error)\n        end\n\n        # Find or initialize a record with group of attributes based on a list of required attributes.\n        def find_or_initialize_with_errors(required_attributes, attributes, error = :invalid) #:nodoc:\n          attributes.try(:permit!)\n          attributes = attributes.to_h.with_indifferent_access\n                                 .slice(*required_attributes)\n                                 .delete_if { |key, value| value.blank? }\n\n          if attributes.size == required_attributes.size\n            record = find_first_by_auth_conditions(attributes) and return record\n          end\n\n          new(devise_parameter_filter.filter(attributes)).tap do |record|\n            required_attributes.each do |key|\n              record.errors.add(key, attributes[key].blank? ? :blank : error)\n            end\n          end\n        end\n\n        protected\n\n        def devise_parameter_filter\n          @devise_parameter_filter ||= Devise::ParameterFilter.new(case_insensitive_keys, strip_whitespace_keys)\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/confirmable.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Models\n    # Confirmable is responsible to verify if an account is already confirmed to\n    # sign in, and to send emails with confirmation instructions.\n    # Confirmation instructions are sent to the user email after creating a\n    # record and when manually requested by a new confirmation instruction request.\n    #\n    # Confirmable tracks the following columns:\n    #\n    # * confirmation_token   - A unique random token\n    # * confirmed_at         - A timestamp when the user clicked the confirmation link\n    # * confirmation_sent_at - A timestamp when the confirmation_token was generated (not sent)\n    # * unconfirmed_email    - An email address copied from the email attr. After confirmation\n    #                          this value is copied to the email attr then cleared\n    #\n    # == Options\n    #\n    # Confirmable adds the following options to +devise+:\n    #\n    #   * +allow_unconfirmed_access_for+: the time you want to allow the user to access their account\n    #     before confirming it. After this period, the user access is denied. You can\n    #     use this to let your user access some features of your application without\n    #     confirming the account, but blocking it after a certain period (ie 7 days).\n    #     By default allow_unconfirmed_access_for is zero, it means users always have to confirm to sign in.\n    #   * +reconfirmable+: requires any email changes to be confirmed (exactly the same way as\n    #     initial account confirmation) to be applied. Requires additional unconfirmed_email\n    #     db field to be set up (t.reconfirmable in migrations). Until confirmed, new email is\n    #     stored in unconfirmed email column, and copied to email column on successful\n    #     confirmation. Also, when used in conjunction with `send_email_changed_notification`,\n    #     the notification is sent to the original email when the change is requested,\n    #     not when the unconfirmed email is confirmed.\n    #   * +confirm_within+: the time before a sent confirmation token becomes invalid.\n    #     You can use this to force the user to confirm within a set period of time.\n    #     Confirmable will not generate a new token if a repeat confirmation is requested\n    #     during this time frame, unless the user's email changed too.\n    #\n    # == Examples\n    #\n    #   User.find(1).confirm       # returns true unless it's already confirmed\n    #   User.find(1).confirmed?    # true/false\n    #   User.find(1).send_confirmation_instructions # manually send instructions\n    #\n    module Confirmable\n      extend ActiveSupport::Concern\n\n      included do\n        before_create :generate_confirmation_token, if: :confirmation_required?\n        after_create :skip_reconfirmation_in_callback!, if: :send_confirmation_notification?\n        if Devise::Orm.active_record?(self) # ActiveRecord\n          after_commit :send_on_create_confirmation_instructions, on: :create, if: :send_confirmation_notification?\n          after_commit :send_reconfirmation_instructions, on: :update, if: :reconfirmation_required?\n        else # Mongoid\n          after_create :send_on_create_confirmation_instructions, if: :send_confirmation_notification?\n          after_update :send_reconfirmation_instructions, if: :reconfirmation_required?\n        end\n        before_update :postpone_email_change_until_confirmation_and_regenerate_confirmation_token, if: :postpone_email_change?\n      end\n\n      def initialize(*args, &block)\n        @bypass_confirmation_postpone = false\n        @skip_reconfirmation_in_callback = false\n        @reconfirmation_required = false\n        @skip_confirmation_notification = false\n        @raw_confirmation_token = nil\n        super\n      end\n\n      def self.required_fields(klass)\n        required_methods = [:confirmation_token, :confirmed_at, :confirmation_sent_at]\n        required_methods << :unconfirmed_email if klass.reconfirmable\n        required_methods\n      end\n\n      # Confirm a user by setting it's confirmed_at to actual time. If the user\n      # is already confirmed, add an error to email field. If the user is invalid\n      # add errors\n      def confirm(args = {})\n        pending_any_confirmation do\n          if confirmation_period_expired?\n            self.errors.add(:email, :confirmation_period_expired,\n              period: Devise::TimeInflector.time_ago_in_words(self.class.confirm_within.ago))\n            return false\n          end\n\n          self.confirmed_at = Time.now.utc\n\n          saved = if pending_reconfirmation?\n            skip_reconfirmation!\n            self.email = unconfirmed_email\n            self.unconfirmed_email = nil\n\n            # We need to validate in such cases to enforce e-mail uniqueness\n            save(validate: true)\n          else\n            save(validate: args[:ensure_valid] == true)\n          end\n\n          after_confirmation if saved\n          saved\n        end\n      end\n\n      # Verifies whether a user is confirmed or not\n      def confirmed?\n        !!confirmed_at\n      end\n\n      def pending_reconfirmation?\n        self.class.reconfirmable && unconfirmed_email.present?\n      end\n\n      # Send confirmation instructions by email\n      def send_confirmation_instructions\n        unless @raw_confirmation_token\n          generate_confirmation_token!\n        end\n\n        opts = pending_reconfirmation? ? { to: unconfirmed_email } : { }\n        send_devise_notification(:confirmation_instructions, @raw_confirmation_token, opts)\n      end\n\n      def send_reconfirmation_instructions\n        @reconfirmation_required = false\n\n        unless @skip_confirmation_notification\n          send_confirmation_instructions\n        end\n      end\n\n      # Resend confirmation token.\n      # Regenerates the token if the period is expired.\n      def resend_confirmation_instructions\n        pending_any_confirmation do\n          send_confirmation_instructions\n        end\n      end\n\n      # Overwrites active_for_authentication? for confirmation\n      # by verifying whether a user is active to sign in or not. If the user\n      # is already confirmed, it should never be blocked. Otherwise we need to\n      # calculate if the confirm time has not expired for this user.\n      def active_for_authentication?\n        super && (!confirmation_required? || confirmed? || confirmation_period_valid?)\n      end\n\n      # The message to be shown if the account is inactive.\n      def inactive_message\n        !confirmed? ? :unconfirmed : super\n      end\n\n      # If you don't want confirmation to be sent on create, neither a code\n      # to be generated, call skip_confirmation!\n      def skip_confirmation!\n        self.confirmed_at = Time.now.utc\n      end\n\n      # Skips sending the confirmation/reconfirmation notification email after_create/after_update. Unlike\n      # #skip_confirmation!, record still requires confirmation.\n      def skip_confirmation_notification!\n        @skip_confirmation_notification = true\n      end\n\n      # If you don't want reconfirmation to be sent, neither a code\n      # to be generated, call skip_reconfirmation!\n      def skip_reconfirmation!\n        @bypass_confirmation_postpone = true\n      end\n\n      protected\n\n        # To not require reconfirmation after creating with #save called in a\n        # callback call skip_create_confirmation!\n        def skip_reconfirmation_in_callback!\n          @skip_reconfirmation_in_callback = true\n        end\n\n        # A callback method used to deliver confirmation\n        # instructions on creation. This can be overridden\n        # in models to map to a nice sign up e-mail.\n        def send_on_create_confirmation_instructions\n          send_confirmation_instructions\n        end\n\n        # Callback to overwrite if confirmation is required or not.\n        def confirmation_required?\n          !confirmed?\n        end\n\n        # Checks if the confirmation for the user is within the limit time.\n        # We do this by calculating if the difference between today and the\n        # confirmation sent date does not exceed the confirm in time configured.\n        # allow_unconfirmed_access_for is a model configuration, must always be an integer value.\n        #\n        # Example:\n        #\n        #   # allow_unconfirmed_access_for = 1.day and confirmation_sent_at = today\n        #   confirmation_period_valid?   # returns true\n        #\n        #   # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 4.days.ago\n        #   confirmation_period_valid?   # returns true\n        #\n        #   # allow_unconfirmed_access_for = 5.days and confirmation_sent_at = 5.days.ago\n        #   confirmation_period_valid?   # returns false\n        #\n        #   # allow_unconfirmed_access_for = 0.days\n        #   confirmation_period_valid?   # will always return false\n        #\n        #   # allow_unconfirmed_access_for = nil\n        #   confirmation_period_valid?   # will always return true\n        #\n        def confirmation_period_valid?\n          return true if self.class.allow_unconfirmed_access_for.nil?\n          return false if self.class.allow_unconfirmed_access_for == 0.days\n\n          confirmation_sent_at && confirmation_sent_at.utc >= self.class.allow_unconfirmed_access_for.ago\n        end\n\n        # Checks if the user confirmation happens before the token becomes invalid\n        # Examples:\n        #\n        #   # confirm_within = 3.days and confirmation_sent_at = 2.days.ago\n        #   confirmation_period_expired?  # returns false\n        #\n        #   # confirm_within = 3.days and confirmation_sent_at = 4.days.ago\n        #   confirmation_period_expired?  # returns true\n        #\n        #   # confirm_within = nil\n        #   confirmation_period_expired?  # will always return false\n        #\n        def confirmation_period_expired?\n          self.class.confirm_within && self.confirmation_sent_at && (Time.now.utc > self.confirmation_sent_at.utc + self.class.confirm_within)\n        end\n\n        # Checks whether the record requires any confirmation.\n        def pending_any_confirmation\n          if (!confirmed? || pending_reconfirmation?)\n            yield\n          else\n            self.errors.add(:email, :already_confirmed)\n            false\n          end\n        end\n\n        # Generates a new random token for confirmation, and stores\n        # the time this token is being generated in confirmation_sent_at\n        def generate_confirmation_token\n          if self.confirmation_token && !confirmation_period_expired?\n            @raw_confirmation_token = self.confirmation_token\n          else\n            self.confirmation_token = @raw_confirmation_token = Devise.friendly_token\n            self.confirmation_sent_at = Time.now.utc\n          end\n        end\n\n        def generate_confirmation_token!\n          generate_confirmation_token && save(validate: false)\n        end\n\n        def postpone_email_change_until_confirmation_and_regenerate_confirmation_token\n          @reconfirmation_required = true\n          # Force unconfirmed_email to be updated, even if the value hasn't changed, to prevent a\n          # race condition which could allow an attacker to confirm an email they don't own. See #5783.\n          devise_unconfirmed_email_will_change!\n          self.unconfirmed_email = self.email\n          self.email = self.devise_email_in_database\n          self.confirmation_token = nil\n          generate_confirmation_token\n        end\n\n        def postpone_email_change?\n          postpone = self.class.reconfirmable &&\n            devise_will_save_change_to_email? &&\n            !@bypass_confirmation_postpone &&\n            self.email.present? &&\n            (!@skip_reconfirmation_in_callback || !self.devise_email_in_database.nil?)\n          @bypass_confirmation_postpone = false\n          postpone\n        end\n\n        def reconfirmation_required?\n          self.class.reconfirmable && @reconfirmation_required && (self.email.present? || self.unconfirmed_email.present?)\n        end\n\n        def send_confirmation_notification?\n          confirmation_required? && !@skip_confirmation_notification && self.email.present?\n        end\n\n        # With reconfirmable, notify the original email when the user first\n        # requests the email change, instead of when the change is confirmed.\n        def send_email_changed_notification?\n          if self.class.reconfirmable\n            self.class.send_email_changed_notification && reconfirmation_required?\n          else\n            super\n          end\n        end\n\n        # A callback initiated after successfully confirming. This can be\n        # used to insert your own logic that is only run after the user successfully\n        # confirms.\n        #\n        # Example:\n        #\n        #   def after_confirmation\n        #     self.update_attribute(:invite_code, nil)\n        #   end\n        #\n        def after_confirmation\n        end\n\n      module ClassMethods\n        # Attempt to find a user by its email. If a record is found, send new\n        # confirmation instructions to it. If not, try searching for a user by unconfirmed_email\n        # field. If no user is found, returns a new user with an email not found error.\n        # Options must contain the user email\n        def send_confirmation_instructions(attributes = {})\n          confirmable = find_by_unconfirmed_email_with_errors(attributes) if reconfirmable\n          unless confirmable.try(:persisted?)\n            confirmable = find_or_initialize_with_errors(confirmation_keys, attributes, :not_found)\n          end\n          confirmable.resend_confirmation_instructions if confirmable.persisted?\n          confirmable\n        end\n\n        # Find a user by its confirmation token and try to confirm it.\n        # If no user is found, returns a new user with an error.\n        # If the user is already confirmed, create an error for the user\n        # Options must have the confirmation_token\n        def confirm_by_token(confirmation_token)\n          # When the `confirmation_token` parameter is blank, if there are any users with a blank\n          # `confirmation_token` in the database, the first one would be confirmed here.\n          # The error is being manually added here to ensure no users are confirmed by mistake.\n          # This was done in the model for convenience, since validation errors are automatically\n          # displayed in the view.\n          if confirmation_token.blank?\n            confirmable = new\n            confirmable.errors.add(:confirmation_token, :blank)\n            return confirmable\n          end\n\n          confirmable = find_first_by_auth_conditions(confirmation_token: confirmation_token)\n\n          unless confirmable\n            confirmation_digest = Devise.token_generator.digest(self, :confirmation_token, confirmation_token)\n            confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_digest)\n          end\n\n          # TODO: replace above lines with\n          # confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)\n          # after enough time has passed that Devise clients do not use digested tokens\n\n          confirmable.confirm if confirmable.persisted?\n          confirmable\n        end\n\n        # Find a record for confirmation by unconfirmed email field\n        def find_by_unconfirmed_email_with_errors(attributes = {})\n          attributes = attributes.slice(*confirmation_keys).permit!.to_h if attributes.respond_to? :permit\n          unconfirmed_required_attributes = confirmation_keys.map { |k| k == :email ? :unconfirmed_email : k }\n          unconfirmed_attributes = attributes.symbolize_keys\n          unconfirmed_attributes[:unconfirmed_email] = unconfirmed_attributes.delete(:email)\n          find_or_initialize_with_errors(unconfirmed_required_attributes, unconfirmed_attributes, :not_found)\n        end\n\n        Devise::Models.config(self, :allow_unconfirmed_access_for, :confirmation_keys, :reconfirmable, :confirm_within)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/database_authenticatable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/strategies/database_authenticatable'\n\nmodule Devise\n  module Models\n    # Authenticatable Module, responsible for hashing the password and\n    # validating the authenticity of a user while signing in.\n    #\n    # This module defines a `password=` method. This method will hash the argument\n    # and store it in the `encrypted_password` column, bypassing any pre-existing\n    # `password` column if it exists.\n    #\n    # == Options\n    #\n    # DatabaseAuthenticatable adds the following options to +devise+:\n    #\n    #   * +pepper+: a random string used to provide a more secure hash. Use\n    #     `rails secret` to generate new keys.\n    #\n    #   * +stretches+: the cost given to bcrypt.\n    #\n    #   * +send_email_changed_notification+: notify original email when it changes.\n    #\n    #   * +send_password_change_notification+: notify email when password changes.\n    #\n    # == Examples\n    #\n    #    User.find(1).valid_password?('password123')         # returns true/false\n    #\n    module DatabaseAuthenticatable\n      extend ActiveSupport::Concern\n\n      included do\n        after_update :send_email_changed_notification, if: :send_email_changed_notification?\n        after_update :send_password_change_notification, if: :send_password_change_notification?\n\n        attr_reader :password, :current_password\n        attr_accessor :password_confirmation\n      end\n\n      def initialize(*args, &block)\n        @skip_email_changed_notification = false\n        @skip_password_change_notification = false\n        super\n      end\n\n      # Skips sending the email changed notification after_update\n      def skip_email_changed_notification!\n        @skip_email_changed_notification = true\n      end\n\n      # Skips sending the password change notification after_update\n      def skip_password_change_notification!\n        @skip_password_change_notification = true\n      end\n\n      def self.required_fields(klass)\n        [:encrypted_password] + klass.authentication_keys\n      end\n\n      # Generates a hashed password based on the given value.\n      # For legacy reasons, we use `encrypted_password` to store\n      # the hashed password.\n      def password=(new_password)\n        @password = new_password\n        self.encrypted_password = password_digest(@password) if @password.present?\n      end\n\n      # Verifies whether a password (ie from sign in) is the user password.\n      def valid_password?(password)\n        Devise::Encryptor.compare(self.class, encrypted_password, password)\n      end\n\n      # Set password and password confirmation to nil\n      def clean_up_passwords\n        self.password = self.password_confirmation = nil\n      end\n\n      # Update record attributes when :current_password matches, otherwise\n      # returns error on :current_password.\n      #\n      # This method also rejects the password field if it is blank (allowing\n      # users to change relevant information like the e-mail without changing\n      # their password). In case the password field is rejected, the confirmation\n      # is also rejected as long as it is also blank.\n      def update_with_password(params)\n        current_password = params.delete(:current_password)\n\n        if params[:password].blank?\n          params.delete(:password)\n          params.delete(:password_confirmation) if params[:password_confirmation].blank?\n        end\n\n        result = if valid_password?(current_password)\n          update(params)\n        else\n          assign_attributes(params)\n          valid?\n          errors.add(:current_password, current_password.blank? ? :blank : :invalid)\n          false\n        end\n\n        clean_up_passwords\n        result\n      end\n\n      # Updates record attributes without asking for the current password.\n      # Never allows a change to the current password. If you are using this\n      # method, you should probably override this method to protect other\n      # attributes you would not like to be updated without a password.\n      #\n      # Example:\n      #\n      #   def update_without_password(params)\n      #     params.delete(:email)\n      #     super(params)\n      #   end\n      #\n      def update_without_password(params)\n        params.delete(:password)\n        params.delete(:password_confirmation)\n\n        result = update(params)\n        clean_up_passwords\n        result\n      end\n\n      # Destroy record when :current_password matches, otherwise returns\n      # error on :current_password. It also automatically rejects\n      # :current_password if it is blank.\n      def destroy_with_password(current_password)\n        result = if valid_password?(current_password)\n          destroy\n        else\n          valid?\n          errors.add(:current_password, current_password.blank? ? :blank : :invalid)\n          false\n        end\n\n        result\n      end\n\n      # A callback initiated after successfully authenticating. This can be\n      # used to insert your own logic that is only run after the user successfully\n      # authenticates.\n      #\n      # Example:\n      #\n      #   def after_database_authentication\n      #     self.update_attribute(:invite_code, nil)\n      #   end\n      #\n      def after_database_authentication\n      end\n\n      # A reliable way to expose the salt regardless of the implementation.\n      def authenticatable_salt\n        encrypted_password[0,29] if encrypted_password\n      end\n\n      # Send notification to user when email changes.\n      def send_email_changed_notification\n        send_devise_notification(:email_changed, to: devise_email_before_last_save)\n      end\n\n      # Send notification to user when password changes.\n      def send_password_change_notification\n        send_devise_notification(:password_change)\n      end\n\n    protected\n\n      # Hashes the password using bcrypt. Custom hash functions should override\n      # this method to apply their own algorithm.\n      #\n      # See https://github.com/heartcombo/devise-encryptable for examples\n      # of other hashing engines.\n      def password_digest(password)\n        Devise::Encryptor.digest(self.class, password)\n      end\n\n      def send_email_changed_notification?\n        self.class.send_email_changed_notification && devise_saved_change_to_email? && !@skip_email_changed_notification\n      end\n\n      def send_password_change_notification?\n        self.class.send_password_change_notification && devise_saved_change_to_encrypted_password? && !@skip_password_change_notification\n      end\n\n      module ClassMethods\n        Devise::Models.config(self, :pepper, :stretches, :send_email_changed_notification, :send_password_change_notification)\n\n        # We assume this method already gets the sanitized values from the\n        # DatabaseAuthenticatable strategy. If you are using this method on\n        # your own, be sure to sanitize the conditions hash to only include\n        # the proper fields.\n        def find_for_database_authentication(conditions)\n          find_for_authentication(conditions)\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/lockable.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"devise/hooks/lockable\"\n\nmodule Devise\n  module Models\n    # Handles blocking a user access after a certain number of attempts.\n    # Lockable accepts two different strategies to unlock a user after it's\n    # blocked: email and time. The former will send an email to the user when\n    # the lock happens, containing a link to unlock its account. The second\n    # will unlock the user automatically after some configured time (ie 2.hours).\n    # It's also possible to set up lockable to use both email and time strategies.\n    #\n    # == Options\n    #\n    # Lockable adds the following options to +devise+:\n    #\n    #   * +maximum_attempts+: how many attempts should be accepted before blocking the user.\n    #   * +lock_strategy+: lock the user account by :failed_attempts or :none.\n    #   * +unlock_strategy+: unlock the user account by :time, :email, :both or :none.\n    #   * +unlock_in+: the time you want to unlock the user after lock happens. Only available when unlock_strategy is :time or :both.\n    #   * +unlock_keys+: the keys you want to use when locking and unlocking an account\n    #\n    module Lockable\n      extend  ActiveSupport::Concern\n\n      delegate :lock_strategy_enabled?, :unlock_strategy_enabled?, to: \"self.class\"\n\n      def self.required_fields(klass)\n        attributes = []\n        attributes << :failed_attempts if klass.lock_strategy_enabled?(:failed_attempts)\n        attributes << :locked_at if klass.unlock_strategy_enabled?(:time)\n        attributes << :unlock_token if klass.unlock_strategy_enabled?(:email)\n\n        attributes\n      end\n\n      # Lock a user setting its locked_at to actual time.\n      # * +opts+: Hash options if you don't want to send email\n      #   when you lock access, you could pass the next hash\n      #   `{ send_instructions: false } as option`.\n      def lock_access!(opts = { })\n        self.locked_at = Time.now.utc\n\n        if unlock_strategy_enabled?(:email) && opts.fetch(:send_instructions, true)\n          send_unlock_instructions\n        else\n          save(validate: false)\n        end\n      end\n\n      # Unlock a user by cleaning locked_at and failed_attempts.\n      def unlock_access!\n        self.locked_at = nil\n        self.failed_attempts = 0 if respond_to?(:failed_attempts=)\n        self.unlock_token = nil  if respond_to?(:unlock_token=)\n        save(validate: false)\n      end\n\n      # Resets failed attempts counter to 0.\n      def reset_failed_attempts!\n        if respond_to?(:failed_attempts) && !failed_attempts.to_i.zero?\n          self.failed_attempts = 0\n          save(validate: false)\n        end\n      end\n\n      # Verifies whether a user is locked or not.\n      def access_locked?\n        !!locked_at && !lock_expired?\n      end\n\n      # Send unlock instructions by email\n      def send_unlock_instructions\n        raw, enc = Devise.token_generator.generate(self.class, :unlock_token)\n        self.unlock_token = enc\n        save(validate: false)\n        send_devise_notification(:unlock_instructions, raw, {})\n        raw\n      end\n\n      # Resend the unlock instructions if the user is locked.\n      def resend_unlock_instructions\n        if_access_locked { send_unlock_instructions }\n      end\n\n      # Overwrites active_for_authentication? from Devise::Models::Authenticatable for locking purposes\n      # by verifying whether a user is active to sign in or not based on locked?\n      def active_for_authentication?\n        super && !access_locked?\n      end\n\n      # Overwrites invalid_message from Devise::Models::Authenticatable to define\n      # the correct reason for blocking the sign in.\n      def inactive_message\n        access_locked? ? :locked : super\n      end\n\n      # Overwrites valid_for_authentication? from Devise::Models::Authenticatable\n      # for verifying whether a user is allowed to sign in or not. If the user\n      # is locked, it should never be allowed.\n      def valid_for_authentication?\n        return super unless persisted? && lock_strategy_enabled?(:failed_attempts)\n\n        # Unlock the user if the lock is expired, no matter\n        # if the user can login or not (wrong password, etc)\n        unlock_access! if lock_expired?\n\n        if super && !access_locked?\n          true\n        else\n          increment_failed_attempts\n          if attempts_exceeded?\n            lock_access! unless access_locked?\n          else\n            save(validate: false)\n          end\n          false\n        end\n      end\n\n      def increment_failed_attempts\n        self.class.increment_counter(:failed_attempts, id)\n        reload\n      end\n\n      def unauthenticated_message\n        # If set to paranoid mode, do not show the locked message because it\n        # leaks the existence of an account.\n        if Devise.paranoid\n          super\n        elsif access_locked? || (lock_strategy_enabled?(:failed_attempts) && attempts_exceeded?)\n          :locked\n        elsif lock_strategy_enabled?(:failed_attempts) && last_attempt? && self.class.last_attempt_warning\n          :last_attempt\n        else\n          super\n        end\n      end\n\n      protected\n\n        def attempts_exceeded?\n          self.failed_attempts >= self.class.maximum_attempts\n        end\n\n        def last_attempt?\n          self.failed_attempts == self.class.maximum_attempts - 1\n        end\n\n        # Tells if the lock is expired if :time unlock strategy is active\n        def lock_expired?\n          if unlock_strategy_enabled?(:time)\n            locked_at && locked_at < self.class.unlock_in.ago\n          else\n            false\n          end\n        end\n\n        # Checks whether the record is locked or not, yielding to the block\n        # if it's locked, otherwise adds an error to email.\n        def if_access_locked\n          if access_locked?\n            yield\n          else\n            self.errors.add(Devise.unlock_keys.first, :not_locked)\n            false\n          end\n        end\n\n      module ClassMethods\n        # List of strategies that are enabled/supported if :both is used.\n        BOTH_STRATEGIES = [:time, :email]\n\n        # Attempt to find a user by its unlock keys. If a record is found, send new\n        # unlock instructions to it. If not user is found, returns a new user\n        # with an email not found error.\n        # Options must contain the user's unlock keys\n        def send_unlock_instructions(attributes = {})\n          lockable = find_or_initialize_with_errors(unlock_keys, attributes, :not_found)\n          lockable.resend_unlock_instructions if lockable.persisted?\n          lockable\n        end\n\n        # Find a user by its unlock token and try to unlock it.\n        # If no user is found, returns a new user with an error.\n        # If the user is not locked, creates an error for the user\n        # Options must have the unlock_token\n        def unlock_access_by_token(unlock_token)\n          original_token = unlock_token\n          unlock_token   = Devise.token_generator.digest(self, :unlock_token, unlock_token)\n\n          lockable = find_or_initialize_with_error_by(:unlock_token, unlock_token)\n          lockable.unlock_access! if lockable.persisted?\n          lockable.unlock_token = original_token\n          lockable\n        end\n\n        # Is the unlock enabled for the given unlock strategy?\n        def unlock_strategy_enabled?(strategy)\n          self.unlock_strategy == strategy ||\n            (self.unlock_strategy == :both && BOTH_STRATEGIES.include?(strategy))\n        end\n\n        # Is the lock enabled for the given lock strategy?\n        def lock_strategy_enabled?(strategy)\n          self.lock_strategy == strategy\n        end\n\n        Devise::Models.config(self, :maximum_attempts, :lock_strategy, :unlock_strategy, :unlock_in, :unlock_keys, :last_attempt_warning)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/omniauthable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/omniauth'\n\nmodule Devise\n  module Models\n    # Adds OmniAuth support to your model.\n    #\n    # == Options\n    #\n    # Oauthable adds the following options to +devise+:\n    #\n    #   * +omniauth_providers+: Which providers are available to this model. It expects an array:\n    #\n    #       devise :database_authenticatable, :omniauthable, omniauth_providers: [:twitter]\n    #\n    module Omniauthable\n      extend ActiveSupport::Concern\n\n      def self.required_fields(klass)\n        []\n      end\n\n      module ClassMethods\n        Devise::Models.config(self, :omniauth_providers)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/recoverable.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Models\n\n    # Recoverable takes care of resetting the user password and send reset instructions.\n    #\n    # ==Options\n    #\n    # Recoverable adds the following options to +devise+:\n    #\n    #   * +reset_password_keys+: the keys you want to use when recovering the password for an account\n    #   * +reset_password_within+: the time period within which the password must be reset or the token expires.\n    #   * +sign_in_after_reset_password+: whether or not to sign in the user automatically after a password reset.\n    #\n    # == Examples\n    #\n    #   # resets the user password and save the record, true if valid passwords are given, otherwise false\n    #   User.find(1).reset_password('password123', 'password123')\n    #\n    #   # creates a new token and send it with instructions about how to reset the password\n    #   User.find(1).send_reset_password_instructions\n    #\n    module Recoverable\n      extend ActiveSupport::Concern\n\n      def self.required_fields(klass)\n        [:reset_password_sent_at, :reset_password_token]\n      end\n\n      included do\n        before_update :clear_reset_password_token, if: :clear_reset_password_token?\n      end\n\n      # Update password saving the record and clearing token. Returns true if\n      # the passwords are valid and the record was saved, false otherwise.\n      def reset_password(new_password, new_password_confirmation)\n        if new_password.present?\n          self.password = new_password\n          self.password_confirmation = new_password_confirmation\n          save\n        else\n          errors.add(:password, :blank)\n          false\n        end\n      end\n\n      # Resets reset password token and send reset password instructions by email.\n      # Returns the token sent in the e-mail.\n      def send_reset_password_instructions\n        token = set_reset_password_token\n        send_reset_password_instructions_notification(token)\n\n        token\n      end\n\n      # Checks if the reset password token sent is within the limit time.\n      # We do this by calculating if the difference between today and the\n      # sending date does not exceed the confirm in time configured.\n      # Returns true if the resource is not responding to reset_password_sent_at at all.\n      # reset_password_within is a model configuration, must always be an integer value.\n      #\n      # Example:\n      #\n      #   # reset_password_within = 1.day and reset_password_sent_at = today\n      #   reset_password_period_valid?   # returns true\n      #\n      #   # reset_password_within = 5.days and reset_password_sent_at = 4.days.ago\n      #   reset_password_period_valid?   # returns true\n      #\n      #   # reset_password_within = 5.days and reset_password_sent_at = 5.days.ago\n      #   reset_password_period_valid?   # returns false\n      #\n      #   # reset_password_within = 0.days\n      #   reset_password_period_valid?   # will always return false\n      #\n      def reset_password_period_valid?\n        reset_password_sent_at && reset_password_sent_at.utc >= self.class.reset_password_within.ago.utc\n      end\n\n      protected\n\n        # Removes reset_password token\n        def clear_reset_password_token\n          self.reset_password_token = nil\n          self.reset_password_sent_at = nil\n        end\n\n        def set_reset_password_token\n          raw, enc = Devise.token_generator.generate(self.class, :reset_password_token)\n\n          self.reset_password_token   = enc\n          self.reset_password_sent_at = Time.now.utc\n          save(validate: false)\n          raw\n        end\n\n        def send_reset_password_instructions_notification(token)\n          send_devise_notification(:reset_password_instructions, token, {})\n        end\n\n        def clear_reset_password_token?\n          encrypted_password_changed = devise_respond_to_and_will_save_change_to_attribute?(:encrypted_password)\n          authentication_keys_changed = self.class.authentication_keys.any? do |attribute|\n            devise_respond_to_and_will_save_change_to_attribute?(attribute)\n          end\n\n          authentication_keys_changed || encrypted_password_changed\n        end\n\n      module ClassMethods\n        # Attempt to find a user by password reset token. If a user is found, return it\n        # If a user is not found, return nil\n        def with_reset_password_token(token)\n          reset_password_token = Devise.token_generator.digest(self, :reset_password_token, token)\n          to_adapter.find_first(reset_password_token: reset_password_token)\n        end\n\n        # Attempt to find a user by its email. If a record is found, send new\n        # password instructions to it. If user is not found, returns a new user\n        # with an email not found error.\n        # Attributes must contain the user's email\n        def send_reset_password_instructions(attributes = {})\n          recoverable = find_or_initialize_with_errors(reset_password_keys, attributes, :not_found)\n          recoverable.send_reset_password_instructions if recoverable.persisted?\n          recoverable\n        end\n\n        # Attempt to find a user by its reset_password_token to reset its\n        # password. If a user is found and token is still valid, reset its password and automatically\n        # try saving the record. If not user is found, returns a new user\n        # containing an error in reset_password_token attribute.\n        # Attributes must contain reset_password_token, password and confirmation\n        def reset_password_by_token(attributes = {})\n          original_token       = attributes[:reset_password_token]\n          reset_password_token = Devise.token_generator.digest(self, :reset_password_token, original_token)\n\n          recoverable = find_or_initialize_with_error_by(:reset_password_token, reset_password_token)\n\n          if recoverable.persisted?\n            if recoverable.reset_password_period_valid?\n              recoverable.reset_password(attributes[:password], attributes[:password_confirmation])\n            else\n              recoverable.errors.add(:reset_password_token, :expired)\n            end\n          end\n\n          recoverable.reset_password_token = original_token if recoverable.reset_password_token.present?\n          recoverable\n        end\n\n        Devise::Models.config(self, :reset_password_keys, :reset_password_within, :sign_in_after_reset_password)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/registerable.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Models\n    # Registerable is responsible for everything related to registering a new\n    # resource (ie user sign up).\n    module Registerable\n      extend ActiveSupport::Concern\n\n      def self.required_fields(klass)\n        []\n      end\n\n      module ClassMethods\n        # A convenience method that receives both parameters and session to\n        # initialize a user. This can be used by OAuth, for example, to send\n        # in the user token and be stored on initialization.\n        #\n        # By default discards all information sent by the session by calling\n        # new with params.\n        def new_with_session(params, session)\n          new(params)\n        end\n\n        Devise::Models.config(self, :sign_in_after_change_password)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/rememberable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/strategies/rememberable'\nrequire 'devise/hooks/rememberable'\nrequire 'devise/hooks/forgetable'\n\nmodule Devise\n  module Models\n    # Rememberable manages generating and clearing token for remembering the user\n    # from a saved cookie. Rememberable also has utility methods for dealing\n    # with serializing the user into the cookie and back from the cookie, trying\n    # to lookup the record based on the saved information.\n    # You probably wouldn't use rememberable methods directly, they are used\n    # mostly internally for handling the remember token.\n    #\n    # == Options\n    #\n    # Rememberable adds the following options to +devise+:\n    #\n    #   * +remember_for+: the time you want the user will be remembered without\n    #     asking for credentials. After this time the user will be blocked and\n    #     will have to enter their credentials again. This configuration is also\n    #     used to calculate the expires time for the cookie created to remember\n    #     the user. By default remember_for is 2.weeks.\n    #\n    #   * +extend_remember_period+: if true, extends the user's remember period\n    #     when remembered via cookie. False by default.\n    #\n    #   * +rememberable_options+: configuration options passed to the created cookie.\n    #\n    # == Examples\n    #\n    #   User.find(1).remember_me!  # regenerating the token\n    #   User.find(1).forget_me!    # clearing the token\n    #\n    #   # generating info to put into cookies\n    #   User.serialize_into_cookie(user)\n    #\n    #   # lookup the user based on the incoming cookie information\n    #   User.serialize_from_cookie(cookie_string)\n    module Rememberable\n      extend ActiveSupport::Concern\n\n      attr_accessor :remember_me\n\n      def self.required_fields(klass)\n        [:remember_created_at]\n      end\n\n      def remember_me!\n        self.remember_token ||= self.class.remember_token if respond_to?(:remember_token)\n        self.remember_created_at ||= Time.now.utc\n        save(validate: false) if self.changed?\n      end\n\n      # If the record is persisted, remove the remember token (but only if\n      # it exists), and save the record without validations.\n      def forget_me!\n        return unless persisted?\n        self.remember_token = nil if respond_to?(:remember_token)\n        self.remember_created_at = nil if self.class.expire_all_remember_me_on_sign_out\n        save(validate: false)\n      end\n\n      def remember_expires_at\n        self.class.remember_for.from_now\n      end\n\n      def extend_remember_period\n        self.class.extend_remember_period\n      end\n\n      def rememberable_value\n        if respond_to?(:remember_token)\n          remember_token\n        elsif respond_to?(:authenticatable_salt) && (salt = authenticatable_salt.presence)\n          salt\n        else\n          raise \"authenticatable_salt returned nil for the #{self.class.name} model. \" \\\n            \"In order to use rememberable, you must ensure a password is always set \" \\\n            \"or have a remember_token column in your model or implement your own \" \\\n            \"rememberable_value in the model with custom logic.\"\n        end\n      end\n\n      def rememberable_options\n        self.class.rememberable_options\n      end\n\n      # A callback initiated after successfully being remembered. This can be\n      # used to insert your own logic that is only run after the user is\n      # remembered.\n      #\n      # Example:\n      #\n      #   def after_remembered\n      #     self.update_attribute(:invite_code, nil)\n      #   end\n      #\n      def after_remembered\n      end\n\n      def remember_me?(token, generated_at)\n        # TODO: Normalize the JSON type coercion along with the Timeoutable hook\n        # in a single place https://github.com/heartcombo/devise/blob/ffe9d6d406e79108cf32a2c6a1d0b3828849c40b/lib/devise/hooks/timeoutable.rb#L14-L18\n        if generated_at.is_a?(String)\n          generated_at = time_from_json(generated_at)\n        end\n\n        # The token is only valid if:\n        # 1. we have a date\n        # 2. the current time does not pass the expiry period\n        # 3. the record has a remember_created_at date\n        # 4. the token date is bigger than the remember_created_at\n        # 5. the token matches\n        generated_at.is_a?(Time) &&\n         (self.class.remember_for.ago < generated_at) &&\n         (generated_at > (remember_created_at || Time.now).utc) &&\n         Devise.secure_compare(rememberable_value, token)\n      end\n\n      private\n\n      def time_from_json(value)\n        if value =~ /\\A\\d+\\.\\d+\\Z/\n          Time.at(value.to_f)\n        else\n          Time.parse(value) rescue nil\n        end\n      end\n\n      module ClassMethods\n        # Create the cookie key using the record id and remember_token\n        def serialize_into_cookie(record)\n          [record.to_key, record.rememberable_value, Time.now.utc.to_f.to_s]\n        end\n\n        # Recreate the user based on the stored cookie\n        def serialize_from_cookie(*args)\n          id, token, generated_at = *args\n\n          record = to_adapter.get(id)\n          record if record && record.remember_me?(token, generated_at)\n        end\n\n        # Generate a token checking if one does not already exist in the database.\n        def remember_token #:nodoc:\n          loop do\n            token = Devise.friendly_token\n            break token unless to_adapter.find_first({ remember_token: token })\n          end\n        end\n\n        Devise::Models.config(self, :remember_for, :extend_remember_period, :rememberable_options, :expire_all_remember_me_on_sign_out)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/timeoutable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/hooks/timeoutable'\n\nmodule Devise\n  module Models\n    # Timeoutable takes care of verifying whether a user session has already\n    # expired or not. When a session expires after the configured time, the user\n    # will be asked for credentials again, it means, they will be redirected\n    # to the sign in page.\n    #\n    # == Options\n    #\n    # Timeoutable adds the following options to +devise+:\n    #\n    #   * +timeout_in+: the interval to timeout the user session without activity.\n    #\n    # == Examples\n    #\n    #   user.timedout?(30.minutes.ago)\n    #\n    module Timeoutable\n      extend ActiveSupport::Concern\n\n      def self.required_fields(klass)\n        []\n      end\n\n      # Checks whether the user session has expired based on configured time.\n      def timedout?(last_access)\n        !timeout_in.nil? && last_access && last_access <= timeout_in.ago\n      end\n\n      def timeout_in\n        self.class.timeout_in\n      end\n\n      private\n\n      module ClassMethods\n        Devise::Models.config(self, :timeout_in)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/trackable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/hooks/trackable'\n\nmodule Devise\n  module Models\n    # Track information about your user sign in. It tracks the following columns:\n    #\n    # * sign_in_count      - Increased every time a sign in is made (by form, openid, oauth)\n    # * current_sign_in_at - A timestamp updated when the user signs in\n    # * last_sign_in_at    - Holds the timestamp of the previous sign in\n    # * current_sign_in_ip - The remote ip updated when the user sign in\n    # * last_sign_in_ip    - Holds the remote ip of the previous sign in\n    #\n    module Trackable\n      def self.required_fields(klass)\n        [:current_sign_in_at, :current_sign_in_ip, :last_sign_in_at, :last_sign_in_ip, :sign_in_count]\n      end\n\n      def update_tracked_fields(request)\n        old_current, new_current = self.current_sign_in_at, Time.now.utc\n        self.last_sign_in_at     = old_current || new_current\n        self.current_sign_in_at  = new_current\n\n        old_current, new_current = self.current_sign_in_ip, extract_ip_from(request)\n        self.last_sign_in_ip     = old_current || new_current\n        self.current_sign_in_ip  = new_current\n\n        self.sign_in_count ||= 0\n        self.sign_in_count += 1\n      end\n\n      def update_tracked_fields!(request)\n        # We have to check if the user is already persisted before running\n        # `save` here because invalid users can be saved if we don't.\n        # See https://github.com/heartcombo/devise/issues/4673 for more details.\n        return if new_record?\n\n        update_tracked_fields(request)\n        save(validate: false)\n      end\n\n      protected\n\n      def extract_ip_from(request)\n        request.remote_ip\n      end\n\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models/validatable.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Models\n    # Validatable creates all needed validations for a user email and password.\n    # It's optional, given you may want to create the validations by yourself.\n    # Automatically validate if the email is present, unique and its format is\n    # valid. Also tests presence of password, confirmation and length.\n    #\n    # == Options\n    #\n    # Validatable adds the following options to +devise+:\n    #\n    #   * +email_regexp+: the regular expression used to validate e-mails;\n    #   * +password_length+: a range expressing password length. Defaults to 6..128.\n    #\n    # Since +password_length+ is applied in a proc within `validates_length_of` it can be overridden\n    # at runtime.\n    module Validatable\n      # All validations used by this module.\n      VALIDATIONS = [:validates_presence_of, :validates_uniqueness_of, :validates_format_of,\n                     :validates_confirmation_of, :validates_length_of].freeze\n\n      def self.required_fields(klass)\n        []\n      end\n\n      def self.included(base)\n        base.extend ClassMethods\n        assert_validations_api!(base)\n\n        base.class_eval do\n          validates_presence_of   :email, if: :email_required?\n          validates_uniqueness_of :email, allow_blank: true, case_sensitive: true, if: :devise_will_save_change_to_email?\n          validates_format_of     :email, with: email_regexp, allow_blank: true, if: :devise_will_save_change_to_email?\n\n          validates_presence_of     :password, if: :password_required?\n          validates_confirmation_of :password, if: :password_required?\n          validates_length_of       :password, minimum: proc { password_length.min }, maximum: proc { password_length.max }, allow_blank: true\n        end\n      end\n\n      def self.assert_validations_api!(base) #:nodoc:\n        unavailable_validations = VALIDATIONS.select { |v| !base.respond_to?(v) }\n\n        unless unavailable_validations.empty?\n          raise \"Could not use :validatable module since #{base} does not respond \" \\\n                \"to the following methods: #{unavailable_validations.to_sentence}.\"\n        end\n      end\n\n    protected\n\n      # Checks whether a password is needed or not. For validations only.\n      # Passwords are always required if it's a new record, or if the password\n      # or confirmation are being set somewhere.\n      def password_required?\n        !persisted? || !password.nil? || !password_confirmation.nil?\n      end\n\n      def email_required?\n        true\n      end\n\n      module ClassMethods\n        Devise::Models.config(self, :email_regexp, :password_length)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/models.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Models\n    class MissingAttribute < StandardError\n      def initialize(attributes)\n        @attributes = attributes\n      end\n\n      def message\n        \"The following attribute(s) is (are) missing on your model: #{@attributes.join(\", \")}\"\n      end\n    end\n\n    # Creates configuration values for Devise and for the given module.\n    #\n    #   Devise::Models.config(Devise::Models::DatabaseAuthenticatable, :stretches)\n    #\n    # The line above creates:\n    #\n    #   1) An accessor called Devise.stretches, which value is used by default;\n    #\n    #   2) Some class methods for your model Model.stretches and Model.stretches=\n    #      which have higher priority than Devise.stretches;\n    #\n    #   3) And an instance method stretches.\n    #\n    # To add the class methods you need to have a module ClassMethods defined\n    # inside the given class.\n    #\n    def self.config(mod, *accessors) #:nodoc:\n      class << mod; attr_accessor :available_configs; end\n      mod.available_configs = accessors\n\n      accessors.each do |accessor|\n        mod.class_eval <<-METHOD, __FILE__, __LINE__ + 1\n          def #{accessor}\n            if defined?(@#{accessor})\n              @#{accessor}\n            elsif superclass.respond_to?(:#{accessor})\n              superclass.#{accessor}\n            else\n              Devise.#{accessor}\n            end\n          end\n\n          def #{accessor}=(value)\n            @#{accessor} = value\n          end\n        METHOD\n      end\n    end\n\n    def self.check_fields!(klass)\n      failed_attributes = []\n      instance = klass.new\n\n      klass.devise_modules.each do |mod|\n        constant = const_get(mod.to_s.classify)\n\n        constant.required_fields(klass).each do |field|\n          failed_attributes << field unless instance.respond_to?(field)\n        end\n      end\n\n      if failed_attributes.any?\n        fail Devise::Models::MissingAttribute.new(failed_attributes)\n      end\n    end\n\n    # Include the chosen devise modules in your model:\n    #\n    #   devise :database_authenticatable, :confirmable, :recoverable\n    #\n    # You can also give any of the devise configuration values in form of a hash,\n    # with specific values for this model. Please check your Devise initializer\n    # for a complete description on those values.\n    #\n    def devise(*modules)\n      options = modules.extract_options!.dup\n\n      selected_modules = modules.map(&:to_sym).uniq.sort_by do |s|\n        Devise::ALL.index(s) || -1  # follow Devise::ALL order\n      end\n\n      devise_modules_hook! do\n        include Devise::Orm\n        include Devise::Models::Authenticatable\n\n        selected_modules.each do |m|\n          mod = Devise::Models.const_get(m.to_s.classify)\n\n          if mod.const_defined?(\"ClassMethods\")\n            class_mod = mod.const_get(\"ClassMethods\")\n            extend class_mod\n\n            if class_mod.respond_to?(:available_configs)\n              available_configs = class_mod.available_configs\n              available_configs.each do |config|\n                next unless options.key?(config)\n                send(:\"#{config}=\", options.delete(config))\n              end\n            end\n          end\n\n          include mod\n        end\n\n        self.devise_modules |= selected_modules\n        options.each { |key, value| send(:\"#{key}=\", value) }\n      end\n    end\n\n    # The hook which is called inside devise.\n    # So your ORM can include devise compatibility stuff.\n    def devise_modules_hook!\n      yield\n    end\n  end\nend\n\nrequire 'devise/models/authenticatable'\n"
  },
  {
    "path": "lib/devise/modules.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'active_support/core_ext/object/with_options'\n\nDevise.with_options model: true do |d|\n  # Strategies first\n  d.with_options strategy: true do |s|\n    routes = [nil, :new, :destroy]\n    s.add_module :database_authenticatable, controller: :sessions, route: { session: routes }\n    s.add_module :rememberable, no_input: true\n  end\n\n  # Other authentications\n  d.add_module :omniauthable, controller: :omniauth_callbacks,  route: :omniauth_callback\n\n  # Misc after\n  routes = [nil, :new, :edit]\n  d.add_module :recoverable,  controller: :passwords,     route: { password: routes }\n  d.add_module :registerable, controller: :registrations, route: { registration: (routes << :cancel) }\n  d.add_module :validatable\n\n  # The ones which can sign out after\n  routes = [nil, :new]\n  d.add_module :confirmable,  controller: :confirmations, route: { confirmation: routes }\n  d.add_module :lockable,     controller: :unlocks,       route: { unlock: routes }\n  d.add_module :timeoutable\n\n  # Stats for last, so we make sure the user is really signed in\n  d.add_module :trackable\nend\n"
  },
  {
    "path": "lib/devise/omniauth/config.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module OmniAuth\n    class StrategyNotFound < NameError\n      def initialize(strategy)\n        @strategy = strategy\n        super(\"Could not find a strategy with name `#{strategy}'. \" \\\n          \"Please ensure it is required or explicitly set it using the :strategy_class option.\")\n      end\n    end\n\n    class Config\n      attr_accessor :strategy\n      attr_reader :args, :options, :provider, :strategy_name\n\n      def initialize(provider, args)\n        @provider       = provider\n        @args           = args\n        @options        = @args.last.is_a?(Hash) ? @args.last : {}\n        @strategy       = nil\n        @strategy_name  = options[:name] || @provider\n        @strategy_class = options.delete(:strategy_class)\n      end\n\n      def strategy_class\n        @strategy_class ||= find_strategy || autoload_strategy\n      end\n\n      def find_strategy\n        ::OmniAuth.strategies.find do |strategy_class|\n          strategy_class.to_s =~ /#{::OmniAuth::Utils.camelize(strategy_name)}$/ ||\n            strategy_class.default_options[:name] == strategy_name\n        end\n      end\n\n      def autoload_strategy\n        name = ::OmniAuth::Utils.camelize(provider.to_s)\n        if ::OmniAuth::Strategies.const_defined?(name)\n          ::OmniAuth::Strategies.const_get(name)\n        else\n          raise StrategyNotFound, name\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/omniauth/url_helpers.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module OmniAuth\n    module UrlHelpers\n      def omniauth_authorize_path(resource_or_scope, provider, *args)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        _devise_route_context.send(\"#{scope}_#{provider}_omniauth_authorize_path\", *args)\n      end\n\n      def omniauth_authorize_url(resource_or_scope, provider, *args)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        _devise_route_context.send(\"#{scope}_#{provider}_omniauth_authorize_url\", *args)\n      end\n\n      def omniauth_callback_path(resource_or_scope, provider, *args)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        _devise_route_context.send(\"#{scope}_#{provider}_omniauth_callback_path\", *args)\n      end\n\n      def omniauth_callback_url(resource_or_scope, provider, *args)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        _devise_route_context.send(\"#{scope}_#{provider}_omniauth_callback_url\", *args)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/omniauth.rb",
    "content": "# frozen_string_literal: true\n\nbegin\n  gem \"omniauth\", \">= 1.0.0\"\n\n  require \"omniauth\"\nrescue LoadError\n  warn \"Could not load 'omniauth'. Please ensure you have the omniauth gem >= 1.0.0 installed and listed in your Gemfile.\"\n  raise\nend\n\n# Clean up the default path_prefix. It will be automatically set by Devise.\nOmniAuth.config.path_prefix = nil\n\nOmniAuth.config.on_failure = Proc.new do |env|\n  env['devise.mapping'] = Devise::Mapping.find_by_path!(env['PATH_INFO'], :path)\n  controller_name  = ActiveSupport::Inflector.camelize(env['devise.mapping'].controllers[:omniauth_callbacks])\n  controller_klass = ActiveSupport::Inflector.constantize(\"#{controller_name}Controller\")\n  controller_klass.action(:failure).call(env)\nend\n\nmodule Devise\n  module OmniAuth\n    autoload :Config,      \"devise/omniauth/config\"\n    autoload :UrlHelpers,  \"devise/omniauth/url_helpers\"\n  end\nend\n"
  },
  {
    "path": "lib/devise/orm/active_record.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'orm_adapter/adapters/active_record'\n\nActiveSupport.on_load(:active_record) do\n  extend Devise::Models\nend\n"
  },
  {
    "path": "lib/devise/orm/mongoid.rb",
    "content": "# frozen_string_literal: true\n\nActiveSupport.on_load(:mongoid) do\n  require 'orm_adapter/adapters/mongoid'\n\n  Mongoid::Document::ClassMethods.send :include, Devise::Models\nend\n"
  },
  {
    "path": "lib/devise/orm.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Orm # :nodoc:\n    def self.active_record?(model)\n      defined?(ActiveRecord) && model < ActiveRecord::Base\n    end\n\n    def self.included(model)\n      if Devise::Orm.active_record?(model)\n        model.include DirtyTrackingActiveRecordMethods\n      else\n        model.include DirtyTrackingMongoidMethods\n      end\n    end\n\n    module DirtyTrackingActiveRecordMethods\n      def devise_email_before_last_save\n        email_before_last_save\n      end\n\n      def devise_email_in_database\n        email_in_database\n      end\n\n      def devise_saved_change_to_email?\n        saved_change_to_email?\n      end\n\n      def devise_saved_change_to_encrypted_password?\n        saved_change_to_encrypted_password?\n      end\n\n      def devise_will_save_change_to_email?\n        will_save_change_to_email?\n      end\n\n      def devise_unconfirmed_email_will_change!\n        unconfirmed_email_will_change!\n      end\n\n      def devise_respond_to_and_will_save_change_to_attribute?(attribute)\n        respond_to?(\"will_save_change_to_#{attribute}?\") && send(\"will_save_change_to_#{attribute}?\")\n      end\n    end\n\n    module DirtyTrackingMongoidMethods\n      def devise_email_before_last_save\n        respond_to?(:email_previously_was) ? email_previously_was : email_was\n      end\n\n      def devise_email_in_database\n        email_was\n      end\n\n      def devise_saved_change_to_email?\n        respond_to?(:email_previously_changed?) ? email_previously_changed? : email_changed?\n      end\n\n      def devise_saved_change_to_encrypted_password?\n        respond_to?(:encrypted_password_previously_changed?) ? encrypted_password_previously_changed? : encrypted_password_changed?\n      end\n\n      def devise_will_save_change_to_email?\n        email_changed?\n      end\n\n      def devise_unconfirmed_email_will_change!\n        # Mongoid's will_change! doesn't force unchanged attributes into updates,\n        # so we override changed_attributes to make it see a difference.\n        unconfirmed_email_will_change!\n        changed_attributes[\"unconfirmed_email\"] = nil\n      end\n\n      def devise_respond_to_and_will_save_change_to_attribute?(attribute)\n        respond_to?(\"#{attribute}_changed?\") && send(\"#{attribute}_changed?\")\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/parameter_filter.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  class ParameterFilter\n    def initialize(case_insensitive_keys, strip_whitespace_keys)\n      @case_insensitive_keys = case_insensitive_keys || []\n      @strip_whitespace_keys = strip_whitespace_keys || []\n    end\n\n    def filter(conditions)\n      conditions = stringify_params(conditions.dup)\n\n      conditions.merge!(filtered_hash_by_method_for_given_keys(conditions.dup, :downcase, @case_insensitive_keys))\n      conditions.merge!(filtered_hash_by_method_for_given_keys(conditions.dup, :strip, @strip_whitespace_keys))\n\n      conditions\n    end\n\n    def filtered_hash_by_method_for_given_keys(conditions, method, condition_keys)\n      condition_keys.each do |k|\n        next unless conditions.key?(k)\n\n        value = conditions[k]\n        conditions[k] = value.send(method) if value.respond_to?(method)\n      end\n\n      conditions\n    end\n\n    # Force keys to be string to avoid injection on mongoid related database.\n    def stringify_params(conditions)\n      return conditions unless conditions.is_a?(Hash)\n      conditions.each do |k, v|\n        conditions[k] = v.to_s if param_requires_string_conversion?(v)\n      end\n    end\n\n    private\n\n    def param_requires_string_conversion?(value)\n      true\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/parameter_sanitizer.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  # The +ParameterSanitizer+ deals with permitting specific parameters values\n  # for each +Devise+ scope in the application.\n  #\n  # The sanitizer knows about Devise default parameters (like +password+ and\n  # +password_confirmation+ for the `RegistrationsController`), and you can\n  # extend or change the permitted parameters list on your controllers.\n  #\n  # === Permitting new parameters\n  #\n  # You can add new parameters to the permitted list using the +permit+ method\n  # in a +before_action+ method, for instance.\n  #\n  #    class ApplicationController < ActionController::Base\n  #      before_action :configure_permitted_parameters, if: :devise_controller?\n  #\n  #      protected\n  #\n  #      def configure_permitted_parameters\n  #        # Permit the `subscribe_newsletter` parameter along with the other\n  #        # sign up parameters.\n  #        devise_parameter_sanitizer.permit(:sign_up, keys: [:subscribe_newsletter])\n  #      end\n  #    end\n  #\n  # Using a block yields an +ActionController::Parameters+ object so you can\n  # permit nested parameters and have more control over how the parameters are\n  # permitted in your controller.\n  #\n  #    def configure_permitted_parameters\n  #      devise_parameter_sanitizer.permit(:sign_up) do |user|\n  #        user.permit(newsletter_preferences: [])\n  #      end\n  #    end\n  class ParameterSanitizer\n    DEFAULT_PERMITTED_ATTRIBUTES = {\n      sign_in: [:password, :remember_me],\n      sign_up: [:password, :password_confirmation],\n      account_update: [:password, :password_confirmation, :current_password]\n    }\n\n    def initialize(resource_class, resource_name, params)\n      @auth_keys      = extract_auth_keys(resource_class)\n      @params         = params\n      @resource_name  = resource_name\n      @permitted      = {}\n\n      DEFAULT_PERMITTED_ATTRIBUTES.each_pair do |action, keys|\n        permit(action, keys: keys)\n      end\n    end\n\n    # Sanitize the parameters for a specific +action+.\n    #\n    # === Arguments\n    #\n    # * +action+ - A +Symbol+ with the action that the controller is\n    #   performing, like +sign_up+, +sign_in+, etc.\n    #\n    # === Examples\n    #\n    #    # Inside the `RegistrationsController#create` action.\n    #    resource = build_resource(devise_parameter_sanitizer.sanitize(:sign_up))\n    #    resource.save\n    #\n    # Returns an +ActiveSupport::HashWithIndifferentAccess+ with the permitted\n    # attributes.\n    def sanitize(action)\n      permissions = @permitted[action]\n\n      if permissions.respond_to?(:call)\n        cast_to_hash permissions.call(default_params)\n      elsif permissions.present?\n        cast_to_hash permit_keys(default_params, permissions)\n      else\n        unknown_action!(action)\n      end\n    end\n\n    # Add or remove new parameters to the permitted list of an +action+.\n    #\n    # === Arguments\n    #\n    # * +action+ - A +Symbol+ with the action that the controller is\n    #   performing, like +sign_up+, +sign_in+, etc.\n    # * +keys:+     - An +Array+ of keys that also should be permitted.\n    # * +except:+   - An +Array+ of keys that shouldn't be permitted.\n    # * +block+     - A block that should be used to permit the action\n    #   parameters instead of the +Array+ based approach. The block will be\n    #   called with an +ActionController::Parameters+ instance.\n    #\n    # === Examples\n    #\n    #   # Adding new parameters to be permitted in the `sign_up` action.\n    #   devise_parameter_sanitizer.permit(:sign_up, keys: [:subscribe_newsletter])\n    #\n    #   # Removing the `password` parameter from the `account_update` action.\n    #   devise_parameter_sanitizer.permit(:account_update, except: [:password])\n    #\n    #   # Using the block form to completely override how we permit the\n    #   # parameters for the `sign_up` action.\n    #   devise_parameter_sanitizer.permit(:sign_up) do |user|\n    #     user.permit(:email, :password, :password_confirmation)\n    #   end\n    #\n    #\n    # Returns nothing.\n    def permit(action, keys: nil, except: nil, &block)\n      if block_given?\n        @permitted[action] = block\n      end\n\n      if keys.present?\n        @permitted[action] ||= @auth_keys.dup\n        @permitted[action].concat(keys)\n      end\n\n      if except.present?\n        @permitted[action] ||= @auth_keys.dup\n        @permitted[action] = @permitted[action] - except\n      end\n    end\n\n    private\n\n    # Cast a sanitized +ActionController::Parameters+ to a +HashWithIndifferentAccess+\n    # that can be used elsewhere.\n    #\n    # Returns an +ActiveSupport::HashWithIndifferentAccess+.\n    def cast_to_hash(params)\n      params && params.to_h\n    end\n\n    def default_params\n      if hashable_resource_params?\n        @params.fetch(@resource_name)\n      else\n        empty_params\n      end\n    end\n\n    def hashable_resource_params?\n      @params[@resource_name].respond_to?(:permit)\n    end\n\n    def empty_params\n      ActionController::Parameters.new({})\n    end\n\n    def permit_keys(parameters, keys)\n      parameters.permit(*keys)\n    end\n\n    def extract_auth_keys(klass)\n      auth_keys = klass.authentication_keys\n\n      auth_keys.respond_to?(:keys) ? auth_keys.keys : auth_keys\n    end\n\n    def unknown_action!(action)\n      raise NotImplementedError, <<-MESSAGE.strip_heredoc\n        \"Devise doesn't know how to sanitize parameters for '#{action}'\".\n        If you want to define a new set of parameters to be sanitized use the\n        `permit` method first:\n\n          devise_parameter_sanitizer.permit(:#{action}, keys: [:param1, :param2, :param3])\n      MESSAGE\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/rails/routes.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"active_support/core_ext/object/try\"\nrequire \"active_support/core_ext/hash/slice\"\n\nmodule Devise\n  module RouteSet\n    def finalize!\n      result = super\n      @devise_finalized ||= begin\n        if Devise.router_name.nil? && defined?(@devise_finalized) && self != Rails.application.try(:routes)\n          warn \"[DEVISE] We have detected that you are using devise_for inside engine routes. \" \\\n            \"In this case, you probably want to set Devise.router_name = MOUNT_POINT, where \"   \\\n            \"MOUNT_POINT is a symbol representing where this engine will be mounted at. For \"   \\\n            \"now Devise will default the mount point to :main_app. You can explicitly set it\"   \\\n            \" to :main_app as well in case you want to keep the current behavior.\"\n        end\n\n        Devise.configure_warden!\n        Devise.regenerate_helpers!\n        true\n      end\n      result\n    end\n  end\nend\n\nmodule ActionDispatch::Routing\n  class RouteSet #:nodoc:\n    # Ensure Devise modules are included only after loading routes, because we\n    # need devise_for mappings already declared to create filters and helpers.\n    prepend Devise::RouteSet\n  end\n\n  class Mapper\n    # Includes devise_for method for routes. This method is responsible to\n    # generate all needed routes for devise, based on what modules you have\n    # defined in your model.\n    #\n    # ==== Examples\n    #\n    # Let's say you have an User model configured to use authenticatable,\n    # confirmable and recoverable modules. After creating this inside your routes:\n    #\n    #   devise_for :users\n    #\n    # This method is going to look inside your User model and create the\n    # needed routes:\n    #\n    #  # Session routes for Authenticatable (default)\n    #       new_user_session GET    /users/sign_in                    {controller:\"devise/sessions\", action:\"new\"}\n    #           user_session POST   /users/sign_in                    {controller:\"devise/sessions\", action:\"create\"}\n    #   destroy_user_session DELETE /users/sign_out                   {controller:\"devise/sessions\", action:\"destroy\"}\n    #\n    #  # Password routes for Recoverable, if User model has :recoverable configured\n    #      new_user_password GET    /users/password/new(.:format)     {controller:\"devise/passwords\", action:\"new\"}\n    #     edit_user_password GET    /users/password/edit(.:format)    {controller:\"devise/passwords\", action:\"edit\"}\n    #          user_password PUT    /users/password(.:format)         {controller:\"devise/passwords\", action:\"update\"}\n    #                        POST   /users/password(.:format)         {controller:\"devise/passwords\", action:\"create\"}\n    #\n    #  # Confirmation routes for Confirmable, if User model has :confirmable configured\n    #  new_user_confirmation GET    /users/confirmation/new(.:format) {controller:\"devise/confirmations\", action:\"new\"}\n    #      user_confirmation GET    /users/confirmation(.:format)     {controller:\"devise/confirmations\", action:\"show\"}\n    #                        POST   /users/confirmation(.:format)     {controller:\"devise/confirmations\", action:\"create\"}\n    #\n    # ==== Routes integration\n    #\n    # +devise_for+ is meant to play nicely with other routes methods. For example,\n    # by calling +devise_for+ inside a namespace, it automatically nests your devise\n    # controllers:\n    #\n    #     namespace :publisher do\n    #       devise_for :account\n    #     end\n    #\n    # The snippet above will use publisher/sessions controller instead of devise/sessions\n    # controller. You can revert this change or configure it directly by passing the :module\n    # option described below to +devise_for+.\n    #\n    # Also note that when you use a namespace it will affect all the helpers and methods\n    # for controllers and views. For example, using the above setup you'll end with\n    # following methods: current_publisher_account, authenticate_publisher_account!,\n    # publisher_account_signed_in, etc.\n    #\n    # The only aspect not affect by the router configuration is the model name. The\n    # model name can be explicitly set via the :class_name option.\n    #\n    # ==== Options\n    #\n    # You can configure your routes with some options:\n    #\n    #  * class_name: set up a different class to be looked up by devise, if it cannot be\n    #    properly found by the route name.\n    #\n    #      devise_for :users, class_name: 'Account'\n    #\n    #  * path: allows you to set up path name that will be used, as rails routes does.\n    #    The following route configuration would set up your route as /accounts instead of /users:\n    #\n    #      devise_for :users, path: 'accounts'\n    #\n    #  * singular: set up the singular name for the given resource. This is used as the helper methods\n    #    names in controller (\"authenticate_#{singular}!\", \"#{singular}_signed_in?\", \"current_#{singular}\"\n    #    and \"#{singular}_session\"), as the scope name in routes and as the scope given to warden.\n    #\n    #      devise_for :admins, singular: :manager\n    #\n    #      devise_scope :manager do\n    #        ...\n    #      end\n    #\n    #      class ManagerController < ApplicationController\n    #        before_action authenticate_manager!\n    #\n    #        def show\n    #          @manager = current_manager\n    #          ...\n    #        end\n    #      end\n    #\n    #  * path_names: configure different path names to overwrite defaults :sign_in, :sign_out, :sign_up,\n    #    :password, :confirmation, :unlock.\n    #\n    #      devise_for :users, path_names: {\n    #        sign_in: 'login', sign_out: 'logout',\n    #        password: 'secret', confirmation: 'verification',\n    #        registration: 'register', edit: 'edit/profile'\n    #      }\n    #\n    #  * controllers: the controller which should be used. All routes by default points to Devise controllers.\n    #    However, if you want them to point to custom controller, you should do:\n    #\n    #      devise_for :users, controllers: { sessions: \"users/sessions\" }\n    #\n    #  * failure_app: a rack app which is invoked whenever there is a failure. Strings representing a given\n    #    are also allowed as parameter.\n    #\n    #  * sign_out_via: the HTTP method(s) accepted for the :sign_out action (default: :delete),\n    #    if you wish to restrict this to accept only :post or :delete requests you should do:\n    #\n    #      devise_for :users, sign_out_via: [:get, :post]\n    #\n    #    You need to make sure that your sign_out controls trigger a request with a matching HTTP method.\n    #\n    #  * module: the namespace to find controllers (default: \"devise\", thus\n    #    accessing devise/sessions, devise/registrations, and so on). If you want\n    #    to namespace all at once, use module:\n    #\n    #      devise_for :users, module: \"users\"\n    #\n    #  * skip: tell which controller you want to skip routes from being created.\n    #    It accepts :all as an option, meaning it will not generate any route at all:\n    #\n    #      devise_for :users, skip: :sessions\n    #\n    #  * only: the opposite of :skip, tell which controllers only to generate routes to:\n    #\n    #      devise_for :users, only: :sessions\n    #\n    #  * skip_helpers: skip generating Devise url helpers like new_session_path(@user).\n    #    This is useful to avoid conflicts with previous routes and is false by default.\n    #    It accepts true as option, meaning it will skip all the helpers for the controllers\n    #    given in :skip but it also accepts specific helpers to be skipped:\n    #\n    #      devise_for :users, skip: [:registrations, :confirmations], skip_helpers: true\n    #      devise_for :users, skip_helpers: [:registrations, :confirmations]\n    #\n    #  * format: include \"(.:format)\" in the generated routes? true by default, set to false to disable:\n    #\n    #      devise_for :users, format: false\n    #\n    #  * constraints: works the same as Rails' constraints\n    #\n    #  * defaults: works the same as Rails' defaults\n    #\n    #  * router_name: allows application level router name to be overwritten for the current scope\n    #\n    # ==== Scoping\n    #\n    # Following Rails 3 routes DSL, you can nest devise_for calls inside a scope:\n    #\n    #   scope \"/my\" do\n    #     devise_for :users\n    #   end\n    #\n    # However, since Devise uses the request path to retrieve the current user,\n    # this has one caveat: If you are using a dynamic segment, like so ...\n    #\n    #   scope \":locale\" do\n    #     devise_for :users\n    #   end\n    #\n    # you are required to configure default_url_options in your\n    # ApplicationController class, so Devise can pick it:\n    #\n    #   class ApplicationController < ActionController::Base\n    #     def self.default_url_options\n    #       { locale: I18n.locale }\n    #     end\n    #   end\n    #\n    # ==== Adding custom actions to override controllers\n    #\n    # You can pass a block to devise_for that will add any routes defined in the block to Devise's\n    # list of known actions.  This is important if you add a custom action to a controller that\n    # overrides an out of the box Devise controller.\n    # For example:\n    #\n    #    class RegistrationsController < Devise::RegistrationsController\n    #      def update\n    #         # do something different here\n    #      end\n    #\n    #      def deactivate\n    #        # not a standard action\n    #        # deactivate code here\n    #      end\n    #    end\n    #\n    # In order to get Devise to recognize the deactivate action, your devise_scope entry should look like this:\n    #\n    #     devise_scope :owner do\n    #       post \"deactivate\", to: \"registrations#deactivate\", as: \"deactivate_registration\"\n    #     end\n    #\n    def devise_for(*resources)\n      @devise_finalized = false\n      raise_no_secret_key unless Devise.secret_key\n      options = resources.extract_options!\n\n      options[:as]          ||= @scope[:as]     if @scope[:as].present?\n      options[:module]      ||= @scope[:module] if @scope[:module].present?\n      options[:path_prefix] ||= @scope[:path]   if @scope[:path].present?\n      options[:path_names]    = (@scope[:path_names] || {}).merge(options[:path_names] || {})\n      options[:constraints]   = (@scope[:constraints] || {}).merge(options[:constraints] || {})\n      options[:defaults]      = (@scope[:defaults] || {}).merge(options[:defaults] || {})\n      options[:options]       = @scope[:options] || {}\n\n      resources.map!(&:to_sym)\n\n      resources.each do |resource|\n        mapping = Devise.add_mapping(resource, options)\n\n        begin\n          raise_no_devise_method_error!(mapping.class_name) unless mapping.to.respond_to?(:devise)\n        rescue NameError => e\n          raise unless mapping.class_name == resource.to_s.classify\n          warn \"[WARNING] You provided devise_for #{resource.inspect} but there is \" \\\n            \"no model #{mapping.class_name} defined in your application\"\n          next\n        rescue NoMethodError => e\n          raise unless e.message.include?(\"undefined method `devise'\")\n          raise_no_devise_method_error!(mapping.class_name)\n        end\n\n        if options[:controllers] && options[:controllers][:omniauth_callbacks]\n          unless mapping.omniauthable?\n            raise ArgumentError, \"Mapping omniauth_callbacks on a resource that is not omniauthable\\n\" \\\n              \"Please add `devise :omniauthable` to the `#{mapping.class_name}` model\"\n          end\n        end\n\n        routes = mapping.used_routes\n\n        devise_scope mapping.name do\n          with_devise_exclusive_scope mapping.fullpath, mapping.name, options do\n            routes.each { |mod| send(\"devise_#{mod}\", mapping, mapping.controllers) }\n          end\n        end\n      end\n    end\n\n    # Allow you to add authentication request from the router.\n    # Takes an optional scope and block to provide constraints\n    # on the model instance itself.\n    #\n    #   authenticate do\n    #     resources :post\n    #   end\n    #\n    #   authenticate(:admin) do\n    #     resources :users\n    #   end\n    #\n    #   authenticate :user, lambda {|u| u.role == \"admin\"} do\n    #     root to: \"admin/dashboard#show\", as: :user_root\n    #   end\n    #\n    def authenticate(scope = nil, block = nil)\n      constraints_for(:authenticate!, scope, block) do\n        yield\n      end\n    end\n\n    # Allow you to route based on whether a scope is authenticated. You\n    # can optionally specify which scope and a block. The block accepts\n    # a model and allows extra constraints to be done on the instance.\n    #\n    #   authenticated :admin do\n    #     root to: 'admin/dashboard#show', as: :admin_root\n    #   end\n    #\n    #   authenticated do\n    #     root to: 'dashboard#show', as: :authenticated_root\n    #   end\n    #\n    #   authenticated :user, lambda {|u| u.role == \"admin\"} do\n    #     root to: \"admin/dashboard#show\", as: :user_root\n    #   end\n    #\n    #   root to: 'landing#show'\n    #\n    def authenticated(scope = nil, block = nil)\n      constraints_for(:authenticate?, scope, block) do\n        yield\n      end\n    end\n\n    # Allow you to route based on whether a scope is *not* authenticated.\n    # You can optionally specify which scope.\n    #\n    #   unauthenticated do\n    #     as :user do\n    #       root to: 'devise/registrations#new'\n    #     end\n    #   end\n    #\n    #   root to: 'dashboard#show'\n    #\n    def unauthenticated(scope = nil)\n      constraint = lambda do |request|\n        not request.env[\"warden\"].authenticate? scope: scope\n      end\n\n      constraints(constraint) do\n        yield\n      end\n    end\n\n    # Sets the devise scope to be used in the controller. If you have custom routes,\n    # you are required to call this method (also aliased as :as) in order to specify\n    # to which controller it is targeted.\n    #\n    #   as :user do\n    #     get \"sign_in\", to: \"devise/sessions#new\"\n    #   end\n    #\n    # Notice you cannot have two scopes mapping to the same URL. And remember, if\n    # you try to access a devise controller without specifying a scope, it will\n    # raise ActionNotFound error.\n    #\n    # Also be aware of that 'devise_scope' and 'as' use the singular form of the\n    # noun where other devise route commands expect the plural form. This would be a\n    # good and working example.\n    #\n    #  devise_scope :user do\n    #    get \"/some/route\" => \"some_devise_controller\"\n    #  end\n    #  devise_for :users\n    #\n    # Notice and be aware of the differences above between :user and :users\n    def devise_scope(scope)\n      constraint = lambda do |request|\n        request.env[\"devise.mapping\"] = Devise.mappings[scope]\n        true\n      end\n\n      constraints(constraint) do\n        yield\n      end\n    end\n    alias :as :devise_scope\n\n    protected\n\n      def devise_session(mapping, controllers) #:nodoc:\n        resource :session, only: [], controller: controllers[:sessions], path: \"\" do\n          get   :new,     path: mapping.path_names[:sign_in],  as: \"new\"\n          post  :create,  path: mapping.path_names[:sign_in]\n          match :destroy, path: mapping.path_names[:sign_out], as: \"destroy\", via: mapping.sign_out_via\n        end\n      end\n\n      def devise_password(mapping, controllers) #:nodoc:\n        resource :password, only: [:new, :create, :edit, :update],\n          path: mapping.path_names[:password], controller: controllers[:passwords]\n      end\n\n      def devise_confirmation(mapping, controllers) #:nodoc:\n        resource :confirmation, only: [:new, :create, :show],\n          path: mapping.path_names[:confirmation], controller: controllers[:confirmations]\n      end\n\n      def devise_unlock(mapping, controllers) #:nodoc:\n        if mapping.to.unlock_strategy_enabled?(:email)\n          resource :unlock, only: [:new, :create, :show],\n            path: mapping.path_names[:unlock], controller: controllers[:unlocks]\n        end\n      end\n\n      def devise_registration(mapping, controllers) #:nodoc:\n        path_names = {\n          new: mapping.path_names[:sign_up],\n          edit: mapping.path_names[:edit],\n          cancel: mapping.path_names[:cancel]\n        }\n\n        options = {\n          only: [:new, :create, :edit, :update, :destroy],\n          path: mapping.path_names[:registration],\n          path_names: path_names,\n          controller: controllers[:registrations]\n        }\n\n        resource :registration, **options do\n          get :cancel\n        end\n      end\n\n      def devise_omniauth_callback(mapping, controllers) #:nodoc:\n        if mapping.fullpath =~ /:[a-zA-Z_]/\n          raise <<-ERROR\nDevise does not support scoping OmniAuth callbacks under a dynamic segment\nand you have set #{mapping.fullpath.inspect}. You can work around by passing\n`skip: :omniauth_callbacks` to the `devise_for` call and extract omniauth\noptions to another `devise_for` call outside the scope. Here is an example:\n\n    devise_for :users, only: :omniauth_callbacks, controllers: {omniauth_callbacks: 'users/omniauth_callbacks'}\n\n    scope '/(:locale)', locale: /ru|en/ do\n      devise_for :users, skip: :omniauth_callbacks\n    end\nERROR\n        end\n        current_scope = @scope.dup\n        if @scope.respond_to? :new\n          @scope = @scope.new path: nil\n        else\n          @scope[:path] = nil\n        end\n        path_prefix = Devise.omniauth_path_prefix || \"/#{mapping.fullpath}/auth\".squeeze(\"/\")\n\n        set_omniauth_path_prefix!(path_prefix)\n\n        mapping.to.omniauth_providers.each do |provider|\n          match \"#{path_prefix}/#{provider}\",\n            to: \"#{controllers[:omniauth_callbacks]}#passthru\",\n            as: \"#{provider}_omniauth_authorize\",\n            via: OmniAuth.config.allowed_request_methods\n\n          match \"#{path_prefix}/#{provider}/callback\",\n            to: \"#{controllers[:omniauth_callbacks]}##{provider}\",\n            as: \"#{provider}_omniauth_callback\",\n            via: [:get, :post]\n        end\n      ensure\n        @scope = current_scope\n      end\n\n      def with_devise_exclusive_scope(new_path, new_as, options) #:nodoc:\n        current_scope = @scope.dup\n\n        exclusive = { as: new_as, path: new_path, module: nil }\n        exclusive.merge!(options.slice(:constraints, :format, :defaults, :options))\n\n        if @scope.respond_to? :new\n          @scope = @scope.new exclusive\n        else\n          exclusive.each_pair { |key, value| @scope[key] = value }\n        end\n        yield\n      ensure\n        @scope = current_scope\n      end\n\n      def constraints_for(method_to_apply, scope = nil, block = nil)\n        constraint = lambda do |request|\n          request.env['warden'].send(method_to_apply, scope: scope) &&\n            (block.nil? || block.call(request.env[\"warden\"].user(scope)))\n        end\n\n        constraints(constraint) do\n          yield\n        end\n      end\n\n      def set_omniauth_path_prefix!(path_prefix) #:nodoc:\n        if ::OmniAuth.config.path_prefix && ::OmniAuth.config.path_prefix != path_prefix\n          raise \"Wrong OmniAuth configuration. If you are getting this exception, it means that either:\\n\\n\" \\\n            \"1) You are manually setting OmniAuth.config.path_prefix and it doesn't match the Devise one\\n\" \\\n            \"2) You are setting :omniauthable in more than one model\\n\" \\\n            \"3) You changed your Devise routes/OmniAuth setting and haven't restarted your server\"\n        else\n          ::OmniAuth.config.path_prefix = path_prefix\n        end\n      end\n\n      def raise_no_secret_key #:nodoc:\n        raise <<-ERROR\nDevise.secret_key was not set. Please add the following to your Devise initializer:\n\n  config.secret_key = '#{SecureRandom.hex(64)}'\n\nPlease ensure you restarted your application after installing Devise or setting the key.\nERROR\n      end\n\n      def raise_no_devise_method_error!(klass) #:nodoc:\n        raise \"#{klass} does not respond to 'devise' method. This usually means you haven't \" \\\n          \"loaded your ORM file or it's being loaded too late. To fix it, be sure to require 'devise/orm/YOUR_ORM' \" \\\n          \"inside 'config/initializers/devise.rb' or before your application definition in 'config/application.rb'\"\n      end\n  end\nend\n"
  },
  {
    "path": "lib/devise/rails/warden_compat.rb",
    "content": "# frozen_string_literal: true\n\nmodule Warden::Mixins::Common\n  def request\n    @request ||= ActionDispatch::Request.new(env)\n  end\n\n  def reset_session!\n    request.reset_session\n  end\n\n  def cookies\n    request.cookie_jar\n  end\nend\n"
  },
  {
    "path": "lib/devise/rails.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/rails/routes'\nrequire 'devise/rails/warden_compat'\n\nmodule Devise\n  class Engine < ::Rails::Engine\n    config.devise = Devise\n\n    # Initialize Warden and copy its configurations.\n    config.app_middleware.use Warden::Manager do |config|\n      Devise.warden_config = config\n    end\n\n    # Force routes to be loaded if we are doing any eager load.\n    config.before_eager_load do |app|\n      app.reload_routes! if Devise.reload_routes\n    end\n\n    initializer \"devise.deprecator\" do |app|\n      app.deprecators[:devise] = Devise.deprecator if app.respond_to?(:deprecators)\n    end\n\n    initializer \"devise.url_helpers\" do\n      Devise.include_helpers(Devise::Controllers)\n    end\n\n    initializer \"devise.omniauth\", after: :load_config_initializers, before: :build_middleware_stack do |app|\n      Devise.omniauth_configs.each do |provider, config|\n        app.middleware.use config.strategy_class, *config.args do |strategy|\n          config.strategy = strategy\n        end\n      end\n\n      if Devise.omniauth_configs.any?\n        Devise.include_helpers(Devise::OmniAuth)\n      end\n    end\n\n    initializer \"devise.secret_key\" do |app|\n      Devise.secret_key ||= app.secret_key_base\n\n      Devise.token_generator ||=\n        if secret_key = Devise.secret_key\n          Devise::TokenGenerator.new(\n            ActiveSupport::CachingKeyGenerator.new(ActiveSupport::KeyGenerator.new(secret_key))\n          )\n        end\n    end\n\n    initializer \"devise.configure_zeitwerk\" do\n      if Rails.autoloaders.zeitwerk_enabled? && !defined?(ActionMailer)\n        Rails.autoloaders.main.ignore(\"#{root}/app/mailers/devise/mailer.rb\")\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/strategies/authenticatable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/strategies/base'\n\nmodule Devise\n  module Strategies\n    # This strategy should be used as basis for authentication strategies. It retrieves\n    # parameters both from params or from http authorization headers. See database_authenticatable\n    # for an example.\n    class Authenticatable < Base\n      attr_accessor :authentication_hash, :authentication_type, :password\n\n      def store?\n        super && !mapping.to.skip_session_storage.include?(authentication_type)\n      end\n\n      def valid?\n        valid_for_params_auth? || valid_for_http_auth?\n      end\n\n      # Override and set to false for things like OmniAuth that technically\n      # run through Authentication (user_set) very often, which would normally\n      # reset CSRF data in the session\n      def clean_up_csrf?\n        true\n      end\n\n    private\n\n      # Receives a resource and check if it is valid by calling valid_for_authentication?\n      # A block that will be triggered while validating can be optionally\n      # given as parameter. Check Devise::Models::Authenticatable.valid_for_authentication?\n      # for more information.\n      #\n      # In case the resource can't be validated, it will fail with the given\n      # unauthenticated_message.\n      def validate(resource, &block)\n        result = resource && resource.valid_for_authentication?(&block)\n\n        if result\n          true\n        else\n          if resource\n            fail!(resource.unauthenticated_message)\n          end\n          false\n        end\n      end\n\n      # Get values from params and set in the resource.\n      def remember_me(resource)\n        resource.remember_me = remember_me? if resource.respond_to?(:remember_me=)\n      end\n\n      # Should this resource be marked to be remembered?\n      def remember_me?\n        valid_params? && Devise::TRUE_VALUES.include?(params_auth_hash[:remember_me])\n      end\n\n      # Check if this is a valid strategy for http authentication by:\n      #\n      #   * Validating if the model allows http authentication;\n      #   * If any of the authorization headers were sent;\n      #   * If all authentication keys are present;\n      #\n      def valid_for_http_auth?\n        http_authenticatable? && request.authorization && with_authentication_hash(:http_auth, http_auth_hash)\n      end\n\n      # Check if this is a valid strategy for params authentication by:\n      #\n      #   * Validating if the model allows params authentication;\n      #   * If the request hits the sessions controller through POST;\n      #   * If the params[scope] returns a hash with credentials;\n      #   * If all authentication keys are present;\n      #\n      def valid_for_params_auth?\n        params_authenticatable? && valid_params_request? &&\n          valid_params? && with_authentication_hash(:params_auth, params_auth_hash)\n      end\n\n      # Check if the model accepts this strategy as http authenticatable.\n      def http_authenticatable?\n        mapping.to.http_authenticatable?(authenticatable_name)\n      end\n\n      # Check if the model accepts this strategy as params authenticatable.\n      def params_authenticatable?\n        mapping.to.params_authenticatable?(authenticatable_name)\n      end\n\n      # Extract the appropriate subhash for authentication from params.\n      def params_auth_hash\n        params[scope]\n      end\n\n      # Extract a hash with attributes:values from the http params.\n      def http_auth_hash\n        keys = [http_authentication_key, :password]\n        Hash[*keys.zip(decode_credentials).flatten]\n      end\n\n      # By default, a request is valid if the controller set the proper env variable.\n      def valid_params_request?\n        !!env[\"devise.allow_params_authentication\"]\n      end\n\n      # If the request is valid, finally check if params_auth_hash returns a hash.\n      def valid_params?\n        params_auth_hash.is_a?(Hash)\n      end\n\n      # Note: unlike `Model.valid_password?`, this method does not actually\n      # ensure that the password in the params matches the password stored in\n      # the database. It only checks if the password is *present*. Do not rely\n      # on this method for validating that a given password is correct.\n      def valid_password?\n        password.present?\n      end\n\n      # Helper to decode credentials from HTTP.\n      def decode_credentials\n        return [] unless request.authorization && request.authorization =~ /^Basic (.*)/mi\n        Base64.decode64($1).split(/:/, 2)\n      end\n\n      # Sets the authentication hash and the password from params_auth_hash or http_auth_hash.\n      def with_authentication_hash(auth_type, auth_values)\n        self.authentication_hash, self.authentication_type = {}, auth_type\n        self.password = auth_values[:password]\n\n        parse_authentication_key_values(auth_values, authentication_keys) &&\n        parse_authentication_key_values(request_values, request_keys)\n      end\n\n      def authentication_keys\n        @authentication_keys ||= mapping.to.authentication_keys\n      end\n\n      def http_authentication_key\n        @http_authentication_key ||= mapping.to.http_authentication_key || case authentication_keys\n          when Array then authentication_keys.first\n          when Hash then authentication_keys.keys.first\n        end\n      end\n\n      def request_keys\n        @request_keys ||= mapping.to.request_keys\n      end\n\n      def request_values\n        keys = request_keys.respond_to?(:keys) ? request_keys.keys : request_keys\n        values = keys.map { |k| self.request.send(k) }\n        Hash[keys.zip(values)]\n      end\n\n      def parse_authentication_key_values(hash, keys)\n        keys.each do |key, enforce|\n          value = hash[key].presence\n          if value\n            self.authentication_hash[key] = value\n          else\n            return false unless enforce == false\n          end\n        end\n        true\n      end\n\n      # Holds the authenticatable name for this class. Devise::Strategies::DatabaseAuthenticatable\n      # becomes simply :database.\n      def authenticatable_name\n        @authenticatable_name ||=\n          ActiveSupport::Inflector.underscore(self.class.name.split(\"::\").last).\n            sub(\"_authenticatable\", \"\").to_sym\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/strategies/base.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Strategies\n    # Base strategy for Devise. Responsible for verifying correct scope and mapping.\n    class Base < ::Warden::Strategies::Base\n      # Whenever CSRF cannot be verified, we turn off any kind of storage\n      def store?\n        !env[\"devise.skip_storage\"]\n      end\n\n      # Checks if a valid scope was given for devise and find mapping based on this scope.\n      def mapping\n        @mapping ||= begin\n          mapping = Devise.mappings[scope]\n          raise \"Could not find mapping for #{scope}\" unless mapping\n          mapping\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/strategies/database_authenticatable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/strategies/authenticatable'\n\nmodule Devise\n  module Strategies\n    # Default strategy for signing in a user, based on their email and password in the database.\n    class DatabaseAuthenticatable < Authenticatable\n      def authenticate!\n        resource  = password.present? && mapping.to.find_for_database_authentication(authentication_hash)\n        hashed = false\n\n        if validate(resource){ hashed = true; resource.valid_password?(password) }\n          remember_me(resource)\n          resource.after_database_authentication\n          success!(resource)\n        end\n\n        # In paranoid mode, hash the password even when a resource doesn't exist for the given authentication key.\n        # This is necessary to prevent enumeration attacks - e.g. the request is faster when a resource doesn't\n        # exist in the database if the password hashing algorithm is not called.\n        mapping.to.new.password = password if !hashed && Devise.paranoid\n        unless resource\n          Devise.paranoid ? fail(:invalid) : fail(:not_found_in_database)\n        end\n      end\n    end\n  end\nend\n\nWarden::Strategies.add(:database_authenticatable, Devise::Strategies::DatabaseAuthenticatable)\n"
  },
  {
    "path": "lib/devise/strategies/rememberable.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'devise/strategies/authenticatable'\n\nmodule Devise\n  module Strategies\n    # Remember the user through the remember token. This strategy is responsible\n    # to verify whether there is a cookie with the remember token, and to\n    # recreate the user from this cookie if it exists. Must be called *before*\n    # authenticatable.\n    class Rememberable < Authenticatable\n      # A valid strategy for rememberable needs a remember token in the cookies.\n      def valid?\n        @remember_cookie = nil\n        remember_cookie.present?\n      end\n\n      # To authenticate a user we deserialize the cookie and attempt finding\n      # the record in the database. If the attempt fails, we pass to another\n      # strategy handle the authentication.\n      def authenticate!\n        resource = mapping.to.serialize_from_cookie(*remember_cookie)\n\n        unless resource\n          cookies.delete(remember_key)\n          return pass\n        end\n\n        if validate(resource)\n          remember_me(resource) if extend_remember_me?(resource)\n          resource.after_remembered\n          success!(resource)\n        end\n      end\n\n      # No need to clean up the CSRF when using rememberable.\n      # In fact, cleaning it up here would be a bug because\n      # rememberable is triggered on GET requests which means\n      # we would render a page on first access with all csrf\n      # tokens expired.\n      def clean_up_csrf?\n        false\n      end\n\n    private\n\n      def extend_remember_me?(resource)\n        resource.respond_to?(:extend_remember_period) && resource.extend_remember_period\n      end\n\n      def remember_me?\n        true\n      end\n\n      def remember_key\n        mapping.to.rememberable_options.fetch(:key, \"remember_#{scope}_token\")\n      end\n\n      def remember_cookie\n        @remember_cookie ||= cookies.signed[remember_key]\n      end\n\n    end\n  end\nend\n\nWarden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)\n"
  },
  {
    "path": "lib/devise/test/controller_helpers.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Test\n    # `Devise::Test::ControllerHelpers` provides a facility to test controllers\n    # in isolation when using `ActionController::TestCase` allowing you to\n    # quickly sign_in or sign_out a user. Do not use\n    # `Devise::Test::ControllerHelpers` in integration tests.\n    #\n    # Examples\n    #\n    #  class PostsTest < ActionController::TestCase\n    #    include Devise::Test::ControllerHelpers\n    #\n    #    test 'authenticated users can GET index' do\n    #      sign_in users(:bob)\n    #\n    #      get :index\n    #      assert_response :success\n    #    end\n    #  end\n    #\n    # Important: you should not test Warden specific behavior (like callbacks)\n    # using `Devise::Test::ControllerHelpers` since it is a stub of the actual\n    # behavior. Such callbacks should be tested in your integration suite instead.\n    module ControllerHelpers\n      extend ActiveSupport::Concern\n\n      included do\n        setup :setup_controller_for_warden, :warden\n      end\n\n      # Override process to consider warden.\n      def process(*)\n        _catch_warden { super }\n\n        @response\n      end\n\n      ruby2_keywords(:process) if respond_to?(:ruby2_keywords, true)\n\n      # We need to set up the environment variables and the response in the controller.\n      def setup_controller_for_warden #:nodoc:\n        @request.env['action_controller.instance'] = @controller\n      end\n\n      # Quick access to Warden::Proxy.\n      def warden #:nodoc:\n        @request.env['warden'] ||= begin\n          manager = Warden::Manager.new(nil) do |config|\n            config.merge! Devise.warden_config\n          end\n          Warden::Proxy.new(@request.env, manager)\n        end\n      end\n\n      # sign_in a given resource by storing its keys in the session.\n      # This method bypass any warden authentication callback.\n      #\n      # * +resource+ - The resource that should be authenticated\n      # * +scope+    - An optional +Symbol+ with the scope where the resource\n      #                should be signed in with.\n      # Examples:\n      #\n      # sign_in users(:alice)\n      # sign_in users(:alice), scope: :admin\n      def sign_in(resource, scope: nil)\n        scope ||= Devise::Mapping.find_scope!(resource)\n\n        warden.instance_variable_get(:@users).delete(scope)\n        warden.session_serializer.store(resource, scope)\n      end\n\n      # Sign out a given resource or scope by calling logout on Warden.\n      # This method bypass any warden logout callback.\n      #\n      # Examples:\n      #\n      #   sign_out :user     # sign_out(scope)\n      #   sign_out @user     # sign_out(resource)\n      #\n      def sign_out(resource_or_scope)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n        @controller.instance_variable_set(:\"@current_#{scope}\", nil)\n        user = warden.instance_variable_get(:@users).delete(scope)\n        warden.session_serializer.delete(scope, user)\n      end\n\n      protected\n\n      # Catch warden continuations and handle like the middleware would.\n      # Returns nil when interrupted, otherwise the normal result of the block.\n      def _catch_warden(&block)\n        result = catch(:warden, &block)\n\n        env = @controller.request.env\n\n        result ||= {}\n\n        # Set the response. In production, the rack result is returned\n        # from Warden::Manager#call, which the following is modelled on.\n        case result\n        when Array\n          if result.first == 401 && intercept_401?(env) # does this happen during testing?\n            _process_unauthenticated(env)\n          else\n            result\n          end\n        when Hash\n          _process_unauthenticated(env, result)\n        else\n          result\n        end\n      end\n\n      def _process_unauthenticated(env, options = {})\n        options[:action] ||= :unauthenticated\n        proxy = request.env['warden']\n        result = options[:result] || proxy.result\n\n        ret = case result\n        when :redirect\n          body = proxy.message || \"You are being redirected to #{proxy.headers['Location']}\"\n          [proxy.status, proxy.headers, [body]]\n        when :custom\n          proxy.custom_response\n        else\n          request.env[\"PATH_INFO\"] = \"/#{options[:action]}\"\n          request.env[\"warden.options\"] = options\n          Warden::Manager._run_callbacks(:before_failure, env, options)\n\n          status, headers, response = Devise.warden_config[:failure_app].call(env).to_a\n          @controller.response.headers.merge!(headers)\n          @controller.status = status\n          @controller.response_body = response.body\n          nil # causes process return @response\n        end\n\n        # ensure that the controller response is set up. In production, this is\n        # not necessary since warden returns the results to rack. However, at\n        # testing time, we want the response to be available to the testing\n        # framework to verify what would be returned to rack.\n        if ret.is_a?(Array)\n          status, headers, body = *ret\n          # ensure the controller response is set to our response.\n          @controller.response ||= @response\n          @response.status = status\n          @response.headers.merge!(headers)\n          @response.body = body\n        end\n\n        ret\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/test/integration_helpers.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  # Devise::Test::IntegrationHelpers is a helper module for facilitating\n  # authentication on Rails integration tests to bypass the required steps for\n  # signin in or signin out a record.\n  #\n  # Examples\n  #\n  #  class PostsTest < ActionDispatch::IntegrationTest\n  #    include Devise::Test::IntegrationHelpers\n  #\n  #    test 'authenticated users can see posts' do\n  #      sign_in users(:bob)\n  #\n  #      get '/posts'\n  #      assert_response :success\n  #    end\n  #  end\n  module Test\n    module IntegrationHelpers\n      def self.included(base)\n        base.class_eval do\n          include Warden::Test::Helpers\n\n          setup :setup_integration_for_devise\n          teardown :teardown_integration_for_devise\n        end\n      end\n\n      # Signs in a specific resource, mimicking a successful sign in\n      # operation through +Devise::SessionsController#create+.\n      #\n      # * +resource+ - The resource that should be authenticated\n      # * +scope+    - An optional +Symbol+ with the scope where the resource\n      #                should be signed in with.\n      def sign_in(resource, scope: nil)\n        scope ||= Devise::Mapping.find_scope!(resource)\n\n        login_as(resource, scope: scope)\n      end\n\n      # Signs out a specific scope from the session.\n      #\n      # * +resource_or_scope+ - The resource or scope that should be signed out.\n      def sign_out(resource_or_scope)\n        scope = Devise::Mapping.find_scope!(resource_or_scope)\n\n        logout scope\n      end\n\n      protected\n\n      def setup_integration_for_devise\n        Warden.test_mode!\n      end\n\n      def teardown_integration_for_devise\n        Warden.test_reset!\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/time_inflector.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"active_support/core_ext/module/delegation\"\n\nmodule Devise\n  class TimeInflector\n    include ActionView::Helpers::DateHelper\n\n    class << self\n      attr_reader :instance\n      delegate :time_ago_in_words, to: :instance\n    end\n\n    @instance = new\n  end\nend\n"
  },
  {
    "path": "lib/devise/token_generator.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'openssl'\n\nmodule Devise\n  class TokenGenerator\n    def initialize(key_generator, digest = \"SHA256\")\n      @key_generator = key_generator\n      @digest = digest\n    end\n\n    def digest(klass, column, value)\n      value.present? && OpenSSL::HMAC.hexdigest(@digest, key_for(column), value.to_s)\n    end\n\n    def generate(klass, column)\n      key = key_for(column)\n\n      loop do\n        raw = Devise.friendly_token\n        enc = OpenSSL::HMAC.hexdigest(@digest, key, raw)\n        break [raw, enc] unless klass.to_adapter.find_first({ column => enc })\n      end\n    end\n\n    private\n\n    def key_for(column)\n      @key_generator.generate_key(\"Devise #{column}\")\n    end\n  end\nend\n"
  },
  {
    "path": "lib/devise/version.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  VERSION = \"5.0.3\".freeze\nend\n"
  },
  {
    "path": "lib/devise.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'rails'\nrequire 'active_support/core_ext/numeric/time'\nrequire 'active_support/dependencies'\nrequire 'orm_adapter'\nrequire 'set'\nrequire 'securerandom'\nrequire 'responders'\n\nmodule Devise\n  autoload :Delegator,          'devise/delegator'\n  autoload :Encryptor,          'devise/encryptor'\n  autoload :FailureApp,         'devise/failure_app'\n  autoload :OmniAuth,           'devise/omniauth'\n  autoload :Orm,                'devise/orm'\n  autoload :ParameterFilter,    'devise/parameter_filter'\n  autoload :ParameterSanitizer, 'devise/parameter_sanitizer'\n  autoload :TimeInflector,      'devise/time_inflector'\n  autoload :TokenGenerator,     'devise/token_generator'\n\n  module Controllers\n    autoload :Helpers,        'devise/controllers/helpers'\n    autoload :Rememberable,   'devise/controllers/rememberable'\n    autoload :Responder,      'devise/controllers/responder'\n    autoload :ScopedViews,    'devise/controllers/scoped_views'\n    autoload :SignInOut,      'devise/controllers/sign_in_out'\n    autoload :StoreLocation,  'devise/controllers/store_location'\n    autoload :UrlHelpers,     'devise/controllers/url_helpers'\n  end\n\n  module Hooks\n    autoload :Proxy, 'devise/hooks/proxy'\n  end\n\n  module Mailers\n    autoload :Helpers, 'devise/mailers/helpers'\n  end\n\n  module Strategies\n    autoload :Base,            'devise/strategies/base'\n    autoload :Authenticatable, 'devise/strategies/authenticatable'\n  end\n\n  module Test\n    autoload :ControllerHelpers,  'devise/test/controller_helpers'\n    autoload :IntegrationHelpers, 'devise/test/integration_helpers'\n  end\n\n  # Constants which holds devise configuration for extensions. Those should\n  # not be modified by the \"end user\" (this is why they are constants).\n  ALL         = []\n  CONTROLLERS = {}\n  ROUTES      = {}\n  STRATEGIES  = {}\n  URL_HELPERS = {}\n\n  # Strategies that do not require user input.\n  NO_INPUT = []\n\n  # True values used to check params\n  TRUE_VALUES = [true, 1, '1', 'on', 'ON', 't', 'T', 'true', 'TRUE']\n\n  # Secret key used by the key generator\n  mattr_accessor :secret_key\n  @@secret_key = nil\n\n  # Custom domain or key for cookies. Not set by default\n  mattr_accessor :rememberable_options\n  @@rememberable_options = {}\n\n  # The number of times to hash the password.\n  mattr_accessor :stretches\n  @@stretches = 12\n\n  # The default key used when authenticating over http auth.\n  mattr_accessor :http_authentication_key\n  @@http_authentication_key = nil\n\n  # Keys used when authenticating a user.\n  mattr_accessor :authentication_keys\n  @@authentication_keys = [:email]\n\n  # Request keys used when authenticating a user.\n  mattr_accessor :request_keys\n  @@request_keys = []\n\n  # Keys that should be case-insensitive.\n  mattr_accessor :case_insensitive_keys\n  @@case_insensitive_keys = [:email]\n\n  # Keys that should have whitespace stripped.\n  mattr_accessor :strip_whitespace_keys\n  @@strip_whitespace_keys = [:email]\n\n  # If http authentication is enabled by default.\n  mattr_accessor :http_authenticatable\n  @@http_authenticatable = false\n\n  # If http headers should be returned for ajax requests. True by default.\n  mattr_accessor :http_authenticatable_on_xhr\n  @@http_authenticatable_on_xhr = true\n\n  # If params authenticatable is enabled by default.\n  mattr_accessor :params_authenticatable\n  @@params_authenticatable = true\n\n  # The realm used in Http Basic Authentication.\n  mattr_accessor :http_authentication_realm\n  @@http_authentication_realm = \"Application\"\n\n  # Email regex used to validate email formats. It asserts that there are no\n  # @ symbols or whitespaces in either the localpart or the domain, and that\n  # there is a single @ symbol separating the localpart and the domain.\n  mattr_accessor :email_regexp\n  @@email_regexp = /\\A[^@\\s]+@[^@\\s]+\\z/\n\n  # Range validation for password length\n  mattr_accessor :password_length\n  @@password_length = 6..128\n\n  # The time the user will be remembered without asking for credentials again.\n  mattr_accessor :remember_for\n  @@remember_for = 2.weeks\n\n  # If true, extends the user's remember period when remembered via cookie.\n  mattr_accessor :extend_remember_period\n  @@extend_remember_period = false\n\n  # If true, all the remember me tokens are going to be invalidated when the user signs out.\n  mattr_accessor :expire_all_remember_me_on_sign_out\n  @@expire_all_remember_me_on_sign_out = true\n\n  # Time interval you can access your account before confirming your account.\n  # nil - allows unconfirmed access for unlimited time\n  mattr_accessor :allow_unconfirmed_access_for\n  @@allow_unconfirmed_access_for = 0.days\n\n  # Time interval the confirmation token is valid. nil = unlimited\n  mattr_accessor :confirm_within\n  @@confirm_within = nil\n\n  # Defines which key will be used when confirming an account.\n  mattr_accessor :confirmation_keys\n  @@confirmation_keys = [:email]\n\n  # Defines if email should be reconfirmable.\n  mattr_accessor :reconfirmable\n  @@reconfirmable = true\n\n  # Time interval to timeout the user session without activity.\n  mattr_accessor :timeout_in\n  @@timeout_in = 30.minutes\n\n  # Used to hash the password. Please generate one with rails secret.\n  mattr_accessor :pepper\n  @@pepper = nil\n\n  # Used to send notification to the original user email when their email is changed.\n  mattr_accessor :send_email_changed_notification\n  @@send_email_changed_notification = false\n\n  # Used to enable sending notification to user when their password is changed.\n  mattr_accessor :send_password_change_notification\n  @@send_password_change_notification = false\n\n  # Scoped views. Since it relies on fallbacks to render default views, it's\n  # turned off by default.\n  mattr_accessor :scoped_views\n  @@scoped_views = false\n\n  # Defines which strategy can be used to lock an account.\n  # Values: :failed_attempts, :none\n  mattr_accessor :lock_strategy\n  @@lock_strategy = :failed_attempts\n\n  # Defines which key will be used when locking and unlocking an account\n  mattr_accessor :unlock_keys\n  @@unlock_keys = [:email]\n\n  # Defines which strategy can be used to unlock an account.\n  # Values: :email, :time, :both\n  mattr_accessor :unlock_strategy\n  @@unlock_strategy = :both\n\n  # Number of authentication tries before locking an account\n  mattr_accessor :maximum_attempts\n  @@maximum_attempts = 20\n\n  # Time interval to unlock the account if :time is defined as unlock_strategy.\n  mattr_accessor :unlock_in\n  @@unlock_in = 1.hour\n\n  # Defines which key will be used when recovering the password for an account\n  mattr_accessor :reset_password_keys\n  @@reset_password_keys = [:email]\n\n  # Time interval you can reset your password with a reset password key\n  mattr_accessor :reset_password_within\n  @@reset_password_within = 6.hours\n\n  # When set to false, resetting a password does not automatically sign in a user\n  mattr_accessor :sign_in_after_reset_password\n  @@sign_in_after_reset_password = true\n\n  # The default scope which is used by warden.\n  mattr_accessor :default_scope\n  @@default_scope = nil\n\n  # Address which sends Devise e-mails.\n  mattr_accessor :mailer_sender\n  @@mailer_sender = nil\n\n  # Skip session storage for the following strategies\n  mattr_accessor :skip_session_storage\n  @@skip_session_storage = [:http_auth]\n\n  # Which formats should be treated as navigational.\n  mattr_accessor :navigational_formats\n  @@navigational_formats = [\"*/*\", :html, :turbo_stream]\n\n  # The default responder used by Devise, used to customize status codes with:\n  #\n  #   `config.responder.error_status`\n  #   `config.responder.redirect_status`\n  #\n  # Can be replaced by a custom application responder.\n  mattr_accessor :responder\n  @@responder = Devise::Controllers::Responder\n\n  # When set to true, signing out a user signs out all other scopes.\n  mattr_accessor :sign_out_all_scopes\n  @@sign_out_all_scopes = true\n\n  # The default method used while signing out\n  mattr_accessor :sign_out_via\n  @@sign_out_via = :delete\n\n  # The parent controller all Devise controllers inherits from.\n  # Defaults to ApplicationController. This should be set early\n  # in the initialization process and should be set to a string.\n  mattr_accessor :parent_controller\n  @@parent_controller = \"ApplicationController\"\n\n  # The parent mailer all Devise mailers inherit from.\n  # Defaults to ActionMailer::Base. This should be set early\n  # in the initialization process and should be set to a string.\n  mattr_accessor :parent_mailer\n  @@parent_mailer = \"ActionMailer::Base\"\n\n  # The router Devise should use to generate routes. Defaults\n  # to :main_app. Should be overridden by engines in order\n  # to provide custom routes.\n  mattr_accessor :router_name\n  @@router_name = nil\n\n  # Set the OmniAuth path prefix so it can be overridden when\n  # Devise is used in a mountable engine\n  mattr_accessor :omniauth_path_prefix\n  @@omniauth_path_prefix = nil\n\n  # Set if we should clean up the CSRF Token on authentication\n  mattr_accessor :clean_up_csrf_token_on_authentication\n  @@clean_up_csrf_token_on_authentication = true\n\n  # When false, Devise will not attempt to reload routes on eager load.\n  # This can reduce the time taken to boot the app but if your application\n  # requires the Devise mappings to be loaded during boot time the application\n  # won't boot properly.\n  mattr_accessor :reload_routes\n  @@reload_routes = true\n\n  # PRIVATE CONFIGURATION\n\n  # Store scopes mappings.\n  @@mappings = {}\n  def self.mappings\n    # Starting from Rails 8.0, routes are lazy-loaded by default in test and development environments.\n    # However, Devise's mappings are built during the routes loading phase.\n    # To ensure it works correctly, we need to load the routes first before accessing @@mappings.\n    Rails.application.try(:reload_routes_unless_loaded)\n    @@mappings\n  end\n\n  # OmniAuth configurations.\n  mattr_reader :omniauth_configs\n  @@omniauth_configs = {}\n\n  # Define a set of modules that are called when a mapping is added.\n  mattr_reader :helpers\n  @@helpers = Set.new\n  @@helpers << Devise::Controllers::Helpers\n\n  # Private methods to interface with Warden.\n  mattr_accessor :warden_config\n  @@warden_config = nil\n  @@warden_config_blocks = []\n\n  # When true, enter in paranoid mode to avoid user enumeration.\n  mattr_accessor :paranoid\n  @@paranoid = false\n\n  # When true, warn user if they just used next-to-last attempt of authentication\n  mattr_accessor :last_attempt_warning\n  @@last_attempt_warning = true\n\n  # Stores the token generator\n  mattr_accessor :token_generator\n  @@token_generator = nil\n\n  # When set to false, changing a password does not automatically sign in a user\n  mattr_accessor :sign_in_after_change_password\n  @@sign_in_after_change_password = true\n\n  # Default way to set up Devise. Run rails generate devise_install to create\n  # a fresh initializer with all configuration values.\n  def self.setup\n    yield self\n  end\n\n  class Getter\n    def initialize(name)\n      @name = name\n    end\n\n    def get\n      # TODO: Remove AS::Dependencies usage when dropping support to Rails < 7.\n      if ActiveSupport::Dependencies.respond_to?(:constantize)\n        ActiveSupport::Dependencies.constantize(@name)\n      else\n        @name.constantize\n      end\n    end\n  end\n\n  def self.ref(arg)\n    # TODO: Remove AS::Dependencies usage when dropping support to Rails < 7.\n    if ActiveSupport::Dependencies.respond_to?(:reference)\n      ActiveSupport::Dependencies.reference(arg)\n    end\n    Getter.new(arg)\n  end\n\n  def self.available_router_name\n    router_name || :main_app\n  end\n\n  def self.omniauth_providers\n    omniauth_configs.keys\n  end\n\n  # Get the mailer class from the mailer reference object.\n  def self.mailer\n    @@mailer_ref.get\n  end\n\n  # Set the mailer reference object to access the mailer.\n  def self.mailer=(class_name)\n    @@mailer_ref = ref(class_name)\n  end\n  self.mailer = \"Devise::Mailer\"\n\n  # Small method that adds a mapping to Devise.\n  def self.add_mapping(resource, options)\n    mapping = Devise::Mapping.new(resource, options)\n    @@mappings[mapping.name] = mapping\n    @@default_scope ||= mapping.name\n    @@helpers.each { |h| h.define_helpers(mapping) }\n    mapping\n  end\n\n  # Register available devise modules. For the standard modules that Devise provides, this method is\n  # called from lib/devise/modules.rb. Third-party modules need to be added explicitly using this method.\n  #\n  # Note that adding a module using this method does not cause it to be used in the authentication\n  # process. That requires that the module be listed in the arguments passed to the 'devise' method\n  # in the model class definition.\n  #\n  # == Options:\n  #\n  #   +model+      - String representing the load path to a custom *model* for this module (to autoload.)\n  #   +controller+ - Symbol representing the name of an existing or custom *controller* for this module.\n  #   +route+      - Symbol representing the named *route* helper for this module.\n  #   +strategy+   - Symbol representing if this module got a custom *strategy*.\n  #   +insert_at+  - Integer representing the order in which this module's model will be included\n  #\n  # All values, except :model, accept also a boolean and will have the same name as the given module\n  # name.\n  #\n  # == Examples:\n  #\n  #   Devise.add_module(:party_module)\n  #   Devise.add_module(:party_module, strategy: true, controller: :sessions)\n  #   Devise.add_module(:party_module, model: 'party_module/model')\n  #   Devise.add_module(:party_module, insert_at: 0)\n  #\n  def self.add_module(module_name, options = {})\n    options.assert_valid_keys(:strategy, :model, :controller, :route, :no_input, :insert_at)\n\n    ALL.insert (options[:insert_at] || -1), module_name\n\n    if strategy = options[:strategy]\n      strategy = (strategy == true ? module_name : strategy)\n      STRATEGIES[module_name] = strategy\n    end\n\n    if controller = options[:controller]\n      controller = (controller == true ? module_name : controller)\n      CONTROLLERS[module_name] = controller\n    end\n\n    NO_INPUT << strategy if options[:no_input]\n\n    if route = options[:route]\n      case route\n      when TrueClass\n        key, value = module_name, []\n      when Symbol\n        key, value = route, []\n      when Hash\n        key, value = route.keys.first, route.values.flatten\n      else\n        raise ArgumentError, \":route should be true, a Symbol or a Hash\"\n      end\n\n      URL_HELPERS[key] ||= []\n      URL_HELPERS[key].concat(value)\n      URL_HELPERS[key].uniq!\n\n      ROUTES[module_name] = key\n    end\n\n    if options[:model]\n      path = (options[:model] == true ? \"devise/models/#{module_name}\" : options[:model])\n      camelized = ActiveSupport::Inflector.camelize(module_name.to_s)\n      Devise::Models.send(:autoload, camelized.to_sym, path)\n    end\n\n    Devise::Mapping.add_module module_name\n  end\n\n  # Sets warden configuration using a block that will be invoked on warden\n  # initialization.\n  #\n  #  Devise.setup do |config|\n  #    config.allow_unconfirmed_access_for = 2.days\n  #\n  #    config.warden do |warden_config|\n  #      # Configure warden to use other strategies, like oauth.\n  #      warden_config.oauth(:twitter)\n  #    end\n  #  end\n  def self.warden(&block)\n    @@warden_config_blocks << block\n  end\n\n  # Specify an OmniAuth provider.\n  #\n  #   config.omniauth :github, APP_ID, APP_SECRET\n  #\n  def self.omniauth(provider, *args)\n    config = Devise::OmniAuth::Config.new(provider, args)\n    @@omniauth_configs[config.strategy_name.to_sym] = config\n  end\n\n  # Include helpers in the given scope to AC and AV.\n  def self.include_helpers(scope)\n    ActiveSupport.on_load(:action_controller) do\n      include scope::Helpers if defined?(scope::Helpers)\n      include scope::UrlHelpers\n    end\n\n    ActiveSupport.on_load(:action_view) do\n      include scope::UrlHelpers\n    end\n  end\n\n  # Regenerates url helpers considering Devise.mapping\n  def self.regenerate_helpers!\n    Devise::Controllers::UrlHelpers.remove_helpers!\n    Devise::Controllers::UrlHelpers.generate_helpers!\n  end\n\n  # A method used internally to complete the setup of warden manager after routes are loaded.\n  # See lib/devise/rails/routes.rb - ActionDispatch::Routing::RouteSet#finalize_with_devise!\n  def self.configure_warden! #:nodoc:\n    @@warden_configured ||= begin\n      warden_config.failure_app   = Devise::Delegator.new\n      warden_config.default_scope = Devise.default_scope\n      warden_config.intercept_401 = false\n\n      Devise.mappings.each_value do |mapping|\n        warden_config.scope_defaults mapping.name, strategies: mapping.strategies\n\n        warden_config.serialize_into_session(mapping.name) do |record|\n          mapping.to.serialize_into_session(record)\n        end\n\n        warden_config.serialize_from_session(mapping.name) do |args|\n          mapping.to.serialize_from_session(*args)\n        end\n      end\n\n      @@warden_config_blocks.map { |block| block.call Devise.warden_config }\n      true\n    end\n  end\n\n  # Generate a friendly string randomly to be used as token.\n  # By default, length is 20 characters.\n  def self.friendly_token(length = 20)\n    # To calculate real characters, we must perform this operation.\n    # See SecureRandom.urlsafe_base64\n    rlength = (length * 3) / 4\n    SecureRandom.urlsafe_base64(rlength).tr('lIO0', 'sxyz')\n  end\n\n  # constant-time comparison algorithm to prevent timing attacks\n  def self.secure_compare(a, b)\n    return false if a.nil? || b.nil?\n    ActiveSupport::SecurityUtils.secure_compare(a, b)\n  end\n\n  def self.deprecator\n    @deprecator ||= ActiveSupport::Deprecation.new(\"5.0\", \"Devise\")\n  end\nend\n\nrequire 'warden'\nrequire 'devise/mapping'\nrequire 'devise/models'\nrequire 'devise/modules'\nrequire 'devise/rails'\n"
  },
  {
    "path": "lib/generators/active_record/devise_generator.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'rails/generators/active_record'\nrequire 'generators/devise/orm_helpers'\n\nmodule ActiveRecord\n  module Generators\n    class DeviseGenerator < Base\n      argument :attributes, type: :array, default: [], banner: \"field:type field:type\"\n\n      class_option :primary_key_type, type: :string, desc: \"The type for primary key\"\n\n      include Devise::Generators::OrmHelpers\n      source_root File.expand_path(\"../templates\", __FILE__)\n\n      def copy_devise_migration\n        if (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?(table_name))\n          migration_template \"migration_existing.rb\", \"#{migration_path}/add_devise_to_#{table_name}.rb\", migration_version: migration_version\n        else\n          migration_template \"migration.rb\", \"#{migration_path}/devise_create_#{table_name}.rb\", migration_version: migration_version\n        end\n      end\n\n      def generate_model\n        invoke \"active_record:model\", [name], migration: false unless model_exists? && behavior == :invoke\n      end\n\n      def inject_devise_content\n        content = model_contents\n\n        class_path = if namespaced?\n          class_name.to_s.split(\"::\")\n        else\n          [class_name]\n        end\n\n        indent_depth = class_path.size - 1\n        content = content.split(\"\\n\").map { |line| \"  \" * indent_depth + line } .join(\"\\n\") << \"\\n\"\n\n        inject_into_class(model_path, class_path.last, content) if model_exists?\n      end\n\n      def migration_data\n<<RUBY\n      ## Database authenticatable\n      t.string :email,              null: false, default: \"\"\n      t.string :encrypted_password, null: false, default: \"\"\n\n      ## Recoverable\n      t.string   :reset_password_token\n      t.datetime :reset_password_sent_at\n\n      ## Rememberable\n      t.datetime :remember_created_at\n\n      ## Trackable\n      # t.integer  :sign_in_count, default: 0, null: false\n      # t.datetime :current_sign_in_at\n      # t.datetime :last_sign_in_at\n      # t.#{ip_column} :current_sign_in_ip\n      # t.#{ip_column} :last_sign_in_ip\n\n      ## Confirmable\n      # t.string   :confirmation_token\n      # t.datetime :confirmed_at\n      # t.datetime :confirmation_sent_at\n      # t.string   :unconfirmed_email # Only if using reconfirmable\n\n      ## Lockable\n      # t.integer  :failed_attempts, default: 0, null: false # Only if lock strategy is :failed_attempts\n      # t.string   :unlock_token # Only if unlock strategy is :email or :both\n      # t.datetime :locked_at\nRUBY\n      end\n\n      def ip_column\n        # Padded with spaces so it aligns nicely with the rest of the columns.\n        \"%-8s\" % (inet? ? \"inet\" : \"string\")\n      end\n\n      def inet?\n        postgresql?\n      end\n\n      def rails61_and_up?\n        Rails::VERSION::MAJOR > 6 || (Rails::VERSION::MAJOR == 6 && Rails::VERSION::MINOR >= 1)\n      end\n\n      def postgresql?\n        ar_config && ar_config['adapter'] == 'postgresql'\n      end\n\n      def ar_config\n        if ActiveRecord::Base.configurations.respond_to?(:configs_for)\n          if rails61_and_up?\n            ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, name: \"primary\").configuration_hash\n          else\n            ActiveRecord::Base.configurations.configs_for(env_name: Rails.env, spec_name: \"primary\").config\n          end\n        else\n          ActiveRecord::Base.configurations[Rails.env]\n        end\n      end\n\n      def migration_version\n        \"[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]\"\n      end\n\n     def primary_key_type\n       primary_key_string\n     end\n\n     def primary_key_string\n       key_string = options[:primary_key_type]\n       \", id: :#{key_string}\" if key_string\n     end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/generators/active_record/templates/migration.rb",
    "content": "# frozen_string_literal: true\n\nclass DeviseCreate<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>\n  def change\n    create_table :<%= table_name %><%= primary_key_type %> do |t|\n<%= migration_data -%>\n\n<% attributes.each do |attribute| -%>\n      t.<%= attribute.type %> :<%= attribute.name %>\n<% end -%>\n\n      t.timestamps null: false\n    end\n\n    add_index :<%= table_name %>, :email,                unique: true\n    add_index :<%= table_name %>, :reset_password_token, unique: true\n    # add_index :<%= table_name %>, :confirmation_token,   unique: true\n    # add_index :<%= table_name %>, :unlock_token,         unique: true\n  end\nend\n"
  },
  {
    "path": "lib/generators/active_record/templates/migration_existing.rb",
    "content": "# frozen_string_literal: true\n\nclass AddDeviseTo<%= table_name.camelize %> < ActiveRecord::Migration<%= migration_version %>\n  def self.up\n    change_table :<%= table_name %> do |t|\n<%= migration_data -%>\n\n<% attributes.each do |attribute| -%>\n      t.<%= attribute.type %> :<%= attribute.name %>\n<% end -%>\n\n      # Uncomment below if timestamps were not included in your original model.\n      # t.timestamps null: false\n    end\n\n    add_index :<%= table_name %>, :email,                unique: true\n    add_index :<%= table_name %>, :reset_password_token, unique: true\n    # add_index :<%= table_name %>, :confirmation_token,   unique: true\n    # add_index :<%= table_name %>, :unlock_token,         unique: true\n  end\n\n  def self.down\n    # By default, we don't want to make any assumption about how to roll back a migration when your\n    # model already existed. Please edit below which fields you would like to remove in this migration.\n    raise ActiveRecord::IrreversibleMigration\n  end\nend\n"
  },
  {
    "path": "lib/generators/devise/controllers_generator.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'rails/generators/base'\n\nmodule Devise\n  module Generators\n    class ControllersGenerator < Rails::Generators::Base\n      CONTROLLERS = %w(confirmations passwords registrations sessions unlocks omniauth_callbacks).freeze\n\n      desc <<-DESC.strip_heredoc\n        Create inherited Devise controllers in your app/controllers folder.\n\n        Use -c to specify which controller you want to overwrite.\n        If you do not specify a controller, all controllers will be created.\n        For example:\n\n          rails generate devise:controllers users -c=sessions\n\n        This will create a controller class at app/controllers/users/sessions_controller.rb like this:\n\n          class Users::SessionsController < Devise::SessionsController\n            content...\n          end\n      DESC\n\n      source_root File.expand_path(\"../../templates/controllers\", __FILE__)\n      argument :scope, required: true,\n        desc: \"The scope to create controllers in, e.g. users, admins\"\n      class_option :controllers, aliases: \"-c\", type: :array,\n        desc: \"Select specific controllers to generate (#{CONTROLLERS.join(', ')})\"\n\n      def create_controllers\n        @scope_prefix = scope.blank? ? '' : (scope.camelize + '::')\n        controllers = options[:controllers] || CONTROLLERS\n        controllers.each do |name|\n          template \"#{name}_controller.rb\",\n                   \"app/controllers/#{scope}/#{name}_controller.rb\"\n        end\n      end\n\n      def show_readme\n        readme \"README\" if behavior == :invoke\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/generators/devise/devise_generator.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'rails/generators/named_base'\n\nmodule Devise\n  module Generators\n    class DeviseGenerator < Rails::Generators::NamedBase\n      include Rails::Generators::ResourceHelpers\n\n      namespace \"devise\"\n      source_root File.expand_path(\"../templates\", __FILE__)\n\n      desc \"Generates a model with the given NAME (if one does not exist) with devise \" \\\n           \"configuration plus a migration file and devise routes.\"\n\n      hook_for :orm, required: true\n\n      class_option :routes, desc: \"Generate routes\", type: :boolean, default: true\n\n      def add_devise_routes\n        devise_route  = \"devise_for :#{plural_name}\".dup\n        devise_route << %Q(, class_name: \"#{class_name}\") if class_name.include?(\"::\")\n        devise_route << %Q(, skip: :all) unless options.routes?\n        route devise_route\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/generators/devise/install_generator.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'rails/generators/base'\nrequire 'securerandom'\n\nmodule Devise\n  module Generators\n    MissingORMError = Class.new(Thor::Error)\n\n    class InstallGenerator < Rails::Generators::Base\n      source_root File.expand_path(\"../../templates\", __FILE__)\n\n      desc \"Creates a Devise initializer and copy locale files to your application.\"\n      class_option :orm, required: true\n\n      def copy_initializer\n        unless options[:orm]\n          raise MissingORMError, <<-ERROR.strip_heredoc\n          An ORM must be set to install Devise in your application.\n\n          Be sure to have an ORM like Active Record or Mongoid loaded in your\n          app or configure your own at `config/application.rb`.\n\n            config.generators do |g|\n              g.orm :your_orm_gem\n            end\n          ERROR\n        end\n\n        template \"devise.rb\", \"config/initializers/devise.rb\"\n      end\n\n      def copy_locale\n        copy_file \"../../../config/locales/en.yml\", \"config/locales/devise.en.yml\"\n      end\n\n      def show_readme\n        readme \"README\" if behavior == :invoke\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/generators/devise/orm_helpers.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  module Generators\n    module OrmHelpers\n      def model_contents\n        buffer = <<-CONTENT\n  # Include default devise modules. Others available are:\n  # :confirmable, :lockable, :timeoutable, :trackable and :omniauthable\n  devise :database_authenticatable, :registerable,\n         :recoverable, :rememberable, :validatable\n\nCONTENT\n        buffer\n      end\n\n      private\n\n      def model_exists?\n        File.exist?(File.join(destination_root, model_path))\n      end\n\n      def migration_exists?(table_name)\n        Dir.glob(\"#{File.join(destination_root, migration_path)}/[0-9]*_*.rb\").grep(/\\d+_add_devise_to_#{table_name}.rb$/).first\n      end\n\n      def migration_path\n        db_migrate_path\n      end\n\n      def model_path\n        @model_path ||= File.join(\"app\", \"models\", \"#{file_path}.rb\")\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/generators/devise/views_generator.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'rails/generators/base'\n\nmodule Devise\n  module Generators\n    # Include this module in your generator to generate Devise views.\n    # `copy_views` is the main method and by default copies all views\n    # with forms.\n    module ViewPathTemplates #:nodoc:\n      extend ActiveSupport::Concern\n\n      included do\n        argument :scope, required: false, default: nil,\n                         desc: \"The scope to copy views to\"\n\n        # Le sigh, ensure Thor won't handle opts as args\n        # It should be fixed in future Rails releases\n        class_option :form_builder, aliases: \"-b\"\n        class_option :markerb\n        class_option :views, aliases: \"-v\", type: :array, desc: \"Select specific view directories to generate (confirmations, passwords, registrations, sessions, unlocks, mailer)\"\n\n        public_task :copy_views\n      end\n\n      def copy_views\n        if options[:views]\n          options[:views].each do |directory|\n            view_directory directory.to_sym\n          end\n        else\n          view_directory :confirmations\n          view_directory :passwords\n          view_directory :registrations\n          view_directory :sessions\n          view_directory :unlocks\n        end\n      end\n\n      protected\n\n      def view_directory(name, _target_path = nil)\n        directory name.to_s, _target_path || \"#{target_path}/#{name}\" do |content|\n          if scope\n            content.gsub(\"devise/shared\", \"#{plural_scope}/shared\")\n          else\n            content\n          end\n        end\n      end\n\n      def target_path\n        @target_path ||= \"app/views/#{plural_scope || :devise}\"\n      end\n\n      def plural_scope\n        @plural_scope ||= scope.presence && scope.underscore.pluralize\n      end\n    end\n\n    class SharedViewsGenerator < Rails::Generators::Base #:nodoc:\n      include ViewPathTemplates\n      source_root File.expand_path(\"../../../../app/views/devise\", __FILE__)\n      desc \"Copies shared Devise views to your application.\"\n      hide!\n\n      # Override copy_views to just copy mailer and shared.\n      def copy_views\n        view_directory :shared\n      end\n    end\n\n    class FormForGenerator < Rails::Generators::Base #:nodoc:\n      include ViewPathTemplates\n      source_root File.expand_path(\"../../../../app/views/devise\", __FILE__)\n      desc \"Copies default Devise views to your application.\"\n      hide!\n    end\n\n    class SimpleFormForGenerator < Rails::Generators::Base #:nodoc:\n      include ViewPathTemplates\n      source_root File.expand_path(\"../../templates/simple_form_for\", __FILE__)\n      desc \"Copies simple form enabled views to your application.\"\n      hide!\n\n      def copy_views\n        if options[:views]\n          options[:views].delete('mailer')\n        end\n        super\n      end\n    end\n\n    class ErbGenerator < Rails::Generators::Base #:nodoc:\n      include ViewPathTemplates\n      source_root File.expand_path(\"../../../../app/views/devise\", __FILE__)\n      desc \"Copies Devise mail erb views to your application.\"\n      hide!\n\n      def copy_views\n        if !options[:views] || options[:views].include?('mailer')\n          view_directory :mailer\n        end\n      end\n    end\n\n    class MarkerbGenerator < Rails::Generators::Base #:nodoc:\n      include ViewPathTemplates\n      source_root File.expand_path(\"../../templates\", __FILE__)\n      desc \"Copies Devise mail markerb views to your application.\"\n      hide!\n\n      def copy_views\n        if !options[:views] || options[:views].include?('mailer')\n          view_directory :markerb, target_path\n        end\n      end\n\n      def target_path\n        \"app/views/#{plural_scope || :devise}/mailer\"\n      end\n    end\n\n    class ViewsGenerator < Rails::Generators::Base\n      desc \"Copies Devise views to your application.\"\n\n      argument :scope, required: false, default: nil,\n                       desc: \"The scope to copy views to\"\n\n      invoke SharedViewsGenerator\n\n      hook_for :form_builder, aliases: \"-b\",\n                              desc: \"Form builder to be used\",\n                              default: defined?(SimpleForm) ? \"simple_form_for\" : \"form_for\"\n\n      hook_for :markerb,  desc: \"Generate markerb instead of erb mail views\",\n                          default: defined?(Markerb),\n                          type: :boolean\n\n      hook_for :erb,      desc: \"Generate erb mail views\",\n                          default: !defined?(Markerb),\n                          type: :boolean\n    end\n  end\nend\n"
  },
  {
    "path": "lib/generators/mongoid/devise_generator.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'rails/generators/named_base'\nrequire 'generators/devise/orm_helpers'\n\nmodule Mongoid\n  module Generators\n    class DeviseGenerator < Rails::Generators::NamedBase\n      include Devise::Generators::OrmHelpers\n\n      def generate_model\n        invoke \"mongoid:model\", [name] unless model_exists? && behavior == :invoke\n      end\n\n      def inject_field_types\n        inject_into_file model_path, migration_data, after: \"include Mongoid::Document\\n\" if model_exists?\n      end\n\n      def inject_devise_content\n        inject_into_file model_path, model_contents, after: \"include Mongoid::Document\\n\" if model_exists?\n      end\n\n      def migration_data\n<<RUBY\n  ## Database authenticatable\n  field :email,              type: String, default: \"\"\n  field :encrypted_password, type: String, default: \"\"\n\n  ## Recoverable\n  field :reset_password_token,   type: String\n  field :reset_password_sent_at, type: Time\n\n  ## Rememberable\n  field :remember_created_at, type: Time\n\n  ## Trackable\n  # field :sign_in_count,      type: Integer, default: 0\n  # field :current_sign_in_at, type: Time\n  # field :last_sign_in_at,    type: Time\n  # field :current_sign_in_ip, type: String\n  # field :last_sign_in_ip,    type: String\n\n  ## Confirmable\n  # field :confirmation_token,   type: String\n  # field :confirmed_at,         type: Time\n  # field :confirmation_sent_at, type: Time\n  # field :unconfirmed_email,    type: String # Only if using reconfirmable\n\n  ## Lockable\n  # field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts\n  # field :unlock_token,    type: String # Only if unlock strategy is :email or :both\n  # field :locked_at,       type: Time\nRUBY\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/generators/templates/README",
    "content": "===============================================================================\n\nDepending on your application's configuration some manual setup may be required:\n\n  1. Ensure you have defined default url options in your environments files. Here\n     is an example of default_url_options appropriate for a development environment\n     in config/environments/development.rb:\n\n       config.action_mailer.default_url_options = { host: 'localhost', port: 3000 }\n\n     In production, :host should be set to the actual host of your application.\n\n     * Required for all applications. *\n\n  2. Ensure you have defined root_url to *something* in your config/routes.rb.\n     For example:\n\n       root to: \"home#index\"\n     \n     * Not required for API-only Applications *\n\n  3. Ensure you have flash messages in app/views/layouts/application.html.erb.\n     For example:\n\n       <p class=\"notice\"><%= notice %></p>\n       <p class=\"alert\"><%= alert %></p>\n\n     * Not required for API-only Applications *\n\n  4. You can copy Devise views (for customization) to your app by running:\n\n       rails g devise:views\n       \n     * Not required *\n\n===============================================================================\n"
  },
  {
    "path": "lib/generators/templates/controllers/README",
    "content": "===============================================================================\n\nSome setup you must do manually if you haven't yet:\n\n  Ensure you have overridden routes for generated controllers in your routes.rb.\n  For example:\n\n    Rails.application.routes.draw do\n      devise_for :users, controllers: {\n        sessions: 'users/sessions'\n      }\n    end\n\n===============================================================================\n"
  },
  {
    "path": "lib/generators/templates/controllers/confirmations_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass <%= @scope_prefix %>ConfirmationsController < Devise::ConfirmationsController\n  # GET /resource/confirmation/new\n  # def new\n  #   super\n  # end\n\n  # POST /resource/confirmation\n  # def create\n  #   super\n  # end\n\n  # GET /resource/confirmation?confirmation_token=abcdef\n  # def show\n  #   super\n  # end\n\n  # protected\n\n  # The path used after resending confirmation instructions.\n  # def after_resending_confirmation_instructions_path_for(resource_name)\n  #   super(resource_name)\n  # end\n\n  # The path used after confirmation.\n  # def after_confirmation_path_for(resource_name, resource)\n  #   super(resource_name, resource)\n  # end\nend\n"
  },
  {
    "path": "lib/generators/templates/controllers/omniauth_callbacks_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass <%= @scope_prefix %>OmniauthCallbacksController < Devise::OmniauthCallbacksController\n  # You should configure your model like this:\n  # devise :omniauthable, omniauth_providers: [:twitter]\n\n  # You should also create an action method in this controller like this:\n  # def twitter\n  # end\n\n  # More info at:\n  # https://github.com/heartcombo/devise#omniauth\n\n  # GET|POST /resource/auth/twitter\n  # def passthru\n  #   super\n  # end\n\n  # GET|POST /users/auth/twitter/callback\n  # def failure\n  #   super\n  # end\n\n  # protected\n\n  # The path used when OmniAuth fails\n  # def after_omniauth_failure_path_for(scope)\n  #   super(scope)\n  # end\nend\n"
  },
  {
    "path": "lib/generators/templates/controllers/passwords_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass <%= @scope_prefix %>PasswordsController < Devise::PasswordsController\n  # GET /resource/password/new\n  # def new\n  #   super\n  # end\n\n  # POST /resource/password\n  # def create\n  #   super\n  # end\n\n  # GET /resource/password/edit?reset_password_token=abcdef\n  # def edit\n  #   super\n  # end\n\n  # PUT /resource/password\n  # def update\n  #   super\n  # end\n\n  # protected\n\n  # def after_resetting_password_path_for(resource)\n  #   super(resource)\n  # end\n\n  # The path used after sending reset password instructions\n  # def after_sending_reset_password_instructions_path_for(resource_name)\n  #   super(resource_name)\n  # end\nend\n"
  },
  {
    "path": "lib/generators/templates/controllers/registrations_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass <%= @scope_prefix %>RegistrationsController < Devise::RegistrationsController\n  # before_action :configure_sign_up_params, only: [:create]\n  # before_action :configure_account_update_params, only: [:update]\n\n  # GET /resource/sign_up\n  # def new\n  #   super\n  # end\n\n  # POST /resource\n  # def create\n  #   super\n  # end\n\n  # GET /resource/edit\n  # def edit\n  #   super\n  # end\n\n  # PUT /resource\n  # def update\n  #   super\n  # end\n\n  # DELETE /resource\n  # def destroy\n  #   super\n  # end\n\n  # GET /resource/cancel\n  # Forces the session data which is usually expired after sign\n  # in to be expired now. This is useful if the user wants to\n  # cancel oauth signing in/up in the middle of the process,\n  # removing all OAuth session data.\n  # def cancel\n  #   super\n  # end\n\n  # protected\n\n  # If you have extra params to permit, append them to the sanitizer.\n  # def configure_sign_up_params\n  #   devise_parameter_sanitizer.permit(:sign_up, keys: [:attribute])\n  # end\n\n  # If you have extra params to permit, append them to the sanitizer.\n  # def configure_account_update_params\n  #   devise_parameter_sanitizer.permit(:account_update, keys: [:attribute])\n  # end\n\n  # The path used after sign up.\n  # def after_sign_up_path_for(resource)\n  #   super(resource)\n  # end\n\n  # The path used after sign up for inactive accounts.\n  # def after_inactive_sign_up_path_for(resource)\n  #   super(resource)\n  # end\nend\n"
  },
  {
    "path": "lib/generators/templates/controllers/sessions_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass <%= @scope_prefix %>SessionsController < Devise::SessionsController\n  # before_action :configure_sign_in_params, only: [:create]\n\n  # GET /resource/sign_in\n  # def new\n  #   super\n  # end\n\n  # POST /resource/sign_in\n  # def create\n  #   super\n  # end\n\n  # DELETE /resource/sign_out\n  # def destroy\n  #   super\n  # end\n\n  # protected\n\n  # If you have extra params to permit, append them to the sanitizer.\n  # def configure_sign_in_params\n  #   devise_parameter_sanitizer.permit(:sign_in, keys: [:attribute])\n  # end\nend\n"
  },
  {
    "path": "lib/generators/templates/controllers/unlocks_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass <%= @scope_prefix %>UnlocksController < Devise::UnlocksController\n  # GET /resource/unlock/new\n  # def new\n  #   super\n  # end\n\n  # POST /resource/unlock\n  # def create\n  #   super\n  # end\n\n  # GET /resource/unlock?unlock_token=abcdef\n  # def show\n  #   super\n  # end\n\n  # protected\n\n  # The path used after sending unlock password instructions\n  # def after_sending_unlock_instructions_path_for(resource)\n  #   super(resource)\n  # end\n\n  # The path used after unlocking the resource\n  # def after_unlock_path_for(resource)\n  #   super(resource)\n  # end\nend\n"
  },
  {
    "path": "lib/generators/templates/devise.rb",
    "content": "# frozen_string_literal: true\n\n# Assuming you have not yet modified this file, each configuration option below\n# is set to its default value. Note that some are commented out while others\n# are not: uncommented lines are intended to protect your configuration from\n# breaking changes in upgrades (i.e., in the event that future versions of\n# Devise change the default values for those options).\n#\n# Use this hook to configure devise mailer, warden hooks and so forth.\n# Many of these configuration options can be set straight in your model.\nDevise.setup do |config|\n  # The secret key used by Devise. Devise uses this key to generate\n  # random tokens. Changing this key will render invalid all existing\n  # confirmation, reset password and unlock tokens in the database.\n  # Devise will use the `secret_key_base` as its `secret_key`\n  # by default. You can change it below and use your own secret key.\n  # config.secret_key = '<%= SecureRandom.hex(64) %>'\n\n  # ==> Controller configuration\n  # Configure the parent class to the devise controllers.\n  # config.parent_controller = 'DeviseController'\n\n  # ==> Mailer Configuration\n  # Configure the e-mail address which will be shown in Devise::Mailer,\n  # note that it will be overwritten if you use your own mailer class\n  # with default \"from\" parameter.\n  config.mailer_sender = 'please-change-me-at-config-initializers-devise@example.com'\n\n  # Configure the class responsible to send e-mails.\n  # config.mailer = 'Devise::Mailer'\n\n  # Configure the parent class responsible to send e-mails.\n  # config.parent_mailer = 'ActionMailer::Base'\n\n  # ==> ORM configuration\n  # Load and configure the ORM. Supports :active_record (default) and\n  # :mongoid (bson_ext recommended) by default. Other ORMs may be\n  # available as additional gems.\n  require 'devise/orm/<%= options[:orm] %>'\n\n  # ==> Configuration for any authentication mechanism\n  # Configure which keys are used when authenticating a user. The default is\n  # just :email. You can configure it to use [:username, :subdomain], so for\n  # authenticating a user, both parameters are required. Remember that those\n  # parameters are used only when authenticating and not when retrieving from\n  # session. If you need permissions, you should implement that in a before filter.\n  # You can also supply a hash where the value is a boolean determining whether\n  # or not authentication should be aborted when the value is not present.\n  # config.authentication_keys = [:email]\n\n  # Configure parameters from the request object used for authentication. Each entry\n  # given should be a request method and it will automatically be passed to the\n  # find_for_authentication method and considered in your model lookup. For instance,\n  # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.\n  # The same considerations mentioned for authentication_keys also apply to request_keys.\n  # config.request_keys = []\n\n  # Configure which authentication keys should be case-insensitive.\n  # These keys will be downcased upon creating or modifying a user and when used\n  # to authenticate or find a user. Default is :email.\n  config.case_insensitive_keys = [:email]\n\n  # Configure which authentication keys should have whitespace stripped.\n  # These keys will have whitespace before and after removed upon creating or\n  # modifying a user and when used to authenticate or find a user. Default is :email.\n  config.strip_whitespace_keys = [:email]\n\n  # Tell if authentication through request.params is enabled. True by default.\n  # It can be set to an array that will enable params authentication only for the\n  # given strategies, for example, `config.params_authenticatable = [:database]` will\n  # enable it only for database (email + password) authentication.\n  # config.params_authenticatable = true\n\n  # Tell if authentication through HTTP Auth is enabled. False by default.\n  # It can be set to an array that will enable http authentication only for the\n  # given strategies, for example, `config.http_authenticatable = [:database]` will\n  # enable it only for database authentication.\n  # For API-only applications to support authentication \"out-of-the-box\", you will likely want to\n  # enable this with :database unless you are using a custom strategy.\n  # The supported strategies are:\n  # :database      = Support basic authentication with authentication key + password\n  # config.http_authenticatable = false\n\n  # If 401 status code should be returned for AJAX requests. True by default.\n  # config.http_authenticatable_on_xhr = true\n\n  # The realm used in Http Basic Authentication. 'Application' by default.\n  # config.http_authentication_realm = 'Application'\n\n  # It will change confirmation, password recovery and other workflows\n  # to behave the same regardless if the e-mail provided was right or wrong.\n  # Does not affect registerable.\n  # config.paranoid = true\n\n  # By default Devise will store the user in session. You can skip storage for\n  # particular strategies by setting this option.\n  # Notice that if you are skipping storage for all authentication paths, you\n  # may want to disable generating routes to Devise's sessions controller by\n  # passing skip: :sessions to `devise_for` in your config/routes.rb\n  config.skip_session_storage = [:http_auth]\n\n  # By default, Devise cleans up the CSRF token on authentication to\n  # avoid CSRF token fixation attacks. This means that, when using AJAX\n  # requests for sign in and sign up, you need to get a new CSRF token\n  # from the server. You can disable this option at your own risk.\n  # config.clean_up_csrf_token_on_authentication = true\n\n  # When false, Devise will not attempt to reload routes on eager load.\n  # This can reduce the time taken to boot the app but if your application\n  # requires the Devise mappings to be loaded during boot time the application\n  # won't boot properly.\n  # config.reload_routes = true\n\n  # ==> Configuration for :database_authenticatable\n  # For bcrypt, this is the cost for hashing the password and defaults to 12. If\n  # using other algorithms, it sets how many times you want the password to be hashed.\n  # The number of stretches used for generating the hashed password are stored\n  # with the hashed password. This allows you to change the stretches without\n  # invalidating existing passwords.\n  #\n  # Limiting the stretches to just one in testing will increase the performance of\n  # your test suite dramatically. However, it is STRONGLY RECOMMENDED to not use\n  # a value less than 10 in other environments. Note that, for bcrypt (the default\n  # algorithm), the cost increases exponentially with the number of stretches (e.g.\n  # a value of 20 is already extremely slow: approx. 60 seconds for 1 calculation).\n  config.stretches = Rails.env.test? ? 1 : 12\n\n  # Set up a pepper to generate the hashed password.\n  # config.pepper = '<%= SecureRandom.hex(64) %>'\n\n  # Send a notification to the original email when the user's email is changed.\n  # config.send_email_changed_notification = false\n\n  # Send a notification email when the user's password is changed.\n  # config.send_password_change_notification = false\n\n  # ==> Configuration for :confirmable\n  # A period that the user is allowed to access the website even without\n  # confirming their account. For instance, if set to 2.days, the user will be\n  # able to access the website for two days without confirming their account,\n  # access will be blocked just in the third day.\n  # You can also set it to nil, which will allow the user to access the website\n  # without confirming their account.\n  # Default is 0.days, meaning the user cannot access the website without\n  # confirming their account.\n  # config.allow_unconfirmed_access_for = 2.days\n\n  # A period that the user is allowed to confirm their account before their\n  # token becomes invalid. For example, if set to 3.days, the user can confirm\n  # their account within 3 days after the mail was sent, but on the fourth day\n  # their account can't be confirmed with the token any more.\n  # Default is nil, meaning there is no restriction on how long a user can take\n  # before confirming their account.\n  # config.confirm_within = 3.days\n\n  # If true, requires any email changes to be confirmed (exactly the same way as\n  # initial account confirmation) to be applied. Requires additional unconfirmed_email\n  # db field (see migrations). Until confirmed, new email is stored in\n  # unconfirmed_email column, and copied to email column on successful confirmation.\n  # Also, when used in conjunction with `send_email_changed_notification`,\n  # the notification is sent to the original email when the change is requested,\n  # not when the unconfirmed email is confirmed.\n  config.reconfirmable = true\n\n  # Defines which key will be used when confirming an account\n  # config.confirmation_keys = [:email]\n\n  # ==> Configuration for :rememberable\n  # The time the user will be remembered without asking for credentials again.\n  # config.remember_for = 2.weeks\n\n  # Invalidates all the remember me tokens when the user signs out.\n  config.expire_all_remember_me_on_sign_out = true\n\n  # If true, extends the user's remember period when remembered via cookie.\n  # config.extend_remember_period = false\n\n  # Options to be passed to the created cookie. For instance, you can set\n  # secure: true in order to force SSL only cookies.\n  # config.rememberable_options = {}\n\n  # ==> Configuration for :validatable\n  # Range for password length.\n  config.password_length = 6..128\n\n  # Email regex used to validate email formats. It simply asserts that\n  # one (and only one) @ exists in the given string. This is mainly\n  # to give user feedback and not to assert the e-mail validity.\n  config.email_regexp = /\\A[^@\\s]+@[^@\\s]+\\z/\n\n  # ==> Configuration for :timeoutable\n  # The time you want to timeout the user session without activity. After this\n  # time the user will be asked for credentials again. Default is 30 minutes.\n  # config.timeout_in = 30.minutes\n\n  # ==> Configuration for :lockable\n  # Defines which strategy will be used to lock an account.\n  # :failed_attempts = Locks an account after a number of failed attempts to sign in.\n  # :none            = No lock strategy. You should handle locking by yourself.\n  # config.lock_strategy = :failed_attempts\n\n  # Defines which key will be used when locking and unlocking an account\n  # config.unlock_keys = [:email]\n\n  # Defines which strategy will be used to unlock an account.\n  # :email = Sends an unlock link to the user email\n  # :time  = Re-enables login after a certain amount of time (see :unlock_in below)\n  # :both  = Enables both strategies\n  # :none  = No unlock strategy. You should handle unlocking by yourself.\n  # config.unlock_strategy = :both\n\n  # Number of authentication tries before locking an account if lock_strategy\n  # is failed attempts.\n  # config.maximum_attempts = 20\n\n  # Time interval to unlock the account if :time is enabled as unlock_strategy.\n  # config.unlock_in = 1.hour\n\n  # Warn on the last attempt before the account is locked.\n  # config.last_attempt_warning = true\n\n  # ==> Configuration for :recoverable\n  #\n  # Defines which key will be used when recovering the password for an account\n  # config.reset_password_keys = [:email]\n\n  # Time interval you can reset your password with a reset password key.\n  # Don't put a too small interval or your users won't have the time to\n  # change their passwords.\n  config.reset_password_within = 6.hours\n\n  # When set to false, does not sign a user in automatically after their password is\n  # reset. Defaults to true, so a user is signed in automatically after a reset.\n  # config.sign_in_after_reset_password = true\n\n  # ==> Configuration for :encryptable\n  # Allow you to use another hashing or encryption algorithm besides bcrypt (default).\n  # You can use :sha1, :sha512 or algorithms from others authentication tools as\n  # :clearance_sha1, :authlogic_sha512 (then you should set stretches above to 20\n  # for default behavior) and :restful_authentication_sha1 (then you should set\n  # stretches to 10, and copy REST_AUTH_SITE_KEY to pepper).\n  #\n  # Require the `devise-encryptable` gem when using anything other than bcrypt\n  # config.encryptor = :sha512\n\n  # ==> Scopes configuration\n  # Turn scoped views on. Before rendering \"sessions/new\", it will first check for\n  # \"users/sessions/new\". It's turned off by default because it's slower if you\n  # are using only default views.\n  # config.scoped_views = false\n\n  # Configure the default scope given to Warden. By default it's the first\n  # devise role declared in your routes (usually :user).\n  # config.default_scope = :user\n\n  # Set this configuration to false if you want /users/sign_out to sign out\n  # only the current scope. By default, Devise signs out all scopes.\n  # config.sign_out_all_scopes = true\n\n  # ==> Navigation configuration\n  # Lists the formats that should be treated as navigational. Formats like\n  # :html should redirect to the sign in page when the user does not have\n  # access, but formats like :xml or :json, should return 401.\n  #\n  # If you have any extra navigational formats, like :iphone or :mobile, you\n  # should add them to the navigational formats lists.\n  #\n  # The \"*/*\" below is required to match Internet Explorer requests.\n  # config.navigational_formats = ['*/*', :html, :turbo_stream]\n\n  # The default HTTP method used to sign out a resource. Default is :delete.\n  config.sign_out_via = :delete\n\n  # ==> OmniAuth\n  # Add a new OmniAuth provider. Check the wiki for more information on setting\n  # up on your models and hooks.\n  # config.omniauth :github, 'APP_ID', 'APP_SECRET', scope: 'user,public_repo'\n\n  # ==> Warden configuration\n  # If you want to use other strategies, that are not supported by Devise, or\n  # change the failure app, you can configure them inside the config.warden block.\n  #\n  # config.warden do |warden_config|\n  #   warden_config.intercept_401 = false\n  #   warden_config.default_strategies(scope: :user).unshift :some_external_strategy\n  # end\n\n  # ==> Mountable engine configurations\n  # When using Devise inside an engine, let's call it `MyEngine`, and this engine\n  # is mountable, there are some extra configurations to be taken into account.\n  # The following options are available, assuming the engine is mounted as:\n  #\n  #     mount MyEngine, at: '/my_engine'\n  #\n  # The router that invoked `devise_for`, in the example above, would be:\n  # config.router_name = :my_engine\n  #\n  # When using OmniAuth, Devise cannot automatically set OmniAuth path,\n  # so you need to do it manually. For the users scope, it would be:\n  # config.omniauth_path_prefix = '/my_engine/users/auth'\n\n  # ==> Hotwire/Turbo configuration\n  # When using Devise with Hotwire/Turbo, the http status for error responses\n  # and some redirects must match the following. The default in Devise for existing\n  # apps is `200 OK` and `302 Found` respectively, but new apps are generated with\n  # these new defaults that match Hotwire/Turbo behavior.\n  # Note: These might become the new default in future versions of Devise.\n  config.responder.error_status = <%= Rack::Utils::SYMBOL_TO_STATUS_CODE.key(422).inspect %>\n  config.responder.redirect_status = :see_other\n\n  # ==> Configuration for :registerable\n\n  # When set to false, does not sign a user in automatically after their password is\n  # changed. Defaults to true, so a user is signed in automatically after changing a password.\n  # config.sign_in_after_change_password = true\nend\n"
  },
  {
    "path": "lib/generators/templates/markerb/confirmation_instructions.markerb",
    "content": "Welcome <%= @email %>!\n\nYou can confirm your account through the link below:\n\n[Confirm my account](<%= confirmation_url(@resource, confirmation_token: @token) %>)\n"
  },
  {
    "path": "lib/generators/templates/markerb/email_changed.markerb",
    "content": "Hello <%= @email %>!\n\n<% if @resource.try(:unconfirmed_email?) %>\nWe're contacting you to notify you that your email is being changed to <%= @resource.unconfirmed_email %>.\n<% else %>\nWe're contacting you to notify you that your email has been changed to <%= @resource.email %>.\n<% end %>\n"
  },
  {
    "path": "lib/generators/templates/markerb/password_change.markerb",
    "content": "Hello <%= @resource.email %>!\n\nWe're contacting you to notify you that your password has been changed.\n"
  },
  {
    "path": "lib/generators/templates/markerb/reset_password_instructions.markerb",
    "content": "Hello <%= @resource.email %>!\n\nSomeone has requested a link to change your password, and you can do this through the link below.\n\n[Change my password](<%= edit_password_url(@resource, reset_password_token: @token) %>)\n\nIf you didn't request this, please ignore this email.\nYour password won't change until you access the link above and create a new one.\n"
  },
  {
    "path": "lib/generators/templates/markerb/unlock_instructions.markerb",
    "content": "Hello <%= @resource.email %>!\n\nYour account has been locked due to an excessive number of unsuccessful sign in attempts.\n\nClick the link below to unlock your account:\n\n[Unlock my account](<%= unlock_url(@resource, unlock_token: @token) %>)\n"
  },
  {
    "path": "lib/generators/templates/simple_form_for/confirmations/new.html.erb",
    "content": "<h2>Resend confirmation instructions</h2>\n\n<%= simple_form_for(resource, as: resource_name, url: confirmation_path(resource_name), html: { method: :post }) do |f| %>\n  <%= f.error_notification %>\n  <%= f.full_error :confirmation_token %>\n\n  <div class=\"form-inputs\">\n    <%= f.input :email,\n                required: true,\n                autofocus: true,\n                value: (resource.pending_reconfirmation? ? resource.unconfirmed_email : resource.email),\n                input_html: { autocomplete: \"email\" } %>\n  </div>\n\n  <div class=\"form-actions\">\n    <%= f.button :submit, \"Resend confirmation instructions\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "lib/generators/templates/simple_form_for/passwords/edit.html.erb",
    "content": "<h2>Change your password</h2>\n\n<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :put }) do |f| %>\n  <%= f.error_notification %>\n\n  <%= f.input :reset_password_token, as: :hidden %>\n  <%= f.full_error :reset_password_token %>\n\n  <div class=\"form-inputs\">\n    <%= f.input :password,\n                label: \"New password\",\n                required: true,\n                autofocus: true,\n                hint: (\"#{@minimum_password_length} characters minimum\" if @minimum_password_length),\n                input_html: { autocomplete: \"new-password\" } %>\n    <%= f.input :password_confirmation,\n                label: \"Confirm your new password\",\n                required: true,\n                input_html: { autocomplete: \"new-password\" } %>\n  </div>\n\n  <div class=\"form-actions\">\n    <%= f.button :submit, \"Change my password\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "lib/generators/templates/simple_form_for/passwords/new.html.erb",
    "content": "<h2>Forgot your password?</h2>\n\n<%= simple_form_for(resource, as: resource_name, url: password_path(resource_name), html: { method: :post }) do |f| %>\n  <%= f.error_notification %>\n\n  <div class=\"form-inputs\">\n    <%= f.input :email,\n                required: true,\n                autofocus: true,\n                input_html: { autocomplete: \"email\" } %>\n  </div>\n\n  <div class=\"form-actions\">\n    <%= f.button :submit, \"Send me password reset instructions\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "lib/generators/templates/simple_form_for/registrations/edit.html.erb",
    "content": "<h2>Edit <%= resource_name.to_s.humanize %></h2>\n\n<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put }) do |f| %>\n  <%= f.error_notification %>\n\n  <div class=\"form-inputs\">\n    <%= f.input :email, required: true, autofocus: true %>\n\n    <% if devise_mapping.confirmable? && resource.pending_reconfirmation? %>\n      <p>Currently waiting confirmation for: <%= resource.unconfirmed_email %></p>\n    <% end %>\n\n    <%= f.input :password,\n                hint: \"leave it blank if you don't want to change it\",\n                required: false,\n                input_html: { autocomplete: \"new-password\" } %>\n    <%= f.input :password_confirmation,\n                required: false,\n                input_html: { autocomplete: \"new-password\" } %>\n    <%= f.input :current_password,\n                hint: \"we need your current password to confirm your changes\",\n                required: true,\n                input_html: { autocomplete: \"current-password\" } %>\n  </div>\n\n  <div class=\"form-actions\">\n    <%= f.button :submit, \"Update\" %>\n  </div>\n<% end %>\n\n<h3>Cancel my account</h3>\n\n<div>Unhappy? <%= button_to \"Cancel my account\", registration_path(resource_name), data: { confirm: \"Are you sure?\", turbo_confirm: \"Are you sure?\" }, method: :delete %></div>\n\n<%= link_to \"Back\", :back %>\n"
  },
  {
    "path": "lib/generators/templates/simple_form_for/registrations/new.html.erb",
    "content": "<h2>Sign up</h2>\n\n<%= simple_form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>\n  <%= f.error_notification %>\n\n  <div class=\"form-inputs\">\n    <%= f.input :email,\n                required: true,\n                autofocus: true,\n                input_html: { autocomplete: \"email\" }%>\n    <%= f.input :password,\n                required: true,\n                hint: (\"#{@minimum_password_length} characters minimum\" if @minimum_password_length),\n                input_html: { autocomplete: \"new-password\" } %>\n    <%= f.input :password_confirmation,\n                required: true,\n                input_html: { autocomplete: \"new-password\" } %>\n  </div>\n\n  <div class=\"form-actions\">\n    <%= f.button :submit, \"Sign up\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "lib/generators/templates/simple_form_for/sessions/new.html.erb",
    "content": "<h2>Log in</h2>\n\n<%= simple_form_for(resource, as: resource_name, url: session_path(resource_name)) do |f| %>\n  <div class=\"form-inputs\">\n    <%= f.input :email,\n                required: false,\n                autofocus: true,\n                input_html: { autocomplete: \"email\" } %>\n    <%= f.input :password,\n                required: false,\n                input_html: { autocomplete: \"current-password\" } %>\n    <%= f.input :remember_me, as: :boolean if devise_mapping.rememberable? %>\n  </div>\n\n  <div class=\"form-actions\">\n    <%= f.button :submit, \"Log in\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "lib/generators/templates/simple_form_for/unlocks/new.html.erb",
    "content": "<h2>Resend unlock instructions</h2>\n\n<%= simple_form_for(resource, as: resource_name, url: unlock_path(resource_name), html: { method: :post }) do |f| %>\n  <%= f.error_notification %>\n  <%= f.full_error :unlock_token %>\n\n  <div class=\"form-inputs\">\n    <%= f.input :email,\n                required: true,\n                autofocus: true,\n                input_html: { autocomplete: \"email\" } %>\n  </div>\n\n  <div class=\"form-actions\">\n    <%= f.button :submit, \"Resend unlock instructions\" %>\n  </div>\n<% end %>\n\n<%= render \"devise/shared/links\" %>\n"
  },
  {
    "path": "test/controllers/custom_registrations_controller_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass CustomRegistrationsControllerTest < Devise::ControllerTestCase\n  tests Custom::RegistrationsController\n\n  include Devise::Test::ControllerHelpers\n\n  setup do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    @password = 'password'\n    @user = create_user(password: @password, password_confirmation: @password).tap(&:confirm)\n  end\n\n  test \"yield resource to block on create success\" do\n    post :create, params: { user: { email: \"user@example.org\", password: \"password\", password_confirmation: \"password\" } }\n    assert @controller.create_block_called?, \"create failed to yield resource to provided block\"\n  end\n\n  test \"yield resource to block on create failure\" do\n    post :create, params: { user: { } }\n    assert @controller.create_block_called?, \"create failed to yield resource to provided block\"\n  end\n\n  test \"yield resource to block on update success\" do\n    sign_in @user\n    put :update, params: { user: { current_password: @password } }\n    assert @controller.update_block_called?, \"update failed to yield resource to provided block\"\n  end\n\n  test \"yield resource to block on update failure\" do\n    sign_in @user\n    put :update, params: { user: { } }\n    assert @controller.update_block_called?, \"update failed to yield resource to provided block\"\n  end\n\n  test \"yield resource to block on new\" do\n    get :new\n    assert @controller.new_block_called?, \"new failed to yield resource to provided block\"\n  end\nend\n"
  },
  {
    "path": "test/controllers/custom_strategy_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\nrequire 'ostruct'\nrequire 'warden/strategies/base'\nrequire 'devise/test/controller_helpers'\n\nclass CustomStrategyController < ActionController::Base\n  def new\n    warden.authenticate!(:custom_strategy)\n  end\nend\n\n# These tests are to prove that a warden strategy can successfully\n# return a custom response, including a specific status code and\n# custom http response headers. This does work in production,\n# however, at the time of writing this, the Devise test helpers do\n# not recognise the custom response and proceed to calling the\n# Failure App. This makes it impossible to write tests for a\n# strategy that return a custom response with Devise.\nclass CustomStrategy < Warden::Strategies::Base\n  def authenticate!\n    custom_headers = { \"X-FOO\" => \"BAR\" }\n    response = Rack::Response.new(\"BAD REQUEST\", 400, custom_headers)\n    custom! response.finish\n  end\nend\n\nclass CustomStrategyTest < Devise::ControllerTestCase\n  tests CustomStrategyController\n\n  include Devise::Test::ControllerHelpers\n\n  setup do\n    Warden::Strategies.add(:custom_strategy, CustomStrategy)\n  end\n\n  teardown do\n    Warden::Strategies._strategies.delete(:custom_strategy)\n  end\n\n  test \"custom strategy can return its own status code\" do\n    ret = get :new\n\n    # check the returned response\n    assert ret.is_a?(ActionDispatch::TestResponse)\n\n    # check the saved response as well. This is purely so that the response is available to the testing framework\n    # for verification. In production, the above array would be delivered directly to Rack.\n    assert_response 400\n  end\n\n  test \"custom strategy can return custom headers\" do\n    ret = get :new\n\n    # check the returned response\n    assert ret.is_a?(ActionDispatch::TestResponse)\n\n    # check the saved response headers as well.\n    assert_equal 'BAR', response.headers['X-FOO']\n  end\nend\n"
  },
  {
    "path": "test/controllers/helper_methods_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass ApiController < ActionController::Metal\n  include Devise::Controllers::Helpers\nend\n\nclass HelperMethodsTest < Devise::ControllerTestCase\n  tests ApiController\n\n  test 'includes Devise::Controllers::Helpers' do\n    assert_includes @controller.class.ancestors, Devise::Controllers::Helpers\n  end\n\n  test 'does not respond_to helper or helper_method' do\n    assert_not_respond_to @controller.class, :helper\n    assert_not_respond_to @controller.class, :helper_method\n  end\n\n  test 'defines methods like current_user' do\n    assert_respond_to @controller, :current_user\n  end\nend\n"
  },
  {
    "path": "test/controllers/helpers_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\nrequire 'ostruct'\n\nclass ControllerAuthenticatableTest < Devise::ControllerTestCase\n  tests ApplicationController\n\n  def setup\n    @mock_warden = OpenStruct.new\n    @controller.request.env['warden'] = @mock_warden\n  end\n\n  test 'provide access to warden instance' do\n    assert_equal @mock_warden, @controller.warden\n  end\n\n  test 'proxy signed_in?(scope) to authenticate?' do\n    @mock_warden.expects(:authenticate?).with(scope: :my_scope)\n    @controller.signed_in?(:my_scope)\n  end\n\n  test 'proxy signed_in?(nil) to authenticate?' do\n    Devise.mappings.keys.each do |scope| # :user, :admin, :manager\n      @mock_warden.expects(:authenticate?).with(scope: scope)\n    end\n    @controller.signed_in?\n  end\n\n  test 'proxy [group]_signed_in? to authenticate? with each scope' do\n    [:user, :admin].each do |scope|\n      @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)\n    end\n    @controller.commenter_signed_in?\n  end\n\n  test 'proxy current_user to authenticate with user scope' do\n    @mock_warden.expects(:authenticate).with(scope: :user)\n    @controller.current_user\n  end\n\n  test 'proxy current_admin to authenticate with admin scope' do\n    @mock_warden.expects(:authenticate).with(scope: :admin)\n    @controller.current_admin\n  end\n\n  test 'proxy current_[group] to authenticate with each scope' do\n    [:user, :admin].each do |scope|\n      @mock_warden.expects(:authenticate).with(scope: scope).returns(nil)\n    end\n    @controller.current_commenter\n  end\n\n  test 'proxy current_[plural_group] to authenticate with each scope' do\n    [:user, :admin].each do |scope|\n      @mock_warden.expects(:authenticate).with(scope: scope)\n    end\n    @controller.current_commenters\n  end\n\n  test 'proxy current_publisher_account to authenticate with namespaced publisher account scope' do\n    @mock_warden.expects(:authenticate).with(scope: :publisher_account)\n    @controller.current_publisher_account\n  end\n\n  test 'proxy authenticate_user! to authenticate with user scope' do\n    @mock_warden.expects(:authenticate!).with({ scope: :user, locale: :en })\n    @controller.authenticate_user!\n  end\n\n  test 'proxy authenticate_user! options to authenticate with user scope' do\n    @mock_warden.expects(:authenticate!).with({ scope: :user, recall: \"foo\", locale: :en })\n    @controller.authenticate_user!(recall: \"foo\")\n  end\n\n  test 'proxy authenticate_admin! to authenticate with admin scope' do\n    @mock_warden.expects(:authenticate!).with({ scope: :admin, locale: :en })\n    @controller.authenticate_admin!\n  end\n\n  test 'proxy authenticate_[group]! to authenticate!? with each scope' do\n    [:user, :admin].each do |scope|\n      @mock_warden.expects(:authenticate!).with({ scope: scope, locale: :en })\n      @mock_warden.expects(:authenticate?).with(scope: scope).returns(false)\n    end\n    @controller.authenticate_commenter!\n  end\n\n  test 'proxy authenticate_publisher_account! to authenticate with namespaced publisher account scope' do\n    @mock_warden.expects(:authenticate!).with({ scope: :publisher_account, locale: :en })\n    @controller.authenticate_publisher_account!\n  end\n\n  test 'proxy user_signed_in? to authenticate with user scope' do\n    @mock_warden.expects(:authenticate).with(scope: :user).returns(\"user\")\n    assert @controller.user_signed_in?\n  end\n\n  test 'proxy admin_signed_in? to authenticatewith admin scope' do\n    @mock_warden.expects(:authenticate).with(scope: :admin)\n    assert_not @controller.admin_signed_in?\n  end\n\n  test 'proxy publisher_account_signed_in? to authenticate with namespaced publisher account scope' do\n    @mock_warden.expects(:authenticate).with(scope: :publisher_account)\n    @controller.publisher_account_signed_in?\n  end\n\n  test 'proxy user_session to session scope in warden' do\n    @mock_warden.expects(:authenticate).with(scope: :user).returns(true)\n    @mock_warden.expects(:session).with(:user).returns({})\n    @controller.user_session\n  end\n\n  test 'proxy admin_session to session scope in warden' do\n    @mock_warden.expects(:authenticate).with(scope: :admin).returns(true)\n    @mock_warden.expects(:session).with(:admin).returns({})\n    @controller.admin_session\n  end\n\n  test 'proxy publisher_account_session from namespaced scope to session scope in warden' do\n    @mock_warden.expects(:authenticate).with(scope: :publisher_account).returns(true)\n    @mock_warden.expects(:session).with(:publisher_account).returns({})\n    @controller.publisher_account_session\n  end\n\n  test 'sign in proxy to set_user on warden' do\n    user = User.new\n    @mock_warden.expects(:user).returns(nil)\n    @mock_warden.expects(:set_user).with(user, { scope: :user }).returns(true)\n    @controller.sign_in(:user, user)\n  end\n\n  test 'sign in accepts a resource as argument' do\n    user = User.new\n    @mock_warden.expects(:user).returns(nil)\n    @mock_warden.expects(:set_user).with(user, { scope: :user }).returns(true)\n    @controller.sign_in(user)\n  end\n\n  test 'does not sign in again if the user is already in' do\n    user = User.new\n    @mock_warden.expects(:user).returns(user)\n    @mock_warden.expects(:set_user).never\n    assert @controller.sign_in(user)\n  end\n\n  test 'sign in again when the user is already in only if force is given' do\n    user = User.new\n    @mock_warden.expects(:user).returns(user)\n    @mock_warden.expects(:set_user).with(user, { scope: :user }).returns(true)\n    @controller.sign_in(user, force: true)\n  end\n\n  test 'bypass the sign in' do\n    user = User.new\n    @mock_warden.expects(:session_serializer).returns(serializer = mock())\n    serializer.expects(:store).with(user, :user)\n    @controller.bypass_sign_in(user)\n  end\n\n  test 'sign out clears up any signed in user from all scopes' do\n    user = User.new\n    @mock_warden.expects(:user).times(Devise.mappings.size)\n    @mock_warden.expects(:logout).with().returns(true)\n    @controller.instance_variable_set(:@current_user, user)\n    @controller.instance_variable_set(:@current_admin, user)\n    @controller.sign_out\n    assert_nil @controller.instance_variable_get(:@current_user)\n    assert_nil @controller.instance_variable_get(:@current_admin)\n  end\n\n  test 'sign out logs out and clears up any signed in user by scope' do\n    user = User.new\n    @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(user)\n    @mock_warden.expects(:logout).with(:user).returns(true)\n    @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)\n    @controller.instance_variable_set(:@current_user, user)\n    @controller.sign_out(:user)\n    assert_nil @controller.instance_variable_get(:@current_user)\n  end\n\n  test 'sign out accepts a resource as argument' do\n    @mock_warden.expects(:user).with(scope: :user, run_callbacks: false).returns(true)\n    @mock_warden.expects(:logout).with(:user).returns(true)\n    @mock_warden.expects(:clear_strategies_cache!).with(scope: :user).returns(true)\n    @controller.sign_out(User.new)\n  end\n\n  test 'sign out without args proxy to sign out all scopes' do\n    @mock_warden.expects(:user).times(Devise.mappings.size)\n    @mock_warden.expects(:logout).with().returns(true)\n    @mock_warden.expects(:clear_strategies_cache!).with().returns(true)\n    @controller.sign_out\n  end\n\n  test 'sign out everybody proxy to logout on warden' do\n    @mock_warden.expects(:user).times(Devise.mappings.size)\n    @mock_warden.expects(:logout).with().returns(true)\n    @controller.sign_out_all_scopes\n  end\n\n  test 'stored location for returns the location for a given scope' do\n    assert_nil @controller.stored_location_for(:user)\n    @controller.session[:\"user_return_to\"] = \"/foo.bar\"\n    assert_equal \"/foo.bar\", @controller.stored_location_for(:user)\n  end\n\n  test 'stored location for accepts a resource as argument' do\n    assert_nil @controller.stored_location_for(:user)\n    @controller.session[:\"user_return_to\"] = \"/foo.bar\"\n    assert_equal \"/foo.bar\", @controller.stored_location_for(User.new)\n  end\n\n  test 'stored location cleans information after reading' do\n    @controller.session[:\"user_return_to\"] = \"/foo.bar\"\n    assert_equal \"/foo.bar\", @controller.stored_location_for(:user)\n    assert_nil @controller.session[:\"user_return_to\"]\n  end\n\n  test 'store location for stores a location to redirect back to' do\n    assert_nil @controller.stored_location_for(:user)\n    @controller.store_location_for(:user, \"/foo.bar\")\n    assert_equal \"/foo.bar\", @controller.stored_location_for(:user)\n  end\n\n  test 'store bad location for stores a location to redirect back to' do\n    assert_nil @controller.stored_location_for(:user)\n    @controller.store_location_for(:user, \"/foo.bar\\\">Carry\")\n    assert_nil @controller.stored_location_for(:user)\n  end\n\n  test 'store location for accepts a resource as argument' do\n    @controller.store_location_for(User.new, \"/foo.bar\")\n    assert_equal \"/foo.bar\", @controller.stored_location_for(User.new)\n  end\n\n  test 'store location for stores paths' do\n    @controller.store_location_for(:user, \"//host/foo.bar\")\n    assert_equal \"/foo.bar\", @controller.stored_location_for(:user)\n    @controller.store_location_for(:user, \"///foo.bar\")\n    assert_equal \"/foo.bar\", @controller.stored_location_for(:user)\n  end\n\n  test 'store location for stores query string' do\n    @controller.store_location_for(:user, \"/foo?bar=baz\")\n    assert_equal \"/foo?bar=baz\", @controller.stored_location_for(:user)\n  end\n\n  test 'store location for stores fragments' do\n    @controller.store_location_for(:user, \"/foo#bar\")\n    assert_equal \"/foo#bar\", @controller.stored_location_for(:user)\n  end\n\n  test 'after sign in path defaults to root path if none by was specified for the given scope' do\n    assert_equal root_path, @controller.after_sign_in_path_for(:user)\n  end\n\n  test 'after sign in path defaults to the scoped root path' do\n    assert_equal admin_root_path, @controller.after_sign_in_path_for(:admin)\n  end\n\n  test 'after sign out path defaults to the root path' do\n    assert_equal root_path, @controller.after_sign_out_path_for(:admin)\n    assert_equal root_path, @controller.after_sign_out_path_for(:user)\n  end\n\n  test 'sign in and redirect uses the stored location' do\n    user = User.new\n    @controller.session[:user_return_to] = \"/foo.bar\"\n    @mock_warden.expects(:user).with(:user).returns(nil)\n    @mock_warden.expects(:set_user).with(user, { scope: :user }).returns(true)\n    @controller.expects(:redirect_to).with(\"/foo.bar\")\n    @controller.sign_in_and_redirect(user)\n  end\n\n  test 'sign in and redirect uses the configured after sign in path' do\n    admin = Admin.new\n    @mock_warden.expects(:user).with(:admin).returns(nil)\n    @mock_warden.expects(:set_user).with(admin, { scope: :admin }).returns(true)\n    @controller.expects(:redirect_to).with(admin_root_path)\n    @controller.sign_in_and_redirect(admin)\n  end\n\n  test 'sign in and redirect does not sign in again if user is already signed' do\n    admin = Admin.new\n    @mock_warden.expects(:user).with(:admin).returns(admin)\n    @mock_warden.expects(:set_user).never\n    @controller.expects(:redirect_to).with(admin_root_path)\n    @controller.sign_in_and_redirect(admin)\n  end\n\n  test 'sign out and redirect uses the configured after sign out path when signing out only the current scope' do\n    swap Devise, sign_out_all_scopes: false do\n      @mock_warden.expects(:user).with(scope: :admin, run_callbacks: false).returns(true)\n      @mock_warden.expects(:logout).with(:admin).returns(true)\n      @mock_warden.expects(:clear_strategies_cache!).with(scope: :admin).returns(true)\n      @controller.expects(:redirect_to).with(admin_root_path)\n      @controller.instance_eval \"def after_sign_out_path_for(resource); admin_root_path; end\"\n      @controller.sign_out_and_redirect(:admin)\n    end\n  end\n\n  test 'sign out and redirect uses the configured after sign out path when signing out all scopes' do\n    swap Devise, sign_out_all_scopes: true do\n      @mock_warden.expects(:user).times(Devise.mappings.size)\n      @mock_warden.expects(:logout).with().returns(true)\n      @mock_warden.expects(:clear_strategies_cache!).with().returns(true)\n      @controller.expects(:redirect_to).with(admin_root_path)\n      @controller.instance_eval \"def after_sign_out_path_for(resource); admin_root_path; end\"\n      @controller.sign_out_and_redirect(:admin)\n    end\n  end\n\n  test 'is_flashing_format? depends on is_navigation_format?' do\n    @controller.expects(:is_navigational_format?).returns(true)\n    assert @controller.is_flashing_format?\n  end\n\n  test 'is_flashing_format? is guarded against flash (middleware) not being loaded' do\n    @controller.request.expects(:respond_to?).with(:flash).returns(false)\n    assert_not @controller.is_flashing_format?\n  end\n\n  test 'is not a devise controller' do\n    assert_not @controller.devise_controller?\n  end\nend\n"
  },
  {
    "path": "test/controllers/inherited_controller_i18n_messages_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass SessionsInheritedController < Devise::SessionsController\n  def test_i18n_scope\n    set_flash_message(:notice, :signed_in)\n  end\nend\n\nclass AnotherInheritedController < SessionsInheritedController\n  protected\n\n  def translation_scope\n    'another'\n  end\nend\n\nclass InheritedControllerTest < Devise::ControllerTestCase\n  tests SessionsInheritedController\n\n  def setup\n    @mock_warden = OpenStruct.new\n    @controller.request.env['warden'] = @mock_warden\n    @controller.request.env['devise.mapping'] = Devise.mappings[:user]\n  end\n\n  test 'I18n scope is inherited from Devise::Sessions' do\n    I18n.expects(:t).with do |message, options|\n      message == 'user.signed_in' &&\n        options[:scope] == 'devise.sessions'\n    end\n    @controller.test_i18n_scope\n  end\nend\n\nclass AnotherInheritedControllerTest < Devise::ControllerTestCase\n  tests AnotherInheritedController\n\n  def setup\n    @mock_warden = OpenStruct.new\n    @controller.request.env['warden'] = @mock_warden\n    @controller.request.env['devise.mapping'] = Devise.mappings[:user]\n  end\n\n  test 'I18n scope is overridden' do\n    I18n.expects(:t).with do |message, options|\n      message == 'user.signed_in' &&\n        options[:scope] == 'another'\n    end\n    @controller.test_i18n_scope\n  end\nend\n"
  },
  {
    "path": "test/controllers/internal_helpers_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass MyController < DeviseController\nend\n\nclass HelpersTest < Devise::ControllerTestCase\n  tests MyController\n\n  def setup\n    @mock_warden = OpenStruct.new\n    @controller.request.env['warden'] = @mock_warden\n    @controller.request.env['devise.mapping'] = Devise.mappings[:user]\n  end\n\n  test 'get resource name from env' do\n    assert_equal :user, @controller.send(:resource_name)\n  end\n\n  test 'get resource class from env' do\n    assert_equal User, @controller.send(:resource_class)\n  end\n\n  test 'get resource instance variable from env' do\n    @controller.instance_variable_set(:@user, user = User.new)\n    assert_equal user, @controller.send(:resource)\n  end\n\n  test 'set resource instance variable from env' do\n    user = @controller.send(:resource_class).new\n    @controller.send(:resource=, user)\n\n    assert_equal user, @controller.send(:resource)\n    assert_equal user, @controller.instance_variable_get(:@user)\n  end\n\n  test 'get resource params from request params using resource name as key' do\n    user_params = {'email' => 'shirley@templar.com'}\n\n    # Stub controller name so strong parameters can filter properly.\n    # DeviseController does not allow any parameters by default.\n    @controller.stubs(:controller_name).returns(:sessions_controller)\n\n    params = ActionController::Parameters.new({'user' => user_params})\n\n    @controller.stubs(:params).returns(params)\n\n    res_params = @controller.send(:resource_params).permit!.to_h\n    assert_equal user_params, res_params\n  end\n\n  test 'resources methods are not controller actions' do\n    assert_empty @controller.class.action_methods.delete_if { |m| m.include? 'commenter' }\n  end\n\n  test 'require no authentication tests current mapping' do\n    @mock_warden.expects(:authenticate?).with(:rememberable, { scope: :user }).returns(true)\n    @mock_warden.expects(:user).with(:user).returns(User.new)\n    @controller.expects(:redirect_to).with(root_path)\n    @controller.send :require_no_authentication\n  end\n\n  test 'require no authentication only checks if already authenticated if no inputs strategies are available' do\n    Devise.mappings[:user].expects(:no_input_strategies).returns([])\n    @mock_warden.expects(:authenticate?).never\n    @mock_warden.expects(:authenticated?).with(:user).once.returns(true)\n    @mock_warden.expects(:user).with(:user).returns(User.new)\n    @controller.expects(:redirect_to).with(root_path)\n    @controller.send :require_no_authentication\n  end\n\n  test 'require no authentication sets a flash message' do\n    @mock_warden.expects(:authenticate?).with(:rememberable, { scope: :user }).returns(true)\n    @mock_warden.expects(:user).with(:user).returns(User.new)\n    @controller.expects(:redirect_to).with(root_path)\n    @controller.send :require_no_authentication\n    assert flash[:alert] == I18n.t(\"devise.failure.already_authenticated\")\n  end\n\n  test 'signed in resource returns signed in resource for current scope' do\n    @mock_warden.expects(:authenticate).with(scope: :user).returns(User.new)\n    assert_kind_of User, @controller.send(:signed_in_resource)\n  end\n\n  test 'is a devise controller' do\n    assert @controller.devise_controller?\n  end\n\n  test 'does not issue blank flash messages' do\n    I18n.stubs(:t).returns('   ')\n    @controller.send :set_flash_message, :notice, :send_instructions\n    assert flash[:notice].nil?\n  end\n\n  test 'issues non-blank flash messages normally' do\n    I18n.stubs(:t).returns('non-blank')\n    @controller.send :set_flash_message, :notice, :send_instructions\n    assert_equal 'non-blank', flash[:notice]\n  end\n\n  test 'issues non-blank flash.now messages normally' do\n    I18n.stubs(:t).returns('non-blank')\n    @controller.send :set_flash_message, :notice, :send_instructions, { now: true }\n    assert_equal 'non-blank', flash.now[:notice]\n  end\n\n  test 'uses custom i18n options' do\n    @controller.stubs(:devise_i18n_options).returns(default: \"devise custom options\")\n    @controller.send :set_flash_message, :notice, :invalid_i18n_messagesend_instructions\n    assert_equal 'devise custom options', flash[:notice]\n  end\n\n  test 'allows custom i18n options to override resource_name' do\n    I18n.expects(:t).with(\"custom_resource_name.confirmed\", anything)\n    @controller.stubs(:devise_i18n_options).returns(resource_name: \"custom_resource_name\")\n    @controller.send :set_flash_message, :notice, :confirmed\n  end\n\n  test 'navigational_formats not returning a wild card' do\n    MyController.send(:public, :navigational_formats)\n\n    swap Devise, navigational_formats: ['*/*', :html] do\n      assert_not @controller.navigational_formats.include?(\"*/*\")\n    end\n\n    MyController.send(:protected, :navigational_formats)\n  end\nend\n"
  },
  {
    "path": "test/controllers/load_hooks_controller_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass LoadHooksControllerTest < Devise::ControllerTestCase\n  setup do\n    ActiveSupport.on_load(:devise_controller) do\n      define_method :defined_by_load_hook do\n        puts 'I am defined dynamically by activesupport load hook'\n      end\n    end\n  end\n\n  teardown do\n    DeviseController.class_eval { undef :defined_by_load_hook }\n  end\n\n  test 'load hook called when controller is loaded' do\n    assert_includes DeviseController.instance_methods, :defined_by_load_hook\n  end\nend\n"
  },
  {
    "path": "test/controllers/passwords_controller_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass PasswordsControllerTest < Devise::ControllerTestCase\n  tests Devise::PasswordsController\n  include Devise::Test::ControllerHelpers\n\n  setup do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    @user = create_user.tap(&:confirm)\n    @raw  = @user.send_reset_password_instructions\n  end\n\n  def put_update_with_params\n    put :update, params: { \"user\" => {\n        \"reset_password_token\" => @raw, \"password\" => \"1234567\", \"password_confirmation\" => \"1234567\"\n      }\n    }\n  end\n\n  test 'redirect to after_sign_in_path_for if after_resetting_password_path_for is not overridden' do\n    put_update_with_params\n    assert_redirected_to \"http://test.host/\"\n  end\n\n  test 'redirect accordingly if after_resetting_password_path_for is overridden' do\n    custom_path = \"http://custom.path/\"\n    Devise::PasswordsController.any_instance.stubs(:after_resetting_password_path_for).with(@user).returns(custom_path)\n\n    put_update_with_params\n    assert_redirected_to custom_path\n  end\n\n  test 'calls after_database_authentication callback after sign_in immediately after password update' do\n    User.any_instance.expects :after_database_authentication\n    put_update_with_params\n  end\nend\n"
  },
  {
    "path": "test/controllers/sessions_controller_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass SessionsControllerTest < Devise::ControllerTestCase\n  tests Devise::SessionsController\n  include Devise::Test::ControllerHelpers\n\n  test \"#create doesn't raise unpermitted params when sign in fails\" do\n    begin\n      subscriber = ActiveSupport::Notifications.subscribe %r{unpermitted_parameters} do |name, start, finish, id, payload|\n        flunk \"Unpermitted params: #{payload}\"\n      end\n      request.env[\"devise.mapping\"] = Devise.mappings[:user]\n      request.session[\"user_return_to\"] = 'foo.bar'\n      create_user\n      post :create, params: { user: {\n          email: \"wrong@email.com\",\n          password: \"wrongpassword\"\n        }\n      }\n      assert_equal 200, @response.status\n    ensure\n      ActiveSupport::Notifications.unsubscribe(subscriber)\n    end\n  end\n\n  test \"#create works even with scoped views\" do\n    swap Devise, scoped_views: true do\n      request.env[\"devise.mapping\"] = Devise.mappings[:user]\n      post :create\n      assert_equal 200, @response.status\n      assert_template \"users/sessions/new\"\n    end\n  end\n\n  test \"#create delete the url stored in the session if the requested format is navigational\" do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    request.session[\"user_return_to\"] = 'foo.bar'\n\n    user = create_user\n    user.confirm\n    post :create, params: { user: {\n        email: user.email,\n        password: user.password\n      }\n    }\n    assert_nil request.session[\"user_return_to\"]\n  end\n\n  test \"#create doesn't delete the url stored in the session if the requested format is not navigational\" do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    request.session[\"user_return_to\"] = 'foo.bar'\n\n    user = create_user\n    user.confirm\n    post :create, params: { format: 'json', user: {\n        email: user.email,\n        password: user.password\n      }\n    }\n\n    assert_equal 'foo.bar', request.session[\"user_return_to\"]\n  end\n\n  test \"#create doesn't raise exception after Warden authentication fails when TestHelpers included\" do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    post :create, params: { user: {\n        email: \"nosuchuser@example.com\",\n        password: \"wevdude\"\n      }\n    }\n    assert_equal 200, @response.status\n    assert_template \"devise/sessions/new\"\n  end\n\n  test \"#destroy doesn't set the flash and returns 204 status if the requested format is not navigational\" do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    user = create_user\n    user.confirm\n    post :create, params: { format: 'json', user: {\n        email: user.email,\n        password: user.password\n      }\n    }\n    delete :destroy, format: 'json'\n    assert flash[:notice].blank?, \"flash[:notice] should be blank, not #{flash[:notice].inspect}\"\n    assert_equal 204, @response.status\n  end\n\n  test \"#destroy returns 401 status if user is not signed in and the requested format is not navigational\" do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    delete :destroy, format: 'json'\n    assert_equal 401, @response.status\n  end\n\n  test \"#destroy returns 302 status if user is not signed in and the requested format is navigational\" do\n    request.env[\"devise.mapping\"] = Devise.mappings[:user]\n    delete :destroy\n    assert_equal 302, @response.status\n  end\nend\n"
  },
  {
    "path": "test/controllers/url_helpers_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass RoutesTest < Devise::ControllerTestCase\n  tests ApplicationController\n\n  def assert_path_and_url(name, prepend_path = nil)\n    @request.path = '/users/session'\n    prepend_path = \"#{prepend_path}_\" if prepend_path\n\n    # Resource param\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_path\", :user),\n                 send(:\"#{prepend_path}user_#{name}_path\")\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_url\", :user),\n                 send(:\"#{prepend_path}user_#{name}_url\")\n\n    # With string\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_path\", \"user\"),\n                 send(:\"#{prepend_path}user_#{name}_path\")\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_url\", \"user\"),\n                 send(:\"#{prepend_path}user_#{name}_url\")\n\n    # Default url params\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_path\", :user, param: 123),\n                 send(:\"#{prepend_path}user_#{name}_path\", param: 123)\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_url\", :user, param: 123),\n                 send(:\"#{prepend_path}user_#{name}_url\", param: 123)\n\n    @request.path = nil\n    # With an object\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_path\", User.new),\n                 send(:\"#{prepend_path}user_#{name}_path\")\n    assert_equal @controller.send(:\"#{prepend_path}#{name}_url\", User.new),\n                 send(:\"#{prepend_path}user_#{name}_url\")\n  end\n\n\n  test 'should alias session to mapped user session' do\n    assert_path_and_url :session\n    assert_path_and_url :session, :new\n    assert_path_and_url :session, :destroy\n  end\n\n  test 'should alias password to mapped user password' do\n    assert_path_and_url :password\n    assert_path_and_url :password, :new\n    assert_path_and_url :password, :edit\n  end\n\n  test 'should alias confirmation to mapped user confirmation' do\n    assert_path_and_url :confirmation\n    assert_path_and_url :confirmation, :new\n  end\n\n  test 'should alias unlock to mapped user unlock' do\n    assert_path_and_url :unlock\n    assert_path_and_url :unlock, :new\n  end\n\n  test 'should alias registration to mapped user registration' do\n    assert_path_and_url :registration\n    assert_path_and_url :registration, :new\n    assert_path_and_url :registration, :edit\n    assert_path_and_url :registration, :cancel\n  end\nend\n"
  },
  {
    "path": "test/delegator_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass DelegatorTest < ActiveSupport::TestCase\n  def delegator\n    Devise::Delegator.new\n  end\n\n  test 'failure_app returns default failure app if no warden options in env' do\n    assert_equal Devise::FailureApp, delegator.failure_app({})\n  end\n\n  test 'failure_app returns default failure app if no scope in warden options' do\n    assert_equal Devise::FailureApp, delegator.failure_app({\"warden.options\" => {}})\n  end\n\n  test 'failure_app returns associated failure app by scope in the given environment' do\n    assert_kind_of Proc, delegator.failure_app({\"warden.options\" => {scope: \"manager\"}})\n  end\nend\n"
  },
  {
    "path": "test/devise_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nmodule Devise\n  def self.yield_and_restore\n    @@warden_configured = nil\n    c, b = @@warden_config, @@warden_config_blocks\n    yield\n  ensure\n    @@warden_config, @@warden_config_blocks = c, b\n  end\nend\n\nclass DeviseTest < ActiveSupport::TestCase\n  test 'bcrypt on the class' do\n    password = \"super secret\"\n    klass    = Struct.new(:pepper, :stretches).new(\"blahblah\", 2)\n    hash     = Devise::Encryptor.digest(klass, password)\n    assert_equal ::BCrypt::Password.create(hash), hash\n\n    klass    = Struct.new(:pepper, :stretches).new(\"bla\", 2)\n    hash     = Devise::Encryptor.digest(klass, password)\n    assert_not_equal ::BCrypt::Password.new(hash), hash\n  end\n\n  test 'model options can be configured through Devise' do\n    swap Devise, allow_unconfirmed_access_for: 113, pepper: \"foo\" do\n      assert_equal 113, Devise.allow_unconfirmed_access_for\n      assert_equal \"foo\", Devise.pepper\n    end\n  end\n\n  test 'setup block yields self' do\n    Devise.setup do |config|\n      assert_equal Devise, config\n    end\n  end\n\n  test 'stores warden configuration' do\n    assert_kind_of Devise::Delegator, Devise.warden_config.failure_app\n    assert_equal :user, Devise.warden_config.default_scope\n  end\n\n  test 'warden manager user configuration through a block' do\n    Devise.yield_and_restore do\n      executed = false\n      Devise.warden do |config|\n        executed = true\n        assert_kind_of Warden::Config, config\n      end\n\n      Devise.configure_warden!\n      assert executed\n    end\n  end\n\n  test 'warden manager user configuration through multiple blocks' do\n    Devise.yield_and_restore do\n      executed = 0\n\n      3.times do\n        Devise.warden { |config| executed += 1 }\n      end\n\n      Devise.configure_warden!\n      assert_equal 3, executed\n    end\n  end\n\n  test 'add new module using the helper method' do\n    Devise.add_module(:coconut)\n    assert_equal 1, Devise::ALL.select { |v| v == :coconut }.size\n    assert_not Devise::STRATEGIES.include?(:coconut)\n    assert_not defined?(Devise::Models::Coconut)\n    Devise::ALL.delete(:coconut)\n\n    Devise.add_module(:banana, strategy: :fruits)\n    assert_equal :fruits, Devise::STRATEGIES[:banana]\n    Devise::ALL.delete(:banana)\n    Devise::STRATEGIES.delete(:banana)\n\n    Devise.add_module(:kivi, controller: :fruits)\n    assert_equal :fruits, Devise::CONTROLLERS[:kivi]\n    Devise::ALL.delete(:kivi)\n    Devise::CONTROLLERS.delete(:kivi)\n  end\n\n  test 'Devise.secure_compare fails when comparing different strings or nil' do\n    [nil, \"\"].each do |empty|\n      assert_not Devise.secure_compare(empty, \"something\")\n      assert_not Devise.secure_compare(\"something\", empty)\n    end\n    assert_not Devise.secure_compare(nil, nil)\n    assert_not Devise.secure_compare(\"size_1\", \"size_four\")\n  end\n\n  test 'Devise.secure_compare passes when strings are the same, even two empty strings' do\n    assert Devise.secure_compare(\"\", \"\")\n    assert Devise.secure_compare(\"something\", \"something\")\n  end\n\n  test 'Devise.email_regexp should match valid email addresses' do\n    valid_emails = [\"test@example.com\", \"jo@jo.co\", \"f4$_m@you.com\", \"testing.example@example.com.ua\", \"test@tt\", \"test@valid---domain.com\"]\n    non_valid_emails = [\"rex\", \"test user@example.com\", \"test_user@example server.com\"]\n\n    valid_emails.each do |email|\n      assert_match Devise.email_regexp, email\n    end\n    non_valid_emails.each do |email|\n      assert_no_match Devise.email_regexp, email\n    end\n  end\nend\n"
  },
  {
    "path": "test/failure_app_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\nrequire 'ostruct'\n\nclass FailureTest < ActiveSupport::TestCase\n  class RootFailureApp < Devise::FailureApp\n    def fake_app\n      Object.new\n    end\n  end\n\n  class FailureWithSubdomain < RootFailureApp\n    routes = ActionDispatch::Routing::RouteSet.new\n\n    routes.draw do\n      scope subdomain: 'sub' do\n        root to: 'foo#bar'\n      end\n    end\n\n    include routes.url_helpers\n  end\n\n  class FailureWithI18nOptions < Devise::FailureApp\n    def i18n_options(options)\n      options.merge(name: 'Steve')\n    end\n  end\n\n  class FailureWithoutRootPath < Devise::FailureApp\n    class FakeURLHelpers\n    end\n\n    class FakeRoutesWithoutRoot\n      def url_helpers\n        FakeURLHelpers.new\n      end\n    end\n\n    class FakeAppWithoutRootPath\n      def routes\n        FakeRoutesWithoutRoot.new\n      end\n    end\n\n    def main_app\n      FakeAppWithoutRootPath.new\n    end\n  end\n\n  class FakeEngineApp < Devise::FailureApp\n    class FakeEngine\n      def new_user_on_engine_session_url _\n        '/user_on_engines/sign_in'\n      end\n    end\n\n    def main_app\n      raise 'main_app router called instead of fake_engine'\n    end\n\n    def fake_engine\n      @fake_engine ||= FakeEngine.new\n    end\n  end\n\n  class RequestWithoutFlashSupport < ActionDispatch::Request\n    undef_method :flash\n  end\n\n  def self.context(name, &block)\n    instance_eval(&block)\n  end\n\n  def call_failure(env_params = {})\n    env = {\n      'REQUEST_URI' => 'http://test.host/',\n      'HTTP_HOST' => 'test.host',\n      'REQUEST_METHOD' => 'GET',\n      'warden.options' => { scope: :user },\n      'action_dispatch.request.formats' => Array(env_params.delete('formats') || Mime[:html]),\n      'rack.input' => \"\",\n      'warden' => OpenStruct.new(message: nil)\n    }.merge!(env_params)\n\n    # Passing nil for action_dispatch.request.formats prevents the default from being used in Rails 5, need to remove it\n    if env.has_key?('action_dispatch.request.formats') && env['action_dispatch.request.formats'].nil?\n      env.delete 'action_dispatch.request.formats' unless env['action_dispatch.request.formats']\n    end\n\n    @response = (env.delete(:app) || Devise::FailureApp).call(env).to_a\n    @request  = (env.delete(:request_klass) || ActionDispatch::Request).new(env)\n  end\n\n  context 'When redirecting' do\n    test 'returns to the default redirect location' do\n      call_failure\n      assert_equal 302, @response.first\n      assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]\n      assert_equal 'http://test.host/users/sign_in', @response.second['Location']\n    end\n\n    test 'returns to the default redirect location considering subdomain' do\n      call_failure('warden.options' => { scope: :subdomain_user })\n      assert_equal 302, @response.first\n      assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]\n      assert_equal 'http://sub.test.host/subdomain_users/sign_in', @response.second['Location']\n    end\n\n    test 'returns to the default redirect location for wildcard requests' do\n      call_failure 'action_dispatch.request.formats' => nil, 'HTTP_ACCEPT' => '*/*'\n      assert_equal 302, @response.first\n      assert_equal 'http://test.host/users/sign_in', @response.second['Location']\n    end\n\n    test 'returns to the root path if no session path is available' do\n      swap Devise, router_name: :fake_app do\n        call_failure app: RootFailureApp\n        assert_equal 302, @response.first\n        assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]\n        assert_equal 'http://test.host/', @response.second['Location']\n      end\n    end\n\n    test 'returns to the root path even when it\\'s not defined' do\n      call_failure app: FailureWithoutRootPath\n      assert_equal 302, @response.first\n      assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]\n      assert_equal 'http://test.host/', @response.second['Location']\n    end\n\n    test 'returns to the root path considering subdomain if no session path is available' do\n      swap Devise, router_name: :fake_app do\n        call_failure app: FailureWithSubdomain\n        assert_equal 302, @response.first\n        assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]\n        assert_equal 'http://sub.test.host/', @response.second['Location']\n      end\n    end\n\n    test 'returns to the default redirect location considering the router for supplied scope' do\n      call_failure app: FakeEngineApp, 'warden.options' => { scope: :user_on_engine }\n      assert_equal 302, @response.first\n      assert_equal 'You need to sign in or sign up before continuing.', @request.flash[:alert]\n      assert_equal 'http://test.host/user_on_engines/sign_in', @response.second['Location']\n    end\n\n    if Rails.application.config.respond_to?(:relative_url_root)\n      test 'returns to the default redirect location considering the relative url root' do\n        swap Rails.application.config, relative_url_root: \"/sample\" do\n          call_failure\n          assert_equal 302, @response.first\n          assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']\n        end\n      end\n\n      test 'returns to the default redirect location considering the relative url root and subdomain' do\n        swap Rails.application.config, relative_url_root: \"/sample\" do\n          call_failure('warden.options' => { scope: :subdomain_user })\n          assert_equal 302, @response.first\n          assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']\n        end\n      end\n    end\n\n    if Rails.application.config.action_controller.respond_to?(:relative_url_root)\n      test \"returns to the default redirect location considering action_controller's relative url root\" do\n        swap Rails.application.config.action_controller, relative_url_root: \"/sample\" do\n          call_failure\n          assert_equal 302, @response.first\n          assert_equal 'http://test.host/sample/users/sign_in', @response.second['Location']\n        end\n      end\n\n      test \"returns to the default redirect location considering action_controller's relative url root and subdomain\" do\n        swap Rails.application.config.action_controller, relative_url_root: \"/sample\" do\n          call_failure('warden.options' => { scope: :subdomain_user })\n          assert_equal 302, @response.first\n          assert_equal 'http://sub.test.host/sample/subdomain_users/sign_in', @response.second['Location']\n        end\n      end\n    end\n\n    test 'uses the proxy failure message as symbol' do\n      call_failure('warden' => OpenStruct.new(message: :invalid))\n      assert_equal 'Invalid email or password.', @request.flash[:alert]\n      assert_equal 'http://test.host/users/sign_in', @response.second[\"Location\"]\n    end\n\n    test 'supports authentication_keys as a Hash for the flash message' do\n      swap Devise, authentication_keys: { email: true, login: true } do\n        call_failure('warden' => OpenStruct.new(message: :invalid))\n        assert_equal 'Invalid email, login or password.', @request.flash[:alert]\n      end\n    end\n\n    test 'downcases authentication_keys for the flash message' do\n      call_failure('warden' => OpenStruct.new(message: :invalid))\n      assert_equal 'Invalid email or password.', @request.flash[:alert]\n    end\n\n    test 'humanizes the flash message' do\n      call_failure('warden' => OpenStruct.new(message: :invalid))\n      assert_equal @request.flash[:alert], @request.flash[:alert].humanize\n    end\n\n    test 'uses custom i18n options' do\n      call_failure('warden' => OpenStruct.new(message: :does_not_exist), app: FailureWithI18nOptions)\n      assert_equal 'User Steve does not exist', @request.flash[:alert]\n    end\n\n    test 'respects the i18n locale passed via warden options when redirecting' do\n      call_failure('warden' => OpenStruct.new(message: :invalid), 'warden.options' => { locale: :\"pt-BR\" })\n\n      assert_equal 'Email ou senha inválidos.', @request.flash[:alert]\n      assert_equal 'http://test.host/users/sign_in', @response.second[\"Location\"]\n\n      call_failure('warden' => OpenStruct.new(message: :invalid), 'warden.options' => { locale: :de })\n\n      assert_equal 'E-Mail oder Passwort ist ungültig.', @request.flash[:alert]\n      assert_equal 'http://test.host/users/sign_in', @response.second[\"Location\"]\n    end\n\n    test 'uses the proxy failure message as string' do\n      call_failure('warden' => OpenStruct.new(message: 'Hello world'))\n      assert_equal 'Hello world', @request.flash[:alert]\n      assert_equal 'http://test.host/users/sign_in', @response.second[\"Location\"]\n    end\n\n    test 'set content type to default text/html' do\n      call_failure\n      assert_equal 'text/html; charset=utf-8', @response.second['Content-Type']\n    end\n\n    test 'set up a default message' do\n      call_failure\n      if Devise::Test.rails71_and_up?\n        assert_empty @response.last.body\n      else\n        assert_match(/You are being/, @response.last.body)\n        assert_match(/redirected/, @response.last.body)\n        assert_match(/users\\/sign_in/, @response.last.body)\n      end\n    end\n\n    test 'works for any navigational format' do\n      swap Devise, navigational_formats: [:json] do\n        call_failure('formats' => Mime[:json])\n        assert_equal 302, @response.first\n      end\n    end\n\n    test 'redirects the correct format if it is a non-html format request' do\n      swap Devise, navigational_formats: [:js] do\n        call_failure('formats' => Mime[:js])\n        assert_equal 'http://test.host/users/sign_in.js', @response.second[\"Location\"]\n      end\n    end\n  end\n\n  context 'For HTTP request' do\n    test 'return 401 status' do\n      call_failure('formats' => Mime[:json])\n      assert_equal 401, @response.first\n    end\n\n    test 'return appropriate body for xml' do\n      call_failure('formats' => Mime[:xml])\n      result = %(<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n<errors>\\n  <error>You need to sign in or sign up before continuing.</error>\\n</errors>\\n)\n      assert_equal result, @response.last.body\n    end\n\n    test 'return appropriate body for json' do\n      call_failure('formats' => Mime[:json])\n      result = %({\"error\":\"You need to sign in or sign up before continuing.\"})\n      assert_equal result, @response.last.body\n    end\n\n    test 'return 401 status for unknown formats' do\n      call_failure 'formats' => []\n      assert_equal 401, @response.first\n    end\n\n    test 'return WWW-authenticate headers if model allows' do\n      call_failure('formats' => Mime[:json])\n      assert_equal 'Basic realm=\"Application\"', @response.second[\"WWW-Authenticate\"]\n    end\n\n    test 'does not return WWW-authenticate headers if model does not allow' do\n      swap Devise, http_authenticatable: false do\n        call_failure('formats' => Mime[:json])\n        assert_nil @response.second[\"WWW-Authenticate\"]\n      end\n    end\n\n    test 'works for any non navigational format' do\n      swap Devise, navigational_formats: [] do\n        call_failure('formats' => Mime[:html])\n        assert_equal 401, @response.first\n      end\n    end\n\n    test 'uses the failure message as response body' do\n      call_failure('formats' => Mime[:xml], 'warden' => OpenStruct.new(message: :invalid))\n      assert_match '<error>Invalid email or password.</error>', @response.third.body\n    end\n\n    test 'respects the i18n locale passed via warden options when responding to HTTP request' do\n      call_failure('formats' => Mime[:json], 'warden' => OpenStruct.new(message: :invalid), 'warden.options' => { locale: :\"pt-BR\" })\n\n      assert_equal %({\"error\":\"Email ou senha inválidos.\"}), @response.third.body\n    end\n\n    context 'on ajax call' do\n      context 'when http_authenticatable_on_xhr is false' do\n        test 'dont return 401 with navigational formats' do\n          swap Devise, http_authenticatable_on_xhr: false do\n            call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')\n            assert_equal 302, @response.first\n            assert_equal 'http://test.host/users/sign_in', @response.second[\"Location\"]\n          end\n        end\n\n        test 'dont return 401 with non navigational formats' do\n          swap Devise, http_authenticatable_on_xhr: false do\n            call_failure('formats' => Mime[:json], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')\n            assert_equal 302, @response.first\n            assert_equal 'http://test.host/users/sign_in.json', @response.second[\"Location\"]\n          end\n        end\n      end\n\n      context 'when http_authenticatable_on_xhr is true' do\n        test 'return 401' do\n          swap Devise, http_authenticatable_on_xhr: true do\n            call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')\n            assert_equal 401, @response.first\n          end\n        end\n\n        test 'skip WWW-Authenticate header' do\n          swap Devise, http_authenticatable_on_xhr: true do\n            call_failure('formats' => Mime[:html], 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest')\n            assert_nil @response.second['WWW-Authenticate']\n          end\n        end\n      end\n    end\n  end\n\n  context 'With recall' do\n    test 'calls the original controller if invalid email or password' do\n      env = {\n        \"warden.options\" => { recall: \"devise/sessions#new\", attempted_path: \"/users/sign_in\" },\n        \"devise.mapping\" => Devise.mappings[:user],\n        \"warden\" => stub_everything\n      }\n      call_failure(env)\n      assert_includes @response.third.body, '<h2>Log in</h2>'\n      assert_includes @response.third.body, 'Invalid email or password.'\n    end\n\n    test 'calls the original controller if not confirmed email' do\n      env = {\n        \"warden.options\" => { recall: \"devise/sessions#new\", attempted_path: \"/users/sign_in\", message: :unconfirmed },\n        \"devise.mapping\" => Devise.mappings[:user],\n        \"warden\" => stub_everything\n      }\n      call_failure(env)\n      assert_includes @response.third.body, '<h2>Log in</h2>'\n      assert_includes @response.third.body, 'You have to confirm your email address before continuing.'\n    end\n\n    test 'calls the original controller if inactive account' do\n      env = {\n        \"warden.options\" => { recall: \"devise/sessions#new\", attempted_path: \"/users/sign_in\", message: :inactive },\n        \"devise.mapping\" => Devise.mappings[:user],\n        \"warden\" => stub_everything\n      }\n      call_failure(env)\n      assert_includes @response.third.body, '<h2>Log in</h2>'\n      assert_includes @response.third.body, 'Your account is not activated yet.'\n    end\n\n    if Rails.application.config.respond_to?(:relative_url_root)\n      test 'calls the original controller with the proper environment considering the relative url root' do\n        swap Rails.application.config, relative_url_root: \"/sample\" do\n          env = {\n            \"warden.options\" => { recall: \"devise/sessions#new\", attempted_path: \"/sample/users/sign_in\"},\n            \"devise.mapping\" => Devise.mappings[:user],\n            \"warden\" => stub_everything\n          }\n          call_failure(env)\n          assert_includes @response.third.body, '<h2>Log in</h2>'\n          assert_includes @response.third.body, 'Invalid email or password.'\n          assert_equal '/sample', @request.env[\"SCRIPT_NAME\"]\n          assert_equal '/users/sign_in', @request.env[\"PATH_INFO\"]\n        end\n      end\n    end\n\n    test 'respects the i18n locale passed via warden options when recalling original controller' do\n      env = {\n        \"warden.options\" => { recall: \"devise/sessions#new\", attempted_path: \"/users/sign_in\", locale: :\"pt-BR\" },\n        \"devise.mapping\" => Devise.mappings[:user],\n        \"warden\" => stub_everything\n      }\n      call_failure(env)\n\n      assert_includes @response.third.body, '<h2>Log in</h2>'\n      assert_includes @response.third.body, 'Email ou senha inválidos.'\n    end\n\n    # TODO: remove conditional/else when supporting only responders 3.1+\n    if ActionController::Responder.respond_to?(:error_status=)\n      test 'respects the configured responder `error_status` for the status code' do\n        swap Devise.responder, error_status: :unprocessable_entity do\n          env = {\n            \"warden.options\" => { recall: \"devise/sessions#new\", attempted_path: \"/users/sign_in\" },\n            \"devise.mapping\" => Devise.mappings[:user],\n            \"warden\" => stub_everything\n          }\n          call_failure(env)\n\n          assert_equal 422, @response.first\n          assert_includes @response.third.body, 'Invalid email or password.'\n        end\n      end\n\n      test 'respects the configured responder `redirect_status` if the recall app returns a redirect status code' do\n        swap Devise.responder, redirect_status: :see_other do\n          env = {\n            \"warden.options\" => { recall: \"devise/registrations#cancel\", attempted_path: \"/users/cancel\" },\n            \"devise.mapping\" => Devise.mappings[:user],\n            \"warden\" => stub_everything\n          }\n          call_failure(env)\n\n          assert_equal 303, @response.first\n        end\n      end\n    else\n      test 'uses default hardcoded responder `error_status` for the status code since responders version does not support configuring it' do\n        env = {\n          \"warden.options\" => { recall: \"devise/sessions#new\", attempted_path: \"/users/sign_in\" },\n          \"devise.mapping\" => Devise.mappings[:user],\n          \"warden\" => stub_everything\n        }\n        call_failure(env)\n\n        assert_equal 200, @response.first\n        assert_includes @response.third.body, 'Invalid email or password.'\n      end\n\n      test 'users default hardcoded responder `redirect_status` for the status code since responders version does not support configuring it' do\n        env = {\n          \"warden.options\" => { recall: \"devise/registrations#cancel\", attempted_path: \"/users/cancel\" },\n          \"devise.mapping\" => Devise.mappings[:user],\n          \"warden\" => stub_everything\n        }\n        call_failure(env)\n\n        assert_equal 302, @response.first\n      end\n    end\n  end\n\n  context \"Lazy loading\" do\n    test \"loads\" do\n      assert_equal \"yes it does\", Devise::FailureApp.new.lazy_loading_works?\n    end\n  end\n\n  context \"Without Flash Support\" do\n    test \"returns to the default redirect location without a flash message\" do\n      call_failure request_klass: RequestWithoutFlashSupport\n      assert_equal 302, @response.first\n      assert_equal 'http://test.host/users/sign_in', @response.second['Location']\n    end\n  end\nend\n"
  },
  {
    "path": "test/generators/active_record_generator_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"test_helper\"\n\nif DEVISE_ORM == :active_record\n  require \"generators/active_record/devise_generator\"\n\n  class ActiveRecordGeneratorTest < Rails::Generators::TestCase\n    tests ActiveRecord::Generators::DeviseGenerator\n    destination File.expand_path(\"../../tmp\", __FILE__)\n    setup :prepare_destination\n\n    test \"all files are properly created with rails31 migration syntax\" do\n      run_generator %w(monster)\n      assert_migration \"db/migrate/devise_create_monsters.rb\", /def change/\n    end\n\n    test \"all files are properly created with changed db/migrate path in application configuration\" do\n      old_paths = Rails.application.config.paths[\"db/migrate\"]\n      Rails.application.config.paths.add \"db/migrate\", with: \"db2/migrate\"\n\n      run_generator %w(monster)\n      assert_migration \"db2/migrate/devise_create_monsters.rb\", /def change/\n\n      Rails.application.config.paths[\"db/migrate\"] = old_paths\n    end\n\n    test \"all files for namespaced model are properly created\" do\n      run_generator %w(admin/monster)\n      assert_migration \"db/migrate/devise_create_admin_monsters.rb\", /def change/\n    end\n\n    test \"update model migration when model exists\" do\n      run_generator %w(monster)\n      assert_file \"app/models/monster.rb\"\n      run_generator %w(monster)\n      assert_migration \"db/migrate/add_devise_to_monsters.rb\"\n    end\n\n    test \"update model migration when model exists with changed db/migrate path in application configuration\" do\n      old_paths = Rails.application.config.paths[\"db/migrate\"]\n      Rails.application.config.paths.add \"db/migrate\", with: \"db2/migrate\"\n\n      run_generator %w(monster)\n      assert_file \"app/models/monster.rb\"\n      run_generator %w(monster)\n\n      assert_migration \"db2/migrate/add_devise_to_monsters.rb\"\n\n      Rails.application.config.paths[\"db/migrate\"] = old_paths\n    end\n\n    test \"all files are properly deleted\" do\n      run_generator %w(monster)\n      run_generator %w(monster)\n      assert_migration \"db/migrate/devise_create_monsters.rb\"\n      assert_migration \"db/migrate/add_devise_to_monsters.rb\"\n      run_generator %w(monster), behavior: :revoke\n      assert_no_migration \"db/migrate/add_devise_to_monsters.rb\"\n      assert_migration \"db/migrate/devise_create_monsters.rb\"\n      run_generator %w(monster), behavior: :revoke\n      assert_no_file \"app/models/monster.rb\"\n      assert_no_migration \"db/migrate/devise_create_monsters.rb\"\n    end\n\n    test \"use string column type for ip addresses\" do\n      run_generator %w(monster)\n      assert_migration \"db/migrate/devise_create_monsters.rb\", /t.string   :current_sign_in_ip/\n      assert_migration \"db/migrate/devise_create_monsters.rb\", /t.string   :last_sign_in_ip/\n    end\n\n    test \"do NOT add primary key type when NOT specified in rails generator\" do\n      run_generator %w(monster)\n      assert_migration \"db/migrate/devise_create_monsters.rb\", /create_table :monsters do/\n    end\n\n    test \"add primary key type with rails 5 when specified in rails generator\" do\n      run_generator [\"monster\", \"--primary_key_type=uuid\"]\n      assert_migration \"db/migrate/devise_create_monsters.rb\", /create_table :monsters, id: :uuid do/\n    end\n  end\n\n  module RailsEngine\n    class Engine < Rails::Engine\n      isolate_namespace RailsEngine\n    end\n  end\n\n  def simulate_inside_engine(engine, namespace)\n    if Rails::Generators.respond_to?(:namespace=)\n      swap Rails::Generators, namespace: namespace do\n        yield\n      end\n    else\n      swap Rails, application: engine.instance do\n        yield\n      end\n    end\n  end\n\n  class ActiveRecordEngineGeneratorTest < Rails::Generators::TestCase\n    tests ActiveRecord::Generators::DeviseGenerator\n    destination File.expand_path(\"../../tmp\", __FILE__)\n    setup :prepare_destination\n\n    test \"all files are properly created in rails 4.0\" do\n      simulate_inside_engine(RailsEngine::Engine, RailsEngine) do\n        run_generator [\"monster\"]\n\n        assert_file \"app/models/rails_engine/monster.rb\", /devise/\n        assert_file \"app/models/rails_engine/monster.rb\" do |content|\n          assert_no_match %r{attr_accessible :email}, content\n        end\n      end\n    end\n\n  end\nend\n"
  },
  {
    "path": "test/generators/controllers_generator_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"test_helper\"\n\nclass ControllersGeneratorTest < Rails::Generators::TestCase\n  tests Devise::Generators::ControllersGenerator\n  destination File.expand_path(\"../../tmp\", __FILE__)\n  setup :prepare_destination\n\n  test \"Assert no controllers are created with no params\" do\n    capture(:stderr) { run_generator }\n    assert_no_file \"app/controllers/sessions_controller.rb\"\n    assert_no_file \"app/controllers/registrations_controller.rb\"\n    assert_no_file \"app/controllers/confirmations_controller.rb\"\n    assert_no_file \"app/controllers/passwords_controller.rb\"\n    assert_no_file \"app/controllers/unlocks_controller.rb\"\n    assert_no_file \"app/controllers/omniauth_callbacks_controller.rb\"\n  end\n\n  test \"Assert all controllers are properly created with scope param\" do\n    run_generator %w(users)\n    assert_class_names 'users'\n\n    run_generator %w(admins)\n    assert_class_names 'admins'\n  end\n\n  test \"Assert specified controllers with scope\" do\n    run_generator %w(users -c sessions)\n    assert_file \"app/controllers/users/sessions_controller.rb\"\n    assert_no_file \"app/controllers/users/registrations_controller.rb\"\n    assert_no_file \"app/controllers/users/confirmations_controller.rb\"\n    assert_no_file \"app/controllers/users/passwords_controller.rb\"\n    assert_no_file \"app/controllers/users/unlocks_controller.rb\"\n    assert_no_file \"app/controllers/users/omniauth_callbacks_controller.rb\"\n  end\n\n  private\n\n    def assert_class_names(scope, options = {})\n      base_dir = \"app/controllers#{scope.blank? ? '' : ('/' + scope)}\"\n      scope_prefix = scope.blank? ? '' : (scope.camelize + '::')\n      controllers = options[:controllers] ||\n        %w(confirmations passwords registrations sessions unlocks omniauth_callbacks)\n\n      controllers.each do |c|\n        assert_file \"#{base_dir}/#{c}_controller.rb\", /#{scope_prefix + c.camelize}/\n      end\n    end\nend\n"
  },
  {
    "path": "test/generators/devise_generator_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nrequire \"generators/devise/devise_generator\"\n\nclass DeviseGeneratorTest < Rails::Generators::TestCase\n  tests Devise::Generators::DeviseGenerator\n  destination File.expand_path(\"../../tmp\", __FILE__)\n\n  setup do\n    prepare_destination\n    copy_routes\n  end\n\n  test \"route generation for simple model names\" do\n    run_generator %w(monster name:string)\n    assert_file \"config/routes.rb\", /devise_for :monsters/\n  end\n\n  test \"route generation for namespaced model names\" do\n    run_generator %w(monster/goblin name:string)\n    match = /devise_for :goblins, class_name: \"Monster::Goblin\"/\n    assert_file \"config/routes.rb\", match\n  end\n\n  test \"route generation with skip routes\" do\n    run_generator %w(monster name:string --skip-routes)\n    match = /devise_for :monsters, skip: :all/\n    assert_file \"config/routes.rb\", match\n  end\n\n  def copy_routes\n    routes = File.expand_path(\"../../rails_app/config/routes.rb\", __FILE__)\n    destination = File.join(destination_root, \"config\")\n\n    FileUtils.mkdir_p(destination)\n    FileUtils.cp routes, destination\n  end\nend\n"
  },
  {
    "path": "test/generators/install_generator_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"test_helper\"\n\nclass InstallGeneratorTest < Rails::Generators::TestCase\n  tests Devise::Generators::InstallGenerator\n  destination File.expand_path(\"../../tmp\", __FILE__)\n  setup :prepare_destination\n\n  test \"assert all files are properly created\" do\n    run_generator([\"--orm=active_record\"])\n    assert_file \"config/initializers/devise.rb\", /devise\\/orm\\/active_record/\n    assert_file \"config/locales/devise.en.yml\"\n  end\n\n  test \"fails if no ORM is specified\" do\n    stderr = capture(:stderr) do\n      run_generator\n    end\n\n    assert_match %r{An ORM must be set to install Devise}, stderr\n\n    assert_no_file \"config/initializers/devise.rb\"\n    assert_no_file \"config/locales/devise.en.yml\"\n  end\n\n  test \"responder error_status based on rack version\" do\n    run_generator([\"--orm=active_record\"])\n\n    error_status = Rack::RELEASE >= \"3.1\" ? :unprocessable_content : :unprocessable_entity\n\n    assert_file \"config/initializers/devise.rb\", /config\\.responder\\.error_status = #{error_status.inspect}/\n  end\nend\n"
  },
  {
    "path": "test/generators/mongoid_generator_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"test_helper\"\n\nif DEVISE_ORM == :mongoid\n  require \"generators/mongoid/devise_generator\"\n\n  class MongoidGeneratorTest < Rails::Generators::TestCase\n    tests Mongoid::Generators::DeviseGenerator\n    destination File.expand_path(\"../../tmp\", __FILE__)\n    setup :prepare_destination\n\n    test \"all files are properly created\" do\n      run_generator %w(monster)\n      assert_file \"app/models/monster.rb\", /devise/\n    end\n\n    test \"all files are properly deleted\" do\n      run_generator %w(monster)\n      run_generator %w(monster), behavior: :revoke\n      assert_no_file \"app/models/monster.rb\"\n    end\n  end\nend\n\n"
  },
  {
    "path": "test/generators/views_generator_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"test_helper\"\n\nclass ViewsGeneratorTest < Rails::Generators::TestCase\n  tests Devise::Generators::ViewsGenerator\n  destination File.expand_path(\"../../tmp\", __FILE__)\n  setup :prepare_destination\n\n  test \"Assert all views are properly created with no params\" do\n    run_generator\n    assert_files\n    assert_shared_links\n    assert_error_messages\n  end\n\n  test \"Assert all views are properly created with scope param\" do\n    run_generator %w(users)\n    assert_files \"users\"\n    assert_shared_links \"users\"\n    assert_error_messages \"users\"\n\n    run_generator %w(admins)\n    assert_files \"admins\"\n    assert_shared_links \"admins\"\n    assert_error_messages \"admins\"\n  end\n\n  test \"Assert views with simple form\" do\n    run_generator %w(-b simple_form_for)\n    assert_files\n    assert_file \"app/views/devise/confirmations/new.html.erb\", /simple_form_for/\n\n    run_generator %w(users -b simple_form_for)\n    assert_files \"users\"\n    assert_file \"app/views/users/confirmations/new.html.erb\", /simple_form_for/\n  end\n\n  test \"Assert views with markerb\" do\n    run_generator %w(--markerb)\n    assert_files nil, mail_template_engine: \"markerb\"\n  end\n\n\n  test \"Assert only views within specified directories\" do\n    run_generator %w(-v sessions registrations)\n    assert_file \"app/views/devise/sessions/new.html.erb\"\n    assert_file \"app/views/devise/registrations/new.html.erb\"\n    assert_file \"app/views/devise/registrations/edit.html.erb\"\n    assert_no_file \"app/views/devise/confirmations/new.html.erb\"\n    assert_no_file \"app/views/devise/mailer/confirmation_instructions.html.erb\"\n  end\n\n  test \"Assert mailer specific directory with simple form\" do\n    run_generator %w(-v mailer -b simple_form_for)\n    assert_file \"app/views/devise/mailer/confirmation_instructions.html.erb\"\n    assert_file \"app/views/devise/mailer/reset_password_instructions.html.erb\"\n    assert_file \"app/views/devise/mailer/unlock_instructions.html.erb\"\n  end\n\n  test \"Assert specified directories with scope\" do\n    run_generator %w(users -v sessions)\n    assert_file \"app/views/users/sessions/new.html.erb\"\n    assert_no_file \"app/views/users/confirmations/new.html.erb\"\n  end\n\n  test \"Assert specified directories with simple form\" do\n    run_generator %w(-v registrations -b simple_form_for)\n    assert_file \"app/views/devise/registrations/new.html.erb\", /simple_form_for/\n    assert_no_file \"app/views/devise/confirmations/new.html.erb\"\n    end\n\n  test \"Assert specified directories with markerb\" do\n    run_generator %w(--markerb -v passwords mailer)\n    assert_file \"app/views/devise/passwords/new.html.erb\"\n    assert_no_file \"app/views/devise/confirmations/new.html.erb\"\n    assert_file \"app/views/devise/mailer/reset_password_instructions.markerb\"\n  end\n\n  def assert_files(scope = nil, options = {})\n    scope = \"devise\" if scope.nil?\n    mail_template_engine = options[:mail_template_engine] || \"html.erb\"\n\n    assert_file \"app/views/#{scope}/confirmations/new.html.erb\"\n    assert_file \"app/views/#{scope}/mailer/confirmation_instructions.#{mail_template_engine}\"\n    assert_file \"app/views/#{scope}/mailer/reset_password_instructions.#{mail_template_engine}\"\n    assert_file \"app/views/#{scope}/mailer/unlock_instructions.#{mail_template_engine}\"\n    assert_file \"app/views/#{scope}/passwords/edit.html.erb\"\n    assert_file \"app/views/#{scope}/passwords/new.html.erb\"\n    assert_file \"app/views/#{scope}/registrations/new.html.erb\"\n    assert_file \"app/views/#{scope}/registrations/edit.html.erb\"\n    assert_file \"app/views/#{scope}/sessions/new.html.erb\"\n    assert_file \"app/views/#{scope}/shared/_links.html.erb\"\n    assert_file \"app/views/#{scope}/shared/_error_messages.html.erb\"\n    assert_file \"app/views/#{scope}/unlocks/new.html.erb\"\n  end\n\n  def assert_shared_links(scope = nil)\n    scope = \"devise\" if scope.nil?\n    link = /<%= render \\\"#{scope}\\/shared\\/links\\\" %>/\n\n    assert_file \"app/views/#{scope}/passwords/edit.html.erb\", link\n    assert_file \"app/views/#{scope}/passwords/new.html.erb\", link\n    assert_file \"app/views/#{scope}/confirmations/new.html.erb\", link\n    assert_file \"app/views/#{scope}/registrations/new.html.erb\", link\n    assert_file \"app/views/#{scope}/sessions/new.html.erb\", link\n    assert_file \"app/views/#{scope}/unlocks/new.html.erb\", link\n  end\n\n  def assert_error_messages(scope = nil)\n    scope = \"devise\" if scope.nil?\n    link = /<%= render \\\"#{scope}\\/shared\\/error_messages\\\", resource: resource %>/\n\n    assert_file \"app/views/#{scope}/passwords/edit.html.erb\", link\n    assert_file \"app/views/#{scope}/passwords/new.html.erb\", link\n    assert_file \"app/views/#{scope}/confirmations/new.html.erb\", link\n    assert_file \"app/views/#{scope}/registrations/new.html.erb\", link\n    assert_file \"app/views/#{scope}/registrations/edit.html.erb\", link\n    assert_file \"app/views/#{scope}/unlocks/new.html.erb\", link\n  end\nend\n"
  },
  {
    "path": "test/helpers/devise_helper_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass DeviseHelperTest < Devise::IntegrationTest\n  setup do\n    model_labels = { models: { user: \"the user\" } }\n    translations = {\n      errors: { messages: { not_saved: {\n        one: \"Can't save %{resource} because of 1 error\",\n        other: \"Can't save %{resource} because of %{count} errors\",\n      } } },\n      activerecord: model_labels,\n      mongoid: model_labels\n    }\n\n    I18n.available_locales\n    I18n.backend.store_translations(:en, translations)\n  end\n\n  teardown do\n    I18n.reload!\n  end\n\n  test 'test errors.messages.not_saved with single error from i18n' do\n    get new_user_registration_path\n\n    fill_in 'password', with: 'new_user123'\n    fill_in 'password confirmation', with: 'new_user123'\n    click_button 'Sign up'\n\n    assert_have_selector '#error_explanation'\n    assert_contain \"Can't save the user because of 1 error\"\n  end\n\n  test 'test errors.messages.not_saved with multiple errors from i18n' do\n    get new_user_registration_path\n\n    fill_in 'email', with: 'invalid_email'\n    fill_in 'password', with: 'new_user123'\n    fill_in 'password confirmation', with: 'new_user321'\n    click_button 'Sign up'\n\n    assert_have_selector '#error_explanation'\n    assert_contain \"Can't save the user because of 2 errors\"\n  end\nend\n"
  },
  {
    "path": "test/integration/authenticatable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass AuthenticationSanityTest < Devise::IntegrationTest\n  test 'sign in should not run model validations' do\n    sign_in_as_user\n\n    assert_not User.validations_performed\n  end\n\n  test 'home should be accessible without sign in' do\n    visit '/'\n    assert_response :success\n    assert_template 'home/index'\n  end\n\n  test 'sign in as user should not authenticate admin scope' do\n    sign_in_as_user\n    assert warden.authenticated?(:user)\n    assert_not warden.authenticated?(:admin)\n  end\n\n  test 'sign in as admin should not authenticate user scope' do\n    sign_in_as_admin\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'sign in as both user and admin at same time' do\n    sign_in_as_user\n    sign_in_as_admin\n    assert warden.authenticated?(:user)\n    assert warden.authenticated?(:admin)\n  end\n\n  test 'sign out as user should not touch admin authentication if sign_out_all_scopes is false' do\n    swap Devise, sign_out_all_scopes: false do\n      sign_in_as_user\n      sign_in_as_admin\n      delete destroy_user_session_path\n      assert_not warden.authenticated?(:user)\n      assert warden.authenticated?(:admin)\n    end\n  end\n\n  test 'sign out as admin should not touch user authentication if sign_out_all_scopes is false' do\n    swap Devise, sign_out_all_scopes: false do\n      sign_in_as_user\n      sign_in_as_admin\n\n      delete destroy_admin_session_path\n      assert_not warden.authenticated?(:admin)\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'sign out as user should also sign out admin if sign_out_all_scopes is true' do\n    swap Devise, sign_out_all_scopes: true do\n      sign_in_as_user\n      sign_in_as_admin\n\n      delete destroy_user_session_path\n      assert_not warden.authenticated?(:user)\n      assert_not warden.authenticated?(:admin)\n    end\n  end\n\n  test 'sign out as admin should also sign out user if sign_out_all_scopes is true' do\n    swap Devise, sign_out_all_scopes: true do\n      sign_in_as_user\n      sign_in_as_admin\n\n      delete destroy_admin_session_path\n      assert_not warden.authenticated?(:admin)\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'not signed in as admin should not be able to access admins actions' do\n    get admins_path\n    assert_redirected_to new_admin_session_path\n    assert_not warden.authenticated?(:admin)\n  end\n\n  test 'signed in as user should not be able to access admins actions' do\n    sign_in_as_user\n    assert warden.authenticated?(:user)\n    assert_not warden.authenticated?(:admin)\n\n    get admins_path\n    assert_redirected_to new_admin_session_path\n  end\n\n  test 'signed in as admin should be able to access admin actions' do\n    sign_in_as_admin\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n\n    get admins_path\n\n    assert_response :success\n    assert_template 'admins/index'\n    assert_contain 'Welcome Admin'\n  end\n\n  test 'authenticated admin should not be able to sign as admin again' do\n    sign_in_as_admin\n    get new_admin_session_path\n\n    assert_response :redirect\n    assert_redirected_to admin_root_path\n    assert warden.authenticated?(:admin)\n  end\n\n  test 'authenticated admin should be able to sign out' do\n    sign_in_as_admin\n    assert warden.authenticated?(:admin)\n\n    delete destroy_admin_session_path\n    assert_response :redirect\n    assert_redirected_to root_path\n\n    get root_path\n    assert_contain 'Signed out successfully'\n    assert_not warden.authenticated?(:admin)\n  end\n\n  test 'unauthenticated admin set message on sign out' do\n    delete destroy_admin_session_path\n    assert_response :redirect\n    assert_redirected_to root_path\n\n    get root_path\n    assert_contain 'Signed out successfully'\n  end\n\n  test 'scope uses custom failure app' do\n    put \"/en/accounts/management\"\n    assert_equal \"Oops, not found\", response.body\n    assert_equal 404, response.status\n  end\nend\n\nclass AuthenticationRoutesRestrictions < Devise::IntegrationTest\n  test 'not signed in should not be able to access private route (authenticate denied)' do\n    get private_path\n    assert_redirected_to new_admin_session_path\n    assert_not warden.authenticated?(:admin)\n  end\n\n  test 'signed in as user should not be able to access private route restricted to admins (authenticate denied)' do\n    sign_in_as_user\n    assert warden.authenticated?(:user)\n    assert_not warden.authenticated?(:admin)\n    get private_path\n    assert_redirected_to new_admin_session_path\n  end\n\n  test 'signed in as admin should be able to access private route restricted to admins (authenticate accepted)' do\n    sign_in_as_admin\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n\n    get private_path\n\n    assert_response :success\n    assert_template 'home/private'\n    assert_contain 'Private!'\n  end\n\n  test 'signed in as inactive admin should not be able to access private/active route restricted to active admins (authenticate denied)' do\n    sign_in_as_admin(active: false)\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n\n    assert_raises ActionController::RoutingError do\n      get \"/private/active\"\n    end\n  end\n\n  test 'signed in as active admin should be able to access private/active route restricted to active admins (authenticate accepted)' do\n    sign_in_as_admin(active: true)\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n\n    get private_active_path\n\n    assert_response :success\n    assert_template 'home/private'\n    assert_contain 'Private!'\n  end\n\n  test 'signed in as admin should get admin dashboard (authenticated accepted)' do\n    sign_in_as_admin\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n\n    get dashboard_path\n\n    assert_response :success\n    assert_template 'home/admin_dashboard'\n    assert_contain 'Admin dashboard'\n  end\n\n  test 'signed in as user should get user dashboard (authenticated accepted)' do\n    sign_in_as_user\n    assert warden.authenticated?(:user)\n    assert_not warden.authenticated?(:admin)\n\n    get dashboard_path\n\n    assert_response :success\n    assert_template 'home/user_dashboard'\n    assert_contain 'User dashboard'\n  end\n\n  test 'not signed in should get no dashboard (authenticated denied)' do\n    assert_raises ActionController::RoutingError do\n      get dashboard_path\n    end\n  end\n\n  test 'signed in as inactive admin should not be able to access dashboard/active route restricted to active admins (authenticated denied)' do\n    sign_in_as_admin(active: false)\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n\n    assert_raises ActionController::RoutingError do\n      get \"/dashboard/active\"\n    end\n  end\n\n  test 'signed in as active admin should be able to access dashboard/active route restricted to active admins (authenticated accepted)' do\n    sign_in_as_admin(active: true)\n    assert warden.authenticated?(:admin)\n    assert_not warden.authenticated?(:user)\n\n    get dashboard_active_path\n\n    assert_response :success\n    assert_template 'home/admin_dashboard'\n    assert_contain 'Admin dashboard'\n  end\n\n  test 'signed in user should not see unauthenticated page (unauthenticated denied)' do\n    sign_in_as_user\n    assert warden.authenticated?(:user)\n    assert_not warden.authenticated?(:admin)\n\n    assert_raises ActionController::RoutingError do\n      get join_path\n    end\n  end\n\n  test 'not signed in users should see unauthenticated page (unauthenticated accepted)' do\n    get join_path\n\n    assert_response :success\n    assert_template 'home/join'\n    assert_contain 'Join'\n  end\nend\n\nclass AuthenticationRedirectTest < Devise::IntegrationTest\n  test 'redirect from warden shows sign in or sign up message' do\n    get admins_path\n\n    warden_path = new_admin_session_path\n    assert_redirected_to warden_path\n\n    get warden_path\n    assert_contain 'You need to sign in or sign up before continuing.'\n  end\n\n  test 'redirect from warden respects i18n locale set at the controller' do\n    get admins_path(locale: \"pt-BR\")\n\n    assert_redirected_to new_admin_session_path\n    follow_redirect!\n\n    assert_contain 'Para continuar, faça login ou registre-se.'\n  end\n\n  test 'redirect to default url if no other was configured' do\n    sign_in_as_user\n    assert_template 'home/index'\n    assert_nil session[:\"user_return_to\"]\n  end\n\n  test 'redirect to requested url after sign in' do\n    get users_path\n    assert_redirected_to new_user_session_path\n    assert_equal users_path, session[:\"user_return_to\"]\n\n    follow_redirect!\n    sign_in_as_user visit: false\n\n    assert_current_url '/users'\n    assert_nil session[:\"user_return_to\"]\n  end\n\n  test 'redirect to last requested url overwriting the stored return_to option' do\n    get expire_user_path(create_user)\n    assert_redirected_to new_user_session_path\n    assert_equal expire_user_path(create_user), session[:\"user_return_to\"]\n\n    get users_path\n    assert_redirected_to new_user_session_path\n    assert_equal users_path, session[:\"user_return_to\"]\n\n    follow_redirect!\n    sign_in_as_user visit: false\n\n    assert_current_url '/users'\n    assert_nil session[:\"user_return_to\"]\n  end\n\n  test 'xml http requests does not store urls for redirect' do\n    get users_path, headers: { 'HTTP_X_REQUESTED_WITH' => 'XMLHttpRequest' }\n    assert_equal 401, response.status\n    assert_nil session[:\"user_return_to\"]\n  end\n\n  test 'redirect to configured home path for a given scope after sign in' do\n    sign_in_as_admin\n    assert_equal \"/admin_area/home\", @request.path\n  end\n\n  test 'require_no_authentication should set the already_authenticated flash message' do\n    sign_in_as_user\n    visit new_user_session_path\n    assert_equal I18n.t(\"devise.failure.already_authenticated\"), flash[:alert]\n  end\n\n  test 'require_no_authentication should set the already_authenticated flash message as admin' do\n    store_translations :en, devise: { failure: { admin: { already_authenticated: 'You are already signed in as admin.' } } } do\n      sign_in_as_admin\n      visit new_admin_session_path\n      assert_equal \"You are already signed in as admin.\", flash[:alert]\n    end\n  end\nend\n\nclass AuthenticationSessionTest < Devise::IntegrationTest\n  test 'destroyed account is signed out' do\n    sign_in_as_user\n    get '/users'\n\n    User.destroy_all\n    get '/users'\n    assert_redirected_to new_user_session_path\n  end\n\n  test 'refreshes _csrf_token' do\n    swap ApplicationController, allow_forgery_protection: true do\n      get new_user_session_path\n      token_from_session = request.session[:_csrf_token]\n\n      if Devise::Test.rails71_and_up?\n        token_from_env = request.env[\"action_controller.csrf_token\"]\n      end\n\n      sign_in_as_user\n      assert_not_equal request.session[:_csrf_token], token_from_session\n\n      if Devise::Test.rails71_and_up?\n        assert_not_equal request.env[\"action_controller.csrf_token\"], token_from_env\n      end\n    end\n  end\n\n  test 'allows session to be set for a given scope' do\n    sign_in_as_user\n    get '/users'\n    assert_equal \"Cart\", @controller.user_session[:cart]\n  end\n\n  test 'session id is changed on sign in' do\n    get '/users'\n    session_id = request.session[\"session_id\"]\n\n    get '/users'\n    assert_equal session_id, request.session[\"session_id\"]\n\n    sign_in_as_user\n    assert_not_equal session_id, request.session[\"session_id\"]\n  end\nend\n\nclass AuthenticationWithScopedViewsTest < Devise::IntegrationTest\n  test 'renders the scoped view if turned on and view is available' do\n    swap Devise, scoped_views: true do\n      assert_raise Webrat::NotFoundError do\n        sign_in_as_user\n      end\n      assert_match %r{Special user view}, response.body\n    end\n  end\n\n  test 'renders the scoped view if turned on in a specific controller' do\n    begin\n      Devise::SessionsController.scoped_views = true\n      assert_raise Webrat::NotFoundError do\n        sign_in_as_user\n      end\n\n      assert_match %r{Special user view}, response.body\n      assert_not Devise::PasswordsController.scoped_views?\n    ensure\n      Devise::SessionsController.send :remove_instance_variable, :@scoped_views\n    end\n  end\n\n  test 'does not render the scoped view if turned off' do\n    swap Devise, scoped_views: false do\n      assert_nothing_raised do\n        sign_in_as_user\n      end\n    end\n  end\n\n  test 'does not render the scoped view if not available' do\n    swap Devise, scoped_views: true do\n      assert_nothing_raised do\n        sign_in_as_admin\n      end\n    end\n  end\nend\n\nclass AuthenticationOthersTest < Devise::IntegrationTest\n  test 'handles unverified requests gets rid of caches' do\n    swap ApplicationController, allow_forgery_protection: true do\n      post exhibit_user_url(1)\n      assert_not warden.authenticated?(:user)\n\n      sign_in_as_user\n      assert warden.authenticated?(:user)\n\n      post exhibit_user_url(1)\n      assert_not warden.authenticated?(:user)\n      assert_equal \"User is not authenticated\", response.body\n    end\n  end\n\n  test 'uses the custom controller with the custom controller view' do\n    get '/admin_area/sign_in'\n    assert_contain 'Log in'\n    assert_contain 'Welcome to \"admins/sessions\" controller!'\n    assert_contain 'Welcome to \"sessions/new\" view!'\n  end\n\n  test 'render 404 on roles without routes' do\n    assert_raise ActionController::RoutingError do\n      get '/admin_area/password/new'\n    end\n  end\n\n  test 'does not intercept Rails 401 responses' do\n    get '/unauthenticated'\n    assert_equal 401, response.status\n  end\n\n  test 'render 404 on roles without mapping' do\n    assert_raise AbstractController::ActionNotFound do\n      get '/sign_in'\n    end\n  end\n\n  test 'sign in with script name' do\n    assert_nothing_raised do\n      get new_user_session_path, headers: { \"SCRIPT_NAME\" => \"/omg\" }\n      fill_in \"email\", with: \"user@test.com\"\n    end\n  end\n\n  test 'sign in stub in json format' do\n    get new_user_session_path(format: 'json')\n    assert_match '{\"user\":{', response.body\n    assert_match '\"email\":\"\"', response.body\n    assert_match '\"password\":null', response.body\n  end\n\n  test 'sign in stub in json with non attribute key' do\n    swap Devise, authentication_keys: [:other_key] do\n      get new_user_session_path(format: 'json')\n      assert_match '{\"user\":{', response.body\n      assert_match '\"other_key\":null', response.body\n      assert_match '\"password\":null', response.body\n    end\n  end\n\n  test 'uses the mapping from router' do\n    sign_in_as_user visit: \"/as/sign_in\"\n    assert warden.authenticated?(:user)\n    assert_not warden.authenticated?(:admin)\n  end\n\n  test 'sign in with json format returns json response' do\n    create_user\n    post user_session_path(format: 'json'), params: { user: {email: \"user@test.com\", password: '12345678'} }\n    assert_response :success\n    assert_includes response.body, '{\"user\":{'\n  end\n\n  test 'sign in with json format is idempotent' do\n    get new_user_session_path(format: 'json')\n    assert_response :success\n\n    create_user\n    post user_session_path(format: 'json'), params: { user: {email: \"user@test.com\", password: '12345678'} }\n    assert_response :success\n\n    get new_user_session_path(format: 'json')\n    assert_response :success\n\n    post user_session_path(format: 'json'), params: { user: {email: \"user@test.com\", password: '12345678'} }\n    assert_response :success\n    assert_includes response.body, '{\"user\":{'\n  end\n\n  test 'sign out with html redirects' do\n    sign_in_as_user\n    delete destroy_user_session_path\n    assert_response :redirect\n    assert_current_url '/'\n\n    sign_in_as_user\n    delete destroy_user_session_path(format: 'html')\n    assert_response :redirect\n    assert_current_url '/'\n  end\n\n  test 'sign out with json format returns no content' do\n    sign_in_as_user\n    delete destroy_user_session_path(format: 'json')\n    assert_response :no_content\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'sign out with non-navigational format via XHR does not redirect' do\n    swap Devise, navigational_formats: ['*/*', :html] do\n      sign_in_as_admin\n      get destroy_sign_out_via_get_session_path, xhr: true, headers: { \"HTTP_ACCEPT\" => \"application/json,text/javascript,*/*\" } # NOTE: Bug is triggered by combination of XHR and */*.\n      assert_response :no_content\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  # Belt and braces ... Perhaps this test is not necessary?\n  test 'sign out with navigational format via XHR does redirect' do\n    swap Devise, navigational_formats: ['*/*', :html] do\n      sign_in_as_user\n      delete destroy_user_session_path, xhr: true, headers: { \"HTTP_ACCEPT\" => \"text/html,*/*\" }\n      assert_response :redirect\n      assert_not warden.authenticated?(:user)\n    end\n  end\nend\n\nclass AuthenticationKeysTest < Devise::IntegrationTest\n  test 'missing authentication keys cause authentication to abort' do\n    swap Devise, authentication_keys: [:subdomain] do\n      sign_in_as_user\n      assert_contain \"Invalid subdomain or password.\"\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'missing authentication keys cause authentication to abort unless marked as not required' do\n    swap Devise, authentication_keys: { email: true, subdomain: false } do\n      sign_in_as_user\n      assert warden.authenticated?(:user)\n    end\n  end\nend\n\nclass AuthenticationRequestKeysTest < Devise::IntegrationTest\n  test 'request keys are used on authentication' do\n    host! 'foo.bar.baz'\n\n    swap Devise, request_keys: [:subdomain] do\n      User.expects(:find_for_authentication).with({ subdomain: 'foo', email: 'user@test.com' }).returns(create_user)\n      sign_in_as_user\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'invalid request keys raises NoMethodError' do\n    swap Devise, request_keys: [:unknown_method] do\n      assert_raise NoMethodError do\n        sign_in_as_user\n      end\n\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'blank request keys cause authentication to abort' do\n    host! 'test.com'\n\n    swap Devise, request_keys: [:subdomain] do\n      sign_in_as_user\n      assert_contain \"Invalid email or password.\"\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'blank request keys cause authentication to abort unless if marked as not required' do\n    host! 'test.com'\n\n    swap Devise, request_keys: { subdomain: false } do\n      sign_in_as_user\n      assert warden.authenticated?(:user)\n    end\n  end\nend\n\nclass AuthenticationSignOutViaTest < Devise::IntegrationTest\n  def sign_in!(scope)\n    sign_in_as_admin(visit: send(\"new_#{scope}_session_path\"))\n    assert warden.authenticated?(scope)\n  end\n\n  test 'allow sign out via delete when sign_out_via provides only delete' do\n    sign_in!(:sign_out_via_delete)\n    delete destroy_sign_out_via_delete_session_path\n    assert_not warden.authenticated?(:sign_out_via_delete)\n  end\n\n  test 'do not allow sign out via get when sign_out_via provides only delete' do\n    sign_in!(:sign_out_via_delete)\n    assert_raise ActionController::RoutingError do\n      get destroy_sign_out_via_delete_session_path\n    end\n    assert warden.authenticated?(:sign_out_via_delete)\n  end\n\n  test 'allow sign out via post when sign_out_via provides only post' do\n    sign_in!(:sign_out_via_post)\n    post destroy_sign_out_via_post_session_path\n    assert_not warden.authenticated?(:sign_out_via_post)\n  end\n\n  test 'do not allow sign out via get when sign_out_via provides only post' do\n    sign_in!(:sign_out_via_post)\n    assert_raise ActionController::RoutingError do\n      get destroy_sign_out_via_delete_session_path\n    end\n    assert warden.authenticated?(:sign_out_via_post)\n  end\n\n  test 'allow sign out via delete when sign_out_via provides delete and post' do\n    sign_in!(:sign_out_via_delete_or_post)\n    delete destroy_sign_out_via_delete_or_post_session_path\n    assert_not warden.authenticated?(:sign_out_via_delete_or_post)\n  end\n\n  test 'allow sign out via post when sign_out_via provides delete and post' do\n    sign_in!(:sign_out_via_delete_or_post)\n    post destroy_sign_out_via_delete_or_post_session_path\n    assert_not warden.authenticated?(:sign_out_via_delete_or_post)\n  end\n\n  test 'do not allow sign out via get when sign_out_via provides delete and post' do\n    sign_in!(:sign_out_via_delete_or_post)\n    assert_raise ActionController::RoutingError do\n      get destroy_sign_out_via_delete_or_post_session_path\n    end\n    assert warden.authenticated?(:sign_out_via_delete_or_post)\n  end\nend\n\nclass DoubleAuthenticationRedirectTest < Devise::IntegrationTest\n  test 'signed in as user redirects when visiting user sign in page' do\n    sign_in_as_user\n    get new_user_session_path(format: :html)\n    assert_redirected_to '/'\n  end\n\n  test 'signed in as admin redirects when visiting admin sign in page' do\n    sign_in_as_admin\n    get new_admin_session_path(format: :html)\n    assert_redirected_to '/admin_area/home'\n  end\n\n  test 'signed in as both user and admin redirects when visiting admin sign in page' do\n    sign_in_as_user\n    sign_in_as_admin\n    get new_user_session_path(format: :html)\n    assert_redirected_to '/'\n    get new_admin_session_path(format: :html)\n    assert_redirected_to '/admin_area/home'\n  end\nend\n\nclass DoubleSignOutRedirectTest < Devise::IntegrationTest\n  test 'sign out after already having signed out redirects to sign in' do\n    sign_in_as_user\n\n    post destroy_sign_out_via_delete_or_post_session_path\n\n    get root_path\n    assert_contain 'Signed out successfully.'\n\n    post destroy_sign_out_via_delete_or_post_session_path\n\n    get root_path\n    assert_contain 'Signed out successfully.'\n  end\nend\n"
  },
  {
    "path": "test/integration/confirmable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass ConfirmationTest < Devise::IntegrationTest\n\n  def visit_user_confirmation_with_token(confirmation_token)\n    visit user_confirmation_path(confirmation_token: confirmation_token)\n  end\n\n  def resend_confirmation\n    user = create_user(confirm: false)\n    ActionMailer::Base.deliveries.clear\n\n    visit new_user_session_path\n    click_link \"Didn't receive confirmation instructions?\"\n\n    fill_in 'email', with: user.email\n    click_button 'Resend confirmation instructions'\n  end\n\n  test 'user should be able to request a new confirmation' do\n    resend_confirmation\n\n    assert_current_url '/users/sign_in'\n    assert_contain 'You will receive an email with instructions for how to confirm your email address in a few minutes'\n    assert_equal 1, ActionMailer::Base.deliveries.size\n    assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from\n  end\n\n  test 'user should receive a confirmation from a custom mailer' do\n    User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)\n    resend_confirmation\n    assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from\n  end\n\n  test 'user with invalid confirmation token should not be able to confirm an account' do\n    visit_user_confirmation_with_token('invalid_confirmation')\n    assert_have_selector '#error_explanation'\n    assert_contain %r{Confirmation token(.*)invalid}\n  end\n\n  test 'user with valid confirmation token should not be able to confirm an account after the token has expired' do\n    swap Devise, confirm_within: 3.days do\n      user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)\n      assert_not user.confirmed?\n      visit_user_confirmation_with_token(user.raw_confirmation_token)\n\n      assert_have_selector '#error_explanation'\n      assert_contain %r{needs to be confirmed within 3 days}\n      assert_not user.reload.confirmed?\n      assert_current_url \"/users/confirmation?confirmation_token=#{user.raw_confirmation_token}\"\n    end\n  end\n\n  test 'user with valid confirmation token where the token has expired and with application router_name set to a different engine it should raise an error' do\n    user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)\n\n    swap Devise, confirm_within: 3.days, router_name: :fake_engine do\n      assert_raise ActionView::Template::Error do\n        visit_user_confirmation_with_token(user.raw_confirmation_token)\n      end\n    end\n  end\n\n  test 'user with valid confirmation token where the token has expired and with application router_name set to a different engine and route overrides back to main it shows the path' do\n    user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)\n\n    swap Devise, confirm_within: 3.days, router_name: :fake_engine do\n      visit user_on_main_app_confirmation_path(confirmation_token: user.raw_confirmation_token)\n\n      assert_current_url \"/user_on_main_apps/confirmation?confirmation_token=#{user.raw_confirmation_token}\"\n    end\n  end\n\n  test 'user with valid confirmation token where the token has expired with router overrides different engine it shows the path' do\n    user = create_user(confirm: false, confirmation_sent_at: 4.days.ago)\n\n    swap Devise, confirm_within: 3.days do\n      visit user_on_engine_confirmation_path(confirmation_token: user.raw_confirmation_token)\n\n      assert_current_url \"/user_on_engines/confirmation?confirmation_token=#{user.raw_confirmation_token}\"\n    end\n  end\n\n  test 'user with valid confirmation token should be able to confirm an account before the token has expired' do\n    swap Devise, confirm_within: 3.days do\n      user = create_user(confirm: false, confirmation_sent_at: 2.days.ago)\n      assert_not user.confirmed?\n      visit_user_confirmation_with_token(user.raw_confirmation_token)\n\n      assert_contain 'Your email address has been successfully confirmed.'\n      assert_current_url '/users/sign_in'\n      assert user.reload.confirmed?\n    end\n  end\n\n  test 'user should be redirected to a custom path after confirmation' do\n    Devise::ConfirmationsController.any_instance.stubs(:after_confirmation_path_for).returns(\"/?custom=1\")\n\n    user = create_user(confirm: false)\n    visit_user_confirmation_with_token(user.raw_confirmation_token)\n\n    assert_current_url \"/?custom=1\"\n  end\n\n  test 'already confirmed user should not be able to confirm the account again' do\n    user = create_user(confirm: false)\n    user.confirmed_at = Time.now\n    user.save\n    visit_user_confirmation_with_token(user.raw_confirmation_token)\n\n    assert_have_selector '#error_explanation'\n    assert_contain 'already confirmed'\n  end\n\n  test 'already confirmed user should not be able to confirm the account again neither request confirmation' do\n    user = create_user(confirm: false)\n    user.confirmed_at = Time.now\n    user.save\n\n    visit_user_confirmation_with_token(user.raw_confirmation_token)\n    assert_contain 'already confirmed'\n\n    fill_in 'email', with: user.email\n    click_button 'Resend confirmation instructions'\n    assert_contain 'already confirmed'\n  end\n\n  test 'not confirmed user with setup to block without confirmation should not be able to sign in' do\n    swap Devise, allow_unconfirmed_access_for: 0.days do\n      sign_in_as_user(confirm: false)\n\n      assert_contain 'You have to confirm your email address before continuing'\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'not confirmed user redirect respects i18n locale set' do\n    swap Devise, allow_unconfirmed_access_for: 0.days do\n      sign_in_as_user(confirm: false, visit: new_user_session_path(locale: \"pt-BR\"))\n\n      assert_contain 'Você precisa confirmar seu email para continuar'\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'not confirmed user should not see confirmation message if invalid credentials are given' do\n    swap Devise, allow_unconfirmed_access_for: 0.days do\n      sign_in_as_user(confirm: false) do\n        fill_in 'password', with: 'invalid'\n      end\n\n      assert_contain 'Invalid email or password'\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'not confirmed user but configured with some days to confirm should be able to sign in' do\n    swap Devise, allow_unconfirmed_access_for: 1.day do\n      sign_in_as_user(confirm: false)\n\n      assert_response :success\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'unconfirmed but signed in user should be redirected to their root path' do\n    swap Devise, allow_unconfirmed_access_for: 1.day do\n      user = sign_in_as_user(confirm: false)\n\n      visit_user_confirmation_with_token(user.raw_confirmation_token)\n      assert_contain 'Your email address has been successfully confirmed.'\n      assert_current_url '/'\n    end\n  end\n\n  test 'user should be redirected to sign in page whenever signed in as another resource at same session already' do\n    sign_in_as_admin\n\n    user = create_user(confirm: false)\n    visit_user_confirmation_with_token(user.raw_confirmation_token)\n\n    assert_current_url '/users/sign_in'\n  end\n\n  test \"should not be able to confirm an email with a blank confirmation token\" do\n    visit_user_confirmation_with_token(\"\")\n\n    assert_contain %r{Confirmation token can['’]t be blank}\n  end\n\n  test \"should not be able to confirm an email with a nil confirmation token\" do\n    visit_user_confirmation_with_token(nil)\n\n    assert_contain %r{Confirmation token can['’]t be blank}\n  end\n\n  test \"should not be able to confirm user with blank confirmation token\" do\n    user = create_user(confirm: false)\n    user.update_attribute(:confirmation_token, \"\")\n\n    visit_user_confirmation_with_token(\"\")\n\n    assert_contain %r{Confirmation token can['’]t be blank}\n  end\n\n  test \"should not be able to confirm user with nil confirmation token\" do\n    user = create_user(confirm: false)\n    user.update_attribute(:confirmation_token, nil)\n\n    visit_user_confirmation_with_token(nil)\n\n    assert_contain %r{Confirmation token can['’]t be blank}\n  end\n\n  test 'error message is configurable by resource name' do\n    store_translations :en, devise: {\n      failure: { user: { unconfirmed: \"Not confirmed user\" } }\n    } do\n      sign_in_as_user(confirm: false)\n      assert_contain 'Not confirmed user'\n    end\n  end\n\n  test 'resent confirmation token with valid e-mail in JSON format should return empty and valid response' do\n    user = create_user(confirm: false)\n    post user_confirmation_path(format: 'json'), params: { user: { email: user.email } }\n    assert_response :success\n    assert_equal({}.to_json, response.body)\n  end\n\n  test 'resent confirmation token with invalid e-mail in JSON format should return invalid response' do\n    create_user(confirm: false)\n    post user_confirmation_path(format: 'json'), params: { user: { email: 'invalid.test@test.com' } }\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"errors\":{'\n  end\n\n  test 'confirm account with valid confirmation token in JSON format should return valid response' do\n    user = create_user(confirm: false)\n    get user_confirmation_path(confirmation_token: user.raw_confirmation_token, format: 'json')\n    assert_response :success\n    assert_includes response.body, '{\"user\":{'\n  end\n\n  test 'confirm account with invalid confirmation token in JSON format should return invalid response' do\n    create_user(confirm: false)\n    get user_confirmation_path(confirmation_token: 'invalid_confirmation', format: 'json')\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"confirmation_token\":['\n  end\n\n  test \"when in paranoid mode and with a valid e-mail, should not say that the e-mail is valid\" do\n    swap Devise, paranoid: true do\n      user = create_user(confirm: false)\n      visit new_user_session_path\n\n      click_link \"Didn't receive confirmation instructions?\"\n      fill_in 'email', with: user.email\n      click_button 'Resend confirmation instructions'\n\n      assert_contain \"If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes.\"\n      assert_current_url \"/users/sign_in\"\n    end\n  end\n\n  test \"when in paranoid mode and with a invalid e-mail, should not say that the e-mail is invalid\" do\n    swap Devise, paranoid: true do\n      visit new_user_session_path\n\n      click_link \"Didn't receive confirmation instructions?\"\n      fill_in 'email', with: \"idonthavethisemail@gmail.com\"\n      click_button 'Resend confirmation instructions'\n\n      assert_not_contain \"1 error prohibited this user from being saved:\"\n      assert_not_contain \"Email not found\"\n\n      assert_contain \"If your email address exists in our database, you will receive an email with instructions for how to confirm your email address in a few minutes.\"\n      assert_current_url \"/users/sign_in\"\n    end\n  end\nend\n\nclass ConfirmationOnChangeTest < Devise::IntegrationTest\n  def create_second_admin(options = {})\n    @admin = nil\n    create_admin(options)\n  end\n\n  def visit_admin_confirmation_with_token(confirmation_token)\n    visit admin_confirmation_path(confirmation_token: confirmation_token)\n  end\n\n  test 'admin should be able to request a new confirmation after email changed' do\n    admin = create_admin\n    admin.update(email: 'new_test@example.com')\n\n    visit new_admin_session_path\n    click_link \"Didn't receive confirmation instructions?\"\n\n    fill_in 'email', with: admin.unconfirmed_email\n    assert_difference \"ActionMailer::Base.deliveries.size\" do\n      click_button 'Resend confirmation instructions'\n    end\n\n    assert_current_url '/admin_area/sign_in'\n    assert_contain 'You will receive an email with instructions for how to confirm your email address in a few minutes'\n  end\n\n  test 'admin with valid confirmation token should be able to confirm email after email changed' do\n    admin = create_admin\n    admin.update(email: 'new_test@example.com')\n    assert_equal 'new_test@example.com', admin.unconfirmed_email\n    visit_admin_confirmation_with_token(admin.raw_confirmation_token)\n\n    assert_contain 'Your email address has been successfully confirmed.'\n    assert_current_url '/admin_area/sign_in'\n    assert admin.reload.confirmed?\n    assert_not admin.reload.pending_reconfirmation?\n  end\n\n  test 'admin with previously valid confirmation token should not be able to confirm email after email changed again' do\n    admin = create_admin\n    admin.update(email: 'first_test@example.com')\n    assert_equal 'first_test@example.com', admin.unconfirmed_email\n\n    raw_confirmation_token = admin.raw_confirmation_token\n    admin = Admin.find(admin.id)\n\n    admin.update(email: 'second_test@example.com')\n    assert_equal 'second_test@example.com', admin.unconfirmed_email\n\n    visit_admin_confirmation_with_token(raw_confirmation_token)\n    assert_have_selector '#error_explanation'\n    assert_contain(/Confirmation token(.*)invalid/)\n\n    visit_admin_confirmation_with_token(admin.raw_confirmation_token)\n    assert_contain 'Your email address has been successfully confirmed.'\n    assert_current_url '/admin_area/sign_in'\n    assert admin.reload.confirmed?\n    assert_not admin.reload.pending_reconfirmation?\n  end\n\n  test 'admin email should be unique also within unconfirmed_email' do\n    admin = create_admin\n    admin.update(email: 'new_admin_test@example.com')\n    assert_equal 'new_admin_test@example.com', admin.unconfirmed_email\n\n    create_second_admin(email: \"new_admin_test@example.com\")\n\n    visit_admin_confirmation_with_token(admin.raw_confirmation_token)\n    assert_have_selector '#error_explanation'\n    assert_contain(/Email.*already.*taken/)\n    assert admin.reload.pending_reconfirmation?\n  end\n\n  test 'concurrent \"update email\" requests should not allow confirming a victim email address' do\n    attacker_email = \"attacker@example.com\"\n    victim_email = \"victim@example.com\"\n\n    attacker = create_admin\n    # update the email address of the attacker, but do not confirm it yet\n    attacker.update!(email: attacker_email)\n\n    # A new request starts, to update the unconfirmed email again.\n    attacker = Admin.find_by(id: attacker.id)\n\n    # A concurrent request also updates the email address to the victim, while the `attacker` request's model is in memory\n    Admin.where(id: attacker.id).update_all(\n      unconfirmed_email: victim_email,\n      confirmation_token: \"different token\"\n    )\n\n    # Now the attacker updates to the same prior unconfirmed email address, and confirm.\n    # This should update the `unconfirmed_email` in the database, even though it is unchanged from the models point of view.\n    attacker.update!(email: attacker_email)\n    attacker_token = attacker.raw_confirmation_token\n    visit_admin_confirmation_with_token(attacker_token)\n\n    attacker.reload\n    assert attacker.confirmed?\n    assert_equal attacker_email, attacker.email\n  end\nend\n"
  },
  {
    "path": "test/integration/database_authenticatable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass DatabaseAuthenticationTest < Devise::IntegrationTest\n  test 'sign in with email of different case should succeed when email is in the list of case insensitive keys' do\n    create_user(email: 'Foo@Bar.com')\n\n    sign_in_as_user do\n      fill_in 'email', with: 'foo@bar.com'\n    end\n\n    assert warden.authenticated?(:user)\n  end\n\n  test 'sign in with email of different case should fail when email is NOT the list of case insensitive keys' do\n    swap Devise, case_insensitive_keys: [] do\n      create_user(email: 'Foo@Bar.com')\n\n      sign_in_as_user do\n        fill_in 'email', with: 'foo@bar.com'\n      end\n\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'sign in with email including extra spaces should succeed when email is in the list of strip whitespace keys' do\n    create_user(email: ' foo@bar.com ')\n\n    sign_in_as_user do\n      fill_in 'email', with: 'foo@bar.com'\n    end\n\n    assert warden.authenticated?(:user)\n  end\n\n  test 'sign in with email including extra spaces should fail when email is NOT the list of strip whitespace keys' do\n    swap Devise, strip_whitespace_keys: [] do\n      create_user(email: 'foo@bar.com')\n\n      sign_in_as_user do\n        fill_in 'email', with: ' foo@bar.com '\n      end\n\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'sign in should not authenticate if not using proper authentication keys' do\n    swap Devise, authentication_keys: [:username] do\n      sign_in_as_user\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'sign in with invalid email should return to sign in form with error message' do\n    store_translations :en, devise: { failure: { admin: { not_found_in_database: 'Invalid email address' } } } do\n      sign_in_as_admin do\n        fill_in 'email', with: 'wrongemail@test.com'\n      end\n\n      assert_contain 'Invalid email address'\n      assert_not warden.authenticated?(:admin)\n    end\n  end\n\n  test 'sign in with invalid password should return to sign in form with error message' do\n    sign_in_as_admin do\n      fill_in 'password', with: 'abcdef'\n    end\n\n    assert_contain 'Invalid email or password'\n    assert_not warden.authenticated?(:admin)\n  end\n\n  test 'when in paranoid mode and without a valid e-mail' do\n    swap Devise, paranoid: true do\n      store_translations :en, devise: { failure: { not_found_in_database: 'Not found in database' } } do\n        sign_in_as_user do\n          fill_in 'email', with: 'wrongemail@test.com'\n        end\n\n        assert_not_contain 'Not found in database'\n        assert_contain 'Invalid email or password.'\n      end\n    end\n  end\n\n  test 'error message is configurable by resource name' do\n    store_translations :en, devise: { failure: { admin: { invalid: \"Invalid credentials\" } } } do\n      sign_in_as_admin do\n        fill_in 'password', with: 'abcdef'\n      end\n\n      assert_contain 'Invalid credentials'\n    end\n  end\n\n  test 'valid sign in calls after_database_authentication callback' do\n    user = create_user(email: ' foo@bar.com ')\n\n    User.expects(:find_for_database_authentication).returns user\n    user.expects :after_database_authentication\n\n    sign_in_as_user do\n      fill_in 'email', with: 'foo@bar.com'\n    end\n  end\nend\n"
  },
  {
    "path": "test/integration/http_authenticatable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass HttpAuthenticationTest < Devise::IntegrationTest\n  test 'sign in with HTTP should not run model validations' do\n    sign_in_as_new_user_with_http\n\n    assert_not User.validations_performed\n  end\n\n  test 'handles unverified requests gets rid of caches but continues signed in' do\n    swap ApplicationController, allow_forgery_protection: true do\n      create_user\n      post exhibit_user_url(1), headers: { \"HTTP_AUTHORIZATION\" => \"Basic #{Base64.encode64(\"user@test.com:12345678\")}\" }\n      assert warden.authenticated?(:user)\n      assert_equal \"User is authenticated\", response.body\n    end\n  end\n\n  test 'sign in should authenticate with http' do\n    swap Devise, skip_session_storage: [] do\n      sign_in_as_new_user_with_http\n      assert_response 200\n      assert_match '\"email\":\"user@test.com\"', response.body\n      assert warden.authenticated?(:user)\n\n      get users_path(format: :json)\n      assert_response 200\n    end\n  end\n\n  test 'sign in should authenticate with http but not emit a cookie if skipping session storage' do\n    swap Devise, skip_session_storage: [:http_auth] do\n      sign_in_as_new_user_with_http\n      assert_response 200\n      assert_match '\"email\":\"user@test.com\"', response.body\n      assert warden.authenticated?(:user)\n\n      get users_path(format: :json)\n      assert_response 401\n    end\n  end\n\n  test 'returns a custom response with www-authenticate header on failures' do\n    sign_in_as_new_user_with_http(\"unknown\")\n    assert_equal 401, status\n    assert_equal 'Basic realm=\"Application\"', headers[\"WWW-Authenticate\"]\n  end\n\n  test 'uses the request format as response content type' do\n    sign_in_as_new_user_with_http(\"unknown\")\n    assert_equal 401, status\n    assert_equal \"application/json; charset=utf-8\", headers[\"Content-Type\"]\n    assert_match '\"error\":\"Invalid email or password.\"', response.body\n  end\n\n  test 'returns a custom response with www-authenticate and chosen realm' do\n    swap Devise, http_authentication_realm: \"MyApp\" do\n      sign_in_as_new_user_with_http(\"unknown\")\n      assert_equal 401, status\n      assert_equal 'Basic realm=\"MyApp\"', headers[\"WWW-Authenticate\"]\n    end\n  end\n\n  test 'sign in should authenticate with http even with specific authentication keys' do\n    swap Devise, authentication_keys: [:username] do\n      sign_in_as_new_user_with_http(\"usertest\")\n      assert_response :success\n      assert_match '\"email\":\"user@test.com\"', response.body\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'it uses appropriate authentication_keys when configured with hash' do\n    swap Devise, authentication_keys: { username: false, email: false } do\n      sign_in_as_new_user_with_http(\"usertest\")\n      assert_response :success\n      assert_match '\"email\":\"user@test.com\"', response.body\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'it uses the appropriate key when configured explicitly' do\n    swap Devise, authentication_keys: { email: false, username: false }, http_authentication_key: :username do\n      sign_in_as_new_user_with_http(\"usertest\")\n      assert_response :success\n      assert_match '\"email\":\"user@test.com\"', response.body\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'test request with oauth2 header doesnt get mistaken for basic authentication' do\n    swap Devise, http_authenticatable: true do\n      add_oauth2_header\n      assert_equal 401, status\n      assert_equal 'Basic realm=\"Application\"', headers[\"WWW-Authenticate\"]\n    end\n  end\n\n  private\n    def sign_in_as_new_user_with_http(username = \"user@test.com\", password = \"12345678\")\n      user = create_user\n      get users_path(format: :json), headers: { \"HTTP_AUTHORIZATION\" => \"Basic #{Base64.encode64(\"#{username}:#{password}\")}\" }\n      user\n    end\n\n    # Sign in with oauth2 token. This is just to test that it isn't misinterpreted as basic authentication\n    def add_oauth2_header\n      user = create_user\n      get users_path(format: :json), headers: { \"HTTP_AUTHORIZATION\" => \"OAuth #{Base64.encode64(\"#{user.email}:12345678\")}\" }\n    end\nend\n"
  },
  {
    "path": "test/integration/lockable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass LockTest < Devise::IntegrationTest\n\n  def visit_user_unlock_with_token(unlock_token)\n    visit user_unlock_path(unlock_token: unlock_token)\n  end\n\n  def send_unlock_request\n    user = create_user(locked: true)\n    ActionMailer::Base.deliveries.clear\n\n    visit new_user_session_path\n    click_link \"Didn't receive unlock instructions?\"\n\n    Devise.stubs(:friendly_token).returns(\"abcdef\")\n    fill_in 'email', with: user.email\n    click_button 'Resend unlock instructions'\n  end\n\n  test 'user should be able to request a new unlock token' do\n    send_unlock_request\n\n    assert_template 'sessions/new'\n    assert_contain 'You will receive an email with instructions for how to unlock your account in a few minutes'\n\n    mail = ActionMailer::Base.deliveries.last\n    assert_equal 1, ActionMailer::Base.deliveries.size\n    assert_equal ['please-change-me@config-initializers-devise.com'], mail.from\n    assert_match user_unlock_path(unlock_token: 'abcdef'), mail.body.encoded\n  end\n\n  test 'user should receive the instructions from a custom mailer' do\n    User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)\n\n    send_unlock_request\n\n    assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from\n  end\n\n  test 'unlocked user should not be able to request a unlock token' do\n    user = create_user(locked: false)\n    ActionMailer::Base.deliveries.clear\n\n    visit new_user_session_path\n    click_link \"Didn't receive unlock instructions?\"\n\n    fill_in 'email', with: user.email\n    click_button 'Resend unlock instructions'\n\n    assert_template 'unlocks/new'\n    assert_contain 'not locked'\n    assert_equal 0, ActionMailer::Base.deliveries.size\n  end\n\n  test 'unlocked pages should not be available if email strategy is disabled' do\n    visit \"/admin_area/sign_in\"\n\n    assert_raise Webrat::NotFoundError do\n      click_link \"Didn't receive unlock instructions?\"\n    end\n\n    assert_raise NameError do\n      visit new_admin_unlock_path\n    end\n\n    assert_raise ActionController::RoutingError do\n      visit \"/admin_area/unlock/new\"\n    end\n  end\n\n  test 'user with invalid unlock token should not be able to unlock an account' do\n    visit_user_unlock_with_token('invalid_token')\n\n    assert_response :success\n    assert_current_url '/users/unlock?unlock_token=invalid_token'\n    assert_have_selector '#error_explanation'\n    assert_contain %r{Unlock token(.*)invalid}\n  end\n\n  test \"locked user should be able to unlock account\" do\n    user = create_user\n    raw  = user.lock_access!\n    visit_user_unlock_with_token(raw)\n\n    assert_current_url \"/users/sign_in\"\n    assert_contain 'Your account has been unlocked successfully. Please sign in to continue.'\n    assert_not user.reload.access_locked?\n  end\n\n  test \"user should not send a new e-mail if already locked\" do\n    user = create_user(locked: true)\n    user.failed_attempts = User.maximum_attempts + 1\n    user.save!\n\n    ActionMailer::Base.deliveries.clear\n\n    sign_in_as_user(password: \"invalid\")\n    assert_contain 'Your account is locked.'\n    assert_empty ActionMailer::Base.deliveries\n  end\n\n  test 'error message is configurable by resource name' do\n    store_translations :en, devise: {\n        failure: {user: {locked: \"You are locked!\"}}\n    } do\n\n      user = create_user(locked: true)\n      user.failed_attempts = User.maximum_attempts + 1\n      user.save!\n\n      sign_in_as_user(password: \"invalid\")\n      assert_contain \"You are locked!\"\n    end\n  end\n\n  test \"user should not be able to sign in when locked\" do\n    store_translations :en, devise: {\n        failure: {user: {locked: \"You are locked!\"}}\n    } do\n\n      user = create_user(locked: true)\n      user.failed_attempts = User.maximum_attempts + 1\n      user.save!\n\n      sign_in_as_user(password: \"123456\")\n      assert_contain \"You are locked!\"\n    end\n  end\n\n  test 'user should be able to request a new unlock token via JSON request and should return empty and valid response' do\n    user = create_user(locked: true)\n    ActionMailer::Base.deliveries.clear\n\n    post user_unlock_path(format: 'json'), params: { user: {email: user.email} }\n    assert_response :success\n    assert_equal({}.to_json, response.body)\n    assert_equal 1, ActionMailer::Base.deliveries.size\n  end\n\n  test 'unlocked user should not be able to request a unlock token via JSON request' do\n    user = create_user(locked: false)\n    ActionMailer::Base.deliveries.clear\n\n    post user_unlock_path(format: 'json'), params: { user: {email: user.email} }\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"errors\":{'\n    assert_equal 0, ActionMailer::Base.deliveries.size\n  end\n\n  test 'user with valid unlock token should be able to unlock account via JSON request' do\n    user = create_user()\n    raw  = user.lock_access!\n    assert user.access_locked?\n    get user_unlock_path(format: 'json', unlock_token: raw)\n    assert_response :success\n    assert_includes response.body, '{\"user\":{'\n  end\n\n  test 'user with invalid unlock token should not be able to unlock the account via JSON request' do\n    get user_unlock_path(format: 'json', unlock_token: 'invalid_token')\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"unlock_token\":['\n  end\n\n  test \"in paranoid mode, when trying to unlock a user that exists it should not say that it exists if it is locked\" do\n    swap Devise, paranoid: true do\n      user = create_user(locked: true)\n\n      visit new_user_session_path\n      click_link \"Didn't receive unlock instructions?\"\n\n      fill_in 'email', with: user.email\n      click_button 'Resend unlock instructions'\n\n      assert_current_url \"/users/sign_in\"\n      assert_contain \"If your account exists, you will receive an email with instructions for how to unlock it in a few minutes.\"\n    end\n  end\n\n  test \"in paranoid mode, when trying to unlock a user that exists it should not say that it exists if it is not locked\" do\n    swap Devise, paranoid: true do\n      user = create_user(locked: false)\n\n      visit new_user_session_path\n      click_link \"Didn't receive unlock instructions?\"\n\n      fill_in 'email', with: user.email\n      click_button 'Resend unlock instructions'\n\n      assert_current_url \"/users/sign_in\"\n      assert_contain \"If your account exists, you will receive an email with instructions for how to unlock it in a few minutes.\"\n    end\n  end\n\n  test \"in paranoid mode, when trying to unlock a user that does not exists it should not say that it does not exists\" do\n    swap Devise, paranoid: true do\n      visit new_user_session_path\n      click_link \"Didn't receive unlock instructions?\"\n\n      fill_in 'email', with: \"arandomemail@hotmail.com\"\n      click_button 'Resend unlock instructions'\n\n      assert_not_contain \"1 error prohibited this user from being saved:\"\n      assert_not_contain \"Email not found\"\n      assert_current_url \"/users/sign_in\"\n\n      assert_contain \"If your account exists, you will receive an email with instructions for how to unlock it in a few minutes.\"\n\n    end\n  end\n\n  test \"in paranoid mode, when locking a user that exists it should not say that the user was locked\" do\n    swap Devise, paranoid: true, maximum_attempts: 1 do\n      user = create_user(locked: false)\n\n      visit new_user_session_path\n      fill_in 'email', with: user.email\n      fill_in 'password', with: \"abadpassword\"\n      click_button 'Log in'\n\n      fill_in 'email', with: user.email\n      fill_in 'password', with: \"abadpassword\"\n      click_button 'Log in'\n\n      assert_current_url \"/users/sign_in\"\n      assert_not_contain \"locked\"\n    end\n  end\n\nend\n"
  },
  {
    "path": "test/integration/mounted_engine_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nmodule MyMountableEngine\n  class Engine < ::Rails::Engine\n    isolate_namespace MyMountableEngine\n  end\n  class TestsController < ActionController::Base\n    def index\n      render plain: 'Root test successful'\n    end\n    def inner_route\n      render plain: 'Inner route test successful'\n    end\n  end\nend\n\nMyMountableEngine::Engine.routes.draw do\n  get 'test', to: 'tests#inner_route'\n  root to: 'tests#index'\nend\n\n# If disable_clear_and_finalize is set to true, Rails will not clear other routes when calling\n# again the draw method. Look at the source code at:\n# http://www.rubydoc.info/docs/rails/ActionDispatch/Routing/RouteSet:draw\nRails.application.routes.disable_clear_and_finalize = true\n\nRails.application.routes.draw do\n  authenticate(:user) do\n    mount MyMountableEngine::Engine, at: '/mountable_engine'\n  end\nend\n\nclass AuthenticatedMountedEngineTest < Devise::IntegrationTest\n  test 'redirects to the sign in page when not authenticated' do\n    get '/mountable_engine'\n    follow_redirect!\n\n    assert_response :ok\n    assert_contain 'You need to sign in or sign up before continuing.'\n  end\n\n  test 'renders the mounted engine when authenticated' do\n    sign_in_as_user\n    get '/mountable_engine'\n\n    assert_response :success\n    assert_contain 'Root test successful'\n  end\n\n\n  test 'renders a inner route of the mounted engine when authenticated' do\n    sign_in_as_user\n    get '/mountable_engine/test'\n\n    assert_response :success\n    assert_contain 'Inner route test successful'\n  end\n\n  test 'respond properly to a non existing route of the mounted engine' do\n    sign_in_as_user\n    \n    assert_raise ActionController::RoutingError do\n      get '/mountable_engine/non-existing-route'\n    end\n  end\nend\n"
  },
  {
    "path": "test/integration/omniauthable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\n\nclass OmniauthableIntegrationTest < Devise::IntegrationTest\n  FACEBOOK_INFO = {\n    \"id\" => '12345',\n    \"link\" => 'http://facebook.com/josevalim',\n    \"email\" => 'user@example.com',\n    \"first_name\" => 'Jose',\n    \"last_name\" => 'Valim',\n    \"website\" => 'http://blog.plataformatec.com.br'\n  }\n\n  setup do\n    OmniAuth.config.test_mode = true\n    OmniAuth.config.mock_auth[:facebook] = {\n      \"uid\" => '12345',\n      \"provider\" => 'facebook',\n      \"user_info\" => {\"nickname\" => 'josevalim'},\n      \"credentials\" => {\"token\" => 'plataformatec'},\n      \"extra\" => {\"user_hash\" => FACEBOOK_INFO}\n    }\n    OmniAuth.config.add_camelization 'facebook', 'FaceBook'\n    if OmniAuth.config.respond_to?(:request_validation_phase)\n      OmniAuth.config.request_validation_phase = ->(env) {}\n    end\n  end\n\n  teardown do\n    OmniAuth.config.camelizations.delete('facebook')\n    OmniAuth.config.test_mode = false\n  end\n\n  def stub_action!(name)\n    Users::OmniauthCallbacksController.class_eval do\n      alias_method :__old_facebook, :facebook\n      alias_method :facebook, name\n    end\n    yield\n  ensure\n    Users::OmniauthCallbacksController.class_eval do\n      alias_method :facebook, :__old_facebook\n    end\n  end\n\n  test \"omniauth sign in should not run model validations\" do\n    stub_action!(:sign_in_facebook) do\n      create_user\n      post \"/users/auth/facebook\"\n      follow_redirect!\n      assert warden.authenticated?(:user)\n\n      assert_not User.validations_performed\n    end\n  end\n\n  test \"can access omniauth.auth in the env hash\" do\n    post \"/users/auth/facebook\"\n    follow_redirect!\n\n    json = ActiveSupport::JSON.decode(response.body)\n\n    assert_equal \"12345\",         json[\"uid\"]\n    assert_equal \"facebook\",      json[\"provider\"]\n    assert_equal \"josevalim\",     json[\"user_info\"][\"nickname\"]\n    assert_equal FACEBOOK_INFO,   json[\"extra\"][\"user_hash\"]\n    assert_equal \"plataformatec\", json[\"credentials\"][\"token\"]\n  end\n\n  test \"cleans up session on sign up\" do\n    assert_no_difference \"User.count\" do\n      post \"/users/auth/facebook\"\n      follow_redirect!\n    end\n\n    assert session[\"devise.facebook_data\"]\n\n    assert_difference \"User.count\" do\n      visit \"/users/sign_up\"\n      fill_in \"Password\", with: \"12345678\"\n      fill_in \"Password confirmation\", with: \"12345678\"\n      click_button \"Sign up\"\n    end\n\n    assert_current_url \"/\"\n    assert_contain \"You have signed up successfully.\"\n    assert_contain \"Hello User user@example.com\"\n    assert_not session[\"devise.facebook_data\"]\n  end\n\n  test \"cleans up session on cancel\" do\n    assert_no_difference \"User.count\" do\n      post \"/users/auth/facebook\"\n      follow_redirect!\n    end\n\n    assert session[\"devise.facebook_data\"]\n    visit \"/users/cancel\"\n    assert_not session[\"devise.facebook_data\"]\n  end\n\n  test \"cleans up session on sign in\" do\n    assert_no_difference \"User.count\" do\n      post \"/users/auth/facebook\"\n      follow_redirect!\n    end\n\n    assert session[\"devise.facebook_data\"]\n    sign_in_as_user\n    assert_not session[\"devise.facebook_data\"]\n  end\n\n  test \"sign in and send remember token if configured\" do\n    post \"/users/auth/facebook\"\n    follow_redirect!\n    assert_nil warden.cookies[\"remember_user_token\"]\n\n    stub_action!(:sign_in_facebook) do\n      create_user\n      post \"/users/auth/facebook\"\n      follow_redirect!\n      assert warden.authenticated?(:user)\n      assert warden.cookies[\"remember_user_token\"]\n    end\n  end\n\n  test \"authorization path via GET when Omniauth allowed_request_methods includes GET\" do\n    original_allowed = OmniAuth.config.allowed_request_methods\n    OmniAuth.config.allowed_request_methods = [:get, :post]\n\n    get \"/users/auth/facebook\"\n\n    assert_response(:redirect)\n  ensure\n    OmniAuth.config.allowed_request_methods = original_allowed\n  end\n\n  test \"authorization path via GET when Omniauth allowed_request_methods doesn't include GET\" do\n    original_allowed = OmniAuth.config.allowed_request_methods\n    OmniAuth.config.allowed_request_methods = [:post]\n\n    assert_raises(ActionController::RoutingError) do\n      get \"/users/auth/facebook\"\n    end\n  ensure\n    OmniAuth.config.allowed_request_methods = original_allowed\n  end\n\n  test \"generates a link to authenticate with provider\" do\n    visit \"/users/sign_in\"\n    assert_select \"form[action=?][method=post]\", \"/users/auth/facebook\" do\n      assert_select \"input[type=submit][value=?]\", \"Sign in with FaceBook\"\n    end\n  end\n\n  test \"generates a proper link when SCRIPT_NAME is set\" do\n    header 'SCRIPT_NAME', '/q'\n    visit \"/users/sign_in\"\n    assert_select \"form[action=?][method=post]\", \"/q/users/auth/facebook\" do\n      assert_select \"input[type=submit][value=?]\", \"Sign in with FaceBook\"\n    end\n  end\n\n  test \"handles callback error parameter according to the specification\" do\n    OmniAuth.config.mock_auth[:facebook] = :access_denied\n    visit \"/users/auth/facebook/callback?error=access_denied\"\n    assert_current_url \"/users/sign_in\"\n    assert_contain 'Could not authenticate you from FaceBook because \"Access denied\".'\n  end\n\n  test \"handles other exceptions from OmniAuth\" do\n    OmniAuth.config.mock_auth[:facebook] = :invalid_credentials\n\n    post \"/users/auth/facebook\"\n    follow_redirect!\n    follow_redirect!\n\n    assert_contain 'Could not authenticate you from FaceBook because \"Invalid credentials\".'\n  end\nend\n"
  },
  {
    "path": "test/integration/recoverable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass PasswordTest < Devise::IntegrationTest\n\n  def visit_new_password_path\n    visit new_user_session_path\n    click_link 'Forgot your password?'\n  end\n\n  def request_forgot_password(&block)\n    visit_new_password_path\n    assert_response :success\n    assert_not warden.authenticated?(:user)\n\n    fill_in 'email', with: 'user@test.com'\n    yield if block_given?\n\n    Devise.stubs(:friendly_token).returns(\"abcdef\")\n    click_button 'Send me password reset instructions'\n  end\n\n  def reset_password(options = {}, &block)\n    unless options[:visit] == false\n      visit edit_user_password_path(reset_password_token: options[:reset_password_token] || \"abcdef\")\n      assert_response :success\n    end\n\n    fill_in 'New password', with: '987654321'\n    fill_in 'Confirm new password', with: '987654321'\n    yield if block_given?\n    click_button 'Change my password'\n  end\n\n  test 'reset password should send to user record email and avoid case mapping collisions' do\n    create_user(email: 'user@github.com')\n\n    request_forgot_password do\n      fill_in 'email', with: 'user@gıthub.com'\n    end\n\n    mail = ActionMailer::Base.deliveries.last\n    assert_equal ['user@github.com'], mail.to\n  end\n\n  test 'reset password with email of different case should succeed when email is in the list of case insensitive keys' do\n    create_user(email: 'Foo@Bar.com')\n\n    request_forgot_password do\n      fill_in 'email', with: 'foo@bar.com'\n    end\n\n    assert_current_url '/users/sign_in'\n    assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'\n  end\n\n  test 'reset password with email should send an email from a custom mailer' do\n    create_user(email: 'Foo@Bar.com')\n\n    User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)\n    request_forgot_password do\n      fill_in 'email', with: 'foo@bar.com'\n    end\n\n    mail = ActionMailer::Base.deliveries.last\n    assert_equal ['custom@example.com'], mail.from\n    assert_match edit_user_password_path(reset_password_token: 'abcdef'), mail.body.encoded\n  end\n\n  test 'reset password with email of different case should fail when email is NOT the list of case insensitive keys' do\n    swap Devise, case_insensitive_keys: [] do\n      create_user(email: 'Foo@Bar.com')\n\n      request_forgot_password do\n        fill_in 'email', with: 'foo@bar.com'\n      end\n\n      assert_response :success\n      assert_current_url '/users/password'\n      assert_have_selector \"input[type=email][value='foo@bar.com']\"\n      assert_contain 'not found'\n    end\n  end\n\n  test 'reset password with email with extra whitespace should succeed when email is in the list of strip whitespace keys' do\n    create_user(email: 'foo@bar.com')\n\n    request_forgot_password do\n      fill_in 'email', with: ' foo@bar.com '\n    end\n\n    assert_current_url '/users/sign_in'\n    assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'\n  end\n\n  test 'reset password with email with extra whitespace should fail when email is NOT the list of strip whitespace keys' do\n    swap Devise, strip_whitespace_keys: [] do\n      create_user(email: 'foo@bar.com')\n\n      request_forgot_password do\n        fill_in 'email', with: ' foo@bar.com '\n      end\n\n      assert_response :success\n      assert_current_url '/users/password'\n      assert_have_selector \"input[type=email][value=' foo@bar.com ']\"\n      assert_contain 'not found'\n    end\n  end\n\n  test 'authenticated user should not be able to visit forgot password page' do\n    sign_in_as_user\n    assert warden.authenticated?(:user)\n\n    get new_user_password_path\n\n    assert_response :redirect\n    assert_redirected_to root_path\n  end\n\n  test 'not authenticated user should be able to request a forgot password' do\n    create_user\n    request_forgot_password\n\n    assert_current_url '/users/sign_in'\n    assert_contain 'You will receive an email with instructions on how to reset your password in a few minutes.'\n  end\n\n  test 'not authenticated user with invalid email should receive an error message' do\n    request_forgot_password do\n      fill_in 'email', with: 'invalid.test@test.com'\n    end\n\n    assert_response :success\n    assert_current_url '/users/password'\n    assert_have_selector \"input[type=email][value='invalid.test@test.com']\"\n    assert_contain 'not found'\n  end\n\n  test 'authenticated user should not be able to visit edit password page' do\n    sign_in_as_user\n    get edit_user_password_path\n    assert_response :redirect\n    assert_redirected_to root_path\n    assert warden.authenticated?(:user)\n  end\n\n  test 'not authenticated user without a reset password token should not be able to visit the page' do\n    get edit_user_password_path\n    assert_response :redirect\n    assert_redirected_to \"/users/sign_in\"\n  end\n\n  test 'not authenticated user with invalid reset password token should not be able to change their password' do\n    user = create_user\n    reset_password reset_password_token: 'invalid_reset_password'\n\n    assert_response :success\n    assert_current_url '/users/password'\n    assert_have_selector '#error_explanation'\n    assert_contain %r{Reset password token(.*)invalid}\n    assert_not user.reload.valid_password?('987654321')\n  end\n\n  test 'not authenticated user with valid reset password token but invalid password should not be able to change their password' do\n    user = create_user\n    request_forgot_password\n    reset_password do\n      fill_in 'Confirm new password', with: 'other_password'\n    end\n\n    assert_response :success\n    assert_current_url '/users/password'\n    assert_have_selector '#error_explanation'\n    assert_contain %r{Password confirmation doesn['’]t match Password}\n    assert_not user.reload.valid_password?('987654321')\n  end\n\n  test 'not authenticated user with valid data should be able to change their password' do\n    user = create_user\n    request_forgot_password\n    reset_password\n\n    assert_current_url '/'\n    assert_contain 'Your password has been changed successfully. You are now signed in.'\n    assert user.reload.valid_password?('987654321')\n  end\n\n  test 'after entering invalid data user should still be able to change their password' do\n    user = create_user\n    request_forgot_password\n\n    reset_password {  fill_in 'Confirm new password', with: 'other_password' }\n    assert_response :success\n    assert_have_selector '#error_explanation'\n    assert_not user.reload.valid_password?('987654321')\n\n    reset_password visit: false\n    assert_contain 'Your password has been changed successfully.'\n    assert user.reload.valid_password?('987654321')\n  end\n\n  test 'sign in user automatically after changing its password' do\n    create_user\n    request_forgot_password\n    reset_password\n\n    assert warden.authenticated?(:user)\n  end\n\n  test 'does not sign in user automatically after changing its password if config.sign_in_after_reset_password is false' do\n    swap Devise, sign_in_after_reset_password: false do\n      create_user\n      request_forgot_password\n      reset_password\n\n      assert_contain 'Your password has been changed successfully.'\n      assert_not_contain 'You are now signed in.'\n      assert_equal new_user_session_path, @request.path\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'does not sign in user automatically after changing its password if resource_class.sign_in_after_reset_password is false' do\n    swap_model_config User, sign_in_after_reset_password: false do\n      create_user\n      request_forgot_password\n      reset_password\n\n      assert_contain 'Your password has been changed successfully'\n      assert_not_contain 'You are now signed in.'\n      assert_equal new_user_session_path, @request.path\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'sign in user automatically after changing its password if resource_class.sign_in_after_reset_password is true' do\n    swap Devise, sign_in_after_reset_password: false do\n      swap_model_config User, sign_in_after_reset_password: true do\n        create_user\n        request_forgot_password\n        reset_password\n\n        assert warden.authenticated?(:user)\n      end\n    end\n  end\n\n  test 'does not sign in user automatically after changing its password if it\\'s locked and unlock strategy is :none or :time' do\n    [:none, :time].each do |strategy|\n      swap Devise, unlock_strategy: strategy do\n        create_user(locked: true)\n        request_forgot_password\n        reset_password\n\n        assert_contain 'Your password has been changed successfully.'\n        assert_not_contain 'You are now signed in.'\n        assert_equal new_user_session_path, @request.path\n        assert_not warden.authenticated?(:user)\n      end\n    end\n  end\n\n  test 'unlocks and signs in locked user automatically after changing it\\'s password if unlock strategy is :email' do\n    swap Devise, unlock_strategy: :email do\n      user = create_user(locked: true)\n      request_forgot_password\n      reset_password\n\n      assert_contain 'Your password has been changed successfully.'\n      assert_not user.reload.access_locked?\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'unlocks and signs in locked user automatically after changing it\\'s password if unlock strategy is :both' do\n    swap Devise, unlock_strategy: :both do\n      user = create_user(locked: true)\n      request_forgot_password\n      reset_password\n\n      assert_contain 'Your password has been changed successfully.'\n      assert_not user.reload.access_locked?\n      assert warden.authenticated?(:user)\n    end\n  end\n\n  test 'reset password request with valid e-mail in JSON format should return empty and valid response' do\n    create_user\n    post user_password_path(format: 'json'), params: { user: {email: \"user@test.com\"} }\n    assert_response :success\n    assert_equal({}.to_json, response.body)\n  end\n\n  test 'reset password request with invalid e-mail in JSON format should return valid response' do\n    create_user\n    post user_password_path(format: 'json'), params: { user: {email: \"invalid.test@test.com\"} }\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"errors\":{'\n  end\n\n  test 'reset password request with invalid e-mail in JSON format should return empty and valid response in paranoid mode' do\n    swap Devise, paranoid: true do\n      create_user\n      post user_password_path(format: 'json'), params: { user: {email: \"invalid@test.com\"} }\n      assert_response :success\n      assert_equal({}.to_json, response.body)\n    end\n  end\n\n  test 'change password with valid parameters in JSON format should return valid response' do\n    create_user\n    request_forgot_password\n    put user_password_path(format: 'json'), params: { user: {\n      reset_password_token: 'abcdef', password: '987654321', password_confirmation: '987654321'\n    } }\n    assert_response :success\n    assert warden.authenticated?(:user)\n  end\n\n  test 'change password with invalid token in JSON format should return invalid response' do\n    create_user\n    request_forgot_password\n    put user_password_path(format: 'json'), params: { user: {reset_password_token: 'invalid.token', password: '987654321', password_confirmation: '987654321'} }\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"errors\":{'\n  end\n\n  test 'change password with invalid new password in JSON format should return invalid response' do\n    user = create_user\n    request_forgot_password\n    put user_password_path(format: 'json'), params: { user: {reset_password_token: user.reload.reset_password_token, password: '', password_confirmation: '987654321'} }\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"errors\":{'\n  end\n\n  test \"when in paranoid mode and with an invalid e-mail, asking to reset a password should display a message that does not indicates that the e-mail does not exists in the database\" do\n    swap Devise, paranoid: true do\n      visit_new_password_path\n      fill_in \"email\", with: \"arandomemail@test.com\"\n      click_button 'Send me password reset instructions'\n\n      assert_not_contain \"1 error prohibited this user from being saved:\"\n      assert_not_contain \"Email not found\"\n      assert_contain \"If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes.\"\n      assert_current_url \"/users/sign_in\"\n    end\n  end\n\n  test \"when in paranoid mode and with a valid e-mail, asking to reset password should display a message that does not indicates that the email exists in the database and redirect to the failure route\" do\n    swap Devise, paranoid: true do\n      user = create_user\n      visit_new_password_path\n      fill_in 'email', with: user.email\n      click_button 'Send me password reset instructions'\n\n      assert_contain \"If your email address exists in our database, you will receive a password recovery link at your email address in a few minutes.\"\n      assert_current_url \"/users/sign_in\"\n    end\n  end\n\n  test \"after recovering a password, should set failed attempts to 0\" do\n    user = create_user\n    user.update_attribute(:failed_attempts, 10)\n\n    assert_equal 10, user.failed_attempts\n    request_forgot_password\n    reset_password\n\n    assert warden.authenticated?(:user)\n    user.reload\n    assert_equal 0, user.failed_attempts\n  end\nend\n"
  },
  {
    "path": "test/integration/registerable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass RegistrationTest < Devise::IntegrationTest\n\n  test 'a guest admin should be able to sign in successfully' do\n    get new_admin_session_path\n    click_link 'Sign up'\n\n    assert_template 'registrations/new'\n\n    fill_in 'email', with: 'new_user@test.com'\n    fill_in 'password', with: 'new_user123'\n    fill_in 'password confirmation', with: 'new_user123'\n    click_button 'Sign up'\n\n    assert_contain 'You have signed up successfully'\n    assert warden.authenticated?(:admin)\n    assert_current_url \"/admin_area/home\"\n\n    admin = Admin.to_adapter.find_first(order: [:id, :desc])\n    assert_equal 'new_user@test.com', admin.email\n  end\n\n  test 'a guest admin should be able to sign in and be redirected to a custom location' do\n    Devise::RegistrationsController.any_instance.stubs(:after_sign_up_path_for).returns(\"/?custom=1\")\n    get new_admin_session_path\n    click_link 'Sign up'\n\n    fill_in 'email', with: 'new_user@test.com'\n    fill_in 'password', with: 'new_user123'\n    fill_in 'password confirmation', with: 'new_user123'\n    click_button 'Sign up'\n\n    assert_contain 'Welcome! You have signed up successfully.'\n    assert warden.authenticated?(:admin)\n    assert_current_url \"/?custom=1\"\n  end\n\n  test 'a guest admin should not see a warning about minimum password length' do\n    get new_admin_session_path\n    assert_not_contain 'characters minimum'\n  end\n\n  def user_sign_up\n    ActionMailer::Base.deliveries.clear\n\n    get new_user_registration_path\n\n    fill_in 'email', with: 'new_user@test.com'\n    fill_in 'password', with: 'new_user123'\n    fill_in 'password confirmation', with: 'new_user123'\n    click_button 'Sign up'\n  end\n\n  test 'a guest user should see a warning about minimum password length' do\n    get new_user_registration_path\n    assert_contain '7 characters minimum'\n  end\n\n  test 'a guest user should be able to sign up successfully and be blocked by confirmation' do\n    user_sign_up\n\n    assert_contain 'A message with a confirmation link has been sent to your email address. Please follow the link to activate your account.'\n    assert_not_contain 'You have to confirm your account before continuing'\n    assert_current_url \"/\"\n\n    assert_not warden.authenticated?(:user)\n\n    user = User.to_adapter.find_first(order: [:id, :desc])\n    assert_equal 'new_user@test.com', user.email\n    assert_not user.confirmed?\n  end\n\n  test 'a guest user should receive the confirmation instructions from the default mailer' do\n    user_sign_up\n    assert_equal ['please-change-me@config-initializers-devise.com'], ActionMailer::Base.deliveries.first.from\n  end\n\n  test 'a guest user should receive the confirmation instructions from a custom mailer' do\n    User.any_instance.stubs(:devise_mailer).returns(Users::Mailer)\n    user_sign_up\n    assert_equal ['custom@example.com'], ActionMailer::Base.deliveries.first.from\n  end\n\n  test 'a guest user should be blocked by confirmation and redirected to a custom path' do\n    Devise::RegistrationsController.any_instance.stubs(:after_inactive_sign_up_path_for).returns(\"/?custom=1\")\n    get new_user_registration_path\n\n    fill_in 'email', with: 'new_user@test.com'\n    fill_in 'password', with: 'new_user123'\n    fill_in 'password confirmation', with: 'new_user123'\n    click_button 'Sign up'\n\n    assert_current_url \"/?custom=1\"\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'a guest user cannot sign up with invalid information' do\n    get new_user_registration_path\n\n    fill_in 'email', with: 'invalid_email'\n    fill_in 'password', with: 'new_user123'\n    fill_in 'password confirmation', with: 'new_user321'\n    click_button 'Sign up'\n\n    assert_template 'registrations/new'\n    assert_have_selector '#error_explanation'\n    assert_contain \"Email is invalid\"\n    assert_contain %r{Password confirmation doesn['’]t match Password}\n    assert_contain \"2 errors prohibited\"\n    assert_nil User.to_adapter.find_first\n\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'a guest should not sign up with email/password that already exists' do\n    create_user\n    get new_user_registration_path\n\n    fill_in 'email', with: 'user@test.com'\n    fill_in 'password', with: '123456'\n    fill_in 'password confirmation', with: '123456'\n    click_button 'Sign up'\n\n    assert_current_url '/users'\n    assert_contain(/Email.*already.*taken/)\n\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'a guest should not be able to change account' do\n    get edit_user_registration_path\n    assert_redirected_to new_user_session_path\n    follow_redirect!\n    assert_contain 'You need to sign in or sign up before continuing.'\n  end\n\n  test 'a signed in user should not be able to access sign up' do\n    sign_in_as_user\n    get new_user_registration_path\n    assert_redirected_to root_path\n  end\n\n  test 'a signed in user should be able to edit their account' do\n    sign_in_as_user\n    get edit_user_registration_path\n\n    fill_in 'email', with: 'user.new@example.com'\n    fill_in 'current password', with: '12345678'\n    click_button 'Update'\n\n    assert_current_url '/'\n    assert_contain 'Your account has been updated successfully.'\n\n    assert_equal \"user.new@example.com\", User.to_adapter.find_first.email\n  end\n\n  test 'a signed in user should still be able to use the website after changing their password' do\n    sign_in_as_user\n    get edit_user_registration_path\n\n    fill_in 'password', with: '1234567890'\n    fill_in 'password confirmation', with: '1234567890'\n    fill_in 'current password', with: '12345678'\n    click_button 'Update'\n\n    assert_contain 'Your account has been updated successfully.'\n    get users_path\n    assert warden.authenticated?(:user)\n  end\n\n  test 'a signed in user should not be able to use the website after changing their password if config.sign_in_after_change_password is false' do\n    swap Devise, sign_in_after_change_password: false do\n      sign_in_as_user\n      get edit_user_registration_path\n\n      fill_in 'password', with: '1234567890'\n      fill_in 'password confirmation', with: '1234567890'\n      fill_in 'current password', with: '12345678'\n      click_button 'Update'\n\n      assert_contain 'Your account has been updated successfully, but since your password was changed, you need to sign in again.'\n      assert_equal new_user_session_path, @request.path\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'a signed in user should not be able to use the website after changing their password if resource_class.sign_in_after_change_password is false' do\n    swap_model_config User, sign_in_after_change_password: false do\n      sign_in_as_user\n      get edit_user_registration_path\n\n      fill_in 'password', with: '1234567890'\n      fill_in 'password confirmation', with: '1234567890'\n      fill_in 'current password', with: '12345678'\n      click_button 'Update'\n\n      assert_contain 'Your account has been updated successfully, but since your password was changed, you need to sign in again.'\n      assert_equal new_user_session_path, @request.path\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'a signed in user should be able to use the website after changing its email with config.sign_in_after_change_password is false' do\n    swap Devise, sign_in_after_change_password: false do\n      sign_in_as_user\n      get edit_user_registration_path\n\n      fill_in 'email', with: 'user.new@example.com'\n      fill_in 'current password', with: '12345678'\n      click_button 'Update'\n\n      assert_current_url '/'\n      assert_contain 'Your account has been updated successfully.'\n\n      assert warden.authenticated?(:user)\n      assert_equal \"user.new@example.com\", User.to_adapter.find_first.email\n    end\n  end\n\n  test 'a signed in user should not change their current user with invalid password' do\n    sign_in_as_user\n    get edit_user_registration_path\n\n    fill_in 'email', with: 'user.new@example.com'\n    fill_in 'current password', with: 'invalid'\n    click_button 'Update'\n\n    assert_template 'registrations/edit'\n    assert_contain 'user@test.com'\n    assert_have_selector 'form input[value=\"user.new@example.com\"]'\n\n    assert_equal \"user@test.com\", User.to_adapter.find_first.email\n  end\n\n  test 'a signed in user should be able to edit their password' do\n    sign_in_as_user\n    get edit_user_registration_path\n\n    fill_in 'password', with: 'pass1234'\n    fill_in 'password confirmation', with: 'pass1234'\n    fill_in 'current password', with: '12345678'\n    click_button 'Update'\n\n    assert_current_url '/'\n    assert_contain 'Your account has been updated successfully.'\n\n    assert User.to_adapter.find_first.valid_password?('pass1234')\n  end\n\n  test 'a signed in user should not be able to edit their password with invalid confirmation' do\n    sign_in_as_user\n    get edit_user_registration_path\n\n    fill_in 'password', with: 'pas123'\n    fill_in 'password confirmation', with: ''\n    fill_in 'current password', with: '12345678'\n    click_button 'Update'\n\n    assert_contain %r{Password confirmation doesn['’]t match Password}\n    assert_not User.to_adapter.find_first.valid_password?('pas123')\n  end\n\n  test 'a signed in user should see a warning about minimum password length' do\n    sign_in_as_user\n    get edit_user_registration_path\n    assert_contain 'characters minimum'\n  end\n\n  test 'a signed in user should be able to cancel their account' do\n    sign_in_as_user\n    get edit_user_registration_path\n\n    click_button \"Cancel my account\"\n    assert_contain \"Bye! Your account has been successfully cancelled. We hope to see you again soon.\"\n\n    assert_empty User.to_adapter.find_all\n  end\n\n  test 'a user should be able to cancel sign up by deleting data in the session' do\n    get \"/set\"\n    assert_equal \"something\", @request.session[\"devise.foo_bar\"]\n\n    get \"/users/sign_up\"\n    assert_equal \"something\", @request.session[\"devise.foo_bar\"]\n\n    get \"/users/cancel\"\n    assert_nil @request.session[\"devise.foo_bar\"]\n    assert_redirected_to new_user_registration_path\n  end\n\n  test 'a user with JSON sign up stub' do\n    get new_user_registration_path(format: 'json')\n    assert_response :success\n    assert_match %({\"user\":), response.body\n    assert_no_match(/\"confirmation_token\"/, response.body)\n  end\n\n  test 'an admin sign up with valid information in JSON format should return valid response' do\n    post admin_registration_path(format: 'json'), params: { admin: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }\n    assert_response :success\n    assert_includes response.body, '{\"admin\":{'\n\n    admin = Admin.to_adapter.find_first(order: [:id, :desc])\n    assert_equal 'new_user@test.com', admin.email\n  end\n\n  test 'a user sign up with valid information in JSON format should return valid response' do\n    post user_registration_path(format: 'json'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'new_user123' } }\n    assert_response :success\n    assert_includes response.body, '{\"user\":{'\n\n    user = User.to_adapter.find_first(order: [:id, :desc])\n    assert_equal 'new_user@test.com', user.email\n  end\n\n  test 'a user sign up with invalid information in JSON format should return invalid response' do\n    post user_registration_path(format: 'json'), params: { user: { email: 'new_user@test.com', password: 'new_user123', password_confirmation: 'invalid' } }\n    assert_response :unprocessable_entity\n    assert_includes response.body, '{\"errors\":{'\n  end\n\n  test 'a user update information with valid data in JSON format should return valid response' do\n    user = sign_in_as_user\n    put user_registration_path(format: 'json'), params: { user: { current_password: '12345678', email: 'user.new@test.com' } }\n    assert_response :success\n    assert_equal 'user.new@test.com', user.reload.email\n  end\n\n  test 'a user update information with invalid data in JSON format should return invalid response' do\n    user = sign_in_as_user\n    put user_registration_path(format: 'json'), params: { user: { current_password: 'invalid', email: 'user.new@test.com' } }\n    assert_response :unprocessable_entity\n    assert_equal 'user@test.com', user.reload.email\n  end\n\n  test 'a user cancel their account in JSON format should return valid response' do\n    sign_in_as_user\n    delete user_registration_path(format: 'json')\n    assert_response :success\n    assert_equal 0, User.to_adapter.find_all.size\n  end\nend\n\nclass ReconfirmableRegistrationTest < Devise::IntegrationTest\n  test 'a signed in admin should see a more appropriate flash message when editing their account if reconfirmable is enabled' do\n    sign_in_as_admin\n    get edit_admin_registration_path\n\n    fill_in 'email', with: 'admin.new@example.com'\n    fill_in 'current password', with: '123456'\n    click_button 'Update'\n\n    assert_current_url '/admin_area/home'\n    assert_contain 'but we need to verify your new email address'\n    assert_equal 'admin.new@example.com', Admin.to_adapter.find_first.unconfirmed_email\n\n    get edit_admin_registration_path\n    assert_contain 'Currently waiting confirmation for: admin.new@example.com'\n  end\n\n  test 'a signed in admin should not see a reconfirmation message if they did not change their password' do\n    sign_in_as_admin\n    get edit_admin_registration_path\n\n    fill_in 'password', with: 'pas123'\n    fill_in 'password confirmation', with: 'pas123'\n    fill_in 'current password', with: '123456'\n    click_button 'Update'\n\n    assert_current_url '/admin_area/home'\n    assert_contain 'Your account has been updated successfully.'\n\n    assert Admin.to_adapter.find_first.valid_password?('pas123')\n  end\n\n  test 'a signed in admin should not see a reconfirmation message if they did not change their email, despite having an unconfirmed email' do\n    sign_in_as_admin\n\n    get edit_admin_registration_path\n    fill_in 'email', with: 'admin.new@example.com'\n    fill_in 'current password', with: '123456'\n    click_button 'Update'\n\n    get edit_admin_registration_path\n    fill_in 'password', with: 'pas123'\n    fill_in 'password confirmation', with: 'pas123'\n    fill_in 'current password', with: '123456'\n    click_button 'Update'\n\n    assert_current_url '/admin_area/home'\n    assert_contain 'Your account has been updated successfully.'\n\n    assert_equal \"admin.new@example.com\", Admin.to_adapter.find_first.unconfirmed_email\n    assert Admin.to_adapter.find_first.valid_password?('pas123')\n  end\nend\n"
  },
  {
    "path": "test/integration/rememberable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass RememberMeTest < Devise::IntegrationTest\n  def create_user_and_remember(add_to_token = '')\n    user = create_user\n    user.remember_me!\n    raw_cookie = User.serialize_into_cookie(user).tap { |a| a[1] << add_to_token }\n    cookies['remember_user_token'] = generate_signed_cookie(raw_cookie)\n    user\n  end\n\n  def generate_signed_cookie(raw_cookie)\n    request = ActionController::TestRequest.create(Class.new) # needs a \"controller class\"\n    request.cookie_jar.signed['raw_cookie'] = raw_cookie\n    request.cookie_jar['raw_cookie']\n  end\n\n  def signed_cookie(key)\n    controller.send(:cookies).signed[key]\n  end\n\n  def cookie_expires(key)\n    cookie  = response.headers[\"Set-Cookie\"].split(\"\\n\").grep(/^#{key}/).first\n    expires = cookie.split(\";\").map(&:strip).grep(/^expires=/).first\n    Time.parse(expires).utc\n  end\n\n  test 'do not remember the user if they have not checked remember me option' do\n    sign_in_as_user\n    assert_nil request.cookies[\"remember_user_cookie\"]\n  end\n\n  test 'handle unverified requests gets rid of caches' do\n    swap ApplicationController, allow_forgery_protection: true do\n      post exhibit_user_url(1)\n      assert_not warden.authenticated?(:user)\n\n      create_user_and_remember\n      post exhibit_user_url(1)\n      assert_equal \"User is not authenticated\", response.body\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'handle unverified requests does not create cookies on sign in' do\n    swap ApplicationController, allow_forgery_protection: true do\n      get new_user_session_path\n      assert request.session[:_csrf_token]\n\n      post user_session_path, params: {\n          authenticity_token: \"oops\",\n          user: { email: \"jose.valim@gmail.com\", password: \"123456\", remember_me: \"1\" }\n        }\n      assert_not warden.authenticated?(:user)\n      assert_not request.cookies['remember_user_token']\n    end\n  end\n\n  test 'generate remember token after sign in' do\n    sign_in_as_user remember_me: true\n    assert request.cookies['remember_user_token']\n  end\n\n  test 'generate remember token after sign in setting cookie options' do\n    # We test this by asserting the cookie is not sent after the redirect\n    # since we changed the domain. This is the only difference with the\n    # previous test.\n    swap Devise, rememberable_options: { domain: \"omg.somewhere.com\" } do\n      sign_in_as_user remember_me: true\n      assert_nil request.cookies[\"remember_user_token\"]\n    end\n  end\n\n  test 'generate remember token with a custom key' do\n    swap Devise, rememberable_options: { key: \"v1lat_token\" } do\n      sign_in_as_user remember_me: true\n      assert request.cookies[\"v1lat_token\"]\n    end\n  end\n\n  test 'generate remember token after sign in setting session options' do\n    begin\n      Rails.configuration.session_options[:domain] = \"omg.somewhere.com\"\n      sign_in_as_user remember_me: true\n      assert_nil request.cookies[\"remember_user_token\"]\n    ensure\n      Rails.configuration.session_options.delete(:domain)\n    end\n  end\n\n  test 'remember the user before sign in' do\n    user = create_user_and_remember\n    get users_path\n    assert_response :success\n    assert warden.authenticated?(:user)\n    assert warden.user(:user) == user\n  end\n\n  test 'remember the user before sign up and redirect them to their home' do\n    create_user_and_remember\n    get new_user_registration_path\n    assert warden.authenticated?(:user)\n    assert_redirected_to root_path\n  end\n\n  test 'does not extend remember period through sign in' do\n    swap Devise, extend_remember_period: true, remember_for: 1.year do\n      user = create_user\n      user.remember_me!\n\n      user.remember_created_at = old = 10.days.ago\n      user.save\n\n      sign_in_as_user remember_me: true\n      user.reload\n\n      assert warden.user(:user) == user\n      assert_equal old.to_i, user.remember_created_at.to_i\n    end\n  end\n\n  test 'extends remember period when extend remember period config is true' do\n    swap Devise, extend_remember_period: true, remember_for: 1.year do\n      create_user_and_remember\n      old_remember_token = nil\n\n      travel_to 1.day.ago do\n        get root_path\n        old_remember_token = request.cookies['remember_user_token']\n      end\n\n      get root_path\n      current_remember_token = request.cookies['remember_user_token']\n\n      assert_not_equal old_remember_token, current_remember_token\n    end\n  end\n\n  test 'does not extend remember period when extend period config is false' do\n    swap Devise, extend_remember_period: false, remember_for: 1.year do\n      create_user_and_remember\n      old_remember_token = nil\n\n      travel_to 1.day.ago do\n        get root_path\n        old_remember_token = request.cookies['remember_user_token']\n      end\n\n      get root_path\n      current_remember_token = request.cookies['remember_user_token']\n\n      assert_equal old_remember_token, current_remember_token\n    end\n  end\n\n  test 'do not remember other scopes' do\n    create_user_and_remember\n    get root_path\n    assert_response :success\n    assert warden.authenticated?(:user)\n    assert_not warden.authenticated?(:admin)\n  end\n\n  test 'do not remember with invalid token' do\n    create_user_and_remember('add')\n    get users_path\n    assert_not warden.authenticated?(:user)\n    assert_redirected_to new_user_session_path\n  end\n\n  test 'do not remember with expired token' do\n    create_user_and_remember\n    swap Devise, remember_for: 0.days do\n      get users_path\n      assert_not warden.authenticated?(:user)\n      assert_redirected_to new_user_session_path\n    end\n  end\n\n  test 'do not remember the user anymore after forget' do\n    create_user_and_remember\n    get users_path\n    assert warden.authenticated?(:user)\n\n    delete destroy_user_session_path\n    assert_not warden.authenticated?(:user)\n    assert_nil warden.cookies['remember_user_token']\n\n    get users_path\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'changing user password expires remember me token' do\n    user = create_user_and_remember\n    user.password = \"another_password\"\n    user.password_confirmation = \"another_password\"\n    user.save!\n\n    get users_path\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'valid sign in calls after_remembered callback' do\n    user = create_user_and_remember\n\n    User.expects(:serialize_from_cookie).returns user\n    user.expects :after_remembered\n\n    get new_user_registration_path\n  end\nend\n"
  },
  {
    "path": "test/integration/timeoutable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass SessionTimeoutTest < Devise::IntegrationTest\n\n  def last_request_at\n    @controller.user_session['last_request_at']\n  end\n\n  test 'set last request at in user session after each request' do\n    sign_in_as_user\n    assert_not_nil last_request_at\n\n    @controller.user_session.delete('last_request_at')\n    get users_path\n    assert_not_nil last_request_at\n  end\n\n  test 'set last request at in user session after each request is skipped if tracking is disabled' do\n    sign_in_as_user\n    old_last_request = last_request_at\n    assert_not_nil last_request_at\n\n    get users_path, headers: { 'devise.skip_trackable' => true }\n    assert_equal old_last_request, last_request_at\n  end\n\n  test 'does not set last request at in user session after each request if timeoutable is disabled' do\n    sign_in_as_user\n    old_last_request = last_request_at\n    assert_not_nil last_request_at\n\n    new_time = 2.seconds.from_now\n    Time.stubs(:now).returns(new_time)\n\n    get users_path, headers: { 'devise.skip_timeoutable' => true }\n    assert_equal old_last_request, last_request_at\n  end\n\n  test 'does not time out user session before default limit time' do\n    sign_in_as_user\n    assert_response :success\n    assert warden.authenticated?(:user)\n\n    get users_path\n    assert_response :success\n    assert warden.authenticated?(:user)\n  end\n\n  test 'time out user session after default limit time when sign_out_all_scopes is false' do\n    swap Devise, sign_out_all_scopes: false do\n      sign_in_as_admin\n\n      user = sign_in_as_user\n      get expire_user_path(user)\n      assert_not_nil last_request_at\n\n      get users_path\n      assert_redirected_to users_path\n      assert_not warden.authenticated?(:user)\n      assert warden.authenticated?(:admin)\n    end\n  end\n\n  test 'time out all sessions after default limit time when sign_out_all_scopes is true' do\n    swap Devise, sign_out_all_scopes: true do\n      sign_in_as_admin\n\n      user = sign_in_as_user\n      get expire_user_path(user)\n      assert_not_nil last_request_at\n\n      get root_path\n      assert_not warden.authenticated?(:user)\n      assert_not warden.authenticated?(:admin)\n    end\n  end\n\n  test 'time out user session after default limit time and redirect to latest get request' do\n    user = sign_in_as_user\n    visit edit_form_user_path(user)\n\n    click_button 'Update'\n    sign_in_as_user\n\n    assert_equal edit_form_user_url(user), current_url\n  end\n\n  test 'time out is not triggered on sign out' do\n    user = sign_in_as_user\n    get expire_user_path(user)\n\n    delete destroy_user_session_path\n\n    assert_response :redirect\n    assert_redirected_to root_path\n    follow_redirect!\n    assert_contain 'Signed out successfully'\n  end\n\n  test 'expired session is not extended by sign in page' do\n    user = sign_in_as_user\n    get expire_user_path(user)\n    assert warden.authenticated?(:user)\n\n    get \"/users/sign_in\"\n    assert_redirected_to \"/users/sign_in\"\n    follow_redirect!\n\n    assert_response :success\n    assert_contain 'Log in'\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'time out is not triggered on sign in' do\n    user = sign_in_as_user\n    get expire_user_path(user)\n\n    post \"/users/sign_in\", params: { email: user.email, password: \"123456\" }\n\n    assert_response :redirect\n    follow_redirect!\n    assert_contain 'You are signed in'\n  end\n\n  test 'user configured timeout limit' do\n    swap Devise, timeout_in: 8.minutes do\n      user = sign_in_as_user\n\n      get users_path\n      assert_not_nil last_request_at\n      assert_response :success\n      assert warden.authenticated?(:user)\n\n      get expire_user_path(user)\n      get users_path\n      assert_redirected_to users_path\n      assert_not warden.authenticated?(:user)\n    end\n  end\n\n  test 'error message with i18n' do\n    store_translations :en, devise: {\n      failure: { user: { timeout: 'Session expired!' } }\n    } do\n      user = sign_in_as_user\n\n      get expire_user_path(user)\n      get root_path\n      follow_redirect!\n      assert_contain 'Session expired!'\n    end\n  end\n\n  test 'error message with i18n with double redirect' do\n    store_translations :en, devise: {\n      failure: { user: { timeout: 'Session expired!' } }\n    } do\n      user = sign_in_as_user\n\n      get expire_user_path(user)\n      get users_path\n      follow_redirect!\n      follow_redirect!\n      assert_contain 'Session expired!'\n    end\n  end\n\n  test 'error message redirect respects i18n locale set' do\n    user = sign_in_as_user\n\n    get expire_user_path(user)\n    get root_path(locale: \"pt-BR\")\n    follow_redirect!\n\n    assert_contain 'Sua sessão expirou. Por favor faça o login novamente para continuar.'\n    assert_not warden.authenticated?(:user)\n  end\n\n  test 'time out not triggered if remembered' do\n    user = sign_in_as_user remember_me: true\n    get expire_user_path(user)\n    assert_not_nil last_request_at\n\n    get users_path\n    assert_response :success\n    assert warden.authenticated?(:user)\n  end\n\n  test 'does not crash when the last_request_at is a String' do\n    user = sign_in_as_user\n\n    assert_nothing_raised do\n      get edit_form_user_path(user, last_request_at: Time.now.utc.to_s)\n      get users_path\n    end\n  end\nend\n"
  },
  {
    "path": "test/integration/trackable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass TrackableHooksTest < Devise::IntegrationTest\n  test \"trackable should not run model validations\" do\n    sign_in_as_user\n\n    assert_not User.validations_performed\n  end\n\n  test \"current and last sign in timestamps are updated on each sign in\" do\n    user = create_user\n    assert_nil user.current_sign_in_at\n    assert_nil user.last_sign_in_at\n\n    sign_in_as_user\n    user.reload\n\n    assert user.current_sign_in_at.acts_like?(:time)\n    assert user.last_sign_in_at.acts_like?(:time)\n\n    assert_equal user.current_sign_in_at, user.last_sign_in_at\n    assert user.current_sign_in_at >= user.created_at\n\n    delete destroy_user_session_path\n    new_time = 2.seconds.from_now\n    Time.stubs(:now).returns(new_time)\n\n    sign_in_as_user\n    user.reload\n    assert user.current_sign_in_at > user.last_sign_in_at\n  end\n\n  test \"current and last sign in remote ip are updated on each sign in\" do\n    user = create_user\n    assert_nil user.current_sign_in_ip\n    assert_nil user.last_sign_in_ip\n\n    sign_in_as_user\n    user.reload\n\n    assert_equal \"127.0.0.1\", user.current_sign_in_ip\n    assert_equal \"127.0.0.1\", user.last_sign_in_ip\n  end\n\n  test \"current and last sign in remote ip returns original ip behind a non transparent proxy\" do\n    user = create_user\n\n    arbitrary_ip = '200.121.1.69'\n    sign_in_as_user do\n      header 'HTTP_X_FORWARDED_FOR', arbitrary_ip\n    end\n    user.reload\n    assert_equal arbitrary_ip, user.current_sign_in_ip\n    assert_equal arbitrary_ip, user.last_sign_in_ip\n  end\n\n  test \"increase sign in count\" do\n    user = create_user\n    assert_equal 0, user.sign_in_count\n\n    sign_in_as_user\n    user.reload\n    assert_equal 1, user.sign_in_count\n\n    delete destroy_user_session_path\n    sign_in_as_user\n    user.reload\n    assert_equal 2, user.sign_in_count\n  end\n\n  test \"does not update anything if user has signed out along the way\" do\n    swap Devise, allow_unconfirmed_access_for: 0.days do\n      user = create_user(confirm: false)\n      sign_in_as_user\n\n      user.reload\n      assert_nil user.current_sign_in_at\n      assert_nil user.last_sign_in_at\n    end\n  end\n\n  test \"do not track if devise.skip_trackable is set\" do\n    user = create_user\n    sign_in_as_user do\n      header 'devise.skip_trackable', '1'\n    end\n    user.reload\n    assert_equal 0, user.sign_in_count\n    delete destroy_user_session_path\n\n    sign_in_as_user do\n      header 'devise.skip_trackable', false\n    end\n    user.reload\n    assert_equal 1, user.sign_in_count\n  end\n\nend\n"
  },
  {
    "path": "test/mailers/confirmation_instructions_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass ConfirmationInstructionsTest < ActionMailer::TestCase\n\n  def setup\n    setup_mailer\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'test@example.com'\n  end\n\n  def teardown\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'\n  end\n\n  def user\n    @user ||= create_user\n  end\n\n  def mail\n    @mail ||= begin\n      user\n      ActionMailer::Base.deliveries.first\n    end\n  end\n\n  test 'email sent after creating the user' do\n    assert_not_nil mail\n  end\n\n  test 'content type should be set to html' do\n    assert_includes mail.content_type, 'text/html'\n  end\n\n  test 'send confirmation instructions to the user email' do\n    mail\n    assert_equal [user.email], mail.to\n  end\n\n  test 'set up sender from configuration' do\n    assert_equal ['test@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults' do\n    Devise.mailer = 'Users::Mailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults with proc' do\n    Devise.mailer = 'Users::FromProcMailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'custom mailer renders parent mailer template' do\n    Devise.mailer = 'Users::Mailer'\n    assert_present mail.body.encoded\n  end\n\n  test 'set up reply to as copy from sender' do\n    assert_equal ['test@example.com'], mail.reply_to\n  end\n\n  test 'set up reply to as different if set in defaults' do\n    Devise.mailer = 'Users::ReplyToMailer'\n    assert_equal ['custom@example.com'], mail.from\n    assert_equal ['custom_reply_to@example.com'], mail.reply_to\n  end\n\n  test 'set up subject from I18n' do\n    store_translations :en, devise: { mailer: { confirmation_instructions: { subject: 'Account Confirmation' } } } do\n      assert_equal 'Account Confirmation', mail.subject\n    end\n  end\n\n  test 'subject namespaced by model' do\n    store_translations :en, devise: { mailer: { confirmation_instructions: { user_subject: 'User Account Confirmation' } } } do\n      assert_equal 'User Account Confirmation', mail.subject\n    end\n  end\n\n  test 'body should have user info' do\n    assert_match user.email, mail.body.encoded\n  end\n\n  test 'body should have link to confirm the account' do\n    host, port = ActionMailer::Base.default_url_options.values_at :host, :port\n\n    if mail.body.encoded =~ %r{<a href=\\\"http://#{host}:#{port}/users/confirmation\\?confirmation_token=([^\"]+)\">}\n      assert_equal user.confirmation_token, $1\n    else\n      flunk \"expected confirmation url regex to match\"\n    end\n  end\n\n  test 'renders a scoped if scoped_views is set to true' do\n    swap Devise, scoped_views: true do\n      assert_equal user.email, mail.body.decoded\n    end\n  end\n\n  test 'renders a scoped if scoped_views is set in the mailer class' do\n    begin\n      Devise::Mailer.scoped_views = true\n      assert_equal user.email, mail.body.decoded\n    ensure\n      Devise::Mailer.send :remove_instance_variable, :@scoped_views\n    end\n  end\n\n  test 'mailer sender accepts a proc' do\n    swap Devise, mailer_sender: proc { \"another@example.com\" } do\n      assert_equal ['another@example.com'], mail.from\n    end\n  end\nend\n"
  },
  {
    "path": "test/mailers/email_changed_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass EmailChangedTest < ActionMailer::TestCase\n  def setup\n    setup_mailer\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'test@example.com'\n    Devise.send_email_changed_notification = true\n  end\n\n  def teardown\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'\n    Devise.send_email_changed_notification = false\n  end\n\n  def user\n    @user ||= create_user.tap { |u|\n      @original_user_email = u.email\n      u.update!(email: 'new-email@example.com')\n    }\n  end\n\n  def mail\n    @mail ||= begin\n      user\n      ActionMailer::Base.deliveries.last\n    end\n  end\n\n  test 'email sent after changing the user email' do\n    assert_not_nil mail\n  end\n\n  test 'content type should be set to html' do\n    assert_includes mail.content_type, 'text/html'\n  end\n\n  test 'send email changed to the original user email' do\n    mail\n    assert_equal [@original_user_email], mail.to\n  end\n\n  test 'set up sender from configuration' do\n    assert_equal ['test@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults' do\n    Devise.mailer = 'Users::Mailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults with proc' do\n    Devise.mailer = 'Users::FromProcMailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'custom mailer renders parent mailer template' do\n    Devise.mailer = 'Users::Mailer'\n    assert_present mail.body.encoded\n  end\n\n  test 'set up reply to as copy from sender' do\n    assert_equal ['test@example.com'], mail.reply_to\n  end\n\n  test 'set up reply to as different if set in defaults' do\n    Devise.mailer = 'Users::ReplyToMailer'\n    assert_equal ['custom@example.com'], mail.from\n    assert_equal ['custom_reply_to@example.com'], mail.reply_to\n  end\n\n  test 'set up subject from I18n' do\n    store_translations :en, devise: { mailer: { email_changed: { subject: 'Email Has Changed' } } } do\n      assert_equal 'Email Has Changed', mail.subject\n    end\n  end\n\n  test 'subject namespaced by model' do\n    store_translations :en, devise: { mailer: { email_changed: { user_subject: 'User Email Has Changed' } } } do\n      assert_equal 'User Email Has Changed', mail.subject\n    end\n  end\n\n  test 'body should have user info' do\n    body = mail.body.encoded\n    assert_match \"Hello #{@original_user_email}\", body\n    assert_match \"has been changed to #{user.email}\", body\n  end\nend\n\nclass EmailChangedReconfirmationTest < ActionMailer::TestCase\n  def setup\n    setup_mailer\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'test@example.com'\n    Devise.send_email_changed_notification = true\n  end\n\n  def teardown\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'\n    Devise.send_email_changed_notification = false\n  end\n\n  def admin\n    @admin ||= create_admin.tap { |u|\n      @original_admin_email = u.email\n      u.update!(email: 'new-email@example.com')\n    }\n  end\n\n  def mail\n    @mail ||= begin\n      admin\n      ActionMailer::Base.deliveries[-2]\n    end\n  end\n\n  test 'send email changed to the original user email' do\n    mail\n    assert_equal [@original_admin_email], mail.to\n  end\n\n  test 'body should have unconfirmed user info' do\n    body = mail.body.encoded\n    assert_match admin.email, body\n    assert_match \"is being changed to #{admin.unconfirmed_email}\", body\n  end\nend\n"
  },
  {
    "path": "test/mailers/mailer_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"test_helper\"\n\nclass MailerTest < ActionMailer::TestCase\n  test \"pass given block to #mail call\" do\n    class TestMailer < Devise::Mailer\n      def confirmation_instructions(record, token, opts = {})\n        @token = token\n        devise_mail(record, :confirmation_instructions, opts) do |format|\n          format.html(content_transfer_encoding: \"7bit\")\n        end\n      end\n    end\n\n    mail = TestMailer.confirmation_instructions(create_user, \"confirmation-token\")\n\n    assert mail.content_transfer_encoding, \"7bit\"\n  end\n\n  test \"default values defined as proc with different arity are handled correctly\" do\n    class TestMailerWithDefault < Devise::Mailer\n      default from: -> { computed_from }\n      default reply_to: ->(_) { computed_reply_to }\n\n      def confirmation_instructions(record, token, opts = {})\n        @token = token\n        devise_mail(record, :confirmation_instructions, opts)\n      end\n\n      private\n\n      def computed_from\n        \"from@example.com\"\n      end\n\n      def computed_reply_to\n        \"reply_to@example.com\"\n      end\n    end\n\n    mail = TestMailerWithDefault.confirmation_instructions(create_user, \"confirmation-token\")\n    assert mail.from, \"from@example.com\"\n    assert mail.reply_to, \"reply_to@example.com\"\n  end\nend\n"
  },
  {
    "path": "test/mailers/reset_password_instructions_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass ResetPasswordInstructionsTest < ActionMailer::TestCase\n  def setup\n    setup_mailer\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'test@example.com'\n  end\n\n  def teardown\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'\n  end\n\n  def user\n    @user ||= begin\n      user = create_user\n      user.send_reset_password_instructions\n      user\n    end\n  end\n\n  def mail\n    @mail ||= begin\n      user\n      ActionMailer::Base.deliveries.last\n    end\n  end\n\n  test 'email sent after resetting the user password' do\n    assert_not_nil mail\n  end\n\n  test 'content type should be set to html' do\n    assert_includes mail.content_type, 'text/html'\n  end\n\n  test 'send confirmation instructions to the user email' do\n    assert_equal [user.email], mail.to\n  end\n\n  test 'set up sender from configuration' do\n    assert_equal ['test@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults' do\n    Devise.mailer = 'Users::Mailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults with proc' do\n    Devise.mailer = 'Users::FromProcMailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'custom mailer renders parent mailer template' do\n    Devise.mailer = 'Users::Mailer'\n    assert_present mail.body.encoded\n  end\n\n  test 'set up reply to as copy from sender' do\n    assert_equal ['test@example.com'], mail.reply_to\n  end\n\n  test 'set up subject from I18n' do\n    store_translations :en, devise: { mailer: { reset_password_instructions: { subject: 'Reset instructions' } } } do\n      assert_equal 'Reset instructions', mail.subject\n    end\n  end\n\n  test 'subject namespaced by model' do\n    store_translations :en, devise: { mailer: { reset_password_instructions: { user_subject: 'User Reset Instructions' } } } do\n      assert_equal 'User Reset Instructions', mail.subject\n    end\n  end\n\n  test 'body should have user info' do\n    assert_match user.email, mail.body.encoded\n  end\n\n  test 'body should have link to confirm the account' do\n    host, port = ActionMailer::Base.default_url_options.values_at :host, :port\n\n    if mail.body.encoded =~ %r{<a href=\\\"http://#{host}:#{port}/users/password/edit\\?reset_password_token=([^\"]+)\">}\n      assert_equal user.reset_password_token, Devise.token_generator.digest(user.class, :reset_password_token, $1)\n    else\n      flunk \"expected reset password url regex to match\"\n    end\n  end\n\n  test 'mailer sender accepts a proc' do\n    swap Devise, mailer_sender: proc { \"another@example.com\" } do\n      assert_equal ['another@example.com'], mail.from\n    end\n  end\nend\n"
  },
  {
    "path": "test/mailers/unlock_instructions_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass UnlockInstructionsTest < ActionMailer::TestCase\n\n  def setup\n    setup_mailer\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'test@example.com'\n  end\n\n  def teardown\n    Devise.mailer = 'Devise::Mailer'\n    Devise.mailer_sender = 'please-change-me@config-initializers-devise.com'\n  end\n\n  def user\n    @user ||= begin\n      user = create_user\n      user.lock_access!\n      user\n    end\n  end\n\n  def mail\n    @mail ||= begin\n      user\n      ActionMailer::Base.deliveries.last\n    end\n  end\n\n  test 'email sent after locking the user' do\n    assert_not_nil mail\n  end\n\n  test 'content type should be set to html' do\n    assert_includes mail.content_type, 'text/html'\n  end\n\n  test 'send unlock instructions to the user email' do\n    assert_equal [user.email], mail.to\n  end\n\n  test 'set up sender from configuration' do\n    assert_equal ['test@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults' do\n    Devise.mailer = 'Users::Mailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'set up sender from custom mailer defaults with proc' do\n    Devise.mailer = 'Users::FromProcMailer'\n    assert_equal ['custom@example.com'], mail.from\n  end\n\n  test 'custom mailer renders parent mailer template' do\n    Devise.mailer = 'Users::Mailer'\n    assert_present mail.body.encoded\n  end\n\n  test 'set up reply to as copy from sender' do\n    assert_equal ['test@example.com'], mail.reply_to\n  end\n\n  test 'set up subject from I18n' do\n    store_translations :en, devise: { mailer: { unlock_instructions:  { subject: 'Yo unlock instructions' } } } do\n      assert_equal 'Yo unlock instructions', mail.subject\n    end\n  end\n\n  test 'subject namespaced by model' do\n    store_translations :en, devise: { mailer: { unlock_instructions: { user_subject: 'User Unlock Instructions' } } } do\n      assert_equal 'User Unlock Instructions', mail.subject\n    end\n  end\n\n  test 'body should have user info' do\n    assert_match user.email, mail.body.encoded\n  end\n\n  test 'body should have link to unlock the account' do\n    host, port = ActionMailer::Base.default_url_options.values_at :host, :port\n\n    if mail.body.encoded =~ %r{<a href=\\\"http://#{host}:#{port}/users/unlock\\?unlock_token=([^\"]+)\">}\n      assert_equal user.unlock_token, Devise.token_generator.digest(user.class, :unlock_token, $1)\n    else\n      flunk \"expected unlock url regex to match\"\n    end\n  end\nend\n"
  },
  {
    "path": "test/mapping_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass FakeRequest < Struct.new(:path_info, :params)\nend\n\nclass MappingTest < ActiveSupport::TestCase\n  def fake_request(path, params = {})\n    FakeRequest.new(path, params)\n  end\n\n  test 'store options' do\n    mapping = Devise.mappings[:user]\n    assert_equal User,                mapping.to\n    assert_equal User.devise_modules, mapping.modules\n    assert_equal \"users\",             mapping.scoped_path\n    assert_equal :user,               mapping.singular\n    assert_equal \"users\",             mapping.path\n    assert_equal \"/users\",            mapping.fullpath\n  end\n\n  test 'store options with namespace' do\n    mapping = Devise.mappings[:publisher_account]\n    assert_equal Admin,                 mapping.to\n    assert_equal \"publisher/accounts\",  mapping.scoped_path\n    assert_equal :publisher_account,    mapping.singular\n    assert_equal \"accounts\",            mapping.path\n    assert_equal \"/publisher/accounts\", mapping.fullpath\n  end\n\n  test 'allows path to be given' do\n    assert_equal \"admin_area\", Devise.mappings[:admin].path\n  end\n\n  test 'allows to skip all routes' do\n    assert_equal [], Devise.mappings[:skip_admin].used_routes\n  end\n\n  test 'sign_out_via defaults to :delete' do\n    assert_equal :delete, Devise.mappings[:user].sign_out_via\n  end\n\n  test 'allows custom sign_out_via to be given' do\n    assert_equal :delete,          Devise.mappings[:sign_out_via_delete].sign_out_via\n    assert_equal :post,            Devise.mappings[:sign_out_via_post].sign_out_via\n    assert_equal [:delete, :post], Devise.mappings[:sign_out_via_delete_or_post].sign_out_via\n  end\n\n  test 'allows custom singular to be given' do\n    assert_equal \"accounts\", Devise.mappings[:manager].path\n  end\n\n  test 'has strategies depending on the model declaration' do\n    assert_equal [:rememberable, :database_authenticatable], Devise.mappings[:user].strategies\n    assert_equal [:database_authenticatable], Devise.mappings[:admin].strategies\n  end\n\n  test 'has no input strategies depending on the model declaration' do\n    assert_equal [:rememberable], Devise.mappings[:user].no_input_strategies\n    assert_equal [], Devise.mappings[:admin].no_input_strategies\n  end\n\n  test 'find scope for a given object' do\n    assert_equal :user, Devise::Mapping.find_scope!(User)\n    assert_equal :user, Devise::Mapping.find_scope!(:user)\n    assert_equal :user, Devise::Mapping.find_scope!(\"user\")\n    assert_equal :user, Devise::Mapping.find_scope!(User.new)\n  end\n\n  test 'find scope works with single table inheritance' do\n    assert_equal :user, Devise::Mapping.find_scope!(Class.new(User))\n    assert_equal :user, Devise::Mapping.find_scope!(Class.new(User).new)\n  end\n\n  test 'find scope uses devise_scope' do\n    user = User.new\n    def user.devise_scope; :special_scope; end\n    assert_equal :special_scope, Devise::Mapping.find_scope!(user)\n  end\n\n  test 'find scope raises an error if cannot be found' do\n    assert_raise RuntimeError do\n      Devise::Mapping.find_scope!(String)\n    end\n  end\n\n  test 'return default path names' do\n    mapping = Devise.mappings[:user]\n    assert_equal 'sign_in',      mapping.path_names[:sign_in]\n    assert_equal 'sign_out',     mapping.path_names[:sign_out]\n    assert_equal 'password',     mapping.path_names[:password]\n    assert_equal 'confirmation', mapping.path_names[:confirmation]\n    assert_equal 'sign_up',      mapping.path_names[:sign_up]\n    assert_equal 'unlock',       mapping.path_names[:unlock]\n  end\n\n  test 'allow custom path names to be given' do\n    mapping = Devise.mappings[:manager]\n    assert_equal 'login',        mapping.path_names[:sign_in]\n    assert_equal 'logout',       mapping.path_names[:sign_out]\n    assert_equal 'secret',       mapping.path_names[:password]\n    assert_equal 'verification', mapping.path_names[:confirmation]\n    assert_equal 'register',     mapping.path_names[:sign_up]\n    assert_equal 'unblock',      mapping.path_names[:unlock]\n  end\n\n  test 'magic predicates' do\n    mapping = Devise.mappings[:user]\n    assert mapping.authenticatable?\n    assert mapping.confirmable?\n    assert mapping.recoverable?\n    assert mapping.rememberable?\n    assert mapping.registerable?\n\n    mapping = Devise.mappings[:admin]\n    assert mapping.authenticatable?\n    assert mapping.recoverable?\n    assert mapping.lockable?\n    assert_not mapping.omniauthable?\n  end\n\n  test 'find mapping by path' do\n    assert_raise RuntimeError do\n      Devise::Mapping.find_by_path!('/accounts/facebook/callback')\n    end\n\n    assert_nothing_raised do\n      Devise::Mapping.find_by_path!('/:locale/accounts/login')\n    end\n\n    assert_nothing_raised do\n      Devise::Mapping.find_by_path!('/accounts/facebook/callback', :path)\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/authenticatable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass AuthenticatableTest < ActiveSupport::TestCase\n  test 'required_fields should be an empty array' do\n    assert_equal [], Devise::Models::Validatable.required_fields(User)\n  end\n\n  test 'find_first_by_auth_conditions allows custom filtering parameters' do\n    user = User.create!(email: \"example@example.com\", password: \"1234567\")\n    assert_equal user, User.find_first_by_auth_conditions({ email: \"example@example.com\" })\n    assert_nil User.find_first_by_auth_conditions({ email: \"example@example.com\" }, id: user.id.to_s.next)\n  end\n\n  # assumes default configuration of\n  # config.case_insensitive_keys = [:email]\n  # config.strip_whitespace_keys = [:email]\n  test 'find_or_initialize_with_errors uses parameter filter on find' do\n    user = User.create!(email: \"example@example.com\", password: \"1234567\")\n    assert_equal user, User.find_or_initialize_with_errors([:email], { email: \" EXAMPLE@example.com \" })\n  end\n\n  # assumes default configuration of\n  # config.case_insensitive_keys = [:email]\n  # config.strip_whitespace_keys = [:email]\n  test 'find_or_initialize_with_errors uses parameter filter on initialize' do\n    assert_equal \"example@example.com\", User.find_or_initialize_with_errors([:email], { email: \" EXAMPLE@example.com \" }).email\n  end\n\n  test 'find_or_initialize_with_errors adds blank error' do\n    user_with_error = User.find_or_initialize_with_errors([:email], { email: \"\" })\n    assert user_with_error.errors.added?(:email, :blank)\n  end\n\n  test 'find_or_initialize_with_errors adds invalid error' do\n    user_with_error = User.find_or_initialize_with_errors([:email], { email: \"example@example.com\" })\n    assert user_with_error.errors.added?(:email, :invalid)\n  end\n\n  if defined?(ActionController::Parameters)\n    test 'does not passes an ActionController::Parameters to find_first_by_auth_conditions through find_or_initialize_with_errors' do\n      user = create_user(email: 'example@example.com')\n      attributes = ActionController::Parameters.new(email: 'example@example.com')\n\n      User.expects(:find_first_by_auth_conditions).with({ 'email' => 'example@example.com' }).returns(user)\n      User.find_or_initialize_with_errors([:email], attributes)\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/confirmable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass ConfirmableTest < ActiveSupport::TestCase\n\n  def setup\n    setup_mailer\n  end\n\n  test 'should set callbacks to send the mail' do\n    if DEVISE_ORM == :active_record\n      defined_callbacks = User._commit_callbacks.map(&:filter)\n      assert_includes defined_callbacks, :send_on_create_confirmation_instructions\n      assert_includes defined_callbacks, :send_reconfirmation_instructions\n    elsif DEVISE_ORM == :mongoid\n      assert_includes User._create_callbacks.map(&:filter), :send_on_create_confirmation_instructions\n      assert_includes User._update_callbacks.map(&:filter), :send_reconfirmation_instructions\n    end\n  end\n\n  test 'should generate confirmation token after creating a record' do\n    assert_nil new_user.confirmation_token\n    assert_not_nil create_user.confirmation_token\n  end\n\n  test 'should never generate the same confirmation token for different users' do\n    confirmation_tokens = []\n    3.times do\n      token = create_user.confirmation_token\n      assert_not_includes confirmation_tokens, token\n      confirmation_tokens << token\n    end\n  end\n\n  test 'should confirm a user by updating confirmed at' do\n    user = create_user\n    assert_nil user.confirmed_at\n    assert user.confirm\n    assert_not_nil user.confirmed_at\n  end\n\n  test 'should verify whether a user is confirmed or not' do\n    assert_not new_user.confirmed?\n    user = create_user\n    assert_not user.confirmed?\n    user.confirm\n    assert user.confirmed?\n  end\n\n  test 'should not confirm a user already confirmed' do\n    user = create_user\n    assert user.confirm\n    assert_blank user.errors[:email]\n\n    assert_not user.confirm\n    assert_equal \"was already confirmed, please try signing in\", user.errors[:email].join\n  end\n\n  test 'should find and confirm a user automatically based on the raw token' do\n    user = create_user\n    raw  = user.raw_confirmation_token\n    confirmed_user = User.confirm_by_token(raw)\n    assert_equal user, confirmed_user\n    assert user.reload.confirmed?\n  end\n\n  test 'should return a new record with errors when a invalid token is given' do\n    confirmed_user = User.confirm_by_token('invalid_confirmation_token')\n    assert_not confirmed_user.persisted?\n    assert_equal \"is invalid\", confirmed_user.errors[:confirmation_token].join\n  end\n\n  test 'should return a new record with errors when a blank token is given' do\n    confirmed_user = User.confirm_by_token('')\n    assert_not confirmed_user.persisted?\n    assert confirmed_user.errors.added?(:confirmation_token, :blank)\n  end\n\n  test 'should return a new record with errors when a blank token is given and a record exists on the database' do\n    user = create_user(confirmation_token: '')\n\n    confirmed_user = User.confirm_by_token('')\n\n    assert_not user.reload.confirmed?\n    assert confirmed_user.errors.added?(:confirmation_token, :blank)\n  end\n\n  test 'should return a new record with errors when a nil token is given and a record exists on the database' do\n    user = create_user(confirmation_token: nil)\n\n    confirmed_user = User.confirm_by_token(nil)\n\n    assert_not user.reload.confirmed?\n    assert confirmed_user.errors.added?(:confirmation_token, :blank)\n  end\n\n  test 'should generate errors for a user email if user is already confirmed' do\n    user = create_user\n    user.confirmed_at = Time.now\n    user.save\n    confirmed_user = User.confirm_by_token(user.raw_confirmation_token)\n    assert confirmed_user.confirmed?\n    assert_equal \"was already confirmed, please try signing in\", confirmed_user.errors[:email].join\n  end\n\n  test 'should show error when a token has already been used' do\n    user = create_user\n    raw  = user.raw_confirmation_token\n    User.confirm_by_token(raw)\n    assert user.reload.confirmed?\n\n    confirmed_user = User.confirm_by_token(raw)\n    assert_equal \"was already confirmed, please try signing in\", confirmed_user.errors[:email].join\n  end\n\n  test 'should send confirmation instructions by email' do\n    assert_email_sent \"mynewuser@example.com\" do\n      create_user email: \"mynewuser@example.com\"\n    end\n  end\n\n  test 'should not send confirmation when trying to save an invalid user' do\n    assert_email_not_sent do\n      user = new_user\n      user.stubs(:valid?).returns(false)\n      user.save\n    end\n  end\n\n  test 'should not generate a new token neither send e-mail if skip_confirmation! is invoked' do\n    user = new_user\n    user.skip_confirmation!\n\n    assert_email_not_sent do\n      user.save!\n      assert_nil user.confirmation_token\n      assert_not_nil user.confirmed_at\n    end\n  end\n\n  test 'should skip confirmation e-mail without confirming if skip_confirmation_notification! is invoked' do\n    user = new_user\n    user.skip_confirmation_notification!\n\n    assert_email_not_sent do\n      user.save!\n      assert_not user.confirmed?\n    end\n  end\n\n  test 'should not send confirmation when no email is provided' do\n    assert_email_not_sent do\n      user = new_user\n      user.email = ''\n      user.save(validate: false)\n    end\n  end\n\n  test 'should find a user to send confirmation instructions' do\n    user = create_user\n    confirmation_user = User.send_confirmation_instructions(email: user.email)\n    assert_equal user, confirmation_user\n  end\n\n  test 'should return a new user if no email was found' do\n    confirmation_user = User.send_confirmation_instructions(email: \"invalid@example.com\")\n    assert_not confirmation_user.persisted?\n  end\n\n  test 'should add error to new user email if no email was found' do\n    confirmation_user = User.send_confirmation_instructions(email: \"invalid@example.com\")\n    assert confirmation_user.errors[:email]\n    assert_equal \"not found\", confirmation_user.errors[:email].join\n  end\n\n  test 'should send email instructions for the user confirm its email' do\n    user = create_user\n    assert_email_sent user.email do\n      User.send_confirmation_instructions(email: user.email)\n    end\n  end\n\n  test 'should always have confirmation token when email is sent' do\n    user = new_user\n    user.instance_eval { def confirmation_required?; false end }\n    user.save\n    user.send_confirmation_instructions\n    assert_not_nil user.reload.confirmation_token\n  end\n\n  test 'should not resend email instructions if the user change their email' do\n    user = create_user\n    user.email = 'new_test@example.com'\n    assert_email_not_sent do\n      user.save!\n    end\n  end\n\n  test 'should not reset confirmation status or token when updating email' do\n    user = create_user\n    original_token = user.confirmation_token\n    user.confirm\n    user.email = 'new_test@example.com'\n    user.save!\n\n    user.reload\n    assert user.confirmed?\n    assert_equal original_token, user.confirmation_token\n  end\n\n  test 'should not be able to send instructions if the user is already confirmed' do\n    user = create_user\n    user.confirm\n    assert_not user.resend_confirmation_instructions\n    assert user.confirmed?\n    assert_equal 'was already confirmed, please try signing in', user.errors[:email].join\n  end\n\n  test 'confirm time should fallback to devise confirm in default configuration' do\n    swap Devise, allow_unconfirmed_access_for: 1.day do\n      user = create_user\n      user.confirmation_sent_at = 2.days.ago\n      assert_not user.active_for_authentication?\n\n      Devise.allow_unconfirmed_access_for = 3.days\n      assert user.active_for_authentication?\n    end\n  end\n\n  test 'should be active when confirmation sent at is not overpast' do\n    swap Devise, allow_unconfirmed_access_for: 5.days do\n      Devise.allow_unconfirmed_access_for = 5.days\n      user = create_user\n\n      user.confirmation_sent_at = 4.days.ago\n      assert user.active_for_authentication?\n\n      user.confirmation_sent_at = 5.days.ago\n      assert_not user.active_for_authentication?\n    end\n  end\n\n  test 'should be active when already confirmed' do\n    user = create_user\n    assert_not user.confirmed?\n    assert_not user.active_for_authentication?\n\n    user.confirm\n    assert user.confirmed?\n    assert user.active_for_authentication?\n  end\n\n  test 'should not be active when confirm in is zero' do\n    Devise.allow_unconfirmed_access_for = 0.days\n    user = create_user\n    user.confirmation_sent_at = Time.zone.today\n    assert_not user.active_for_authentication?\n  end\n\n  test 'should not be active when confirm period is set to 0 days' do\n    Devise.allow_unconfirmed_access_for = 0.days\n    user = create_user\n\n    Timecop.freeze(Time.zone.today) do\n      user.confirmation_sent_at = Time.zone.today\n      assert_not user.active_for_authentication?\n    end\n  end\n\n  test 'should be active when we set allow_unconfirmed_access_for to nil' do\n    swap Devise, allow_unconfirmed_access_for: nil do\n      user = create_user\n      user.confirmation_sent_at = Time.zone.today\n      assert user.active_for_authentication?\n    end\n  end\n\n  test 'should not be active without confirmation' do\n    user = create_user\n    user.confirmation_sent_at = nil\n    user.save\n    assert_not user.reload.active_for_authentication?\n  end\n\n  test 'should be active without confirmation when confirmation is not required' do\n    user = create_user\n    user.instance_eval { def confirmation_required?; false end }\n    user.confirmation_sent_at = nil\n    user.save\n    assert user.reload.active_for_authentication?\n  end\n\n  test 'should not break when a user tries to reset their password in the case where confirmation is not required and confirm_within is set' do\n    swap Devise, confirm_within: 3.days do\n      user = create_user\n      user.instance_eval { def confirmation_required?; false end }\n      user.confirmation_sent_at = nil\n      user.save\n      assert user.reload.confirm\n    end\n  end\n\n  test 'should find a user to send email instructions for the user confirm its email by authentication_keys' do\n    swap Devise, authentication_keys: [:username, :email] do\n      user = create_user\n      confirm_user = User.send_confirmation_instructions(email: user.email, username: user.username)\n      assert_equal user, confirm_user\n    end\n  end\n\n  test 'should require all confirmation_keys' do\n    swap Devise, confirmation_keys: [:username, :email] do\n      user = create_user\n      confirm_user = User.send_confirmation_instructions(email: user.email)\n      assert_not confirm_user.persisted?\n      assert confirm_user.errors.added?(:username, :blank)\n    end\n  end\n\n  def confirm_user_by_token_with_confirmation_sent_at(confirmation_sent_at)\n    user = create_user\n    user.update_attribute(:confirmation_sent_at, confirmation_sent_at)\n    confirmed_user = User.confirm_by_token(user.raw_confirmation_token)\n    assert_equal user, confirmed_user\n    user.reload.confirmed?\n  end\n\n  test 'should accept confirmation email token even after 5 years when no expiration is set' do\n    assert confirm_user_by_token_with_confirmation_sent_at(5.years.ago)\n  end\n\n  test 'should accept confirmation email token after 2 days when expiration is set to 3 days' do\n    swap Devise, confirm_within: 3.days do\n      assert confirm_user_by_token_with_confirmation_sent_at(2.days.ago)\n    end\n  end\n\n  test 'should not accept confirmation email token after 4 days when expiration is set to 3 days' do\n    swap Devise, confirm_within: 3.days do\n      assert_not confirm_user_by_token_with_confirmation_sent_at(4.days.ago)\n    end\n  end\n\n  test 'do not generate a new token on resend' do\n    user = create_user\n    old  = user.confirmation_token\n    user = User.find(user.id)\n    user.resend_confirmation_instructions\n    assert_equal user.confirmation_token, old\n  end\n\n  test 'generate a new token after first has expired' do\n    swap Devise, confirm_within: 3.days do\n      user = create_user\n      old = user.confirmation_token\n      user.update_attribute(:confirmation_sent_at, 4.days.ago)\n      user = User.find(user.id)\n      user.resend_confirmation_instructions\n      assert_not_equal user.confirmation_token, old\n    end\n  end\n\n  test 'should call after_confirmation if confirmed' do\n    user = create_user\n    user.define_singleton_method :after_confirmation do\n      self.username = self.username.to_s + 'updated'\n    end\n    old = user.username\n    assert user.confirm\n    assert_not_equal user.username, old\n  end\n\n  test 'should not call after_confirmation if not confirmed' do\n    user = create_user\n    assert user.confirm\n    user.define_singleton_method :after_confirmation do\n      self.username = self.username.to_s + 'updated'\n    end\n    old = user.username\n    assert_not user.confirm\n    assert_equal user.username, old\n  end\n\n  test 'should always perform validations upon confirm when ensure valid true' do\n    admin = create_admin\n    admin.stubs(:valid?).returns(false)\n    assert_not admin.confirm(ensure_valid: true)\n  end\nend\n\nclass ReconfirmableTest < ActiveSupport::TestCase\n  test 'should not worry about validations on confirm even with reconfirmable' do\n    admin = create_admin\n    admin.reset_password_token = \"a\"\n    assert admin.confirm\n  end\n\n  test 'should generate confirmation token after changing email' do\n    admin = create_admin\n    assert admin.confirm\n    residual_token = admin.confirmation_token\n    assert admin.update(email: 'new_test@example.com')\n    assert_not_equal residual_token, admin.confirmation_token\n  end\n\n  test 'should not regenerate confirmation token or require reconfirmation if skipping reconfirmation after changing email' do\n    admin = create_admin\n    original_token = admin.confirmation_token\n    assert admin.confirm\n    admin.skip_reconfirmation!\n    assert admin.update(email: 'new_test@example.com')\n    assert admin.confirmed?\n    assert_not admin.pending_reconfirmation?\n    assert_equal original_token, admin.confirmation_token\n  end\n\n  test 'should skip sending reconfirmation email when email is changed and skip_confirmation_notification! is invoked' do\n    admin = create_admin\n    admin.skip_confirmation_notification!\n\n    assert_email_not_sent do\n      admin.update(email: 'new_test@example.com')\n    end\n  end\n\n  test 'should regenerate confirmation token after changing email' do\n    admin = create_admin\n    assert admin.confirm\n    assert admin.update(email: 'old_test@example.com')\n    token = admin.confirmation_token\n    assert admin.update(email: 'new_test@example.com')\n    assert_not_equal token, admin.confirmation_token\n  end\n\n  test 'should send confirmation instructions by email after changing email' do\n    admin = create_admin\n    assert admin.confirm\n    assert_email_sent \"new_test@example.com\" do\n      assert admin.update(email: 'new_test@example.com')\n    end\n    assert_match \"new_test@example.com\", ActionMailer::Base.deliveries.last.body.encoded\n  end\n\n  test 'should send confirmation instructions by email after changing email from nil' do\n    admin = create_admin(email: nil)\n    assert_email_sent \"new_test@example.com\" do\n      assert admin.update(email: 'new_test@example.com')\n    end\n    assert_match \"new_test@example.com\", ActionMailer::Base.deliveries.last.body.encoded\n  end\n\n  test 'should not send confirmation by email after changing password' do\n    admin = create_admin\n    assert admin.confirm\n    assert_email_not_sent do\n      assert admin.update(password: 'newpass', password_confirmation: 'newpass')\n    end\n  end\n\n  test 'should not send confirmation by email after changing to a blank email' do\n    admin = create_admin\n    assert admin.confirm\n    assert_email_not_sent do\n      admin.email = ''\n      admin.save(validate: false)\n    end\n  end\n\n  test 'should stay confirmed when email is changed' do\n    admin = create_admin\n    assert admin.confirm\n    assert admin.update(email: 'new_test@example.com')\n    assert admin.confirmed?\n  end\n\n  test 'should update email only when it is confirmed' do\n    admin = create_admin\n    assert admin.confirm\n    assert admin.update(email: 'new_test@example.com')\n    assert_not_equal 'new_test@example.com', admin.email\n    assert admin.confirm\n    assert_equal 'new_test@example.com', admin.email\n  end\n\n  test 'should not allow admin to get past confirmation email by resubmitting their new address' do\n    admin = create_admin\n    assert admin.confirm\n    assert admin.update(email: 'new_test@example.com')\n    assert_not_equal 'new_test@example.com', admin.email\n    assert admin.update(email: 'new_test@example.com')\n    assert_not_equal 'new_test@example.com', admin.email\n  end\n\n  test 'should find a admin by send confirmation instructions with unconfirmed_email' do\n    admin = create_admin\n    assert admin.confirm\n    assert admin.update(email: 'new_test@example.com')\n    confirmation_admin = Admin.send_confirmation_instructions(email: admin.unconfirmed_email)\n    assert_equal admin, confirmation_admin\n  end\n\n  test 'should return a new admin if no email or unconfirmed_email was found' do\n    confirmation_admin = Admin.send_confirmation_instructions(email: \"invalid@email.com\")\n    assert_not confirmation_admin.persisted?\n  end\n\n  test 'should add error to new admin email if no email or unconfirmed_email was found' do\n    confirmation_admin = Admin.send_confirmation_instructions(email: \"invalid@email.com\")\n    assert confirmation_admin.errors[:email]\n    assert_equal \"not found\", confirmation_admin.errors[:email].join\n  end\n\n  test 'should find admin with email in unconfirmed_emails' do\n    admin = create_admin\n    admin.unconfirmed_email = \"new_test@email.com\"\n    assert admin.save\n    admin = Admin.find_by_unconfirmed_email_with_errors(email: \"new_test@email.com\")\n    assert admin.persisted?\n  end\n\n  test 'required_fields should contain the fields that Devise uses' do\n    assert_equal [\n      :confirmation_token,\n      :confirmed_at,\n      :confirmation_sent_at\n    ], Devise::Models::Confirmable.required_fields(User)\n  end\n\n  test 'required_fields should also contain unconfirmable when reconfirmable_email is true' do\n    assert_equal [\n      :confirmation_token,\n      :confirmed_at,\n      :confirmation_sent_at,\n      :unconfirmed_email\n    ], Devise::Models::Confirmable.required_fields(Admin)\n  end\n\n  test 'should not require reconfirmation after creating a record' do\n    admin = create_admin\n    assert_not admin.pending_reconfirmation?\n  end\n\n  test 'should not require reconfirmation after creating a record with #save called in callback' do\n    class Admin::WithSaveInCallback < Admin\n      after_create :save\n    end\n\n    admin = Admin::WithSaveInCallback.create(valid_attributes.except(:username))\n    assert_not admin.pending_reconfirmation?\n  end\n\n  test 'should require reconfirmation after creating a record and updating the email' do\n    admin = create_admin\n    assert_not admin.instance_variable_get(:@bypass_confirmation_postpone)\n    admin.email = \"new_test@email.com\"\n    admin.save\n    assert admin.pending_reconfirmation?\n  end\n\n  test 'should notify previous email on email change when configured' do\n    swap Devise, send_email_changed_notification: true do\n      admin = create_admin\n      original_email = admin.email\n\n      assert_difference 'ActionMailer::Base.deliveries.size', 2 do\n        assert admin.update(email: 'new-email@example.com')\n      end\n      assert_equal original_email, ActionMailer::Base.deliveries[-2]['to'].to_s\n      assert_equal 'new-email@example.com', ActionMailer::Base.deliveries[-1]['to'].to_s\n\n      assert_email_not_sent do\n        assert admin.confirm\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/database_authenticatable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\nrequire 'test_models'\nrequire 'digest/sha1'\n\nclass DatabaseAuthenticatableTest < ActiveSupport::TestCase\n  def setup\n    setup_mailer\n  end\n\n  test 'should downcase case insensitive keys when saving' do\n    # case_insensitive_keys is set to :email by default.\n    email = 'Foo@Bar.com'\n    user = new_user(email: email)\n\n    assert_equal email, user.email\n    user.save!\n    assert_equal email.downcase, user.email\n  end\n\n  test 'should downcase case insensitive keys that refer to virtual attributes when saving' do\n    email        = 'Foo@Bar1.com'\n    confirmation = 'Foo@Bar1.com'\n    attributes   = valid_attributes(email: email, email_confirmation: confirmation)\n    user = UserWithVirtualAttributes.new(attributes)\n\n    assert_equal confirmation, user.email_confirmation\n    user.save!\n    assert_equal confirmation.downcase, user.email_confirmation\n  end\n\n  test 'should not mutate value assigned to case insensitive key' do\n    email          = 'Foo@Bar.com'\n    original_email = email.dup\n    user           = new_user(email: email)\n\n    user.save!\n    assert_equal original_email, email\n  end\n\n  test 'should remove whitespace from strip whitespace keys when saving' do\n    # strip_whitespace_keys is set to :email by default.\n    email = ' foo@bar.com '\n    user = new_user(email: email)\n\n    assert_equal email, user.email\n    user.save!\n    assert_equal email.strip, user.email\n  end\n\n  test 'should not mutate value assigned to string whitespace key' do\n    email          = ' foo@bar.com '\n    original_email = email.dup\n    user           = new_user(email: email)\n\n    user.save!\n    assert_equal original_email, email\n  end\n\n  test \"doesn't throw exception when globally configured strip_whitespace_keys are not present on a model\" do\n    swap Devise, strip_whitespace_keys: [:fake_key] do\n      assert_nothing_raised { create_user }\n    end\n  end\n\n  test \"doesn't throw exception when globally configured case_insensitive_keys are not present on a model\" do\n    swap Devise, case_insensitive_keys: [:fake_key] do\n      assert_nothing_raised { create_user }\n    end\n  end\n\n  test \"param filter should not convert booleans and integer to strings\" do\n    conditions = { \"login\" => \"foo@bar.com\", \"bool1\" => true, \"bool2\" => false, \"fixnum\" => 123, \"will_be_converted\" => (1..10) }\n    conditions = Devise::ParameterFilter.new([], []).filter(conditions)\n    assert_equal( { \"login\" => \"foo@bar.com\", \"bool1\" => \"true\", \"bool2\" => \"false\", \"fixnum\" => \"123\", \"will_be_converted\" => \"1..10\" }, conditions)\n  end\n\n  test 'param filter should filter case_insensitive_keys as insensitive' do\n    conditions = {'insensitive' => 'insensitive_VAL', 'sensitive' => 'sensitive_VAL'}\n    conditions = Devise::ParameterFilter.new(['insensitive'], []).filter(conditions)\n    assert_equal( {'insensitive' => 'insensitive_val', 'sensitive' => 'sensitive_VAL'}, conditions )\n  end\n\n  test 'param filter should filter strip_whitespace_keys stripping whitespaces' do\n    conditions = {'strip_whitespace' => ' strip_whitespace_val ', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}\n    conditions = Devise::ParameterFilter.new([], ['strip_whitespace']).filter(conditions)\n    assert_equal( {'strip_whitespace' => 'strip_whitespace_val', 'do_not_strip_whitespace' => ' do_not_strip_whitespace_val '}, conditions )\n  end\n\n  test 'param filter should not add keys to filtered hash' do\n    conditions = { 'present' => 'present_val' }\n    conditions.default = ''\n    conditions = Devise::ParameterFilter.new(['not_present'], []).filter(conditions)\n    assert_equal({ 'present' => 'present_val' }, conditions)\n  end\n\n  test 'should respond to password and password confirmation' do\n    user = new_user\n    assert_respond_to user, :password\n    assert_respond_to user, :password_confirmation\n  end\n\n  test 'should generate a hashed password while setting password' do\n    user = new_user\n    assert_present user.encrypted_password\n  end\n\n  test 'should support custom hashing methods' do\n    user = UserWithCustomHashing.new(password: '654321')\n    assert_equal '123456', user.encrypted_password\n  end\n\n  test 'allow authenticatable_salt to work even with nil hashed password' do\n    user = User.new\n    user.encrypted_password = nil\n    assert_nil user.authenticatable_salt\n  end\n\n  test 'should not generate a hashed password if password is blank' do\n    assert_blank new_user(password: nil).encrypted_password\n    assert_blank new_user(password: '').encrypted_password\n  end\n\n  test 'should hash password again if password has changed' do\n    user = create_user\n    encrypted_password = user.encrypted_password\n    user.password = user.password_confirmation = 'new_password'\n    user.save!\n    assert_not_equal encrypted_password, user.encrypted_password\n  end\n\n  test 'should test for a valid password' do\n    user = create_user\n    assert user.valid_password?('12345678')\n    assert_not user.valid_password?('654321')\n  end\n\n  test 'should not raise error with an empty password' do\n    user = create_user\n    user.encrypted_password = ''\n    assert_nothing_raised { user.valid_password?('12345678') }\n  end\n\n  test 'should be an invalid password if the user has an empty password' do\n    user = create_user\n    user.encrypted_password = ''\n    assert_not user.valid_password?('654321')\n  end\n\n  test 'should respond to current password' do\n    assert_respond_to new_user, :current_password\n  end\n\n  test 'should update password with valid current password' do\n    user = create_user\n    assert user.update_with_password(current_password: '12345678',\n      password: 'pass4321', password_confirmation: 'pass4321')\n    assert user.reload.valid_password?('pass4321')\n  end\n\n  test 'should add an error to current password when it is invalid' do\n    user = create_user\n    assert_not user.update_with_password(current_password: 'other',\n      password: 'pass4321', password_confirmation: 'pass4321')\n    assert user.reload.valid_password?('12345678')\n    assert_match \"is invalid\", user.errors[:current_password].join\n  end\n\n  test 'should add an error to current password when it is blank' do\n    user = create_user\n    assert_not user.update_with_password(password: 'pass4321',\n      password_confirmation: 'pass4321')\n    assert user.reload.valid_password?('12345678')\n    assert user.errors.added?(:current_password, :blank)\n  end\n\n  test 'should run validations even when current password is invalid or blank' do\n    user = UserWithValidation.create!(valid_attributes)\n    user.save\n    assert user.persisted?\n    assert_not user.update_with_password(username: \"\")\n    assert_match \"usertest\", user.reload.username\n    assert user.errors.added?(:username, :blank)\n  end\n\n  test 'should ignore password and its confirmation if they are blank' do\n    user = create_user\n    assert user.update_with_password(current_password: '12345678', email: \"new@example.com\")\n    assert_equal \"new@example.com\", user.email\n  end\n\n  test 'should not update password with invalid confirmation' do\n    user = create_user\n    assert_not user.update_with_password(current_password: '12345678',\n      password: 'pass4321', password_confirmation: 'other')\n    assert user.reload.valid_password?('12345678')\n  end\n\n  test 'should clean up password fields on failure' do\n    user = create_user\n    assert_not user.update_with_password(current_password: '12345678',\n      password: 'pass4321', password_confirmation: 'other')\n    assert user.password.blank?\n    assert user.password_confirmation.blank?\n  end\n\n  test 'should update the user without password' do\n    user = create_user\n    user.update_without_password(email: 'new@example.com')\n    assert_equal 'new@example.com', user.email\n  end\n\n  test 'should not update password without password' do\n    user = create_user\n    user.update_without_password(password: 'pass4321', password_confirmation: 'pass4321')\n    assert_not user.reload.valid_password?('pass4321')\n    assert user.valid_password?('12345678')\n  end\n\n  test 'should destroy user if current password is valid' do\n    user = create_user\n    assert user.destroy_with_password('12345678')\n    assert_not user.persisted?\n  end\n\n  test 'should not destroy user with invalid password' do\n    user = create_user\n    assert_not user.destroy_with_password('other')\n    assert user.persisted?\n    assert_match \"is invalid\", user.errors[:current_password].join\n  end\n\n  test 'should not destroy user with blank password' do\n    user = create_user\n    assert_not user.destroy_with_password(nil)\n    assert user.persisted?\n    assert user.errors.added?(:current_password, :blank)\n  end\n\n  test 'should not email on password change' do\n    user = create_user\n    assert_email_not_sent do\n      assert user.update(password: 'newpass', password_confirmation: 'newpass')\n    end\n  end\n\n  test 'should notify previous email on email change when configured' do\n    swap Devise, send_email_changed_notification: true do\n      user = create_user\n      original_email = user.email\n      assert_email_sent original_email do\n        assert user.update(email: 'new-email@example.com')\n      end\n      assert_match original_email, ActionMailer::Base.deliveries.last.body.encoded\n    end\n  end\n\n  test 'should notify email on password change when configured' do\n    swap Devise, send_password_change_notification: true do\n      user = create_user\n      assert_email_sent user.email do\n        assert user.update(password: 'newpass', password_confirmation: 'newpass')\n      end\n      assert_match user.email, ActionMailer::Base.deliveries.last.body.encoded\n    end\n  end\n\n  test 'should not notify email on password change even when configured if skip_password_change_notification! is invoked' do\n    swap Devise, send_password_change_notification: true do\n      user = create_user\n      user.skip_password_change_notification!\n      assert_email_not_sent do\n        assert user.update(password: 'newpass', password_confirmation: 'newpass')\n      end\n    end\n  end\n\n  test 'should not notify email on email change even when configured if skip_email_changed_notification! is invoked' do\n    swap Devise, send_email_changed_notification: true do\n      user = create_user\n      user.skip_email_changed_notification!\n      assert_email_not_sent do\n        assert user.update(email: 'new-email@example.com')\n      end\n    end\n  end\n\n  test 'downcase_keys with validation' do\n    User.create(email: \"HEllO@example.com\", password: \"123456\")\n    user = User.create(email: \"HEllO@example.com\", password: \"123456\")\n    assert_not user.valid?\n  end\n\n  test 'required_fields should be encryptable_password and the email field by default' do\n    assert_equal [\n      :encrypted_password,\n      :email\n    ], Devise::Models::DatabaseAuthenticatable.required_fields(User)\n  end\n\n  test 'required_fields should be encryptable_password and the login when the login is on authentication_keys' do\n    swap Devise, authentication_keys: [:login] do\n      assert_equal [\n        :encrypted_password,\n        :login\n      ], Devise::Models::DatabaseAuthenticatable.required_fields(User)\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/lockable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass LockableTest < ActiveSupport::TestCase\n  def setup\n    setup_mailer\n  end\n\n  test \"should respect maximum attempts configuration\" do\n    user = create_user\n    user.confirm\n    swap Devise, maximum_attempts: 2 do\n      2.times { user.valid_for_authentication?{ false } }\n      assert user.reload.access_locked?\n    end\n  end\n\n  test \"should increment failed_attempts on successful validation if the user is already locked\" do\n    user = create_user\n    user.confirm\n\n    swap Devise, maximum_attempts: 2 do\n      2.times { user.valid_for_authentication?{ false } }\n      assert user.reload.access_locked?\n    end\n\n    user.valid_for_authentication?{ true }\n    assert_equal 3, user.reload.failed_attempts\n  end\n\n  test \"should not touch failed_attempts if lock_strategy is none\" do\n    user = create_user\n    user.confirm\n    swap Devise, lock_strategy: :none, maximum_attempts: 2 do\n      3.times { user.valid_for_authentication?{ false } }\n      assert_not user.access_locked?\n      assert_equal 0, user.failed_attempts\n    end\n  end\n\n  test \"should read failed_attempts from database when incrementing\" do\n    user = create_user\n    initial_failed_attempts = user.failed_attempts\n    same_user = User.find(user.id)\n\n    user.increment_failed_attempts\n    same_user.increment_failed_attempts\n\n    assert_equal initial_failed_attempts + 2, user.reload.failed_attempts\n  end\n\n  test \"reset_failed_attempts! updates the failed attempts counter back to 0\" do\n    user = create_user(failed_attempts: 3)\n    assert_equal 3, user.failed_attempts\n\n    user.reset_failed_attempts!\n    assert_equal 0, user.failed_attempts\n\n    user.reset_failed_attempts!\n    assert_equal 0, user.failed_attempts\n  end\n\n  test \"reset_failed_attempts! does not run model validations\" do\n    user = create_user(failed_attempts: 1)\n    user.expects(:after_validation_callback).never\n\n    assert user.reset_failed_attempts!\n    assert_equal 0, user.failed_attempts\n  end\n\n  test \"reset_failed_attempts! does not try to reset if not using failed attempts strategy\" do\n    admin = create_admin\n\n    assert_not_respond_to admin, :failed_attempts\n    assert_not admin.reset_failed_attempts!\n  end\n\n  test 'should be valid for authentication with a unlocked user' do\n    user = create_user\n    user.lock_access!\n    user.unlock_access!\n    assert user.valid_for_authentication?{ true }\n  end\n\n  test \"should verify whether a user is locked or not\" do\n    user = create_user\n    assert_not user.access_locked?\n    user.lock_access!\n    assert user.access_locked?\n  end\n\n  test \"active_for_authentication? should be the opposite of locked?\" do\n    user = create_user\n    user.confirm\n    assert user.active_for_authentication?\n    user.lock_access!\n    assert_not user.active_for_authentication?\n  end\n\n  test \"should unlock a user by cleaning locked_at, failed_attempts and unlock_token\" do\n    user = create_user\n    user.lock_access!\n    assert_not_nil user.reload.locked_at\n    assert_not_nil user.reload.unlock_token\n\n    user.unlock_access!\n    assert_nil user.reload.locked_at\n    assert_nil user.reload.unlock_token\n    assert_equal 0, user.reload.failed_attempts\n  end\n\n  test \"new user should not be locked and should have zero failed_attempts\" do\n    assert_not new_user.access_locked?\n    assert_equal 0, create_user.failed_attempts\n  end\n\n  test \"should unlock user after unlock_in period\" do\n    swap Devise, unlock_in: 3.hours do\n      user = new_user\n      user.locked_at = 2.hours.ago\n      assert user.access_locked?\n\n      Devise.unlock_in = 1.hour\n      assert_not user.access_locked?\n    end\n  end\n\n  test \"should not unlock in 'unlock_in' if :time unlock strategy is not set\" do\n    swap Devise, unlock_strategy: :email do\n      user = new_user\n      user.locked_at = 2.hours.ago\n      assert user.access_locked?\n    end\n  end\n\n  test \"should set unlock_token when locking\" do\n    user = create_user\n    assert_nil user.unlock_token\n    user.lock_access!\n    assert_not_nil user.unlock_token\n  end\n\n  test \"should never generate the same unlock token for different users\" do\n    unlock_tokens = []\n    3.times do\n      user = create_user\n      user.lock_access!\n      token = user.unlock_token\n      assert_not_includes unlock_tokens, token\n      unlock_tokens << token\n    end\n  end\n\n  test \"should not generate unlock_token when :email is not an unlock strategy\" do\n    swap Devise, unlock_strategy: :time do\n      user = create_user\n      user.lock_access!\n      assert_nil user.unlock_token\n    end\n  end\n\n  test \"should send email with unlock instructions when :email is an unlock strategy\" do\n    swap Devise, unlock_strategy: :email do\n      user = create_user\n      assert_email_sent do\n        user.lock_access!\n      end\n    end\n  end\n\n  test \"doesn't send email when you pass option send_instructions to false\" do\n    swap Devise, unlock_strategy: :email do\n      user = create_user\n      assert_email_not_sent do\n        user.lock_access! send_instructions: false\n      end\n    end\n  end\n\n  test \"sends email when you pass options other than send_instructions\" do\n    swap Devise, unlock_strategy: :email do\n      user = create_user\n      assert_email_sent do\n        user.lock_access! foo: :bar, bar: :foo\n      end\n    end\n  end\n\n  test \"should not send email with unlock instructions when :email is not an unlock strategy\" do\n    swap Devise, unlock_strategy: :time do\n      user = create_user\n      assert_email_not_sent do\n        user.lock_access!\n      end\n    end\n  end\n\n  test 'should find and unlock a user automatically based on raw token' do\n    user = create_user\n    raw  = user.send_unlock_instructions\n    locked_user = User.unlock_access_by_token(raw)\n    assert_equal user, locked_user\n    assert_not user.reload.access_locked?\n  end\n\n  test 'should return a new record with errors when a invalid token is given' do\n    locked_user = User.unlock_access_by_token('invalid_token')\n    assert_not locked_user.persisted?\n    assert_equal \"is invalid\", locked_user.errors[:unlock_token].join\n  end\n\n  test 'should return a new record with errors when a blank token is given' do\n    locked_user = User.unlock_access_by_token('')\n    assert_not locked_user.persisted?\n    assert locked_user.errors.added?(:unlock_token, :blank)\n  end\n\n  test 'should find a user to send unlock instructions' do\n    user = create_user\n    user.lock_access!\n    unlock_user = User.send_unlock_instructions(email: user.email)\n    assert_equal user, unlock_user\n  end\n\n  test 'should return a new user if no email was found' do\n    unlock_user = User.send_unlock_instructions(email: \"invalid@example.com\")\n    assert_not unlock_user.persisted?\n  end\n\n  test 'should add error to new user email if no email was found' do\n    unlock_user = User.send_unlock_instructions(email: \"invalid@example.com\")\n    assert_equal 'not found', unlock_user.errors[:email].join\n  end\n\n  test 'should find a user to send unlock instructions by authentication_keys' do\n    swap Devise, authentication_keys: [:username, :email] do\n      user = create_user\n      unlock_user = User.send_unlock_instructions(email: user.email, username: user.username)\n      assert_equal user, unlock_user\n    end\n  end\n\n  test 'should require all unlock_keys' do\n    swap Devise, unlock_keys: [:username, :email] do\n      user = create_user\n      unlock_user = User.send_unlock_instructions(email: user.email)\n      assert_not unlock_user.persisted?\n      assert unlock_user.errors.added?(:username, :blank)\n    end\n  end\n\n  test 'should not be able to send instructions if the user is not locked' do\n    user = create_user\n    assert_not user.resend_unlock_instructions\n    assert_not user.access_locked?\n    assert_equal 'was not locked', user.errors[:email].join\n  end\n\n  test 'should not be able to send instructions if the user if not locked and have username as unlock key' do\n    swap Devise, unlock_keys: [:username] do\n      user = create_user\n      assert_not user.resend_unlock_instructions\n      assert_not user.access_locked?\n      assert_equal 'was not locked', user.errors[:username].join\n    end\n  end\n\n  test 'should unlock account if lock has expired and increase attempts on failure' do\n    swap Devise, unlock_in: 1.minute do\n      user = create_user\n      user.confirm\n\n      user.failed_attempts = 2\n      user.locked_at = 2.minutes.ago\n\n      user.valid_for_authentication? { false }\n      assert_equal 1, user.failed_attempts\n    end\n  end\n\n  test 'should unlock account if lock has expired on success' do\n    swap Devise, unlock_in: 1.minute do\n      user = create_user\n      user.confirm\n\n      user.failed_attempts = 2\n      user.locked_at = 2.minutes.ago\n\n      user.valid_for_authentication? { true }\n      assert_equal 0, user.failed_attempts\n      assert_nil user.locked_at\n    end\n  end\n\n  test 'required_fields should contain the all the fields when all the strategies are enabled' do\n    swap Devise, unlock_strategy: :both do\n      swap Devise, lock_strategy: :failed_attempts do\n        assert_equal [\n          :failed_attempts,\n          :locked_at,\n          :unlock_token\n        ], Devise::Models::Lockable.required_fields(User)\n      end\n    end\n  end\n\n  test 'required_fields should contain only failed_attempts and locked_at when the strategies are time and failed_attempts are enabled' do\n    swap Devise, unlock_strategy: :time do\n      swap Devise, lock_strategy: :failed_attempts do\n        assert_equal [\n          :failed_attempts,\n          :locked_at\n        ], Devise::Models::Lockable.required_fields(User)\n      end\n    end\n  end\n\n  test 'required_fields should contain only failed_attempts and unlock_token when the strategies are token and failed_attempts are enabled' do\n    swap Devise, unlock_strategy: :email do\n      swap Devise, lock_strategy: :failed_attempts do\n        assert_equal [\n          :failed_attempts,\n          :unlock_token\n        ], Devise::Models::Lockable.required_fields(User)\n      end\n    end\n  end\n\n  test 'should not return a locked unauthenticated message if in paranoid mode' do\n    swap Devise, paranoid: :true do\n      user = create_user\n      user.failed_attempts = Devise.maximum_attempts + 1\n      user.lock_access!\n\n      assert_equal :invalid, user.unauthenticated_message\n    end\n  end\n\n  test 'should return last attempt message if user made next-to-last attempt of password entering' do\n    swap Devise, last_attempt_warning: true, lock_strategy: :failed_attempts do\n      user = create_user\n      user.failed_attempts = Devise.maximum_attempts - 2\n      assert_equal :invalid, user.unauthenticated_message\n\n      user.failed_attempts = Devise.maximum_attempts - 1\n      assert_equal :last_attempt, user.unauthenticated_message\n\n      user.failed_attempts = Devise.maximum_attempts\n      assert_equal :locked, user.unauthenticated_message\n    end\n  end\n\n  test 'should not return last attempt message if last_attempt_warning is disabled' do\n    swap Devise, last_attempt_warning: false, lock_strategy: :failed_attempts do\n      user = create_user\n      user.failed_attempts = Devise.maximum_attempts - 1\n      assert_equal :invalid, user.unauthenticated_message\n    end\n  end\n\n  test 'should return locked message if user was programatically locked' do\n    user = create_user\n    user.lock_access!\n    assert_equal :locked, user.unauthenticated_message\n  end\n\n  test 'unlock_strategy_enabled? should return true for both, email, and time strategies if :both is used' do\n    swap Devise, unlock_strategy: :both do\n      user = create_user\n      assert_equal true, user.unlock_strategy_enabled?(:both)\n      assert_equal true, user.unlock_strategy_enabled?(:time)\n      assert_equal true, user.unlock_strategy_enabled?(:email)\n      assert_equal false, user.unlock_strategy_enabled?(:none)\n      assert_equal false, user.unlock_strategy_enabled?(:an_undefined_strategy)\n    end\n  end\n\n  test 'unlock_strategy_enabled? should return true only for the configured strategy' do\n    swap Devise, unlock_strategy: :email do\n      user = create_user\n      assert_equal false, user.unlock_strategy_enabled?(:both)\n      assert_equal false, user.unlock_strategy_enabled?(:time)\n      assert_equal true, user.unlock_strategy_enabled?(:email)\n      assert_equal false, user.unlock_strategy_enabled?(:none)\n      assert_equal false, user.unlock_strategy_enabled?(:an_undefined_strategy)\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/omniauthable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass OmniauthableTest < ActiveSupport::TestCase\n  test 'required_fields should contain the fields that Devise uses' do\n    assert_equal [], Devise::Models::Omniauthable.required_fields(User)\n  end\nend\n"
  },
  {
    "path": "test/models/recoverable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass RecoverableTest < ActiveSupport::TestCase\n\n  def setup\n    setup_mailer\n  end\n\n  test 'should not generate reset password token after creating a record' do\n    assert_nil new_user.reset_password_token\n  end\n\n  test 'should never generate the same reset password token for different users' do\n    reset_password_tokens = []\n    3.times do\n      user = create_user\n      user.send_reset_password_instructions\n      token = user.reset_password_token\n      assert_not_includes reset_password_tokens, token\n      reset_password_tokens << token\n    end\n  end\n\n  test 'should reset password and password confirmation from params' do\n    user = create_user\n    user.reset_password('123456789', '987654321')\n    assert_equal '123456789', user.password\n    assert_equal '987654321', user.password_confirmation\n  end\n\n  test 'should reset password and save the record' do\n    assert create_user.reset_password('123456789', '123456789')\n  end\n\n  test 'should clear reset password token while resetting the password' do\n    user = create_user\n    assert_nil user.reset_password_token\n\n    user.send_reset_password_instructions\n    assert_present user.reset_password_token\n    assert user.reset_password('123456789', '123456789')\n    assert_nil user.reset_password_token\n  end\n\n  test 'should not clear reset password token for new user' do\n    user = new_user\n    assert_nil user.reset_password_token\n\n    user.send_reset_password_instructions\n    assert_present user.reset_password_token\n\n    user.save\n    assert_present user.reset_password_token\n  end\n\n  test 'should clear reset password token if changing password' do\n    user = create_user\n    assert_nil user.reset_password_token\n\n    user.send_reset_password_instructions\n    assert_present user.reset_password_token\n    user.password = \"123456678\"\n    user.password_confirmation = \"123456678\"\n    user.save!\n    assert_nil user.reset_password_token\n  end\n\n  test 'should clear reset password token if changing email' do\n    user = create_user\n    assert_nil user.reset_password_token\n\n    user.send_reset_password_instructions\n    assert_present user.reset_password_token\n    user.email = \"another@example.com\"\n    user.save!\n    assert_nil user.reset_password_token\n  end\n\n  test 'should clear reset password successfully even if there is no email' do\n    user = create_user_without_email\n    assert_nil user.reset_password_token\n\n    user.send_reset_password_instructions\n    assert_present user.reset_password_token\n    user.password = \"123456678\"\n    user.password_confirmation = \"123456678\"\n    user.save!\n    assert_nil user.reset_password_token\n  end\n\n  test 'should not clear reset password token if record is invalid' do\n    user = create_user\n    user.send_reset_password_instructions\n    assert_present user.reset_password_token\n    assert_not user.reset_password('123456789', '987654321')\n    assert_present user.reset_password_token\n  end\n\n  test 'should not reset password with invalid data' do\n    user = create_user\n    user.stubs(:valid?).returns(false)\n    assert_not user.reset_password('123456789', '987654321')\n  end\n\n  test 'should reset reset password token and send instructions by email' do\n    user = create_user\n    assert_email_sent do\n      token = user.reset_password_token\n      user.send_reset_password_instructions\n      assert_not_equal token, user.reset_password_token\n    end\n  end\n\n  test 'should find a user to send instructions by email' do\n    user = create_user\n    reset_password_user = User.send_reset_password_instructions(email: user.email)\n    assert_equal user, reset_password_user\n  end\n\n  test 'should return a new record with errors if user was not found by e-mail' do\n    reset_password_user = User.send_reset_password_instructions(email: \"invalid@example.com\")\n    assert_not reset_password_user.persisted?\n    assert_equal \"not found\", reset_password_user.errors[:email].join\n  end\n\n  test 'should find a user to send instructions by authentication_keys' do\n    swap Devise, authentication_keys: [:username, :email] do\n      user = create_user\n      reset_password_user = User.send_reset_password_instructions(email: user.email, username: user.username)\n      assert_equal user, reset_password_user\n    end\n  end\n\n  test 'should require all reset_password_keys' do\n    swap Devise, reset_password_keys: [:username, :email] do\n      user = create_user\n      reset_password_user = User.send_reset_password_instructions(email: user.email)\n      assert_not reset_password_user.persisted?\n      assert reset_password_user.errors.added?(:username, :blank)\n    end\n  end\n\n  test 'should reset reset_password_token before send the reset instructions email' do\n    user = create_user\n    token = user.reset_password_token\n    User.send_reset_password_instructions(email: user.email)\n    assert_not_equal token, user.reload.reset_password_token\n  end\n\n  test 'should send email instructions to the user reset their password' do\n    user = create_user\n    assert_email_sent do\n      User.send_reset_password_instructions(email: user.email)\n    end\n  end\n\n  test 'should find a user to reset their password based on the raw token' do\n    user = create_user\n    raw  = user.send_reset_password_instructions\n\n    reset_password_user = User.reset_password_by_token(reset_password_token: raw)\n    assert_equal user, reset_password_user\n  end\n\n  test 'should return a new record with errors if no reset_password_token is found' do\n    reset_password_user = User.reset_password_by_token(reset_password_token: 'invalid_token')\n    assert_not reset_password_user.persisted?\n    assert_equal \"is invalid\", reset_password_user.errors[:reset_password_token].join\n  end\n\n  test 'should return a new record with errors if reset_password_token is blank' do\n    reset_password_user = User.reset_password_by_token(reset_password_token: '')\n    assert_not reset_password_user.persisted?\n    assert reset_password_user.errors.added?(:reset_password_token, :blank)\n  end\n\n  test 'should return a new record with errors if password is blank' do\n    user = create_user\n    raw  = user.send_reset_password_instructions\n\n    reset_password_user = User.reset_password_by_token(reset_password_token: raw, password: '')\n    assert_not reset_password_user.errors.empty?\n    assert reset_password_user.errors.added?(:password, :blank)\n    assert_equal raw, reset_password_user.reset_password_token\n  end\n\n  test 'should return a new record with errors if password is not provided' do\n    user = create_user\n    raw  = user.send_reset_password_instructions\n\n    reset_password_user = User.reset_password_by_token(reset_password_token: raw)\n    assert_not reset_password_user.errors.empty?\n    assert reset_password_user.errors.added?(:password, :blank)\n    assert_equal raw, reset_password_user.reset_password_token\n  end\n\n  test 'should reset successfully user password given the new password and confirmation' do\n    user = create_user\n    old_password = user.password\n    raw  = user.send_reset_password_instructions\n\n    reset_password_user = User.reset_password_by_token(\n      reset_password_token: raw,\n      password: 'new_password',\n      password_confirmation: 'new_password'\n    )\n    assert_nil reset_password_user.reset_password_token\n\n    user.reload\n    assert_not user.valid_password?(old_password)\n    assert user.valid_password?('new_password')\n    assert_nil user.reset_password_token\n  end\n\n  test 'should not reset password after reset_password_within time' do\n    swap Devise, reset_password_within: 1.hour do\n      user = create_user\n      raw  = user.send_reset_password_instructions\n\n      old_password = user.password\n      user.reset_password_sent_at = 2.days.ago\n      user.save!\n\n      reset_password_user = User.reset_password_by_token(\n        reset_password_token: raw,\n        password: 'new_password',\n        password_confirmation: 'new_password'\n      )\n      user.reload\n\n      assert user.valid_password?(old_password)\n      assert_not user.valid_password?('new_password')\n      assert_equal \"has expired, please request a new one\", reset_password_user.errors[:reset_password_token].join\n    end\n  end\n\n  test 'required_fields should contain the fields that Devise uses' do\n    assert_equal [\n      :reset_password_sent_at,\n      :reset_password_token\n    ], Devise::Models::Recoverable.required_fields(User)\n  end\n\n  test 'should return a user based on the raw token' do\n    user = create_user\n    raw  = user.send_reset_password_instructions\n\n    assert_equal user, User.with_reset_password_token(raw)\n  end\n\n  test 'should return the same reset password token as generated' do\n    user = create_user\n    raw  = user.send_reset_password_instructions\n    assert_equal user.reset_password_token, Devise.token_generator.digest(self.class, :reset_password_token, raw)\n  end\n\n  test 'should return nil if a user based on the raw token is not found' do\n    assert_nil User.with_reset_password_token('random-token')\n  end\n\nend\n"
  },
  {
    "path": "test/models/registerable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass RegisterableTest < ActiveSupport::TestCase\n  test 'required_fields should contain the fields that Devise uses' do\n    assert_equal [], Devise::Models::Registerable.required_fields(User)\n  end\nend\n"
  },
  {
    "path": "test/models/rememberable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass RememberableTest < ActiveSupport::TestCase\n  def resource_class\n    User\n  end\n\n  def create_resource\n    create_user\n  end\n\n  test 'remember_me should not generate a new token if using salt' do\n    user = create_user\n    user.expects(:valid?).never\n    user.remember_me!\n    assert user.remember_created_at\n  end\n\n  test 'remember_me should not generate a new token if valid token exists' do\n    user = create_user\n    user.singleton_class.send(:attr_accessor, :remember_token)\n    User.to_adapter.expects(:find_first).returns(nil)\n\n    user.remember_me!\n    existing_token = user.remember_token\n\n    user.remember_me!\n    assert_equal existing_token, user.remember_token\n  end\n\n  test 'forget_me should not clear remember token if using salt' do\n    user = create_user\n    user.remember_me!\n    user.expects(:valid?).never\n    user.forget_me!\n  end\n\n  test 'can generate remember token' do\n    user = create_user\n    user.singleton_class.send(:attr_accessor, :remember_token)\n    User.to_adapter.expects(:find_first).returns(nil)\n    user.remember_me!\n    assert user.remember_token\n  end\n\n  test 'serialize into cookie' do\n    user = create_user\n    user.remember_me!\n    id, token, date = User.serialize_into_cookie(user)\n    assert_equal id, user.to_key\n    assert_equal token, user.authenticatable_salt\n    assert date.is_a?(String)\n  end\n\n  test 'serialize from cookie' do\n    user = create_user\n    user.remember_me!\n    assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc)\n  end\n\n  test 'serialize from cookie should accept a String with the datetime seconds and microseconds' do\n    user = create_user\n    user.remember_me!\n    assert_equal user, User.serialize_from_cookie(user.to_key, user.authenticatable_salt, Time.now.utc.to_f.to_json)\n  end\n\n  test 'serialize from cookie should return nil with invalid datetime' do\n    user = create_user\n    user.remember_me!\n    assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, \"2013\")\n  end\n\n  test 'serialize from cookie should return nil if no resource is found' do\n    assert_nil resource_class.serialize_from_cookie([0], \"123\", Time.now.utc)\n  end\n\n  test 'serialize from cookie should return nil if no timestamp' do\n    user = create_user\n    user.remember_me!\n    assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt)\n  end\n\n  test 'serialize from cookie should return nil if timestamp is earlier than token creation' do\n    user = create_user\n    user.remember_me!\n    assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 1.day.ago)\n  end\n\n  test 'serialize from cookie should return nil if timestamp is older than remember_for' do\n    user = create_user\n    user.remember_created_at = 1.month.ago\n    user.remember_me!\n    assert_nil User.serialize_from_cookie(user.to_key, user.authenticatable_salt, 3.weeks.ago)\n  end\n\n  test 'serialize from cookie me return nil if is a valid resource with invalid token' do\n    user = create_user\n    user.remember_me!\n    assert_nil User.serialize_from_cookie(user.to_key, \"123\", Time.now.utc)\n  end\n\n  test 'raises a RuntimeError if the user does not implements a rememberable value' do\n    user = User.new\n    assert_raise(RuntimeError) { user.rememberable_value }\n\n    user_with_remember_token = User.new\n    def user_with_remember_token.remember_token; '123-token'; end\n    assert_equal '123-token', user_with_remember_token.rememberable_value\n\n    user_with_salt = User.new\n    def user_with_salt.authenticatable_salt; '123-salt'; end\n    assert_equal '123-salt', user_with_salt.rememberable_value\n  end\n\n  test 'raises a RuntimeError if authenticatable_salt is nil or empty' do\n    user = User.new\n    def user.authenticatable_salt; nil; end\n    assert_raise RuntimeError do\n      user.rememberable_value\n    end\n\n    user = User.new\n    def user.authenticatable_salt; \"\"; end\n    assert_raise RuntimeError do\n      user.rememberable_value\n    end\n  end\n\n  test 'should respond to remember_me attribute' do\n    assert_respond_to resource_class.new, :remember_me\n    assert_respond_to resource_class.new, :remember_me=\n  end\n\n  test 'forget_me should clear remember_created_at if expire_all_remember_me_on_sign_out is true' do\n    swap Devise, expire_all_remember_me_on_sign_out: true do\n      resource = create_resource\n      resource.remember_me!\n      assert_not_nil resource.remember_created_at\n\n      resource.forget_me!\n      assert_nil resource.remember_created_at\n    end\n  end\n\n  test 'forget_me should not clear remember_created_at if expire_all_remember_me_on_sign_out is false' do\n    swap Devise, expire_all_remember_me_on_sign_out: false do\n      resource = create_resource\n      resource.remember_me!\n\n      assert_not_nil resource.remember_created_at\n\n      resource.forget_me!\n      assert_not_nil resource.remember_created_at\n    end\n  end\n\n  test 'forget_me should not try to update resource if it has been destroyed' do\n    resource = create_resource\n    resource.expects(:remember_created_at).never\n    resource.expects(:save).never\n\n    resource.destroy\n    resource.forget_me!\n  end\n\n  test 'remember expires at uses remember for configuration' do\n    swap Devise, remember_for: 3.days do\n      resource = create_resource\n      resource.remember_me!\n      assert_equal 3.days.from_now.to_date, resource.remember_expires_at.to_date\n\n      Devise.remember_for = 5.days\n      assert_equal 5.days.from_now.to_date, resource.remember_expires_at.to_date\n    end\n  end\n\n  test 'should have the required_fields array' do\n    assert_equal [\n      :remember_created_at\n    ], Devise::Models::Rememberable.required_fields(User)\n  end\nend\n"
  },
  {
    "path": "test/models/serializable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass SerializableTest < ActiveSupport::TestCase\n  setup do\n    @user = create_user\n  end\n\n  test 'should not include unsafe keys on JSON' do\n    keys = from_json().keys.select{ |key| !key.include?(\"id\") }\n    assert_equal %w(created_at email facebook_token updated_at username), keys.sort\n  end\n\n  test 'should not include unsafe keys on JSON even if a new except is provided' do\n    assert_no_key \"email\", from_json(except: :email)\n    assert_no_key \"confirmation_token\", from_json(except: :email)\n  end\n\n  test 'should include unsafe keys on JSON if a force_except is provided' do\n    assert_no_key \"email\", from_json(force_except: :email)\n    assert_key \"confirmation_token\", from_json(force_except: :email)\n  end\n\n  test 'should not include unsafe keys in inspect' do\n    assert_match(/email/, @user.inspect)\n    assert_no_match(/confirmation_token/, @user.inspect)\n  end\n\n  test 'should accept frozen options' do\n    assert_key \"username\", @user.as_json({ only: :username, except: [:email].freeze }.freeze)[\"user\"]\n  end\n\n  def assert_key(key, subject)\n    assert subject.key?(key), \"Expected #{subject.inspect} to have key #{key.inspect}\"\n  end\n\n  def assert_no_key(key, subject)\n    assert_not subject.key?(key), \"Expected #{subject.inspect} to not have key #{key.inspect}\"\n  end\n\n  def from_json(options = nil)\n    ActiveSupport::JSON.decode(@user.to_json(options))[\"user\"]\n  end\nend\n"
  },
  {
    "path": "test/models/timeoutable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass TimeoutableTest < ActiveSupport::TestCase\n\n  test 'should be expired' do\n    assert new_user.timedout?(31.minutes.ago)\n  end\n\n  test 'should not be expired' do\n    assert_not new_user.timedout?(29.minutes.ago)\n  end\n\n  test 'should not be expired when params is nil' do\n    assert_not new_user.timedout?(nil)\n  end\n\n  test 'should use timeout_in method' do\n    user = new_user\n    user.instance_eval { def timeout_in; 10.minutes end }\n\n    assert user.timedout?(12.minutes.ago)\n    assert_not user.timedout?(8.minutes.ago)\n  end\n\n  test 'should not be expired when timeout_in method returns nil' do\n    user = new_user\n    user.instance_eval { def timeout_in; nil end }\n    assert_not user.timedout?(10.hours.ago)\n  end\n\n  test 'fallback to Devise config option' do\n    swap Devise, timeout_in: 1.minute do\n      user = new_user\n      assert user.timedout?(2.minutes.ago)\n      assert_not user.timedout?(30.seconds.ago)\n\n      Devise.timeout_in = 5.minutes\n      assert_not user.timedout?(2.minutes.ago)\n      assert user.timedout?(6.minutes.ago)\n    end\n  end\n\n  test 'required_fields should contain the fields that Devise uses' do\n    assert_equal [], Devise::Models::Timeoutable.required_fields(User)\n  end\n\n  test 'should not raise error if remember_created_at is not empty and rememberable is disabled' do\n    user = create_admin(remember_created_at: Time.current)\n    assert user.timedout?(31.minutes.ago)\n  end\nend\n"
  },
  {
    "path": "test/models/trackable_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass TrackableTest < ActiveSupport::TestCase\n  test 'required_fields should contain the fields that Devise uses' do\n    assert_equal [\n      :current_sign_in_at,\n      :current_sign_in_ip,\n      :last_sign_in_at,\n      :last_sign_in_ip,\n      :sign_in_count\n    ], Devise::Models::Trackable.required_fields(User)\n  end\n\n  test 'update_tracked_fields should only set attributes but not save the record' do\n    user = create_user\n    request = mock\n    request.stubs(:remote_ip).returns(\"127.0.0.1\")\n\n    assert_nil user.current_sign_in_ip\n    assert_nil user.last_sign_in_ip\n    assert_nil user.current_sign_in_at\n    assert_nil user.last_sign_in_at\n    assert_equal 0, user.sign_in_count\n\n    user.update_tracked_fields(request)\n\n    assert_equal \"127.0.0.1\", user.current_sign_in_ip\n    assert_equal \"127.0.0.1\", user.last_sign_in_ip\n    assert_not_nil user.current_sign_in_at\n    assert_not_nil user.last_sign_in_at\n    assert_equal 1, user.sign_in_count\n\n    user.reload\n\n    assert_nil user.current_sign_in_ip\n    assert_nil user.last_sign_in_ip\n    assert_nil user.current_sign_in_at\n    assert_nil user.last_sign_in_at\n    assert_equal 0, user.sign_in_count\n  end\n\n  test \"update_tracked_fields! should not persist invalid records\" do\n    user = UserWithValidations.new\n    request = mock\n    request.stubs(:remote_ip).returns(\"127.0.0.1\")\n\n    assert_not user.update_tracked_fields!(request)\n    assert_not user.persisted?\n  end\n\n  test \"update_tracked_fields! should not run model validations\" do\n    user = User.new\n    request = mock\n    request.stubs(:remote_ip).returns(\"127.0.0.1\")\n\n    user.expects(:after_validation_callback).never\n\n    assert_not user.update_tracked_fields!(request)\n  end\n\n  test 'extract_ip_from should be overridable' do\n    class UserWithOverride < User\n      protected\n        def extract_ip_from(request)\n          \"127.0.0.2\"\n        end\n    end\n\n    request = mock\n    request.stubs(:remote_ip).returns(\"127.0.0.1\")\n    user = UserWithOverride.new\n\n    user.update_tracked_fields(request)\n\n    assert_equal \"127.0.0.2\", user.current_sign_in_ip\n    assert_equal \"127.0.0.2\", user.last_sign_in_ip\n  end\nend\n"
  },
  {
    "path": "test/models/validatable_test.rb",
    "content": "# encoding: UTF-8\n# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass ValidatableTest < ActiveSupport::TestCase\n  test 'should require email to be set' do\n    user = new_user(email: nil)\n    assert user.invalid?\n    assert user.errors[:email]\n    assert user.errors.added?(:email, :blank)\n  end\n\n  test 'should require uniqueness of email if email has changed, allowing blank' do\n    existing_user = create_user\n\n    user = new_user(email: '')\n    assert user.invalid?\n    assert_no_match(/taken/, user.errors[:email].join)\n\n    user.email = existing_user.email\n    assert user.invalid?\n    assert_match(/taken/, user.errors[:email].join)\n\n    user.save(validate: false)\n    assert user.valid?\n  end\n\n  test 'should require correct email format if email has changed, allowing blank' do\n    user = new_user(email: '')\n    assert user.invalid?\n    assert_not_equal 'is invalid', user.errors[:email].join\n\n    %w{invalid_email_format 123 $$$ () ☃}.each do |email|\n      user.email = email\n      assert user.invalid?, \"should be invalid with email #{email}\"\n      assert_equal 'is invalid', user.errors[:email].join\n    end\n\n    user.save(validate: false)\n    assert user.valid?\n  end\n\n  test 'should accept valid emails' do\n    %w(a.b.c@example.com test_mail@gmail.com any@any.net email@test.br 123@mail.test 1☃3@mail.test).each do |email|\n      user = new_user(email: email)\n      assert user.valid?, \"should be valid with email #{email}\"\n      assert_blank user.errors[:email]\n    end\n  end\n\n  test 'should require password to be set when creating a new record' do\n    user = new_user(password: '', password_confirmation: '')\n    assert user.invalid?\n    assert user.errors.added?(:password, :blank)\n  end\n\n  test 'should require confirmation to be set when creating a new record' do\n    user = new_user(password: 'new_password', password_confirmation: 'blabla')\n    assert user.invalid?\n\n    assert user.errors.added?(:password_confirmation, :confirmation, attribute: \"Password\")\n  end\n\n  test 'should require password when updating/resetting password' do\n    user = create_user\n\n    user.password = ''\n    user.password_confirmation = ''\n\n    assert user.invalid?\n    assert user.errors.added?(:password, :blank)\n  end\n\n  test 'should require confirmation when updating/resetting password' do\n    user = create_user\n    user.password_confirmation = 'another_password'\n    assert user.invalid?\n\n    assert user.errors.added?(:password_confirmation, :confirmation, attribute: \"Password\")\n  end\n\n  test 'should require a password with minimum of 7 characters' do\n    user = new_user(password: '12345', password_confirmation: '12345')\n    assert user.invalid?\n    assert_equal 'is too short (minimum is 7 characters)', user.errors[:password].join\n  end\n\n  test 'should require a password with maximum of 72 characters long' do\n    user = new_user(password: 'x'*73, password_confirmation: 'x'*73)\n    assert user.invalid?\n    assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join\n  end\n\n  test 'should not require password length when it\\'s not changed' do\n    user = create_user.reload\n    user.password = user.password_confirmation = nil\n    assert user.valid?\n\n    user.password_confirmation = 'confirmation'\n    assert user.invalid?\n    assert_not (user.errors[:password].join =~ /is too long/)\n  end\n\n  test 'should complain about length even if password is not required' do\n    user = new_user(password: 'x'*73, password_confirmation: 'x'*73)\n    user.stubs(:password_required?).returns(false)\n    assert user.invalid?\n    assert_equal 'is too long (maximum is 72 characters)', user.errors[:password].join\n  end\n\n  test 'should not be included in objects with invalid API' do\n    exception = assert_raise RuntimeError do\n      Class.new.send :include, Devise::Models::Validatable\n    end\n\n    expected_message = /Could not use :validatable module since .* does not respond to the following methods: validates_presence_of.*/\n    assert_match expected_message, exception.message\n  end\n\n  test 'required_fields should be an empty array' do\n    assert_equal [], Devise::Models::Validatable.required_fields(User)\n  end\nend\n"
  },
  {
    "path": "test/models_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\nrequire 'test_models'\n\nclass ActiveRecordTest < ActiveSupport::TestCase\n  def include_module?(klass, mod)\n    klass.devise_modules.include?(mod) &&\n      klass.included_modules.include?(Devise::Models::const_get(mod.to_s.classify))\n  end\n\n  def assert_include_modules(klass, *modules)\n    modules.each do |mod|\n      assert include_module?(klass, mod)\n    end\n\n    (Devise::ALL - modules).each do |mod|\n      assert_not include_module?(klass, mod)\n    end\n  end\n\n  test 'can cherry pick modules' do\n    assert_include_modules Admin, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable\n  end\n\n  test 'validations options are not applied too late' do\n    validators = WithValidation.validators_on :password\n    length = validators.find { |v| v.kind == :length }\n    assert_equal 2, length.options[:minimum].call\n    assert_equal 6, length.options[:maximum].call\n  end\n\n  test 'validations are applied just once' do\n    validators = Several.validators_on :password\n    assert_equal 1, validators.select{ |v| v.kind == :length }.length\n  end\n\n  test 'chosen modules are inheritable' do\n    assert_include_modules Inheritable, :database_authenticatable, :registerable, :timeoutable, :recoverable, :lockable, :confirmable\n  end\n\n  test 'order of module inclusion' do\n    correct_module_order   = [:database_authenticatable, :recoverable, :registerable, :confirmable, :lockable, :timeoutable]\n    incorrect_module_order = [:database_authenticatable, :timeoutable, :registerable, :recoverable, :lockable, :confirmable]\n\n    assert_include_modules Admin, *incorrect_module_order\n\n    # get module constants from symbol list\n    module_constants = correct_module_order.collect { |mod| Devise::Models::const_get(mod.to_s.classify) }\n\n    # confirm that they adhere to the order in ALL\n    # get included modules, filter out the noise, and reverse the order\n    assert_equal module_constants, (Admin.included_modules & module_constants).reverse\n  end\n\n  test 'raise error on invalid module' do\n    assert_raise NameError do\n      # Mix valid an invalid modules.\n      Configurable.class_eval { devise :database_authenticatable, :doesnotexit }\n    end\n  end\n\n  test 'set a default value for stretches' do\n    assert_equal 15, Configurable.stretches\n  end\n\n  test 'set a default value for pepper' do\n    assert_equal 'abcdef', Configurable.pepper\n  end\n\n  test 'set a default value for allow_unconfirmed_access_for' do\n    assert_equal 5.days, Configurable.allow_unconfirmed_access_for\n  end\n\n  test 'set a default value for remember_for' do\n    assert_equal 7.days, Configurable.remember_for\n  end\n\n  test 'set a default value for timeout_in' do\n    assert_equal 15.minutes, Configurable.timeout_in\n  end\n\n  test 'set a default value for unlock_in' do\n    assert_equal 10.days, Configurable.unlock_in\n  end\n\n  test 'set null fields on migrations' do\n    # Ignore email sending since no email exists.\n    klass = Class.new(Admin) do\n      def send_devise_notification(*); end\n    end\n\n    assert_nothing_raised { klass.create! }\n  end\nend\n\nmodule StubModelFilters\n  def stub_filter(name)\n    define_singleton_method(name) { |*| nil }\n  end\nend\n\nclass CheckFieldsTest < ActiveSupport::TestCase\n  test 'checks if the class respond_to the required fields' do\n    Player = Class.new do\n      extend Devise::Models\n      extend StubModelFilters\n\n      stub_filter :before_validation\n      stub_filter :after_update\n\n      devise :database_authenticatable\n\n      attr_accessor :encrypted_password, :email\n    end\n\n    assert_nothing_raised do\n      Devise::Models.check_fields!(Player)\n    end\n  end\n\n  test 'raises Devise::Models::MissingAtrribute and shows the missing attribute if the class doesn\\'t respond_to one of the attributes' do\n    Clown = Class.new do\n      extend Devise::Models\n      extend StubModelFilters\n\n      stub_filter :before_validation\n      stub_filter :after_update\n\n      devise :database_authenticatable\n\n      attr_accessor :encrypted_password\n    end\n\n    assert_raise_with_message Devise::Models::MissingAttribute, \"The following attribute(s) is (are) missing on your model: email\" do\n      Devise::Models.check_fields!(Clown)\n    end\n  end\n\n  test 'raises Devise::Models::MissingAtrribute with all the missing attributes if there is more than one' do\n    Magician = Class.new do\n      extend Devise::Models\n      extend StubModelFilters\n\n      stub_filter :before_validation\n      stub_filter :after_update\n\n      devise :database_authenticatable\n    end\n\n    assert_raise_with_message Devise::Models::MissingAttribute, \"The following attribute(s) is (are) missing on your model: encrypted_password, email\" do\n      Devise::Models.check_fields!(Magician)\n    end\n  end\nend\n"
  },
  {
    "path": "test/omniauth/config_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass OmniAuthConfigTest < ActiveSupport::TestCase\n  class MyStrategy\n    include OmniAuth::Strategy\n  end\n\n  test 'strategy_name returns provider if no options given' do\n    config = Devise::OmniAuth::Config.new :facebook, [{}]\n    assert_equal :facebook, config.strategy_name\n  end\n\n  test 'strategy_name returns provider if no name option are given' do\n    config = Devise::OmniAuth::Config.new :facebook, [{ other: :option }]\n    assert_equal :facebook, config.strategy_name\n  end\n\n  test 'returns name option when have a name' do\n    config = Devise::OmniAuth::Config.new :facebook, [{ name: :github }]\n    assert_equal :github, config.strategy_name\n  end\n\n  test \"finds contrib strategies\" do\n    config = Devise::OmniAuth::Config.new :facebook, [{}]\n    assert_equal OmniAuth::Strategies::Facebook, config.strategy_class\n  end\n\n  class NamedTestStrategy\n    include OmniAuth::Strategy\n    option :name, :the_one\n  end\n\n  test \"finds the strategy in OmniAuth's list by name\" do\n    config = Devise::OmniAuth::Config.new :the_one, [{}]\n    assert_equal NamedTestStrategy, config.strategy_class\n  end\n\n  class UnNamedTestStrategy\n    include OmniAuth::Strategy\n  end\n\n  test \"finds the strategy in OmniAuth's list by class name\" do\n    config = Devise::OmniAuth::Config.new :un_named_test_strategy, [{}]\n    assert_equal UnNamedTestStrategy, config.strategy_class\n  end\n\n  test 'raises an error if strategy cannot be found' do\n    config = Devise::OmniAuth::Config.new :my_other_strategy, [{}]\n    assert_raise Devise::OmniAuth::StrategyNotFound do\n      config.strategy_class\n    end\n  end\n\n  test 'allows the user to define a custom require path' do\n    config = Devise::OmniAuth::Config.new :my_strategy, [{strategy_class: MyStrategy}]\n    config_class = config.strategy_class\n    assert_equal MyStrategy, config_class\n  end\nend\n"
  },
  {
    "path": "test/omniauth/url_helpers_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass OmniAuthRoutesTest < ActionController::TestCase\n  tests ApplicationController\n\n  def assert_path(action, provider, with_param = true)\n    # Resource param\n    assert_equal @controller.send(action, :user, provider),\n                 @controller.send(\"user_#{provider}_#{action}\")\n\n    # With an object\n    assert_equal @controller.send(action, User.new, provider),\n                 @controller.send(\"user_#{provider}_#{action}\")\n\n    if with_param\n      # Default url params\n      assert_equal @controller.send(action, :user, provider, param: 123),\n                   @controller.send(\"user_#{provider}_#{action}\", param: 123)\n    end\n  end\n\n  test 'should alias omniauth_callback to mapped user auth_callback' do\n    assert_path :omniauth_callback_path, :facebook\n  end\n\n  test 'should alias omniauth_authorize to mapped user auth_authorize' do\n    assert_path :omniauth_authorize_path, :facebook, false\n  end\n\n  test 'should generate authorization path' do\n    assert_match \"/users/auth/facebook\", @controller.omniauth_authorize_path(:user, :facebook)\n\n    assert_raise NoMethodError do\n      @controller.omniauth_authorize_path(:user, :github)\n    end\n  end\n\n  test 'should generate authorization path for named open_id omniauth' do\n    assert_match \"/users/auth/google\", @controller.omniauth_authorize_path(:user, :google)\n  end\n\n  test 'should generate authorization path with params' do\n    assert_match \"/users/auth/openid?openid_url=http%3A%2F%2Fyahoo.com\",\n                  @controller.omniauth_authorize_path(:user, :openid, openid_url: \"http://yahoo.com\")\n  end\n\n  test 'should not add a \"?\" if no param was sent' do\n    assert_equal \"/users/auth/openid\",\n                  @controller.omniauth_authorize_path(:user, :openid)\n  end\nend\n"
  },
  {
    "path": "test/orm/active_record.rb",
    "content": "# frozen_string_literal: true\n\nActiveRecord::Migration.verbose = false\nActiveRecord::Base.logger = Logger.new(nil)\nActiveRecord::Base.include_root_in_json = true\n\nmigrate_path = File.expand_path(\"../../rails_app/db/migrate/\", __FILE__)\nif Devise::Test.rails71_and_up?\n  ActiveRecord::MigrationContext.new(migrate_path).migrate\nelse\n  ActiveRecord::MigrationContext.new(migrate_path, ActiveRecord::SchemaMigration).migrate\nend\n\nclass ActiveSupport::TestCase\n  self.use_transactional_tests = true\n  self.use_instantiated_fixtures  = false\nend\n"
  },
  {
    "path": "test/orm/mongoid.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'mongoid/version'\n\nMongoid.configure do |config|\n  config.load!('test/support/mongoid.yml')\n  config.use_utc = true\n  config.include_root_in_json = true\nend\n\nclass ActiveSupport::TestCase\n  setup do\n    Mongoid::Config.purge!\n  end\nend\n"
  },
  {
    "path": "test/parameter_sanitizer_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\nrequire 'devise/parameter_sanitizer'\n\nclass ParameterSanitizerTest < ActiveSupport::TestCase\n  def sanitizer(params)\n    params = ActionController::Parameters.new(params)\n    Devise::ParameterSanitizer.new(User, :user, params)\n  end\n\n  test 'permits the default parameters for sign in' do\n    sanitizer = sanitizer('user' => { 'email' => 'jose' })\n    sanitized = sanitizer.sanitize(:sign_in)\n\n    assert_equal({ 'email' => 'jose' }, sanitized)\n  end\n\n  test 'permits empty params when received not a hash' do\n    sanitizer = sanitizer({ 'user' => 'string' })\n    sanitized = sanitizer.sanitize(:sign_in)\n\n    assert_equal({}, sanitized)\n  end\n\n  test 'does not rise error when received string instead of hash' do\n    sanitizer = sanitizer('user' => 'string')\n    assert_nothing_raised do\n      sanitizer.sanitize(:sign_in)\n    end\n  end\n\n  test 'does not rise error when received nil instead of hash' do\n    sanitizer = sanitizer('user' => nil)\n    assert_nothing_raised do\n      sanitizer.sanitize(:sign_in)\n    end\n  end\n\n  test 'permits empty params when received nil instead of hash' do\n    sanitizer = sanitizer({ 'user' => nil })\n    sanitized = sanitizer.sanitize(:sign_in)\n\n    assert_equal({}, sanitized)\n  end\n\n  test 'permits the default parameters for sign up' do\n    sanitizer = sanitizer('user' => { 'email' => 'jose', 'role' => 'invalid' })\n    sanitized = sanitizer.sanitize(:sign_up)\n\n    assert_equal({ 'email' => 'jose' }, sanitized)\n  end\n\n  test 'permits the default parameters for account update' do\n    sanitizer = sanitizer('user' => { 'email' => 'jose', 'role' => 'invalid' })\n    sanitized = sanitizer.sanitize(:account_update)\n\n    assert_equal({ 'email' => 'jose' }, sanitized)\n  end\n\n  test 'permits news parameters for an existing action' do\n    sanitizer = sanitizer('user' => { 'username' => 'jose' })\n    sanitizer.permit(:sign_in, keys: [:username])\n    sanitized = sanitizer.sanitize(:sign_in)\n\n    assert_equal({ 'username' => 'jose' }, sanitized)\n  end\n\n  test 'permits news parameters for an existing action with a block' do\n    sanitizer = sanitizer('user' => { 'username' => 'jose' })\n    sanitizer.permit(:sign_in) do |user|\n      user.permit(:username)\n    end\n\n    sanitized = sanitizer.sanitize(:sign_in)\n\n    assert_equal({ 'username' => 'jose' }, sanitized)\n  end\n\n  test 'permit parameters for new actions' do\n    sanitizer = sanitizer('user' => { 'email' => 'jose@omglol', 'name' => 'Jose' })\n    sanitizer.permit(:invite_user, keys: [:email, :name])\n\n    sanitized = sanitizer.sanitize(:invite_user)\n\n    assert_equal({ 'email' => 'jose@omglol', 'name' => 'Jose' }, sanitized)\n  end\n\n  test 'fails when we do not have any permitted parameters for the action' do\n    sanitizer = sanitizer('user' => { 'email' => 'jose', 'password' => 'invalid' })\n\n    assert_raise NotImplementedError do\n      sanitizer.sanitize(:unknown)\n    end\n  end\n\n  test 'removes permitted parameters' do\n    sanitizer = sanitizer('user' => { 'email' => 'jose@omglol', 'username' => 'jose' })\n\n    sanitizer.permit(:sign_in, keys: [:username], except: [:email])\n    sanitized = sanitizer.sanitize(:sign_in)\n\n    assert_equal({ 'username' => 'jose' }, sanitized)\n  end\nend\n"
  },
  {
    "path": "test/rails_app/Rakefile",
    "content": "# Add your own tasks in files placed in lib/tasks ending in .rake,\n# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.\n\nrequire File.expand_path('../config/application', __FILE__)\n\nRails.application.load_tasks\n"
  },
  {
    "path": "test/rails_app/app/active_record/admin.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_admin'\n\nclass Admin < ActiveRecord::Base\n  include Shim\n  include SharedAdmin\nend\n"
  },
  {
    "path": "test/rails_app/app/active_record/shim.rb",
    "content": "# frozen_string_literal: true\n\nmodule Shim\nend\n"
  },
  {
    "path": "test/rails_app/app/active_record/user.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_user'\n\nclass User < ActiveRecord::Base\n  include Shim\n  include SharedUser\n\n  validates :sign_in_count, presence: true\n\n  cattr_accessor :validations_performed\n\n  after_validation :after_validation_callback\n\n  def after_validation_callback\n    # used to check in our test if the validations were called\n    @@validations_performed = true\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/active_record/user_on_engine.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_user_without_omniauth'\n\nclass UserOnEngine < ActiveRecord::Base\n  self.table_name = 'users'\n  include Shim\n  include SharedUserWithoutOmniauth\nend\n"
  },
  {
    "path": "test/rails_app/app/active_record/user_on_main_app.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_user_without_omniauth'\n\nclass UserOnMainApp < ActiveRecord::Base\n  self.table_name = 'users'\n  include Shim\n  include SharedUserWithoutOmniauth\nend\n"
  },
  {
    "path": "test/rails_app/app/active_record/user_with_validations.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_user'\n\nclass UserWithValidations < ActiveRecord::Base\n  self.table_name = 'users'\n  include Shim\n  include SharedUser\n\n  validates :email, presence: true\nend\n\n"
  },
  {
    "path": "test/rails_app/app/active_record/user_without_email.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"shared_user_without_email\"\n\nclass UserWithoutEmail < ActiveRecord::Base\n  self.table_name = 'users'\n  include Shim\n  include SharedUserWithoutEmail\nend\n\n"
  },
  {
    "path": "test/rails_app/app/controllers/admins/sessions_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Admins::SessionsController < Devise::SessionsController\n  def new\n    flash[:special] = \"Welcome to #{controller_path.inspect} controller!\"\n    super\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/admins_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass AdminsController < ApplicationController\n  before_action :authenticate_admin!\n\n  def index\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/application_controller.rb",
    "content": "# frozen_string_literal: true\n\n# Filters added to this controller apply to all controllers in the application.\n# Likewise, all the methods added will be available for all controllers.\n\nclass ApplicationController < ActionController::Base\n  protect_from_forgery\n  around_action :set_locale\n  before_action :current_user, unless: :devise_controller?\n  before_action :authenticate_user!, if: :devise_controller?\n  respond_to(*Mime::SET.map(&:to_sym))\n\n  devise_group :commenter, contains: [:user, :admin]\n\n  private\n\n  def set_locale\n    I18n.with_locale(params[:locale] || I18n.default_locale) { yield }\n  end\n\n  def default_url_options\n    {locale: params[:locale]}.compact\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/application_with_fake_engine.rb",
    "content": "# frozen_string_literal: true\n\nclass ApplicationWithFakeEngine < ApplicationController\n  private\n\n  helper_method :fake_engine\n  def fake_engine\n    @fake_engine ||= FakeEngine.new\n  end\nend\n\nclass FakeEngine\n  def user_on_engine_confirmation_path\n    '/user_on_engine/confirmation'\n  end\n\n  def new_user_on_engine_session_path\n    '/user_on_engine/confirmation/new'\n  end\n\n  def new_user_on_engine_registration_path\n    '/user_on_engine/registration/new'\n  end\n\n  def new_user_on_engine_password_path\n    '/user_on_engine/password/new'\n  end\n\n  def new_user_on_engine_unlock_path\n    '/user_on_engine/unlock/new'\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/custom/registrations_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Custom::RegistrationsController < Devise::RegistrationsController\n  def new\n    super do |resource|\n      @new_block_called = true\n    end\n  end\n\n  def create\n    super do |resource|\n      @create_block_called = true\n    end\n  end\n\n  def update\n    super do |resource|\n      @update_block_called = true\n    end\n  end\n\n  def create_block_called?\n    @create_block_called == true\n  end\n\n  def update_block_called?\n    @update_block_called == true\n  end\n\n  def new_block_called?\n    @new_block_called == true\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/home_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass HomeController < ApplicationController\n  def index\n  end\n\n  def private\n  end\n\n  def user_dashboard\n  end\n\n  def admin_dashboard\n  end\n\n  def join\n  end\n\n  def set\n    session[\"devise.foo_bar\"] = \"something\"\n    head :ok\n  end\n\n  def unauthenticated\n    render body: \"unauthenticated\", status: :unauthorized\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/publisher/registrations_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Publisher::RegistrationsController < ApplicationController\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/publisher/sessions_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Publisher::SessionsController < ApplicationController\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/streaming_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass StreamingController < ApplicationController\n  include ActionController::Live\n\n  before_action :authenticate_user!\n\n  def index\n    render body: 'Index'\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/users/omniauth_callbacks_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController\n  def facebook\n    data = request.respond_to?(:get_header) ? request.get_header(\"omniauth.auth\") : request.env[\"omniauth.auth\"]\n    session[\"devise.facebook_data\"] = data[\"extra\"][\"user_hash\"]\n    render json: data\n  end\n\n  def sign_in_facebook\n    user = User.to_adapter.find_first(email: 'user@test.com')\n    user.remember_me = true\n    sign_in user\n    render body: \"\"\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/controllers/users_controller.rb",
    "content": "# frozen_string_literal: true\n\nclass UsersController < ApplicationController\n  prepend_before_action :current_user, only: :exhibit\n  before_action :authenticate_user!, except: [:accept, :exhibit]\n  clear_respond_to\n  respond_to :html, :json\n\n  def index\n    user_session[:cart] = \"Cart\"\n    respond_with(current_user)\n  end\n\n  def edit_form\n    user_session['last_request_at'] = params.fetch(:last_request_at, 31.minutes.ago.utc)\n  end\n\n  def update_form\n    render body: 'Update'\n  end\n\n  def accept\n    @current_user = current_user\n  end\n\n  def exhibit\n    render body: current_user ? \"User is authenticated\" : \"User is not authenticated\"\n  end\n\n  def expire\n    user_session['last_request_at'] = 31.minutes.ago.utc\n    render body: 'User will be expired on next request'\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/helpers/application_helper.rb",
    "content": "# frozen_string_literal: true\n\n# Methods added to this helper will be available to all templates in the application.\nmodule ApplicationHelper\nend\n"
  },
  {
    "path": "test/rails_app/app/mailers/users/from_proc_mailer.rb",
    "content": "# frozen_string_literal: true\n\nclass Users::FromProcMailer < Devise::Mailer\n  default from: proc { 'custom@example.com' }\nend\n"
  },
  {
    "path": "test/rails_app/app/mailers/users/mailer.rb",
    "content": "# frozen_string_literal: true\n\nclass Users::Mailer < Devise::Mailer\n  default from: 'custom@example.com'\nend\n"
  },
  {
    "path": "test/rails_app/app/mailers/users/reply_to_mailer.rb",
    "content": "# frozen_string_literal: true\n\nclass Users::ReplyToMailer < Devise::Mailer\n  default from: 'custom@example.com'\n  default reply_to: 'custom_reply_to@example.com'\nend\n"
  },
  {
    "path": "test/rails_app/app/mongoid/admin.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_admin'\n\nclass Admin\n  include Mongoid::Document\n  include Shim\n  include SharedAdmin\n\n  ## Database authenticatable\n  field :email,              type: String\n  field :encrypted_password, type: String\n\n  ## Recoverable\n  field :reset_password_token,   type: String\n  field :reset_password_sent_at, type: Time\n\n  ## Rememberable\n  field :remember_created_at, type: Time\n\n  ## Confirmable\n  field :confirmation_token,   type: String\n  field :confirmed_at,         type: Time\n  field :confirmation_sent_at, type: Time\n  field :unconfirmed_email,    type: String # Only if using reconfirmable\n\n  ## Lockable\n  field :locked_at, type: Time\n\n  field :active, type: Boolean, default: false\nend\n"
  },
  {
    "path": "test/rails_app/app/mongoid/shim.rb",
    "content": "# frozen_string_literal: true\n\nmodule Shim\n  extend ::ActiveSupport::Concern\n\n  included do\n    include ::Mongoid::Timestamps\n    field :created_at, type: DateTime\n  end\n\n  module ClassMethods\n    def order(attribute)\n      asc(attribute)\n    end\n\n    def find_by_email(email)\n      find_by(email: email)\n    end\n  end\n\n  # overwrite equality (because some devise tests use this for asserting model equality)\n  def ==(other)\n    other.is_a?(self.class) && _id == other._id\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/mongoid/user.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_user'\n\nclass User\n  include Mongoid::Document\n  include Shim\n  include SharedUser\n\n  field :username, type: String\n  field :facebook_token, type: String\n\n  ## Database authenticatable\n  field :email,              type: String, default: \"\"\n  field :encrypted_password, type: String, default: \"\"\n\n  ## Recoverable\n  field :reset_password_token,   type: String\n  field :reset_password_sent_at, type: Time\n\n  ## Rememberable\n  field :remember_created_at, type: Time\n\n  ## Trackable\n  field :sign_in_count,      type: Integer, default: 0\n  field :current_sign_in_at, type: Time\n  field :last_sign_in_at,    type: Time\n  field :current_sign_in_ip, type: String\n  field :last_sign_in_ip,    type: String\n\n  ## Confirmable\n  field :confirmation_token,   type: String\n  field :confirmed_at,         type: Time\n  field :confirmation_sent_at, type: Time\n  # field :unconfirmed_email,    type: String # Only if using reconfirmable\n\n  ## Lockable\n  field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts\n  field :unlock_token,    type: String # Only if unlock strategy is :email or :both\n  field :locked_at,       type: Time\n\n  cattr_accessor :validations_performed\n\n  after_validation :after_validation_callback\n\n  def after_validation_callback\n    # used to check in our test if the validations were called\n    @@validations_performed = true\n  end\nend\n"
  },
  {
    "path": "test/rails_app/app/mongoid/user_on_engine.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_user_without_omniauth'\n\nclass UserOnEngine\n  include Mongoid::Document\n  include Shim\n  include SharedUserWithoutOmniauth\n\n  field :username, type: String\n  field :facebook_token, type: String\n\n  ## Database authenticatable\n  field :email, type: String, default: \"\"\n  field :encrypted_password, type: String, default: \"\"\n\n  ## Recoverable\n  field :reset_password_token, type: String\n  field :reset_password_sent_at, type: Time\n\n  ## Rememberable\n  field :remember_created_at, type: Time\n\n  ## Trackable\n  field :sign_in_count, type: Integer, default: 0\n  field :current_sign_in_at, type: Time\n  field :last_sign_in_at, type: Time\n  field :current_sign_in_ip, type: String\n  field :last_sign_in_ip, type: String\n\n  ## Confirmable\n  field :confirmation_token, type: String\n  field :confirmed_at, type: Time\n  field :confirmation_sent_at, type: Time\n  # field :unconfirmed_email,    type: String # Only if using reconfirmable\n\n  ## Lockable\n  field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts\n  field :unlock_token, type: String # Only if unlock strategy is :email or :both\n  field :locked_at, type: Time\nend\n"
  },
  {
    "path": "test/rails_app/app/mongoid/user_on_main_app.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'shared_user_without_omniauth'\n\nclass UserOnMainApp\n  include Mongoid::Document\n  include Shim\n  include SharedUserWithoutOmniauth\n\n  field :username, type: String\n  field :facebook_token, type: String\n\n  ## Database authenticatable\n  field :email, type: String, default: \"\"\n  field :encrypted_password, type: String, default: \"\"\n\n  ## Recoverable\n  field :reset_password_token, type: String\n  field :reset_password_sent_at, type: Time\n\n  ## Rememberable\n  field :remember_created_at, type: Time\n\n  ## Trackable\n  field :sign_in_count, type: Integer, default: 0\n  field :current_sign_in_at, type: Time\n  field :last_sign_in_at, type: Time\n  field :current_sign_in_ip, type: String\n  field :last_sign_in_ip, type: String\n\n  ## Confirmable\n  field :confirmation_token, type: String\n  field :confirmed_at, type: Time\n  field :confirmation_sent_at, type: Time\n  # field :unconfirmed_email,    type: String # Only if using reconfirmable\n\n  ## Lockable\n  field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts\n  field :unlock_token, type: String # Only if unlock strategy is :email or :both\n  field :locked_at, type: Time\nend\n"
  },
  {
    "path": "test/rails_app/app/mongoid/user_with_validations.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"shared_user\"\n\nclass UserWithValidations\n  include Mongoid::Document\n  include Shim\n  include SharedUser\n\n  field :username, type: String\n  field :facebook_token, type: String\n\n  ## Database authenticatable\n  field :email, type: String, default: \"\"\n  field :encrypted_password, type: String, default: \"\"\n\n  ## Recoverable\n  field :reset_password_token, type: String\n  field :reset_password_sent_at, type: Time\n\n  ## Rememberable\n  field :remember_created_at, type: Time\n\n  ## Trackable\n  field :sign_in_count, type: Integer, default: 0\n  field :current_sign_in_at, type: Time\n  field :last_sign_in_at, type: Time\n  field :current_sign_in_ip, type: String\n  field :last_sign_in_ip, type: String\n\n  ## Lockable\n  field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts\n  field :unlock_token, type: String # Only if unlock strategy is :email or :both\n  field :locked_at, type: Time\n\n  validates :email, presence: true\nend\n"
  },
  {
    "path": "test/rails_app/app/mongoid/user_without_email.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"shared_user_without_email\"\n\nclass UserWithoutEmail\n  include Mongoid::Document\n  include Shim\n  include SharedUserWithoutEmail\n\n  field :username, type: String\n  field :facebook_token, type: String\n\n  ## Database authenticatable\n  field :email, type: String, default: \"\"\n  field :encrypted_password, type: String, default: \"\"\n\n  ## Recoverable\n  field :reset_password_token, type: String\n  field :reset_password_sent_at, type: Time\n\n  ## Rememberable\n  field :remember_created_at, type: Time\n\n  ## Trackable\n  field :sign_in_count, type: Integer, default: 0\n  field :current_sign_in_at, type: Time\n  field :last_sign_in_at, type: Time\n  field :current_sign_in_ip, type: String\n  field :last_sign_in_ip, type: String\n\n  ## Lockable\n  field :failed_attempts, type: Integer, default: 0 # Only if lock strategy is :failed_attempts\n  field :unlock_token, type: String # Only if unlock strategy is :email or :both\n  field :locked_at, type: Time\nend\n"
  },
  {
    "path": "test/rails_app/app/views/admins/index.html.erb",
    "content": "Welcome Admin!\n"
  },
  {
    "path": "test/rails_app/app/views/admins/sessions/new.html.erb",
    "content": "Welcome to \"sessions/new\" view!\n<%= render template: \"devise/sessions/new\" %>\n"
  },
  {
    "path": "test/rails_app/app/views/home/admin_dashboard.html.erb",
    "content": "Admin dashboard\n"
  },
  {
    "path": "test/rails_app/app/views/home/index.html.erb",
    "content": "Home!\n"
  },
  {
    "path": "test/rails_app/app/views/home/join.html.erb",
    "content": "Join\n"
  },
  {
    "path": "test/rails_app/app/views/home/private.html.erb",
    "content": "Private!\n"
  },
  {
    "path": "test/rails_app/app/views/home/user_dashboard.html.erb",
    "content": "User dashboard\n"
  },
  {
    "path": "test/rails_app/app/views/layouts/application.html.erb",
    "content": "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"\n  \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">\n<html>\n  <head>\n    <title>Devise Test App</title>\n  </head>\n  <body>\n    <div id=\"container\">\n      <%- flash.each do |name, msg| -%>\n        <%= content_tag :div, msg, id: \"flash_#{name}\" %>\n      <%- end -%>\n\n      <% if user_signed_in? -%>\n        <p>Hello User <%= current_user.email %>! You are signed in!</p>\n      <% end -%>\n\n      <% if admin_signed_in? -%>\n        <p>Hello Admin <%= current_admin.email %>! You are signed in!</p>\n      <% end -%>\n\n      <%= yield %>\n    </div>\n  </body>\n</html>\n"
  },
  {
    "path": "test/rails_app/app/views/users/edit_form.html.erb",
    "content": "<%= button_to 'Update', update_form_user_path(current_user), method: 'put' %>\n"
  },
  {
    "path": "test/rails_app/app/views/users/index.html.erb",
    "content": "Welcome User #<%= current_user.id %>!\n"
  },
  {
    "path": "test/rails_app/app/views/users/mailer/confirmation_instructions.erb",
    "content": "<%= @resource.email %>"
  },
  {
    "path": "test/rails_app/app/views/users/sessions/new.html.erb",
    "content": "Special user view\n"
  },
  {
    "path": "test/rails_app/bin/bundle",
    "content": "#!/usr/bin/env ruby\nENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)\nload Gem.bin_path('bundler', 'bundle')\n"
  },
  {
    "path": "test/rails_app/bin/rails",
    "content": "#!/usr/bin/env ruby\nAPP_PATH = File.expand_path('../../config/application',  __FILE__)\nrequire_relative '../config/boot'\nrequire 'rails/commands'\n"
  },
  {
    "path": "test/rails_app/bin/rake",
    "content": "#!/usr/bin/env ruby\nrequire_relative '../config/boot'\nrequire 'rake'\nRake.application.run\n"
  },
  {
    "path": "test/rails_app/config/application.rb",
    "content": "# frozen_string_literal: true\n\nrequire File.expand_path('../boot', __FILE__)\n\nrequire \"logger\"\nrequire \"action_controller/railtie\"\nrequire \"action_mailer/railtie\"\nrequire \"rails/test_unit/railtie\"\n\nBundler.require :default, DEVISE_ORM\n\nbegin\n  require \"#{DEVISE_ORM}/railtie\"\nrescue LoadError\nend\n\nrequire \"devise\"\n\nmodule RailsApp\n  class Application < Rails::Application\n    # Add additional load paths for your own custom dirs\n    config.autoload_paths.reject!{ |p| p =~ /\\/app\\/(\\w+)$/ && !%w(controllers helpers mailers views).include?($1) }\n    config.autoload_paths += [\"#{config.root}/app/#{DEVISE_ORM}\"]\n\n    # Configure generators values. Many other options are available, be sure to check the documentation.\n    # config.generators do |g|\n    #   g.orm             :active_record\n    #   g.template_engine :erb\n    #   g.test_framework  :test_unit, fixture: true\n    # end\n\n    # Configure sensitive parameters which will be filtered from the log file.\n    config.filter_parameters << :password\n    # config.assets.enabled = false\n\n    config.action_mailer.default_url_options = { host: \"localhost\", port: 3000 }\n\n    # This was used to break devise in some situations\n    config.to_prepare do\n      Devise::SessionsController.layout \"application\"\n    end\n\n    if DEVISE_ORM == :active_record\n      if Devise::Test.rails70?\n        config.active_record.legacy_connection_handling = false\n      end\n    end\n\n    if Devise::Test.rails70_and_up?\n      config.active_support.cache_format_version = 7.0\n    end\n  end\nend\n"
  },
  {
    "path": "test/rails_app/config/boot.rb",
    "content": "# frozen_string_literal: true\n\nunless defined?(DEVISE_ORM)\n  DEVISE_ORM = (ENV[\"DEVISE_ORM\"] || :active_record).to_sym\nend\n\nmodule Devise\n  module Test\n    # Detection for minor differences between Rails versions in tests.\n\n    def self.rails71_and_up?\n      !rails70? && Rails::VERSION::MAJOR >= 7\n    end\n\n    def self.rails70_and_up?\n      Rails::VERSION::MAJOR >= 7\n    end\n\n    def self.rails70?\n      Rails.version.start_with? '7.0'\n    end\n  end\nend\n\n# Set up gems listed in the Gemfile.\nENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)\nrequire 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])\n"
  },
  {
    "path": "test/rails_app/config/database.yml",
    "content": "# SQLite version 3.x\n#   gem install sqlite3-ruby (not necessary on OS X Leopard)\ndevelopment:\n  adapter: sqlite3\n  database: db/development.sqlite3\n  pool: 5\n  timeout: 5000\n\n# Warning: The database defined as \"test\" will be erased and\n# re-generated from your development database when you run \"rake\".\n# Do not set this db to the same as development or production.\ntest:\n  adapter: sqlite3\n  database: \":memory:\"\n\nproduction:\n  adapter: sqlite3\n  database: \":memory:\"\n"
  },
  {
    "path": "test/rails_app/config/environment.rb",
    "content": "# frozen_string_literal: true\n\n# Load the rails application.\nrequire File.expand_path('../application', __FILE__)\n\n# Initialize the rails application.\nRailsApp::Application.initialize!\n"
  },
  {
    "path": "test/rails_app/config/environments/development.rb",
    "content": "# frozen_string_literal: true\n\nRailsApp::Application.configure do\n  # Settings specified here will take precedence over those in config/application.rb.\n\n  # In the development environment your application's code is reloaded on\n  # every request. This slows down response time but is perfect for development\n  # since you don't have to restart the web server when you make code changes.\n  config.cache_classes = false\n\n  # Do not eager load code on boot.\n  config.eager_load = false\n\n  # Show full error reports and disable caching.\n  config.consider_all_requests_local       = true\n  config.action_controller.perform_caching = false\n\n  # Don't care if the mailer can't send.\n  config.action_mailer.raise_delivery_errors = false\n\n  # Print deprecation notices to the Rails logger.\n  config.active_support.deprecation = :log\n\n  # Only use best-standards-support built into browsers.\n  config.action_dispatch.best_standards_support = :builtin\n\n  # Raise an error on page load if there are pending migrations\n  config.active_record.migration_error = :page_load\n\n  # Debug mode disables concatenation and preprocessing of assets.\n  config.assets.debug = true\nend\n"
  },
  {
    "path": "test/rails_app/config/environments/production.rb",
    "content": "# frozen_string_literal: true\n\nRailsApp::Application.configure do\n  # Settings specified here will take precedence over those in config/application.rb.\n\n  # Code is not reloaded between requests.\n  config.cache_classes = true\n\n  # Eager load code on boot. This eager loads most of Rails and\n  # your application in memory, allowing both thread web servers\n  # and those relying on copy on write to perform better.\n  # Rake tasks automatically ignore this option for performance.\n  config.eager_load = true\n\n  # Full error reports are disabled and caching is turned on.\n  config.consider_all_requests_local       = false\n  config.action_controller.perform_caching = true\n\n  # Enable Rack::Cache to put a simple HTTP cache in front of your application\n  # Add `rack-cache` to your Gemfile before enabling this.\n  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.\n  # config.action_dispatch.rack_cache = true\n\n  # Disable Rails's static asset server (Apache or nginx will already do this).\n  config.public_file_server.enabled = false\n\n  # Compress JavaScripts and CSS.\n  config.assets.js_compressor  = :uglifier\n  # config.assets.css_compressor = :sass\n\n  # Whether to fallback to assets pipeline if a precompiled asset is missed.\n  config.assets.compile = false\n\n  # Generate digests for assets URLs.\n  config.assets.digest = true\n\n  # Version of your assets, change this if you want to expire all your assets.\n  config.assets.version = '1.0'\n\n  # Specifies the header that your server uses for sending files.\n  # config.action_dispatch.x_sendfile_header = \"X-Sendfile\" # for apache\n  # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx\n\n  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.\n  # config.force_ssl = true\n\n  # Set to :debug to see everything in the log.\n  config.log_level = :info\n\n  # Prepend all log lines with the following tags.\n  # config.log_tags = [:subdomain, :uuid]\n\n  # Use a different logger for distributed setups.\n  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)\n\n  # Use a different cache store in production.\n  # config.cache_store = :mem_cache_store\n\n  # Enable serving of images, stylesheets, and JavaScripts from an asset server.\n  # config.action_controller.asset_host = \"http://assets.example.com\"\n\n  # Precompile additional assets.\n  # application.js, application.css, and all non-JS/CSS in app/assets folder are already added.\n  # config.assets.precompile += %w( search.js )\n\n  # Ignore bad email addresses and do not raise email delivery errors.\n  # Set this to true and configure the email server for immediate delivery to raise delivery errors.\n  # config.action_mailer.raise_delivery_errors = false\n\n  # Enable locale fallbacks for I18n (makes lookups for any locale fall back to\n  # the I18n.default_locale when a translation can not be found).\n  config.i18n.fallbacks = true\n\n  # Send deprecation notices to registered listeners.\n  config.active_support.deprecation = :notify\n\n  # Disable automatic flushing of the log to improve performance.\n  # config.autoflush_log = false\n\n  # Use default logging formatter so that PID and timestamp are not suppressed.\n  config.log_formatter = ::Logger::Formatter.new\nend\n"
  },
  {
    "path": "test/rails_app/config/environments/test.rb",
    "content": "# frozen_string_literal: true\n\nRailsApp::Application.configure do\n  # Settings specified here will take precedence over those in config/application.rb.\n\n  # The test environment is used exclusively to run your application's\n  # test suite. You never need to work with it otherwise. Remember that\n  # your test database is \"scratch space\" for the test suite and is wiped\n  # and recreated between test runs. Don't rely on the data there!\n  config.cache_classes = true\n\n  # Do not eager load code on boot. This avoids loading your whole application\n  # just for the purpose of running a single test. If you are using a tool that\n  # preloads Rails for running tests, you may have to set it to true.\n  config.eager_load = false\n\n  # Disable serving static files from the `/public` folder by default since\n  # Apache or NGINX already handles this.\n  config.public_file_server.enabled = true\n  config.public_file_server.headers = {'Cache-Control' => 'public, max-age=3600'}\n\n  # Show full error reports and disable caching.\n  config.consider_all_requests_local       = true\n  config.action_controller.perform_caching = false\n\n  # Raise exceptions instead of rendering exception templates.\n  if Devise::Test.rails71_and_up?\n    config.action_dispatch.show_exceptions = :none\n  else\n    config.action_dispatch.show_exceptions = false\n  end\n\n  # Disable request forgery protection in test environment.\n  config.action_controller.allow_forgery_protection = false\n\n  # Tell Action Mailer not to deliver emails to the real world.\n  # The :test delivery method accumulates sent emails in the\n  # ActionMailer::Base.deliveries array.\n  config.action_mailer.delivery_method = :test\n\n  # Print deprecation notices to the stderr.\n  config.active_support.deprecation = :stderr\nend\n"
  },
  {
    "path": "test/rails_app/config/initializers/backtrace_silencers.rb",
    "content": "# frozen_string_literal: true\n\n# Be sure to restart your server when you modify this file.\n\n# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces.\n# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ }\n\n# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code.\nRails.backtrace_cleaner.remove_silencers!\n"
  },
  {
    "path": "test/rails_app/config/initializers/devise.rb",
    "content": "# frozen_string_literal: true\n\nrequire \"omniauth-facebook\"\nrequire \"omniauth-openid\"\n\n# Assuming you have not yet modified this file, each configuration option below\n# is set to its default value. Note that some are commented out while others\n# are not: uncommented lines are intended to protect your configuration from\n# breaking changes in upgrades (i.e., in the event that future versions of\n# Devise change the default values for those options).\n#\n# Use this hook to configure devise mailer, warden hooks and so forth. The first\n# four configuration values can also be set straight in your models.\nDevise.setup do |config|\n  config.secret_key = \"d9eb5171c59a4c817f68b0de27b8c1e340c2341b52cdbc60d3083d4e8958532\" \\\n                      \"18dcc5f589cafde048faec956b61f864b9b5513ff9ce29bf9e5d58b0f234f8e3b\"\n\n  # ==> Mailer Configuration\n  # Configure the e-mail address which will be shown in Devise::Mailer,\n  # note that it will be overwritten if you use your own mailer class with default \"from\" parameter.\n  config.mailer_sender = \"please-change-me@config-initializers-devise.com\"\n\n\n  config.parent_controller = \"ApplicationWithFakeEngine\"\n  # Configure the class responsible to send e-mails.\n  # config.mailer = \"Devise::Mailer\"\n\n  # ==> ORM configuration\n  # Load and configure the ORM. Supports :active_record (default) and\n  # :mongoid (bson_ext recommended) by default. Other ORMs may be\n  # available as additional gems.\n  require \"devise/orm/#{DEVISE_ORM}\"\n\n  # ==> Configuration for any authentication mechanism\n  # Configure which keys are used when authenticating a user. By default is\n  # just :email. You can configure it to use [:username, :subdomain], so for\n  # authenticating a user, both parameters are required. Remember that those\n  # parameters are used only when authenticating and not when retrieving from\n  # session. If you need permissions, you should implement that in a before filter.\n  # You can also supply hash where the value is a boolean expliciting if authentication\n  # should be aborted or not if the value is not present. By default is empty.\n  # config.authentication_keys = [:email]\n\n  # Configure parameters from the request object used for authentication. Each entry\n  # given should be a request method and it will automatically be passed to\n  # find_for_authentication method and considered in your model lookup. For instance,\n  # if you set :request_keys to [:subdomain], :subdomain will be used on authentication.\n  # The same considerations mentioned for authentication_keys also apply to request_keys.\n  # config.request_keys = []\n\n  # Configure which authentication keys should be case-insensitive.\n  # These keys will be downcased upon creating or modifying a user and when used\n  # to authenticate or find a user. Default is :email.\n  config.case_insensitive_keys = [:email]\n\n  # Configure which authentication keys should have whitespace stripped.\n  # These keys will have whitespace before and after removed upon creating or\n  # modifying a user and when used to authenticate or find a user. Default is :email.\n  config.strip_whitespace_keys = [:email]\n\n  # Tell if authentication through request.params is enabled. True by default.\n  # config.params_authenticatable = true\n\n  # Tell if authentication through HTTP Basic Auth is enabled. False by default.\n  config.http_authenticatable = true\n\n  # If http headers should be returned for AJAX requests. True by default.\n  # config.http_authenticatable_on_xhr = true\n\n  # The realm used in Http Basic Authentication. \"Application\" by default.\n  # config.http_authentication_realm = \"Application\"\n\n  # ==> Configuration for :database_authenticatable\n  # For bcrypt, this is the cost for hashing the password and defaults to 10. If\n  # using other encryptors, it sets how many times you want the password re-encrypted.\n  config.stretches = Rails.env.test? ? 1 : 10\n\n  # ==> Configuration for :confirmable\n  # The time you want to give your user to confirm their account. During this time\n  # they will be able to access your application without confirming. Default is nil.\n  # When allow_unconfirmed_access_for is zero, the user won't be able to sign in without confirming.\n  # You can use this to let your user access some features of your application\n  # without confirming the account, but blocking it after a certain period\n  # (ie 2 days).\n  # config.allow_unconfirmed_access_for = 2.days\n\n  # Defines which key will be used when confirming an account\n  # config.confirmation_keys = [:email]\n\n  # ==> Configuration for :rememberable\n  # The time the user will be remembered without asking for credentials again.\n  # config.remember_for = 2.weeks\n\n  # If true, extends the user's remember period when remembered via cookie.\n  # config.extend_remember_period = false\n\n  # ==> Configuration for :validatable\n  # Range for password length. Default is 8..72.\n  # config.password_length = 8..72\n\n  # Regex to use to validate the email address\n  # config.email_regexp = /^([\\w\\.%\\+\\-]+)@([\\w\\-]+\\.)+([\\w]{2,})$/i\n\n  # ==> Configuration for :timeoutable\n  # The time you want to timeout the user session without activity. After this\n  # time the user will be asked for credentials again. Default is 30 minutes.\n  # config.timeout_in = 30.minutes\n\n  # ==> Configuration for :lockable\n  # Defines which strategy will be used to lock an account.\n  # :failed_attempts = Locks an account after a number of failed attempts to sign in.\n  # :none            = No lock strategy. You should handle locking by yourself.\n  # config.lock_strategy = :failed_attempts\n\n  # Defines which key will be used when locking and unlocking an account\n  # config.unlock_keys = [:email]\n\n  # Defines which strategy will be used to unlock an account.\n  # :email = Sends an unlock link to the user email\n  # :time  = Re-enables login after a certain amount of time (see :unlock_in below)\n  # :both  = Enables both strategies\n  # :none  = No unlock strategy. You should handle unlocking by yourself.\n  # config.unlock_strategy = :both\n\n  # Number of authentication tries before locking an account if lock_strategy\n  # is failed attempts.\n  # config.maximum_attempts = 20\n\n  # Time interval to unlock the account if :time is enabled as unlock_strategy.\n  # config.unlock_in = 1.hour\n\n  # ==> Configuration for :recoverable\n  #\n  # Defines which key will be used when recovering the password for an account\n  # config.reset_password_keys = [:email]\n\n  # Time interval you can reset your password with a reset password key.\n  # Don't put a too small interval or your users won't have the time to\n  # change their passwords.\n  config.reset_password_within = 2.hours\n\n  # When set to false, does not sign a user in automatically after their password is\n  # reset. Defaults to true, so a user is signed in automatically after a reset.\n  # config.sign_in_after_reset_password = true\n\n  # Set up a pepper to generate the encrypted password.\n  config.pepper = \"d142367154e5beacca404b1a6a4f8bc52c6fdcfa3ccc3cf8eb49f3458a688ee6ac3b9fae488432a3bfca863b8a90008368a9f3a3dfbe5a962e64b6ab8f3a3a1a\"\n\n  # ==> Scopes configuration\n  # Turn scoped views on. Before rendering \"sessions/new\", it will first check for\n  # \"users/sessions/new\". It's turned off by default because it's slower if you\n  # are using only default views.\n  # config.scoped_views = false\n\n  # Configure the default scope given to Warden. By default it's the first\n  # devise role declared in your routes (usually :user).\n  # config.default_scope = :user\n\n  # Configure sign_out behavior.\n  # Sign_out action can be scoped (i.e. /users/sign_out affects only :user scope).\n  # The default is true, which means any logout action will sign out all active scopes.\n  # config.sign_out_all_scopes = true\n\n  # ==> Navigation configuration\n  # Lists the formats that should be treated as navigational. Formats like\n  # :html, should redirect to the sign in page when the user does not have\n  # access, but formats like :xml or :json, should return 401.\n  # If you have any extra navigational formats, like :iphone or :mobile, you\n  # should add them to the navigational formats lists. Default is [:html]\n  # config.navigational_formats = [:html, :iphone]\n\n  # The default HTTP method used to sign out a resource. Default is :get.\n  # config.sign_out_via = :get\n\n  # ==> OmniAuth\n  config.omniauth :facebook, 'APP_ID', 'APP_SECRET', scope: 'email,offline_access'\n  config.omniauth :openid\n  config.omniauth :openid, name: 'google', identifier: 'https://www.google.com/accounts/o8/id'\n\n  # ==> Warden configuration\n  # If you want to use other strategies, that are not supported by Devise, or\n  # change the failure app, you can configure them inside the config.warden block.\n  #\n  # config.warden do |warden_config|\n  #   warden_config.failure_app = AnotherApp\n  #   warden_config.default_strategies(scope: :user).unshift :some_external_strategy\n  # end\n\n  # ==> Configuration for :registerable\n\n  # When set to false, does not sign a user in automatically after their password is\n  # changed. Defaults to true, so a user is signed in automatically after changing a password.\n  # config.sign_in_after_change_password = true\n\n  ActiveSupport.on_load(:devise_failure_app) do\n    require \"lazy_load_test_module\"\n    include LazyLoadTestModule\n  end\nend\n"
  },
  {
    "path": "test/rails_app/config/initializers/inflections.rb",
    "content": "# frozen_string_literal: true\n\nActiveSupport::Inflector.inflections do |inflect|\nend\n"
  },
  {
    "path": "test/rails_app/config/initializers/secret_token.rb",
    "content": "# frozen_string_literal: true\n\nconfig = Rails.application.config\n\nconfig.secret_key_base = 'd588e99efff13a86461fd6ab82327823ad2f8feb5dc217ce652cdd9f0dfc5eb4b5a62a92d24d2574d7d51dfb1ea8dd453ea54e00cf672159a13104a135422a10'\n"
  },
  {
    "path": "test/rails_app/config/initializers/session_store.rb",
    "content": "# frozen_string_literal: true\n\nRailsApp::Application.config.session_store :cookie_store, key: '_rails_app_session'\n"
  },
  {
    "path": "test/rails_app/config/routes.rb",
    "content": "# frozen_string_literal: true\n\nRails.application.routes.draw do\n  # Resources for testing\n  resources :users, only: [:index] do\n    member do\n      get :expire\n      get :accept\n      get :edit_form\n      put :update_form\n    end\n\n    authenticate do\n      post :exhibit, on: :member\n    end\n  end\n\n  resources :admins, only: [:index]\n\n  resources :streaming, only: [:index]\n\n  # Users scope\n  devise_for :users, controllers: { omniauth_callbacks: \"users/omniauth_callbacks\" }\n\n  devise_for :user_on_main_apps,\n    class_name: 'UserOnMainApp',\n    router_name: :main_app,\n    module: :devise\n\n  devise_for :user_on_engines,\n    class_name: 'UserOnEngine',\n    router_name: :fake_engine,\n    module: :devise\n\n  devise_for :user_without_email,\n    class_name: 'UserWithoutEmail',\n    router_name: :main_app,\n    module: :devise\n\n  as :user do\n    get \"/as/sign_in\", to: \"devise/sessions#new\"\n  end\n\n  get \"/sign_in\", to: \"devise/sessions#new\"\n\n  # Routes for custom controller testing\n  devise_for :user, only: [:registrations], controllers: { registrations: \"custom/registrations\" }, as: :custom, path: :custom\n\n  # Admin scope\n  devise_for :admin, path: \"admin_area\", controllers: { sessions: :\"admins/sessions\" }, skip: :passwords\n\n  get \"/admin_area/home\", to: \"admins#index\", as: :admin_root\n  get \"/anywhere\", to: \"foo#bar\", as: :new_admin_password\n\n  authenticate(:admin) do\n    get \"/private\", to: \"home#private\", as: :private\n  end\n\n  authenticate(:admin, lambda { |admin| admin.active? }) do\n    get \"/private/active\", to: \"home#private\", as: :private_active\n  end\n\n  authenticated :admin do\n    get \"/dashboard\", to: \"home#admin_dashboard\"\n  end\n\n  authenticated :admin, lambda { |admin| admin.active? } do\n    get \"/dashboard/active\", to: \"home#admin_dashboard\"\n  end\n\n  authenticated do\n    get \"/dashboard\", to: \"home#user_dashboard\"\n  end\n\n  unauthenticated do\n    get \"/join\", to: \"home#join\"\n  end\n\n  # Routes for constraints testing\n  devise_for :headquarters_admin, class_name: \"Admin\", path: \"headquarters\", constraints: {host: /192\\.168\\.1\\.\\d\\d\\d/}\n\n  constraints(host: /192\\.168\\.1\\.\\d\\d\\d/) do\n    devise_for :homebase_admin, class_name: \"Admin\", path: \"homebase\"\n  end\n\n  scope(subdomain: 'sub') do\n    devise_for :subdomain_users, class_name: \"User\", only: [:sessions]\n  end\n\n  devise_for :skip_admin, class_name: \"Admin\", skip: :all\n\n  # Routes for format=false testing\n  devise_for :htmlonly_admin, class_name: \"Admin\", skip: [:confirmations, :unlocks], path: \"htmlonly_admin\", format: false, skip_helpers: [:confirmations, :unlocks]\n  devise_for :htmlonly_users, class_name: \"User\", only: [:confirmations, :unlocks], path: \"htmlonly_users\", format: false, skip_helpers: true\n\n  # Other routes for routing_test.rb\n  devise_for :reader, class_name: \"User\", only: :passwords\n\n  scope host: \"sub.example.com\" do\n    devise_for :sub_admin, class_name: \"Admin\"\n  end\n\n  namespace :publisher, path_names: { sign_in: \"i_dont_care\", sign_out: \"get_out\" } do\n    devise_for :accounts, class_name: \"Admin\", path_names: { sign_in: \"get_in\" }\n  end\n\n  scope \":locale\", module: :invalid do\n    devise_for :accounts, singular: \"manager\", class_name: \"Admin\",\n      path_names: {\n        sign_in: \"login\", sign_out: \"logout\",\n        password: \"secret\", confirmation: \"verification\",\n        unlock: \"unblock\", sign_up: \"register\",\n        registration: \"management\",\n        cancel: \"giveup\", edit: \"edit/profile\"\n      }, failure_app: lambda { |env| [404, {\"Content-Type\" => \"text/plain\"}, [\"Oops, not found\"]] }, module: :devise\n  end\n\n  namespace :sign_out_via, module: \"devise\" do\n    devise_for :deletes, sign_out_via: :delete, class_name: \"Admin\"\n    devise_for :posts, sign_out_via: :post, class_name: \"Admin\"\n    devise_for :gets, sign_out_via: :get, class_name: \"Admin\"\n    devise_for :delete_or_posts, sign_out_via: [:delete, :post], class_name: \"Admin\"\n  end\n\n  get \"/set\", to: \"home#set\"\n  get \"/unauthenticated\", to: \"home#unauthenticated\"\n  get \"/custom_strategy/new\"\n\n  root to: \"home#index\", via: [:get, :post]\nend\n"
  },
  {
    "path": "test/rails_app/config.ru",
    "content": "# This file is used by Rack-based servers to start the application.\n\nrequire ::File.expand_path('../config/environment',  __FILE__)\nrun RailsApp::Application\n"
  },
  {
    "path": "test/rails_app/db/migrate/20100401102949_create_tables.rb",
    "content": "# frozen_string_literal: true\n\nclass CreateTables < ActiveRecord::Migration[5.0]\n  def self.up\n    create_table :users do |t|\n      t.string :username\n      t.string :facebook_token\n\n      ## Database authenticatable\n      t.string :email,              null: false, default: \"\"\n      t.string :encrypted_password, null: false, default: \"\"\n\n      ## Recoverable\n      t.string   :reset_password_token\n      t.datetime :reset_password_sent_at\n\n      ## Rememberable\n      t.datetime :remember_created_at\n\n      ## Trackable\n      t.integer  :sign_in_count, default: 0\n      t.datetime :current_sign_in_at\n      t.datetime :last_sign_in_at\n      t.string   :current_sign_in_ip\n      t.string   :last_sign_in_ip\n\n      ## Confirmable\n      t.string   :confirmation_token\n      t.datetime :confirmed_at\n      t.datetime :confirmation_sent_at\n      # t.string   :unconfirmed_email # Only if using reconfirmable\n\n      ## Lockable\n      t.integer  :failed_attempts, default: 0 # Only if lock strategy is :failed_attempts\n      t.string   :unlock_token # Only if unlock strategy is :email or :both\n      t.datetime :locked_at\n\n      t.timestamps null: false\n    end\n\n    create_table :admins do |t|\n      ## Database authenticatable\n      t.string :email,              null: true\n      t.string :encrypted_password, null: true\n\n      ## Recoverable\n      t.string   :reset_password_token\n      t.datetime :reset_password_sent_at\n\n      ## Rememberable\n      t.datetime :remember_created_at\n\n      ## Confirmable\n      t.string   :confirmation_token\n      t.datetime :confirmed_at\n      t.datetime :confirmation_sent_at\n      t.string   :unconfirmed_email # Only if using reconfirmable\n\n      ## Lockable\n      t.datetime :locked_at\n\n      ## Attribute for testing route blocks\n      t.boolean :active, default: false\n\n      t.timestamps null: false\n    end\n  end\n\n  def self.down\n    drop_table :users\n    drop_table :admins\n  end\nend\n"
  },
  {
    "path": "test/rails_app/db/schema.rb",
    "content": "# encoding: UTF-8\n# frozen_string_literal: true\n\n# This file is auto-generated from the current state of the database. Instead\n# of editing this file, please use the migrations feature of Active Record to\n# incrementally modify your database, and then regenerate this schema definition.\n#\n# Note that this schema.rb definition is the authoritative source for your\n# database schema. If you need to create the application database on another\n# system, you should be using db:schema:load, not running all the migrations\n# from scratch. The latter is a flawed and unsustainable approach (the more migrations\n# you'll amass, the slower it'll run and the greater likelihood for issues).\n#\n# It's strongly recommended that you check this file into your version control system.\n\nActiveRecord::Schema.define(version: 20100401102949) do\n\n  create_table \"admins\", force: true do |t|\n    t.string   \"email\"\n    t.string   \"encrypted_password\"\n    t.string   \"reset_password_token\"\n    t.datetime \"reset_password_sent_at\"\n    t.datetime \"remember_created_at\"\n    t.string   \"confirmation_token\"\n    t.datetime \"confirmed_at\"\n    t.datetime \"confirmation_sent_at\"\n    t.string   \"unconfirmed_email\"\n    t.datetime \"locked_at\"\n    t.boolean  \"active\",                 default: false\n    t.datetime \"created_at\"\n    t.datetime \"updated_at\"\n  end\n\n  create_table \"users\", force: true do |t|\n    t.string   \"username\"\n    t.string   \"facebook_token\"\n    t.string   \"email\",                  default: \"\", null: false\n    t.string   \"encrypted_password\",     default: \"\", null: false\n    t.string   \"reset_password_token\"\n    t.datetime \"reset_password_sent_at\"\n    t.datetime \"remember_created_at\"\n    t.integer  \"sign_in_count\",          default: 0\n    t.datetime \"current_sign_in_at\"\n    t.datetime \"last_sign_in_at\"\n    t.string   \"current_sign_in_ip\"\n    t.string   \"last_sign_in_ip\"\n    t.string   \"confirmation_token\"\n    t.datetime \"confirmed_at\"\n    t.datetime \"confirmation_sent_at\"\n    t.integer  \"failed_attempts\",        default: 0\n    t.string   \"unlock_token\"\n    t.datetime \"locked_at\"\n    t.datetime \"created_at\"\n    t.datetime \"updated_at\"\n  end\n\nend\n"
  },
  {
    "path": "test/rails_app/lib/lazy_load_test_module.rb",
    "content": "module LazyLoadTestModule\n  def lazy_loading_works?\n    \"yes it does\"\n  end\nend"
  },
  {
    "path": "test/rails_app/lib/shared_admin.rb",
    "content": "# frozen_string_literal: true\n\nmodule SharedAdmin\n  extend ActiveSupport::Concern\n\n  included do\n    devise :database_authenticatable, :registerable,\n           :timeoutable, :recoverable, :lockable, :confirmable,\n           unlock_strategy: :time, lock_strategy: :none,\n           allow_unconfirmed_access_for: 2.weeks, reconfirmable: true\n\n    validates_length_of     :reset_password_token, minimum: 3, allow_blank: true\n    validates_uniqueness_of :email, allow_blank: true, if: :devise_will_save_change_to_email?\n  end\n\n  def raw_confirmation_token\n    @raw_confirmation_token\n  end\nend\n"
  },
  {
    "path": "test/rails_app/lib/shared_user.rb",
    "content": "# frozen_string_literal: true\n\nmodule SharedUser\n  extend ActiveSupport::Concern\n\n  included do\n    devise :database_authenticatable, :confirmable, :lockable, :recoverable,\n           :registerable, :rememberable, :timeoutable,\n           :trackable, :validatable, :omniauthable, password_length: 7..72,\n           reconfirmable: false\n\n    attr_accessor :other_key\n\n    # They need to be included after Devise is called.\n    extend ExtendMethods\n  end\n\n  def raw_confirmation_token\n    @raw_confirmation_token\n  end\n\n  module ExtendMethods\n    def new_with_session(params, session)\n      super.tap do |user|\n        if data = session[\"devise.facebook_data\"]\n          user.email = data[\"email\"]\n          user.confirmed_at = Time.now\n        end\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "test/rails_app/lib/shared_user_without_email.rb",
    "content": "# frozen_string_literal: true\n\nmodule SharedUserWithoutEmail\n  extend ActiveSupport::Concern\n\n  included do\n    # NOTE: This is missing :validatable and :confirmable, as they both require\n    # an email field at the moment. It is also missing :omniauthable because that\n    # adds unnecessary complexity to the setup\n    devise :database_authenticatable, :lockable, :recoverable,\n           :registerable, :rememberable, :timeoutable,\n           :trackable\n  end\n\n  # This test stub is a bit rubbish because it's tied very closely to the\n  # implementation where we care about this one case. However, completely\n  # removing the email field breaks \"recoverable\" tests completely, so we are\n  # just taking the approach here that \"email\" is something that is a not an\n  # ActiveRecord field.\n  def email_changed?\n    raise NoMethodError\n  end\n\n  def respond_to?(method_name, include_all = false)\n    return false if method_name.to_sym == :email_changed?\n    super(method_name, include_all)\n  end\nend\n"
  },
  {
    "path": "test/rails_app/lib/shared_user_without_omniauth.rb",
    "content": "# frozen_string_literal: true\n\nmodule SharedUserWithoutOmniauth\n  extend ActiveSupport::Concern\n\n  included do\n    devise :database_authenticatable, :confirmable, :lockable, :recoverable,\n      :registerable, :rememberable, :timeoutable,\n      :trackable, :validatable, reconfirmable: false\n  end\n\n  def raw_confirmation_token\n    @raw_confirmation_token\n  end\nend\n"
  },
  {
    "path": "test/rails_app/public/404.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>The page you were looking for doesn't exist (404)</title>\n  <style type=\"text/css\">\n    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }\n    div.dialog {\n      width: 25em;\n      padding: 0 4em;\n      margin: 4em auto 0 auto;\n      border: 1px solid #ccc;\n      border-right-color: #999;\n      border-bottom-color: #999;\n    }\n    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }\n  </style>\n</head>\n\n<body>\n  <!-- This file lives in public/404.html -->\n  <div class=\"dialog\">\n    <h1>The page you were looking for doesn't exist.</h1>\n    <p>You may have mistyped the address or the page may have moved.</p>\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "test/rails_app/public/422.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>The change you wanted was rejected (422)</title>\n  <style type=\"text/css\">\n    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }\n    div.dialog {\n      width: 25em;\n      padding: 0 4em;\n      margin: 4em auto 0 auto;\n      border: 1px solid #ccc;\n      border-right-color: #999;\n      border-bottom-color: #999;\n    }\n    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }\n  </style>\n</head>\n\n<body>\n  <!-- This file lives in public/422.html -->\n  <div class=\"dialog\">\n    <h1>The change you wanted was rejected.</h1>\n    <p>Maybe you tried to change something you didn't have access to.</p>\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "test/rails_app/public/500.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>We're sorry, but something went wrong (500)</title>\n  <style type=\"text/css\">\n    body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }\n    div.dialog {\n      width: 25em;\n      padding: 0 4em;\n      margin: 4em auto 0 auto;\n      border: 1px solid #ccc;\n      border-right-color: #999;\n      border-bottom-color: #999;\n    }\n    h1 { font-size: 100%; color: #f00; line-height: 1.5em; }\n  </style>\n</head>\n\n<body>\n  <!-- This file lives in public/500.html -->\n  <div class=\"dialog\">\n    <h1>We're sorry, but something went wrong.</h1>\n    <p>We've been notified about this issue and we'll take a look at it shortly.</p>\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "test/rails_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass RailsTest < ActiveSupport::TestCase\n  test 'correct initializer position' do\n    initializer = Devise::Engine.initializers.detect { |i| i.name == 'devise.omniauth' }\n    assert_equal :load_config_initializers, initializer.after\n    assert_equal :build_middleware_stack, initializer.before\n  end\n\n  if Devise::Test.rails71_and_up?\n    test 'deprecator is added to application deprecators' do\n      assert_not_nil Rails.application.deprecators[:devise]\n    end\n  end\nend\n"
  },
  {
    "path": "test/routes_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nExpectedRoutingError = Minitest::Assertion\n\nclass DefaultRoutingTest < ActionController::TestCase\n  test 'map new user session' do\n    assert_recognizes({controller: 'devise/sessions', action: 'new'}, {path: 'users/sign_in', method: :get})\n    assert_named_route \"/users/sign_in\", :new_user_session_path\n  end\n\n  test 'map create user session' do\n    assert_recognizes({controller: 'devise/sessions', action: 'create'}, {path: 'users/sign_in', method: :post})\n    assert_named_route \"/users/sign_in\", :user_session_path\n  end\n\n  test 'map destroy user session' do\n    assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: 'users/sign_out', method: :delete})\n    assert_named_route \"/users/sign_out\", :destroy_user_session_path\n  end\n\n  test 'map new user confirmation' do\n    assert_recognizes({controller: 'devise/confirmations', action: 'new'}, 'users/confirmation/new')\n    assert_named_route \"/users/confirmation/new\", :new_user_confirmation_path\n  end\n\n  test 'map create user confirmation' do\n    assert_recognizes({controller: 'devise/confirmations', action: 'create'}, {path: 'users/confirmation', method: :post})\n    assert_named_route \"/users/confirmation\", :user_confirmation_path\n  end\n\n  test 'map show user confirmation' do\n    assert_recognizes({controller: 'devise/confirmations', action: 'show'}, {path: 'users/confirmation', method: :get})\n  end\n\n  test 'map new user password' do\n    assert_recognizes({controller: 'devise/passwords', action: 'new'}, 'users/password/new')\n    assert_named_route \"/users/password/new\", :new_user_password_path\n  end\n\n  test 'map create user password' do\n    assert_recognizes({controller: 'devise/passwords', action: 'create'}, {path: 'users/password', method: :post})\n    assert_named_route \"/users/password\", :user_password_path\n  end\n\n  test 'map edit user password' do\n    assert_recognizes({controller: 'devise/passwords', action: 'edit'}, 'users/password/edit')\n    assert_named_route \"/users/password/edit\", :edit_user_password_path\n  end\n\n  test 'map update user password' do\n    assert_recognizes({controller: 'devise/passwords', action: 'update'}, {path: 'users/password', method: :put})\n  end\n\n  test 'map new user unlock' do\n    assert_recognizes({controller: 'devise/unlocks', action: 'new'}, 'users/unlock/new')\n    assert_named_route \"/users/unlock/new\", :new_user_unlock_path\n  end\n\n  test 'map create user unlock' do\n    assert_recognizes({controller: 'devise/unlocks', action: 'create'}, {path: 'users/unlock', method: :post})\n    assert_named_route \"/users/unlock\", :user_unlock_path\n  end\n\n  test 'map show user unlock' do\n    assert_recognizes({controller: 'devise/unlocks', action: 'show'}, {path: 'users/unlock', method: :get})\n  end\n\n  test 'map new user registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'new'}, 'users/sign_up')\n    assert_named_route \"/users/sign_up\", :new_user_registration_path\n  end\n\n  test 'map create user registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'create'}, {path: 'users', method: :post})\n    assert_named_route \"/users\", :user_registration_path\n  end\n\n  test 'map edit user registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'edit'}, {path: 'users/edit', method: :get})\n    assert_named_route \"/users/edit\", :edit_user_registration_path\n  end\n\n  test 'map update user registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'update'}, {path: 'users', method: :put})\n  end\n\n  test 'map destroy user registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'destroy'}, {path: 'users', method: :delete})\n  end\n\n  test 'map cancel user registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'cancel'}, {path: 'users/cancel', method: :get})\n    assert_named_route \"/users/cancel\", :cancel_user_registration_path\n  end\n\n  test 'map omniauth callbacks' do\n    assert_recognizes({controller: 'users/omniauth_callbacks', action: 'facebook'}, {path: 'users/auth/facebook/callback', method: :get})\n    assert_recognizes({controller: 'users/omniauth_callbacks', action: 'facebook'}, {path: 'users/auth/facebook/callback', method: :post})\n    assert_named_route \"/users/auth/facebook/callback\", :user_facebook_omniauth_callback_path\n\n    # named open_id\n    assert_recognizes({controller: 'users/omniauth_callbacks', action: 'google'}, {path: 'users/auth/google/callback', method: :get})\n    assert_recognizes({controller: 'users/omniauth_callbacks', action: 'google'}, {path: 'users/auth/google/callback', method: :post})\n    assert_named_route \"/users/auth/google/callback\", :user_google_omniauth_callback_path\n\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'ysers/omniauth_callbacks', action: 'twitter'}, {path: 'users/auth/twitter/callback', method: :get})\n    end\n  end\n\n  protected\n\n  def assert_named_route(result, *args)\n    assert_equal result, @routes.url_helpers.send(*args)\n  end\nend\n\nclass CustomizedRoutingTest < ActionController::TestCase\n  test 'map admin with :path option' do\n    assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'admin_area/sign_up', method: :get})\n  end\n\n  test 'map admin with :controllers option' do\n    assert_recognizes({controller: 'admins/sessions', action: 'new'}, {path: 'admin_area/sign_in', method: :get})\n  end\n\n  test 'does not map admin password' do\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'devise/passwords', action: 'new'}, 'admin_area/password/new')\n    end\n  end\n\n  test 'subdomain admin' do\n    assert_recognizes({\"host\"=>\"sub.example.com\", controller: 'devise/sessions', action: 'new'}, {host: \"sub.example.com\", path: '/sub_admin/sign_in', method: :get})\n  end\n\n  test 'does only map reader password' do\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'devise/sessions', action: 'new'}, 'reader/sessions/new')\n    end\n    assert_recognizes({controller: 'devise/passwords', action: 'new'}, 'reader/password/new')\n  end\n\n  test 'map account with custom path name for session sign in' do\n    assert_recognizes({controller: 'devise/sessions', action: 'new', locale: 'en'}, '/en/accounts/login')\n  end\n\n  test 'map account with custom path name for session sign out' do\n    assert_recognizes({controller: 'devise/sessions', action: 'destroy', locale: 'en'}, {path: '/en/accounts/logout', method: :delete })\n  end\n\n  test 'map account with custom path name for password' do\n    assert_recognizes({controller: 'devise/passwords', action: 'new', locale: 'en'}, '/en/accounts/secret/new')\n  end\n\n  test 'map account with custom path name for registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'new', locale: 'en'}, '/en/accounts/management/register')\n  end\n\n  test 'map account with custom path name for edit registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'edit', locale: 'en'}, '/en/accounts/management/edit/profile')\n  end\n\n  test 'map account with custom path name for cancel registration' do\n    assert_recognizes({controller: 'devise/registrations', action: 'cancel', locale: 'en'}, '/en/accounts/management/giveup')\n  end\n\n  test 'map deletes with :sign_out_via option' do\n    assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/deletes/sign_out', method: :delete})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/deletes/sign_out', method: :get})\n    end\n  end\n\n  test 'map posts with :sign_out_via option' do\n    assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/posts/sign_out', method: :post})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/posts/sign_out', method: :get})\n    end\n  end\n\n  test 'map delete_or_posts with :sign_out_via option' do\n    assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/delete_or_posts/sign_out', method: :post})\n    assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/delete_or_posts/sign_out', method: :delete})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'devise/sessions', action: 'destroy'}, {path: '/sign_out_via/delete_or_posts/sign_out', method: :get})\n    end\n  end\n\n  test 'map with constraints defined in hash' do\n    assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://192.168.1.100/headquarters/sign_up', method: :get})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://10.0.0.100/headquarters/sign_up', method: :get})\n    end\n  end\n\n  test 'map with constraints defined in block' do\n    assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://192.168.1.100/homebase/sign_up', method: :get})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes({controller: 'devise/registrations', action: 'new'}, {path: 'http://10.0.0.100//homebase/sign_up', method: :get})\n    end\n  end\n\n  test 'map with format false for sessions' do\n    expected_params = {controller: 'devise/sessions', action: 'new'}\n\n    assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_in', method: :get})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_in.json', method: :get})\n    end\n  end\n\n  test 'map with format false for passwords' do\n    expected_params = {controller: 'devise/passwords', action: 'create'}\n\n    assert_recognizes(expected_params, {path: '/htmlonly_admin/password', method: :post})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes(expected_params, {path: '/htmlonly_admin/password.json', method: :post})\n    end\n  end\n\n  test 'map with format false for registrations' do\n    expected_params = {controller: 'devise/registrations', action: 'new'}\n\n    assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_up', method: :get})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes(expected_params, {path: '/htmlonly_admin/sign_up.json', method: :get})\n    end\n  end\n\n  test 'map with format false for confirmations' do\n    expected_params = {controller: 'devise/confirmations', action: 'show'}\n\n    assert_recognizes(expected_params, {path: '/htmlonly_users/confirmation', method: :get})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes(expected_params, {path: '/htmlonly_users/confirmation.json', method: :get})\n    end\n  end\n\n  test 'map with format false for unlocks' do\n    expected_params = {controller: 'devise/unlocks', action: 'show'}\n\n    assert_recognizes(expected_params, {path: '/htmlonly_users/unlock', method: :get})\n    assert_raise ExpectedRoutingError do\n      assert_recognizes(expected_params, {path: '/htmlonly_users/unlock.json', method: :get})\n    end\n  end\n\n  test 'map with format false is not permanent' do\n    assert_equal \"/set.json\", @routes.url_helpers.set_path(:json)\n  end\n\n  test 'checks if mapping has proper configuration for omniauth callback' do\n    e = assert_raise ArgumentError do\n      routes = ActionDispatch::Routing::RouteSet.new\n      routes.draw do\n        devise_for :not_omniauthable, class_name: 'Admin', controllers: {omniauth_callbacks: \"users/omniauth_callbacks\"}\n      end\n    end\n    assert_match \"Mapping omniauth_callbacks on a resource that is not omniauthable\", e.message\n  end\nend\n\nclass ScopedRoutingTest < ActionController::TestCase\n  test 'map publisher account' do\n    assert_recognizes({controller: 'publisher/registrations', action: 'new'}, {path: '/publisher/accounts/sign_up', method: :get})\n    assert_equal '/publisher/accounts/sign_up', @routes.url_helpers.new_publisher_account_registration_path\n  end\n\n  test 'map publisher account merges path names' do\n    assert_recognizes({controller: 'publisher/sessions', action: 'new'}, {path: '/publisher/accounts/get_in', method: :get})\n    assert_equal '/publisher/accounts/get_in', @routes.url_helpers.new_publisher_account_session_path\n  end\nend\n"
  },
  {
    "path": "test/support/action_controller/record_identifier.rb",
    "content": "# frozen_string_literal: true\n\n# Since webrat uses ActionController::RecordIdentifier class that was moved to\n# ActionView namespace in Rails 4.1+\n\nunless defined?(ActionController::RecordIdentifier)\n  require 'action_view/record_identifier'\n\n  module ActionController\n    RecordIdentifier = ActionView::RecordIdentifier\n  end\nend\n"
  },
  {
    "path": "test/support/assertions.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'active_support/test_case'\n\nclass ActiveSupport::TestCase\n  def assert_blank(assertion)\n    assert assertion.blank?\n  end\n\n  def assert_present(assertion)\n    assert assertion.present?\n  end\n\n  def assert_email_sent(address = nil, &block)\n    assert_difference('ActionMailer::Base.deliveries.size', &block)\n    if address.present?\n      assert_equal address, ActionMailer::Base.deliveries.last['to'].to_s\n    end\n  end\n\n  def assert_email_not_sent(&block)\n    assert_no_difference('ActionMailer::Base.deliveries.size', &block)\n  end\n\n  def assert_raise_with_message(exception_klass, message, &block)\n    exception = assert_raise exception_klass, &block\n    assert_equal exception.message, message,\n      \"The expected message was #{message} but your exception throwed #{exception.message}\"\n  end\nend\n"
  },
  {
    "path": "test/support/helpers.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'active_support/test_case'\n\nclass ActiveSupport::TestCase\n  def setup_mailer\n    ActionMailer::Base.deliveries = []\n  end\n\n  def store_translations(locale, translations, &block)\n    # Calling 'available_locales' before storing the translations to ensure\n    # that the I18n backend will be initialized before we store our custom\n    # translations, so they will always override the translations for the\n    # YML file.\n    I18n.available_locales\n    I18n.backend.store_translations(locale, translations)\n    yield\n  ensure\n    I18n.reload!\n  end\n\n  def generate_unique_email\n    @@email_count ||= 0\n    @@email_count += 1\n    \"test#{@@email_count}@example.com\"\n  end\n\n  def valid_attributes(attributes = {})\n    { username: \"usertest\",\n      email: generate_unique_email,\n      password: '12345678',\n      password_confirmation: '12345678' }.update(attributes)\n  end\n\n  def new_user(attributes = {})\n    User.new(valid_attributes(attributes))\n  end\n\n  def create_user(attributes = {})\n    User.create!(valid_attributes(attributes))\n  end\n\n  def create_admin(attributes = {})\n    valid_attributes = valid_attributes(attributes)\n    valid_attributes.delete(:username)\n    Admin.create!(valid_attributes)\n  end\n\n  def create_user_without_email(attributes = {})\n    UserWithoutEmail.create!(valid_attributes(attributes))\n  end\n\n  def create_user_with_validations(attributes = {})\n    UserWithValidations.create!(valid_attributes(attributes))\n  end\n\n  # Execute the block setting the given values and restoring old values after\n  # the block is executed.\n  def swap(object, new_values)\n    old_values = {}\n    new_values.each do |key, value|\n      old_values[key] = object.send key\n      object.send :\"#{key}=\", value\n    end\n    clear_cached_variables(new_values)\n    yield\n  ensure\n    clear_cached_variables(new_values)\n    old_values.each do |key, value|\n      object.send :\"#{key}=\", value\n    end\n  end\n\n  def swap_model_config(model, new_values)\n    new_values.each do |key, value|\n      model.send :\"#{key}=\", value\n    end\n    yield\n  ensure\n    new_values.each_key do |key|\n      model.remove_instance_variable :\"@#{key}\"\n    end\n  end\n\n  def clear_cached_variables(options)\n    if options.key?(:case_insensitive_keys) || options.key?(:strip_whitespace_keys)\n      Devise.mappings.each do |_, mapping|\n        mapping.to.instance_variable_set(:@devise_parameter_filter, nil)\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "test/support/http_method_compatibility.rb",
    "content": "# frozen_string_literal: true\n\nmodule Devise\n  class IntegrationTest < ActionDispatch::IntegrationTest\n  end\n\n  class ControllerTestCase < ActionController::TestCase\n  end\nend\n"
  },
  {
    "path": "test/support/integration.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'action_dispatch/testing/integration'\n\nclass ActionDispatch::IntegrationTest\n  def warden\n    request.env['warden']\n  end\n\n  def create_user(options = {})\n    @user ||= begin\n      user = User.create!(\n        username: 'usertest',\n        email: options[:email] || 'user@test.com',\n        password: options[:password] || '12345678',\n        password_confirmation: options[:password] || '12345678',\n        created_at: Time.now.utc\n      )\n      user.update_attribute(:confirmation_sent_at, options[:confirmation_sent_at]) if options[:confirmation_sent_at]\n      user.confirm unless options[:confirm] == false\n      user.lock_access! if options[:locked] == true\n      User.validations_performed = false\n      user\n    end\n  end\n\n  def create_admin(options = {})\n    @admin ||= begin\n      admin = Admin.create!(\n        email: options[:email] || 'admin@test.com',\n        password: '123456', password_confirmation: '123456',\n        active: options[:active]\n      )\n      admin.confirm unless options[:confirm] == false\n      admin\n    end\n  end\n\n  def sign_in_as_user(options = {}, &block)\n    user = create_user(options)\n    visit_with_option options[:visit], new_user_session_path\n    fill_in 'email', with: options[:email] || 'user@test.com'\n    fill_in 'password', with: options[:password] || '12345678'\n    check 'remember me' if options[:remember_me] == true\n    yield if block_given?\n    click_button 'Log In'\n    user\n  end\n\n  def sign_in_as_admin(options = {}, &block)\n    admin = create_admin(options)\n    visit_with_option options[:visit], new_admin_session_path\n    fill_in 'email', with: 'admin@test.com'\n    fill_in 'password', with: '123456'\n    yield if block_given?\n    click_button 'Log In'\n    admin\n  end\n\n  # Fix assert_redirect_to in integration sessions because they don't take into\n  # account Middleware redirects.\n  #\n  def assert_redirected_to(url)\n    assert_includes [301, 302, 303], @integration_session.status,\n           \"Expected status to be 301, 302, or 303, got #{@integration_session.status}\"\n\n    assert_url url, @integration_session.headers[\"Location\"]\n  end\n\n  def assert_current_url(expected)\n    assert_url expected, current_url\n  end\n\n  def assert_url(expected, actual)\n    assert_equal prepend_host(expected), prepend_host(actual)\n  end\n\n  protected\n\n    def visit_with_option(given, default)\n      case given\n      when String\n        visit given\n      when FalseClass\n        # Do nothing\n      else\n        visit default\n      end\n    end\n\n    def prepend_host(url)\n      url = \"http://#{request.host}#{url}\" if url[0] == ?/\n      url\n    end\nend\n"
  },
  {
    "path": "test/support/locale/de.yml",
    "content": "de:\n  activerecord:\n    attributes:\n      user:\n        email: E-Mail\n  mongoid:\n    attributes:\n      user:\n        email: E-Mail\n  devise:\n    failure:\n      invalid: \"%{authentication_keys} oder Passwort ist ungültig.\"\n"
  },
  {
    "path": "test/support/locale/en.yml",
    "content": "en:\n  devise:\n    failure:\n      user:\n        does_not_exist: \"User %{name} does not exist\"\n  errors:\n    messages:\n      taken: \"has already been taken\"\n"
  },
  {
    "path": "test/support/locale/pt-BR.yml",
    "content": "pt-BR:\n  devise:\n    failure:\n      invalid: \"%{authentication_keys} ou senha inválidos.\"\n      unauthenticated: \"Para continuar, faça login ou registre-se.\"\n      timeout: \"Sua sessão expirou. Por favor faça o login novamente para continuar.\"\n      unconfirmed: \"Você precisa confirmar seu email para continuar.\"\n"
  },
  {
    "path": "test/support/mongoid.yml",
    "content": "test:\n  clients:\n    default:\n      database: devise-test-suite\n      hosts:\n        - localhost:<%= ENV['MONGODB_PORT'] || '27017' %>\n"
  },
  {
    "path": "test/support/webrat/integrations/rails.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'webrat/core/elements/form'\nrequire 'action_dispatch/testing/integration'\n\nmodule Webrat\n  Form.class_eval do\n    def self.parse_rails_request_params(params)\n      Rack::Utils.parse_nested_query(params)\n    end\n  end\n\n  module Logging\n    # Avoid RAILS_DEFAULT_LOGGER deprecation warning\n    def logger # :nodoc:\n      ::Rails.logger\n    end\n  end\n\n  class RailsAdapter\n    # This method is private within webrat gem and after Ruby 2.4 we get a lot of warnings because\n    # Webrat::Session#response is delegated to this method.\n    def response\n      integration_session.response\n    end\n\n    protected\n\n    def do_request(http_method, url, data, headers)\n      update_protocol(url)\n      integration_session.send(http_method, normalize_url(url), params: data, headers: headers)\n    end\n  end\nend\n\nmodule ActionDispatch #:nodoc:\n  IntegrationTest.class_eval do\n    include Webrat::Methods\n    include Webrat::Matchers\n  end\nend\n"
  },
  {
    "path": "test/support/webrat/matchers.rb",
    "content": "# Monkey patch for Nokogiri changes - https://github.com/sparklemotion/nokogiri/issues/2469\nmodule Webrat\n  module Matchers\n    class HaveSelector\n      def query\n        Nokogiri::CSS::Parser.new.parse(@expected.to_s).map do |ast|\n          if ::Gem::Version.new(Nokogiri::VERSION) < ::Gem::Version.new('1.17.2')\n            ast.to_xpath('//', Nokogiri::CSS::XPathVisitor.new)\n          else\n            ast.to_xpath(Nokogiri::CSS::XPathVisitor.new)\n          end\n        end.first\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "test/test/controller_helpers_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass TestControllerHelpersTest < Devise::ControllerTestCase\n  tests UsersController\n  include Devise::Test::ControllerHelpers\n\n  test \"redirects if attempting to access a page unauthenticated\" do\n    get :index\n    assert_redirected_to new_user_session_path\n    assert_equal \"You need to sign in or sign up before continuing.\", flash[:alert]\n  end\n\n  test \"redirects if attempting to access a page with an unconfirmed account\" do\n    swap Devise, allow_unconfirmed_access_for: 0.days do\n      user = create_user\n      assert_not user.active_for_authentication?\n\n      sign_in user\n      get :index\n      assert_redirected_to new_user_session_path\n    end\n  end\n\n  test \"returns nil if accessing current_user with an unconfirmed account\" do\n    swap Devise, allow_unconfirmed_access_for: 0.days do\n      user = create_user\n      assert_not user.active_for_authentication?\n\n      sign_in user\n      get :accept, params: { id: user }\n      assert_nil assigns(:current_user)\n    end\n  end\n\n  test \"does not redirect with valid user\" do\n    user = create_user\n    user.confirm\n\n    sign_in user\n    get :index\n    assert_response :success\n  end\n\n  test \"does not redirect with valid user after failed first attempt\" do\n    get :index\n    assert_response :redirect\n\n    user = create_user\n    user.confirm\n\n    sign_in user\n    get :index\n    assert_response :success\n  end\n\n  test \"redirects if valid user signed out\" do\n    user = create_user\n    user.confirm\n\n    sign_in user\n    get :index\n\n    sign_out user\n    get :index\n    assert_redirected_to new_user_session_path\n  end\n\n  test \"respects custom failure app\" do\n    custom_failure_app = Class.new(Devise::FailureApp) do\n      def redirect\n        self.status = 300\n      end\n    end\n\n    swap Devise.warden_config, failure_app: custom_failure_app do\n      get :index\n      assert_response 300\n    end\n  end\n\n  test \"passes given headers from the failure app to the response\" do\n    custom_failure_app = Class.new(Devise::FailureApp) do\n      def respond\n        self.status = 401\n        self.response.headers[\"CUSTOMHEADER\"] = 1\n      end\n    end\n\n    swap Devise.warden_config, failure_app: custom_failure_app do\n      sign_in create_user\n      get :index\n      assert_equal 1, @response.headers[\"CUSTOMHEADER\"]\n    end\n  end\n\n  test \"returns the body of a failure app\" do\n    get :index\n\n    if Devise::Test.rails71_and_up?\n      assert_empty response.body\n    else\n      assert_equal \"<html><body>You are being <a href=\\\"http://test.host/users/sign_in\\\">redirected</a>.</body></html>\", response.body\n    end\n  end\n\n  test \"returns the content type of a failure app\" do\n    get :index, params: { format: :json }\n\n    assert_includes response.media_type, 'application/json'\n  end\n\n  test \"defined Warden after_authentication callback should not be called when sign_in is called\" do\n    assert_nothing_raised do\n      Warden::Manager.after_authentication do |user, auth, opts|\n        flunk \"callback was called while it should not\"\n      end\n\n      user = create_user\n      user.confirm\n      sign_in user\n    ensure\n      Warden::Manager._after_set_user.pop\n    end\n  end\n\n  test \"defined Warden before_logout callback should not be called when sign_out is called\" do\n    assert_nothing_raised do\n      Warden::Manager.before_logout do |user, auth, opts|\n        flunk \"callback was called while it should not\"\n      end\n      user = create_user\n      user.confirm\n\n      sign_in user\n      sign_out user\n    ensure\n      Warden::Manager._before_logout.pop\n    end\n  end\n\n  test \"before_failure call should work\" do\n    begin\n      executed = false\n      Warden::Manager.before_failure do |env,opts|\n        executed = true\n      end\n\n      user = create_user\n      sign_in user\n\n      get :index\n      assert executed\n    ensure\n      Warden::Manager._before_failure.pop\n    end\n  end\n\n  test \"allows to sign in with different users\" do\n    first_user = create_user\n    first_user.confirm\n\n    sign_in first_user\n    get :index\n    assert_match /User ##{first_user.id}/, @response.body\n    sign_out first_user\n\n    second_user = create_user\n    second_user.confirm\n\n    sign_in second_user\n    get :index\n    assert_match /User ##{second_user.id}/, @response.body\n  end\n\n  test \"creates a new warden proxy if the request object has changed\" do\n    old_warden_proxy = warden\n\n    @request = ActionController::TestRequest.create(Class.new) # needs a \"controller class\"\n\n    new_warden_proxy = warden\n\n    assert_not_equal old_warden_proxy, new_warden_proxy\n  end\n\n  test \"doesn't create a new warden proxy if the request object hasn't changed\" do\n    old_warden_proxy = warden\n    new_warden_proxy = warden\n\n    assert_equal old_warden_proxy, new_warden_proxy\n  end\nend\n\nclass TestControllerHelpersForStreamingControllerTest < Devise::ControllerTestCase\n  tests StreamingController\n  include Devise::Test::ControllerHelpers\n\n  test \"doesn't hang when sending an authentication error response body\" do\n    get :index\n\n    if Devise::Test.rails71_and_up?\n      assert_empty response.body\n    else\n      assert_equal \"<html><body>You are being <a href=\\\"http://test.host/users/sign_in\\\">redirected</a>.</body></html>\", response.body\n    end\n  end\nend\n"
  },
  {
    "path": "test/test/integration_helpers_test.rb",
    "content": "# frozen_string_literal: true\n\nrequire 'test_helper'\n\nclass TestIntegrationsHelpersTest < Devise::IntegrationTest\n  include Devise::Test::IntegrationHelpers\n\n  test '#sign_in signs in the resource directly' do\n    sign_in(create_user)\n\n    visit '/'\n    assert warden.authenticated?(:user)\n  end\n\n  test '#sign_outs signs out in the resource directly' do\n    user = create_user\n    sign_in user\n    sign_out user\n\n    visit '/'\n    assert_not warden.authenticated?(:user)\n  end\n\n  test '#sign_out does not signs out other scopes' do\n    sign_in(create_user)\n    sign_in(create_admin)\n    sign_out :user\n\n    visit '/'\n\n    assert_not warden.authenticated?(:user)\n    assert warden.authenticated?(:admin)\n  end\nend\n"
  },
  {
    "path": "test/test_helper.rb",
    "content": "# frozen_string_literal: true\n\nENV[\"RAILS_ENV\"] = \"test\"\nDEVISE_ORM = (ENV[\"DEVISE_ORM\"] || :active_record).to_sym\n\n$:.unshift File.dirname(__FILE__)\nputs \"\\n==> Devise.orm = #{DEVISE_ORM.inspect}\"\n\nrequire \"rails_app/config/environment\"\nrequire \"rails/test_help\"\nrequire \"orm/#{DEVISE_ORM}\"\n\nI18n.load_path.concat Dir[\"#{File.dirname(__FILE__)}/support/locale/*.yml\"]\n\nrequire 'mocha/minitest'\nrequire 'timecop'\nrequire 'webrat'\nWebrat.configure do |config|\n  config.mode = :rails\n  config.open_error_files = false\nend\n\nif ActiveSupport.respond_to?(:test_order)\n  ActiveSupport.test_order = :random\nend\n\nOmniAuth.config.logger = Logger.new('/dev/null')\n\n# Add support to load paths so we can overwrite broken webrat setup\n$:.unshift File.expand_path('../support', __FILE__)\nDir[\"#{File.dirname(__FILE__)}/support/**/*.rb\"].each { |f| require f }\n\n# For generators\nrequire \"rails/generators/test_case\"\nrequire \"generators/devise/install_generator\"\nrequire \"generators/devise/views_generator\"\nrequire \"generators/devise/controllers_generator\"\n"
  },
  {
    "path": "test/test_models.rb",
    "content": "# frozen_string_literal: true\n\nclass Configurable < User\n  devise :database_authenticatable, :confirmable, :rememberable, :timeoutable, :lockable,\n         stretches: 15, pepper: 'abcdef', allow_unconfirmed_access_for: 5.days,\n         remember_for: 7.days, timeout_in: 15.minutes, unlock_in: 10.days\nend\n\nclass WithValidation < Admin\n  devise :database_authenticatable, :validatable, password_length: 2..6\nend\n\nclass UserWithValidation < User\n  validates_presence_of :username\nend\n\nclass UserWithCustomHashing < User\n  protected\n  def password_digest(password)\n    password.reverse\n  end\nend\n\nclass UserWithVirtualAttributes < User\n  devise case_insensitive_keys: [:email, :email_confirmation]\n  validates :email, presence: true, confirmation: { on: :create }\nend\n\nclass Several < Admin\n  devise :validatable\n  devise :lockable\nend\n\nclass Inheritable < Admin\nend\n"
  }
]