8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price
13 (tests|runs), 37 assertions, 0 failures, 0 errors. <0> expected to be >= <1>. Traceback: /home/rubys/git/awdwr/edition4/checkdepot.rb:36:in `assert_test_summary' /home/rubys/git/awdwr/edition4/checkdepot.rb:128:in `block in <class:DepotTest>'
Demonstrate use of assert_select to test views.
Verify that the tests still pass.
rake 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 rescue in <class:Exception> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/web-console-2.1.2/lib/web_console/integration/cruby.rb:37)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in <top (required)> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/web-console-2.1.2/lib/web_console/extensions.rb:18)
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-head-n50123/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:7)
Run options: --seed 50814
# Running:
DEPRECATION WARNING: before_filter is deprecated and will be removed in Rails 5.1. Use before_action instead. (called from block (3 levels) in <class:Engine> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/turbolinks-2.5.3/lib/turbolinks.rb:14)
DEPRECATION WARNING: after_filter is deprecated and will be removed in Rails 5.1. Use after_action instead. (called from block (3 levels) in <class:Engine> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/turbolinks-2.5.3/lib/turbolinks.rb:15)
..E...E......
Finished in 0.329021s, 39.5112 runs/s, 97.2583 assertions/s.
1) Error:
ProductsControllerTest#test_should_create_product:
ActionController::ParameterMissing: param is missing or the value is empty: product
app/controllers/products_controller.rb:79:in `product_params'
app/controllers/products_controller.rb:27:in `create'
test/controllers/products_controller_test.rb:34:in `block (2 levels) in <class:ProductsControllerTest>'
test/controllers/products_controller_test.rb:32:in `block in <class:ProductsControllerTest>'
2) Error:
ProductsControllerTest#test_should_update_product:
ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"products", :description=>"Wibbles are fun!", :image_url=>"lorem.jpg", :price=>"19.95", :title=>"Lorem Ipsum"}
test/controllers/products_controller_test.rb:57:in `block in <class:ProductsControllerTest>'
13 runs, 32 assertions, 0 failures, 2 errors, 0 skips
Failed tests:
bin/rails test /home/rubys/git/awdwr/edition4/work-220/depot/test/controllers/products_controller_test.rb:31
bin/rails test /home/rubys/git/awdwr/edition4/work-220/depot/test/controllers/products_controller_test.rb:55
Add tests for layout, product display, and formatting, using counts, string comparisons, and regular expressions.
edit test/controllers/store_controller_test.rb
require 'test_helper'
class StoreControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_select '#columns #side a', minimum: 4
assert_select '#main .entry', 3
assert_select 'h3', 'Programming Ruby 1.9'
assert_select '.price', /\$[,\d]+\.\d\d/
end
end
Review fixure data
edit test/fixtures/products.yml
# Read about fixtures at
# http://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
one:
title: MyString
description: MyText
image_url: MyString
price: 9.99
two:
title: MyString
description: MyText
image_url: MyString
price: 9.99
ruby:
title: Programming Ruby 1.9
description:
Ruby is the fastest growing and most exciting dynamic
language out there. If you need to get working programs
delivered fast, you should add Ruby to your toolbox.
price: 49.50
image_url: ruby.png
Show that the tests pass.
rake test:controllers
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from rescue in <class:Exception> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/web-console-2.1.2/lib/web_console/integration/cruby.rb:37)
DEPRECATION WARNING: alias_method_chain is deprecated. Please, use Module#prepend instead. From module, you can access the original method using super. (called from block in <top (required)> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/web-console-2.1.2/lib/web_console/extensions.rb:18)
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-head-n50123/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:7)
Run options: --seed 9131
# Running:
DEPRECATION WARNING: before_filter is deprecated and will be removed in Rails 5.1. Use before_action instead. (called from block (3 levels) in <class:Engine> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/turbolinks-2.5.3/lib/turbolinks.rb:14)
DEPRECATION WARNING: after_filter is deprecated and will be removed in Rails 5.1. Use after_action instead. (called from block (3 levels) in <class:Engine> at /home/rubys/.rvm/gems/ruby-head-n50123/gems/turbolinks-2.5.3/lib/turbolinks.rb:15)
E...E...
Finished in 0.133733s, 59.8207 runs/s, 97.2087 assertions/s.
1) Error:
ProductsControllerTest#test_should_update_product:
ActionController::UrlGenerationError: No route matches {:action=>"update", :controller=>"products", :description=>"Wibbles are fun!", :image_url=>"lorem.jpg", :price=>"19.95", :title=>"Lorem Ipsum"}
test/controllers/products_controller_test.rb:57:in `block in <class:ProductsControllerTest>'
2) Error:
ProductsControllerTest#test_should_create_product:
ActionController::ParameterMissing: param is missing or the value is empty: product
app/controllers/products_controller.rb:79:in `product_params'
app/controllers/products_controller.rb:27:in `create'
test/controllers/products_controller_test.rb:34:in `block (2 levels) in <class:ProductsControllerTest>'
test/controllers/products_controller_test.rb:32:in `block in <class:ProductsControllerTest>'
8 runs, 13 assertions, 0 failures, 2 errors, 0 skips
Failed tests:
bin/rails test /home/rubys/git/awdwr/edition4/work-220/depot/test/controllers/products_controller_test.rb:55
bin/rails test /home/rubys/git/awdwr/edition4/work-220/depot/test/controllers/products_controller_test.rb:31
8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price