From 59f20aaddbf3da0913d2c67a367a3403537bfb9b Mon Sep 17 00:00:00 2001 From: Rafael Soares <893971+rafasoares@users.noreply.github.com> Date: Sat, 11 May 2024 15:27:22 +0200 Subject: [PATCH] chore: housekeeping and CI improvements (#18) * chore: housekeeping and CI improvements * fix: CC test coverage report --- .codeclimate.yml | 2 +- .../actions/setup-credentials/.eslintignore | 3 - .github/actions/setup-credentials/.gitignore | 2 - .../actions/setup-credentials/dist/index.js | 430 ------------------ .../workflows/{gempush.yml => publish.yml} | 42 +- .github/workflows/tests.yml | 84 ++-- .gitignore | 58 ++- .hound.yml | 1 - .reek.yml | 6 - .rspec | 2 - .rubocop.yml | 17 +- .ruby-version | 2 +- CHANGELOG.md | 3 + Gemfile | 22 + Gemfile.lock | 173 ++++--- Guardfile | 8 - README.md | 36 +- bin/rake | 12 +- bin/rspec | 27 ++ bin/setup | 2 - human_enum.gemspec | 27 +- lib/human_enum.rb | 3 +- spec/human_enum_spec.rb | 8 +- spec/setup_helper.rb | 12 + spec/spec_helper.rb | 108 ++++- spec/support/db.rb | 17 + spec/support/db/database.yml | 4 - spec/support/db/schema.rb | 7 - spec/support/i18n.rb | 8 + 29 files changed, 452 insertions(+), 674 deletions(-) delete mode 100644 .github/actions/setup-credentials/.eslintignore delete mode 100644 .github/actions/setup-credentials/.gitignore delete mode 100644 .github/actions/setup-credentials/dist/index.js rename .github/workflows/{gempush.yml => publish.yml} (57%) delete mode 100644 .reek.yml create mode 100755 bin/rspec create mode 100644 spec/setup_helper.rb create mode 100644 spec/support/db.rb delete mode 100644 spec/support/db/database.yml delete mode 100644 spec/support/db/schema.rb create mode 100644 spec/support/i18n.rb diff --git a/.codeclimate.yml b/.codeclimate.yml index 7a3508f..c9e9a05 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -1,4 +1,4 @@ plugins: rubocop: enabled: true - channel: rubocop-0-72 + channel: rubocop-1-56-3 diff --git a/.github/actions/setup-credentials/.eslintignore b/.github/actions/setup-credentials/.eslintignore deleted file mode 100644 index 6de9a76..0000000 --- a/.github/actions/setup-credentials/.eslintignore +++ /dev/null @@ -1,3 +0,0 @@ -dist/ -lib/ -node_modules/ diff --git a/.github/actions/setup-credentials/.gitignore b/.github/actions/setup-credentials/.gitignore deleted file mode 100644 index 3b4e8dc..0000000 --- a/.github/actions/setup-credentials/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -lib/ -node_modules/ diff --git a/.github/actions/setup-credentials/dist/index.js b/.github/actions/setup-credentials/dist/index.js deleted file mode 100644 index 741ff21..0000000 --- a/.github/actions/setup-credentials/dist/index.js +++ /dev/null @@ -1,430 +0,0 @@ -module.exports = -/******/ (function(modules, runtime) { // webpackBootstrap -/******/ "use strict"; -/******/ // The module cache -/******/ var installedModules = {}; -/******/ -/******/ // The require function -/******/ function __webpack_require__(moduleId) { -/******/ -/******/ // Check if module is in cache -/******/ if(installedModules[moduleId]) { -/******/ return installedModules[moduleId].exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = installedModules[moduleId] = { -/******/ i: moduleId, -/******/ l: false, -/******/ exports: {} -/******/ }; -/******/ -/******/ // Execute the module function -/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__); -/******/ -/******/ // Flag the module as loaded -/******/ module.l = true; -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/******/ -/******/ __webpack_require__.ab = __dirname + "/"; -/******/ -/******/ // the startup function -/******/ function startup() { -/******/ // Load entry module and return exports -/******/ return __webpack_require__(131); -/******/ }; -/******/ // initialize runtime -/******/ runtime(__webpack_require__); -/******/ -/******/ // run startup -/******/ return startup(); -/******/ }) -/************************************************************************/ -/******/ ({ - -/***/ 87: -/***/ (function(module) { - -module.exports = require("os"); - -/***/ }), - -/***/ 131: -/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); -/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(470); -/* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__); -/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(747); -/* harmony import */ var fs__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(fs__WEBPACK_IMPORTED_MODULE_1__); -/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(87); -/* harmony import */ var os__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(os__WEBPACK_IMPORTED_MODULE_2__); - - - -async function main() { - let home = Object(os__WEBPACK_IMPORTED_MODULE_2__.homedir)(); - if (!home) - home = '.'; - const path = `${home}/.gem/credentials`; - const credential = Object(_actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput)('credential', { required: true }); - const data = `---\n${credential}\n`; - await fs__WEBPACK_IMPORTED_MODULE_1__.promises.writeFile(path, data); -} -main(); - - -/***/ }), - -/***/ 431: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const os = __importStar(__webpack_require__(87)); -/** - * Commands - * - * Command Format: - * ::name key=value,key=value::message - * - * Examples: - * ::warning::This is the message - * ::set-env name=MY_VAR::some value - */ -function issueCommand(command, properties, message) { - const cmd = new Command(command, properties, message); - process.stdout.write(cmd.toString() + os.EOL); -} -exports.issueCommand = issueCommand; -function issue(name, message = '') { - issueCommand(name, {}, message); -} -exports.issue = issue; -const CMD_STRING = '::'; -class Command { - constructor(command, properties, message) { - if (!command) { - command = 'missing.command'; - } - this.command = command; - this.properties = properties; - this.message = message; - } - toString() { - let cmdStr = CMD_STRING + this.command; - if (this.properties && Object.keys(this.properties).length > 0) { - cmdStr += ' '; - let first = true; - for (const key in this.properties) { - if (this.properties.hasOwnProperty(key)) { - const val = this.properties[key]; - if (val) { - if (first) { - first = false; - } - else { - cmdStr += ','; - } - cmdStr += `${key}=${escapeProperty(val)}`; - } - } - } - } - cmdStr += `${CMD_STRING}${escapeData(this.message)}`; - return cmdStr; - } -} -function escapeData(s) { - return (s || '') - .replace(/%/g, '%25') - .replace(/\r/g, '%0D') - .replace(/\n/g, '%0A'); -} -function escapeProperty(s) { - return (s || '') - .replace(/%/g, '%25') - .replace(/\r/g, '%0D') - .replace(/\n/g, '%0A') - .replace(/:/g, '%3A') - .replace(/,/g, '%2C'); -} -//# sourceMappingURL=command.js.map - -/***/ }), - -/***/ 470: -/***/ (function(__unusedmodule, exports, __webpack_require__) { - -"use strict"; - -var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -}; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -const command_1 = __webpack_require__(431); -const os = __importStar(__webpack_require__(87)); -const path = __importStar(__webpack_require__(622)); -/** - * The code to exit an action - */ -var ExitCode; -(function (ExitCode) { - /** - * A code indicating that the action was successful - */ - ExitCode[ExitCode["Success"] = 0] = "Success"; - /** - * A code indicating that the action was a failure - */ - ExitCode[ExitCode["Failure"] = 1] = "Failure"; -})(ExitCode = exports.ExitCode || (exports.ExitCode = {})); -//----------------------------------------------------------------------- -// Variables -//----------------------------------------------------------------------- -/** - * Sets env variable for this action and future actions in the job - * @param name the name of the variable to set - * @param val the value of the variable - */ -function exportVariable(name, val) { - process.env[name] = val; - command_1.issueCommand('set-env', { name }, val); -} -exports.exportVariable = exportVariable; -/** - * Registers a secret which will get masked from logs - * @param secret value of the secret - */ -function setSecret(secret) { - command_1.issueCommand('add-mask', {}, secret); -} -exports.setSecret = setSecret; -/** - * Prepends inputPath to the PATH (for this action and future actions) - * @param inputPath - */ -function addPath(inputPath) { - command_1.issueCommand('add-path', {}, inputPath); - process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; -} -exports.addPath = addPath; -/** - * Gets the value of an input. The value is also trimmed. - * - * @param name name of the input to get - * @param options optional. See InputOptions. - * @returns string - */ -function getInput(name, options) { - const val = process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] || ''; - if (options && options.required && !val) { - throw new Error(`Input required and not supplied: ${name}`); - } - return val.trim(); -} -exports.getInput = getInput; -/** - * Sets the value of an output. - * - * @param name name of the output to set - * @param value value to store - */ -function setOutput(name, value) { - command_1.issueCommand('set-output', { name }, value); -} -exports.setOutput = setOutput; -//----------------------------------------------------------------------- -// Results -//----------------------------------------------------------------------- -/** - * Sets the action status to failed. - * When the action exits it will be with an exit code of 1 - * @param message add error issue message - */ -function setFailed(message) { - process.exitCode = ExitCode.Failure; - error(message); -} -exports.setFailed = setFailed; -//----------------------------------------------------------------------- -// Logging Commands -//----------------------------------------------------------------------- -/** - * Writes debug message to user log - * @param message debug message - */ -function debug(message) { - command_1.issueCommand('debug', {}, message); -} -exports.debug = debug; -/** - * Adds an error issue - * @param message error issue message - */ -function error(message) { - command_1.issue('error', message); -} -exports.error = error; -/** - * Adds an warning issue - * @param message warning issue message - */ -function warning(message) { - command_1.issue('warning', message); -} -exports.warning = warning; -/** - * Writes info to log with console.log. - * @param message info message - */ -function info(message) { - process.stdout.write(message + os.EOL); -} -exports.info = info; -/** - * Begin an output group. - * - * Output until the next `groupEnd` will be foldable in this group - * - * @param name The name of the output group - */ -function startGroup(name) { - command_1.issue('group', name); -} -exports.startGroup = startGroup; -/** - * End an output group. - */ -function endGroup() { - command_1.issue('endgroup'); -} -exports.endGroup = endGroup; -/** - * Wrap an asynchronous function call in a group. - * - * Returns the same type as the function itself. - * - * @param name The name of the group - * @param fn The function to wrap in the group - */ -function group(name, fn) { - return __awaiter(this, void 0, void 0, function* () { - startGroup(name); - let result; - try { - result = yield fn(); - } - finally { - endGroup(); - } - return result; - }); -} -exports.group = group; -//----------------------------------------------------------------------- -// Wrapper action state -//----------------------------------------------------------------------- -/** - * Saves state for current action, the state can only be retrieved by this action's post job execution. - * - * @param name name of the state to store - * @param value value to store - */ -function saveState(name, value) { - command_1.issueCommand('save-state', { name }, value); -} -exports.saveState = saveState; -/** - * Gets the value of an state set by this action's main execution. - * - * @param name name of the state to get - * @returns string - */ -function getState(name) { - return process.env[`STATE_${name}`] || ''; -} -exports.getState = getState; -//# sourceMappingURL=core.js.map - -/***/ }), - -/***/ 622: -/***/ (function(module) { - -module.exports = require("path"); - -/***/ }), - -/***/ 747: -/***/ (function(module) { - -module.exports = require("fs"); - -/***/ }) - -/******/ }, -/******/ function(__webpack_require__) { // webpackRuntimeModules -/******/ "use strict"; -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ !function() { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ }(); -/******/ -/******/ /* webpack/runtime/compat get default export */ -/******/ !function() { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ }(); -/******/ -/******/ /* webpack/runtime/define property getter */ -/******/ !function() { -/******/ // define getter function for harmony exports -/******/ var hasOwnProperty = Object.prototype.hasOwnProperty; -/******/ __webpack_require__.d = function(exports, name, getter) { -/******/ if(!hasOwnProperty.call(exports, name)) { -/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter }); -/******/ } -/******/ }; -/******/ }(); -/******/ -/******/ } -); \ No newline at end of file diff --git a/.github/workflows/gempush.yml b/.github/workflows/publish.yml similarity index 57% rename from .github/workflows/gempush.yml rename to .github/workflows/publish.yml index 1266f22..cf2e028 100644 --- a/.github/workflows/gempush.yml +++ b/.github/workflows/publish.yml @@ -1,29 +1,46 @@ -name: Ruby Gem +name: Publish gem on: push: branches: - - master + - main + paths: + - lib/human_enum/version.rb + +permissions: + packages: write + contents: read jobs: - build: - name: Build + Publish + tests: + uses: ./.github/workflows/tests.yml + + publish: runs-on: ubuntu-latest + needs: tests + steps: - - uses: actions/checkout@master - - name: Set up Ruby 2.6 - uses: ruby/setup-ruby@v1 + - uses: actions/checkout@v3 + + - uses: ruby/setup-ruby@v1 with: - version: 3.2 + rubygems: latest + bundler-cache: true - - name: Publish to GPR + - name: Create credentials file run: | mkdir -p $HOME/.gem touch $HOME/.gem/credentials chmod 600 $HOME/.gem/credentials echo ":github: Bearer ${GITHUB_TOKEN}" >> ~/.gem/credentials - gem build *.gemspec + echo ":rubygems_api_key: Bearer ${RUBYGEMS_AUTH_TOKEN}" > ~/.gem/credentials + + - name: Build gem + run: gem build *.gemspec + + - name: Publish to Github Packages + run: | gem push --KEY github --host https://rubygems.pkg.github.com/${OWNER} *.gem env: GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} @@ -31,11 +48,6 @@ jobs: - name: Publish to RubyGems run: | - mkdir -p $HOME/.gem - touch $HOME/.gem/credentials - chmod 600 $HOME/.gem/credentials - echo ":rubygems_api_key: Bearer ${RUBYGEMS_AUTH_TOKEN}" >> ~/.gem/credentials - gem build *.gemspec gem push *.gem env: RUBYGEMS_AUTH_TOKEN: ${{secrets.RUBYGEMS_AUTH_TOKEN}} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 8e28877..f249ab4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -1,69 +1,49 @@ -name: Tests - on: push: - branches: [master, develop] + branches: [main, develop] pull_request: - branches: [master, develop] + branches: [main, develop] + workflow_call: + +permissions: + contents: read jobs: - rspec: - name: RSpec + test: + name: Run specs runs-on: ubuntu-latest + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + - uses: ruby/setup-ruby@v1 with: - ruby-version: 3.2 - - uses: actions/cache@v1 - with: - path: vendor/bundle - key: ${{ runner.os }}-gems-${{ hashFiles('**/Gemfile.lock') }} - restore-keys: | - ${{ runner.os }}-gems- - - name: Update Bundler - run: gem install bundler:2.0.2 - - name: Setup SQLite - run: sudo apt-get install libsqlite3-dev - - name: Bundle install - run: | - bundle config deployment true - bundle config path vendor/bundle - bin/setup + rubygems: latest + bundler-cache: true + - name: Run specs - run: bin/rake spec - - uses: actions/upload-artifact@v1.0.0 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + run: bin/rspec + + - uses: actions/upload-artifact@v4 with: name: code-coverage path: coverage coverage: - name: Code Coverage - needs: rspec + name: Report code coverage + needs: test runs-on: ubuntu-latest - env: - CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} + steps: - - uses: actions/checkout@v2 - - name: Extract branch name - id: extract_branch - env: - branch: ${{ github.head_ref || github.ref }} - run: echo "##[set-output name=branch;]$(echo ${branch#refs/heads/})" - - name: Download and setup Code Climate Test Reporter - env: - GIT_BRANCH: ${{steps.extract_branch.outputs.branch}} - GIT_COMMIT_SHA: ${{ github.sha }} - run: | - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - chmod +x ./cc-test-reporter - ./cc-test-reporter before-build - - uses: actions/download-artifact@v1.0.0 - with: - name: code-coverage - path: coverage - - name: Upload coverage report to Code Climate - env: - GIT_BRANCH: ${{steps.extract_branch.outputs.branch}} - GIT_COMMIT_SHA: ${{ github.sha }} - run: ./cc-test-reporter after-build -t simplecov + - uses: actions/checkout@v3 + + - uses: actions/download-artifact@v4 + with: + name: code-coverage + path: coverage + + - uses: paambaati/codeclimate-action@v6 + env: + CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }} diff --git a/.gitignore b/.gitignore index c8098e0..e3200e0 100644 --- a/.gitignore +++ b/.gitignore @@ -1,14 +1,56 @@ -/.bundle/ -/.yardoc -/_yardoc/ +*.gem +*.rbc +/.config /coverage/ -/doc/ +/InstalledFiles /pkg/ /spec/reports/ +/spec/examples.txt +/test/tmp/ +/test/version_tmp/ /tmp/ -# rspec failure tracking -.rspec_status +# Used by dotenv library to load environment variables. +# .env + +# Ignore Byebug command history file. +.byebug_history + +## Specific to RubyMotion: +.dat* +.repl_history +build/ +*.bridgesupport +build-iPhoneOS/ +build-iPhoneSimulator/ + +## Specific to RubyMotion (use of CocoaPods): +# +# We recommend against adding the Pods directory to your .gitignore. However +# you should judge for yourself, the pros and cons are mentioned at: +# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control +# +# vendor/Pods/ + +## Documentation cache and generated files: +/.yardoc/ +/_yardoc/ +/doc/ +/rdoc/ + +## Environment normalization: +/.bundle/ +/vendor/bundle +/lib/bundler/man/ + +# for a library or gem, you might want to ignore these files since the code is +# intended to run in multiple environments; otherwise, check them in: +# Gemfile.lock +# .ruby-version +# .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc -# rspec local configuration -.rspec-local +# Used by RuboCop. Remote config files pulled in from inherit_from directive. +# .rubocop-https?--* diff --git a/.hound.yml b/.hound.yml index c462698..fd4787b 100644 --- a/.hound.yml +++ b/.hound.yml @@ -1,7 +1,6 @@ rubocop: version: 0.72.0 - jshint: enabled: false diff --git a/.reek.yml b/.reek.yml deleted file mode 100644 index e2d307c..0000000 --- a/.reek.yml +++ /dev/null @@ -1,6 +0,0 @@ ---- -# Reek configuration file - -detectors: - UtilityFunction: - public_methods_only: true diff --git a/.rspec b/.rspec index 34c5164..c99d2e7 100644 --- a/.rspec +++ b/.rspec @@ -1,3 +1 @@ ---format documentation ---color --require spec_helper diff --git a/.rubocop.yml b/.rubocop.yml index 58eeaca..5081017 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,9 +1,20 @@ require: - rubocop-performance + - rubocop-rake + - rubocop-rails - rubocop-rspec +AllCops: + NewCops: enable + TargetRubyVersion: 3.0 + Metrics/BlockLength: Exclude: - - 'Rakefile' - - '**/*.gemspec' - - 'spec/**/*.rb' + - "Rakefile" + - "Guardfile" + - "**/*.gemspec" + - "spec/**/*.rb" + +Rails/ApplicationRecord: + Exclude: + - "spec/**/*.rb" diff --git a/.ruby-version b/.ruby-version index a9cadc6..aed7acb 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-3.2.0 +ruby-3.2.4 diff --git a/CHANGELOG.md b/CHANGELOG.md index 487c7eb..61fe7f7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ # Changelog +## 1.0.0 +Updating to Ruby 3.2 and Rails 7 + ## 0.1.3 No code changes, just changing our CI diff --git a/Gemfile b/Gemfile index 6ea99b8..9aac809 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,25 @@ source 'https://rubygems.org' # Specify your gem's dependencies in human_enum.gemspec gemspec + +gem 'rake', '~> 13.0' + +gem 'sqlite3', '~> 1.4' + +gem 'rspec', '~> 3.12' + +# Should match the version in .codeclimate.yml +gem 'rubocop', '~> 1.56.3' +gem 'rubocop-performance' +gem 'rubocop-rails' +gem 'rubocop-rake' +gem 'rubocop-rspec' + +gem 'ruby-lsp-rails' +gem 'ruby-lsp-rspec', require: false + +gem 'guard', '~> 2.18' +gem 'guard-rspec', '~> 4.7' +gem 'guard-rubocop', '~> 1.5' + +gem 'simplecov', '~> 0.22.0' diff --git a/Gemfile.lock b/Gemfile.lock index 452025e..e5de414 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,30 +2,31 @@ PATH remote: . specs: human_enum (1.0.0) - activerecord (> 5.0.0) + activerecord (>= 6.1, < 7) GEM remote: https://rubygems.org/ specs: - activemodel (7.0.7.2) - activesupport (= 7.0.7.2) - activerecord (7.0.7.2) - activemodel (= 7.0.7.2) - activesupport (= 7.0.7.2) - activesupport (7.0.7.2) + activemodel (6.1.7.7) + activesupport (= 6.1.7.7) + activerecord (6.1.7.7) + activemodel (= 6.1.7.7) + activesupport (= 6.1.7.7) + activesupport (6.1.7.7) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) + zeitwerk (~> 2.3) ast (2.4.2) - codeclimate-engine-rb (0.4.2) + base64 (0.1.1) coderay (1.1.3) - concurrent-ruby (1.2.2) - diff-lcs (1.5.0) + concurrent-ruby (1.2.3) + diff-lcs (1.5.1) docile (1.4.0) - ffi (1.15.5) + ffi (1.16.3) formatador (1.1.0) - guard (2.18.0) + guard (2.18.1) formatador (>= 0.2.4) listen (>= 2.7, < 4.0) lumberjack (>= 1.0.12, < 2.0) @@ -42,93 +43,131 @@ GEM guard-rubocop (1.5.0) guard (~> 2.0) rubocop (< 2.0) - i18n (1.14.1) + i18n (1.14.5) concurrent-ruby (~> 1.0) - jaro_winkler (1.5.4) - json (2.6.3) - kwalify (0.7.2) - listen (3.8.0) + json (2.7.2) + language_server-protocol (3.17.0.3) + listen (3.9.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - lumberjack (1.2.8) - method_source (1.0.0) - minitest (5.19.0) + lumberjack (1.2.10) + method_source (1.1.0) + minitest (5.22.3) nenv (0.3.0) notiffany (0.1.3) nenv (~> 0.1) shellany (~> 0.0) - parallel (1.22.1) - parser (2.7.2.0) + parallel (1.24.0) + parser (3.3.1.0) ast (~> 2.4.1) + racc + prism (0.27.0) pry (0.14.2) coderay (~> 1.1) method_source (~> 1.0) - psych (3.1.0) + racc (1.7.3) + rack (3.0.11) rainbow (3.1.1) - rake (13.0.6) + rake (13.2.1) rb-fsevent (0.11.2) rb-inotify (0.10.1) ffi (~> 1.0) - reek (5.6.0) - codeclimate-engine-rb (~> 0.4.0) - kwalify (~> 0.7.0) - parser (>= 2.5.0.0, < 2.8, != 2.5.1.1) - psych (~> 3.1.0) - rainbow (>= 2.0, < 4.0) - rspec (3.12.0) - rspec-core (~> 3.12.0) - rspec-expectations (~> 3.12.0) - rspec-mocks (~> 3.12.0) - rspec-core (3.12.0) - rspec-support (~> 3.12.0) - rspec-expectations (3.12.2) + regexp_parser (2.9.0) + rexml (3.2.6) + rspec (3.13.0) + rspec-core (~> 3.13.0) + rspec-expectations (~> 3.13.0) + rspec-mocks (~> 3.13.0) + rspec-core (3.13.0) + rspec-support (~> 3.13.0) + rspec-expectations (3.13.0) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-mocks (3.12.3) + rspec-support (~> 3.13.0) + rspec-mocks (3.13.1) diff-lcs (>= 1.2.0, < 2.0) - rspec-support (~> 3.12.0) - rspec-support (3.12.0) - rubocop (0.72.0) - jaro_winkler (~> 1.5.1) + rspec-support (~> 3.13.0) + rspec-support (3.13.1) + rubocop (1.56.4) + base64 (~> 0.1.1) + json (~> 2.3) + language_server-protocol (>= 3.17.0) parallel (~> 1.10) - parser (>= 2.6) + parser (>= 3.2.2.3) rainbow (>= 2.2.2, < 4.0) + regexp_parser (>= 1.8, < 3.0) + rexml (>= 3.2.5, < 4.0) + rubocop-ast (>= 1.28.1, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 1.4.0, < 1.7) - rubocop-performance (1.6.1) - rubocop (>= 0.71.0) - rubocop-rspec (1.41.0) - rubocop (>= 0.68.1) - ruby-progressbar (1.11.0) + unicode-display_width (>= 2.4.0, < 3.0) + rubocop-ast (1.31.3) + parser (>= 3.3.1.0) + rubocop-capybara (2.20.0) + rubocop (~> 1.41) + rubocop-factory_bot (2.25.1) + rubocop (~> 1.41) + rubocop-performance (1.21.0) + rubocop (>= 1.48.1, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rails (2.24.1) + activesupport (>= 4.2.0) + rack (>= 1.1) + rubocop (>= 1.33.0, < 2.0) + rubocop-ast (>= 1.31.1, < 2.0) + rubocop-rake (0.6.0) + rubocop (~> 1.0) + rubocop-rspec (2.29.2) + rubocop (~> 1.40) + rubocop-capybara (~> 2.17) + rubocop-factory_bot (~> 2.22) + rubocop-rspec_rails (~> 2.28) + rubocop-rspec_rails (2.28.3) + rubocop (~> 1.40) + ruby-lsp (0.16.6) + language_server-protocol (~> 3.17.0) + prism (>= 0.23.0, < 0.28) + sorbet-runtime (>= 0.5.10782) + ruby-lsp-rails (0.3.6) + ruby-lsp (>= 0.16.5, < 0.17.0) + sorbet-runtime (>= 0.5.9897) + ruby-lsp-rspec (0.1.11) + ruby-lsp (~> 0.16.0) + ruby-progressbar (1.13.0) shellany (0.0.1) - simplecov (0.17.1) + simplecov (0.22.0) docile (~> 1.1) - json (>= 1.8, < 3) - simplecov-html (~> 0.10.0) - simplecov-html (0.10.2) - sqlite3 (1.6.0-x86_64-linux) - thor (1.2.1) + simplecov-html (~> 0.11) + simplecov_json_formatter (~> 0.1) + simplecov-html (0.12.3) + simplecov_json_formatter (0.1.4) + sorbet-runtime (0.5.11371) + sqlite3 (1.7.3-x86_64-darwin) + sqlite3 (1.7.3-x86_64-linux) + thor (1.3.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (1.6.1) + unicode-display_width (2.5.0) + zeitwerk (2.6.13) PLATFORMS + x86_64-darwin-22 x86_64-linux DEPENDENCIES - bundler (~> 2.0) - guard (~> 2.15) + guard (~> 2.18) guard-rspec (~> 4.7) - guard-rubocop (~> 1.3) + guard-rubocop (~> 1.5) human_enum! rake (~> 13.0) - reek (~> 5.6.0) - rspec (~> 3.0) - rubocop (~> 0.72.0) - rubocop-performance (~> 1.5) - rubocop-rspec (~> 1.36) - simplecov (~> 0.17.1) + rspec (~> 3.12) + rubocop (~> 1.56.3) + rubocop-performance + rubocop-rails + rubocop-rake + rubocop-rspec + ruby-lsp-rails + ruby-lsp-rspec + simplecov (~> 0.22.0) sqlite3 (~> 1.4) BUNDLED WITH - 2.4.5 + 2.4.19 diff --git a/Guardfile b/Guardfile index 2d18d3f..2ca5fac 100644 --- a/Guardfile +++ b/Guardfile @@ -9,8 +9,6 @@ guard :rspec, cmd: 'bundle exec rspec' do require 'guard/rspec/dsl' dsl = Guard::RSpec::Dsl.new(self) - # Feel free to open issues for suggestions and improvements - # RSpec files rspec = dsl.rspec watch(rspec.spec_helper) { rspec.spec_dir } @@ -20,10 +18,4 @@ guard :rspec, cmd: 'bundle exec rspec' do # Ruby files ruby = dsl.ruby dsl.watch_spec_files_for(ruby.lib_files) - - # Turnip features and steps - watch(%r{^spec/acceptance/(.+)\.feature$}) - watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) do |m| - Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' - end end diff --git a/README.md b/README.md index 31ed49b..0f68b65 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,14 @@ This gem allows you to specify enum value translations in your I18n locale files [![Maintainability](https://api.codeclimate.com/v1/badges/b1caef25c888cde6688e/maintainability)](https://codeclimate.com/github/rafasoares/human_enum/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/b1caef25c888cde6688e/test_coverage)](https://codeclimate.com/github/rafasoares/human_enum/test_coverage) +## Requirements + +This gem only supports actively maintained versions of Ruby and Rails. Currently, that is: +* Ruby 3.0+ +* Rails 6.1+ + +It may work with older versions, but it is not officially supported. + ## Installation Add this line to your application's Gemfile: @@ -16,15 +24,19 @@ gem 'human_enum' And then execute: - $ bundle +```sh +bundle +``` Or install it yourself as: - $ gem install human_enum +```sh +gem install human_enum +``` ## Usage -First, include the concern in your models: +First, include the concern in your models. ```ruby class MyModel < ApplicationRecord @@ -32,7 +44,7 @@ class MyModel < ApplicationRecord end ``` -Alternativelly, add it to your `ApplicationRecord` to add the functionality to every model in your application: +For convenience, you can add it to your `ApplicationRecord` to add the functionality to every model in your application. For models that don't declare `enum` attributes, no extra logic is called. ```ruby class ApplicationRecord < ActiveRecord::Base @@ -42,15 +54,15 @@ class ApplicationRecord < ActiveRecord::Base end ``` -Declare your enums as you normally would: +Then declare your enums as you normally would: ```ruby class MyModel < ApplicationRecord - enum model_type: [:default, :special] + enum model_type: %i[default special] end ``` -And add the enum values to your locale files under the pluralized version of the enum attribute: +And add the enum values to your locale files under the **pluralized** version of the enum attribute: ```yaml en: @@ -62,10 +74,12 @@ en: special: I am so special ``` -Then, you can use the helper method `human_[enum_attribute_name]` whenever you need the translated / humanized version of the enum value: +Note: internally, `human_enum` uses the model's [`i18n_scope`](https://api.rubyonrails.org/classes/ActiveModel/Translation.html#method-i-i18n_scope), so any customizations to your model/I18n setup should be automatically picked up. + +Finally, you can use the helper method `human_[enum_attribute_name]` whenever you need the translated/human version of the enum value: ```ruby -model = MyModel.new model_type: :special +model = MyModel.new(model_type: :special) puts model.human_model_type # "I am so special" ``` @@ -77,9 +91,9 @@ puts MyModel.human_model_types # "{default: 'Default Type', special: 'I am so sp ## Development -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To install this gem onto your local machine, run `bin/rake install`. ## Contributing diff --git a/bin/rake b/bin/rake index 4eb7d7b..9646b91 100755 --- a/bin/rake +++ b/bin/rake @@ -8,12 +8,12 @@ # this file is here to facilitate running it. # -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) -bundle_binstub = File.expand_path("bundle", __dir__) +bundle_binstub = File.expand_path('bundle', __dir__) if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") + if File.read(bundle_binstub, 300).include?('This file was generated by Bundler') load(bundle_binstub) else abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. @@ -21,7 +21,7 @@ Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this end end -require "rubygems" -require "bundler/setup" +require 'rubygems' +require 'bundler/setup' -load Gem.bin_path("rake", "rake") +load Gem.bin_path('rake', 'rake') diff --git a/bin/rspec b/bin/rspec new file mode 100755 index 0000000..b79c4d1 --- /dev/null +++ b/bin/rspec @@ -0,0 +1,27 @@ +#!/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. +# + +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +bundle_binstub = File.expand_path('bundle', __dir__) + +if File.file?(bundle_binstub) + if File.read(bundle_binstub, 300).include?('This file was generated by Bundler') + load(bundle_binstub) + else + abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. +Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") + end +end + +require 'rubygems' +require 'bundler/setup' + +load Gem.bin_path('rspec-core', 'rspec') diff --git a/bin/setup b/bin/setup index dce67d8..cf4ad25 100755 --- a/bin/setup +++ b/bin/setup @@ -4,5 +4,3 @@ IFS=$'\n\t' set -vx bundle install - -# Do any other automated setup that you need to do here diff --git a/human_enum.gemspec b/human_enum.gemspec index a156973..67516e1 100644 --- a/human_enum.gemspec +++ b/human_enum.gemspec @@ -8,7 +8,10 @@ Gem::Specification.new do |spec| spec.name = 'human_enum' spec.version = HumanEnum::VERSION spec.authors = ['Rafael Soares'] - spec.email = ['rafasoaresms@gmail.com'] + spec.email = ['893971+rafasoares@users.noreply.github.com'] + + # Should always be the lowest maint version of Ruby + spec.required_ruby_version = '>= 3.0.0' spec.summary = 'Adds simple and easy I18n support for Rails enums' spec.description = 'This gem allows you to specify enum value translations @@ -19,7 +22,8 @@ Gem::Specification.new do |spec| spec.metadata['homepage_uri'] = spec.homepage spec.metadata['source_code_uri'] = 'https://github.com/rafasoares/human_enum' - spec.metadata['changelog_uri'] = 'https://github.com/rafasoares/human_enum/blob/master/CHANGELOG.md' + spec.metadata['changelog_uri'] = 'https://github.com/rafasoares/human_enum/blob/main/CHANGELOG.md' + spec.metadata['rubygems_mfa_required'] = 'true' spec.files = `git ls-files -z`.split("\x0").reject do |f| f.match(%r{^(test|spec|features)/}) @@ -28,22 +32,5 @@ Gem::Specification.new do |spec| spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } spec.require_paths = ['lib'] - spec.add_development_dependency 'bundler', '~> 2.0' - spec.add_development_dependency 'rake', '~> 13.0' - spec.add_development_dependency 'rspec', '~> 3.0' - spec.add_development_dependency 'simplecov', '~> 0.17.1' - - spec.add_development_dependency 'rubocop', '~> 0.72.0' - spec.add_development_dependency 'rubocop-performance', '~> 1.5' - spec.add_development_dependency 'rubocop-rspec', '~> 1.36' - - spec.add_development_dependency 'reek', '~> 5.6.0' - - spec.add_development_dependency 'guard', '~> 2.15' - spec.add_development_dependency 'guard-rspec', '~> 4.7' - spec.add_development_dependency 'guard-rubocop', '~> 1.3' - - spec.add_development_dependency 'sqlite3', '~> 1.4' - - spec.add_dependency 'activerecord', '> 5.0.0' + spec.add_dependency 'activerecord', '>= 6.1', '< 7' end diff --git a/lib/human_enum.rb b/lib/human_enum.rb index 886f930..e36c1ea 100644 --- a/lib/human_enum.rb +++ b/lib/human_enum.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'human_enum/version' +require 'active_support' require 'active_support/concern' require 'active_support/core_ext/array' require 'active_model/naming' @@ -45,7 +46,7 @@ def human_enum_value(enum_name, enum_value) defaults << :"attributes.#{enum_key}" defaults << enum_value.to_s.humanize - I18n.translate defaults.shift, default: defaults + I18n.t defaults.shift, default: defaults end def human_enum(enum_name) diff --git a/spec/human_enum_spec.rb b/spec/human_enum_spec.rb index 759c27e..226941b 100644 --- a/spec/human_enum_spec.rb +++ b/spec/human_enum_spec.rb @@ -1,5 +1,7 @@ # frozen_string_literal: true +require 'setup_helper' + class TestModel < ActiveRecord::Base include HumanEnum @@ -8,7 +10,7 @@ class TestModel < ActiveRecord::Base RSpec.describe HumanEnum do it 'has a version number' do - expect(HumanEnum::VERSION).not_to be nil + expect(HumanEnum::VERSION).not_to be_nil end context 'when included' do @@ -21,7 +23,7 @@ class TestModel < ActiveRecord::Base it { is_expected.to respond_to :human_enum_value } end - describe 'Model class method' do + describe 'Model class methods' do subject(:values) { TestModel.human_my_enums } let(:expected_values) do @@ -40,7 +42,7 @@ class TestModel < ActiveRecord::Base subject { TestModel.new(params).human_my_enum } context 'with a blank value' do - let(:params) {} + let(:params) { {} } it { is_expected.to be_nil } end diff --git a/spec/setup_helper.rb b/spec/setup_helper.rb new file mode 100644 index 0000000..e80686f --- /dev/null +++ b/spec/setup_helper.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +require 'simplecov' + +SimpleCov.start do + add_filter '/spec/' +end + +require 'bundler/setup' +require 'human_enum' + +Dir[File.join(__dir__, 'support', '*.rb')].each { |f| require f } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 3a231b9..1d6bed9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,32 +1,98 @@ # frozen_string_literal: true -require 'simplecov' -SimpleCov.start do - add_filter '/spec/' -end +# 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. +# +# See https://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration +RSpec.configure do |config| + # 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 -require 'bundler/setup' -require 'active_record' -require 'human_enum' + expectations.syntax = :expect + end -RSpec.configure do |config| - support_path = File.join(config.default_path, 'support') + # 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 + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + + # This allows 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. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # 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: + # https://rspec.info/features/3-12/rspec-core/configuration/zero-monkey-patching-mode/ + config.disable_monkey_patching! - # Enable flags like --only-failures and --next-failure - config.example_status_persistence_file_path = '.rspec_status' + # This setting enables warnings. It's recommended, but in some cases may + # be too noisy due to issues in dependencies. + config.warnings = true - config.expect_with :rspec do |c| - c.syntax = :expect + # 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 - # Use an in-memory DB since we don't need persistence - config_file_path = File.join(support_path, 'db', 'database.yml') - db_config = YAML.safe_load(File.open(config_file_path)) + # 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 - ActiveRecord::Base.establish_connection(db_config['sqlite3']) - load File.join(support_path, 'db', 'schema.rb') + # 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 - # Set up I18n - I18n.load_path += Dir[File.join(support_path, 'locales', '*.{rb,yml}')] - I18n.default_locale = :en + # 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/support/db.rb b/spec/support/db.rb new file mode 100644 index 0000000..8f79366 --- /dev/null +++ b/spec/support/db.rb @@ -0,0 +1,17 @@ +# frozen_string_literal: true + +require 'active_record' + +RSpec.configure do |_config| + ActiveRecord::Base.establish_connection( + adapter: 'sqlite3', + database: ':memory:', + encoding: 'utf8' + ) + + ActiveRecord::Schema.define do + create_table 'test_models' do |t| + t.string 'my_enum' + end + end +end diff --git a/spec/support/db/database.yml b/spec/support/db/database.yml deleted file mode 100644 index 3fcda8e..0000000 --- a/spec/support/db/database.yml +++ /dev/null @@ -1,4 +0,0 @@ -sqlite3: - adapter: sqlite3 - database: ":memory:" - encoding: utf8 diff --git a/spec/support/db/schema.rb b/spec/support/db/schema.rb deleted file mode 100644 index e838ae9..0000000 --- a/spec/support/db/schema.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -ActiveRecord::Schema.define do - create_table 'test_models' do |t| - t.string 'my_enum' - end -end diff --git a/spec/support/i18n.rb b/spec/support/i18n.rb new file mode 100644 index 0000000..164414a --- /dev/null +++ b/spec/support/i18n.rb @@ -0,0 +1,8 @@ +# frozen_string_literal: true + +RSpec.configure do |_config| + locales_path = File.join(__dir__, 'locales', '*.{rb,yml}') + + I18n.load_path += Dir[locales_path] + I18n.default_locale = :en +end