accessing named route helper in cache sweepers

In my cache sweeper I call expire_fragment and use some named route
helpers for its argument (like comments_path(...)).

This works fine in the app, but in my tests it's causing problems,
because there's no controller and comments_path returns nil. (See
method_missing in actionpack/lib/action_controller/caching/sweeper.rb
-- that's what's returning nil in this case. I don't understand why
that's acceptable, but whatever.)

When my tests run Comment.create() directly, the sweeper gets called,
with no controller. How can I get to comments_path in this case?

In my cache sweeper I call expire_fragment and use some named route

helpers for its argument (like comments_path(…)).

This works fine in the app, but in my tests it’s causing problems,

because there’s no controller and comments_path returns nil. (See

method_missing in actionpack/lib/action_controller/caching/sweeper.rb

– that’s what’s returning nil in this case. I don’t understand why

that’s acceptable, but whatever.)

When my tests run Comment.create() directly, the sweeper gets called,

with no controller. How can I get to comments_path in this case?

I do know if the most effective way to do things because caching is turned

off by default within the test configuration. Next, where’s the code for the

test(s) with issues?

-Conrad

The test is trivial. Using rspec and machinist:

In user_spec.rb:

describe User do
  it "should create a new instance given valid attributes" do
    User.create!(User.plan)
  end
end

And in blueprints.rb:

User.blueprint do
  login { Sham.name }
  email { "#{self.login}@foo.com" }
  password { Sham.name }
  password_confirmation { password}
end

I just realized that this works when run by itself. It only breaks
when run after other specs that use controllers with the cache_sweeper
directive. (I guess that causes the sweeper to get loaded and begin
observing the models.)