small medium large xlarge

Generic-user-small
25 May 2012, 18:38
Carlos Rodrigues (2 posts)

Hi.

I’m following the book for Rails 3.2. Section 11.6 asks you to use the following code to test tha Ajax functionality.

  test "should create line_item via ajax" do
    assert_difference('LineItem.count') do
        xhr :post, :create, :product_id => products( :ruby ).id
    end

    assert_response :success
    assert_select_jquery :html, '#cart' do
        assert_select 'tr#current_item td', /Programming Ruby 1.9/
    end
  end

When I run the tests, I get:

  1) Failure:
test_should_create_line_item_via_ajax(LineItemsControllerTest) [/home/carlosr/Own/Dropbox/Devel/Rails/awdr3/depot/test/functional/line_items_controller_test.rb:34]:
No JQuery call matches [:html, "#cart"]

I’m using Rails 3.2.3 with jquery-rails 2.0.2

Img_0118_pragsmall
09 Oct 2012, 06:14
Steve Loveless (1 post)

I’m seeing the same thing with Rails 3.2.8 and query-rails 2.1.3. Ever figure this one out?

Generic-user-small
08 Nov 2012, 13:52
Jack Chen (2 posts)

Helly guys, Please check that in file app/views/line_items/create.js.erb, it is $('#cart').html("<%= escape_javascript(render(@cart)) %>"); not $('#cart').html('<%= escape_javascript(render(@cart)) %>'); I find that assert_select_jquery:https://github.com/rails/jquery-rails/blob/master/lib/jquery/assert_select.rb doesn’t allow html string begin with ‘.

  You must be logged in to comment