Skip to content

Commit

Permalink
Update test for use full rails environment
Browse files Browse the repository at this point in the history
  • Loading branch information
huacnlee committed Sep 14, 2021
1 parent 0849bb2 commit c220633
Show file tree
Hide file tree
Showing 40 changed files with 501 additions and 65 deletions.
13 changes: 1 addition & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,14 @@ GEM
zeitwerk (~> 2.3)
ast (2.4.0)
builder (3.2.4)
codecov (0.2.11)
json
simplecov
concurrent-ruby (1.1.9)
crass (1.0.6)
docile (1.3.2)
erubi (1.10.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
i18n (1.8.10)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.2)
json (2.3.1)
loofah (2.10.0)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
Expand Down Expand Up @@ -143,10 +138,6 @@ GEM
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.6)
ruby-progressbar (1.10.0)
simplecov (0.19.0)
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.3)
sprockets (4.0.2)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
Expand All @@ -169,14 +160,12 @@ PLATFORMS
x86_64-darwin-20

DEPENDENCIES
codecov
minitest
pg
rails (~> 6.1.0)
rails-settings-cached!
rubocop
simplecov
sqlite3

BUNDLED WITH
2.2.4
2.2.23
15 changes: 15 additions & 0 deletions bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

# This command will automatically be run when you run "rails" with Rails gems
# installed from the root of your application.

ENGINE_ROOT = File.expand_path("..", __dir__)
ENGINE_PATH = File.expand_path("../lib/rails-settings/railtie", __dir__)

# Set up gems listed in the Gemfile.
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])

require "rails/all"
require "rails/engine/commands"
4 changes: 1 addition & 3 deletions rails-settings-cached.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@ Gem::Specification.new do |s|

s.add_dependency "rails", ">= 5.0.0"

s.add_development_dependency "codecov"
s.add_development_dependency "minitest"
s.add_development_dependency "pg"
s.add_development_dependency "minitest"
s.add_development_dependency "rubocop"
s.add_development_dependency "simplecov"
s.add_development_dependency "sqlite3"
end
6 changes: 6 additions & 0 deletions test/dummy/Rakefile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions test/dummy/app/assets/config/manifest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
//= link_tree ../images
//= link_directory ../stylesheets .css
//= link action_draft_manifest.js
Empty file.
15 changes: 15 additions & 0 deletions test/dummy/app/assets/stylesheets/application.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* This is a manifest file that'll be compiled into application.css, which will include all the files
* listed below.
*
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
* or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
*
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS
* files in this directory. Styles in this file should be added after the last require_* statement.
* It is generally better to create a new file per style scope.
*
*= require_tree .
*= require_self
*/
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions test/dummy/bin/bundle
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
4 changes: 4 additions & 0 deletions test/dummy/bin/rails
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
APP_PATH = File.expand_path('../config/application', __dir__)
require_relative '../config/boot'
require 'rails/commands'
4 changes: 4 additions & 0 deletions test/dummy/bin/rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env ruby
require_relative '../config/boot'
require 'rake'
Rake.application.run
34 changes: 34 additions & 0 deletions test/dummy/bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
# This script is a starting point to setup your application.
# Add necessary setup steps to this file.

puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
# cp 'config/database.yml.sample', 'config/database.yml'
# end

puts "\n== Preparing database =="
system! 'bin/rails db:setup'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
29 changes: 29 additions & 0 deletions test/dummy/bin/update
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env ruby
require 'pathname'
require 'fileutils'
include FileUtils

# path to your application root.
APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)

def system!(*args)
system(*args) || abort("\n== Command #{args} failed ==")
end

chdir APP_ROOT do
# This script is a way to update your development environment automatically.
# Add necessary update steps to this file.

puts '== Installing dependencies =='
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')

puts "\n== Updating database =="
system! 'bin/rails db:migrate'

puts "\n== Removing old logs and tempfiles =="
system! 'bin/rails log:clear tmp:clear'

puts "\n== Restarting application server =="
system! 'bin/rails restart'
end
5 changes: 5 additions & 0 deletions test/dummy/config.ru
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# This file is used by Rack-based servers to start the application.

require_relative 'config/environment'

run Rails.application
15 changes: 15 additions & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require_relative "boot"

require "rails/all"

Bundler.require(*Rails.groups)
require "rails-settings-cached"

module Dummy
class Application < Rails::Application
# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
# -- all .rb files in that directory are automatically loaded.
config.cache_store = :memory_store
end
end
5 changes: 5 additions & 0 deletions test/dummy/config/boot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Set up gems listed in the Gemfile.
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)

require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)
17 changes: 17 additions & 0 deletions test/dummy/config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
default: &default
adapter: sqlite3
timeout: 5000
encoding: utf-8
database: ":memory:"

development:
<<: *default

# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default

production:
<<: *default
20 changes: 20 additions & 0 deletions test/dummy/config/environment.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Load the Rails application.
require_relative "application"

# Initialize the Rails application.
Rails.application.initialize!

# Config for use in memory database
# ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Base.establish_connection adapter: "sqlite3", database: ":memory:"
# ActiveRecord::Base.configurations = true

ActiveRecord::Schema.verbose = false
ActiveRecord::Schema.define(version: 1) do
create_table :settings do |t|
t.string :var, null: false
t.text :value
t.datetime :created_at
t.datetime :updated_at
end
end
47 changes: 47 additions & 0 deletions test/dummy/config/environments/development.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
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.
config.action_controller.perform_caching = true

config.public_file_server.headers = {
"Cache-Control" => "public, max-age=172800"
}

# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false

config.action_mailer.perform_caching = false

# Print deprecation notices to the Rails logger.
config.active_support.deprecation = :log

# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load

# Debug mode disables concatenation and preprocessing of assets.
# This option may cause significant delays in view rendering with a large
# number of complex assets.
config.assets.debug = true

# Suppress logger output for asset requests.
config.assets.quiet = true

# 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
86 changes: 86 additions & 0 deletions test/dummy/config/environments/production.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
Rails.application.configure do
# Settings specified here will take precedence over those in config/application.rb.

# Code is not reloaded between requests.
config.cache_classes = true

# Eager load code on boot. This eager loads most of Rails and
# your application in memory, allowing both threaded web servers
# and those relying on copy on write to perform better.
# Rake tasks automatically ignore this option for performance.
config.eager_load = true

# Full error reports are disabled and caching is turned on.
config.consider_all_requests_local = false
config.action_controller.perform_caching = true

# 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?

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
config.assets.compile = false

# `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb

# 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

# Mount Action Cable outside main process or domain
# config.action_cable.mount_path = nil
# config.action_cable.url = 'wss://example.com/cable'
# config.action_cable.allowed_request_origins = [ 'http://example.com', /http:\/\/example.*/ ]

# 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 = "dummy_#{Rails.env}"
config.action_mailer.perform_caching = false

# Ignore bad email addresses and do not raise email delivery errors.
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
# config.action_mailer.raise_delivery_errors = false

# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
# the I18n.default_locale when a translation cannot be found).
config.i18n.fallbacks = true

# Send deprecation notices to registered listeners.
config.active_support.deprecation = :notify

# Use default logging formatter so that PID and timestamp are not suppressed.
config.log_formatter = ::Logger::Formatter.new

# 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

# Do not dump schema after migrations.
config.active_record.dump_schema_after_migration = false
end
Loading

0 comments on commit c220633

Please sign in to comment.