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?
On Sun, Oct 25, 2009 at 3:15 PM, Scott Johnson <scott-wIW8SF+lElu2kH9Ulgv/9g@public.gmane.org>wrote:> > 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> > >--~--~---------~--~----~------------~-------~--~----~ 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?hl=en -~----------~----~----~----~------~----~------~--~---
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.) On Oct 25, 7:22 pm, Conrad Taylor <conra...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sun, Oct 25, 2009 at 3:15 PM, Scott Johnson <sc...-wIW8SF+lElu2kH9Ulgv/9g@public.gmane.org>wrote: > > > > > 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 > >