Testing fake-safe controller methods in Rails

I am trying to test the method that I have in my application, but I do not know how the unit test method, which is protected from fake, look at this:

    def index
    @alumnos = Alumno.paginate :per_page => 20, 
      :page => params[:page], :order => :nombre

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @alumnos }
    end
  end

In index.html.erb, I have this line:

<%= javascript_tag "window._token = '#{form_authenticity_token}'" %>

So, when I try to test it with a functional test, it seems that the session does not have secret work that will lead to the test failing, can anyone try these methods?

+3
source share
1 answer

Here is one solution (or workaround): in your controllers /application.rb

   if RAILS_ENV =='test'
    protect_from_forgery  :secret => 'write ur secret in config/environment.rb'

  else

protect\_from_forgery

  end
+1
source

All Articles