Skip to content

Instantly share code, notes, and snippets.

@igal
Created April 18, 2010 16:07
Show Gist options
  • Save igal/370310 to your computer and use it in GitHub Desktop.
Save igal/370310 to your computer and use it in GitHub Desktop.
# Tell controller not to check for authenticity token:
Rails.configuration.action_controller.allow_forgery_protection = false
# Create a session:
app = ActionController::Integration::Session.new
# Setup parameters from log:
params = {"start_date"=>"2010-04-15", "end_date"=>"2010-04-15", "commit"=>"Create", "event"=>{"title"=>"Brain Silo Hackfest/Open House", "url"=>"http://brainsilo.org", "venue_id"=>"202392003", "description"=>"The silo is open to any interested parties who want to hack or just check out the space during the welcome meeting. <b>This is an Open House meeting</b>\r\n\r\nNOTE: The entrance for the space is on the backside of the building in the alley -- NOT at the mailing address. See this satellite view for clarification: http://bit.ly/8Arvpt\r\n\r\nThe outside door is at the top of a set of stairs. The space is marked with a small sticker that is labeled \"BrainSilo\"\r\n", "tag_list"=>"brainsilo, hackfest"}, "venue_name"=>"bRainSilo", "trap_field"=>"", "start_time"=>"07:00 PM", "end_time"=>"08:00 PM"}
# Remove the authenticity token, because if it's listed, it'll be checked:
params.delete "authenticity_token"
# Try to invoke the controller method EventsController#create with the given parameters:
puts app.post '/events', params
# If run via "script/runner", the above fails with a 422 error, likely because of the authenticity token.
# If run via "script/console", the above fails with this error:
### ThreadError Exception: thread 0x8212138 tried to join itself
# And this error is likely this Rails 2.3.x bug:
### https://rails.lighthouseapp.com/projects/8994/tickets/3153-actioncontrollerintegrationsession-broken-in-234
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment