Agile Web Development with Rails, Edition 4

17 Retrospective 15.4 Task J4: Add a locale switcher.

16 Deployment

git add .
git commit -a -m "save work"
[master 634626b] save work
 122 files changed, 2500 insertions(+), 119 deletions(-)
 create mode 100644 app/assets/javascripts/admin.js.coffee
 create mode 100644 app/assets/javascripts/carts.js.coffee
 create mode 100644 app/assets/javascripts/line_items.js.coffee
 create mode 100644 app/assets/javascripts/orders.js.coffee
 create mode 100644 app/assets/javascripts/sessions.js.coffee
 create mode 100644 app/assets/javascripts/store.js.coffee
 create mode 100644 app/assets/javascripts/users.js.coffee
 create mode 100644 app/assets/stylesheets/admin.css.scss
 create mode 100644 app/assets/stylesheets/application.css.scss
 create mode 100644 app/assets/stylesheets/carts.css.scss
 create mode 100644 app/assets/stylesheets/line_items.css.scss
 create mode 100644 app/assets/stylesheets/orders.css.scss
 create mode 100644 app/assets/stylesheets/sessions.css.scss
 create mode 100644 app/assets/stylesheets/store.css.scss
 create mode 100644 app/assets/stylesheets/users.css.scss
 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/mailers/order_notifier.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/_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.text.erb
 create mode 100644 app/views/line_items/create.js.erb
 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_notifier/received.text.erb
 create mode 100644 app/views/order_notifier/shipped.html.erb
 create mode 100644 app/views/order_notifier/shipped.text.erb
 create mode 100644 app/views/orders/_form.html.erb
 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/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 100644 config/initializers/i18n.rb
 rewrite config/locales/en.yml (99%)
 create mode 100644 config/locales/es.yml
 rewrite config/routes.rb (92%)
 create mode 100644 db/migrate/20130224000002_create_carts.rb
 create mode 100644 db/migrate/20130224000003_create_line_items.rb
 create mode 100644 db/migrate/20130224000004_add_quantity_to_line_items.rb
 create mode 100644 db/migrate/20130224000005_combine_items_in_cart.rb
 create mode 100644 db/migrate/20130224000006_add_price_to_line_item.rb
 create mode 100644 db/migrate/20130224000007_create_orders.rb
 create mode 100644 db/migrate/20130224000008_add_order_id_to_line_item.rb
 create mode 100644 db/migrate/20130224000009_create_users.rb
 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/helpers/admin_helper_test.rb
 create mode 100644 test/helpers/carts_helper_test.rb
 create mode 100644 test/helpers/line_items_helper_test.rb
 create mode 100644 test/helpers/orders_helper_test.rb
 create mode 100644 test/helpers/sessions_helper_test.rb
 create mode 100644 test/helpers/store_helper_test.rb
 create mode 100644 test/helpers/users_helper_test.rb
 create mode 100644 test/integration/dsl_user_stories_test.rb
 create mode 100644 test/integration/user_stories_test.rb
 create mode 100644 test/mailers/order_notifier_test.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
edit config/database.yml
# SQLite version 3.x
#   gem install sqlite3
#
#   Ensure the SQLite 3 gem is defined in your Gemfile
#   gem 'sqlite3'
development:
  adapter: sqlite3
  database: db/development.sqlite3
  pool: 5
  timeout: 5000
 
# 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:
  adapter: sqlite3
  database: db/test.sqlite3
  pool: 5
  timeout: 5000
 
production:
  adapter: mysql2
  encoding: utf8
  reconnect: false
  database: depot_production
  pool: 5
  username: username
  password: password
  host: localhost
edit Gemfile
# source 'https://rubygems.org'
 
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem "activeresource", :path => "/home/rubys/git/activeresource"
gem "activerecord-deprecated_finders", :path => "/home/rubys/git/activerecord-deprecated_finders"
gem "arel", :path => "/home/rubys/git/arel"
gem 'rails', :path => "/home/rubys/git/rails" # '4.0.0.beta'
 
gem 'sqlite3'
group :production do
  gem 'mysql2'
end
 
# Gems used only for assets and not required
# in production environments by default.
group :assets do
  gem 'sprockets-rails', :path => "/home/rubys/git/sprockets-rails" # '~> 2.0.0.rc1'
  gem 'sass-rails',   :path => "/home/rubys/git/sass-rails" # '~> 4.0.0.beta'
  gem 'coffee-rails', :path => "/home/rubys/git/coffee-rails" # '~> 4.0.0.beta'
 
  # See https://github.com/sstephenson/execjs#readme for more supported runtimes
  # gem 'therubyracer', platforms: :ruby
 
  gem 'uglifier', '>= 1.0.3'
end
 
gem 'jquery-rails'
 
# Turbolinks makes following links in your web application faster.
# Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
 
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.0.1'
 
# To use ActiveModel has_secure_password
gem 'bcrypt-ruby', '~> 3.0.0'
 
# Use unicorn as the app server
# gem 'unicorn'
 
# Deploy with Capistrano
gem 'capistrano', group: :development
 
# To use debugger
# gem 'debugger'
bundle install
Using rake (10.0.3) 
Using i18n (0.6.1) 
Using minitest (4.6.1) 
Using multi_json (1.6.1) 
Using atomic (1.0.1) 
Using thread_safe (0.1.0) 
Using tzinfo (0.3.35) 
Using activesupport (4.0.0.beta) 
Using builder (3.1.4) 
Using erubis (2.7.0) 
Using rack (1.5.2) 
Using rack-test (0.6.2) 
Using actionpack (4.0.0.beta) 
Using mime-types (1.21) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.5.3) 
Using actionmailer (4.0.0.beta) 
Using activemodel (4.0.0.beta) 
Using activerecord-deprecated_finders (0.0.3) 
Using arel (3.0.2.20120819075748) 
Using activerecord (4.0.0.beta) 
Using activeresource (4.0.0.beta) 
Using bcrypt-ruby (3.0.1) 
Using bundler (1.3.0.pre.8) 
Using highline (1.6.15) 
Using net-ssh (2.6.5) 
Using net-scp (1.1.0) 
Using net-sftp (2.1.1) 
Using net-ssh-gateway (1.2.0) 
Using capistrano (2.14.2) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using json (1.7.7) 
Using rdoc (3.12.1) 
Using thor (0.17.0) 
Using railties (4.0.0.beta) 
Using coffee-rails (4.0.0.beta) 
Using hike (1.2.1) 
Using jbuilder (1.0.2) 
Using jquery-rails (2.2.1) 
Using mysql2 (0.3.11) 
Using tilt (1.3.3) 
Using sprockets (2.8.2) 
Using sprockets-rails (2.0.0.rc2) 
Using rails (4.0.0.beta) 
Using sass (3.2.6) 
Using sass-rails (4.0.0.beta) 
Using sqlite3 (1.3.7) 
Using turbolinks (1.0.0) 
Using uglifier (1.3.0) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
rake db:setup RAILS_ENV=production
depot_production already exists
-- create_table("carts", {:force=>true})
   -> 0.1227s
-- create_table("line_items", {:force=>true})
   -> 0.1253s
-- add_index("line_items", ["cart_id"], {:name=>"index_line_items_on_cart_id"})
   -> 0.0981s
-- add_index("line_items", ["product_id"], {:name=>"index_line_items_on_product_id"})
   -> 0.1081s
-- create_table("orders", {:force=>true})
   -> 0.0829s
-- create_table("products", {:force=>true})
   -> 0.0831s
-- create_table("users", {:force=>true})
   -> 0.1202s
-- initialize_schema_migrations_table()
   -> 0.1881s
-- assume_migrated_upto_version(20130224000009, ["/home/rubys/git/awdwr/edition4/work-200/depot/db/migrate"])
   -> 0.0743s
