Skip to content
Browse files

Add feature for javascript emulation

  * rails CSRF protection wipes the session when it triggers
  * to trigger it in cucumber we first enable it in test mode
    by changing config/environments/test.rb
  * we also need to make correct behaviour rely on the session being
    present, so we set up a before_filter
  * we need an action that configures the setup correctly:
    session/establish
  • Loading branch information...
1 parent cf6b2eb commit 6d8b2be295d16924765e31721a54da801b8f7bc0 @JonathonMA JonathonMA committed Aug 25, 2011
Showing with 54 additions and 0 deletions.
  1. +54 −0 features/emulate_javascript.feature
View
54 features/emulate_javascript.feature
@@ -32,3 +32,57 @@ Feature: Emulate Javascript
3 steps (3 passed)
"""
+ Scenario: Pass on the CSRF token
+ Given I have created a new Rails 3 app "widgets" with cucumber-rails support
+ And I successfully run `rails generate scaffold widget name:string`
+ And I successfully run `sed -i -e 's/forgery_protection *= false/forgery_protection = true/' config/environments/test.rb`
+ And I successfully run `rails generate controller session establish`
+ And I write to "app/controllers/session_controller.rb" with:
+ """
+ class SessionController < ApplicationController
+ def establish
+ session[:verified] = true
+ end
+ end
+ """
+ And I write to "app/controllers/application_controller.rb" with:
+ """
+ class ApplicationController < ActionController::Base
+ protect_from_forgery
+ before_filter :except => :establish do
+ render :text => "denied", :status => :forbidden and return false unless session[:verified]
+ end
+ end
+ """
+ And I write to "features/f.feature" with:
+ """
+ Feature: Widget inventory
+ Scenario: Delete a widget
+ Given there is a widget named "wrench"
+ When I go to the session establish page
+ And I go to the widgets page
+ Then I should see "wrench"
+ When I follow "Destroy"
+ Then I should not see "denied"
+ And I should be on the widgets page
+ And I should not see "wrench"
+ """
+ And I write to "features/step_definitions/s.rb" with:
+ """
+ Given /^there is a widget named "([^"]*)"$/ do |name|
+ Factory(:widget, :name => name)
+ end
+ """
+ And I write to "features/support/factories.rb" with:
+ """
+ Factory.define :widget do |f|
+ f.name 'testwidget'
+ end
+ """
+ When I run `bundle exec rake db:migrate`
+ And I run `bundle exec rake cucumber`
+ Then it should pass with:
+ """
+ 1 scenario (1 passed)
+ 8 steps (8 passed)
+ """

0 comments on commit 6d8b2be

Please sign in to comment.
Something went wrong with that request. Please try again.