Agile Web Development with Rails, Edition 4

8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price

8.4 Iteration C4: Functional Testing

13 (tests|runs), 37 assertions, 0 failures, 0 errors.
<0> expected to be
>=
<1>.

Traceback:
  /home/rubys/git/awdwr/edition4/checkdepot.rb:38:in `assert_test_summary'
  /home/rubys/git/awdwr/edition4/checkdepot.rb:136:in `block in <class:DepotTest>'

Demonstrate use of assert_select to test views.

Verify that the tests still pass.

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)
Run options: --seed 5044
 
# 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-2.3.0/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-2.3.0/gems/turbolinks-2.5.3/lib/turbolinks.rb:15)
F
 
Failure:
ProductsControllerTest#test_should_create_product:
"Product.count" didn't change by 1.
Expected: 4
  Actual: 3
 
bin/rails test test/controllers/products_controller_test.rb:19
 
...F
 
Failure:
ProductsControllerTest#test_should_update_product:
Expected response to be a <3XX: redirect>, but was a <200: OK>
 
bin/rails test test/controllers/products_controller_test.rb:38
 
........
 
Finished in 0.374627s, 34.7012 runs/s, 88.0877 assertions/s.
 
13 runs, 33 assertions, 2 failures, 0 errors, 0 skips

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 < ActionDispatch::IntegrationTest
  test "should get index" do
    get store_index_url
    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 included at /home/rubys/.rvm/gems/ruby-2.3.0/gems/turbolinks-2.5.3/lib/turbolinks/xhr_url_for.rb:7)
Run options: --seed 40702
 
# 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-2.3.0/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-2.3.0/gems/turbolinks-2.5.3/lib/turbolinks.rb:15)
.F
 
Failure:
ProductsControllerTest#test_should_create_product:
"Product.count" didn't change by 1.
Expected: 4
  Actual: 3
 
bin/rails test test/controllers/products_controller_test.rb:19
 
....F
 
Failure:
ProductsControllerTest#test_should_update_product:
Expected response to be a <3XX: redirect>, but was a <200: OK>
 
bin/rails test test/controllers/products_controller_test.rb:38
 
.
 
Finished in 0.254612s, 31.4204 runs/s, 54.9856 assertions/s.
 
8 runs, 14 assertions, 2 failures, 0 errors, 0 skips

8.5 Iteration C5 - Caching 8.3 Iteration C3: Use a Helper to Format the Price