Rails hashes: etag, which you provide:
headers['ETag'] = %("#{Digest::MD5.hexdigest(ActiveSupport::Cache.expand_cache_key(etag))}")
so install something simple like
frash_when(:etag => 'foo')
will only be called with the correct digest (double quotes are needed)
def with_etag if stale?(:etag => 'foo') render :text => 'OK' end end ... tested by ... @request.env['HTTP_IF_NONE_MATCH'] = '"acbd18db4cc2f85cedef654fccc4a4d8"' get :with_etag assert_equal 304, @response.status.to_i
same for modified:
def with_modified if stale?(:last_modified => 1.minute.ago) render :text => 'OK' end end ... tested by ... @request.env['HTTP_IF_MODIFIED_SINCE'] = 2.minutes.ago.rfc2822 get :with_modified assert_equal 304, @response.status.to_i
grosser
source share