Agile Web Development with Rails, Edition 5

18 Retrospective 16.4 Task K4: Add a locale switcher.

17 Deployment

</mkdir -p/> was expected to be =~
<"<pre class=\"stderr\">DEPRECATION WARNING: Passing the environment's name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -e option instead. (called from run at /home/rubys/.rvm/gems/ruby-2.4.1/gems/thor-0.19.4/lib/thor/command.rb:27)</pre>">.

Traceback:
  /home/rubys/git/awdwr/edition4/checkdepot.rb:519:in `block (3 levels) in <class:DepotTest>'
  /home/rubys/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.1/lib/nokogiri/xml/node_set.rb:190:in `block in each'
  /home/rubys/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.1/lib/nokogiri/xml/node_set.rb:189:in `upto'
  /home/rubys/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.1/lib/nokogiri/xml/node_set.rb:189:in `each'
  /home/rubys/git/awdwr/edition4/checkdepot.rb:518:in `block (2 levels) in <class:DepotTest>'
  /home/rubys/.rvm/gems/ruby-2.4.1/gems/rails-dom-testing-2.0.3/lib/rails/dom/testing/assertions/selector_assertions.rb:286:in `nest_selection'
  /home/rubys/.rvm/gems/ruby-2.4.1/gems/rails-dom-testing-2.0.3/lib/rails/dom/testing/assertions/selector_assertions.rb:175:in `block in assert_select'
  /home/rubys/.rvm/gems/ruby-2.4.1/gems/rails-dom-testing-2.0.3/lib/rails/dom/testing/assertions/selector_assertions.rb:171:in `tap'
  /home/rubys/.rvm/gems/ruby-2.4.1/gems/rails-dom-testing-2.0.3/lib/rails/dom/testing/assertions/selector_assertions.rb:171:in `assert_select'
  /home/rubys/git/awdwr/edition4/checkdepot.rb:517:in `block in <class:DepotTest>'
