09 Jun 2010, 07:06
Samr_small_pragsmall

Sam Ruby (584 posts)

Ruby put out a new preview; this is the version to use if you want to try out the new goodies in Ruby 1.9.2. There are definitely problems with prior versions of 1.9.2 and even 1.9.1, but to date I’ve not seen any with this preview.

Rails put out a new beta; the only change required is that when you are creating a new application, e.g. depot, you type rails new depot instead of simply rails depot.

16 Jun 2010, 09:03
Generic-user-small

Manuel Korfmann (3 posts)

I installed rails 3.0.0.beta4 and then tried to run the tests in the downloaded code/depot_m folder and got some weird errors:

Manuel-Korfmanns-MacBook-Pro:depot_o mkorfmann$ rake test
(in /Users/mkorfmann/projects/code/depot_o)
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
.........
Finished in 0.111852 seconds.

9 tests, 30 assertions, 0 failures, 0 errors
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
...............F...F.F.........
Finished in 0.804792 seconds.

  1) Failure:
test_should_create_order(OrdersControllerTest) [/test/functional/orders_controller_test.rb:28]:
"Order.count" didn't change by 1.
<3> expected but was
<2>.

  2) Failure:
test_should_get_new(OrdersControllerTest) [/test/functional/orders_controller_test.rb:24]:
Expected response to be a <:success>, but was <302>

  3) Failure:
test_should_update_order(OrdersControllerTest) [/test/functional/orders_controller_test.rb:47]:
Expected response to be a <:redirect>, but was <200>

31 tests, 49 assertions, 3 failures, 0 errors
Errors running test:functionals!
Manuel-Korfmanns-MacBook-Pro:depot_o mkorfmann$ cd ../depot_m
Manuel-Korfmanns-MacBook-Pro:depot_m mkorfmann$ rake test
(in /Users/mkorfmann/projects/code/depot_m)
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
........
Finished in 0.109409 seconds.

8 tests, 29 assertions, 0 failures, 0 errors
Loaded suite /Library/Ruby/Gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
...E...F.EEEE....EEEE..
Finished in 0.606231 seconds.

  1) Error:
test_should_get_index(CartsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    app/controllers/carts_controller.rb:15:in `index'
    /test/functional/carts_controller_test.rb:17:in `test_should_get_index'

  2) Failure:
test_should_create_line_item(LineItemsControllerTest) [/test/functional/line_items_controller_test.rb:32]:
Expected response to be a redirect to <http://test.host/carts/980190963> but was a redirect to <http://test.host/>.

  3) Error:
test_should_get_edit(LineItemsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    /test/functional/line_items_controller_test.rb:41:in `test_should_get_edit'

  4) Error:
test_should_get_index(LineItemsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    app/controllers/line_items_controller.rb:15:in `index'
    /test/functional/line_items_controller_test.rb:17:in `test_should_get_index'

  5) Error:
test_should_get_new(LineItemsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    app/controllers/line_items_controller.rb:37:in `new'
    /test/functional/line_items_controller_test.rb:23:in `test_should_get_new'

  6) Error:
test_should_show_line_item(LineItemsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    app/controllers/line_items_controller.rb:26:in `show'
    /test/functional/line_items_controller_test.rb:36:in `test_should_show_line_item'

  7) Error:
test_should_get_edit(ProductsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    /test/functional/products_controller_test.rb:48:in `test_should_get_edit'

  8) Error:
test_should_get_index(ProductsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    app/controllers/products_controller.rb:15:in `index'
    /test/functional/products_controller_test.rb:24:in `test_should_get_index'

  9) Error:
test_should_get_new(ProductsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    app/controllers/products_controller.rb:37:in `new'
    /test/functional/products_controller_test.rb:30:in `test_should_get_new'

 10) Error:
