Skip to content

Instantly share code, notes, and snippets.

@satococoa
Last active December 14, 2017 02:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save satococoa/53d0f5494fc5497c7f78144aa914e2c2 to your computer and use it in GitHub Desktop.
Save satococoa/53d0f5494fc5497c7f78144aa914e2c2 to your computer and use it in GitHub Desktop.
Rails API mode の差分
diff -urN apimode/.gitignore normal/.gitignore
--- apimode/.gitignore 2017-12-13 18:38:46.000000000 +0900
+++ normal/.gitignore 2017-12-13 18:38:57.000000000 +0900
@@ -17,4 +17,7 @@
!/log/.keep
!/tmp/.keep
+/node_modules
+/yarn-error.log
+
.byebug_history
diff -urN apimode/Gemfile normal/Gemfile
--- apimode/Gemfile 2017-12-13 18:38:46.000000000 +0900
+++ normal/Gemfile 2017-12-13 18:38:57.000000000 +0900
@@ -12,8 +12,19 @@
gem 'sqlite3'
# Use Puma as the app server
gem 'puma', '~> 3.7'
+# Use SCSS for stylesheets
+gem 'sass-rails', '~> 5.0'
+# Use Uglifier as compressor for JavaScript assets
+gem 'uglifier', '>= 1.3.0'
+# See https://github.com/rails/execjs#readme for more supported runtimes
+# gem 'therubyracer', platforms: :ruby
+
+# Use CoffeeScript for .coffee assets and views
+gem 'coffee-rails', '~> 4.2'
+# Turbolinks makes navigating your web application faster. Read more: https://github.com/turbolinks/turbolinks
+gem 'turbolinks', '~> 5'
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
-# gem 'jbuilder', '~> 2.5'
+gem 'jbuilder', '~> 2.5'
# Use Redis adapter to run Action Cable in production
# gem 'redis', '~> 3.0'
# Use ActiveModel has_secure_password
@@ -22,15 +33,17 @@
# Use Capistrano for deployment
# gem 'capistrano-rails', group: :development
-# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
-# gem 'rack-cors'
-
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]
+ # Adds support for Capybara system testing and selenium driver
+ gem 'capybara', '~> 2.13'
+ gem 'selenium-webdriver'
end
group :development do
+ # Access an IRB console on exception pages or by using <%= console %> anywhere in the code.
+ gem 'web-console', '>= 3.3.0'
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'
diff -urN apimode/app/assets/config/manifest.js normal/app/assets/config/manifest.js
--- apimode/app/assets/config/manifest.js 1970-01-01 09:00:00.000000000 +0900
+++ normal/app/assets/config/manifest.js 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,3 @@
+//= link_tree ../images
+//= link_directory ../javascripts .js
+//= link_directory ../stylesheets .css
diff -urN apimode/app/assets/javascripts/application.js normal/app/assets/javascripts/application.js
--- apimode/app/assets/javascripts/application.js 1970-01-01 09:00:00.000000000 +0900
+++ normal/app/assets/javascripts/application.js 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,15 @@
+// This is a manifest file that'll be compiled into application.js, which will include all the files
+// listed below.
+//
+// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, or any plugin's
+// vendor/assets/javascripts directory can be referenced here using a relative path.
+//
+// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
+// compiled file. JavaScript code in this file should be added after the last require_* statement.
+//
+// Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
+// about supported directives.
+//
+//= require rails-ujs
+//= require turbolinks
+//= require_tree .
diff -urN apimode/app/assets/javascripts/cable.js normal/app/assets/javascripts/cable.js
--- apimode/app/assets/javascripts/cable.js 1970-01-01 09:00:00.000000000 +0900
+++ normal/app/assets/javascripts/cable.js 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,13 @@
+// Action Cable provides the framework to deal with WebSockets in Rails.
+// You can generate new channels where WebSocket features live using the `rails generate channel` command.
+//
+//= require action_cable
+//= require_self
+//= require_tree ./channels
+
+(function() {
+ this.App || (this.App = {});
+
+ App.cable = ActionCable.createConsumer();
+
+}).call(this);
diff -urN apimode/app/assets/stylesheets/application.css normal/app/assets/stylesheets/application.css
--- apimode/app/assets/stylesheets/application.css 1970-01-01 09:00:00.000000000 +0900
+++ normal/app/assets/stylesheets/application.css 2017-12-13 18:38:57.000000000 +0900
@@ -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, 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
+ */
diff -urN apimode/app/controllers/application_controller.rb normal/app/controllers/application_controller.rb
--- apimode/app/controllers/application_controller.rb 2017-12-13 18:38:46.000000000 +0900
+++ normal/app/controllers/application_controller.rb 2017-12-13 18:38:57.000000000 +0900
@@ -1,2 +1,3 @@
-class ApplicationController < ActionController::API
+class ApplicationController < ActionController::Base
+ protect_from_forgery with: :exception
end
diff -urN apimode/app/helpers/application_helper.rb normal/app/helpers/application_helper.rb
--- apimode/app/helpers/application_helper.rb 1970-01-01 09:00:00.000000000 +0900
+++ normal/app/helpers/application_helper.rb 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,2 @@
+module ApplicationHelper
+end
diff -urN apimode/app/views/layouts/application.html.erb normal/app/views/layouts/application.html.erb
--- apimode/app/views/layouts/application.html.erb 1970-01-01 09:00:00.000000000 +0900
+++ normal/app/views/layouts/application.html.erb 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+ <head>
+ <title>Normal</title>
+ <%= csrf_meta_tags %>
+
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload' %>
+ <%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
+ </head>
+
+ <body>
+ <%= yield %>
+ </body>
+</html>
diff -urN apimode/bin/setup normal/bin/setup
--- apimode/bin/setup 2017-12-13 18:38:46.000000000 +0900
+++ normal/bin/setup 2017-12-13 18:38:57.000000000 +0900
@@ -18,6 +18,9 @@
system! 'gem install bundler --conservative'
system('bundle check') || system!('bundle install')
+ # Install JavaScript dependencies if using Yarn
+ # system('bin/yarn')
+
# puts "\n== Copying sample files =="
# unless File.exist?('config/database.yml')
diff -urN apimode/bin/yarn normal/bin/yarn
--- apimode/bin/yarn 1970-01-01 09:00:00.000000000 +0900
+++ normal/bin/yarn 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,11 @@
+#!/usr/bin/env ruby
+VENDOR_PATH = File.expand_path('..', __dir__)
+Dir.chdir(VENDOR_PATH) do
+ begin
+ exec "yarnpkg #{ARGV.join(" ")}"
+ rescue Errno::ENOENT
+ $stderr.puts "Yarn executable was not detected in the system."
+ $stderr.puts "Download Yarn at https://yarnpkg.com/en/docs/install"
+ exit 1
+ end
+end
diff -urN apimode/config/application.rb normal/config/application.rb
--- apimode/config/application.rb 2017-12-13 18:38:46.000000000 +0900
+++ normal/config/application.rb 2017-12-13 18:38:57.000000000 +0900
@@ -1,22 +1,12 @@
require_relative 'boot'
-require "rails"
-# Pick the frameworks you want:
-require "active_model/railtie"
-require "active_job/railtie"
-require "active_record/railtie"
-require "action_controller/railtie"
-require "action_mailer/railtie"
-require "action_view/railtie"
-require "action_cable/engine"
-# require "sprockets/railtie"
-require "rails/test_unit/railtie"
+require 'rails/all'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)
-module Apimode
+module Normal
class Application < Rails::Application
# Initialize configuration defaults for originally generated Rails version.
config.load_defaults 5.1
@@ -24,10 +14,5 @@
# 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.
-
- # 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 -urN apimode/config/cable.yml normal/config/cable.yml
--- apimode/config/cable.yml 2017-12-13 18:38:46.000000000 +0900
+++ normal/config/cable.yml 2017-12-13 18:38:57.000000000 +0900
@@ -7,4 +7,4 @@
production:
adapter: redis
url: redis://localhost:6379/1
- channel_prefix: apimode_production
+ channel_prefix: normal_production
diff -urN apimode/config/environments/development.rb normal/config/environments/development.rb
--- apimode/config/environments/development.rb 2017-12-13 18:38:46.000000000 +0900
+++ normal/config/environments/development.rb 2017-12-13 18:38:57.000000000 +0900
@@ -37,6 +37,13 @@
# 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
diff -urN apimode/config/environments/production.rb normal/config/environments/production.rb
--- apimode/config/environments/production.rb 2017-12-13 18:38:46.000000000 +0900
+++ normal/config/environments/production.rb 2017-12-13 18:38:57.000000000 +0900
@@ -23,6 +23,14 @@
# 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'
@@ -51,7 +59,7 @@
# 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 = "apimode_#{Rails.env}"
+ # config.active_job.queue_name_prefix = "normal_#{Rails.env}"
config.action_mailer.perform_caching = false
# Ignore bad email addresses and do not raise email delivery errors.
diff -urN apimode/config/initializers/assets.rb normal/config/initializers/assets.rb
--- apimode/config/initializers/assets.rb 1970-01-01 09:00:00.000000000 +0900
+++ normal/config/initializers/assets.rb 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,14 @@
+# Be sure to restart your server when you modify this file.
+
+# Version of your assets, change this if you want to expire all your assets.
+Rails.application.config.assets.version = '1.0'
+
+# Add additional assets to the asset load path.
+# Rails.application.config.assets.paths << Emoji.images_path
+# Add Yarn node_modules folder to the asset load path.
+Rails.application.config.assets.paths << Rails.root.join('node_modules')
+
+# Precompile additional assets.
+# application.js, application.css, and all non-JS/CSS in the app/assets
+# folder are already added.
+# Rails.application.config.assets.precompile += %w( admin.js admin.css )
diff -urN apimode/config/initializers/cookies_serializer.rb normal/config/initializers/cookies_serializer.rb
--- apimode/config/initializers/cookies_serializer.rb 1970-01-01 09:00:00.000000000 +0900
+++ normal/config/initializers/cookies_serializer.rb 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,5 @@
+# Be sure to restart your server when you modify this file.
+
+# Specify a serializer for the signed and encrypted cookie jars.
+# Valid options are :json, :marshal, and :hybrid.
+Rails.application.config.action_dispatch.cookies_serializer = :json
diff -urN apimode/config/initializers/cors.rb normal/config/initializers/cors.rb
--- apimode/config/initializers/cors.rb 2017-12-13 18:38:46.000000000 +0900
+++ normal/config/initializers/cors.rb 1970-01-01 09:00:00.000000000 +0900
@@ -1,16 +0,0 @@
-# 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 -urN apimode/config/secrets.yml normal/config/secrets.yml
--- apimode/config/secrets.yml 2017-12-13 18:38:46.000000000 +0900
+++ normal/config/secrets.yml 2017-12-13 18:38:57.000000000 +0900
@@ -18,10 +18,10 @@
# Environmental secrets are only available for that specific environment.
development:
- secret_key_base: 2386cc3b2a8ce1956de7c1238cc94d3548ad19f1ca6e09b70552bdb3958dc35e479b84931e552ef0d404561fdfd918b9bcc790f9f17729c053f03f1394b8e103
+ secret_key_base: c8be8dbd7a3ddefaa04cd9b2dfb24ca55747bae879285d8e33e07a1e058593d3c8507ecc61820d5a36abba4801fbb3905bee537728b914e940f1b9a9a1ec9528
test:
- secret_key_base: 62f18b1724fa4e8fb5e7ae99f86fb8f1bdf665a8d662680ffb0ca213a09464ec6b525b3617257c88cb5ca2395002a89eac5f525d060f66409c9f817f942923b9
+ secret_key_base: cee6bd48dcb1f2427d47b6efb3972024f91e183db2a0db39bc1b6975737138a071fb5bad8a10d6713f2fbd1e7781eb8212631ae8c4ad8e30efc6f486dbbf3526
# Do not keep production secrets in the unencrypted secrets file.
# Instead, either read values from the environment.
diff -urN apimode/package.json normal/package.json
--- apimode/package.json 1970-01-01 09:00:00.000000000 +0900
+++ normal/package.json 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,5 @@
+{
+ "name": "normal",
+ "private": true,
+ "dependencies": {}
+}
diff -urN apimode/public/404.html normal/public/404.html
--- apimode/public/404.html 1970-01-01 09:00:00.000000000 +0900
+++ normal/public/404.html 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The page you were looking for doesn't exist (404)</title>
+ <meta name="viewport" content="width=device-width,initial-scale=1">
+ <style>
+ .rails-default-error-page {
+ background-color: #EFEFEF;
+ color: #2E2F30;
+ text-align: center;
+ font-family: arial, sans-serif;
+ margin: 0;
+ }
+
+ .rails-default-error-page div.dialog {
+ width: 95%;
+ max-width: 33em;
+ margin: 4em auto 0;
+ }
+
+ .rails-default-error-page div.dialog > div {
+ border: 1px solid #CCC;
+ border-right-color: #999;
+ border-left-color: #999;
+ border-bottom-color: #BBB;
+ border-top: #B00100 solid 4px;
+ border-top-left-radius: 9px;
+ border-top-right-radius: 9px;
+ background-color: white;
+ padding: 7px 12% 0;
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
+ }
+
+ .rails-default-error-page h1 {
+ font-size: 100%;
+ color: #730E15;
+ line-height: 1.5em;
+ }
+
+ .rails-default-error-page div.dialog > p {
+ margin: 0 0 1em;
+ padding: 1em;
+ background-color: #F7F7F7;
+ border: 1px solid #CCC;
+ border-right-color: #999;
+ border-left-color: #999;
+ border-bottom-color: #999;
+ border-bottom-left-radius: 4px;
+ border-bottom-right-radius: 4px;
+ border-top-color: #DADADA;
+ color: #666;
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
+ }
+ </style>
+</head>
+
+<body class="rails-default-error-page">
+ <!-- This file lives in public/404.html -->
+ <div class="dialog">
+ <div>
+ <h1>The page you were looking for doesn't exist.</h1>
+ <p>You may have mistyped the address or the page may have moved.</p>
+ </div>
+ <p>If you are the application owner check the logs for more information.</p>
+ </div>
+</body>
+</html>
diff -urN apimode/public/422.html normal/public/422.html
--- apimode/public/422.html 1970-01-01 09:00:00.000000000 +0900
+++ normal/public/422.html 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,67 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>The change you wanted was rejected (422)</title>
+ <meta name="viewport" content="width=device-width,initial-scale=1">
+ <style>
+ .rails-default-error-page {
+ background-color: #EFEFEF;
+ color: #2E2F30;
+ text-align: center;
+ font-family: arial, sans-serif;
+ margin: 0;
+ }
+
+ .rails-default-error-page div.dialog {
+ width: 95%;
+ max-width: 33em;
+ margin: 4em auto 0;
+ }
+
+ .rails-default-error-page div.dialog > div {
+ border: 1px solid #CCC;
+ border-right-color: #999;
+ border-left-color: #999;
+ border-bottom-color: #BBB;
+ border-top: #B00100 solid 4px;
+ border-top-left-radius: 9px;
+ border-top-right-radius: 9px;
+ background-color: white;
+ padding: 7px 12% 0;
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
+ }
+
+ .rails-default-error-page h1 {
+ font-size: 100%;
+ color: #730E15;
+ line-height: 1.5em;
+ }
+
+ .rails-default-error-page div.dialog > p {
+ margin: 0 0 1em;
+ padding: 1em;
+ background-color: #F7F7F7;
+ border: 1px solid #CCC;
+ border-right-color: #999;
+ border-left-color: #999;
+ border-bottom-color: #999;
+ border-bottom-left-radius: 4px;
+ border-bottom-right-radius: 4px;
+ border-top-color: #DADADA;
+ color: #666;
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
+ }
+ </style>
+</head>
+
+<body class="rails-default-error-page">
+ <!-- This file lives in public/422.html -->
+ <div class="dialog">
+ <div>
+ <h1>The change you wanted was rejected.</h1>
+ <p>Maybe you tried to change something you didn't have access to.</p>
+ </div>
+ <p>If you are the application owner check the logs for more information.</p>
+ </div>
+</body>
+</html>
diff -urN apimode/public/500.html normal/public/500.html
--- apimode/public/500.html 1970-01-01 09:00:00.000000000 +0900
+++ normal/public/500.html 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,66 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <title>We're sorry, but something went wrong (500)</title>
+ <meta name="viewport" content="width=device-width,initial-scale=1">
+ <style>
+ .rails-default-error-page {
+ background-color: #EFEFEF;
+ color: #2E2F30;
+ text-align: center;
+ font-family: arial, sans-serif;
+ margin: 0;
+ }
+
+ .rails-default-error-page div.dialog {
+ width: 95%;
+ max-width: 33em;
+ margin: 4em auto 0;
+ }
+
+ .rails-default-error-page div.dialog > div {
+ border: 1px solid #CCC;
+ border-right-color: #999;
+ border-left-color: #999;
+ border-bottom-color: #BBB;
+ border-top: #B00100 solid 4px;
+ border-top-left-radius: 9px;
+ border-top-right-radius: 9px;
+ background-color: white;
+ padding: 7px 12% 0;
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
+ }
+
+ .rails-default-error-page h1 {
+ font-size: 100%;
+ color: #730E15;
+ line-height: 1.5em;
+ }
+
+ .rails-default-error-page div.dialog > p {
+ margin: 0 0 1em;
+ padding: 1em;
+ background-color: #F7F7F7;
+ border: 1px solid #CCC;
+ border-right-color: #999;
+ border-left-color: #999;
+ border-bottom-color: #999;
+ border-bottom-left-radius: 4px;
+ border-bottom-right-radius: 4px;
+ border-top-color: #DADADA;
+ color: #666;
+ box-shadow: 0 3px 8px rgba(50, 50, 50, 0.17);
+ }
+ </style>
+</head>
+
+<body class="rails-default-error-page">
+ <!-- This file lives in public/500.html -->
+ <div class="dialog">
+ <div>
+ <h1>We're sorry, but something went wrong.</h1>
+ </div>
+ <p>If you are the application owner check the logs for more information.</p>
+ </div>
+</body>
+</html>
diff -urN apimode/test/application_system_test_case.rb normal/test/application_system_test_case.rb
--- apimode/test/application_system_test_case.rb 1970-01-01 09:00:00.000000000 +0900
+++ normal/test/application_system_test_case.rb 2017-12-13 18:38:57.000000000 +0900
@@ -0,0 +1,5 @@
+require "test_helper"
+
+class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
+ driven_by :selenium, using: :chrome, screen_size: [1400, 1400]
+end
rails new apimode --api --skip-bundle
rails new normal --skip-bundle
diff -urN apimode normal > apimode.diff
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment