#68 new
Fernando Blat

Testing fragment/action cache to be generated or expired

Reported by Fernando Blat | September 6th, 2008 @ 10:50 AM

Hi,

I have beeing adding some methods for testing that action cache is generated or expired, and the same with fragment cache in functional tests.

I attach a patch with the methods added to lib/shoulda/controller/helpers.rb, but I don't know if you consider that the best place. I did this because I needed instance methods.

I added also a new cache storage engine at lib/shoulda/test_store.rb

Also you can find some tests in posts_controller_test.rb and the new tags_controller_test.rb

Take a look if you find this useful :)

I have a GitHub branch for it, too: http://github.com/ferblape/shoul...

Cheers

Comments and changes to this ticket

  • Tammer Saleh

    Tammer Saleh September 10th, 2008 @ 09:30 AM

    • → Assigned user cleared.

    Hi Fernando,

    This looks like a really useful addition to shoulda, but I have a couple of questions about the patch.

    Can we do without the call to ActionController::Base.cache_store.clear that's in each setup block? Not only do the setup blocks get called all the time, but we're aiming soon to convert Shoulda to a gem so that it's useable outside of rails projects.

    Running rake produces the following warnings:

      * WARNING: 'test: Logged in viewing posts for a user should respond with success. ' is already defined
      * WARNING: 'test: Logged in viewing posts for a user should assign @user. ' is already defined
      * WARNING: 'test: Logged in viewing posts for a user should assign @posts. ' is already defined
      * WARNING: 'test: Logged in viewing posts for a user should not assign to @foo. ' is already defined
      * WARNING: 'test: Logged in viewing posts for a user should not assign to @bar. ' is already defined
    

    And finally, is it possible to do away with the "map.connect ':controller/:action/:id'" route in the test suite? I worry that this catch-all route could hide future failures in the tests.

    Thanks for the help, Tammer

  • Fernando Blat

    Fernando Blat September 10th, 2008 @ 11:44 AM

    Hi!

    I'm attaching a new patch that:

    • only clears cache if is defined ActionController and if perform_caching is true

    • corrects all the warnings

    • avoids the default route and creates a new resource :tags

    Thanks for the interest!

  • Tammer Saleh

    Tammer Saleh September 10th, 2008 @ 12:40 PM

    This is a good direction, but I really still don't like that kind of platform specific code being in the setup method at all. It would make more sense to me to submit a patch to rails that clears the cache via ActiveSupport::TestCase.

  • Fernando Blat

    Fernando Blat September 10th, 2008 @ 02:52 PM

    Ok,

    I'll check it out and try to have a second thought when I come back from my holidays in 15 days.

    Meanwhile, if you want, you can discard the ticket.

  • Fernando Blat

    Fernando Blat September 26th, 2008 @ 01:22 PM

    And what about hacking the run method?

    The problem of add the clear method to Rails is that not all cache storages support that method (for example disk store), so, it's quite probable that they don't like that approach.

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 »

People watching this ticket