Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I had exactly the same issue following the same Ajax section of Chapter 11 in the RailsTutorial(with Rails 3.2). I think Michael de Silva was right in that the xhr were unfortunately mixed with the RSpec here. </p> <p>Anyways, I decided that for the sake of completeness (I'm almost done with the tutorial) - I was going to get xhr to somehow work here. I think Mike Hartl's Listing 11.37 should have used the ActionDispatcher::Integration::RequestHelpers method xhr, as in <a href="http://api.rubyonrails.org/classes/ActionDispatch/Integration/RequestHelpers.html#method-i-xhr" rel="nofollow">http://api.rubyonrails.org/classes/ActionDispatch/Integration/RequestHelpers.html#method-i-xhr</a></p> <p>rather than the ActionController::TestCase::Behavior method xhr, as in <a href="http://api.rubyonrails.org/classes/ActionController/TestCase/Behavior.html#method-i-xhr" rel="nofollow">http://api.rubyonrails.org/classes/ActionController/TestCase/Behavior.html#method-i-xhr</a></p> <p>So I replaced the reference to actions :create and :destroy with their named routes and the test examples in Listing 11.37 turned green. The original</p> <pre><code>expect do xhr :post, :create, relationship: { followed_id: other_user.id } end.to change(Relationship, :count).by(1) </code></pre> <p>becomes,</p> <pre><code>expect do xhr :post, relationships_path, relationship: { followed_id: other_user.id } end.to change(Relationship, :count).by(1) </code></pre> <p>and, the original</p> <pre><code>expect do xhr :delete, :destroy, id: relationship.id end.to change(Relationship, :count).by(-1) </code></pre> <p>becomes,</p> <pre><code>expect do xhr :delete, relationship_path(relationship.id), id: relationship.id end.to change(Relationship, :count).by(-1) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload