13.2 Iteration H2: Integration Tests 12.4 Playtime
RuntimeError: Edit app/mailers/order_notifier.rb failed at makedepot.rb:2543 Traceback:
Create a mailer
rails generate mailer OrderNotifier received shipped
create app/mailers/order_notifier_mailer.rb
invoke erb
create app/views/order_notifier_mailer
create app/views/order_notifier_mailer/received.text.erb
create app/views/order_notifier_mailer/received.html.erb
create app/views/order_notifier_mailer/shipped.text.erb
create app/views/order_notifier_mailer/shipped.html.erb
invoke test_unit
create test/mailers/order_notifier_mailer_test.rb
create test/mailers/previews/order_notifier_mailer_preview.rb
Edit development configuration
edit config/environments/development.rb
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.
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = false
config.cache_store = :memory_store
config.public_file_server.headers = {
'Cache-Control' => 'public, max-age=172800'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
# Don't care if the mailer can't send.
config.action_mailer.raise_delivery_errors = false
# Don't actually send emails
config.action_mailer.delivery_method = :test
#
# Alternate configuration example, using gmail:
# config.action_mailer.delivery_method = :smtp
# config.action_mailer.smtp_settings = {
# address: "smtp.gmail.com",
# port: 587,
# domain: "domain.of.sender.net",
# authentication: "plain",
# user_name: "dave",
# password: "secret",
# enable_starttls_auto: true
# }
# 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
# Asset digests allow you to set far-future HTTP expiration dates on all assets,
# yet still be able to expire them through the digest params.
config.assets.digest = true
# Adds additional error checking when serving assets at runtime.
# Checks for improperly declared sprockets dependencies.
# Raises helpful error messages.
config.assets.raise_runtime_errors = 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
Tailor the from address
edit app/mailers/order_notifier.rb
#<IndexError: regexp not matched> /home/rubys/git/gorp/lib/gorp/edit.rb:91:in `edit' makedepot.rb:2543:in `block (2 levels) in <main>' /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `instance_exec' /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `edit' makedepot.rb:2542:in `block in <main>' /home/rubys/git/gorp/lib/gorp/output.rb:59:in `block (4 levels) in <top (required)>' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `each' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `block (3 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:22:in `block (2 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:11:in `block in <top (required)>'
Tailor the confirm receipt email
edit app/views/order_notifier/received.text.erb
#<Errno::ENOENT: No such file or directory @ rb_sysopen - app/views/order_notifier/received.text.erb> /home/rubys/git/gorp/lib/gorp/edit.rb:177:in `initialize' /home/rubys/git/gorp/lib/gorp/edit.rb:177:in `open' /home/rubys/git/gorp/lib/gorp/edit.rb:177:in `edit' makedepot.rb:2554:in `block in <main>' /home/rubys/git/gorp/lib/gorp/output.rb:59:in `block (4 levels) in <top (required)>' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `each' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `block (3 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:22:in `block (2 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:11:in `block in <top (required)>'
Dear <%= @order.name %>
Thank you for your recent order from The Pragmatic Store.
You ordered the following items:
<%= render @order.line_items -%>
We'll send you a separate e-mail when your order ships.
Text partial for the line items
edit app/views/line_items/_line_item.text.erb
<%= sprintf("%2d x %s",
line_item.quantity,
truncate(line_item.product.title, length: 50)) %>
Get the order, sent the confirmation
edit app/mailers/order_notifier.rb
#<IndexError: regexp not matched> /home/rubys/git/gorp/lib/gorp/edit.rb:107:in `dcl' makedepot.rb:2584:in `block (3 levels) in <main>' makedepot.rb:2583:in `each' makedepot.rb:2583:in `block (2 levels) in <main>' /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `instance_exec' /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `edit' makedepot.rb:2581:in `block in <main>' /home/rubys/git/gorp/lib/gorp/output.rb:59:in `block (4 levels) in <top (required)>' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `each' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `block (3 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:22:in `block (2 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:11:in `block in <top (required)>'
Invoke mailer from the controller
edit app/controllers/orders_controller.rb
def create
@order = Order.new(order_params)
@order.add_line_items_from_cart(@cart)
respond_to do |format|
if @order.save
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
session[:order_id] = @order.id
OrderNotifier.received(@order).deliver_later
format.html { redirect_to store_url, notice:
'Thank you for your order.' }
format.json { render :show, status: :created,
location: @order }
else
format.html { render :new }
format.json { render json: @order.errors,
status: :unprocessable_entity }
end
end
end
Tailor the confirm shipped email (this time in HTML)
edit app/views/order_notifier/shipped.html.erb
#<Errno::ENOENT: No such file or directory @ rb_sysopen - app/views/order_notifier/shipped.html.erb> /home/rubys/git/gorp/lib/gorp/edit.rb:177:in `initialize' /home/rubys/git/gorp/lib/gorp/edit.rb:177:in `open' /home/rubys/git/gorp/lib/gorp/edit.rb:177:in `edit' makedepot.rb:2615:in `block in <main>' /home/rubys/git/gorp/lib/gorp/output.rb:59:in `block (4 levels) in <top (required)>' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `each' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `block (3 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:22:in `block (2 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:11:in `block in <top (required)>'
<h3>Pragmatic Order Shipped</h3>
<p>
This is just to let you know that we've shipped your recent order:
</p>
<table>
<tr><th colspan="2">Qty</th><th>Description</th></tr>
<%= render @order.line_items -%>
</table>
Review HTML partial for the line items
edit app/views/line_items/_line_item.html.erb
<% if line_item == @current_item %>
<tr id="current_item">
<% else %>
<tr>
<% end %>
<td><%= line_item.quantity %>×</td>
<td><%= line_item.product.title %></td>
<td class="item_price"><%= number_to_currency(line_item.total_price) %></td>
</tr>
Update the test case
edit test/*/order_notifier_test.rb
#<IndexError: regexp not matched> /home/rubys/git/gorp/lib/gorp/edit.rb:150:in `[]=' /home/rubys/git/gorp/lib/gorp/edit.rb:150:in `msub' makedepot.rb:2637:in `block (3 levels) in <main>' makedepot.rb:2636:in `times' makedepot.rb:2636:in `block (2 levels) in <main>' /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `instance_exec' /home/rubys/git/gorp/lib/gorp/edit.rb:173:in `edit' makedepot.rb:2635:in `block in <main>' /home/rubys/git/gorp/lib/gorp/output.rb:59:in `block (4 levels) in <top (required)>' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `each' /home/rubys/git/gorp/lib/gorp/output.rb:49:in `block (3 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:22:in `block (2 levels) in <top (required)>' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:175:in `_nested_structures' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:68:in `tag!' /home/rubys/.rvm/gems/ruby-2.3.0/gems/builder-3.2.2/lib/builder/xmlbase.rb:93:in `method_missing' /home/rubys/git/gorp/lib/gorp/output.rb:11:in `block in <top (required)>'
rails test
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from included at /home/rubys/.rvm/gems/ruby-2.3.0/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:7)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from included at /home/rubys/.rvm/gems/ruby-2.3.0/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:7)
rails aborted!
ActiveRecord::NoEnvironmentInSchemaError:
Environment data not found in the schema. To resolve this issue, run:
bin/rails db:environment:set RAILS_ENV=test
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:1259:in `last_stored_environment'
/home/rubys/git/rails/activerecord/lib/active_record/tasks/database_tasks.rb:48:in `check_protected_environments!'
/home/rubys/git/rails/activerecord/lib/active_record/railties/databases.rake:11:in `block (2 levels) in <top (required)>'
/home/rubys/git/rails/activerecord/lib/active_record/railties/databases.rake:375:in `block (3 levels) in <top (required)>'
/home/rubys/git/rails/railties/lib/rails/commands/rake_proxy.rb:13:in `block in run_rake_task'
/home/rubys/git/rails/railties/lib/rails/commands/rake_proxy.rb:10:in `run_rake_task'
/home/rubys/git/rails/railties/lib/rails/commands/commands_tasks.rb:51:in `run_command!'
/home/rubys/git/rails/railties/lib/rails/command.rb:20:in `run'
/home/rubys/git/rails/railties/lib/rails/commands.rb:19:in `<top (required)>'
bin/rails:4:in `require'
bin/rails:4:in `<main>'
Tasks: TOP => db:test:load => db:test:purge => db:check_protected_environments
(See full trace by running task with --trace)
/home/rubys/git/rails/activerecord/lib/active_record/migration.rb:578:in `check_pending!': (ActiveRecord::PendingMigrationError)
Migrations are pending. To resolve this issue, run:
bin/rails db:migrate RAILS_ENV=test
from /home/rubys/git/rails/activerecord/lib/active_record/migration.rb:591:in `load_schema_if_pending!'
from /home/rubys/git/rails/activerecord/lib/active_record/migration.rb:597:in `block in maintain_test_schema!'
from /home/rubys/git/rails/activerecord/lib/active_record/migration.rb:828:in `suppress_messages'
from /home/rubys/git/rails/activerecord/lib/active_record/migration.rb:602:in `method_missing'
from /home/rubys/git/rails/activerecord/lib/active_record/migration.rb:597:in `maintain_test_schema!'
from /home/rubys/git/rails/railties/lib/rails/test_help.rb:15:in `<top (required)>'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:302:in `require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:302:in `block in require'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:268:in `load_dependency'
from /home/rubys/git/rails/activesupport/lib/active_support/dependencies.rb:302:in `require'
from /home/rubys/git/awdwr/edition4/work-230/depot/test/test_helper.rb:3:in `<top (required)>'
from /home/rubys/git/awdwr/edition4/work-230/depot/test/controllers/carts_controller_test.rb:1:in `require'
from /home/rubys/git/awdwr/edition4/work-230/depot/test/controllers/carts_controller_test.rb:1:in `<top (required)>'
from /home/rubys/git/rails/railties/lib/rails/test_unit/test_requirer.rb:11:in `require'
from /home/rubys/git/rails/railties/lib/rails/test_unit/test_requirer.rb:11:in `block in require_files'
from /home/rubys/git/rails/railties/lib/rails/test_unit/test_requirer.rb:10:in `each'
from /home/rubys/git/rails/railties/lib/rails/test_unit/test_requirer.rb:10:in `require_files'
from /home/rubys/git/rails/railties/lib/rails/test_unit/minitest_plugin.rb:75:in `plugin_rails_init'
from /home/rubys/.rvm/gems/ruby-2.3.0@global/gems/minitest-5.8.3/lib/minitest.rb:74:in `block in init_plugins'
from /home/rubys/.rvm/gems/ruby-2.3.0@global/gems/minitest-5.8.3/lib/minitest.rb:72:in `each'
from /home/rubys/.rvm/gems/ruby-2.3.0@global/gems/minitest-5.8.3/lib/minitest.rb:72:in `init_plugins'
from /home/rubys/.rvm/gems/ruby-2.3.0@global/gems/minitest-5.8.3/lib/minitest.rb:123:in `run'
from /home/rubys/git/rails/railties/lib/rails/commands/test.rb:9:in `<top (required)>'
from /home/rubys/git/rails/railties/lib/rails/commands/commands_tasks.rb:138:in `require'
from /home/rubys/git/rails/railties/lib/rails/commands/commands_tasks.rb:138:in `require_command!'
from /home/rubys/git/rails/railties/lib/rails/commands/commands_tasks.rb:95:in `test'
from /home/rubys/git/rails/railties/lib/rails/commands/commands_tasks.rb:49:in `run_command!'
from /home/rubys/git/rails/railties/lib/rails/command.rb:20:in `run'
from /home/rubys/git/rails/railties/lib/rails/commands.rb:19:in `<top (required)>'
from bin/rails:4:in `require'
from bin/rails:4:in `<main>'