git add .
git commit -a -m "save work"
[master 9705ced] save work
 151 files changed, 9837 insertions(+), 67 deletions(-)
 create mode 100644 .babelrc
 create mode 100644 .postcssrc.yml
 create mode 100644 app/assets/javascripts/admin.coffee
 create mode 100644 app/assets/javascripts/carts.coffee
 create mode 100644 app/assets/javascripts/channels/products.coffee
 create mode 100644 app/assets/javascripts/line_items.coffee
 create mode 100644 app/assets/javascripts/locale_switcher.coffee
 create mode 100644 app/assets/javascripts/orders.coffee
 create mode 100644 app/assets/javascripts/sessions.coffee
 create mode 100644 app/assets/javascripts/store.coffee
 create mode 100644 app/assets/javascripts/users.coffee
 create mode 100644 app/assets/stylesheets/admin.scss
 create mode 100644 app/assets/stylesheets/application.scss
 create mode 100644 app/assets/stylesheets/carts.scss
 create mode 100644 app/assets/stylesheets/line_items.scss
 create mode 100644 app/assets/stylesheets/orders.scss
 create mode 100644 app/assets/stylesheets/sessions.scss
 create mode 100644 app/assets/stylesheets/store.scss
 create mode 100644 app/assets/stylesheets/users.scss
 create mode 100644 app/channels/products_channel.rb
 create mode 100644 app/controllers/admin_controller.rb
 create mode 100644 app/controllers/carts_controller.rb
 create mode 100644 app/controllers/concerns/current_cart.rb
 create mode 100644 app/controllers/line_items_controller.rb
 create mode 100644 app/controllers/orders_controller.rb
 create mode 100644 app/controllers/sessions_controller.rb
 create mode 100644 app/controllers/store_controller.rb
 create mode 100644 app/controllers/users_controller.rb
 create mode 100644 app/helpers/admin_helper.rb
 create mode 100644 app/helpers/carts_helper.rb
 create mode 100644 app/helpers/line_items_helper.rb
 create mode 100644 app/helpers/orders_helper.rb
 create mode 100644 app/helpers/sessions_helper.rb
 create mode 100644 app/helpers/store_helper.rb
 create mode 100644 app/helpers/users_helper.rb
 create mode 100644 app/javascript/PayTypeSelector/CheckPayType.jsx
 create mode 100644 app/javascript/PayTypeSelector/CreditCardPayType.jsx
 create mode 100644 app/javascript/PayTypeSelector/NoPayType.jsx
 create mode 100644 app/javascript/PayTypeSelector/PurchaseOrderPayType.jsx
 create mode 100644 app/javascript/PayTypeSelector/index.jsx
 create mode 100644 app/javascript/packs/application.js
 create mode 100644 app/javascript/packs/hello_react.jsx
 create mode 100644 app/javascript/packs/pay_type.jsx
 create mode 100644 app/jobs/charge_order_job.rb
 create mode 100644 app/mailers/order_mailer.rb
 create mode 100644 app/models/cart.rb
 create mode 100644 app/models/line_item.rb
 create mode 100644 app/models/order.rb
 create mode 100644 app/models/user.rb
 create mode 100644 app/views/admin/index.html.erb
 create mode 100644 app/views/carts/_cart.html.erb
 create mode 100644 app/views/carts/_cart.json.jbuilder
 create mode 100644 app/views/carts/_form.html.erb
 create mode 100644 app/views/carts/edit.html.erb
 create mode 100644 app/views/carts/index.html.erb
 create mode 100644 app/views/carts/index.json.jbuilder
 create mode 100644 app/views/carts/new.html.erb
 create mode 100644 app/views/carts/show.html.erb
 create mode 100644 app/views/carts/show.json.jbuilder
 create mode 100644 app/views/line_items/_form.html.erb
 create mode 100644 app/views/line_items/_line_item.html.erb
 create mode 100644 app/views/line_items/_line_item.json.jbuilder
 create mode 100644 app/views/line_items/_line_item.text.erb
 create mode 100644 app/views/line_items/create.js.coffee
 create mode 100644 app/views/line_items/edit.html.erb
 create mode 100644 app/views/line_items/index.html.erb
 create mode 100644 app/views/line_items/index.json.jbuilder
 create mode 100644 app/views/line_items/new.html.erb
 create mode 100644 app/views/line_items/show.html.erb
 create mode 100644 app/views/line_items/show.json.jbuilder
 create mode 100644 app/views/order_mailer/received.text.erb
 create mode 100644 app/views/order_mailer/shipped.html.erb
 create mode 100644 app/views/orders/_form.html.erb
 create mode 100644 app/views/orders/_order.html.erb
 create mode 100644 app/views/orders/_order.json.jbuilder
 create mode 100644 app/views/orders/edit.html.erb
 create mode 100644 app/views/orders/index.html.erb
 create mode 100644 app/views/orders/index.json.jbuilder
 create mode 100644 app/views/orders/new.html.erb
 create mode 100644 app/views/orders/show.html.erb
 create mode 100644 app/views/orders/show.json.jbuilder
 create mode 100644 app/views/products/who_bought.atom.builder
 create mode 100644 app/views/products/who_bought.html.erb
 create mode 100644 app/views/products/who_bought.xml.builder
 create mode 100644 app/views/sessions/create.html.erb
 create mode 100644 app/views/sessions/destroy.html.erb
 create mode 100644 app/views/sessions/new.html.erb
 create mode 100644 app/views/store/index.html.erb
 create mode 100644 app/views/users/_form.html.erb
 create mode 100644 app/views/users/_user.json.jbuilder
 create mode 100644 app/views/users/edit.html.erb
 create mode 100644 app/views/users/index.html.erb
 create mode 100644 app/views/users/index.json.jbuilder
 create mode 100644 app/views/users/new.html.erb
 create mode 100644 app/views/users/show.html.erb
 create mode 100644 app/views/users/show.json.jbuilder
 create mode 100755 bin/webpack
 create mode 100755 bin/webpack-dev-server
 create mode 100644 config/initializers/i18n.rb
 rewrite config/locales/en.yml (99%)
 create mode 100644 config/locales/es.yml
 create mode 100644 config/webpack/development.js
 create mode 100644 config/webpack/environment.js
 create mode 100644 config/webpack/production.js
 create mode 100644 config/webpack/test.js
 create mode 100644 config/webpacker.yml
 create mode 100644 db/migrate/20171113000002_create_carts.rb
 create mode 100644 db/migrate/20171113000003_create_line_items.rb
 create mode 100644 db/migrate/20171113000004_add_quantity_to_line_items.rb
 create mode 100644 db/migrate/20171113000005_combine_items_in_cart.rb
 create mode 100644 db/migrate/20171113000006_add_price_to_line_item.rb
 create mode 100644 db/migrate/20171113000007_create_orders.rb
 create mode 100644 db/migrate/20171113000008_add_order_id_to_line_item.rb
 create mode 100644 db/migrate/20171113000009_create_users.rb
 create mode 100644 depot/config/initializers/i18n.rb
 create mode 100644 lib/pago.rb
 create mode 100644 public/javascripts/i18n.js
 create mode 100644 public/javascripts/translations.js
 create mode 100644 test/controllers/admin_controller_test.rb
 create mode 100644 test/controllers/carts_controller_test.rb
 create mode 100644 test/controllers/line_items_controller_test.rb
 create mode 100644 test/controllers/orders_controller_test.rb
 create mode 100644 test/controllers/sessions_controller_test.rb
 create mode 100644 test/controllers/store_controller_test.rb
 create mode 100644 test/controllers/users_controller_test.rb
 create mode 100644 test/fixtures/carts.yml
 create mode 100644 test/fixtures/line_items.yml
 create mode 100644 test/fixtures/orders.yml
 create mode 100644 test/fixtures/users.yml
 create mode 100644 test/jobs/charge_order_job_test.rb
 create mode 100644 test/mailers/order_mailer_test.rb
 create mode 100644 test/mailers/previews/order_mailer_preview.rb
 create mode 100644 test/models/cart_test.rb
 create mode 100644 test/models/line_item_test.rb
 create mode 100644 test/models/order_test.rb
 create mode 100644 test/models/user_test.rb
 create mode 100644 test/system/carts_test.rb
 create mode 100644 test/system/line_items_test.rb
 create mode 100644 test/system/orders_test.rb
 create mode 100644 test/system/users_test.rb
 create mode 100644 yarn.lock
