should cache-money work with rails unit tests?

The Cache Money page (http://github.com/nkallen/cache-money) mentions

"For your unit tests, it is faster to use a Memcached mock than the real

deal."

Faster is fine but will it work with memcached? It doesn’t work with

mine, I suspect the cache is not cleared between tests. I suspect this

is just a documentation issue.

This is a great GEM but it’s sad that documentation corrections are on

various forums. :-\

One other question. to get it to work I needed to require memcache in

my initializer. Anyone know why this is? Here it is (pieced together

from various forums)

require ‘memcache’

require ‘cache_money’

if RAILS_ENV == ‘test’

$memcache = Cash::Mock.new

else

if RAILS_ENV != ‘development’

config = YAML.load(IO.read(File.join(RAILS_ROOT, "config",

“memcached.yml”)))[RAILS_ENV]

$memcache = MemCache.new(config)

$memcache.servers = config['servers']

$local = Cash::Local.new($memcache)

$lock = Cash::Lock.new($memcache)

$cache = Cash::Transactional.new($local, $lock)



class ActiveRecord::Base

  is_cached :repository => $cache

end

else

If we’re in development mode, we don’t want to

deal with cacheing oddities, so let’s overrite

cache-money’s #index method to do nothing…

class ActiveRecord::Base

  def self.index(*args)

  end

end

end

end

Hi, I would recommend taking a look at the following for proper use of:

http://github.com/ngmoco/cache-money/blob/master/spec/memcached_wrapper_test.rb

Good luck,

-Conrad

The Cache Money page (http://github.com/nkallen/cache-money) mentions

"For your unit tests, it is faster to use a Memcached mock than the real

deal."

Faster is fine but will it work with memcached? It doesn’t work with

mine, I suspect the cache is not cleared between tests. I suspect this

is just a documentation issue.

For properly clearing the cache before each test, you should reference the

link below to create a suitable ‘setup’ and ‘teardown’ methods for your unit,

functional, and integration tests.

This is a great GEM but it’s sad that documentation corrections are on

various forums. :-\

One other question. to get it to work I needed to require memcache in

my initializer. Anyone know why this is? Here it is (pieced together

from various forums)

In short, it’s part of the Rails application initialization process and it must be

completed before the Rails application is ready for use. For example, if you take

a look at the file in #{RAILS_ROOT}/config/initializers, you’ll see other files

that are part of the application initialization process. Furthermore, this process

usually takes place after the loading of both plugins and gems.

Good luck,

-Conrad

Thanks for the pointers Conrad. It seems this project has several
active forks on github. How does one go about choosing one? My hunch
is to go with a fork that is still active but my fear is that it may
diverge from what the original author intended and will become
deprecated.

Any recommendations here?

Thanks for the pointers Conrad. It seems this project has several

active forks on github. How does one go about choosing one? My hunch

is to go with a fork that is still active but my fear is that it may

diverge from what the original author intended and will become

deprecated.

Any recommendations here?

Hi, I would recommend getting the version from

http://www.gemcutter.org/gems/ngmoco-cache-money

-Conrad

It looks like these newer versions don't bother with the initializer
making the setup easier (i guess test cases us the mock by default).

At the moment I am using ashleym1972-cache-money-0.2.9 as ngmoco gives
the following error

gem install ngmoco-cache-money
ERROR: could not find gem ngmoco-cache-money locally or in a
repository

I have the following sources.
gem sources
*** CURRENT SOURCES ***

http://gems.rubyforge.org/
http://gems.github.com

Thanks for the pointers Conrad. It seems this project has several

active forks on github. How does one go about choosing one? My hunch

is to go with a fork that is still active but my fear is that it may

diverge from what the original author intended and will become

deprecated.

Any recommendations here?

Hi, I would recommend getting the version from

http://www.gemcutter.org/gems/ngmoco-cache-money

-Conrad

It looks like these newer versions don’t bother with the initializer

making the setup easier (i guess test cases us the mock by default).

At the moment I am using ashleym1972-cache-money-0.2.9 as ngmoco gives

the following error

gem install ngmoco-cache-money

ERROR: could not find gem ngmoco-cache-money locally or in a

repository

I have the following sources.

gem sources

*** CURRENT SOURCES ***

http://gems.rubyforge.org/

http://gems.github.com

Hi, you’ll need to install gemcutter gem and update your primary gem host by doing the following:

sudo gem install gemcutter

gem tumble

Good luck,

-Conrad