bundle pack
Your Gemfile contains path and git dependencies. If you want to package them as well, please pass the --all flag. This will be the default on Bundler 2.0.
Using rake (10.0.3) 
Using i18n (0.6.1) 
Using minitest (4.6.1) 
Using multi_json (1.6.1) 
Using atomic (1.0.1) 
Using thread_safe (0.1.0) 
Using tzinfo (0.3.35) 
Using activesupport (4.0.0.beta) 
Using builder (3.1.4) 
Using erubis (2.7.0) 
Using rack (1.5.2) 
Using rack-test (0.6.2) 
Using actionpack (4.0.0.beta) 
Using mime-types (1.21) 
Using polyglot (0.3.3) 
Using treetop (1.4.12) 
Using mail (2.5.3) 
Using actionmailer (4.0.0.beta) 
Using activemodel (4.0.0.beta) 
Using activerecord-deprecated_finders (0.0.3) 
Using arel (3.0.2.20120819075748) 
Using activerecord (4.0.0.beta) 
Using activeresource (4.0.0.beta) 
Using bcrypt-ruby (3.0.1) 
Using bundler (1.3.0.pre.8) 
Using highline (1.6.15) 
Using net-ssh (2.6.5) 
Using net-scp (1.1.0) 
Using net-sftp (2.1.1) 
Using net-ssh-gateway (1.2.0) 
Using capistrano (2.14.2) 
Using coffee-script-source (1.4.0) 
Using execjs (1.4.0) 
Using coffee-script (2.2.0) 
Using json (1.7.7) 
Using rdoc (3.12.1) 
Using thor (0.17.0) 
Using railties (4.0.0.beta) 
Using coffee-rails (4.0.0.beta) 
Using hike (1.2.1) 
Using jbuilder (1.0.2) 
Using jquery-rails (2.2.1) 
Using mysql2 (0.3.11) 
Using tilt (1.3.3) 
Using sprockets (2.8.2) 
Using sprockets-rails (2.0.0.rc2) 
Using rails (4.0.0.beta) 
Using sass (3.2.6) 
Using sass-rails (4.0.0.beta) 
Using sqlite3 (1.3.7) 
Using turbolinks (1.0.0) 
Using uglifier (1.3.0) 
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Updating files in vendor/cache
  * rake-10.0.3.gem
  * i18n-0.6.1.gem
  * minitest-4.6.1.gem
  * multi_json-1.6.1.gem
  * atomic-1.0.1.gem
  * thread_safe-0.1.0.gem
  * tzinfo-0.3.35.gem
Could not find activesupport-4.0.0.beta.gem for installation
capify .
[add] writing './Capfile'
[add] writing './config/deploy.rb'
[done] capified!
edit config/deploy.rb
require 'bundler/capistrano'
 
# be sure to change these
set :user, 'rubys'
set :domain, 'depot.pragprog.com'
set :application, 'depot'
 
# adjust if you are using RVM, remove if you are not
require "rvm/capistrano"
set :rvm_ruby_string, '1.9.3'
set :rvm_type, :user
 
# file paths
set :repository,  "#{user}@#{domain}:git/#{application}.git" 
set :deploy_to, "/home/#{user}/#{domain}" 
 
# 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, :primary => true
 
# you might need to set this if you aren't seeing password prompts
# default_run_options[: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.
# default_environment['PATH']='<your paths>:/usr/local/bin:/usr/bin:/bin'
# default_environment['GEM_PATH']='<your paths>:/usr/lib/ruby/gems/1.8'
 
# miscellaneous options
set :deploy_via, :remote_cache
set :scm, 'git'
set :branch, 'master'
set :scm_verbose, true
set :use_sudo, false
set :rails_env, :production
 
namespace :deploy do
  desc "cause Passenger to initiate a restart"
  task :restart do
    run "touch #{current_path}/tmp/restart.txt" 
  end
 
  desc "reload the database with seed data"
  task :seed do
    run "cd #{current_path}; rake db:seed RAILS_ENV=#{rails_env}"
  end