edit config/database.yml
# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
#
default: &default
  adapter: sqlite3
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  timeout: 5000
 
development:
  <<: *default
  database: db/development.sqlite3
 
# 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
  database: db/test.sqlite3
 
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: depot_production
  pool: 5
  username: username
  password: password
  host: localhost
edit Gemfile
group :production do
  gem 'mysql2', '~> 0.4.0'
end
edit Gemfile
# Use Capistrano for deployment
gem 'capistrano-rails', group: :development
gem 'capistrano-rvm', group: :development
gem 'capistrano-bundler', group: :development
gem 'capistrano-passenger', group: :development
bundle install --local
Resolving dependencies...
Using rake 12.2.1
Using concurrent-ruby 1.0.5
Using i18n 0.9.1
Using minitest 5.10.3
Using thread_safe 0.3.6
Using tzinfo 1.2.4
Using activesupport 5.2.0.alpha from source at `/home/rubys/git/rails`
Using builder 3.2.3
Using erubi 1.7.0
Using mini_portile2 2.3.0
Using nokogiri 1.8.1
Using rails-dom-testing 2.0.3
Using crass 1.0.2
Using loofah 2.1.1
Using rails-html-sanitizer 1.0.3
Using actionview 5.2.0.alpha from source at `/home/rubys/git/rails`
Using rack 2.0.3
Using rack-test 0.7.0
Using actionpack 5.2.0.alpha from source at `/home/rubys/git/rails`
Using nio4r 2.1.0
Using websocket-extensions 0.1.3
Using websocket-driver 0.6.5
Using actioncable 5.2.0.alpha from source at `/home/rubys/git/rails`
Using globalid 0.4.1
Using activejob 5.2.0.alpha from source at `/home/rubys/git/rails`
Using mini_mime 1.0.0
Using mail 2.7.0
Using actionmailer 5.2.0.alpha from source at `/home/rubys/git/rails`
Using activemodel 5.2.0.alpha from source at `/home/rubys/git/rails`
Using activemodel-serializers-xml 1.0.2
Using arel 9.0.0.alpha from source at `/home/rubys/git/arel`
Using activerecord 5.2.0.alpha from source at `/home/rubys/git/rails`
Using activestorage 5.2.0.alpha from source at `/home/rubys/git/rails`
Using public_suffix 3.0.1
Using addressable 2.5.2
Using net-ssh 4.2.0
Using net-scp 1.2.1
Using sshkit 1.15.0
Using airbrussh 1.3.0
Using io-like 0.3.0
Using archive-zip 0.7.0
Using bcrypt 3.1.11
Using bindex 0.5.0
Using msgpack 1.1.0
Using bootsnap 1.1.5
Using bundler 1.16.0
Using byebug 9.1.0
Using capistrano 3.10.0
Using capistrano-bundler 1.3.0
Using capistrano-passenger 0.2.0
Using capistrano-rails 1.3.0
Using capistrano-rvm 0.1.2
Using xpath 2.1.0
Using capybara 2.15.4
Using ffi 1.9.18
Using childprocess 0.8.0
Using chromedriver-helper 1.1.0
Using coffee-script-source 1.12.2
Using execjs 2.7.0
Using coffee-script 2.4.1
Using method_source 0.9.0
Using thor 0.19.4
Using railties 5.2.0.alpha from source at `/home/rubys/git/rails`
Using coffee-rails 4.2.2
Using et-orbi 1.0.8
Using i18n-js 3.0.2
Using multi_json 1.12.2
Using jbuilder 2.7.0
Using mono_logger 1.1.0
Using mustermann 1.0.1
Using mysql2 0.4.9
Using pg 0.19.0
Using puma 3.10.0
Using queue_classic 3.2.0.RC1 from source at `/home/rubys/git/queue_classic`
Using rack-protection 2.0.0
Using rack-proxy 0.6.2
Using sprockets 3.7.1
Using sprockets-rails 3.2.1
Using rails 5.2.0.alpha from source at `/home/rubys/git/rails`
Using rb-fsevent 0.10.2
Using rb-inotify 0.9.9 from source at `/home/rubys/git/rb-inotify`
Using redis 4.0.1
Using redis-namespace 1.6.0
Using tilt 2.0.8
Using sinatra 2.0.0
Using vegas 0.1.11
Using resque 1.27.4
Using rufus-scheduler 3.4.2
Using resque-scheduler 4.3.0 from source at `/home/rubys/git/resque-scheduler`
Using rubyzip 1.2.1
Using sass-listen 4.0.0
Using sass 3.5.3
Using sass-rails 5.0.6 from source at `/home/rubys/git/sass-rails`
Using selenium-webdriver 3.7.0
Using spring 2.0.2
Using sqlite3 1.3.13
Using turbolinks-source 5.0.3
Using turbolinks 5.0.1
Using uglifier 3.2.0
Using web-console 3.5.1 from source at `/home/rubys/git/web-console`
Using webpacker 3.0.2
Bundle complete! 29 Gemfile dependencies, 101 gems now installed.
Use `bundle info [gemname]` to see where a bundled gem is installed.
rake db:setup RAILS_ENV=production
Created database 'depot_production'
-- create_table("carts", {:force=>:cascade})
   -> 0.0234s
-- create_table("line_items", {:force=>:cascade})
   -> 0.0199s
-- create_table("orders", {:force=>:cascade})
   -> 0.0194s
-- create_table("products", {:force=>:cascade})
   -> 0.0197s
-- create_table("users", {:force=>:cascade})
   -> 0.0194s
echo no | bundle exec cap install STAGES=production
mkdir -p config/deploy
mkdir -p lib/capistrano/tasks
create config/deploy.rb
create config/deploy/production.rb
create Capfile
Capified
edit config/deploy.rb
# be sure to change these values
user = 'rubys'
domain = 'depot.pragprog.com'
 
# adjust if you are using RVM, remove if you are not
set :rvm_type, :system
set :rvm_ruby_string, 'ruby-2.4.1'
 
# file paths
set :application, 'depot'
set :repo_url, "#{user}@#{domain}:git/#{fetch(:application)}.git" 
set :deploy_to, "/home/#{user}/deploy/#{fetch(:application)}" 
 
# distribute your applications across servers (the instructions below put them
# all on the same server, defined above as 'domain', adjust as necessary)
role :app, domain
role :web, domain
role :db, domain
 
# you might need to set this if you aren't seeing password prompts
# or are seeing errors like 'no tty present and no askpass program specified'
#
# set :pty true
 
