Rails gives use page,action and fragment caching. Is there anyway to write tests to make sure the cache is being expired properly? I''m interested to know what other developers out there feel about this. For example, I was thinkin maybe I could enable caching in test mode, clear the cache on unittest setup and then after certain actions, load other pages and test the contents (to make sure that stale fragments aren''t being used, etc). -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Oct-02 07:24 UTC
Re: Is there a way to test caching in ur app?
TBH, I''m quite willing to trust that the rails guys have written their own thorough unit tests on their caching system, and not bother. Sounds like a lot of effort which will probably prove to be unnessecary... that is, unless you''re having some kind of problem and think that caching is at fault....? -Nathan On 02/10/06, David Barri <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Rails gives use page,action and fragment caching. Is there anyway to > write tests to make sure the cache is being expired properly? I''m > interested to know what other developers out there feel about this. > > For example, I was thinkin maybe I could enable caching in test mode, > clear the cache on unittest setup and then after certain actions, load > other pages and test the contents (to make sure that stale fragments > aren''t being used, etc). > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/2/06, njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <njmacinnes-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> TBH, I''m quite willing to trust that the rails guys have written their > own thorough unit tests on their caching system, and not bother. > Sounds like a lot of effort which will probably prove to be > unnessecary... that is, unless you''re having some kind of problem and > think that caching is at fault....?It''s not to test that cached versions are being served properly; it''s to test that your own code is expiring caches at the right time. Considering how many different pages you may need to flush the cache for when saving a single object, and how many you expect not to be flushed, I would say that being able to test your sweeper code is a good thing. If it''s possible to test it easily, I''d like to know how. Unit tests for the sweeper class? How do you assert that a page or action or fragment is cached?> -NathanSincerely, Tom Lieber http://AllTom.com/ http://GadgetLife.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Tom Lieber wrote:> It''s not to test that cached versions are being served properly; it''s > to test that your own code is expiring caches at the right time.That''s right, that''s what I meant. If I cache a fragment that displays the latest users in my app for example, I could forget to expire the cached fragment when new users are added to the system. Although thats a silly example (cos if u remember to put in the unit test (if there was a way), you would also remember to put in the controller), BUT expire_fragment takes regular expressions so if you later change your routes or you have complicated caching rules, testing wouldn''t be silly at all. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/2/06, David Barri <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Tom Lieber wrote: > > It''s not to test that cached versions are being served properly; it''s > > to test that your own code is expiring caches at the right time.That stuff is difficult to test unfortunately. I use integration testing for that in Mephisto: http://svn.techno-weenie.net/projects/mephisto/trunk/test/integration/caching_test.rb http://svn.techno-weenie.net/projects/mephisto/trunk/test/referenced_caching_test_helper.rb I imagine you could write up some nifty mock fragment cacher that would make that testing easier though. That would be nifty. -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 03/10/06, Rick Olson <technoweenie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 10/2/06, David Barri <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > Tom Lieber wrote: > > > It''s not to test that cached versions are being served properly; it''s > > > to test that your own code is expiring caches at the right time. > > That stuff is difficult to test unfortunately. I use integration > testing for that in Mephisto: > > http://svn.techno-weenie.net/projects/mephisto/trunk/test/integration/caching_test.rb > http://svn.techno-weenie.net/projects/mephisto/trunk/test/referenced_caching_test_helper.rb > > I imagine you could write up some nifty mock fragment cacher that > would make that testing easier though. That would be nifty.I wrote something like this a few months ago - I''ll see if I can dig it up this evening. Tom --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/3/06, Tom Ward <tom-FF2hOUnQ1ZmsTnJN9+BGXg@public.gmane.org> wrote:> I wrote something like this a few months ago - I''ll see if I can dig > it up this evening.Any luck?> TomSincerely, Tom Lieber http://AllTom.com/ http://GadgetLife.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 04/10/06, Tom Lieber <alltom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/3/06, Tom Ward <tom-FF2hOUnQ1ZmsTnJN9+BGXg@public.gmane.org> wrote: > > I wrote something like this a few months ago - I''ll see if I can dig > > it up this evening. > > Any luck?Yeah, I found what I''d written, but it''s a nasty hack, so I''m going to clean it up a little and make it into a plugin. I''ll post it by the end of the day. Tom --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 05/10/06, Tom Ward <tom-FF2hOUnQ1ZmsTnJN9+BGXg@public.gmane.org> wrote:> On 04/10/06, Tom Lieber <alltom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Any luck? > > Yeah, I found what I''d written, but it''s a nasty hack, so I''m going to > clean it up a little and make it into a plugin. I''ll post it by the > end of the day.Slightly later than promised, here''s the code, packaged as a plugin. Unfortunately http access to my svn repository is down, so I''ve created an archive: http://dev.popdog.net/caching_test_helper.tar.gz Basic usage is something like: assert_writes_fragment(:controller => :report, :action => :salary) do # some code end assert_expires_fragment(:controller => :report, :action => :salary) do # some code end There''s no need to clear/populate the cache with fragments before the assertion. Also, the code should work as well in a unit test as a functional one (useful if, like me, you expire fragments in a different process to the web dispatcher). If anyone finds it useful, let me know, Tom --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/7/06, Tom Ward <tom-FF2hOUnQ1ZmsTnJN9+BGXg@public.gmane.org> wrote:> Slightly later than promised, here''s the code, packaged as a plugin. > Unfortunately http access to my svn repository is down, so I''ve > created an archive: > > http://dev.popdog.net/caching_test_helper.tar.gz > > Basic usage is something like: > > assert_writes_fragment(:controller => :report, :action => :salary) do > # some code > end > > assert_expires_fragment(:controller => :report, :action => :salary) do > # some code > end > > There''s no need to clear/populate the cache with fragments before the > assertion. Also, the code should work as well in a unit test as a > functional one (useful if, like me, you expire fragments in a > different process to the web dispatcher). > > If anyone finds it useful, let me know,Thanks, this looks handy! I''m going to try it soon, and let you know if I come across anything odd.> TomSincerely, Tom Lieber http://AllTom.com/ http://GadgetLife.org/ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 07/10/06, Tom Lieber <alltom-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > On 10/7/06, Tom Ward <tom-FF2hOUnQ1ZmsTnJN9+BGXg@public.gmane.org> wrote: > > Slightly later than promised, here''s the code, packaged as a plugin. > > Unfortunately http access to my svn repository is down, so I''ve > > created an archive: > > > > http://dev.popdog.net/caching_test_helper.tar.gz > > > > Basic usage is something like: > > > > assert_writes_fragment(:controller => :report, :action => :salary) do > > # some code > > end > > > > assert_expires_fragment(:controller => :report, :action => :salary) do > > # some code > > end > > > > There''s no need to clear/populate the cache with fragments before the > > assertion. Also, the code should work as well in a unit test as a > > functional one (useful if, like me, you expire fragments in a > > different process to the web dispatcher). > > > > If anyone finds it useful, let me know, > > Thanks, this looks handy! I''m going to try it soon, and let you know > if I come across anything odd.I now have a version in subversion if you''d prefer. No significant changes to the fragment caching assertions, but some work towards page caching assertions. Available from: http://svn.popdog.net/public/rails/plugins/caching_test_helper/tags/REL-0.1/ Tom --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
> I now have a version in subversion if you''d prefer. No significant > changes to the fragment caching assertions, but some work towards page > caching assertions. Available from: > > http://svn.popdog.net/public/rails/plugins/caching_test_helper/tags/REL-0.1/Mine only handled page caching. This plugin looks much better. -- Rick Olson http://weblog.techno-weenie.net http://mephistoblog.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On 10/2/06, David Barri <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Rails gives use page,action and fragment caching. Is there anyway to > write tests to make sure the cache is being expired properly? I''m > interested to know what other developers out there feel about this. > > For example, I was thinkin maybe I could enable caching in test mode, > clear the cache on unittest setup and then after certain actions, load > other pages and test the contents (to make sure that stale fragments > aren''t being used, etc).You could easily do this with Selenium: http://www.openqa.org/ With Selenium you can write a simple DSL to click through the app via one or more browsers with tests in ruby code e.g. def test_expire_name_div a=users(:admin) login_as a open user_profile_url wait_for_page_to_load assert_equal a.name, get_text(''name'') a.name = "bob" a.save! #should expire fragment refresh_page assert_equal a.name, get_text(''name'') end This is a good way to test across browsers, to test ajax, and can provide easier ways to test some aspects of your app from the browser(s) to the db. Think of it as programmatic acceptance testing (write the DSL with the client even). They''re also an impressive client demo (i.e. shiny whilst in operation). pt.> Posted via http://www.ruby-forum.com/. > > > >-- Parker Thompson http://www.parkert.com/ 510.541.0125 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
On Oct 9, 2006, at 10:19 PM, Parker Thompson wrote:> > On 10/2/06, David Barri <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> Rails gives use page,action and fragment caching. Is there anyway to >> write tests to make sure the cache is being expired properly? I''m >> interested to know what other developers out there feel about this. >> >> For example, I was thinkin maybe I could enable caching in test mode, >> clear the cache on unittest setup and then after certain actions, >> load >> other pages and test the contents (to make sure that stale fragments >> aren''t being used, etc). > > You could easily do this with Selenium: > > http://www.openqa.org/ > > With Selenium you can write a simple DSL to click through the app via > one or more browsers with tests in ruby code e.g. > ...This might be helpful: http://agilewebdevelopment.com/plugins/page_cache_test -- Building an e-commerce site with Rails? http://www.agilewebdevelopment.com/rails-ecommerce --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---