From d4b867e930d6afe3eb680ab28a945918939d9ffe Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Fri, 26 Oct 2018 11:13:19 -0500 Subject: [PATCH] Working .travis.yml --- .env.test | 32 ++++++++++++++++ .travis.yml | 4 +- Gemfile | 4 +- Gemfile.lock | 4 +- config/database.yml | 2 +- config/environment.rb | 17 ++++++--- config/environments/ci.rb | 60 ++++++++++++++++++++++++++++-- config/environments/development.rb | 1 + config/environments/test.rb | 9 ++++- config/initializers/log_rage.rb | 4 ++ docker/build/Dockerfile | 2 +- package.json | 2 +- script/test.sh | 2 +- spec/spec_helper.rb | 13 +++++++ 14 files changed, 136 insertions(+), 20 deletions(-) create mode 100644 .env.test diff --git a/.env.test b/.env.test new file mode 100644 index 00000000..99aee497 --- /dev/null +++ b/.env.test @@ -0,0 +1,32 @@ +export DEVISE_SECRET_KEY='0696452e54b14758b8534437d8cf418ea920ff23bb9c3a061a9ab2827bab4685710e89b899ebd4457df600cb5f2e04adb6a0fdef09a6a45558ecae1d6906f4a6' #bundle exec rake secret +export SECRET_TOKEN='0696452e54b14758b8534437d8cf418ea920ff23bb9c3a061a9ab2827bab4685710e89b899ebd4457df600cb5f2e04adb6a0fdef09a6a45558ecae1d6906f4a6' #bundle exec rake secret + +export STRIPE_API_KEY='REPLACE' # use your test private key from your stripe account +export STRIPE_API_PUBLIC='REPLACE' # use your test public key from your stripe account +export S3_BUCKET_NAME='REPLACE' +export AWS_ACCESS_KEY='REPLACE' +export AWS_SECRET_ACCESS_KEY='REPLACE' + +### optional below +export ORG_NAME="default_organization" + +export GOOGLE_API_KEY='REPLACE' +export TWITTER_API_SECRET='REPLACE' +export FACEBOOK_API_SECRET='REPLACE' + +export MAILCHIMP_API_KEY='REPLACE' +export FULL_CONTACT_KEY='REPLACE' + +export LOG_TO_FILES=true + +export MAILCHIMP_OAUTH_CLIENT_ID='REPLACE' +export MAILCHIMP_OAUTH_CLIENT_SECRET='REPLACE' +export MAILCHIMP_REDIRECT_URL='REPLACE' +export FACEBOOK_APP_ID="REPLACE" + + +export CYPHER_KEY="REPLACE" # used for mailchimp integration + + + +export CIVIC_CRM_RABBITMQ_PASSWORD="" diff --git a/.travis.yml b/.travis.yml index 344563e5..0545e24a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,7 @@ services: before_install: - docker-compose -f docker/build/docker-compose.yml build -- cp .env.template .env +- cp .env.test .env script: -- docker-compose -f docker/build/docker-compose.yml run -e RACK_ENV=ci -e RAILS_ENV=ci -e BUILD_DATABASE_URL=postgres://admin:password@db/commitchange_test build script/test.sh +- docker-compose -f docker/build/docker-compose.yml run -e RACK_ENV=ci -e RAILS_ENV=ci -e BUILD_DATABASE_URL=postgres://admin:password@db/commitchange_development build script/test.sh diff --git a/Gemfile b/Gemfile index 30734333..2986fcbd 100755 --- a/Gemfile +++ b/Gemfile @@ -109,13 +109,13 @@ gem 'i18n-js' gem 'countries' -group :development do +group :development, :ci do gem 'traceroute' gem 'debase' gem 'ruby-debug-ide' end -group :development, :test do +group :development, :ci, :test do gem 'timecop' gem 'pry' #gem 'pry-byebug' diff --git a/Gemfile.lock b/Gemfile.lock index 5e10d876..cde0958f 100755 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -526,7 +526,7 @@ DEPENDENCIES webmock RUBY VERSION - ruby 2.3.6p384 + ruby 2.3.7p456 BUNDLED WITH - 1.16.1 + 1.16.4 diff --git a/config/database.yml b/config/database.yml index 95030c22..50c799fe 100755 --- a/config/database.yml +++ b/config/database.yml @@ -33,7 +33,7 @@ test: ci: adapter: postgresql encoding: unicode - database: commitchange_test + database: commitchange_development pool: 5 username: admin password: password diff --git a/config/environment.rb b/config/environment.rb index 74e95206..b55ad3d5 100755 --- a/config/environment.rb +++ b/config/environment.rb @@ -5,16 +5,23 @@ require File.expand_path('../application', __FILE__) Encoding.default_external = Encoding::UTF_8 Encoding.default_internal = Encoding::UTF_8 @ignore_dotenv = ENV['IGNORE_DOTENV'] +@env = Rails.env || 'development' unless (@ignore_dotenv) require 'dotenv' - Dotenv.load ".env" + if @env == 'test' + if File.file?(".env.#{@env}") + Dotenv.load ".env.#{@env}" + end + else + Dotenv.load ".env" + end end -@env = Rails.env || 'development' + @org_name = ENV['ORG_NAME'] || 'default_organization' puts "config files .env .env.#{@env} ./config/settings.#{@env}.yml#{ @env != 'test' ? " ./config/#{@org_name}.yml": " "} #{ @env != 'test' ? " ./config/#{@org_name}.#{@env}.yml": " "} #{ @env == 'test' ? "./config/settings.test.yml" : ""}" -unless @ignore_dotenv - Dotenv.load ".env.#{@env}" if File.file?(".env.#{@env}") -end +# unless @ignore_dotenv +# Dotenv.load ".env.#{@env}" if File.file?(".env.#{@env}") +# end if Rails.env == 'test' Settings.add_source!("./config/settings.test.yml") else diff --git a/config/environments/ci.rb b/config/environments/ci.rb index 885a87ff..33e72132 100755 --- a/config/environments/ci.rb +++ b/config/environments/ci.rb @@ -1,8 +1,60 @@ # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later -require File.expand_path('config/environments/test') - Commitchange::Application.configure do + # Settings specified here will take precedence over those in config/application.rb - config.log_level = :info + # 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 + config.cache_store = Settings.default.cache_store.to_sym -end + # Log error messages when you accidentally call methods on nil. + config.whiny_nils = true + + # Show full error reports and disable caching + config.consider_all_requests_local = true + config.action_controller.perform_caching = false + + # You can uncomment the following to test our real AWS email server on localhost: + # config.action_mailer.delivery_method = :aws_ses + # config.action_mailer.default_url_options = { host: 'commitchange.com' } + config.action_mailer.delivery_method = Settings.mailer.delivery_method.to_sym + config.action_mailer.smtp_settings = { address: Settings.mailer.address, port: Settings.mailer.port } + config.action_mailer.smtp_settings['user_name']= Settings.mailer.username if Settings.mailer.username + config.action_mailer.smtp_settings['password']= Settings.mailer.password if Settings.mailer.password + + config.action_mailer.default_url_options = { host: Settings.mailer.host } + + # Print deprecation notices to the Rails logger + config.active_support.deprecation = :log + + # Only use best-standards-support built into browsers + config.action_dispatch.best_standards_support = :builtin + + # Raise exception on mass assignment protection for Active Record models + config.active_record.mass_assignment_sanitizer = :strict + + # Log the query plan for queries taking more than this (works) + # with SQLite, MySQL, and PostgreSQL) + config.active_record.auto_explain_threshold_in_seconds = 0.5 + + # Do not compress assets + config.assets.compress = false + + # Expands the lines which load the assets + config.assets.debug = true + + config.log_level = :debug + + config.threadsafe! + config.dependency_loading = true if $rails_rake_task + # Turn this on if you want to mess with code inside /node_modules + # config.browserify_rails.evaluate_node_modules = true + + config.middleware.use I18n::JS::Middleware + + config.after_initialize do + ActiveRecord::Base.logger = nil + end + +end \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index c7293c02..6f3da2c3 100755 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -58,4 +58,5 @@ Commitchange::Application.configure do # config.browserify_rails.evaluate_node_modules = true config.middleware.use I18n::JS::Middleware + end diff --git a/config/environments/test.rb b/config/environments/test.rb index da39a8c5..64bf4084 100755 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -38,11 +38,18 @@ Commitchange::Application.configure do # Expands the lines which load the assets config.assets.debug = true - config.log_level = :debug + config.log_level = :none config.action_controller.allow_forgery_protection = false config.cache_store = :memory_store config.threadsafe! + config.after_initialize do + ActiveRecord::Base.logger = nil + ActionController::Base.logger = nil + ActionMailer::Base.logger = nil + end + + end diff --git a/config/initializers/log_rage.rb b/config/initializers/log_rage.rb index a87ed68f..5e8470d6 100644 --- a/config/initializers/log_rage.rb +++ b/config/initializers/log_rage.rb @@ -1,5 +1,8 @@ # License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later Commitchange::Application.configure do + if (Rails.env != 'test') + + config.lograge.enabled = true # add time to lograge config.lograge.custom_options = lambda do |event| @@ -8,4 +11,5 @@ Commitchange::Application.configure do exception_object: event.payload[:exception_object] # the exception instance } end + end end \ No newline at end of file diff --git a/docker/build/Dockerfile b/docker/build/Dockerfile index 9b99c574..c1d27269 100644 --- a/docker/build/Dockerfile +++ b/docker/build/Dockerfile @@ -13,5 +13,5 @@ WORKDIR /myapp COPY Gemfile /myapp/Gemfile COPY Gemfile.lock /myapp/Gemfile.lock RUN bundle install -CMD rake db:create db:structure:load test:prepare && rake spec && npx jest && npm run build-all +CMD rake -T diff --git a/package.json b/package.json index b48b85fa..d4edfbf8 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "watch": "export HOUDINI_WATCH=1; script/build.sh", "build": "script/build.sh", "build-all": "npm ci && script/compile-assets.sh && npm run build", - "test": "rake spec && npm run build && npx jest", + "test": "rake -v spec && npm run build && npx jest", "export-button-config": "bundle exec rake settings:generate_json", "export-i18n": "bundle exec rake settings:combine_translations", "generate-openapi": "rake oapi:gen", diff --git a/script/test.sh b/script/test.sh index 3b28eb5e..c6c33d5d 100755 --- a/script/test.sh +++ b/script/test.sh @@ -1,2 +1,2 @@ #!/bin/bash -npm install && rake db:create db:structure:load test:prepare && rake spec && npx jest && npm run build-all \ No newline at end of file +npm ci && rake db:create db:structure:load db:migrate && RAILS_ENV=test rake db:create db:structure:load test:prepare && rake spec \ No newline at end of file diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 41eae771..70f7fb75 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -117,3 +117,16 @@ RSpec.configure do |config| end end end + +if defined?(RUBY_ENGINE) && RUBY_ENGINE == "ruby" && RUBY_VERSION >= "1.9" + module Kernel + alias :__at_exit :at_exit + def at_exit(&block) + __at_exit do + exit_status = $!.status if $!.is_a?(SystemExit) + block.call + exit exit_status if exit_status + end + end + end +end