#98 open
Chad Humphries

[#11834] Fake Controller Flash object

Reported by Chad Humphries | November 19th, 2007 @ 06:04 AM

Currently it is difficult to test the values on Flash.now, because the Flash.sweep is called during the process action.

We made a Fake Flash Hash object that collects the flash content and does not sweep it when the request is processed.

Comments and changes to this ticket

  • Chad Humphries

    Chad Humphries February 19th, 2008 @ 09:16 PM

    Date: 2007-06-27 02:38

    Sender: Brian Takita

    Mainly, it was Nathan Wilmes who developed this. It is very

    bare bones, and meant for primarily collecting value.

    class MockFlashHash
      def initialize
        @hash = {}
        @now_hash = {}
      end
    
      def [](key)
        @hash[key]
      end
    
      def []=(key, obj)
        @hash[key] = obj
      end
    
      def discard(k = nil)
        initialize
      end
    
      def now
        @now_hash
      end
    
      def update(hash)
        @hash.update(hash)
      end
    
      def sweep
        # This is the key.  We don't really want flash.now's to
    go away.
      end
    end
    

    Date: 2007-06-26 03:02

    Sender: Aslak Hellesøy

    What does it look like?

  • linoj

    linoj January 17th, 2008 @ 03:31 AM

    Where would i put this code if i want to use it?

  • Artūras Šlajus

    Artūras Šlajus February 19th, 2008 @ 07:49 PM

    Why isn't this fixed yet? :(

  • David Chelimsky

    David Chelimsky February 19th, 2008 @ 09:10 PM

    • → State changed from “new” to “open”

    Why haven't you submitted a patch yet?

  • David Chelimsky

    David Chelimsky February 19th, 2008 @ 09:17 PM

    OK - I see that there is a suggested implementation here. But there are no specs for it.

    This is not high priority in my view, but if someone wants to submit a patch with specs, I'll be glad to take a look.

  • Brian Takita

    Brian Takita February 20th, 2008 @ 06:05 AM

    I'll get this one checked in w/ specs.

  • Xavier Shay

    Xavier Shay April 19th, 2008 @ 02:35 AM

    a cleaner way , IMO. Not sure how/if to bake this into rspec_on_rails.

    The summary:

    # spec/spec_helper.rb
    module DisableFlashSweeping
      def sweep
      end
    end
    
    # A spec
    describe BogusController, "handling GET to #index" do
      it "sets flash.now[:message]" do
        @controller.instance_eval { flash.extend(DisableFlashSweeping) }
        get :index
        flash.now[:message].should_not be_nil
      end
    end
    

Please Login or create a free account to add a new comment.

You can update this ticket by sending an email to from your email client. (help)

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

Behaviour Driven Development for Ruby.

Shared Ticket Bins