small medium large xlarge

Generic-user-small
01 Nov 2016, 18:59
Octave Antoni (3 posts)

Hi there, I just finished iteration J of the Depot app and I can’t pass the LineItem.count testing.

I’ve been trying to debug this for the last several hours and I can’t find a reason the test doesn’t pass, as everything is going well on my browser (I even tried a rails server -e test and it worked fine as well).

I completed the last part of the playtime (converting the currency from dollars to euros) by creating a CurrConverter class in the lib folder which defines a global variable called $eur_conversion which I call in my total price calculations (in my cart, product and line item models), and I think this may cause the errors. But I don’t want to just rollback to my latest commit without understanding what isn’t working.

Here are the failures I get :

~~~ Failure: LineItemsControllerTest#test_should_create_line_item_via_ajax [/vagrant/depot/test/controllers/line_items_controller_test.rb:29]:  "LineItem.count" didn't change by 1.
Expected: 3
Actual: 2
      bin/rails test test/controllers/line_items_controller_test.rb:28
~~~
~~~ Failure: LineItemsControllerTest#test_should_create_line_item [/vagrant/depot/test/controllers /line_items_controller_test.rb:19]:    LineItem.count" didn't change by 1.
Expected: 3
  Actual: 2
   bin/rails test test/controllers/line_items_controller_test.rb:18
~~~
~~~ Failure: UserStoriesTest#test_buying_a_product [/vagrant/depot/test/integration/user_stories_test.rb:24]:    Expected: 1
Actual: 0
  bin/rails test test/integration/user_stories_test.rb:13
~~~

Here are the relevant tests in my line_item_controller_test :

~~~ test "should create line_item" do
assert_difference('LineItem.count') do
  post line_items_url, params: { product_id: products(:ruby).id, locale: I18n.locale }
end
follow_redirect!
assert_select 'h2', 'Your Cart'
assert_select 'td', "Programming Ruby 1.9"       end
~~~
~~~   test "should create line_item via ajax" do
assert_difference('LineItem.count') do
  post line_items_url, params: { product_id: products(:ruby).id, locale: I18n.locale},
  xhr: true
end
assert_response :success
assert_select_jquery :html, '#cart' do
  assert_select 'tr#current_item td', /Programming Ruby 1.9/
end   end
~~~

Here are the relevant lines in my user_stories integration test :

~~~ start_order_count=Order.count 
  	ruby_book = products(:ruby)
  	get "/"
  	assert_response :success
  	assert_select 'h1', "Your Pragmatic Catalog"
  	post '/line_items', params: {product_id: ruby_book.id}, xhr: true
  	assert_response :success
  	cart = Cart.find(session[:cart_id])
  	assert_equal 1, cart.line_items.size
~~~

The latest line doesn’t pass the test

If this can help, when I looked into the test database, my line items have a “NIL” price column, which I can’t explain. When I add them from the browser however, they have a valid price.

I would greatly appreciate any help as this is slowing my advancement and I don’t want to just pass to the next topic without understanding what may have cause this.

Thanks in advance for your help,

Octave

You must be logged in to comment