From d3363c7e31c42d6d206fc491baf2421b79996334 Mon Sep 17 00:00:00 2001 From: jmeridth Date: Fri, 16 Feb 2024 15:59:28 -0600 Subject: [PATCH] chore: standardize repository for procore open-source - [x] setup .github folder (actions, dependabot.yaml, ISSUE_TEMPLATES, PULL_REQUEST_TEMPLATE.md, CODEOWNERS) - [x] setup required files (README.md, SECURITY.md, CODE_OF_CONDUCT.md, LICENSE.md, CONTRIBUTING.md) - [x] update gemspec file - [x] setup postgres in tests in GitHub actions - [x] add EMERITUS mentioning former upstream contributors - [x] update LICENSE.md with previous owners - [x] setup dummy rails app in specs folder Signed-off-by: jmeridth --- .github/CODEOWNERS | 1 + .github/ISSUE_TEMPLATE/bug.yml | 66 ++++++++ .github/ISSUE_TEMPLATE/config.yml | 1 + .github/ISSUE_TEMPLATE/docs.yml | 18 ++ .github/ISSUE_TEMPLATE/feature-request.yml | 36 ++++ .github/ISSUE_TEMPLATE/question-support.yml | 18 ++ .github/PULL_REQUEST_TEMPLATE.md | 17 ++ .github/dependabot.yaml | 20 +++ .github/workflows/auto-assign-author.yaml | 13 ++ .github/workflows/codeql.yaml | 43 +++++ .github/workflows/release.yaml | 40 +++++ .github/workflows/stale.yaml | 38 +++++ .github/workflows/test.yaml | 55 ++++++ CODE_OF_CONDUCT.md | 130 ++++++++++++++ CONTRIBUTING.md | 37 ++++ EMERITUS.md | 3 + LICENSE.txt => LICENSE.md | 3 +- README.md | 35 ++-- SECURITY.md | 19 +++ rspec_profiling.gemspec | 15 +- spec/dummy/.gitignore | 2 + spec/dummy/.rspec | 2 + spec/dummy/Gemfile | 13 ++ spec/dummy/README.md | 3 + spec/dummy/Rakefile | 6 + spec/dummy/app/assets/config/manifest.js | 0 spec/dummy/app/assets/images/.keep | 0 .../app/assets/javascripts/application.js | 13 ++ .../app/assets/stylesheets/application.css | 15 ++ .../app/controllers/application_controller.rb | 5 + spec/dummy/app/controllers/concerns/.keep | 0 spec/dummy/app/helpers/application_helper.rb | 2 + spec/dummy/app/mailers/.keep | 0 spec/dummy/app/models/.keep | 0 spec/dummy/app/models/concerns/.keep | 0 .../app/views/layouts/application.html.erb | 14 ++ spec/dummy/bin/bundle | 3 + spec/dummy/bin/rails | 4 + spec/dummy/bin/rake | 4 + spec/dummy/bin/rspec | 16 ++ spec/dummy/bin/setup | 29 ++++ spec/dummy/config.ru | 4 + spec/dummy/config/application.rb | 22 +++ spec/dummy/config/boot.rb | 5 + spec/dummy/config/database.yml | 8 + spec/dummy/config/environment.rb | 5 + spec/dummy/config/environments/development.rb | 41 +++++ spec/dummy/config/environments/production.rb | 79 +++++++++ spec/dummy/config/environments/test.rb | 49 ++++++ spec/dummy/config/initializers/assets.rb | 11 ++ .../initializers/backtrace_silencers.rb | 7 + .../config/initializers/cookies_serializer.rb | 3 + .../initializers/filter_parameter_logging.rb | 4 + spec/dummy/config/initializers/inflections.rb | 16 ++ spec/dummy/config/initializers/mime_types.rb | 4 + .../config/initializers/session_store.rb | 3 + .../config/initializers/wrap_parameters.rb | 14 ++ spec/dummy/config/locales/en.yml | 23 +++ spec/dummy/config/routes.rb | 3 + spec/dummy/config/secrets.yml | 22 +++ spec/dummy/db/migrate/.keep | 0 spec/dummy/lib/assets/.keep | 0 spec/dummy/public/404.html | 67 ++++++++ spec/dummy/public/422.html | 67 ++++++++ spec/dummy/public/500.html | 66 ++++++++ spec/dummy/public/favicon.ico | 0 spec/dummy/spec/handcuffs_rake_spec.rb | 159 ++++++++++++++++++ spec/dummy/spec/spec_helper.rb | 125 ++++++++++++++ .../spec/support/shared_contexts/rake.rb | 20 +++ 69 files changed, 1536 insertions(+), 30 deletions(-) create mode 100644 .github/CODEOWNERS create mode 100644 .github/ISSUE_TEMPLATE/bug.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/docs.yml create mode 100644 .github/ISSUE_TEMPLATE/feature-request.yml create mode 100644 .github/ISSUE_TEMPLATE/question-support.yml create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/dependabot.yaml create mode 100644 .github/workflows/auto-assign-author.yaml create mode 100644 .github/workflows/codeql.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .github/workflows/stale.yaml create mode 100644 .github/workflows/test.yaml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 EMERITUS.md rename LICENSE.txt => LICENSE.md (92%) create mode 100644 SECURITY.md create mode 100644 spec/dummy/.gitignore create mode 100644 spec/dummy/.rspec create mode 100644 spec/dummy/Gemfile create mode 100644 spec/dummy/README.md create mode 100644 spec/dummy/Rakefile create mode 100644 spec/dummy/app/assets/config/manifest.js create mode 100644 spec/dummy/app/assets/images/.keep create mode 100644 spec/dummy/app/assets/javascripts/application.js create mode 100644 spec/dummy/app/assets/stylesheets/application.css create mode 100644 spec/dummy/app/controllers/application_controller.rb create mode 100644 spec/dummy/app/controllers/concerns/.keep create mode 100644 spec/dummy/app/helpers/application_helper.rb create mode 100644 spec/dummy/app/mailers/.keep create mode 100644 spec/dummy/app/models/.keep create mode 100644 spec/dummy/app/models/concerns/.keep create mode 100644 spec/dummy/app/views/layouts/application.html.erb create mode 100755 spec/dummy/bin/bundle create mode 100755 spec/dummy/bin/rails create mode 100755 spec/dummy/bin/rake create mode 100755 spec/dummy/bin/rspec create mode 100755 spec/dummy/bin/setup create mode 100644 spec/dummy/config.ru create mode 100644 spec/dummy/config/application.rb create mode 100644 spec/dummy/config/boot.rb create mode 100644 spec/dummy/config/database.yml create mode 100644 spec/dummy/config/environment.rb create mode 100644 spec/dummy/config/environments/development.rb create mode 100644 spec/dummy/config/environments/production.rb create mode 100644 spec/dummy/config/environments/test.rb create mode 100644 spec/dummy/config/initializers/assets.rb create mode 100644 spec/dummy/config/initializers/backtrace_silencers.rb create mode 100644 spec/dummy/config/initializers/cookies_serializer.rb create mode 100644 spec/dummy/config/initializers/filter_parameter_logging.rb create mode 100644 spec/dummy/config/initializers/inflections.rb create mode 100644 spec/dummy/config/initializers/mime_types.rb create mode 100644 spec/dummy/config/initializers/session_store.rb create mode 100644 spec/dummy/config/initializers/wrap_parameters.rb create mode 100644 spec/dummy/config/locales/en.yml create mode 100644 spec/dummy/config/routes.rb create mode 100644 spec/dummy/config/secrets.yml create mode 100644 spec/dummy/db/migrate/.keep create mode 100644 spec/dummy/lib/assets/.keep create mode 100644 spec/dummy/public/404.html create mode 100644 spec/dummy/public/422.html create mode 100644 spec/dummy/public/500.html create mode 100644 spec/dummy/public/favicon.ico create mode 100644 spec/dummy/spec/handcuffs_rake_spec.rb create mode 100644 spec/dummy/spec/spec_helper.rb create mode 100644 spec/dummy/spec/support/shared_contexts/rake.rb diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS new file mode 100644 index 0000000..30081b1 --- /dev/null +++ b/.github/CODEOWNERS @@ -0,0 +1 @@ +* @procore-oss/procore-ospo diff --git a/.github/ISSUE_TEMPLATE/bug.yml b/.github/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 0000000..bd3c1c9 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug.yml @@ -0,0 +1,66 @@ +name: 🐞 Bug +description: File a bug/issue +title: "[bug] " +labels: [bug, needs-triage] +body: +- type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please search to see if an issue already exists for the bug you encountered. + options: + - label: I have searched the existing issues + required: true +- type: checkboxes + attributes: + label: Is this a regression? + description: Did this behavior work before? + options: + - label: Yes, this used to work before + required: false +- type: textarea + attributes: + label: Current Behavior + description: A concise description of what you're experiencing. + validations: + required: false +- type: textarea + attributes: + label: Expected Behavior + description: A concise description of what you expected to happen. + validations: + required: false +- type: textarea + attributes: + label: Steps To Reproduce + description: Steps to reproduce the behavior. + placeholder: | + 1. + 2. + 3. + 4. + validations: + required: true +- type: textarea + attributes: + label: Environment + description: | + examples: + - **OS**: OSX 13.3.1 + - **Browser Name and Version**: Chrome Version 112.0.5615.49 (Official Build) (arm64) + - **Ruby Version**: 3.0.0 + value: | + - OS: + - Browser Name and version: + - Ruby Version: + render: markdown + validations: + required: true +- type: textarea + attributes: + label: Anything else? + description: | + Links? References? Anything that will give us more context about the issue you are encountering! + + Tip: You can attach images or log files by clicking this area to highlight it and then dragging files in. + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..3ba13e0 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1 @@ +blank_issues_enabled: false diff --git a/.github/ISSUE_TEMPLATE/docs.yml b/.github/ISSUE_TEMPLATE/docs.yml new file mode 100644 index 0000000..387c39d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/docs.yml @@ -0,0 +1,18 @@ +name: 📚 Documentation or README.md issue report +description: File a bug/issue for docs or README.md +title: "[bug] <title>" +labels: [docs, needs-triage] +body: +- type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please search to see if an issue already exists for the bug you encountered. + options: + - label: I have searched the existing issues + required: true +- type: textarea + attributes: + label: Docs/README.md Part to update + description: A concise description of what you thing should be updated + validations: + required: true diff --git a/.github/ISSUE_TEMPLATE/feature-request.yml b/.github/ISSUE_TEMPLATE/feature-request.yml new file mode 100644 index 0000000..e51081f --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature-request.yml @@ -0,0 +1,36 @@ +name: 🚀🆕 Feature Request +description: Suggest an idea or possible new feature for this project +title: "[Feature Request] <title>" +labels: [feature, needs-triage] +body: +- type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please search to see if an issue already exists for the bug you encountered. + options: + - label: I have searched the existing issues + required: true +- type: textarea + attributes: + label: Is your feature request related to a problem? Please describe + description: A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + validations: + required: true +- type: textarea + attributes: + label: Describe the feature you'd like to see implemented + description: A clear and concise description of what you want to happen + validations: + required: true +- type: textarea + attributes: + label: Describe alternatives you've considered + description: A clear and concise description of any alternative solutions or features you've considered + validations: + required: false +- type: textarea + attributes: + label: Additional context + description: Add any other context or additional information about the problem here + validations: + required: false diff --git a/.github/ISSUE_TEMPLATE/question-support.yml b/.github/ISSUE_TEMPLATE/question-support.yml new file mode 100644 index 0000000..c37ec1d --- /dev/null +++ b/.github/ISSUE_TEMPLATE/question-support.yml @@ -0,0 +1,18 @@ +name: ❓ Question or Support Request +description: Questions and requests for support +title: "[Question/Support] <title>" +labels: [question, support, needs-triage] +body: +- type: checkboxes + attributes: + label: Is there an existing issue for this? + description: Please search to see if an issue already exists for the bug you encountered. + options: + - label: I have searched the existing issues + required: true +- type: textarea + attributes: + label: Describe your question or ask for support + description: A concise description of what you would like support with + validations: + required: true diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..d2bc47b --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,17 @@ +Checklist: + +* [ ] I have updated the necessary documentation +* [ ] I have signed off all my commits as required by [DCO](https://github.com/procore-oss/rspec_profiling/blob/main/CONTRIBUTING.md) +* [ ] My build is green + +<!-- +Note on DCO: + +If the DCO check fails, one or more of your commits are not signed off. Please click on the *Details* link next to the DCO action for instructions on how to resolve this. + +TL;DR - You need to sign off your commits with `git commit -s` or `git commit --signoff` to indicate that you agree to the terms of the DCO. + +Note on Versioning: + +Maintainers will bump the version and do a release when they are ready to release (possibly multiple merged PRs). Please do not bump the version in your PRs. +--> diff --git a/.github/dependabot.yaml b/.github/dependabot.yaml new file mode 100644 index 0000000..a69deb7 --- /dev/null +++ b/.github/dependabot.yaml @@ -0,0 +1,20 @@ +version: 2 +updates: + - package-ecosystem: "github-actions" + directory: / + schedule: + interval: "weekly" + timezone: "America/Los_Angeles" + labels: + - "dependabot" + - "dependencies" + - "github-actions" + - package-ecosystem: "bundler" + directory: / + schedule: + interval: "weekly" + timezone: "America/Los_Angeles" + labels: + - "dependabot" + - "dependencies" + - "bundler" diff --git a/.github/workflows/auto-assign-author.yaml b/.github/workflows/auto-assign-author.yaml new file mode 100644 index 0000000..9cb6711 --- /dev/null +++ b/.github/workflows/auto-assign-author.yaml @@ -0,0 +1,13 @@ +name: 'Auto Author Assign' + +on: + pull_request_target: + types: [opened, reopened] + +jobs: + assign-author: + runs-on: ubuntu-latest + steps: + - uses: toshimaru/auto-author-assign@v2.1.0 + with: + repo-token: "${{ secrets.GITHUB_TOKEN }}" diff --git a/.github/workflows/codeql.yaml b/.github/workflows/codeql.yaml new file mode 100644 index 0000000..0b9343e --- /dev/null +++ b/.github/workflows/codeql.yaml @@ -0,0 +1,43 @@ +name: "Custom CodeQL" + +on: + workflow_dispatch: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +permissions: + contents: read + +jobs: + analyze: + name: Analyze + runs-on: Ubuntu-latest + timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }} + permissions: + actions: read + contents: read + security-events: write + + strategy: + fail-fast: false + matrix: + language: [ 'ruby' ] + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Initialize CodeQL + uses: github/codeql-action/init@v3 + with: + languages: ${{ matrix.language }} + + - name: Autobuild + uses: github/codeql-action/autobuild@v3 + + - name: Perform CodeQL Analysis + uses: github/codeql-action/analyze@v3 + with: + category: "/language:${{matrix.language}}" diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..13ad88c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,40 @@ +name: Release +on: + workflow_run: + workflows: [Test] + types: [completed] + branches: [master, main] + workflow_dispatch: # allow manual deployment through GitHub Action UI +jobs: + release: + runs-on: ubuntu-latest + if: ${{ github.event_name == 'workflow_dispatch' || github.event.workflow_run.conclusion == 'success' }} + steps: + - uses: actions/checkout@v4 + - name: Version file changed + id: version-file-changed + uses: tj-actions/changed-files@v42 + with: + files: lib/blueprinter/version.rb + - name: Set up Ruby + if: ${{ github.event_name == 'workflow_dispatch' || steps.version-file-changed.outputs.any_changed == 'true' }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.2 + bundler-cache: true + - name: Installing dependencies + if: ${{ github.event_name == 'workflow_dispatch' || steps.version-file-changed.outputs.any_changed == 'true' }} + run: bundle check --path=vendor/bundle || bundle install --path=vendor/bundle + - name: Build gem file + if: ${{ github.event_name == 'workflow_dispatch' || steps.version-file-changed.outputs.any_changed == 'true' }} + run: bundle exec rake build + - uses: fac/ruby-gem-setup-credentials-action@v2 + if: ${{ github.event_name == 'workflow_dispatch' || steps.version-file-changed.outputs.any_changed == 'true' }} + with: + user: "" + key: rubygems + token: ${{secrets.RUBY_GEMS_API_KEY}} + - uses: fac/ruby-gem-push-action@v2 + if: ${{ github.event_name == 'workflow_dispatch' || steps.version-file-changed.outputs.any_changed == 'true' }} + with: + key: rubygems diff --git a/.github/workflows/stale.yaml b/.github/workflows/stale.yaml new file mode 100644 index 0000000..8b15e9c --- /dev/null +++ b/.github/workflows/stale.yaml @@ -0,0 +1,38 @@ +## Reference: https://github.com/actions/stale +name: Mark stale issues and pull requests +on: + schedule: + - cron: "30 1 * * *" + +permissions: + contents: read + +jobs: + stale: + permissions: + issues: write # for actions/stale to close stale issues + pull-requests: write # for actions/stale to close stale PRs + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v9 + with: + repo-token: ${{ secrets.GITHUB_TOKEN }} + # Number of days of inactivity before an issue becomes stale + days-before-stale: 60 + # Number of days of inactivity before a stale issue is closed + days-before-close: 7 + # Issues with these labels will never be considered stale + exempt-issue-labels: "on-hold,pinned,security" + exempt-pr-labels: "on-hold,pinned,security" + # Comment to post when marking an issue as stale. + stale-issue-message: > + This issue has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + stale-pr-message: > + This pull request has been automatically marked as stale because it has not had + recent activity. It will be closed if no further activity occurs. Thank you + for your contributions. + # Label to use when marking an issue as stale + stale-issue-label: 'no-issue-activity' + stale-pr-label: 'no-pr-activity' diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml new file mode 100644 index 0000000..07a5e29 --- /dev/null +++ b/.github/workflows/test.yaml @@ -0,0 +1,55 @@ +name: Test +on: + push: + branches: [master, main] + pull_request: + branches: [master, main] +permissions: + contents: read +jobs: + test: + env: + ENVIRONMENT: test + POSTGRES_DATABASE: rspec_profiling_test + POSTGRES_HOST: localhost + POSTGRES_DB_PASSWORD: mypassword + POSTGRES_DB_USERNAME: myuser + strategy: + matrix: + #ruby: ['2.7', '3.0', '3.1', '3.2', '3.3'] + #postgres: ['16-bullseye', '15-bullseye', '14-bullseye', '13-bullseye', '12-bullseye'] + ruby: ['3.0'] + postgres: ['16-bullseye'] + name: Ruby ${{ matrix.ruby }} - PostgreSQL ${{ matrix.postgres }} + # https://docs.github.com/en/actions/learn-github-actions/expressions#example + runs-on: ${{ matrix.ruby == '2.7' && 'ubuntu-20.04' || 'ubuntu-latest' }} + services: + postgres: + image: postgres:${{ matrix.postgres }} + env: + POSTGRES_HOST: ${{ env.POSTGRES_HOST }} + POSTGRES_DB: ${{ env.POSTGRES_DATABASE}} + POSTGRES_HOST_AUTH_METHOD: trust + POSTGRES_USER: ${{ env.POSTGRES_DB_USERNAME }} + options: >- + --health-cmd pg_isready + --health-interval 10s + --health-timeout 5s + --health-retries 5 + ports: + - 5432:5432 + steps: + - uses: actions/checkout@v4 + - name: Set up Ruby ${{ matrix.ruby }} + uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - name: Installing dependencies + run: bundle install && cd spec/dummy && bundle install + - name: Setup Database in Dummy Rails App + run: cd spec/dummy && bundle exec rake db:create db:migrate --trace RAILS_ENV=${{ env.ENVIRONMENT }} + - name: Initialize rspec_profiling in Dummy Rails App + run: cd spec/dummy && bundle exec rake rspec_profiling:install RAILS_ENV=${{ env.ENVIRONMENT }} + - name: Run specs + run: bundle exec rake diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..c786297 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,130 @@ +# Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Spam or other deceptive practices that take advantage of the community +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders 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, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +<opensource@procore.com>. +All complaints will be reviewed and investigated promptly and fairly by +the Procore Open Source Program Office (OSPO) + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +<https://www.contributor-covenant.org/version/2/0/code_of_conduct.html>. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +<https://www.contributor-covenant.org/faq>. Translations are available at +<https://www.contributor-covenant.org/translations>. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..d5b8ff2 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,37 @@ +# Contributing to Procore Projects + +This document explains the common procedures expected by contributors while submitting code to Procore open source projects. + +## Code of Conduct + +Please read and abide by the [Code of Conduct](CODE_OF_CONDUCT.md) + +## General workflow + +Once a GitHub issue is accepted and assigned to you, please follow general workflow in order to submit your contribution: + +1. Fork the target repository under your GitHub username. +2. Create a branch in your forked repository for the changes you are about to make. +3. Commit your changes in the branch you created in step 2. All commits need to be signed-off. Check the [legal](#legal) section bellow for more details. +4. Push your commits to your remote fork. +5. Create a Pull Request from your remote fork pointing to the HEAD branch (usually `main` branch) of the target repository. +6. Check the GitHub build and ensure that all checks are green. + +## Legal + +Procore projects use Developer Certificate of Origin ([DCO](https://GitHub.com/apps/dco/)). + +Please sign-off your contributions by doing ONE of the following: + +* Use `git commit -s ...` with each commit to add the sign-off or +* Manually add a `Signed-off-by: Your Name <your.email@example.com>` to each commit message. + +The email address must match your primary GitHub email. You do NOT need cryptographic (e.g. gpg) signing. + +* Use `git commit -s --amend ...` to add a sign-off to the latest commit, if you forgot. + +*Note*: Some projects will provide specific configuration to ensure all commits are signed-off. Please check the project's documentation for more details. + +## Tests + +Make sure your changes are properly covered by automated tests. We aim to build an efficient test suite that is low cost to maintain and bring value to project. Prefer writing unit-tests over heavy end-to-end (e2e) tests. However, sometimes e2e tests are necessary. If you aren't sure, ask one of the maintainers about the requirements for your pull-request. diff --git a/EMERITUS.md b/EMERITUS.md new file mode 100644 index 0000000..7a90ec3 --- /dev/null +++ b/EMERITUS.md @@ -0,0 +1,3 @@ +This repo is a fork of <https://github.com/foraker/rspec_profiling>. + +[Former contributors](https://github.com/foraker/rspec_profiling/graphs/contributors) diff --git a/LICENSE.txt b/LICENSE.md similarity index 92% rename from LICENSE.txt rename to LICENSE.md index a30acfd..4b747bd 100644 --- a/LICENSE.txt +++ b/LICENSE.md @@ -1,4 +1,5 @@ -Copyright (c) 2014 Ben Eddy +Copyright (c) 2014-2024 Ben Eddy +Copyright (c) 2024 Procore Technologies, Inc. MIT License diff --git a/README.md b/README.md index 8514a19..6e66f47 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ with interesting attributes. For example, find the slowest specs, or the spec which issues the most queries. Collected attributes include: + - git commit SHA (or SVN revision) and date - example file, line number and description - example status (i.e. passed or failed) @@ -21,32 +22,32 @@ RspecProfiling should work with Rails >= 3.2 and RSpec >= 2.14. Add this line to your application's Gemfile: -``` +```ruby gem 'rspec_profiling' ``` And then execute: -``` +```bash bundle ``` Require the gem to your `spec_helper.rb`. -``` +```ruby require "rspec_profiling/rspec" ``` Lastly, run the installation rake tasks to initialize an empty database in which results will be collected. -``` +```bash bundle exec rake rspec_profiling:install ``` -If you are planning on using `sqlite` or `pg` ensure to add the depency to your gemfile +If you are planning on using `sqlite` or `pg` ensure to add the dependency to your gemfile -``` +```ruby gem 'sqlite', require: false gem 'pg', require: false ``` @@ -89,7 +90,7 @@ RspecProfiling.configure do |config| end ``` -Note that custom events are only currenly reported by the CSV collector. +Note that custom events are only currently reported by the CSV collector. #### Custom Event Recording @@ -125,7 +126,7 @@ end You can review results by running the RspecProfiling console. The console has a preloaded `results` variable. -``` +```bash bundle exec rake rspec_profiling:console > results.count @@ -134,14 +135,14 @@ bundle exec rake rspec_profiling:console You can find the spec that runs the most queries: -``` +```ruby > results.order(:query_count).last.to_s => "Updating my account - ./spec/features/account_spec.rb:15" ``` Or find the spec that takes the most time: -``` +```ruby > results.order(:time).last.to_s => "Updating my account - ./spec/features/account_spec.rb:15" ``` @@ -216,16 +217,4 @@ To remove the results database, run `bundle exec rake rspec_profiling:uninstall` ## Contributing -1. Fork it -2. Create your feature branch (`git checkout -b my-new-feature`) -3. Commit your changes (`git commit -am 'Add some feature'`) -4. Push to the branch (`git push origin my-new-feature`) -5. Create new Pull Request - -## About Breakwater - -![Breakwater Logo](https://images.squarespace-cdn.com/content/5d084fe43b0b620001239437/1565926359217-2LQ1BOFAO5846OAYAGZV/breakwater.png?content-type=image%2Fpng) - -Breakwater builds exciting web and mobile apps in Louisville, CO. Our work powers a wide variety of businesses with many different needs. We love open source software, and we're proud to contribute where we can. Interested to learn more? [Contact us today](https://www.breakwaterltd.com/contact). - -This project is maintained by Breakwater. The names and logos of Breakwater are fully owned and copyright Breakwater Limited. +Please read [CONTRIBUTING.md](CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us. diff --git a/SECURITY.md b/SECURITY.md new file mode 100644 index 0000000..b8b622c --- /dev/null +++ b/SECURITY.md @@ -0,0 +1,19 @@ +# Security Policy + +## Supported Versions + +Ruby versions that are currently being supported with security updates. + +| Version | Supported | +| ------- | ------------------ | +| <=2.6 | :x: | +| 2.7 | :white_check_mark: | +| 3.0 | :white_check_mark: | +| 3.1 | :white_check_mark: | +| 3.2 | :white_check_mark: | + +## Reporting a Vulnerability + +Please click the `Report a vulnerability` button [here](https://github.com/procore-oss/blueprinter/security) to report a vulnerability. + +A maintainer will respond to you as soon as possible and discuss the process to get the vulnerability fixed. diff --git a/rspec_profiling.gemspec b/rspec_profiling.gemspec index e5a6eeb..a3bf0ca 100644 --- a/rspec_profiling.gemspec +++ b/rspec_profiling.gemspec @@ -6,24 +6,27 @@ require 'rspec_profiling/version' Gem::Specification.new do |spec| spec.name = "rspec_profiling" spec.version = RspecProfiling::VERSION - spec.authors = ["Ben Eddy"] - spec.email = ["bae@foraker.com"] + spec.authors = ["Prodocore Technologies, Inc."] + spec.email = ["opensource@procore.com"] spec.description = %q{Profile RSpec test suites} spec.summary = %q{Profile RSpec test suites} - spec.homepage = "https://github.com/foraker/rspec_profiling" + spec.homepage = "https://github.com/procore-oss/rspec_profiling" spec.license = "MIT" - spec.files = `git ls-files`.split($/) + spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) } spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) spec.require_paths = ["lib"] spec.add_dependency "activerecord" - spec.add_dependency "rails" spec.add_dependency "get_process_mem" + spec.add_dependency "rails" spec.add_development_dependency "bundler", "> 1.3" + spec.add_development_dependency "pry" spec.add_development_dependency "rake" spec.add_development_dependency "rspec" - spec.add_development_dependency "pry" + + spec.metadata['allowed_push_host'] = 'https://rubygems.org' + spec.metadata['rubygems_mfa_required'] = 'true' end diff --git a/spec/dummy/.gitignore b/spec/dummy/.gitignore new file mode 100644 index 0000000..f8fd028 --- /dev/null +++ b/spec/dummy/.gitignore @@ -0,0 +1,2 @@ +log/ +db/schema.rb diff --git a/spec/dummy/.rspec b/spec/dummy/.rspec new file mode 100644 index 0000000..83e16f8 --- /dev/null +++ b/spec/dummy/.rspec @@ -0,0 +1,2 @@ +--color +--require spec_helper diff --git a/spec/dummy/Gemfile b/spec/dummy/Gemfile new file mode 100644 index 0000000..8a7dd3d --- /dev/null +++ b/spec/dummy/Gemfile @@ -0,0 +1,13 @@ +source 'https://rubygems.org' + +gem 'rspec_profiling', path: "../../" +gem 'pg' +gem 'rails' +gem 'sprockets' + +group :test do + gem 'rspec-rails' + gem 'pry' + gem 'pry-rails' + gem 'pry-byebug' +end diff --git a/spec/dummy/README.md b/spec/dummy/README.md new file mode 100644 index 0000000..b2a3f6f --- /dev/null +++ b/spec/dummy/README.md @@ -0,0 +1,3 @@ +== README + +This is a dummy Rails application we use to test the gem. It is not meant to be used as a real application. It is used to test the gem functionality. diff --git a/spec/dummy/Rakefile b/spec/dummy/Rakefile new file mode 100644 index 0000000..ba6b733 --- /dev/null +++ b/spec/dummy/Rakefile @@ -0,0 +1,6 @@ +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. + +require File.expand_path('../config/application', __FILE__) + +Rails.application.load_tasks diff --git a/spec/dummy/app/assets/config/manifest.js b/spec/dummy/app/assets/config/manifest.js new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/assets/images/.keep b/spec/dummy/app/assets/images/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/assets/javascripts/application.js b/spec/dummy/app/assets/javascripts/application.js new file mode 100644 index 0000000..8913b40 --- /dev/null +++ b/spec/dummy/app/assets/javascripts/application.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// compiled file. +// +// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details +// about supported directives. +// +//= require_tree . diff --git a/spec/dummy/app/assets/stylesheets/application.css b/spec/dummy/app/assets/stylesheets/application.css new file mode 100644 index 0000000..f9cd5b3 --- /dev/null +++ b/spec/dummy/app/assets/stylesheets/application.css @@ -0,0 +1,15 @@ +/* + * This is a manifest file that'll be compiled into application.css, which will include all the files + * listed below. + * + * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, + * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path. + * + * You're free to add application-wide styles to this file and they'll appear at the bottom of the + * compiled file so the styles you add here take precedence over styles defined in any styles + * defined in the other CSS/SCSS files in this directory. It is generally better to create a new + * file per style scope. + * + *= require_tree . + *= require_self + */ diff --git a/spec/dummy/app/controllers/application_controller.rb b/spec/dummy/app/controllers/application_controller.rb new file mode 100644 index 0000000..d83690e --- /dev/null +++ b/spec/dummy/app/controllers/application_controller.rb @@ -0,0 +1,5 @@ +class ApplicationController < ActionController::Base + # Prevent CSRF attacks by raising an exception. + # For APIs, you may want to use :null_session instead. + protect_from_forgery with: :exception +end diff --git a/spec/dummy/app/controllers/concerns/.keep b/spec/dummy/app/controllers/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/helpers/application_helper.rb b/spec/dummy/app/helpers/application_helper.rb new file mode 100644 index 0000000..de6be79 --- /dev/null +++ b/spec/dummy/app/helpers/application_helper.rb @@ -0,0 +1,2 @@ +module ApplicationHelper +end diff --git a/spec/dummy/app/mailers/.keep b/spec/dummy/app/mailers/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/models/.keep b/spec/dummy/app/models/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/models/concerns/.keep b/spec/dummy/app/models/concerns/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/app/views/layouts/application.html.erb b/spec/dummy/app/views/layouts/application.html.erb new file mode 100644 index 0000000..593a778 --- /dev/null +++ b/spec/dummy/app/views/layouts/application.html.erb @@ -0,0 +1,14 @@ +<!DOCTYPE html> +<html> +<head> + <title>Dummy + <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %> + <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %> + <%= csrf_meta_tags %> + + + +<%= yield %> + + + diff --git a/spec/dummy/bin/bundle b/spec/dummy/bin/bundle new file mode 100755 index 0000000..66e9889 --- /dev/null +++ b/spec/dummy/bin/bundle @@ -0,0 +1,3 @@ +#!/usr/bin/env ruby +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) +load Gem.bin_path('bundler', 'bundle') diff --git a/spec/dummy/bin/rails b/spec/dummy/bin/rails new file mode 100755 index 0000000..5191e69 --- /dev/null +++ b/spec/dummy/bin/rails @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +APP_PATH = File.expand_path('../../config/application', __FILE__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/spec/dummy/bin/rake b/spec/dummy/bin/rake new file mode 100755 index 0000000..1724048 --- /dev/null +++ b/spec/dummy/bin/rake @@ -0,0 +1,4 @@ +#!/usr/bin/env ruby +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/spec/dummy/bin/rspec b/spec/dummy/bin/rspec new file mode 100755 index 0000000..72202dd --- /dev/null +++ b/spec/dummy/bin/rspec @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true +# +# This file was generated by Bundler. +# +# The application 'rspec' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "pathname" +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require "rubygems" +require "bundler/setup" + +load Gem.bin_path("rspec-core", "rspec") diff --git a/spec/dummy/bin/setup b/spec/dummy/bin/setup new file mode 100755 index 0000000..acdb2c1 --- /dev/null +++ b/spec/dummy/bin/setup @@ -0,0 +1,29 @@ +#!/usr/bin/env ruby +require 'pathname' + +# path to your application root. +APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) + +Dir.chdir APP_ROOT do + # This script is a starting point to setup your application. + # Add necessary setup steps to this file: + + puts "== Installing dependencies ==" + system "gem install bundler --conservative" + system "bundle check || bundle install" + + # puts "\n== Copying sample files ==" + # unless File.exist?("config/database.yml") + # system "cp config/database.yml.sample config/database.yml" + # end + + puts "\n== Preparing database ==" + system "bin/rake db:setup" + + puts "\n== Removing old logs and tempfiles ==" + system "rm -f log/*" + system "rm -rf tmp/cache" + + puts "\n== Restarting application server ==" + system "touch tmp/restart.txt" +end diff --git a/spec/dummy/config.ru b/spec/dummy/config.ru new file mode 100644 index 0000000..bd83b25 --- /dev/null +++ b/spec/dummy/config.ru @@ -0,0 +1,4 @@ +# This file is used by Rack-based servers to start the application. + +require ::File.expand_path('../config/environment', __FILE__) +run Rails.application diff --git a/spec/dummy/config/application.rb b/spec/dummy/config/application.rb new file mode 100644 index 0000000..64f34dc --- /dev/null +++ b/spec/dummy/config/application.rb @@ -0,0 +1,22 @@ +require File.expand_path('../boot', __FILE__) + +require 'rails/all' + +Bundler.require(*Rails.groups) + +module Dummy + class Application < Rails::Application + # Settings in config/environments/* take precedence over those specified here. + # Application configuration should go into files in config/initializers + # -- all .rb files in that directory are automatically loaded. + + # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. + # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. + # config.time_zone = 'Central Time (US & Canada)' + + # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. + # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] + # config.i18n.default_locale = :de + end +end + diff --git a/spec/dummy/config/boot.rb b/spec/dummy/config/boot.rb new file mode 100644 index 0000000..6266cfc --- /dev/null +++ b/spec/dummy/config/boot.rb @@ -0,0 +1,5 @@ +# Set up gems listed in the Gemfile. +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__) + +require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE']) +$LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__) diff --git a/spec/dummy/config/database.yml b/spec/dummy/config/database.yml new file mode 100644 index 0000000..8a86a73 --- /dev/null +++ b/spec/dummy/config/database.yml @@ -0,0 +1,8 @@ +test: + adapter: postgresql + pool: 5 + timeout: 5000 + host: <%= ENV['POSTGRES_HOST'] %> + username: <%= ENV['POSTGRES_DB_USERNAME'] %> + password: <%= ENV['POSTGRES_DB_PASSWORD'] %> + database: rspec_profiling_test diff --git a/spec/dummy/config/environment.rb b/spec/dummy/config/environment.rb new file mode 100644 index 0000000..ee8d90d --- /dev/null +++ b/spec/dummy/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require File.expand_path('../application', __FILE__) + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/spec/dummy/config/environments/development.rb b/spec/dummy/config/environments/development.rb new file mode 100644 index 0000000..cc998cf --- /dev/null +++ b/spec/dummy/config/environments/development.rb @@ -0,0 +1,41 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # In the development environment your application's code is reloaded on + # every request. This slows down response time but is perfect for development + # since you don't have to restart the web server when you make code changes. + config.cache_classes = false + + # Do not eager load code on boot. + config.eager_load = false + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + # Raise an error on page load if there are pending migrations. + config.active_record.migration_error = :page_load + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + # config.assets.debug = true + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + # config.assets.digest = true + + # Adds additional error checking when serving assets at runtime. + # Checks for improperly declared sprockets dependencies. + # Raises helpful error messages. + # config.assets.raise_runtime_errors = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/spec/dummy/config/environments/production.rb b/spec/dummy/config/environments/production.rb new file mode 100644 index 0000000..218ab2d --- /dev/null +++ b/spec/dummy/config/environments/production.rb @@ -0,0 +1,79 @@ +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # Code is not reloaded between requests. + config.cache_classes = true + + # Eager load code on boot. This eager loads most of Rails and + # your application in memory, allowing both threaded web servers + # and those relying on copy on write to perform better. + # Rake tasks automatically ignore this option for performance. + config.eager_load = true + + # Full error reports are disabled and caching is turned on. + config.consider_all_requests_local = false + config.action_controller.perform_caching = true + + # Enable Rack::Cache to put a simple HTTP cache in front of your application + # Add `rack-cache` to your Gemfile before enabling this. + # For large-scale production use, consider using a caching reverse proxy like + # NGINX, varnish or squid. + # config.action_dispatch.rack_cache = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Compress JavaScripts and CSS. + # config.assets.js_compressor = :uglifier + # config.assets.css_compressor = :sass + + # Do not fallback to assets pipeline if a precompiled asset is missed. + # config.assets.compile = false + + # Asset digests allow you to set far-future HTTP expiration dates on all assets, + # yet still be able to expire them through the digest params. + # config.assets.digest = true + + # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb + + # Specifies the header that your server uses for sending files. + # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache + # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX + + # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. + # config.force_ssl = true + + # Use the lowest log level to ensure availability of diagnostic information + # when problems arise. + config.log_level = :debug + + # Prepend all log lines with the following tags. + # config.log_tags = [ :subdomain, :uuid ] + + # Use a different logger for distributed setups. + # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # Ignore bad email addresses and do not raise email delivery errors. + # Set this to true and configure the email server for immediate delivery to raise delivery errors. + # config.action_mailer.raise_delivery_errors = false + + # Enable locale fallbacks for I18n (makes lookups for any locale fall back to + # the I18n.default_locale when a translation cannot be found). + config.i18n.fallbacks = true + + # Send deprecation notices to registered listeners. + config.active_support.deprecation = :notify + + # Use default logging formatter so that PID and timestamp are not suppressed. + config.log_formatter = ::Logger::Formatter.new + + # Do not dump schema after migrations. + config.active_record.dump_schema_after_migration = false +end diff --git a/spec/dummy/config/environments/test.rb b/spec/dummy/config/environments/test.rb new file mode 100644 index 0000000..704f96c --- /dev/null +++ b/spec/dummy/config/environments/test.rb @@ -0,0 +1,49 @@ +ACTIVE_RECORD_MIGRATION_CLASS = if Rails::VERSION::STRING < "5.0" + ActiveRecord::Migration + else + rails_version = Rails::VERSION::STRING.split(".")[0..1].join(".") + eval("ActiveRecord::Migration[#{rails_version}]") + end + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + # The test environment is used exclusively to run your application's + # test suite. You never need to work with it otherwise. Remember that + # your test database is "scratch space" for the test suite and is wiped + # and recreated between test runs. Don't rely on the data there! + config.cache_classes = true + + # Do not eager load code on boot. This avoids loading your whole application + # just for the purpose of running a single test. If you are using a tool that + # preloads Rails for running tests, you may have to set it to true. + config.eager_load = false + + # Configure static file server for tests with Cache-Control for performance. + config.serve_static_files = true + config.static_cache_control = 'public, max-age=3600' + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # Raise exceptions instead of rendering exception templates. + config.action_dispatch.show_exceptions = false + + # Disable request forgery protection in test environment. + config.action_controller.allow_forgery_protection = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + + # Randomize the order test cases are executed. + config.active_support.test_order = :random + + # Print deprecation notices to the stderr. + config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true +end diff --git a/spec/dummy/config/initializers/assets.rb b/spec/dummy/config/initializers/assets.rb new file mode 100644 index 0000000..ff2d229 --- /dev/null +++ b/spec/dummy/config/initializers/assets.rb @@ -0,0 +1,11 @@ +# Be sure to restart your server when you modify this file. + +# Version of your assets, change this if you want to expire all your assets. +# Rails.application.config.assets.version = '1.0' + +# Add additional assets to the asset load path +# Rails.application.config.assets.paths << Emoji.images_path + +# Precompile additional assets. +# application.js, application.css, and all non-JS/CSS in app/assets folder are already added. +# Rails.application.config.assets.precompile += %w( search.js ) diff --git a/spec/dummy/config/initializers/backtrace_silencers.rb b/spec/dummy/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/spec/dummy/config/initializers/backtrace_silencers.rb @@ -0,0 +1,7 @@ +# Be sure to restart your server when you modify this file. + +# You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. +# Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } + +# You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. +# Rails.backtrace_cleaner.remove_silencers! diff --git a/spec/dummy/config/initializers/cookies_serializer.rb b/spec/dummy/config/initializers/cookies_serializer.rb new file mode 100644 index 0000000..7f70458 --- /dev/null +++ b/spec/dummy/config/initializers/cookies_serializer.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.action_dispatch.cookies_serializer = :json diff --git a/spec/dummy/config/initializers/filter_parameter_logging.rb b/spec/dummy/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/spec/dummy/config/initializers/filter_parameter_logging.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Configure sensitive parameters which will be filtered from the log file. +Rails.application.config.filter_parameters += [:password] diff --git a/spec/dummy/config/initializers/inflections.rb b/spec/dummy/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/spec/dummy/config/initializers/inflections.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Add new inflection rules using the following format. Inflections +# are locale specific, and you may define rules for as many different +# locales as you wish. All of these examples are active by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.plural /^(ox)$/i, '\1en' +# inflect.singular /^(ox)en/i, '\1' +# inflect.irregular 'person', 'people' +# inflect.uncountable %w( fish sheep ) +# end + +# These inflection rules are supported but not enabled by default: +# ActiveSupport::Inflector.inflections(:en) do |inflect| +# inflect.acronym 'RESTful' +# end diff --git a/spec/dummy/config/initializers/mime_types.rb b/spec/dummy/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/spec/dummy/config/initializers/mime_types.rb @@ -0,0 +1,4 @@ +# Be sure to restart your server when you modify this file. + +# Add new mime types for use in respond_to blocks: +# Mime::Type.register "text/richtext", :rtf diff --git a/spec/dummy/config/initializers/session_store.rb b/spec/dummy/config/initializers/session_store.rb new file mode 100644 index 0000000..e766b67 --- /dev/null +++ b/spec/dummy/config/initializers/session_store.rb @@ -0,0 +1,3 @@ +# Be sure to restart your server when you modify this file. + +Rails.application.config.session_store :cookie_store, key: '_dummy_session' diff --git a/spec/dummy/config/initializers/wrap_parameters.rb b/spec/dummy/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..33725e9 --- /dev/null +++ b/spec/dummy/config/initializers/wrap_parameters.rb @@ -0,0 +1,14 @@ +# Be sure to restart your server when you modify this file. + +# This file contains settings for ActionController::ParamsWrapper which +# is enabled by default. + +# Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. +ActiveSupport.on_load(:action_controller) do + wrap_parameters format: [:json] if respond_to?(:wrap_parameters) +end + +# To enable root element in JSON for ActiveRecord objects. +# ActiveSupport.on_load(:active_record) do +# self.include_root_in_json = true +# end diff --git a/spec/dummy/config/locales/en.yml b/spec/dummy/config/locales/en.yml new file mode 100644 index 0000000..0653957 --- /dev/null +++ b/spec/dummy/config/locales/en.yml @@ -0,0 +1,23 @@ +# Files in the config/locales directory are used for internationalization +# and are automatically loaded by Rails. If you want to use locales other +# than English, add the necessary files in this directory. +# +# To use the locales, use `I18n.t`: +# +# I18n.t 'hello' +# +# In views, this is aliased to just `t`: +# +# <%= t('hello') %> +# +# To use a different locale, set it with `I18n.locale`: +# +# I18n.locale = :es +# +# This would use the information in config/locales/es.yml. +# +# To learn more, please read the Rails Internationalization guide +# available at http://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/spec/dummy/config/routes.rb b/spec/dummy/config/routes.rb new file mode 100644 index 0000000..9240ef4 --- /dev/null +++ b/spec/dummy/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + +end diff --git a/spec/dummy/config/secrets.yml b/spec/dummy/config/secrets.yml new file mode 100644 index 0000000..0a1d7f8 --- /dev/null +++ b/spec/dummy/config/secrets.yml @@ -0,0 +1,22 @@ +# Be sure to restart your server when you modify this file. + +# Your secret key is used for verifying the integrity of signed cookies. +# If you change this key, all old signed cookies will become invalid! + +# Make sure the secret is at least 30 characters and all random, +# no regular words or you'll be exposed to dictionary attacks. +# You can use `rake secret` to generate a secure secret key. + +# Make sure the secrets in this file are kept private +# if you're sharing your code publicly. + +development: + secret_key_base: efeb6988ca8ca87c818631b405b5f0c5a23c3e118efceca29c55f338704d6f95b4077e543951270c2fbc9218c34401d5269850814667408f54591668128cfb96 + +test: + secret_key_base: 4abfb86243878c7d0f4f9ea218d612be42c14e8b498d247f56808c0bd8d05ee79e796c19ddb99ab0b8b3d69a2f3f0af4351f377c69c3a9fccd789bd266b9269e + +# Do not keep production secrets in the repository, +# instead read values from the environment. +production: + secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> diff --git a/spec/dummy/db/migrate/.keep b/spec/dummy/db/migrate/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/lib/assets/.keep b/spec/dummy/lib/assets/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/public/404.html b/spec/dummy/public/404.html new file mode 100644 index 0000000..b612547 --- /dev/null +++ b/spec/dummy/public/404.html @@ -0,0 +1,67 @@ + + + + The page you were looking for doesn't exist (404) + + + + + + +
+
+

The page you were looking for doesn't exist.

+

You may have mistyped the address or the page may have moved.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/dummy/public/422.html b/spec/dummy/public/422.html new file mode 100644 index 0000000..a21f82b --- /dev/null +++ b/spec/dummy/public/422.html @@ -0,0 +1,67 @@ + + + + The change you wanted was rejected (422) + + + + + + +
+
+

The change you wanted was rejected.

+

Maybe you tried to change something you didn't have access to.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/dummy/public/500.html b/spec/dummy/public/500.html new file mode 100644 index 0000000..061abc5 --- /dev/null +++ b/spec/dummy/public/500.html @@ -0,0 +1,66 @@ + + + + We're sorry, but something went wrong (500) + + + + + + +
+
+

We're sorry, but something went wrong.

+
+

If you are the application owner check the logs for more information.

+
+ + diff --git a/spec/dummy/public/favicon.ico b/spec/dummy/public/favicon.ico new file mode 100644 index 0000000..e69de29 diff --git a/spec/dummy/spec/handcuffs_rake_spec.rb b/spec/dummy/spec/handcuffs_rake_spec.rb new file mode 100644 index 0000000..9ffe629 --- /dev/null +++ b/spec/dummy/spec/handcuffs_rake_spec.rb @@ -0,0 +1,159 @@ +require_relative 'spec_helper.rb' + +RSpec.describe 'handcuffs:migrate' do + include_context 'rake' + + let!(:add_table_foo_version) { '20160329040426' } #pre_restart + let!(:add_column_foo_widget_count_version){ '20160329042840' } #pre_restart + let!(:add_index_foo_widget_count_version) { '20160329224617' } #post_restart + let!(:add_column_foo_whatzit_count_version){ '20160330002738' } #pre_restart + let!(:add_foo_whatzit_default_version){ '20160330003159' } #post_restart + let!(:add_table_bar_version){ '20160330005509' } #none + + it 'raises an error when not passed a phase argument' do + expect { subject.invoke }.to raise_error(RequiresPhaseArgumentError) + end + + it 'raises not configured error if Handcuffs is not configured' do + Handcuffs.config = nil + expect { subject.invoke(:pre_restart) }.to raise_error(HandcuffsNotConfiguredError) + end + + context 'with basic config' do + before(:all) do + Handcuffs.configure do |config| + config.phases = [:pre_restart, :post_restart] + config.default_phase = :pre_restart + end + end + + it 'raises unknown phase error if given unknown phase' do + expect { subject.invoke(:foo) }.to raise_error(HandcuffsUnknownPhaseError) + end + + context '[pre_restart]' do + it 'runs pre_restart migrations only' do + subject.invoke(:pre_restart) + expect(SchemaMigrations.pluck(:version)).to eq [ + add_table_foo_version, + add_column_foo_widget_count_version, + add_column_foo_whatzit_count_version, + add_table_bar_version + ] + end + end + + context '[post_restart]' do + it 'raises phase out of order error if post_restart migrations run' do + expect { subject.invoke(:post_restart) }.to raise_error(HandcuffsPhaseOutOfOrderError) + end + + it 'runs post_restart migrations after pre_restart migrations' do + subject.invoke(:pre_restart) + expect(SchemaMigrations.pluck(:version)).to eq [ + add_table_foo_version, + add_column_foo_widget_count_version, + add_column_foo_whatzit_count_version, + add_table_bar_version + ] + subject.reenable + subject.invoke(:post_restart) + expect(SchemaMigrations.pluck(:version)).to eq [ + add_table_foo_version, + add_column_foo_widget_count_version, + add_column_foo_whatzit_count_version, + add_table_bar_version, + add_index_foo_widget_count_version, + add_foo_whatzit_default_version + ] + end + end + + context '[all]' do + it 'runs all migrations' do + subject.invoke(:all) + expect(SchemaMigrations.pluck(:version)).to eq [ + add_table_foo_version, + add_column_foo_widget_count_version, + add_column_foo_whatzit_count_version, + add_table_bar_version, + add_index_foo_widget_count_version, + add_foo_whatzit_default_version, + ] + end + end + + end + + context 'no default phase' do + before(:all) do + Handcuffs.configure do |config| + config.phases = [:pre_restart, :post_restart] + end + end + + it 'raises error on nil phase' do + expect { subject.invoke(:pre_restart) }.to raise_error(HandcuffsPhaseUndefinedError) + end + end +end + +RSpec.describe 'handcuffs:rollback' do + include_context 'rake' + + let! (:add_table_foo_version) { '20160329040426' } #pre_restart + let! (:add_column_foo_widget_count_version){ '20160329042840' } #pre_restart + let!(:add_index_foo_widget_count_version) { '20160329224617' } #post_restart + let!(:add_column_foo_whatzit_count_version){ '20160330002738' } #pre_restart + let!(:add_foo_whatzit_default_version){ '20160330003159' } #post_restart + let!(:add_table_bar_version){ '20160330005509' } #none + + it 'raises an error when not passed a phase argument' do + expect { subject.invoke }.to raise_error(RequiresPhaseArgumentError) + end + + it 'raises not configured error if Handcuffs is not configured' do + Handcuffs.config = nil + expect { subject.invoke(:pre_restart) }.to raise_error(HandcuffsNotConfiguredError) + end + + context 'with basic config' do + before(:all) do + Handcuffs.configure do |config| + config.phases = [:pre_restart, :post_restart] + config.default_phase = :pre_restart + end + end + + context '[post_restart]' do + + it 'reverses last post_restart migration' do + rake['handcuffs:migrate'].invoke(:all) + subject.invoke(:post_restart) + expect(SchemaMigrations.pluck(:version)).to eq [ + add_table_foo_version, + add_column_foo_widget_count_version, + add_column_foo_whatzit_count_version, + add_table_bar_version, + add_index_foo_widget_count_version, + ] + end + end + + context '[pre_restart]' do + it 'reverses last pre_restart migration' do + rake['handcuffs:migrate'].invoke(:all) + subject.invoke(:pre_restart) + expect(SchemaMigrations.pluck(:version)).to eq [ + add_table_foo_version, + add_column_foo_widget_count_version, + add_column_foo_whatzit_count_version, + add_index_foo_widget_count_version, + add_foo_whatzit_default_version + ] + end + end + end +end + +class SchemaMigrations < ActiveRecord::Base; end diff --git a/spec/dummy/spec/spec_helper.rb b/spec/dummy/spec/spec_helper.rb new file mode 100644 index 0000000..ec9f259 --- /dev/null +++ b/spec/dummy/spec/spec_helper.rb @@ -0,0 +1,125 @@ +# This file was generated by the `rspec --init` command. Conventionally, all +# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`. +# The generated `.rspec` file contains `--require spec_helper` which will cause +# this file to always be loaded, without a need to explicitly require it in any +# files. +# +# Given that it is always loaded, you are encouraged to keep this file as +# light-weight as possible. Requiring heavyweight dependencies from this file +# will add to the boot time of your test suite on EVERY test run, even for an +# individual file that may not need all of that loaded. Instead, consider making +# a separate helper file that requires the additional dependencies and performs +# the additional setup, and require it from the spec files that actually need +# it. +# +# The `.rspec` file also contains a few flags that are not defaults but that +# users commonly want. +# +# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + ENV["RAILS_ENV"] ||= 'test' + require File.expand_path("../../config/environment", __FILE__) + require 'rspec/rails' + + # ADDED FOR TESTING + require "rspec_profiling/rspec" + + Dir[Rails.root.join("spec/support/**/*.rb")].each {|f| require f} + Dir[Rails.root.join("db/migrate/*.rb")].each { |f| require f } + + # ADDED FOR TESTING + RspecProfiling.configure do |config| + config.collector = RspecProfiling::Collectors::PSQL + config.db_path = 'profiling' + end + + config.before(:each) do + connection = ActiveRecord::Base.connection + connection.tables.each do |table| + connection.drop_table(table) + end + end + + config.backtrace_exclusion_patterns = [] + + # include ActiveRecord::Tasks + # DatabaseTasks.database_configuration = connection_info + # DatabaseTasks.db_dir = 'db' + # DatabaseTasks.create_current(Rails.env) + + # rspec-expectations config goes here. You can use an alternate + + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + # rspec-mocks config goes here. You can use an alternate test double + # library (such as bogus or mocha) by changing the `mock_with` option here. + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on + # a real object. This is generally recommended, and will default to + # `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # The settings below are suggested to provide a good initial experience + # with RSpec, but feel free to customize to your heart's content. + # These two settings work together to allow you to limit a spec run + # to individual examples or groups you care about by tagging them with + # `:focus` metadata. When nothing is tagged with `:focus`, all examples + # get run. + config.filter_run :focus + config.run_all_when_everything_filtered = true + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + # config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = 'doc' + end + + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 + + # Run specs in random order to surface order dependencies. If you find an + # order dependency and want to debug it, you can fix the order by providing + # the seed, which is printed after each run. + # --seed 1234 + config.order = :random + + # Seed global randomization in this process using the `--seed` CLI option. + # Setting this allows you to use `--seed` to deterministically reproduce + # test failures related to randomization by passing the same `--seed` value + # as the one that triggered the failure. + Kernel.srand config.seed +end diff --git a/spec/dummy/spec/support/shared_contexts/rake.rb b/spec/dummy/spec/support/shared_contexts/rake.rb new file mode 100644 index 0000000..7dc7f7b --- /dev/null +++ b/spec/dummy/spec/support/shared_contexts/rake.rb @@ -0,0 +1,20 @@ +# https://robots.thoughtbot.com/test-rake-tasks-like-a-boss +require "rake" + +shared_context "rake" do + let(:rake) { Rake::Application.new } + let(:task_name) { self.class.top_level_description } + let(:task_path) { "../../lib/tasks/#{task_name.split(":").first}" } + subject { rake[task_name] } + + def loaded_files_excluding_current_rake_file + $".reject {|file| file == Rails.root.join("#{task_path}.rake").to_s } + end + + before do + Rake.application = rake + Rake.application.rake_require(task_path, [Rails.root.to_s], loaded_files_excluding_current_rake_file) + + Rake::Task.define_task(:environment) + end +end