From bd72d2a64fba9d7ca8daa2995ec7f73534ea62a5 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Wed, 9 Oct 2019 22:25:20 -0400 Subject: [PATCH] Add sample Rails application (#9) * Add rails application * Run tests for sample Rails app --- .github/workflows/ruby.yml | 20 ++++ .rubocop.yml | 1 + spec/rails/.gitignore | 73 ++++++++++++ spec/rails/.ruby-version | 1 + spec/rails/Gemfile | 33 ++++++ spec/rails/README.md | 27 +++++ spec/rails/Rakefile | 6 + spec/rails/app/services/environment_tester.rb | 5 + spec/rails/bin/bundle | 105 ++++++++++++++++++ spec/rails/bin/rails | 9 ++ spec/rails/bin/rake | 9 ++ spec/rails/bin/setup | 25 +++++ spec/rails/bin/spring | 17 +++ spec/rails/config.ru | 5 + spec/rails/config/application.rb | 37 ++++++ spec/rails/config/boot.rb | 4 + spec/rails/config/credentials.yml.enc | 1 + spec/rails/config/environment.rb | 5 + spec/rails/config/environments/development.rb | 38 +++++++ spec/rails/config/environments/production.rb | 88 +++++++++++++++ spec/rails/config/environments/test.rb | 38 +++++++ .../application_controller_renderer.rb | 8 ++ .../initializers/backtrace_silencers.rb | 7 ++ spec/rails/config/initializers/cors.rb | 16 +++ .../initializers/filter_parameter_logging.rb | 4 + spec/rails/config/initializers/inflections.rb | 16 +++ spec/rails/config/initializers/mime_types.rb | 4 + .../config/initializers/wrap_parameters.rb | 9 ++ spec/rails/config/locales/en.yml | 33 ++++++ spec/rails/config/puma.rb | 38 +++++++ spec/rails/config/routes.rb | 3 + spec/rails/config/spring.rb | 6 + spec/rails/lib/tasks/.keep | 0 spec/rails/log/.keep | 0 spec/rails/public/robots.txt | 1 + .../test/services/environment_tester_test.rb | 10 ++ spec/rails/test/test_helper.rb | 11 ++ spec/rails/tmp/.keep | 0 spec/rails/vendor/.keep | 0 39 files changed, 713 insertions(+) create mode 100644 spec/rails/.gitignore create mode 100644 spec/rails/.ruby-version create mode 100644 spec/rails/Gemfile create mode 100644 spec/rails/README.md create mode 100644 spec/rails/Rakefile create mode 100644 spec/rails/app/services/environment_tester.rb create mode 100755 spec/rails/bin/bundle create mode 100755 spec/rails/bin/rails create mode 100755 spec/rails/bin/rake create mode 100755 spec/rails/bin/setup create mode 100755 spec/rails/bin/spring create mode 100644 spec/rails/config.ru create mode 100644 spec/rails/config/application.rb create mode 100644 spec/rails/config/boot.rb create mode 100644 spec/rails/config/credentials.yml.enc create mode 100644 spec/rails/config/environment.rb create mode 100644 spec/rails/config/environments/development.rb create mode 100644 spec/rails/config/environments/production.rb create mode 100644 spec/rails/config/environments/test.rb create mode 100644 spec/rails/config/initializers/application_controller_renderer.rb create mode 100644 spec/rails/config/initializers/backtrace_silencers.rb create mode 100644 spec/rails/config/initializers/cors.rb create mode 100644 spec/rails/config/initializers/filter_parameter_logging.rb create mode 100644 spec/rails/config/initializers/inflections.rb create mode 100644 spec/rails/config/initializers/mime_types.rb create mode 100644 spec/rails/config/initializers/wrap_parameters.rb create mode 100644 spec/rails/config/locales/en.yml create mode 100644 spec/rails/config/puma.rb create mode 100644 spec/rails/config/routes.rb create mode 100644 spec/rails/config/spring.rb create mode 100644 spec/rails/lib/tasks/.keep create mode 100644 spec/rails/log/.keep create mode 100644 spec/rails/public/robots.txt create mode 100644 spec/rails/test/services/environment_tester_test.rb create mode 100644 spec/rails/test/test_helper.rb create mode 100644 spec/rails/tmp/.keep create mode 100644 spec/rails/vendor/.keep diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index a4feaf8..da32f34 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -34,3 +34,23 @@ jobs: gem install bundler -v 1.16 bundle install --jobs 4 --retry 3 bundle exec rspec + + rails: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - name: Set up Ruby 2.6 + uses: actions/setup-ruby@v1 + with: + ruby-version: 2.6.x + - name: Test gem in Rails application + run: | + cd spec/rails + gem install bundler + bundle install --jobs 4 --retry 3 + bundle exec rails test + env: + AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} + AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + AWS_DEFAULT_REGION: us-east-2 + PARAMETER_STORE_PATH: /psenv/test/ diff --git a/.rubocop.yml b/.rubocop.yml index e94ee3a..8dc1533 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,7 @@ AllCops: Exclude: - db/schema.rb - vendor/**/* + - spec/rails/**/* Metrics/LineLength: Description: 'Limit lines to 80 characters.' diff --git a/spec/rails/.gitignore b/spec/rails/.gitignore new file mode 100644 index 0000000..e813bf3 --- /dev/null +++ b/spec/rails/.gitignore @@ -0,0 +1,73 @@ + +# Created by https://www.gitignore.io/api/rails +# Edit at https://www.gitignore.io/?templates=rails + +### Rails ### +*.rbc +capybara-*.html +.rspec +/db/*.sqlite3 +/db/*.sqlite3-journal +/public/system +/coverage/ +/spec/tmp +*.orig +rerun.txt +pickle-email-*.html + +# Ignore all logfiles and tempfiles. +/log/* +/tmp/* +!/log/.keep +!/tmp/.keep + +# TODO Comment out this rule if you are OK with secrets being uploaded to the repo +config/initializers/secret_token.rb +config/master.key + +# Only include if you have production secrets in this file, which is no longer a Rails default +# config/secrets.yml + +# dotenv +# TODO Comment out this rule if environment variables can be committed +.env + +## Environment normalization: +/.bundle +/vendor/bundle + +# these should all be checked in to normalize the environment: +# Gemfile.lock, .ruby-version, .ruby-gemset + +# unless supporting rvm < 1.11.0 or doing something fancy, ignore this: +.rvmrc + +# if using bower-rails ignore default bower_components path bower.json files +/vendor/assets/bower_components +*.bowerrc +bower.json + +# Ignore pow environment settings +.powenv + +# Ignore Byebug command history file. +.byebug_history + +# Ignore node_modules +node_modules/ + +# Ignore precompiled javascript packs +/public/packs +/public/packs-test +/public/assets + +# Ignore yarn files +/yarn-error.log +yarn-debug.log* +.yarn-integrity + +# Ignore uploaded files in development +/storage/* +!/storage/.keep + +# End of https://www.gitignore.io/api/rails diff --git a/spec/rails/.ruby-version b/spec/rails/.ruby-version new file mode 100644 index 0000000..ec1cf33 --- /dev/null +++ b/spec/rails/.ruby-version @@ -0,0 +1 @@ +2.6.3 diff --git a/spec/rails/Gemfile b/spec/rails/Gemfile new file mode 100644 index 0000000..eae3737 --- /dev/null +++ b/spec/rails/Gemfile @@ -0,0 +1,33 @@ +source 'https://rubygems.org' +git_source(:github) { |repo| "https://github.com/#{repo}.git" } + +ruby '2.6.3' + +# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' +gem 'rails', '~> 6.0.0' +# Use Puma as the app server +gem 'puma', '~> 3.11' +# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder +# gem 'jbuilder', '~> 2.7' +# Use Active Model has_secure_password +# gem 'bcrypt', '~> 3.1.7' + +# Reduces boot times through caching; required in config/boot.rb +gem 'bootsnap', '>= 1.4.2', require: false + +# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible +# gem 'rack-cors' + +gem 'psenv-rails' + +group :development, :test do + # Call 'byebug' anywhere in the code to stop execution and get a debugger console + gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] +end + +group :development do + gem 'listen', '>= 3.0.5', '< 3.2' +end + +# Windows does not include zoneinfo files, so bundle the tzinfo-data gem +gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] diff --git a/spec/rails/README.md b/spec/rails/README.md new file mode 100644 index 0000000..20a452e --- /dev/null +++ b/spec/rails/README.md @@ -0,0 +1,27 @@ +# psenv-test + +Used for testing the psenv-rails gem to validate. + +## Usage + +* Generate new parameter store variable in AWS + * `/psenv/test/API_KEY` with value "api_key_value" +* `PARAMETER_STORE_PATH=/psenv/test bundle exec rails test` + +## New Versions + +To test new versions of the gem, you can install the psenv-rails gem locally and +reference it: + +1. Clone psenv and complete work + 1. Likely updating Railtie requirements +1. Update psenv lib/psenv/version.rb + 1. Example version name: `0.5.16-local` +1. Run `bundle exec rake install` in psenv directory +1. Note new gem version installed locally + 1. Example gem version: `0.5.16.pre.local` +1. Open psenv-test project +1. Update Gemfile with test version + 1. `gem 'psenv-rails', '0.5.16.pre.local'` + 1. `bundle install` +1. `PARAMETER_STORE_PATH=/psenv/test bundle exec rails test` diff --git a/spec/rails/Rakefile b/spec/rails/Rakefile new file mode 100644 index 0000000..e85f913 --- /dev/null +++ b/spec/rails/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_relative 'config/application' + +Rails.application.load_tasks diff --git a/spec/rails/app/services/environment_tester.rb b/spec/rails/app/services/environment_tester.rb new file mode 100644 index 0000000..e78250d --- /dev/null +++ b/spec/rails/app/services/environment_tester.rb @@ -0,0 +1,5 @@ +class EnvironmentTester + def self.call + ENV.fetch('API_KEY', '') + end +end diff --git a/spec/rails/bin/bundle b/spec/rails/bin/bundle new file mode 100755 index 0000000..4f5e057 --- /dev/null +++ b/spec/rails/bin/bundle @@ -0,0 +1,105 @@ +#!/usr/bin/env ruby +# frozen_string_literal: true + +# +# This file was generated by Bundler. +# +# The application 'bundle' is installed as part of a gem, and +# this file is here to facilitate running it. +# + +require "rubygems" + +m = Module.new do + module_function + + def invoked_as_script? + File.expand_path($0) == File.expand_path(__FILE__) + end + + def env_var_version + ENV["BUNDLER_VERSION"] + end + + def cli_arg_version + return unless invoked_as_script? # don't want to hijack other binstubs + return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update` + bundler_version = nil + update_index = nil + ARGV.each_with_index do |a, i| + if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN + bundler_version = a + end + next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/ + bundler_version = $1 || ">= 0.a" + update_index = i + end + bundler_version + end + + def gemfile + gemfile = ENV["BUNDLE_GEMFILE"] + return gemfile if gemfile && !gemfile.empty? + + File.expand_path("../../Gemfile", __FILE__) + end + + def lockfile + lockfile = + case File.basename(gemfile) + when "gems.rb" then gemfile.sub(/\.rb$/, gemfile) + else "#{gemfile}.lock" + end + File.expand_path(lockfile) + end + + def lockfile_version + return unless File.file?(lockfile) + lockfile_contents = File.read(lockfile) + return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/ + Regexp.last_match(1) + end + + def bundler_version + @bundler_version ||= begin + env_var_version || cli_arg_version || + lockfile_version || "#{Gem::Requirement.default}.a" + end + end + + def load_bundler! + ENV["BUNDLE_GEMFILE"] ||= gemfile + + # must dup string for RG < 1.8 compatibility + activate_bundler(bundler_version.dup) + end + + def activate_bundler(bundler_version) + if Gem::Version.correct?(bundler_version) && Gem::Version.new(bundler_version).release < Gem::Version.new("2.0") + bundler_version = "< 2" + end + gem_error = activation_error_handling do + gem "bundler", bundler_version + end + return if gem_error.nil? + require_error = activation_error_handling do + require "bundler/version" + end + return if require_error.nil? && Gem::Requirement.new(bundler_version).satisfied_by?(Gem::Version.new(Bundler::VERSION)) + warn "Activating bundler (#{bundler_version}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_version}'`" + exit 42 + end + + def activation_error_handling + yield + nil + rescue StandardError, LoadError => e + e + end +end + +m.load_bundler! + +if m.invoked_as_script? + load Gem.bin_path("bundler", "bundle") +end diff --git a/spec/rails/bin/rails b/spec/rails/bin/rails new file mode 100755 index 0000000..5badb2f --- /dev/null +++ b/spec/rails/bin/rails @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +APP_PATH = File.expand_path('../config/application', __dir__) +require_relative '../config/boot' +require 'rails/commands' diff --git a/spec/rails/bin/rake b/spec/rails/bin/rake new file mode 100755 index 0000000..d87d5f5 --- /dev/null +++ b/spec/rails/bin/rake @@ -0,0 +1,9 @@ +#!/usr/bin/env ruby +begin + load File.expand_path('../spring', __FILE__) +rescue LoadError => e + raise unless e.message.include?('spring') +end +require_relative '../config/boot' +require 'rake' +Rake.application.run diff --git a/spec/rails/bin/setup b/spec/rails/bin/setup new file mode 100755 index 0000000..2e29ac1 --- /dev/null +++ b/spec/rails/bin/setup @@ -0,0 +1,25 @@ +#!/usr/bin/env ruby +require 'fileutils' + +# path to your application root. +APP_ROOT = File.expand_path('..', __dir__) + +def system!(*args) + system(*args) || abort("\n== Command #{args} failed ==") +end + +FileUtils.chdir APP_ROOT do + # This script is a way to setup or update your development environment automatically. + # This script is idempotent, so that you can run it at anytime and get an expectable outcome. + # Add necessary setup steps to this file. + + puts '== Installing dependencies ==' + system! 'gem install bundler --conservative' + system('bundle check') || system!('bundle install') + + puts "\n== Removing old logs and tempfiles ==" + system! 'bin/rails log:clear tmp:clear' + + puts "\n== Restarting application server ==" + system! 'bin/rails restart' +end diff --git a/spec/rails/bin/spring b/spec/rails/bin/spring new file mode 100755 index 0000000..d89ee49 --- /dev/null +++ b/spec/rails/bin/spring @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +# This file loads Spring without using Bundler, in order to be fast. +# It gets overwritten when you run the `spring binstub` command. + +unless defined?(Spring) + require 'rubygems' + require 'bundler' + + lockfile = Bundler::LockfileParser.new(Bundler.default_lockfile.read) + spring = lockfile.specs.detect { |spec| spec.name == 'spring' } + if spring + Gem.use_paths Gem.dir, Bundler.bundle_path.to_s, *Gem.path + gem 'spring', spring.version + require 'spring/binstub' + end +end diff --git a/spec/rails/config.ru b/spec/rails/config.ru new file mode 100644 index 0000000..f7ba0b5 --- /dev/null +++ b/spec/rails/config.ru @@ -0,0 +1,5 @@ +# This file is used by Rack-based servers to start the application. + +require_relative 'config/environment' + +run Rails.application diff --git a/spec/rails/config/application.rb b/spec/rails/config/application.rb new file mode 100644 index 0000000..d48c329 --- /dev/null +++ b/spec/rails/config/application.rb @@ -0,0 +1,37 @@ +require_relative 'boot' + +require "rails" +# Pick the frameworks you want: +# require "active_model/railtie" +# require "active_job/railtie" +# require "active_record/railtie" +# require "active_storage/engine" +# require "action_controller/railtie" +# require "action_mailer/railtie" +# require "action_mailbox/engine" +# require "action_text/engine" +# require "action_view/railtie" +# require "action_cable/engine" +# require "sprockets/railtie" +require "rails/test_unit/railtie" + +# Require the gems listed in Gemfile, including any gems +# you've limited to :test, :development, or :production. +Bundler.require(*Rails.groups) + +module PsenvTest + class Application < Rails::Application + # Initialize configuration defaults for originally generated Rails version. + config.load_defaults 6.0 + + # Settings in config/environments/* take precedence over those specified here. + # Application configuration can go into files in config/initializers + # -- all .rb files in that directory are automatically loaded after loading + # the framework and any gems in your application. + + # Only loads a smaller set of middleware suitable for API only apps. + # Middleware like session, flash, cookies can be added back manually. + # Skip views, helpers and assets when generating a new resource. + config.api_only = true + end +end diff --git a/spec/rails/config/boot.rb b/spec/rails/config/boot.rb new file mode 100644 index 0000000..b9e460c --- /dev/null +++ b/spec/rails/config/boot.rb @@ -0,0 +1,4 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. +require 'bootsnap/setup' # Speed up boot time by caching expensive operations. diff --git a/spec/rails/config/credentials.yml.enc b/spec/rails/config/credentials.yml.enc new file mode 100644 index 0000000..3b6755f --- /dev/null +++ b/spec/rails/config/credentials.yml.enc @@ -0,0 +1 @@ +CCG/EQd33VifoFkRZcFpOp/puREeD3Yt0bh71aB6ab5LVHvctul0xKbeLAN1pyGi5Kk10V1+KBEGFRbpmK9mc923IlzFW3VVRap7D+Ek2cJNM6jA7olaMkLjRcYcsPQw6Hi+786z9jcTsk1UxY6haOr4r/uPklz6jcYl88nS4UnWu/83nWvOBjpSGv2uvz5OJE4wqggFaTe8i93VOvANDE0OMrXrdHcH8h1GPgXm5EGOvArKCnsY4FDrxyyaK9Sx9pRUteh1Xz1FZWLeav5pwMkZw00c7JFWjy2HxNBtdvIP6m0GfssetpyekFIcj9zOcxOCXXzaEhuoT+QY8kOAr5rgEW+f6l9lcKevRcC2UhTNd0FnhUku9mPuq03qyM8pvxlzjL7vs6/OG+raYSoApHomf35c+Sq6BxtC--rzZBIPCfBwWkW2ZH--xSV/WdQx1za3nDCsx0NKhg== \ No newline at end of file diff --git a/spec/rails/config/environment.rb b/spec/rails/config/environment.rb new file mode 100644 index 0000000..426333b --- /dev/null +++ b/spec/rails/config/environment.rb @@ -0,0 +1,5 @@ +# Load the Rails application. +require_relative 'application' + +# Initialize the Rails application. +Rails.application.initialize! diff --git a/spec/rails/config/environments/development.rb b/spec/rails/config/environments/development.rb new file mode 100644 index 0000000..96892b3 --- /dev/null +++ b/spec/rails/config/environments/development.rb @@ -0,0 +1,38 @@ +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. + config.consider_all_requests_local = true + + # Enable/disable caching. By default caching is disabled. + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? + config.cache_store = :memory_store + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{2.days.to_i}" + } + else + # config.action_controller.perform_caching = false + + config.cache_store = :null_store + end + + # Print deprecation notices to the Rails logger. + config.active_support.deprecation = :log + + + # Raises error for missing translations. + # config.action_view.raise_on_missing_translations = true + + # Use an evented file watcher to asynchronously detect changes in source code, + # routes, locales, etc. This feature depends on the listen gem. + config.file_watcher = ActiveSupport::EventedFileUpdateChecker +end diff --git a/spec/rails/config/environments/production.rb b/spec/rails/config/environments/production.rb new file mode 100644 index 0000000..9edb779 --- /dev/null +++ b/spec/rails/config/environments/production.rb @@ -0,0 +1,88 @@ +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 + + # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] + # or in config/master.key. This key is used to decrypt credentials (and other encrypted files). + # config.require_master_key = true + + # Disable serving static files from the `/public` folder by default since + # Apache or NGINX already handles this. + config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? + + # Enable serving of images, stylesheets, and JavaScripts from an asset server. + # config.action_controller.asset_host = 'http://assets.example.com' + + # 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 = [ :request_id ] + + # Use a different cache store in production. + # config.cache_store = :mem_cache_store + + # Use a real queuing backend for Active Job (and separate queues per environment). + # config.active_job.queue_adapter = :resque + # config.active_job.queue_name_prefix = "psenv_test_production" + + # 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 + + # Use a different logger for distributed setups. + # require 'syslog/logger' + # config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') + + if ENV["RAILS_LOG_TO_STDOUT"].present? + logger = ActiveSupport::Logger.new(STDOUT) + logger.formatter = config.log_formatter + config.logger = ActiveSupport::TaggedLogging.new(logger) + end + + # Inserts middleware to perform automatic connection switching. + # The `database_selector` hash is used to pass options to the DatabaseSelector + # middleware. The `delay` is used to determine how long to wait after a write + # to send a subsequent read to the primary. + # + # The `database_resolver` class is used by the middleware to determine which + # database is appropriate to use based on the time delay. + # + # The `database_resolver_context` class is used by the middleware to set + # timestamps for the last write to the primary. The resolver uses the context + # class timestamps to determine how long to wait before reading from the + # replica. + # + # By default Rails will store a last write timestamp in the session. The + # DatabaseSelector middleware is designed as such you can define your own + # strategy for connection switching and pass that into the middleware through + # these configuration options. + # config.active_record.database_selector = { delay: 2.seconds } + # config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver + # config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session +end diff --git a/spec/rails/config/environments/test.rb b/spec/rails/config/environments/test.rb new file mode 100644 index 0000000..c752dfc --- /dev/null +++ b/spec/rails/config/environments/test.rb @@ -0,0 +1,38 @@ +# 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! + +Rails.application.configure do + # Settings specified here will take precedence over those in config/application.rb. + + config.cache_classes = false + + # 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 public file server for tests with Cache-Control for performance. + config.public_file_server.enabled = true + config.public_file_server.headers = { + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" + } + + # Show full error reports and disable caching. + config.consider_all_requests_local = true + # config.action_controller.perform_caching = false + config.cache_store = :null_store + + # 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 + + # 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/rails/config/initializers/application_controller_renderer.rb b/spec/rails/config/initializers/application_controller_renderer.rb new file mode 100644 index 0000000..89d2efa --- /dev/null +++ b/spec/rails/config/initializers/application_controller_renderer.rb @@ -0,0 +1,8 @@ +# Be sure to restart your server when you modify this file. + +# ActiveSupport::Reloader.to_prepare do +# ApplicationController.renderer.defaults.merge!( +# http_host: 'example.org', +# https: false +# ) +# end diff --git a/spec/rails/config/initializers/backtrace_silencers.rb b/spec/rails/config/initializers/backtrace_silencers.rb new file mode 100644 index 0000000..59385cd --- /dev/null +++ b/spec/rails/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/rails/config/initializers/cors.rb b/spec/rails/config/initializers/cors.rb new file mode 100644 index 0000000..3b1c1b5 --- /dev/null +++ b/spec/rails/config/initializers/cors.rb @@ -0,0 +1,16 @@ +# Be sure to restart your server when you modify this file. + +# Avoid CORS issues when API is called from the frontend app. +# Handle Cross-Origin Resource Sharing (CORS) in order to accept cross-origin AJAX requests. + +# Read more: https://github.com/cyu/rack-cors + +# Rails.application.config.middleware.insert_before 0, Rack::Cors do +# allow do +# origins 'example.com' +# +# resource '*', +# headers: :any, +# methods: [:get, :post, :put, :patch, :delete, :options, :head] +# end +# end diff --git a/spec/rails/config/initializers/filter_parameter_logging.rb b/spec/rails/config/initializers/filter_parameter_logging.rb new file mode 100644 index 0000000..4a994e1 --- /dev/null +++ b/spec/rails/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/rails/config/initializers/inflections.rb b/spec/rails/config/initializers/inflections.rb new file mode 100644 index 0000000..ac033bf --- /dev/null +++ b/spec/rails/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/rails/config/initializers/mime_types.rb b/spec/rails/config/initializers/mime_types.rb new file mode 100644 index 0000000..dc18996 --- /dev/null +++ b/spec/rails/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/rails/config/initializers/wrap_parameters.rb b/spec/rails/config/initializers/wrap_parameters.rb new file mode 100644 index 0000000..633c1c8 --- /dev/null +++ b/spec/rails/config/initializers/wrap_parameters.rb @@ -0,0 +1,9 @@ +# 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] +end diff --git a/spec/rails/config/locales/en.yml b/spec/rails/config/locales/en.yml new file mode 100644 index 0000000..cf9b342 --- /dev/null +++ b/spec/rails/config/locales/en.yml @@ -0,0 +1,33 @@ +# 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. +# +# The following keys must be escaped otherwise they will not be retrieved by +# the default I18n backend: +# +# true, false, on, off, yes, no +# +# Instead, surround them with single quotes. +# +# en: +# 'true': 'foo' +# +# To learn more, please read the Rails Internationalization guide +# available at https://guides.rubyonrails.org/i18n.html. + +en: + hello: "Hello world" diff --git a/spec/rails/config/puma.rb b/spec/rails/config/puma.rb new file mode 100644 index 0000000..5ed4437 --- /dev/null +++ b/spec/rails/config/puma.rb @@ -0,0 +1,38 @@ +# Puma can serve each request in a thread from an internal thread pool. +# The `threads` method setting takes two numbers: a minimum and maximum. +# Any libraries that use thread pools should be configured to match +# the maximum value specified for Puma. Default is set to 5 threads for minimum +# and maximum; this matches the default thread size of Active Record. +# +max_threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } +min_threads_count = ENV.fetch("RAILS_MIN_THREADS") { max_threads_count } +threads min_threads_count, max_threads_count + +# Specifies the `port` that Puma will listen on to receive requests; default is 3000. +# +port ENV.fetch("PORT") { 3000 } + +# Specifies the `environment` that Puma will run in. +# +environment ENV.fetch("RAILS_ENV") { "development" } + +# Specifies the `pidfile` that Puma will use. +pidfile ENV.fetch("PIDFILE") { "tmp/pids/server.pid" } + +# Specifies the number of `workers` to boot in clustered mode. +# Workers are forked web server processes. If using threads and workers together +# the concurrency of the application would be max `threads` * `workers`. +# Workers do not work on JRuby or Windows (both of which do not support +# processes). +# +# workers ENV.fetch("WEB_CONCURRENCY") { 2 } + +# Use the `preload_app!` method when specifying a `workers` number. +# This directive tells Puma to first boot the application and load code +# before forking the application. This takes advantage of Copy On Write +# process behavior so workers use less memory. +# +# preload_app! + +# Allow puma to be restarted by `rails restart` command. +plugin :tmp_restart diff --git a/spec/rails/config/routes.rb b/spec/rails/config/routes.rb new file mode 100644 index 0000000..c06383a --- /dev/null +++ b/spec/rails/config/routes.rb @@ -0,0 +1,3 @@ +Rails.application.routes.draw do + # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html +end diff --git a/spec/rails/config/spring.rb b/spec/rails/config/spring.rb new file mode 100644 index 0000000..db5bf13 --- /dev/null +++ b/spec/rails/config/spring.rb @@ -0,0 +1,6 @@ +Spring.watch( + ".ruby-version", + ".rbenv-vars", + "tmp/restart.txt", + "tmp/caching-dev.txt" +) diff --git a/spec/rails/lib/tasks/.keep b/spec/rails/lib/tasks/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/rails/log/.keep b/spec/rails/log/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/rails/public/robots.txt b/spec/rails/public/robots.txt new file mode 100644 index 0000000..c19f78a --- /dev/null +++ b/spec/rails/public/robots.txt @@ -0,0 +1 @@ +# See https://www.robotstxt.org/robotstxt.html for documentation on how to use the robots.txt file diff --git a/spec/rails/test/services/environment_tester_test.rb b/spec/rails/test/services/environment_tester_test.rb new file mode 100644 index 0000000..5a0533a --- /dev/null +++ b/spec/rails/test/services/environment_tester_test.rb @@ -0,0 +1,10 @@ +require 'test_helper' + +class EnvironmentTesterTest < Minitest::Test + describe '.call' do + subject { ::EnvironmentTester.call } + it 'returns the environment variable value' do + assert_equal 'api_key_value', subject + end + end +end diff --git a/spec/rails/test/test_helper.rb b/spec/rails/test/test_helper.rb new file mode 100644 index 0000000..75f0fe1 --- /dev/null +++ b/spec/rails/test/test_helper.rb @@ -0,0 +1,11 @@ +ENV['RAILS_ENV'] ||= 'test' +require_relative '../config/environment' +require 'rails/test_help' +require 'minitest/spec' + +class ActiveSupport::TestCase + # Run tests in parallel with specified workers + parallelize(workers: :number_of_processors) + + # Add more helper methods to be used by all tests here... +end diff --git a/spec/rails/tmp/.keep b/spec/rails/tmp/.keep new file mode 100644 index 0000000..e69de29 diff --git a/spec/rails/vendor/.keep b/spec/rails/vendor/.keep new file mode 100644 index 0000000..e69de29