README

Path: README
Last Update: Thu Jan 17 13:22:05 -0600 2008

Flashback

Calling flashback in your functional test sometime after the TestRequest is instantiated and before your first call to an action, will allow you to access the discarded flash variables (those that were flashed) during the request processing. Specifically, it will allow you to access the Flash.now variables by name.

You will access these discarded variables similar to how you would access them in Flash.now, but this time via a flashed method. For example:

  class FooController < ApplicationController
    def create
      ...
      flash.now[:error] = 'Whoops!' unless params[:foo][:baz]
      ...
    end
  end

  class FooControllerTest < ActionController::TestCase
    def test_create_should_set_some_flash_now_variable
      flashback
      get :create, :foo => {:bar => 'hello'}
      assert_equal 'Whoops!', flash.flashed[:error]
    end
  end

What you will not have access to via flashed are the normal, inter-request Flash variables. This is because Flashback is only tracking those flash variables that are discarded during the transaction, which includes all variables passed through Flash.now.

If you want flashed available all of the time, then simply call flashback in the setup method of your TestCase. There are likely better ways that I hope someone will tell me about, but I just wanted to get this plugin out-the-door.

The only caveat to Flashback is that if you define your own Flash instance and pass that to your various process methods (get, post, head, etc.), your flash will override Flashback‘s, rendering it useless.

Installation

 ./script/plugin install http://glomp.rubyforge.org/svn/plugins/flashback

Notes

I built this plugin using Ruby 1.8.6 on Rails 2.0. It will likely work for Rails 1.2, but it has not been tested.

Acknowledgements

If no one else, then DHH

Contact

Justin Knowlden <justin@goglomp.net>

License

Copyright (c) 2008 Justin Knowlden, released under the MIT license

See MIT-LICENSE for more detail

[Validate]