test_should_show_product(ProductsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:21
    app/controllers/products_controller.rb:26:in `show'
    /test/functional/products_controller_test.rb:43:in `test_should_show_product'

23 tests, 26 assertions, 1 failures, 9 errors

</code>

I used the downloaded depot app and got this. What’s gone wrong here?

16 Jun 2010, 12:49
Samr_small_pragsmall

Sam Ruby (584 posts)

Short answer: you won’t see those problems if you follow the instructions in the book.

Longer answer: Rails 3.0 is evolving quickly. Rails applications consist of a mixture of generated code and user authored application code. I am tracking it closely, and don’t believe that there are any changed needed to the user authored application code due to changes in Rails between beta 3 and beta 4. I haven’t been tracking running Rails beta 3 generated code against Rails beta 4. This is not supported and doesn’t surprise me that it doesn’t work.

Note: what you downloaded may not exactly match beta 3. In order to converge on where Rails is heading, I track and continuously test against the latest (unreleased) version of Rails at all times.

At the present time, my tests are green for edition 4 with the exception of running tests against Ruby 1.9.3 (under development despite the fact that Ruby 1.9.2 isn’t even released yet).

24 Jul 2010, 16:15
04-08-07_1722_pragsmall

Kristan Uccello (1 post)

Hi Sam,

Your short answer is incorrect. I followed along in the book (only exception is that I am using rvm) and got the same errors for the product test cases

“Product.count” didn’t change by 1. <3> expected but was <2>.

and

Expected response to be a , but was <200>

(B5 pdf edition - Pg 93/94)

I did notice however, that running the tests against depot_c - there were no errors shown in the test results.

Anyway, I just wanted to point out that Manuel is not the only one having this issue.

Regards,

24 Jul 2010, 19:09
Samr_small_pragsmall

Sam Ruby (584 posts)

Kristan - the error you are seeing is different than the one that Manuel reported. In your case, Product.count did not change and you don’t (as of yet) even have an Order model. In Manuel’s case, he has both models and Product.count did change but Order.count did not.

Any possibility of you posting your test/functional/products_controller_test.rb file online somewhere (possibly here?)

P.S. Thanks for entering an errata. This helps me track the issue.

19 Feb 2011, 17:37
Generic-user-small

Christina Shannon (1 post)

Am having the following problem - driving me crazy - can’t get past it, would be delighted with some help!!

NoMethodError in Products#new

Showing C:/Documents and Settings/cshannon.WEB2/My Documents/NetBeansProjects/beauty_1_3_1/app/views/layouts/application.html.erb where line #23 raised:

undefined method `model_name’ for NilClass:Class

Extracted source (around line #23):

20: <div id="columns" > 21: <div id="side" > 22: <div id="cart" > 23: <%= render @cart %> 24: </div> 25: 26: Home

Rails.root: C:/Documents and Settings/cshannon.WEB2/My Documents/NetBeansProjects/beauty_1_3_1 Application Trace | Framework Trace | Full Trace

app/views/layouts/application.html.erb:23:in _app_views_layouts_application_html_erb___1484348038_2120_0' app/controllers/products_controller.rb:30:in new’

07 Jun 2011, 01:10
Fotos diciembre - enero 030_pragsmall

Martin Hermosilla G. (2 posts)

Hi Sam,

First I am little off topic because I am using Rails 3.0.7 and Ruby 1.8.7 on Mac OS X. 10.6.7

Does Kristan solved his error on Iteration B1: Validating test issue. I am facing the same thing. I am writing the code as I read the book, then I have added the @update code and the two other insertion points… and still got the errors there

1) Failure: test_should_create_product(ProductsControllerTest) [test/functional/products_controller_test.rb:26]: “Product.count” didn’t change by 1. <3> expected but was <2>.

2) Failure: test_should_update_product(ProductsControllerTest) [test/functional/products_controller_test.rb:45]: Expected response to be a , but was <200>

Regards,

-Martin

22 Aug 2011, 00:13
Duccioarmenise_pragsmall

Duccio Armenise - P.IVA 01360060113 (1 post)

Dear Sirs,

I am using Rails 3.0.7 and Ruby 1.8.7 (my environment is from railsinstaller.org for Windows). I am reading the 4th edition, all tests are green since page 143: as soon as I begin rendering _cart.html.erb partial from application.html.erb I get the same 9 error messages as Manuel Korfmann’s.

$ rake test:functionals
(in C:/Sites/rails_projects/depot)
Loaded suite c:/RailsInstaller/Ruby1.8.7/lib/ruby/gems/1.8/gems/rake-0.8.7/lib/rake/rake_test_loader
Started
...E.....EEEE...EEEE..
Finished in 3.089 seconds.

  1) Error:
test_should_get_index(CartsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:22:in `_app_views_layouts_application_html_erb___889148870_49855668_0'
    app/controllers/carts_controller.rb:7:in `index'
    /test/functional/carts_controller_test.rb:11:in `test_should_get_index'

  2) Error:
test_should_get_edit(LineItemsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:22:in `_app_views_layouts_application_html_erb___889148870_49855668_0'
    /test/functional/line_items_controller_test.rb:33:in `test_should_get_edit'

  3) Error:
test_should_get_index(LineItemsControllerTest):
ActionView::Template::Error: undefined method `model_name' for NilClass:Class
    app/views/layouts/application.html.erb:22:in `_app_views_layouts_application_html_erb___889148870_49855668_0'
    app/controllers/line_items_controller.rb:7:in `index'
    /test/functional/line_items_controller_test.rb:9:in `test_should_get_index'

  [...]

22 tests, 23 assertions, 0 failures, 9 errors

</code>

The problem is clearly related to app/views/layouts/application.html.erb:22 which is:

[..]
<div id="side">
      <div id="cart">
22:->   <%= render @cart %>
      </div>
[...]

</code>

It seems as if @cart variable weren’t properly initialized in app/controllers/store_controller.rb, but here’s mine:

class StoreController < ApplicationController
  def index
    @products = Product.all
    @cart = current_cart
    if store_index_view_count >= 5
      @store_index_view_count = store_index_view_count
    end
  end
end

</code>

Any clue?

EDIT

I found a fix to make tests go all green again! I simply added this line 9 times to every failing action: ~~~ @cart = current_cart ~~~ </code>

Surely this ain’t the optimum solution since the problem were the tests, not the controllers. Anyway it helped me to get out of stuck.

EDIT#2

I guess I finally understood real problem and found the real solution. The errors where due to controller actions rendering application.html.erb without initializing @cart instance variable. But this was due to the fact that those action didn’t need to render the current_cart to work. So, as written on page 155, the solution simply consist to render @cart in application.html.erb only against the condition that @cart is initialized, like this:

[...]
<div id="side">
   <% if @cart %>
      <div id="cart">
         <%= render @cart %>
      </div>
   <% end %>
[...]

</code>

30 Apr 2012, 14:57
Generic-user-small

Robert W Karlsson (2 posts)

If you are getting the “Order.count did not change..” and “Expected response…” errors - Check your test fixtures and make sure spelling and case are correct.

In my case I had “check” instead of “Check” in my orders.yml

23 May 2012, 12:34
Generic-user-small

John ma (1 post)

Thank

22 Jun 2012, 23:31
Me_pragsmall

Andrew Gellene (33 posts)

Like Robert. I had a spelling error in fixtures… thanks Robert

18 Jul 2012, 00:34
Avatar_pragsmall

Christopher Lawrence (1 post)

I was getting the same two “Order.count” and “Expected response” errors after I put the payment types into a database (Chapter 12 Playtime #3)

The fix was to change the fixture data from pay_type: Check to pay_type_id: 1, as this was how I was passing the data through in my view.

  You must be logged in to comment