Skip to content

Commit 38e7c90

Browse files
authored
Update dummy app to current Rails conventions (#110)
* Update test app * Remove testing branch * Update changelog
1 parent 16d178d commit 38e7c90

File tree

30 files changed

+204
-164
lines changed

30 files changed

+204
-164
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
### Next Release
22

33
* Your contribution here.
4+
* [#110](https://github.com/ruby-grape/grape-swagger-rails/pull/110): Update dummy app to current rails conventions - [@duffn](https://github.com/duffn).
45

56
### 0.4.0 (2023/03/28)
67

Gemfile

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@ end
1212

1313
group :development, :test do
1414
gem 'capybara'
15-
gem 'coffee-rails'
1615
gem 'grape-swagger-ui'
1716
gem 'jquery-rails'
1817
gem 'mime-types'
1918
gem 'nokogiri'
2019
gem 'rack', '< 3.0'
2120
gem 'rack-cors'
22-
gem 'rack-no_animations'
2321
gem 'rake'
2422
gem 'rspec-rails'
25-
gem 'rubocop', '0.77.0'
23+
gem 'rubocop'
2624
gem 'ruby-grape-danger', '~> 0.2.0', require: false
27-
gem 'sass'
28-
gem 'sass-rails'
2925
gem 'selenium-webdriver'
30-
gem 'sprockets'
26+
gem 'sprockets-rails', require: 'sprockets/railtie'
3127
gem 'uglifier'
3228
gem 'webrick'
3329
end

Rakefile

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
#!/usr/bin/env rake
2-
begin
3-
require 'bundler/setup'
4-
rescue LoadError
5-
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6-
end
7-
8-
APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
1+
require 'bundler/setup'
92

3+
APP_RAKEFILE = File.expand_path('spec/dummy/Rakefile', __dir__)
104
load 'rails/tasks/engine.rake'
11-
Bundler::GemHelper.install_tasks
125

136
Dir[File.join(File.dirname(__FILE__), 'lib/tasks/**/*.rake')].each do |f|
147
load f
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
//= link_directory ../stylesheets/grape_swagger_rails .css
2+
//= link_directory ../javascripts/grape_swagger_rails .js

spec/dummy/Rakefile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#!/usr/bin/env rake
1+
# Add your own tasks in files placed in lib/tasks ending in .rake,
2+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
23

3-
require File.expand_path('../config/application', __FILE__)
4+
require_relative 'config/application'
45

5-
Dummy::Application.load_tasks
6+
Rails.application.load_tasks
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//= link application.js
2-
//= link application.css
3-
//= link grape_swagger_rails/application.css
4-
//= link grape_swagger_rails/application.js
1+
//= link_directory ../stylesheets .css
2+
//= link_directory ../javascripts .js
3+
//= link grape_swagger_rails_manifest.js
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
//= require jquery
2-
//= require jquery_ujs
31
//= require_tree .

spec/dummy/app/views/layouts/application.html.erb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<%= stylesheet_link_tag 'application', media: 'all' %>
66
<%= javascript_include_tag 'application' %>
77
<%= csrf_meta_tags %>
8+
<%= csp_meta_tag %>
89
</head>
910
<body>
1011

spec/dummy/bin/bundle

Lines changed: 0 additions & 3 deletions
This file was deleted.

spec/dummy/bin/rails

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#!/usr/bin/env ruby
2-
begin
3-
load File.expand_path('../spring', __FILE__)
4-
rescue LoadError
5-
end
6-
APP_PATH = File.expand_path('../../config/application', __FILE__)
2+
APP_PATH = File.expand_path('../config/application', __dir__)
73
require_relative '../config/boot'
84
require 'rails/commands'

spec/dummy/bin/rake

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
11
#!/usr/bin/env ruby
2-
begin
3-
load File.expand_path('../spring', __FILE__)
4-
rescue LoadError
5-
end
62
require_relative '../config/boot'
73
require 'rake'
84
Rake.application.run

spec/dummy/bin/setup

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/usr/bin/env ruby
2+
require 'fileutils'
3+
4+
# path to your application root.
5+
APP_ROOT = File.expand_path('..', __dir__)
6+
7+
def system!(*args)
8+
system(*args) || abort("\n== Command #{args} failed ==")
9+
end
10+
11+
FileUtils.chdir APP_ROOT do
12+
# This script is a way to set up or update your development environment automatically.
13+
# This script is idempotent, so that you can run it at any time and get an expectable outcome.
14+
# Add necessary setup steps to this file.
15+
16+
puts '== Installing dependencies =='
17+
system! 'gem install bundler --conservative'
18+
system('bundle check') || system!('bundle install')
19+
20+
puts "\n== Removing old logs and tempfiles =="
21+
system! 'bin/rails log:clear tmp:clear'
22+
23+
puts "\n== Restarting application server =="
24+
system! 'bin/rails restart'
25+
end

spec/dummy/bin/spring

Lines changed: 0 additions & 18 deletions
This file was deleted.

spec/dummy/config.ru

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
# This file is used by Rack-based servers to start the application.
22

3-
require ::File.expand_path('../config/environment', __FILE__)
4-
run Dummy::Application
3+
require_relative 'config/environment'
4+
5+
run Rails.application
6+
Rails.application.load_server

spec/dummy/config/application.rb

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
1-
require File.expand_path('../boot', __FILE__)
1+
require_relative 'boot'
22

3-
require 'action_controller/railtie'
4-
require 'action_view/railtie'
5-
require 'sprockets/railtie'
6-
require 'jquery-rails'
7-
require 'rack/cors'
8-
require 'rack/no_animations'
3+
require 'rails/all'
94

5+
# Require the gems listed in Gemfile, including any gems
6+
# you've limited to :test, :development, or :production.
107
Bundler.require(*Rails.groups)
118
require 'grape-swagger-rails'
129

1310
module Dummy
1411
class Application < Rails::Application
15-
config.paths.add File.join('app', 'api'), glob: File.join('**', '*.rb')
16-
config.autoload_paths += Dir[Rails.root.join('app', 'api', '*')]
12+
config.load_defaults Rails::VERSION::STRING.to_f
13+
14+
# For compatibility with applications that use this config
15+
config.action_controller.include_all_helpers = false
1716
config.middleware.use Rack::Cors do
1817
allow do
1918
origins '*'

spec/dummy/config/boot.rb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
1-
require 'rubygems'
2-
3-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
1+
# Set up gems listed in the Gemfile.
2+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../Gemfile', __dir__)
43

54
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
6-
7-
require 'sass'
8-
require 'grape'
9-
require 'grape-swagger'
10-
require 'coffee_script'
5+
$LOAD_PATH.unshift File.expand_path('../../../lib', __dir__)

spec/dummy/config/environment.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
require File.expand_path('../application', __FILE__)
1+
# Load the Rails application.
2+
require_relative 'application'
23

3-
Dummy::Application.initialize!
4+
# Initialize the Rails application.
5+
Rails.application.initialize!
Lines changed: 38 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,56 @@
1+
require 'active_support/core_ext/integer/time'
2+
13
Rails.application.configure do
24
# Settings specified here will take precedence over those in config/application.rb.
35

4-
# In the development environment your application's code is reloaded on
5-
# every request. This slows down response time but is perfect for development
6+
# In the development environment your application's code is reloaded any time
7+
# it changes. This slows down response time but is perfect for development
68
# since you don't have to restart the web server when you make code changes.
79
config.cache_classes = false
810

911
# Do not eager load code on boot.
1012
config.eager_load = false
1113

12-
# Show full error reports and disable caching.
13-
config.consider_all_requests_local = true
14-
config.action_controller.perform_caching = false
14+
# Show full error reports.
15+
config.consider_all_requests_local = true
16+
17+
# Enable server timing
18+
config.server_timing = true
19+
20+
# Enable/disable caching. By default caching is disabled.
21+
# Run rails dev:cache to toggle caching.
22+
if Rails.root.join('tmp/caching-dev.txt').exist?
23+
config.action_controller.perform_caching = true
24+
config.action_controller.enable_fragment_cache_logging = true
1525

16-
# Don't care if the mailer can't send.
17-
# config.action_mailer.raise_delivery_errors = false
26+
config.cache_store = :memory_store
27+
config.public_file_server.headers = {
28+
'Cache-Control' => "public, max-age=#{2.days.to_i}"
29+
}
30+
else
31+
config.action_controller.perform_caching = false
32+
33+
config.cache_store = :null_store
34+
end
1835

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

22-
# Debug mode disables concatenation and preprocessing of assets.
23-
# This option may cause significant delays in view rendering with a large
24-
# number of complex assets.
25-
config.assets.debug = true
39+
# Raise exceptions for disallowed deprecations.
40+
config.active_support.disallowed_deprecation = :raise
41+
42+
# Tell Active Support which deprecation messages to disallow.
43+
config.active_support.disallowed_deprecation_warnings = []
44+
45+
# Suppress logger output for asset requests.
46+
config.assets.quiet = true
2647

27-
# Adds additional error checking when serving assets at runtime.
28-
# Checks for improperly declared sprockets dependencies.
29-
# Raises helpful error messages.
30-
config.assets.raise_runtime_errors = true
48+
# Raises error for missing translations.
49+
# config.i18n.raise_on_missing_translations = true
3150

32-
# Raises error for missing translations
33-
# config.action_view.raise_on_missing_translations = true
51+
# Annotate rendered view with file names.
52+
# config.action_view.annotate_rendered_view_with_filenames = true
3453

35-
# Disable animations
36-
config.middleware.use Rack::NoAnimations
54+
# Uncomment if you wish to allow Action Cable access from any origin.
55+
# config.action_cable.disable_request_forgery_protection = true
3756
end
Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'active_support/core_ext/integer/time'
2+
13
Rails.application.configure do
24
# Settings specified here will take precedence over those in config/application.rb.
35

@@ -14,16 +16,17 @@
1416
config.consider_all_requests_local = false
1517
config.action_controller.perform_caching = true
1618

17-
# Enable Rack::Cache to put a simple HTTP cache in front of your application
18-
# Add `rack-cache` to your Gemfile before enabling this.
19-
# For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20-
# config.action_dispatch.rack_cache = true
19+
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
20+
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
21+
# config.require_master_key = true
2122

22-
# Disable Rails's static asset server (Apache or nginx will already do this).
23-
config.serve_static_files = false
23+
# Disable serving static files from the `/public` folder by default since
24+
# Apache or NGINX already handles this.
25+
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present?
2426

2527
# Compress JavaScripts and CSS.
2628
config.assets.js_compressor = :uglifier
29+
# Compress CSS using a preprocessor.
2730
# config.assets.css_compressor = :sass
2831

2932
# Do not fallback to assets pipeline if a precompiled asset is missed.
@@ -32,48 +35,43 @@
3235
# Generate digests for assets URLs.
3336
config.assets.digest = true
3437

35-
# `config.assets.precompile` has moved to config/initializers/assets.rb
38+
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
39+
# config.asset_host = "http://assets.example.com"
3640

3741
# Specifies the header that your server uses for sending files.
38-
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
39-
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
42+
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for Apache
43+
# config.action_dispatch.x_sendfile_header = "X-Accel-Redirect" # for NGINX
4044

4145
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
4246
# config.force_ssl = true
4347

44-
# Set to :debug to see everything in the log.
48+
# Include generic and useful information about system operation, but avoid logging too much
49+
# information to avoid inadvertent exposure of personally identifiable information (PII).
4550
config.log_level = :info
4651

4752
# Prepend all log lines with the following tags.
48-
# config.log_tags = [ :subdomain, :uuid ]
49-
50-
# Use a different logger for distributed setups.
51-
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
53+
config.log_tags = [:request_id]
5254

5355
# Use a different cache store in production.
5456
# config.cache_store = :mem_cache_store
5557

56-
# Enable serving of images, stylesheets, and JavaScripts from an asset server.
57-
# config.action_controller.asset_host = "http://assets.example.com"
58-
59-
# Precompile additional assets.
60-
# application.js, application.css, and all non-JS/CSS in app/assets folder are already added.
61-
# config.assets.precompile += %w( search.js )
62-
63-
# Ignore bad email addresses and do not raise email delivery errors.
64-
# Set this to true and configure the email server for immediate delivery to raise delivery errors.
65-
# config.action_mailer.raise_delivery_errors = false
66-
6758
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to
6859
# the I18n.default_locale when a translation cannot be found).
6960
config.i18n.fallbacks = true
7061

71-
# Send deprecation notices to registered listeners.
72-
config.active_support.deprecation = :notify
73-
74-
# Disable automatic flushing of the log to improve performance.
75-
# config.autoflush_log = false
62+
# Don't log any deprecations.
63+
config.active_support.report_deprecations = false
7664

7765
# Use default logging formatter so that PID and timestamp are not suppressed.
7866
config.log_formatter = ::Logger::Formatter.new
67+
68+
# Use a different logger for distributed setups.
69+
# require "syslog/logger"
70+
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new "app-name")
71+
72+
if ENV['RAILS_LOG_TO_STDOUT'].present?
73+
logger = ActiveSupport::Logger.new(STDOUT)
74+
logger.formatter = config.log_formatter
75+
config.logger = ActiveSupport::TaggedLogging.new(logger)
76+
end
7977
end

0 commit comments

Comments
 (0)