Gmail Calendar Documents Reader Web more »
Recently Visited Groups | Help | Sign in
Google Groups Home
functional testing with form_authenticity_token
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  3 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Greg  
View profile  
 More options Feb 28 2008, 5:21 pm
From: Greg <glhew...@gmail.com>
Date: Thu, 28 Feb 2008 14:21:36 -0800 (PST)
Local: Thurs, Feb 28 2008 5:21 pm
Subject: functional testing with form_authenticity_token
hello,

I am building a page that has many ajax calls on the page, so when I
moved to rails 2.0, I, of course, noticed that my ajax calls stopped
working.  After some research, I came up with the following solution.

I create a <div id="authenticity_token"><%= form_authenticity_token
%></div> at the bottom of my document, so that I could easily grab the
value with javascript and include it in my ajax calls  This worked
great, btw.

The problem comes when I am trying to write functional tests for the
these pages.  For example, the following code:

def test_view_not_logged_in
  get :view, :id =>  users(:quentin).id
  assert_response :success
end

Creates the following error:

ActionView::TemplateError: No :secret given to the
#protect_from_forgery call.  Set that or use a session store capable
of generating its own keys (Cookie Session Store).
    On line #39 of account/_signup_form.rhtml

    36:   </div>
    37:   <a href="javascript:showNewImage()">Try a different image </
a>
    38:   <% end -%>
    39:   <div id="form_authenticity_token" class="hidden"><%=
form_authenticity_token %></div>

I am using the Cookie Session Store in my development and production
environements.  Is there any difference in the test environment?  I
could add the :secret when I do testing, but that is pretty
cumbersome.

thanks in advance for any help!

Greg


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Greg  
View profile  
 More options Feb 28 2008, 5:36 pm
From: Greg <glhew...@gmail.com>
Date: Thu, 28 Feb 2008 14:36:42 -0800 (PST)
Local: Thurs, Feb 28 2008 5:36 pm
Subject: Re: functional testing with form_authenticity_token
Following up on my own post....

I guess that I need to make sure that forgery is turned on:

<% if protect_against_forgery? %>
<div id="authenticity_token"><%= form_authenticity_token %></div>
<% end %>

The test environment turns it off.

On Feb 28, 4:21 pm, Greg <glhew...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tiago Macedo  
View profile  
 More options May 23 2008, 1:10 pm
From: Tiago Macedo <tmac...@webreakstuff.com>
Date: Fri, 23 May 2008 18:10:08 +0100
Local: Fri, May 23 2008 1:10 pm
Subject: Re: [Rails] Re: functional testing with form_authenticity_token
Hi,

Unfortunately I also came into this bug so I created a patch and
submitted it to lighthouse:
http://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/24...

It doesn't merge correctly into 2.0.1, only edge.

Tiago Macedo


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2009 Google