Living on the edge (of Rails) #17

In: Edge Rails|Open Source|Ruby|Ruby on Rails

20 Apr 2008

Not much going on this week on edge Rails. It does seem however that we do have a new Rails core member, Joshua Peek. Also, the new Rails’ bug tracker hosted on Lighthouse is ready for use, so be sure to submit your patches and bug reports there.

This week’s report covers changes from 14 Apr 2008 to 20 Apr 2008 (the day the corresponding Rails Envy podcast was recorded).

Conditional caches_page

The caches_page now takes an :if option for specifying when a page can actually be cached via a Proc. You can now do this, for example:

caches_page :index, :if => { |c| !c.request.format.json? }

That will only cache your index page if the requested format is not JSON.

Credit goes to Paul Horsfall for this enhancement.

Related changeset:

New ActionView::TestCase for testing view helpers

Remember how you can now use specialized TestCase classes for testing controllers and ActionMailer classes? Now you can do the same with your Rails view helpers with the new ActionView::TestCase class.

Here’s a quick example:

module PeopleHelper
  def title(text)
    content_tag(:h1, text)

  def homepage_path

class PeopleHelperTest < ActionView::TestCase
def setup
  ActionController::Routing::Routes.draw do |map|
    map.people 'people', :controller => 'people', :action => 'index'
    map.connect ':controller/:action/:id'

def test_title
  assert_equal "<h1>Ruby on Rails</h1>", title("Ruby on Rails")

def test_homepage_path
  assert_equal "/people", homepage_path

Credit goes to Josh Peek for this sweet little enhancement.

ActiveSupport::Cache’s mem_cache_store accepts options

Even though Memcache-client was added to ActiveSupport recently, it didn’t allow you to specify any configuration options beyond just the IP of the memcached server. Now you can pass along more configuration options like so:

config.action_controller.fragment_cache_store = :mem_cache_store, 'localhost', { :compression => true, :debug => true, :namespace => 'foo' }

This patch is courtesy of Jonathan Weiss.

Related changeset:

As always, let me know of any suggestions or how I can improve the Living on the Edge (of Rails) series.

4 Responses to Living on the edge (of Rails) #17


A Fresh Cup » Blog Archive » Double Shot #191

April 21st, 2008 at 6pm

[…] Living on the edge (of Rails) #17 – A fairly quiet week for Rails development. […]


High Five: five tips on testing with Rails — Learning on Rails

May 6th, 2008 at 4am

[…] Test your helpers: plain and simple. Rais Recipes has a recipe about it and, with Edge Rails, testing helpers got easier. […]


Living on the edge (of Rails) #21 | redemption in a blog

June 20th, 2008 at 1pm

[…] now takes an :if option (just like caches_page does). For […]


Living on the edge (of Rails) #21 « Rails Rider

November 10th, 2009 at 1pm

[…] now takes an :if option (just like caches_page does). For […]