[
  {
    "path": ".github/FUNDING.yml",
    "content": "# These are supported funding model platforms\n\ngithub: [excid3] # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]\npatreon: # Replace with a single Patreon username\nopen_collective: # Replace with a single Open Collective username\nko_fi: # Replace with a single Ko-fi username\ntidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel\ncommunity_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry\nliberapay: # Replace with a single Liberapay username\nissuehunt: # Replace with a single IssueHunt username\notechie: # Replace with a single Otechie username\ncustom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/config.yml",
    "content": "blank_issues_enabled: false\ncontact_links:\n  - name: Get Help\n    url: https://github.com/excid3/refer/discussions/new?category=help\n    about: If you can't get something to work the way you expect, open a question in our discussion forums.\n  - name: Feature Request\n    url: https://github.com/excid3/refer/discussions/new?category=ideas\n    about: 'Suggest any ideas you have using our discussion forums.'\n  - name: Bug Report\n    url: https://github.com/excid3/refer/issues/new?body=%3C%21--%20Please%20provide%20all%20of%20the%20information%20requested%20below.%20We%27re%20a%20small%20team%20and%20without%20all%20of%20this%20information%20it%27s%20not%20possible%20for%20us%20to%20help%20and%20your%20bug%20report%20will%20be%20closed.%20--%3E%0A%0A%2A%2AWhat%20version%20of%20Noticed%20are%20you%20using%3F%2A%2A%0A%0AFor%20example%3A%20v2.0.4%0A%0A%2A%2AWhat%20version%20of%20Rails%20are%20you%20using%3F%2A%2A%0A%0AFor%20example%3A%20v7.1.1%0A%0A%2A%2ADescribe%20your%20issue%2A%2A%0A%0ADescribe%20the%20problem%20you%27re%20seeing%2C%20any%20important%20steps%20to%20reproduce%20and%20what%20behavior%20you%20expect%20instead.\n    about: If you've already asked for help with a problem and confirmed something is broken with Noticed itself, create a bug report.\n"
  },
  {
    "path": ".github/ISSUE_TEMPLATE/issue_template.md",
    "content": "---\nname: 🐞 Bug\nabout: File a bug/issue\ntitle: '[BUG] <title>'\nlabels: Bug, Needs Triage\nassignees: ''\n\n---\n\n## Bug Report\n\n**Describe the Bug:**\n<!-- A clear and concise description of the bug -->\n\n**To Reproduce:**\n<!-- Steps to reproduce the behavior -->\n\n1. Step 1\n2. Step 2\n3. ...\n\n**Expected Behavior:**\n<!-- A clear and concise description of what you expected to happen -->\n\n**Actual Behavior:**\n<!-- A clear and concise description of what actually happened -->\n\n**Screenshots (if applicable):**\n<!-- If applicable, add screenshots to help explain your problem -->\n\n**Environment:**\n- Gem version: <!-- Specify the version of the Noticed gem where the bug occurred -->\n- Ruby version: <!-- Specify the version of Ruby you are using -->\n- Rails version: <!-- Specify the version of Rails you are using -->\n- Operating System: <!-- Specify your operating system -->\n\n**Additional Context:**\n<!-- Add any other context about the problem here -->\n\n**Possible Fix:**\n<!-- If you have suggestions on how to fix the bug, you can provide them here -->\n\n**Steps to Reproduce with Fix (if available):**\n<!-- If you have a fix, outline the steps to reproduce the bug using your fix -->\n\n**Related Issues:**\n<!-- If applicable, reference any related GitHub issues or pull requests -->\n\n**Labels to Apply:**\n<!-- Suggest labels that should be applied to this issue -->\n\n**Checklist:**\n<!-- Make sure all of these items are completed before submitting the issue -->\n\n- [ ] I have searched for similar issues and couldn't find any\n- [ ] I have checked the documentation for relevant information\n- [ ] I have included all the required information\n"
  },
  {
    "path": ".github/dependabot.yml",
    "content": "version: 2\nupdates:\n- package-ecosystem: bundler\n  directory: \"/\"\n  schedule:\n    interval: daily\n  open-pull-requests-limit: 10\n- package-ecosystem: github-actions\n  directory: \"/\"\n  schedule:\n    interval: daily\n  open-pull-requests-limit: 10\n"
  },
  {
    "path": ".github/pull_request_template.md",
    "content": "## Pull Request\n\n**Summary:**\n<!-- Provide a brief summary of the changes in this pull request -->\n\n**Related Issue:**\n<!-- If applicable, reference the GitHub issue that this pull request resolves -->\n\n**Description:**\n<!-- Elaborate on the changes made in this pull request. What motivated these changes? -->\n\n**Testing:**\n<!-- Describe the steps you've taken to test the changes. Include relevant information for other contributors to verify the modifications -->\n\n**Screenshots (if applicable):**\n<!-- Include any relevant screenshots or GIFs that demonstrate the changes -->\n\n**Checklist:**\n<!-- Make sure all of these items are completed before submitting the pull request -->\n\n- [ ] Code follows the project's coding standards\n- [ ] Tests have been added or updated to cover the changes\n- [ ] Documentation has been updated (if applicable)\n- [ ] All existing tests pass\n- [ ] Conforms to the contributing guidelines\n\n**Additional Notes:**\n<!-- Any additional information or notes for the reviewers -->\n"
  },
  {
    "path": ".github/workflows/ci.yml",
    "content": "name: CI\n\non:\n  pull_request:\n  push:\n    branches: [ main ]\n\njobs:\n  lint:\n    runs-on: ubuntu-latest\n    steps:\n      - name: Checkout code\n        uses: actions/checkout@v6\n\n      - name: Set up Ruby\n        uses: ruby/setup-ruby@v1\n        with:\n          ruby-version: .ruby-version\n          bundler-cache: true\n\n      - name: Lint code for consistent style\n        run: bin/rubocop -f github\n\n  test:\n    runs-on: ubuntu-latest\n    strategy:\n      matrix:\n        gemfile:\n          - rails_7.1\n          - rails_7.2\n          - rails_8.0\n          - rails_8.1\n          - rails_main\n\n    steps:\n      - name: Install packages\n        run: sudo apt-get update && sudo apt-get install --no-install-recommends -y google-chrome-stable curl libjemalloc2 libsqlite3-0 libvips libsqlite3-0\n\n      - name: Checkout code\n        uses: actions/checkout@v6\n\n      - name: Set up Ruby\n        uses: ruby/setup-ruby@v1\n        with:\n          ruby-version: .ruby-version\n          bundler-cache: true\n\n      - name: Run tests\n        env:\n          RAILS_ENV: test\n          # REDIS_URL: redis://localhost:6379/0\n        run: bin/rails db:test:prepare && bin/rails test\n\n      - name: Keep screenshots from failed system tests\n        uses: actions/upload-artifact@v6\n        if: failure()\n        with:\n          name: screenshots\n          path: ${{ github.workspace }}/tmp/screenshots\n          if-no-files-found: ignore\n\n"
  },
  {
    "path": ".gitignore",
    "content": "/.bundle/\n/doc/\n/log/*.log\n/pkg/\n/tmp/\n/test/dummy/db/*.sqlite3\n/test/dummy/db/*.sqlite3-*\n/test/dummy/log/*.log\n/test/dummy/storage/\n/test/dummy/tmp/\n"
  },
  {
    "path": ".rubocop.yml",
    "content": "# Omakase Ruby styling for Rails\ninherit_gem: { rubocop-rails-omakase: rubocop.yml }\n\n# Overwrite or add rules to create your own house style\n#\n# # Use `[a, [b, c]]` not `[ a, [ b, c ] ]`\n# Layout/SpaceInsideArrayLiteralBrackets:\n#   Enabled: false\n"
  },
  {
    "path": ".ruby-version",
    "content": "3.4.5\n"
  },
  {
    "path": "Appraisals",
    "content": "appraise \"rails-7.1\" do\n  gem \"rails\", \"~> 7.1.0\"\nend\n\nappraise \"rails-7.2\" do\n  gem \"rails\", \"~> 7.2.0\"\nend\n\nappraise \"rails-8.0\" do\n  gem \"rails\", \"~> 8.0.0\"\nend\n\nappraise \"rails-8.1\" do\n  gem \"rails\", \"~> 8.1.0.beta1\"\nend\n\nappraise \"rails-main\" do\n  gem \"rails\", github: \"rails/rails\"\nend\n"
  },
  {
    "path": "CHANGELOG.md",
    "content": "### Unreleased\n\n### 1.0.4\n\n* Remove deprecated `ActiveSupport::Configurable` and replace with mattr_accessor for global config options\n\n### 1.0.3\n\n* Add lazy load hooks for models #59\n\n### 1.0.2\n\n* Ensure self-referrals aren't allowed #47\n\n### 1.0.1\n\n* Use `as:` for polymorphic associations\n* Add tests against Rails 7.1, 7.2, 8.0 and Rails main\n\n### 1.0.0\n\n* Require Rails 7.1+ for `normalizes` support\n\n### 0.5.3\n\n* Only set ReferralCode#code if it is blank #20\n\n### 0.5.2\n\n* Move controller constant to lib\n\n### 0.5.1\n\n* Fixes HasReferrals constant lookup\n\n### 0.5.0\n\n* Add `Refer.referral_completed = ->(referral) { }` callback that runs when a referral is marked as completed\n* `referral.complete!` does nothing if already completed\n\n### 0.4.0\n\n* Add `completed` scope to `Refer::Referral`\n\n### 0.3.0\n\n* Add visit tracking #5\n* Configurable referral cookie overwrites #4\n  Choose between the original referral code or the most recent referral code to receive the referral\n* Fix referral code default generator\n\n### 0.2.1\n\n* Change migrations to use Rails 6.1 version for compatibility\n\n### 0.2.0\n\n* Add `set_referral_cookie` controller method\n* Add `rails g refer:install` generator to inject `set_referral_cookie`\n\n### 0.1.1\n\n* Added `dependent: :nullify` so ReferralCodes persist Referral records when deleted.\n* Added `dependent: :destroy` so Referrals and ReferralCodes are deleted when users are deleted.\n* Fixed missing `referral_codes` association on users\n\n### 0.1.0\n\n* Initial release\n"
  },
  {
    "path": "Gemfile",
    "content": "source \"https://rubygems.org\"\n\n# Specify your gem's dependencies in refer.gemspec.\ngemspec\n\ngem \"puma\"\n\ngem \"sqlite3\"\n\ngem \"sprockets-rails\"\n\n# Omakase Ruby styling [https://github.com/rails/rubocop-rails-omakase/]\ngem \"rubocop-rails-omakase\", require: false\n\n# Start debugger with binding.b [https://github.com/ruby/debug]\n# gem \"debug\", \">= 1.0.0\"\n\ngem \"appraisal\"\n"
  },
  {
    "path": "MIT-LICENSE",
    "content": "Copyright Chris Oliver\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": "# Refer\n\nReferral codes and affiliate links for Ruby on Rails applications.\n\n## 📦 Installation\nAdd this line to your application's Gemfile:\n\n```ruby\ngem \"refer\"\n```\n\nAnd then execute:\n```bash\n$ bundle\n```\n\nAdd Refer to your controllers to store referral cookies:\n```bash\nbin/rails generate refer:install\n```\n\nAnd add Refer to your model:\n```bash\nbin/rails generate refer:model User\nbin/rails db:migrate\n```\n\n## 🧑‍💻 Usage\n\nRefer adds a model to your Rails application for tracking referrals and referral codes.\n\nTo track referrals, you'll need to\n\n1. Create a referral code\n2. Set a cookie with the referral code\n3. Create the referral\n4. (Optional) Provide a reward for successful referral\n\n##### Create a referral code\n\nYou can create referral codes through the association:\n\n```ruby\nuser.referral_codes.create #=> randomly generated code\nuser.referral_codes.create(code: \"chris\")\n```\n\nTo customize the referral code generator:\n\n```ruby\nRefer.code_generator = ->(referrer) { [referrer.id, SecureRandom.alphanumeric(8)].join(\"-\") }\n#=> generates codes like \"1-7frb5fUw\"\n```\n\nBy default, Refer will generate 8 character alphanumeric codes.\n\n##### Set a referral cookie\n\nTo track users, we need to stash the referral code in a cookie when present. By default, Refer will look for `?ref=code` and save this in a cookie.\n\n```ruby\nclass ApplicationController < ActionController::Base\n  set_referral_cookie\nend\n```\n\nMove `set_referral_cookie` to specific controllers if you'd only like cookies set in certain areas like marketing pages for example.\n\n```ruby\nclass MarketingController < ActionController::Base\n  set_referral_cookie except: [:about_us]\nend\n```\n\nYou can customize the param name with:\n\n```ruby\nRefer.param_name = :ref\n```\n\nYou can customize the cookie name with:\n\n```ruby\nRefer.cookie_name = :refer_code\n```\n\n##### Refer a user:\n\nTo create a referral, you can run the following\n\n```ruby\nclass RegistrationsController < ApplicationController\n  def create\n    @user = User.new(user_params)\n    if @user.save\n      refer @user #=> Looks up cookie and attempts referral\n      redirect_to root_path\n    else\n      render :new, status: :unprocessable_entity\n    end\n  end\nend\n```\n\nYou can also do this manually:\n\n```ruby\nRefer.refer(code: \"referral_code\", referee: user)\n```\n\nRefer will make sure the user has not already been referred and create a Referral.\n\n##### Check if a user was referred already:\n\n```ruby\nRefer.referred?(user)\n#=> true/false\n```\n\n##### Accessing Referrals\n\nTo access a user's referrals, you can use the `referrals` association:\n\n```ruby\nuser.referrals #=> [Refer::Referral, Refer::Referral]\n```\n\nThis returns a list of `Refer::Referral` objects.\n\n##### Accessing Referral\n\nTo access a user's referral, you can use the `referral` association:\n\n```ruby\nuser.referral #=> Refer::Referral\n```\n\nTo access a user's referrer, you can use `referrer`:\n```ruby\nuser.referrer #=> User that referred this User\n```\n## Refer with Devise\n\nTo use Refer with Devise, you'll need to customize the Devise controller to track the referral after a successful registration.\n\nWe can do this by telling Devise to use a custom controller in the routes and hooking into the `create` action to track the referral.\n\n```ruby\n# config/routes.rb\ndevise_for :users, controllers: { registrations: \"users/registrations\" }\n```\n\n```ruby\n# app/controllers/users/registrations_controller.rb\nclass Users::RegistrationsController < Devise::RegistrationsController\n  def create\n    super do\n      refer resource if resource.persisted?\n    end\n  end\nend\n```\n\n## Providing Referral Rewards\n\nThere are several common ways of handling rewards for successful referrals:\n\n* Immediate rewards\nWhen the referral is successfully created, you can immediately credit the referrer with their reward.\n\n* Reward after user actions\nYou can check if a user was referred after they complete the action and provide a reward to the referrer.\n\n* Time-based rewards\nTo provide a reward X days after a successful referral, you can use a schedule job to check for referrals X days ago and provide rewards to those referrers.\n\nWe recommend keeping records for each reward given to a referral so you can limit rewards.\n\n## Customizing Models\n\nYou can add features to Refer's models by using lazy load hooks.\n\n```ruby\n# config/initializers/refer.rb\nActiveSupport.on_load :refer_referral do\n  # Add features to Refer::Referral model\nend\n\nActiveSupport.on_load :refer_referral_code do\n  # Add features to Refer::ReferralCode model\nend\n\nActiveSupport.on_load :refer_visit do\n  # Add features to Refer::Visit model\nend\n```\n\n## 🙏 Contributing\nIf you have an issue you'd like to submit, please do so using the issue tracker in GitHub. In order for us to help you in the best way possible, please be as detailed as you can.\n\n## 📝 License\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n"
  },
  {
    "path": "Rakefile",
    "content": "require \"bundler/setup\"\n\nAPP_RAKEFILE = File.expand_path(\"test/dummy/Rakefile\", __dir__)\nload \"rails/tasks/engine.rake\"\n\nrequire \"bundler/gem_tasks\"\n"
  },
  {
    "path": "app/controllers/.keep",
    "content": ""
  },
  {
    "path": "app/controllers/concerns/.keep",
    "content": ""
  },
  {
    "path": "app/models/.keep",
    "content": ""
  },
  {
    "path": "app/models/refer/application_record.rb",
    "content": "module Refer\n  class ApplicationRecord < ActiveRecord::Base\n    self.abstract_class = true\n    self.table_name_prefix = \"refer_\"\n  end\nend\n"
  },
  {
    "path": "app/models/refer/referral.rb",
    "content": "module Refer\n  class Referral < ApplicationRecord\n    belongs_to :referrer, polymorphic: true\n    belongs_to :referee, polymorphic: true\n    belongs_to :referral_code, optional: true, counter_cache: true\n\n    scope :completed, -> { where.not(completed_at: nil) }\n\n    before_validation do\n      self.referrer = referral_code&.referrer\n    end\n\n    validate :ensure_not_self_referral\n\n    def ensure_not_self_referral\n      errors.add(:base, \"Self-referrals are not allowed\") if referrer == referee\n    end\n\n    def complete!(**attributes)\n      return if completed_at?\n\n      update attributes.with_defaults(completed_at: Time.current)\n      Refer.referral_completed&.call(self)\n    end\n  end\nend\n\nActiveSupport.run_load_hooks :refer_referral, Refer::Referral\n"
  },
  {
    "path": "app/models/refer/referral_code.rb",
    "content": "module Refer\n  class ReferralCode < ApplicationRecord\n    belongs_to :referrer, polymorphic: true\n    has_many :referrals, dependent: :nullify\n    has_many :visits, dependent: :delete_all\n\n    validates :code, presence: true, uniqueness: true\n\n    before_validation if: -> { !code? && Refer.code_generator } do\n      self.code = Refer.code_generator.call(referrer)\n    end\n\n    def to_param\n      code\n    end\n\n    def track_visit(request)\n      visits.from_request(request).save\n    end\n  end\nend\n\nActiveSupport.run_load_hooks :refer_referral_code, Refer::ReferralCode\n"
  },
  {
    "path": "app/models/refer/visit.rb",
    "content": "module Refer\n  class Visit < ApplicationRecord\n    belongs_to :referral_code, counter_cache: true\n\n    normalizes :ip, with: -> { Refer.mask_ip(_1) }\n\n    def self.from_request(request)\n      new(\n        ip: request.ip,\n        user_agent: request.user_agent,\n        referrer: request.referrer,\n        referring_domain: (URI.parse(request.referrer).try(:host) rescue nil)\n      )\n    end\n  end\nend\n\nActiveSupport.run_load_hooks :refer_visit, Refer::Visit\n"
  },
  {
    "path": "bin/rails",
    "content": "#!/usr/bin/env ruby\n# This command will automatically be run when you run \"rails\" with Rails gems\n# installed from the root of your application.\n\nENGINE_ROOT = File.expand_path(\"..\", __dir__)\nENGINE_PATH = File.expand_path(\"../lib/refer/engine\", __dir__)\nAPP_PATH = File.expand_path(\"../test/dummy/config/application\", __dir__)\n\n# Set up gems listed in the Gemfile.\nENV[\"BUNDLE_GEMFILE\"] ||= File.expand_path(\"../Gemfile\", __dir__)\nrequire \"bundler/setup\" if File.exist?(ENV[\"BUNDLE_GEMFILE\"])\n\nrequire \"rails/all\"\nrequire \"rails/engine/commands\"\n"
  },
  {
    "path": "bin/rubocop",
    "content": "#!/usr/bin/env ruby\nrequire \"rubygems\"\nrequire \"bundler/setup\"\n\n# explicit rubocop config increases performance slightly while avoiding config confusion.\nARGV.unshift(\"--config\", File.expand_path(\"../.rubocop.yml\", __dir__))\n\nload Gem.bin_path(\"rubocop\", \"rubocop\")\n"
  },
  {
    "path": "config/routes.rb",
    "content": "Rails.application.routes.draw do\nend\n"
  },
  {
    "path": "db/migrate/20240611180738_create_refer_referrals.rb",
    "content": "class CreateReferReferrals < ActiveRecord::Migration[6.1]\n  def change\n    create_table :refer_referrals do |t|\n      t.belongs_to :referrer, polymorphic: true, null: false\n      t.belongs_to :referee, polymorphic: true, null: false\n      t.belongs_to :referral_code\n\n      t.timestamps\n    end\n  end\nend\n"
  },
  {
    "path": "db/migrate/20240611183349_create_refer_referral_codes.rb",
    "content": "class CreateReferReferralCodes < ActiveRecord::Migration[6.1]\n  def change\n    create_table :refer_referral_codes do |t|\n      t.belongs_to :referrer, polymorphic: true, null: false\n      t.string :code, null: false, index: { unique: true }\n\n      t.timestamps\n    end\n  end\nend\n"
  },
  {
    "path": "db/migrate/20240701172643_create_refer_visits.rb",
    "content": "class CreateReferVisits < ActiveRecord::Migration[6.1]\n  def change\n    create_table :refer_visits do |t|\n      t.belongs_to :referral_code, null: false, foreign_key: { to_table: :refer_referral_codes }\n      t.string :ip\n      t.text :user_agent\n      t.text :referrer\n      t.string :referring_domain\n\n      t.timestamps\n    end\n\n    add_column :refer_referral_codes, :referrals_count, :integer, default: 0\n    add_column :refer_referral_codes, :visits_count, :integer, default: 0\n    add_column :refer_referrals, :completed_at, :datetime\n  end\nend\n"
  },
  {
    "path": "gemfiles/rails_7.1.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"puma\"\ngem \"sqlite3\"\ngem \"sprockets-rails\"\ngem \"rubocop-rails-omakase\", require: false\ngem \"appraisal\"\ngem \"rails\", \"~> 7.1.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/rails_7.2.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"puma\"\ngem \"sqlite3\"\ngem \"sprockets-rails\"\ngem \"rubocop-rails-omakase\", require: false\ngem \"appraisal\"\ngem \"rails\", \"~> 7.2.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/rails_8.0.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"puma\"\ngem \"sqlite3\"\ngem \"sprockets-rails\"\ngem \"rubocop-rails-omakase\", require: false\ngem \"appraisal\"\ngem \"rails\", \"~> 8.0.0\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/rails_8.1.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"puma\"\ngem \"sqlite3\"\ngem \"sprockets-rails\"\ngem \"rubocop-rails-omakase\", require: false\ngem \"appraisal\"\ngem \"rails\", \"~> 8.1.0.beta1\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "gemfiles/rails_main.gemfile",
    "content": "# This file was generated by Appraisal\n\nsource \"https://rubygems.org\"\n\ngem \"puma\"\ngem \"sqlite3\"\ngem \"sprockets-rails\"\ngem \"rubocop-rails-omakase\", require: false\ngem \"appraisal\"\ngem \"rails\", github: \"rails/rails\"\n\ngemspec path: \"../\"\n"
  },
  {
    "path": "lib/generators/refer/install/USAGE",
    "content": "Description:\n    Adds Refer to ApplicationController to set referral cookies\n\nExample:\n    bin/rails generate refer:install\n\n    This will add `sets_refer_cookie` to the ApplicationController class.\n\n"
  },
  {
    "path": "lib/generators/refer/install/install_generator.rb",
    "content": "class Refer::InstallGenerator < Rails::Generators::Base\n  source_root File.expand_path(\"templates\", __dir__)\n\n  def add_refer\n    inject_into_class File.join(\"app\", \"controllers\", \"application_controller.rb\"), \"ApplicationController\", \"  set_referral_cookie\\n\"\n  end\nend\n"
  },
  {
    "path": "lib/generators/refer/model/USAGE",
    "content": "Description:\n    Adds Refer associations to a model\n\nExample:\n    bin/rails generate refer:model User\n\n    This will add `has_referrals` to the User class.\n"
  },
  {
    "path": "lib/generators/refer/model/model_generator.rb",
    "content": "class Refer::ModelGenerator < Rails::Generators::NamedBase\n  source_root File.expand_path(\"templates\", __dir__)\n\n  def migrations\n    rails_command \"refer:install:migrations\"\n  end\n\n  def add_refer\n    inject_into_class File.join(\"app\", \"models\", \"#{file_path}.rb\"), class_name, \"  has_referrals\\n\"\n  end\nend\n"
  },
  {
    "path": "lib/refer/controller.rb",
    "content": "module Refer\n  module Controller\n    extend ActiveSupport::Concern\n\n    class_methods do\n      def set_referral_cookie(param_name: Refer.param_name, cookie_name: Refer.cookie_name, **options)\n        before_action -> { set_refer_cookie(param_name: param_name, cookie_name: cookie_name) }, **options\n      end\n    end\n\n    def refer(referee, cookie_name: Refer.cookie_name)\n      Refer.refer(code: cookies[cookie_name], referee: referee)\n    end\n\n    private\n\n    def set_refer_cookie(param_name: Refer.param_name, cookie_name: Refer.cookie_name, code: nil, track_visit: Refer.track_visits)\n      code ||= params[param_name]\n      return if code.blank?\n\n      cookies[cookie_name] = Refer.cookie(code) if Refer.overwrite_cookie || cookies[cookie_name].blank?\n      ReferralCode.find_by(code: code)&.track_visit(request) if track_visit\n    end\n  end\nend\n"
  },
  {
    "path": "lib/refer/engine.rb",
    "content": "module Refer\n  class Engine < ::Rails::Engine\n    isolate_namespace Refer\n\n    initializer \"refer.hooks\" do\n      ActiveSupport.on_load(:active_record) do\n        include Refer::HasReferrals\n      end\n\n      ActiveSupport.on_load(:action_controller) do\n        include Refer::Controller\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/refer/has_referrals.rb",
    "content": "module Refer\n  module HasReferrals\n    extend ActiveSupport::Concern\n\n    class_methods do\n      def has_referrals\n        include Refer::Model\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "lib/refer/model.rb",
    "content": "module Refer\n  module Model\n    extend ActiveSupport::Concern\n\n    included do\n      has_many :referral_codes, as: :referrer, class_name: \"Refer::ReferralCode\", dependent: :destroy\n      has_many :referrals, as: :referrer, class_name: \"Refer::Referral\", dependent: :destroy\n      has_one :referral, as: :referee, class_name: \"Refer::Referral\", dependent: :destroy\n      delegate :referrer, to: :referral, allow_nil: true\n    end\n  end\nend\n"
  },
  {
    "path": "lib/refer/version.rb",
    "content": "module Refer\n  VERSION = \"1.0.4\"\nend\n"
  },
  {
    "path": "lib/refer.rb",
    "content": "require \"refer/version\"\nrequire \"refer/engine\"\nrequire \"securerandom\"\n\nmodule Refer\n  autoload :Controller, \"refer/controller\"\n  autoload :HasReferrals, \"refer/has_referrals\"\n  autoload :Model, \"refer/model\"\n\n  mattr_accessor :code_generator, default: ->(referrer) { SecureRandom.alphanumeric(8) }\n  mattr_accessor :cookie_length, default: 30.days\n  mattr_accessor :cookie_name, default: :refer_code\n  mattr_accessor :param_name, default: :ref\n  mattr_accessor :overwrite_cookie, default: true\n  mattr_accessor :track_visits, default: true\n  mattr_accessor :mask_ips, default: true\n  mattr_accessor :referral_completed\n\n  class Error < StandardError; end\n  class AlreadyReferred < Error; end\n\n  def self.referred?(referee)\n    Referral.where(referee: referee).exists?\n  end\n\n  def self.refer(code:, referee:)\n    return if referred?(referee)\n    ReferralCode.find_by(code: code)&.referrals&.create(referee: referee)\n  end\n\n  def self.refer!(code:, referee:)\n    raise AlreadyReferred, \"#{referee} has already been referred\" if referred?(referee)\n    ReferralCode.find_by!(code: code).referrals.create!(referee: referee)\n  end\n\n  def self.cookie(code)\n    {\n      value: code,\n      expires: Refer.cookie_length.from_now\n    }\n  end\n\n  # From Ahoy gem: https://github.com/ankane/ahoy/blob/v5.1.0/lib/ahoy.rb#L133-L142\n  def self.mask_ip(ip)\n    return ip unless mask_ips\n\n    addr = IPAddr.new(ip)\n    if addr.ipv4?\n      # set last octet to 0\n      addr.mask(24).to_s\n    else\n      # set last 80 bits to zeros\n      addr.mask(48).to_s\n    end\n  end\nend\n\nActiveSupport.run_load_hooks(:refer, Refer)\n"
  },
  {
    "path": "lib/tasks/refer_tasks.rake",
    "content": "# desc \"Explaining what the task does\"\n# task :refer do\n#   # Task goes here\n# end\n"
  },
  {
    "path": "refer.gemspec",
    "content": "require_relative \"lib/refer/version\"\n\nGem::Specification.new do |spec|\n  spec.name        = \"refer\"\n  spec.version     = Refer::VERSION\n  spec.authors     = [ \"Chris Oliver\" ]\n  spec.email       = [ \"excid3@gmail.com\" ]\n  spec.homepage    = \"https://github.com/excid3/refer\"\n  spec.summary     = \"Referral codes & affiliate links for Ruby on Rails apps\"\n  spec.description = \"Referral codes & affiliate links for Ruby on Rails apps\"\n  spec.license     = \"MIT\"\n\n  spec.metadata[\"homepage_uri\"] = spec.homepage\n  spec.metadata[\"source_code_uri\"] = spec.homepage\n  spec.metadata[\"changelog_uri\"] = spec.homepage + \"/blob/main/CHANGELOG.md\"\n\n  spec.files = Dir.chdir(File.expand_path(__dir__)) do\n    Dir[\"{app,config,db,lib}/**/*\", \"MIT-LICENSE\", \"Rakefile\", \"README.md\"]\n  end\n\n  spec.add_dependency \"rails\", \">= 7.1.0\"\nend\n"
  },
  {
    "path": "test/dummy/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_relative \"config/application\"\n\nRails.application.load_tasks\n"
  },
  {
    "path": "test/dummy/app/assets/config/manifest.js",
    "content": "//= link_tree ../images\n//= link_directory ../stylesheets .css\n"
  },
  {
    "path": "test/dummy/app/assets/images/.keep",
    "content": ""
  },
  {
    "path": "test/dummy/app/assets/stylesheets/application.css",
    "content": "/*\n * This is a manifest file that'll be compiled into application.css, which will include all the files\n * listed below.\n *\n * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,\n * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.\n *\n * You're free to add application-wide styles to this file and they'll appear at the bottom of the\n * compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS\n * files in this directory. Styles in this file should be added after the last require_* statement.\n * It is generally better to create a new file per style scope.\n *\n *= require_tree .\n *= require_self\n */\n"
  },
  {
    "path": "test/dummy/app/channels/application_cable/channel.rb",
    "content": "module ApplicationCable\n  class Channel < ActionCable::Channel::Base\n  end\nend\n"
  },
  {
    "path": "test/dummy/app/channels/application_cable/connection.rb",
    "content": "module ApplicationCable\n  class Connection < ActionCable::Connection::Base\n  end\nend\n"
  },
  {
    "path": "test/dummy/app/controllers/application_controller.rb",
    "content": "class ApplicationController < ActionController::Base\nend\n"
  },
  {
    "path": "test/dummy/app/controllers/concerns/.keep",
    "content": ""
  },
  {
    "path": "test/dummy/app/controllers/referrals_controller.rb",
    "content": "class ReferralsController < ApplicationController\n  set_referral_cookie\n  before_action :set_user, only: [ :create ]\n\n  def show\n    head :ok\n  end\n\n  def create\n    refer @user\n    head :ok\n  end\n\n  private\n\n  def set_user\n    @user = User.find(params[:user_id])\n  end\nend\n"
  },
  {
    "path": "test/dummy/app/helpers/application_helper.rb",
    "content": "module ApplicationHelper\nend\n"
  },
  {
    "path": "test/dummy/app/jobs/application_job.rb",
    "content": "class ApplicationJob < ActiveJob::Base\n  # Automatically retry jobs that encountered a deadlock\n  # retry_on ActiveRecord::Deadlocked\n\n  # Most jobs are safe to ignore if the underlying records are no longer available\n  # discard_on ActiveJob::DeserializationError\nend\n"
  },
  {
    "path": "test/dummy/app/mailers/application_mailer.rb",
    "content": "class ApplicationMailer < ActionMailer::Base\n  default from: \"from@example.com\"\n  layout \"mailer\"\nend\n"
  },
  {
    "path": "test/dummy/app/models/application_record.rb",
    "content": "class ApplicationRecord < ActiveRecord::Base\n  primary_abstract_class\nend\n"
  },
  {
    "path": "test/dummy/app/models/concerns/.keep",
    "content": ""
  },
  {
    "path": "test/dummy/app/models/user.rb",
    "content": "class User < ApplicationRecord\n  has_referrals\nend\n"
  },
  {
    "path": "test/dummy/app/views/layouts/application.html.erb",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <title><%= content_for(:title) || \"Dummy\" %></title>\n    <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n    <meta name=\"apple-mobile-web-app-capable\" content=\"yes\">\n    <%= csrf_meta_tags %>\n    <%= csp_meta_tag %>\n\n    <%= yield :head %>\n\n    <link rel=\"manifest\" href=\"/manifest.json\">\n    <link rel=\"icon\" href=\"/icon.png\" type=\"image/png\">\n    <link rel=\"icon\" href=\"/icon.svg\" type=\"image/svg+xml\">\n    <link rel=\"apple-touch-icon\" href=\"/icon.png\">\n    <%= stylesheet_link_tag \"application\" %>\n  </head>\n\n  <body>\n    <%= yield %>\n  </body>\n</html>\n"
  },
  {
    "path": "test/dummy/app/views/layouts/mailer.html.erb",
    "content": "<!DOCTYPE html>\n<html>\n  <head>\n    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\n    <style>\n      /* Email styles need to be inline */\n    </style>\n  </head>\n\n  <body>\n    <%= yield %>\n  </body>\n</html>\n"
  },
  {
    "path": "test/dummy/app/views/layouts/mailer.text.erb",
    "content": "<%= yield %>\n"
  },
  {
    "path": "test/dummy/app/views/pwa/manifest.json.erb",
    "content": "{\n  \"name\": \"Dummy\",\n  \"icons\": [\n    {\n      \"src\": \"/icon.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\"\n    },\n    {\n      \"src\": \"/icon.png\",\n      \"type\": \"image/png\",\n      \"sizes\": \"512x512\",\n      \"purpose\": \"maskable\"\n    }\n  ],\n  \"start_url\": \"/\",\n  \"display\": \"standalone\",\n  \"scope\": \"/\",\n  \"description\": \"Dummy.\",\n  \"theme_color\": \"red\",\n  \"background_color\": \"red\"\n}\n"
  },
  {
    "path": "test/dummy/app/views/pwa/service-worker.js",
    "content": "// Add a service worker for processing Web Push notifications:\n//\n// self.addEventListener(\"push\", async (event) => {\n//   const { title, options } = await event.data.json()\n//   event.waitUntil(self.registration.showNotification(title, options))\n// })\n// \n// self.addEventListener(\"notificationclick\", function(event) {\n//   event.notification.close()\n//   event.waitUntil(\n//     clients.matchAll({ type: \"window\" }).then((clientList) => {\n//       for (let i = 0; i < clientList.length; i++) {\n//         let client = clientList[i]\n//         let clientPath = (new URL(client.url)).pathname\n// \n//         if (clientPath == event.notification.data.path && \"focus\" in client) {\n//           return client.focus()\n//         }\n//       }\n// \n//       if (clients.openWindow) {\n//         return clients.openWindow(event.notification.data.path)\n//       }\n//     })\n//   )\n// })\n"
  },
  {
    "path": "test/dummy/bin/rails",
    "content": "#!/usr/bin/env ruby\nAPP_PATH = File.expand_path(\"../config/application\", __dir__)\nrequire_relative \"../config/boot\"\nrequire \"rails/commands\"\n"
  },
  {
    "path": "test/dummy/bin/rake",
    "content": "#!/usr/bin/env ruby\nrequire_relative \"../config/boot\"\nrequire \"rake\"\nRake.application.run\n"
  },
  {
    "path": "test/dummy/bin/setup",
    "content": "#!/usr/bin/env ruby\nrequire \"fileutils\"\n\nAPP_ROOT = File.expand_path(\"..\", __dir__)\nAPP_NAME = \"dummy\"\n\ndef system!(*args)\n  system(*args, exception: true)\nend\n\nFileUtils.chdir APP_ROOT do\n  # This script is a way to set up or update your development environment automatically.\n  # This script is idempotent, so that you can run it at any time and get an expectable outcome.\n  # Add necessary setup steps to this file.\n\n  puts \"== Installing dependencies ==\"\n  system! \"gem install bundler --conservative\"\n  system(\"bundle check\") || system!(\"bundle install\")\n\n  # puts \"\\n== Copying sample files ==\"\n  # unless File.exist?(\"config/database.yml\")\n  #   FileUtils.cp \"config/database.yml.sample\", \"config/database.yml\"\n  # end\n\n  puts \"\\n== Preparing database ==\"\n  system! \"bin/rails db:prepare\"\n\n  puts \"\\n== Removing old logs and tempfiles ==\"\n  system! \"bin/rails log:clear tmp:clear\"\n\n  puts \"\\n== Restarting application server ==\"\n  system! \"bin/rails restart\"\n\n  # puts \"\\n== Configuring puma-dev ==\"\n  # system \"ln -nfs #{APP_ROOT} ~/.puma-dev/#{APP_NAME}\"\n  # system \"curl -Is https://#{APP_NAME}.test/up | head -n 1\"\nend\n"
  },
  {
    "path": "test/dummy/config/application.rb",
    "content": "require_relative \"boot\"\n\nrequire \"rails/all\"\n\n# Require the gems listed in Gemfile, including any gems\n# you've limited to :test, :development, or :production.\nBundler.require(*Rails.groups)\n\nmodule Dummy\n  class Application < Rails::Application\n    config.load_defaults Rails::VERSION::STRING.to_f\n\n    # For compatibility with applications that use this config\n    config.action_controller.include_all_helpers = false\n\n    # Please, add to the `ignore` list any other `lib` subdirectories that do\n    # not contain `.rb` files, or that should not be reloaded or eager loaded.\n    # Common ones are `templates`, `generators`, or `middleware`, for example.\n    config.autoload_lib(ignore: %w[assets tasks])\n\n    # Configuration for the application, engines, and railties goes here.\n    #\n    # These settings can be overridden in specific environments using the files\n    # in config/environments, which are processed later.\n    #\n    # config.time_zone = \"Central Time (US & Canada)\"\n    # config.eager_load_paths << Rails.root.join(\"extras\")\n  end\nend\n"
  },
  {
    "path": "test/dummy/config/boot.rb",
    "content": "# Set up gems listed in the Gemfile.\nENV[\"BUNDLE_GEMFILE\"] ||= File.expand_path(\"../../../Gemfile\", __dir__)\n\nrequire \"bundler/setup\" if File.exist?(ENV[\"BUNDLE_GEMFILE\"])\n$LOAD_PATH.unshift File.expand_path(\"../../../lib\", __dir__)\n"
  },
  {
    "path": "test/dummy/config/cable.yml",
    "content": "development:\n  adapter: async\n\ntest:\n  adapter: test\n\nproduction:\n  adapter: redis\n  url: <%= ENV.fetch(\"REDIS_URL\") { \"redis://localhost:6379/1\" } %>\n  channel_prefix: dummy_production\n"
  },
  {
    "path": "test/dummy/config/database.yml",
    "content": "# SQLite. Versions 3.8.0 and up are supported.\n#   gem install sqlite3\n#\n#   Ensure the SQLite 3 gem is defined in your Gemfile\n#   gem \"sqlite3\"\n#\ndefault: &default\n  adapter: sqlite3\n  pool: <%= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } %>\n  timeout: 5000\n\ndevelopment:\n  <<: *default\n  database: storage/development.sqlite3\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  <<: *default\n  database: storage/test.sqlite3\n\n\n# SQLite3 write its data on the local filesystem, as such it requires\n# persistent disks. If you are deploying to a managed service, you should\n# make sure it provides disk persistence, as many don't.\n#\n# Similarly, if you deploy your application as a Docker container, you must\n# ensure the database is located in a persisted volume.\nproduction:\n  <<: *default\n  # database: path/to/persistent/storage/production.sqlite3\n"
  },
  {
    "path": "test/dummy/config/environment.rb",
    "content": "# Load the Rails application.\nrequire_relative \"application\"\n\n# Initialize the Rails application.\nRails.application.initialize!\n"
  },
  {
    "path": "test/dummy/config/environments/development.rb",
    "content": "require \"active_support/core_ext/integer/time\"\n\nRails.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 any time\n  # it changes. 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.enable_reloading = true\n\n  # Do not eager load code on boot.\n  config.eager_load = false\n\n  # Show full error reports.\n  config.consider_all_requests_local = true\n\n  # Enable server timing.\n  config.server_timing = true\n\n  # Enable/disable caching. By default caching is disabled.\n  # Run rails dev:cache to toggle caching.\n  if Rails.root.join(\"tmp/caching-dev.txt\").exist?\n    config.action_controller.perform_caching = true\n    config.action_controller.enable_fragment_cache_logging = true\n\n    config.cache_store = :memory_store\n    config.public_file_server.headers = { \"Cache-Control\" => \"public, max-age=#{2.days.to_i}\" }\n  else\n    config.action_controller.perform_caching = false\n\n    config.cache_store = :null_store\n  end\n\n  # Store uploaded files on the local file system (see config/storage.yml for options).\n  config.active_storage.service = :local\n\n  # Don't care if the mailer can't send.\n  config.action_mailer.raise_delivery_errors = false\n\n  config.action_mailer.perform_caching = false\n\n  config.action_mailer.default_url_options = { host: \"localhost\", port: 3000 }\n\n  # Print deprecation notices to the Rails logger.\n  config.active_support.deprecation = :log\n\n  # Raise exceptions for disallowed deprecations.\n  config.active_support.disallowed_deprecation = :raise\n\n  # Tell Active Support which deprecation messages to disallow.\n  config.active_support.disallowed_deprecation_warnings = []\n\n  # Raise an error on page load if there are pending migrations.\n  config.active_record.migration_error = :page_load\n\n  # Highlight code that triggered database queries in logs.\n  config.active_record.verbose_query_logs = true\n\n  # Highlight code that enqueued background job in logs.\n  config.active_job.verbose_enqueue_logs = true\n\n  # Suppress logger output for asset requests.\n  config.assets.quiet = true\n\n  # Raises error for missing translations.\n  # config.i18n.raise_on_missing_translations = true\n\n  # Annotate rendered view with file names.\n  config.action_view.annotate_rendered_view_with_filenames = true\n\n  # Uncomment if you wish to allow Action Cable access from any origin.\n  # config.action_cable.disable_request_forgery_protection = true\n\n  # Raise error when a before_action's only/except options reference missing actions.\n  config.action_controller.raise_on_missing_callback_actions = true\nend\n"
  },
  {
    "path": "test/dummy/config/environments/production.rb",
    "content": "require \"active_support/core_ext/integer/time\"\n\nRails.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.enable_reloading = false\n\n  # Eager load code on boot. This eager loads most of Rails and\n  # your application in memory, allowing both threaded 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  # Ensures that a master key has been made available in ENV[\"RAILS_MASTER_KEY\"], config/master.key, or an environment\n  # key such as config/credentials/production.key. This key is used to decrypt credentials (and other encrypted files).\n  # config.require_master_key = true\n\n  # Disable serving static files from `public/`, relying on NGINX/Apache to do so instead.\n  # config.public_file_server.enabled = false\n\n  # Compress CSS using a preprocessor.\n  # config.assets.css_compressor = :sass\n\n  # Do not fall back to assets pipeline if a precompiled asset is missed.\n  config.assets.compile = false\n\n  # Enable serving of images, stylesheets, and JavaScripts from an asset server.\n  # config.asset_host = \"http://assets.example.com\"\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  # Store uploaded files on the local file system (see config/storage.yml for options).\n  config.active_storage.service = :local\n\n  # Mount Action Cable outside main process or domain.\n  # config.action_cable.mount_path = nil\n  # config.action_cable.url = \"wss://example.com/cable\"\n  # config.action_cable.allowed_request_origins = [ \"http://example.com\", /http:\\/\\/example.*/ ]\n\n  # Assume all access to the app is happening through a SSL-terminating reverse proxy.\n  # Can be used together with config.force_ssl for Strict-Transport-Security and secure cookies.\n  # config.assume_ssl = true\n\n  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.\n  config.force_ssl = true\n  # Skip http-to-https redirect for the default health check endpoint.\n  # config.ssl_options = { redirect: { exclude: ->(request) { request.path == \"/up\" } } }\n\n  # Log to STDOUT by default\n  config.logger = ActiveSupport::Logger.new(STDOUT)\n    .tap  { |logger| logger.formatter = ::Logger::Formatter.new }\n    .then { |logger| ActiveSupport::TaggedLogging.new(logger) }\n\n  # Prepend all log lines with the following tags.\n  config.log_tags = [ :request_id ]\n\n  # \"info\" includes generic and useful information about system operation, but avoids logging too much\n  # information to avoid inadvertent exposure of personally identifiable information (PII). If you\n  # want to log everything, set the level to \"debug\".\n  config.log_level = ENV.fetch(\"RAILS_LOG_LEVEL\", \"info\")\n\n  # Use a different cache store in production.\n  # config.cache_store = :mem_cache_store\n\n  # Use a real queuing backend for Active Job (and separate queues per environment).\n  # config.active_job.queue_adapter = :resque\n  # config.active_job.queue_name_prefix = \"dummy_production\"\n\n  config.action_mailer.perform_caching = false\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 cannot be found).\n  config.i18n.fallbacks = true\n\n  # Don't log any deprecations.\n  config.active_support.report_deprecations = false\n\n  # Do not dump schema after migrations.\n  config.active_record.dump_schema_after_migration = false\n\n  # Enable DNS rebinding protection and other `Host` header attacks.\n  # config.hosts = [\n  #   \"example.com\",     # Allow requests from example.com\n  #   /.*\\.example\\.com/ # Allow requests from subdomains like `www.example.com`\n  # ]\n  # Skip DNS rebinding protection for the default health check endpoint.\n  # config.host_authorization = { exclude: ->(request) { request.path == \"/up\" } }\nend\n"
  },
  {
    "path": "test/dummy/config/environments/test.rb",
    "content": "require \"active_support/core_ext/integer/time\"\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\nRails.application.configure do\n  # Settings specified here will take precedence over those in config/application.rb.\n\n  # While tests run files are not watched, reloading is not necessary.\n  config.enable_reloading = false\n\n  # Eager loading loads your entire application. When running a single test locally,\n  # this is usually not necessary, and can slow down your test suite. However, it's\n  # recommended that you enable it in continuous integration systems to ensure eager\n  # loading is working properly before deploying your code.\n  config.eager_load = ENV[\"CI\"].present?\n\n  # Configure public file server for tests with Cache-Control for performance.\n  config.public_file_server.headers = { \"Cache-Control\" => \"public, max-age=#{1.hour.to_i}\" }\n\n  # Show full error reports and disable caching.\n  config.consider_all_requests_local = true\n  config.action_controller.perform_caching = false\n  config.cache_store = :null_store\n\n  # Render exception templates for rescuable exceptions and raise for other exceptions.\n  config.action_dispatch.show_exceptions = :rescuable\n\n  # Disable request forgery protection in test environment.\n  config.action_controller.allow_forgery_protection = false\n\n  # Store uploaded files on the local file system in a temporary directory.\n  config.active_storage.service = :test\n\n  config.action_mailer.perform_caching = 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  # Unlike controllers, the mailer instance doesn't have any context about the\n  # incoming request so you'll need to provide the :host parameter yourself.\n  config.action_mailer.default_url_options = { host: \"www.example.com\" }\n\n  # Print deprecation notices to the stderr.\n  config.active_support.deprecation = :stderr\n\n  # Raise exceptions for disallowed deprecations.\n  config.active_support.disallowed_deprecation = :raise\n\n  # Tell Active Support which deprecation messages to disallow.\n  config.active_support.disallowed_deprecation_warnings = []\n\n  # Raises error for missing translations.\n  # config.i18n.raise_on_missing_translations = true\n\n  # Annotate rendered view with file names.\n  # config.action_view.annotate_rendered_view_with_filenames = true\n\n  # Raise error when a before_action's only/except options reference missing actions.\n  config.action_controller.raise_on_missing_callback_actions = true\nend\n"
  },
  {
    "path": "test/dummy/config/initializers/assets.rb",
    "content": "# Be sure to restart your server when you modify this file.\n\n# Version of your assets, change this if you want to expire all your assets.\nRails.application.config.assets.version = \"1.0\"\n\n# Add additional assets to the asset load path.\n# Rails.application.config.assets.paths << Emoji.images_path\n\n# Precompile additional assets.\n# application.js, application.css, and all non-JS/CSS in the app/assets\n# folder are already added.\n# Rails.application.config.assets.precompile += %w( admin.js admin.css )\n"
  },
  {
    "path": "test/dummy/config/initializers/content_security_policy.rb",
    "content": "# Be sure to restart your server when you modify this file.\n\n# Define an application-wide content security policy.\n# See the Securing Rails Applications Guide for more information:\n# https://guides.rubyonrails.org/security.html#content-security-policy-header\n\n# Rails.application.configure do\n#   config.content_security_policy do |policy|\n#     policy.default_src :self, :https\n#     policy.font_src    :self, :https, :data\n#     policy.img_src     :self, :https, :data\n#     policy.object_src  :none\n#     policy.script_src  :self, :https\n#     policy.style_src   :self, :https\n#     # Specify URI for violation reports\n#     # policy.report_uri \"/csp-violation-report-endpoint\"\n#   end\n#\n#   # Generate session nonces for permitted importmap, inline scripts, and inline styles.\n#   config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }\n#   config.content_security_policy_nonce_directives = %w(script-src style-src)\n#\n#   # Report violations without enforcing the policy.\n#   # config.content_security_policy_report_only = true\n# end\n"
  },
  {
    "path": "test/dummy/config/initializers/filter_parameter_logging.rb",
    "content": "# Be sure to restart your server when you modify this file.\n\n# Configure parameters to be partially matched (e.g. passw matches password) and filtered from the log file.\n# Use this to limit dissemination of sensitive information.\n# See the ActiveSupport::ParameterFilter documentation for supported notations and behaviors.\nRails.application.config.filter_parameters += [\n  :passw, :email, :secret, :token, :_key, :crypt, :salt, :certificate, :otp, :ssn\n]\n"
  },
  {
    "path": "test/dummy/config/initializers/inflections.rb",
    "content": "# Be sure to restart your server when you modify this file.\n\n# Add new inflection rules using the following format. Inflections\n# are locale specific, and you may define rules for as many different\n# locales as you wish. All of these examples are active by default:\n# ActiveSupport::Inflector.inflections(:en) do |inflect|\n#   inflect.plural /^(ox)$/i, \"\\\\1en\"\n#   inflect.singular /^(ox)en/i, \"\\\\1\"\n#   inflect.irregular \"person\", \"people\"\n#   inflect.uncountable %w( fish sheep )\n# end\n\n# These inflection rules are supported but not enabled by default:\n# ActiveSupport::Inflector.inflections(:en) do |inflect|\n#   inflect.acronym \"RESTful\"\n# end\n"
  },
  {
    "path": "test/dummy/config/initializers/permissions_policy.rb",
    "content": "# Be sure to restart your server when you modify this file.\n\n# Define an application-wide HTTP permissions policy. For further\n# information see: https://developers.google.com/web/updates/2018/06/feature-policy\n\n# Rails.application.config.permissions_policy do |policy|\n#   policy.camera      :none\n#   policy.gyroscope   :none\n#   policy.microphone  :none\n#   policy.usb         :none\n#   policy.fullscreen  :self\n#   policy.payment     :self, \"https://secure.example.com\"\n# end\n"
  },
  {
    "path": "test/dummy/config/locales/en.yml",
    "content": "# Files in the config/locales directory are used for internationalization and\n# are automatically loaded by Rails. If you want to use locales other than\n# English, add the necessary files in this directory.\n#\n# To use the locales, use `I18n.t`:\n#\n#     I18n.t \"hello\"\n#\n# In views, this is aliased to just `t`:\n#\n#     <%= t(\"hello\") %>\n#\n# To use a different locale, set it with `I18n.locale`:\n#\n#     I18n.locale = :es\n#\n# This would use the information in config/locales/es.yml.\n#\n# To learn more about the API, please read the Rails Internationalization guide\n# at https://guides.rubyonrails.org/i18n.html.\n#\n# Be aware that YAML interprets the following case-insensitive strings as\n# booleans: `true`, `false`, `on`, `off`, `yes`, `no`. Therefore, these strings\n# must be quoted to be interpreted as strings. For example:\n#\n#     en:\n#       \"yes\": yup\n#       enabled: \"ON\"\n\nen:\n  hello: \"Hello world\"\n"
  },
  {
    "path": "test/dummy/config/puma.rb",
    "content": "# This configuration file will be evaluated by Puma. The top-level methods that\n# are invoked here are part of Puma's configuration DSL. For more information\n# about methods provided by the DSL, see https://puma.io/puma/Puma/DSL.html.\n\n# Puma starts a configurable number of processes (workers) and each process\n# serves each request in a thread from an internal thread pool.\n#\n# The ideal number of threads per worker depends both on how much time the\n# application spends waiting for IO operations and on how much you wish to\n# to prioritize throughput over latency.\n#\n# As a rule of thumb, increasing the number of threads will increase how much\n# traffic a given process can handle (throughput), but due to CRuby's\n# Global VM Lock (GVL) it has diminishing returns and will degrade the\n# response time (latency) of the application.\n#\n# The default is set to 3 threads as it's deemed a decent compromise between\n# throughput and latency for the average Rails application.\n#\n# Any libraries that use a connection pool or another resource pool should\n# be configured to provide at least as many connections as the number of\n# threads. This includes Active Record's `pool` parameter in `database.yml`.\nthreads_count = ENV.fetch(\"RAILS_MAX_THREADS\", 3)\nthreads threads_count, threads_count\n\n# Specifies the `environment` that Puma will run in.\nrails_env = ENV.fetch(\"RAILS_ENV\", \"development\")\nenvironment rails_env\n\ncase rails_env\nwhen \"production\"\n  # If you are running more than 1 thread per process, the workers count\n  # should be equal to the number of processors (CPU cores) in production.\n  #\n  # Automatically detect the number of available processors in production.\n  require \"concurrent-ruby\"\n  workers_count = Integer(ENV.fetch(\"WEB_CONCURRENCY\") { Concurrent.available_processor_count })\n  workers workers_count if workers_count > 1\n\n  preload_app!\nwhen \"development\"\n  # Specifies a very generous `worker_timeout` so that the worker\n  # isn't killed by Puma when suspended by a debugger.\n  worker_timeout 3600\nend\n\n# Specifies the `port` that Puma will listen on to receive requests; default is 3000.\nport ENV.fetch(\"PORT\", 3000)\n\n# Allow puma to be restarted by `bin/rails restart` command.\nplugin :tmp_restart\n\n# Only use a pidfile when requested\npidfile ENV[\"PIDFILE\"] if ENV[\"PIDFILE\"]\n"
  },
  {
    "path": "test/dummy/config/routes.rb",
    "content": "Rails.application.routes.draw do\n  # Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html\n  post :refer, to: \"referrals#create\"\n\n  # Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.\n  # Can be used by load balancers and uptime monitors to verify that the app is live.\n  get \"up\" => \"rails/health#show\", as: :rails_health_check\n\n  # Render dynamic PWA files from app/views/pwa/*\n  get \"service-worker\" => \"rails/pwa#service_worker\", as: :pwa_service_worker\n  get \"manifest\" => \"rails/pwa#manifest\", as: :pwa_manifest\n\n  # Defines the root path route (\"/\")\n  root to: \"referrals#show\"\nend\n"
  },
  {
    "path": "test/dummy/config/storage.yml",
    "content": "test:\n  service: Disk\n  root: <%= Rails.root.join(\"tmp/storage\") %>\n\nlocal:\n  service: Disk\n  root: <%= Rails.root.join(\"storage\") %>\n\n# Use bin/rails credentials:edit to set the AWS secrets (as aws:access_key_id|secret_access_key)\n# amazon:\n#   service: S3\n#   access_key_id: <%= Rails.application.credentials.dig(:aws, :access_key_id) %>\n#   secret_access_key: <%= Rails.application.credentials.dig(:aws, :secret_access_key) %>\n#   region: us-east-1\n#   bucket: your_own_bucket-<%= Rails.env %>\n\n# Remember not to checkin your GCS keyfile to a repository\n# google:\n#   service: GCS\n#   project: your_project\n#   credentials: <%= Rails.root.join(\"path/to/gcs.keyfile\") %>\n#   bucket: your_own_bucket-<%= Rails.env %>\n\n# Use bin/rails credentials:edit to set the Azure Storage secret (as azure_storage:storage_access_key)\n# microsoft:\n#   service: AzureStorage\n#   storage_account_name: your_account_name\n#   storage_access_key: <%= Rails.application.credentials.dig(:azure_storage, :storage_access_key) %>\n#   container: your_container_name-<%= Rails.env %>\n\n# mirror:\n#   service: Mirror\n#   primary: local\n#   mirrors: [ amazon, google, microsoft ]\n"
  },
  {
    "path": "test/dummy/config.ru",
    "content": "# This file is used by Rack-based servers to start the application.\n\nrequire_relative \"config/environment\"\n\nrun Rails.application\nRails.application.load_server\n"
  },
  {
    "path": "test/dummy/db/migrate/20240611180748_create_users.rb",
    "content": "class CreateUsers < ActiveRecord::Migration[7.2]\n  def change\n    create_table :users do |t|\n      t.string :name\n\n      t.timestamps\n    end\n  end\nend\n"
  },
  {
    "path": "test/dummy/db/schema.rb",
    "content": "# 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# This file is the source Rails uses to define your schema when running `bin/rails\n# db:schema:load`. When creating a new database, `bin/rails db:schema:load` tends to\n# be faster and is potentially less error prone than running all of your\n# migrations from scratch. Old migrations may fail to apply correctly if those\n# migrations use external dependencies or application code.\n#\n# It's strongly recommended that you check this file into your version control system.\n\nActiveRecord::Schema[7.2].define(version: 2024_07_01_172643) do\n  create_table \"refer_referral_codes\", force: :cascade do |t|\n    t.string \"referrer_type\", null: false\n    t.integer \"referrer_id\", null: false\n    t.string \"code\", null: false\n    t.datetime \"created_at\", null: false\n    t.datetime \"updated_at\", null: false\n    t.integer \"referrals_count\", default: 0\n    t.integer \"visits_count\", default: 0\n    t.index [ \"code\" ], name: \"index_refer_referral_codes_on_code\", unique: true\n    t.index [ \"referrer_type\", \"referrer_id\" ], name: \"index_refer_referral_codes_on_referrer\"\n  end\n\n  create_table \"refer_referrals\", force: :cascade do |t|\n    t.string \"referrer_type\", null: false\n    t.integer \"referrer_id\", null: false\n    t.string \"referee_type\", null: false\n    t.integer \"referee_id\", null: false\n    t.integer \"referral_code_id\"\n    t.datetime \"created_at\", null: false\n    t.datetime \"updated_at\", null: false\n    t.datetime \"completed_at\"\n    t.index [ \"referee_type\", \"referee_id\" ], name: \"index_refer_referrals_on_referee\"\n    t.index [ \"referral_code_id\" ], name: \"index_refer_referrals_on_referral_code_id\"\n    t.index [ \"referrer_type\", \"referrer_id\" ], name: \"index_refer_referrals_on_referrer\"\n  end\n\n  create_table \"refer_visits\", force: :cascade do |t|\n    t.integer \"referral_code_id\", null: false\n    t.string \"ip\"\n    t.text \"user_agent\"\n    t.text \"referrer\"\n    t.string \"referring_domain\"\n    t.datetime \"created_at\", null: false\n    t.datetime \"updated_at\", null: false\n    t.index [ \"referral_code_id\" ], name: \"index_refer_visits_on_referral_code_id\"\n  end\n\n  create_table \"users\", force: :cascade do |t|\n    t.string \"name\"\n    t.datetime \"created_at\", null: false\n    t.datetime \"updated_at\", null: false\n  end\n\n  add_foreign_key \"refer_visits\", \"refer_referral_codes\", column: \"referral_code_id\"\nend\n"
  },
  {
    "path": "test/dummy/lib/assets/.keep",
    "content": ""
  },
  {
    "path": "test/dummy/log/.keep",
    "content": ""
  },
  {
    "path": "test/dummy/public/404.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>The page you were looking for doesn't exist (404)</title>\n  <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n  <style>\n  .rails-default-error-page {\n    background-color: #EFEFEF;\n    color: #2E2F30;\n    text-align: center;\n    font-family: arial, sans-serif;\n    margin: 0;\n  }\n\n  .rails-default-error-page div.dialog {\n    width: 95%;\n    max-width: 33em;\n    margin: 4em auto 0;\n  }\n\n  .rails-default-error-page div.dialog > div {\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #BBB;\n    border-top: #B00100 solid 4px;\n    border-top-left-radius: 9px;\n    border-top-right-radius: 9px;\n    background-color: white;\n    padding: 7px 12% 0;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n\n  .rails-default-error-page h1 {\n    font-size: 100%;\n    color: #730E15;\n    line-height: 1.5em;\n  }\n\n  .rails-default-error-page div.dialog > p {\n    margin: 0 0 1em;\n    padding: 1em;\n    background-color: #F7F7F7;\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #999;\n    border-bottom-left-radius: 4px;\n    border-bottom-right-radius: 4px;\n    border-top-color: #DADADA;\n    color: #666;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n  </style>\n</head>\n\n<body class=\"rails-default-error-page\">\n  <!-- This file lives in public/404.html -->\n  <div class=\"dialog\">\n    <div>\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    <p>If you are the application owner check the logs for more information.</p>\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "test/dummy/public/406-unsupported-browser.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>Your browser is not supported (406)</title>\n  <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n  <style>\n  .rails-default-error-page {\n    background-color: #EFEFEF;\n    color: #2E2F30;\n    text-align: center;\n    font-family: arial, sans-serif;\n    margin: 0;\n  }\n\n  .rails-default-error-page div.dialog {\n    width: 95%;\n    max-width: 33em;\n    margin: 4em auto 0;\n  }\n\n  .rails-default-error-page div.dialog > div {\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #BBB;\n    border-top: #B00100 solid 4px;\n    border-top-left-radius: 9px;\n    border-top-right-radius: 9px;\n    background-color: white;\n    padding: 7px 12% 0;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n\n  .rails-default-error-page h1 {\n    font-size: 100%;\n    color: #730E15;\n    line-height: 1.5em;\n  }\n\n  .rails-default-error-page div.dialog > p {\n    margin: 0 0 1em;\n    padding: 1em;\n    background-color: #F7F7F7;\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #999;\n    border-bottom-left-radius: 4px;\n    border-bottom-right-radius: 4px;\n    border-top-color: #DADADA;\n    color: #666;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n  </style>\n</head>\n\n<body class=\"rails-default-error-page\">\n  <!-- This file lives in public/406-unsupported-browser.html -->\n  <div class=\"dialog\">\n    <div>\n      <h1>Your browser is not supported.</h1>\n      <p>Please upgrade your browser to continue.</p>\n    </div>\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "test/dummy/public/422.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>The change you wanted was rejected (422)</title>\n  <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n  <style>\n  .rails-default-error-page {\n    background-color: #EFEFEF;\n    color: #2E2F30;\n    text-align: center;\n    font-family: arial, sans-serif;\n    margin: 0;\n  }\n\n  .rails-default-error-page div.dialog {\n    width: 95%;\n    max-width: 33em;\n    margin: 4em auto 0;\n  }\n\n  .rails-default-error-page div.dialog > div {\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #BBB;\n    border-top: #B00100 solid 4px;\n    border-top-left-radius: 9px;\n    border-top-right-radius: 9px;\n    background-color: white;\n    padding: 7px 12% 0;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n\n  .rails-default-error-page h1 {\n    font-size: 100%;\n    color: #730E15;\n    line-height: 1.5em;\n  }\n\n  .rails-default-error-page div.dialog > p {\n    margin: 0 0 1em;\n    padding: 1em;\n    background-color: #F7F7F7;\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #999;\n    border-bottom-left-radius: 4px;\n    border-bottom-right-radius: 4px;\n    border-top-color: #DADADA;\n    color: #666;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n  </style>\n</head>\n\n<body class=\"rails-default-error-page\">\n  <!-- This file lives in public/422.html -->\n  <div class=\"dialog\">\n    <div>\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    <p>If you are the application owner check the logs for more information.</p>\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "test/dummy/public/500.html",
    "content": "<!DOCTYPE html>\n<html>\n<head>\n  <title>We're sorry, but something went wrong (500)</title>\n  <meta name=\"viewport\" content=\"width=device-width,initial-scale=1\">\n  <style>\n  .rails-default-error-page {\n    background-color: #EFEFEF;\n    color: #2E2F30;\n    text-align: center;\n    font-family: arial, sans-serif;\n    margin: 0;\n  }\n\n  .rails-default-error-page div.dialog {\n    width: 95%;\n    max-width: 33em;\n    margin: 4em auto 0;\n  }\n\n  .rails-default-error-page div.dialog > div {\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #BBB;\n    border-top: #B00100 solid 4px;\n    border-top-left-radius: 9px;\n    border-top-right-radius: 9px;\n    background-color: white;\n    padding: 7px 12% 0;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n\n  .rails-default-error-page h1 {\n    font-size: 100%;\n    color: #730E15;\n    line-height: 1.5em;\n  }\n\n  .rails-default-error-page div.dialog > p {\n    margin: 0 0 1em;\n    padding: 1em;\n    background-color: #F7F7F7;\n    border: 1px solid #CCC;\n    border-right-color: #999;\n    border-left-color: #999;\n    border-bottom-color: #999;\n    border-bottom-left-radius: 4px;\n    border-bottom-right-radius: 4px;\n    border-top-color: #DADADA;\n    color: #666;\n    box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);\n  }\n  </style>\n</head>\n\n<body class=\"rails-default-error-page\">\n  <!-- This file lives in public/500.html -->\n  <div class=\"dialog\">\n    <div>\n      <h1>We're sorry, but something went wrong.</h1>\n    </div>\n    <p>If you are the application owner check the logs for more information.</p>\n  </div>\n</body>\n</html>\n"
  },
  {
    "path": "test/fixtures/files/.keep",
    "content": ""
  },
  {
    "path": "test/fixtures/refer/referral_codes.yml",
    "content": "# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html\n\none:\n  referrer: one (User)\n  code: chris\n\ntwo:\n  referrer: two (User)\n  code: bob\n"
  },
  {
    "path": "test/fixtures/refer/referrals.yml",
    "content": "# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html\n\none:\n  referrer: one (User)\n  referee: two (User)\n  referral_code: one\n"
  },
  {
    "path": "test/fixtures/refer/visits.yml",
    "content": "# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html\n\none:\n  referral_code: one\n  ip: MyString\n  user_agent: MyText\n  referrer: MyText\n  referring_domain: MyString\n\ntwo:\n  referral_code: two\n  ip: MyString\n  user_agent: MyText\n  referrer: MyText\n  referring_domain: MyString\n"
  },
  {
    "path": "test/fixtures/users.yml",
    "content": "# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html\n\none:\n  name: Chris\n\ntwo:\n  name: Bob\n\nnew:\n  name: David\n"
  },
  {
    "path": "test/integration/.keep",
    "content": ""
  },
  {
    "path": "test/integration/referral_test.rb",
    "content": "require \"test_helper\"\n\nclass ReferralIntegrationTest < ActionDispatch::IntegrationTest\n  test \"referral is created\" do\n    assert_difference \"Refer::Referral.count\" do\n      post refer_path(ref: refer_referral_codes(:one), user_id: users(:new).id)\n    end\n  end\n\n  test \"doesn't set referral cookie if param missing\" do\n    get root_path(other: \"example\")\n    assert_nil cookies[Refer.cookie_name]\n  end\n\n  test \"sets referral cookie\" do\n    referral_code = refer_referral_codes(:one)\n    get root_path(ref: referral_code)\n    assert_equal referral_code.to_param, cookies[Refer.cookie_name]\n  end\n\n  test \"tracks visits\" do\n    referral_code = refer_referral_codes(:one)\n    assert_difference \"referral_code.reload.visits_count\" do\n      get root_path(ref: referral_code)\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/.keep",
    "content": ""
  },
  {
    "path": "test/models/refer/referral_code_test.rb",
    "content": "require \"test_helper\"\nrequire \"minitest/mock\"\n\n\nclass Refer::ReferralCodeTest < ActiveSupport::TestCase\n  test \"deleting referral code doesn't delete referral\" do\n    referral = refer_referrals(:one)\n    assert_not_nil referral.referral_code\n    assert_no_difference \"Refer::Referral.count\" do\n      referral.referral_code.destroy\n    end\n    referral.reload\n    assert_nil referral.referral_code\n  end\n\n  test \"referral codes are dependent destroyed\" do\n    assert_difference \"Refer::ReferralCode.count\", -1 do\n      users(:one).destroy\n    end\n  end\n\n  test \"generates referral codes automatically\" do\n    Refer.stub :code_generator, -> { ->(referrer) { SecureRandom.alphanumeric(8) } } do\n      assert_not_nil users(:one).referral_codes.create!.code\n    end\n  end\n\n  test \"does not generate referral code automatically if empty generator config\" do\n    Refer.stub :code_generator, nil do\n      assert_nil users(:one).referral_codes.create.code\n    end\n  end\n\n  test \"does not generate referral code automatically if using a custom code\" do\n    Refer.stub :code_generator, ->(referrer) { SecureRandom.alphanumeric(8) } do\n      custom_referral = users(:one).referral_codes.create(code: \"custom\")\n      assert_equal custom_referral.code, \"custom\"\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/refer/referral_test.rb",
    "content": "require \"test_helper\"\n\nclass Refer::ReferralTest < ActiveSupport::TestCase\n  test \"referrals are dependent destroyed\" do\n    assert_difference \"Refer::Referral.count\", -1 do\n      users(:one).destroy\n    end\n  end\n\n  test \"can be associated with a referral code\" do\n    assert_equal refer_referral_codes(:one), refer_referrals(:one).referral_code\n  end\n\n  test \"can be completed\" do\n    referral = refer_referrals(:one)\n    assert_nil referral.completed_at\n\n    travel_to Time.current do\n      referral.complete!\n      assert_equal Time.current, referral.completed_at\n    end\n  end\n\n  test \"complete with custom attributes\" do\n    referral = refer_referrals(:one)\n    assert_nil referral.completed_at\n\n    travel_to Time.current do\n      referral.complete!(completed_at: 1.hour.ago)\n      assert_equal 1.hour.ago, referral.completed_at\n    end\n  end\n\n  test \"complete! doesn't override previous completion\" do\n    referral = refer_referrals(:one)\n    assert_nil referral.completed_at\n\n    referral.complete!\n\n    travel_to Time.current + 1.hour do\n      assert_no_difference \"referral.completed_at\" do\n        referral.complete!\n      end\n    end\n  end\nend\n"
  },
  {
    "path": "test/models/refer/visit_test.rb",
    "content": "require \"test_helper\"\n\nmodule Refer\n  class VisitTest < ActiveSupport::TestCase\n    test \"masks ips\" do\n      assert_equal \"127.0.0.0\", Refer::Visit.new(ip: \"127.0.0.1\").ip\n    end\n\n    test \"referring_domain\" do\n      request = ActiveSupport::OrderedOptions.new.merge(referrer: \"https://gorails.com/episodes/1\")\n      assert_equal \"gorails.com\", Refer::Visit.from_request(request).referring_domain\n    end\n  end\nend\n"
  },
  {
    "path": "test/refer_test.rb",
    "content": "require \"test_helper\"\n\nclass ReferTest < ActiveSupport::TestCase\n  test \"it has a version number\" do\n    assert Refer::VERSION\n  end\n\n  test \"refer\" do\n    assert_difference \"Refer::Referral.count\" do\n      Refer.refer(code: refer_referral_codes(:one).code, referee: users(:new))\n    end\n  end\n\n  test \"refer invalid code\" do\n    assert_raises ActiveRecord::RecordNotFound do\n      Refer.refer!(code: \"invalid\", referee: users(:new))\n    end\n  end\n\n  test \"refer self\" do\n    assert_no_difference \"Refer::Referral.count\" do\n      Refer.refer(code: refer_referral_codes(:one).code, referee: users(:one))\n    end\n\n    assert_raises ActiveRecord::RecordInvalid, \"Validation failed: Self-referrals are not allowed\" do\n      Refer.refer!(code: refer_referral_codes(:one).code, referee: users(:one))\n    end\n  end\n\n  test \"refer already referred\" do\n    assert_no_difference \"Refer::Referral.count\" do\n      Refer.refer(code: refer_referral_codes(:one).code, referee: users(:two))\n    end\n\n    assert_raises Refer::AlreadyReferred do\n      Refer.refer!(code: refer_referral_codes(:one).code, referee: users(:two))\n    end\n  end\n\n  test \"referred?\" do\n    assert Refer.referred?(users(:two))\n    assert_not Refer.referred?(users(:new))\n  end\n\n  test \"referral_codes\" do\n    assert_includes users(:one).referral_codes, refer_referral_codes(:one)\n  end\n\n  test \"referrals\" do\n    assert_includes users(:one).referrals, refer_referrals(:one)\n  end\n\n  test \"referral\" do\n    assert_equal refer_referrals(:one), users(:two).referral\n  end\n\n  test \"referrer\" do\n    assert_equal users(:one), users(:two).referrer\n  end\n\n  test \"referrer when nil\" do\n    assert_nil users(:new).referrer\n  end\n\n  test \"referral_completed callback\" do\n    old_callback = Refer.referral_completed\n    referral = refer_referrals(:one)\n    assert_not referral.completed_at?\n\n    completed = nil\n    Refer.referral_completed = ->(referral) {\n      completed = referral\n    }\n\n    # Called the first time a referral is completed\n    referral.complete!\n    assert_equal referral, completed\n\n    # Does not get called second time because referral was already completed\n    completed = nil\n    referral.complete!\n    assert_nil completed\n  ensure\n    Refer.referral_completed = old_callback\n  end\nend\n"
  },
  {
    "path": "test/test_helper.rb",
    "content": "# Configure Rails Environment\nENV[\"RAILS_ENV\"] = \"test\"\n\nrequire_relative \"../test/dummy/config/environment\"\nActiveRecord::Migrator.migrations_paths = [ File.expand_path(\"../test/dummy/db/migrate\", __dir__) ]\nrequire \"rails/test_help\"\n\n# Load fixtures from the engine\nif ActiveSupport::TestCase.respond_to?(:fixture_paths=)\n  ActiveSupport::TestCase.fixture_paths = [ File.expand_path(\"fixtures\", __dir__) ]\n  ActionDispatch::IntegrationTest.fixture_paths = ActiveSupport::TestCase.fixture_paths\n  ActiveSupport::TestCase.file_fixture_path = File.expand_path(\"fixtures\", __dir__) + \"/files\"\n  ActiveSupport::TestCase.fixtures :all\nend\n"
  }
]