From 4d2661ec5e281aa213b3033a61443c69d9c50205 Mon Sep 17 00:00:00 2001 From: Andrew Tomaka Date: Fri, 4 Oct 2019 23:08:31 -0400 Subject: [PATCH] Setup project for testing * Remove unecessary parts of Rails * Write tests * Document usage --- Gemfile | 5 ++- Gemfile.lock | 25 +++++++++++---- README.md | 39 +++++++++++++----------- app/services/environment_tester.rb | 5 +++ config/environments/development.rb | 2 +- config/environments/test.rb | 2 +- test/controllers/.keep | 0 test/fixtures/.keep | 0 test/fixtures/files/.keep | 0 test/integration/.keep | 0 test/models/.keep | 0 test/services/environment_tester_test.rb | 10 ++++++ test/test_helper.rb | 1 + 13 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 app/services/environment_tester.rb delete mode 100644 test/controllers/.keep delete mode 100644 test/fixtures/.keep delete mode 100644 test/fixtures/files/.keep delete mode 100644 test/integration/.keep delete mode 100644 test/models/.keep create mode 100644 test/services/environment_tester_test.rb diff --git a/Gemfile b/Gemfile index b5ea122..eae3737 100644 --- a/Gemfile +++ b/Gemfile @@ -18,6 +18,8 @@ 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] @@ -25,9 +27,6 @@ end group :development do gem 'listen', '>= 3.0.5', '< 3.2' - # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring - gem 'spring' - gem 'spring-watcher-listen', '~> 2.0.0' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index e631aff..0089a3a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -56,6 +56,18 @@ GEM minitest (~> 5.1) tzinfo (~> 1.1) zeitwerk (~> 2.1, >= 2.1.8) + aws-eventstream (1.0.3) + aws-partitions (1.220.0) + aws-sdk-core (3.68.1) + aws-eventstream (~> 1.0, >= 1.0.2) + aws-partitions (~> 1.0) + aws-sigv4 (~> 1.1) + jmespath (~> 1.0) + aws-sdk-ssm (1.57.0) + aws-sdk-core (~> 3, >= 3.61.1) + aws-sigv4 (~> 1.1) + aws-sigv4 (1.1.0) + aws-eventstream (~> 1.0, >= 1.0.2) bootsnap (1.4.5) msgpack (~> 1.0) builder (3.2.3) @@ -68,6 +80,7 @@ GEM activesupport (>= 4.2.0) i18n (1.6.0) concurrent-ruby (~> 1.0) + jmespath (1.4.0) listen (3.1.5) rb-fsevent (~> 0.9, >= 0.9.4) rb-inotify (~> 0.9, >= 0.9.7) @@ -88,6 +101,11 @@ GEM nio4r (2.5.2) nokogiri (1.10.4) mini_portile2 (~> 2.4.0) + psenv (0.5.16.pre.local) + aws-sdk-ssm (~> 1) + psenv-rails (0.5.16.pre.local) + psenv (= 0.5.16.pre.local) + railties (>= 3.2, <= 6.1) puma (3.12.1) rack (2.0.7) rack-test (1.1.0) @@ -123,10 +141,6 @@ GEM rb-inotify (0.10.0) ffi (~> 1.0) ruby_dep (1.5.0) - spring (2.1.0) - spring-watcher-listen (2.0.1) - listen (>= 2.7, < 4.0) - spring (>= 1.2, < 3.0) sprockets (3.7.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -150,10 +164,9 @@ DEPENDENCIES bootsnap (>= 1.4.2) byebug listen (>= 3.0.5, < 3.2) + psenv-rails puma (~> 3.11) rails (~> 6.0.0) - spring - spring-watcher-listen (~> 2.0.0) tzinfo-data RUBY VERSION diff --git a/README.md b/README.md index 7db80e4..20a452e 100644 --- a/README.md +++ b/README.md @@ -1,24 +1,27 @@ -# README +# psenv-test -This README would normally document whatever steps are necessary to get the -application up and running. +Used for testing the psenv-rails gem to validate. -Things you may want to cover: +## Usage -* Ruby version +* 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` -* System dependencies +## New Versions -* Configuration +To test new versions of the gem, you can install the psenv-rails gem locally and +reference it: -* Database creation - -* Database initialization - -* How to run the test suite - -* Services (job queues, cache servers, search engines, etc.) - -* Deployment instructions - -* ... +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/app/services/environment_tester.rb b/app/services/environment_tester.rb new file mode 100644 index 0000000..e78250d --- /dev/null +++ b/app/services/environment_tester.rb @@ -0,0 +1,5 @@ +class EnvironmentTester + def self.call + ENV.fetch('API_KEY', '') + end +end diff --git a/config/environments/development.rb b/config/environments/development.rb index d160dc4..96892b3 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -20,7 +20,7 @@ Rails.application.configure do 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else - config.action_controller.perform_caching = false + # config.action_controller.perform_caching = false config.cache_store = :null_store end diff --git a/config/environments/test.rb b/config/environments/test.rb index c3cae38..c752dfc 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -5,7 +5,7 @@ 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 diff --git a/test/controllers/.keep b/test/controllers/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/.keep b/test/fixtures/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/fixtures/files/.keep b/test/fixtures/files/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/integration/.keep b/test/integration/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/models/.keep b/test/models/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/test/services/environment_tester_test.rb b/test/services/environment_tester_test.rb new file mode 100644 index 0000000..5a0533a --- /dev/null +++ b/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/test/test_helper.rb b/test/test_helper.rb index 5b4817f..75f0fe1 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ 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