title: Cucumber + Capybara testing: AJAX RequestForgeryProtection trouble since Rails 4.1
body: <p>After updating to Rails 4.1, I got an interesting problem with Cucumber and Capybara in a new project.</p>
  
  <p>Inside a view I placed some thumbnail portraits. The user is supposed to click on a thumbnail image link to receive more information about the person he has chosen.  Through the magic of AJAX the information then appears below the thumbnails.  Here's how i did it in the view:</p>
  
  <pre><code>&lt;%= link_to( image_tag( ... ), "/controller/action.js&amp;person=#{@person.nickname}", id: @person.thumb_id , remote: true) %
  </code></pre>
  
  <p>The controller follows the usual proceeding for cases like this with </p>
  
  <pre><code>respond_to do format.js end
  </code></pre>
  
  <p>etc. </p>
  
  <p>Works perfectly in the browser and I love it.</p>
  
  <p>However, Cucumber and Capybara don't work so smoothly. Here's the Capybara line that's giving me a lot of headache:</p>
  
  <pre><code>When(/^I click on one of the portraits to display the person's stuff$/) do
    click_link("jack_sparrow_THUMB") # @user.thumb_id
  end
  </code></pre>
  
  <p>Running the scenario with Cucumber, I receive this error message for the statement above: </p>
  
  <pre><code>Security warning: an embedded &lt;script&gt; tag on another site requested protected 
  JavaScript. If you know what you're doing, go ahead and disable forgery protection 
  on this action to permit cross-origin JavaScript embedding.
  (ActionController::InvalidCrossOriginRequest)
  </code></pre>
  
  <p>The problem must have to do with this</p>
  
  <p><a href="http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html" rel="nofollow">http://api.rubyonrails.org/classes/ActionController/RequestForgeryProtection.html</a></p>
  
  <p>Just have a look at the CROSS_ORIGIN_JAVASCRIPT_WARNING provided ... :(</p>
  
  <p>Is there anything I can do to make my tests run again without downgrading to rails &lt; 4.1 or even turning off Request Forgery Protection in general?  Help would be very much appreciated.</p>