end
edit Capfile
load 'deploy'
# Uncomment if you are using Rails' asset pipeline
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
rake assets:precompile
I, [2013-02-24T10:24:41.778416 #29332]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-200/depot/public/assets/cs-2a71f88e31341ae47ea416a2fff229c7.jpg
I, [2013-02-24T10:24:41.783443 #29332]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-200/depot/public/assets/logo-35c5667fbcda38015ca65ede7bd9195b.png
I, [2013-02-24T10:24:41.787319 #29332]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-200/depot/public/assets/rails-b20ced89d98269c2f0c29672ef75e362.png
I, [2013-02-24T10:24:41.790199 #29332]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-200/depot/public/assets/rtp-1adae7106a7022e8aeb42a070713c3cf.jpg
I, [2013-02-24T10:24:41.793718 #29332]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-200/depot/public/assets/ruby-2c156c1b25553be6ee36fc7987ab9362.jpg
I, [2013-02-24T10:24:41.875111 #29332]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-200/depot/public/assets/application-d49086341a1e06e79d813b5bcedc76be.js
I, [2013-02-24T10:24:41.892270 #29332]  INFO -- : Writing /home/rubys/git/awdwr/edition4/work-200/depot/public/assets/application-4dde5427fcd4389796d92b5e8b5f97ea.css
ls public/assets
application-4dde5427fcd4389796d92b5e8b5f97ea.css
application-d49086341a1e06e79d813b5bcedc76be.js
cs-2a71f88e31341ae47ea416a2fff229c7.jpg
logo-35c5667fbcda38015ca65ede7bd9195b.png
manifest-87675fdfc6d2dec26527b20590da4b46.json
rails-b20ced89d98269c2f0c29672ef75e362.png
rtp-1adae7106a7022e8aeb42a070713c3cf.jpg
ruby-2c156c1b25553be6ee36fc7987ab9362.jpg
edit config/environments/production.rb
Depot::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 thread 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
 
  # Enable Rack::Cache to put a simple HTTP cache in front of your application
  # Add `rack-cache` to your Gemfile before enabling this.
  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
  # config.action_dispatch.rack_cache = true
 
  # Disable Rails's static asset server (Apache or nginx will already do this).
  config.serve_static_assets = false
 
  # Compress JavaScripts and CSS.
  config.assets.js_compressor  = :uglifier
  # config.assets.css_compressor = :sass
 
  # Whether to fallback to assets pipeline if a precompiled asset is missed.
  config.assets.compile = false
 
  # Generate digests for assets URLs.
  config.assets.digest = true
 
  # Version of your assets, change this if you want to expire all your assets.
  config.assets.version = '1.0'
 
  # 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
 
  # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies.
  # config.force_ssl = true
 
  # Set to :debug to see everything in the log.
  config.log_level = :info
 
  # Prepend all log lines with the following tags.
  # config.log_tags = [ :subdomain, :uuid ]
 
  # Use a different logger for distributed setups.
  # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
 
  # Use a different cache store in production.
  # config.cache_store = :mem_cache_store
 
  # Enable serving of images, stylesheets, and JavaScripts from an asset server.
  # config.action_controller.asset_host = "http://assets.example.com"
 
  # 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 can not be found).
  config.i18n.fallbacks = true
 
  # Send deprecation notices to registered listeners.
  config.active_support.deprecation = :notify
 
  # 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
 
  # Disable automatic flushing of the log to improve performance.
  # config.autoflush_log = false
 
  # Use default logging formatter so that PID and timestamp are not suppressed.
  config.log_formatter = ::Logger::Formatter.new
 
    require 'active_support/core_ext/numeric/bytes'
    config.logger = Logger.new(paths['log'].first, 2, 10.kilobytes)
end
echo "Depot::Application.configure { paths['log'].first }" | IRBRC=tmp/irbrc ruby bin/rails console production
Loading production environment (Rails 4.0.0.beta)
Switch to inspect mode.
>> Depot::Application.configure { paths['log'].first }
=> "/home/rubys/git/awdwr/edition4/work-200/depot/log/production.log"
>> 
git st
 M Gemfile
 M Gemfile.lock
 M config/database.yml
 M config/environments/production.rb
?? Capfile
?? config/deploy.rb
?? public/assets/
?? vendor/cache/

17 Retrospective 15.4 Task J4: Add a locale switcher.