# As Capistrano executes in a non-interactive mode and therefore doesn't cause
# any of your shell profile scripts to be run, the following might be needed
# if (for example) you have locally installed gems or applications.  Note:
# this needs to contain the full values for the variables set, not simply
# the deltas.
#
# set :default_environment, {
#   'PATH' => '<your paths>:/usr/local/bin:/usr/bin:/bin',
#   'GEM_PATH' => '<your paths>:/usr/lib/ruby/gems/1.8'
# }
#
# See https://rvm.io/deployment/capistrano#environment for more info.
edit lib/capistrano/tasks/deploy-seed.rake
#
# Additional task to deploy seed data
#
 
namespace :deploy do
  desc "reload the database with seed data"
  task :seed do
    on roles(:app) do
      execute "cd #{current_path}; bin/rails db:seed RAILS_ENV=production"
    end
  end
end
edit Capfile
# Load DSL and set up stages
require "capistrano/setup"
 
# Include default deployment tasks
require "capistrano/deploy"
 
# Load the SCM plugin appropriate to your project:
#
# require "capistrano/scm/hg"
# install_plugin Capistrano::SCM::Hg
# or
# require "capistrano/scm/svn"
# install_plugin Capistrano::SCM::Svn
# or
require "capistrano/scm/git"
install_plugin Capistrano::SCM::Git
 
# Include tasks from other gems included in your Gemfile
#
# For documentation on these, see for example:
#
#   https://github.com/capistrano/rvm
#   https://github.com/capistrano/rbenv
#   https://github.com/capistrano/chruby
#   https://github.com/capistrano/bundler
#   https://github.com/capistrano/rails
#   https://github.com/capistrano/passenger
#
require "capistrano/rvm"
# require "capistrano/rbenv"
# require "capistrano/chruby"
require "capistrano/bundler"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
require "capistrano/passenger"
 
# Load custom tasks from `lib/capistrano/tasks` if you have any defined
Dir.glob("lib/capistrano/tasks/*.rake").each { |r| import r }
edit config/environments/production.rb
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
 
  # Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"]
  # or in config/master.key. This key is used to decrypt credentials (and other encrypted files).
  # config.require_master_key = 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
 
  # Store uploaded files on the local file system (see config/storage.yml for options)
  config.active_storage.service = :local
 
  # 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 = "depot_#{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
 
  require 'active_support/core_ext/numeric/bytes'
  config.logger = Logger.new(paths['log'].first, 2, 10.megabytes)
end
echo "Depot::Application.configure { paths['log'].first }" | IRBRC=tmp/irbrc ruby bin/rails console production
DEPRECATION WARNING: Passing the environment's name as a regular argument is deprecated and will be removed in the next Rails version. Please, use the -e option instead. (called from run at /home/rubys/.rvm/gems/ruby-2.4.1/gems/thor-0.19.4/lib/thor/command.rb:27)
Loading production environment (Rails 5.2.0.alpha)
Switch to inspect mode.
>> Depot::Application.configure { paths['log'].first }
=> "/home/rubys/git/awdwr/edition4/work/depot/log/production.log"
>> 
git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)
 
	modified:   Gemfile
	modified:   Gemfile.lock
	modified:   config/database.yml
	modified:   config/environments/production.rb
 
Untracked files:
  (use "git add <file>..." to include in what will be committed)
 
	Capfile
	config/deploy.rb
	config/deploy/
	lib/capistrano/
 
no changes added to commit (use "git add" and/or "git commit -a")

18 Retrospective 16.4 Task K4: Add a locale switcher.