How to log rails controller filters during rspec controller tests?

Here's how I've solved the same problem. I'm sure the code below can still be improved a lot and possibly put into a module of it's own. Improvements wellcome You'll need to put the following code into the top ActionController, which usually is ApplicationController or whatever the controller is you need to track: class ApplicationController Before_filter_with_logging(*arguments, &block) filters, conditions = ActionController::Filters::FilterChain.

Extract_options(arguments, &block) filter_method_names = filters. Map { |fm| fm. To_s }.

Join(', ') logger. Info "Setting up before_filter to #{filter_method_names}" filter_methods_with_logging = filters. Map { |fm| (fm.

To_s + "_with_logging"). To_sym } filters. Each { |fm| define_method( (fm.

To_s + "_with_logging"). To_sym ) { |*args| logger. Info "Calling before_filter #{fm}" if args.

Empty? Send fm else send fm, args end } } before_filter_without_logging(filter_methods_with_logging, &block) end class.

Here's how I've solved the same problem. I'm sure the code below can still be improved a lot and possibly put into a module of it's own. Improvements wellcome.

You'll need to put the following code into the top ActionController, which usually is ApplicationController or whatever the controller is you need to track: class ApplicationController Map { |fm| fm. To_s }. Join(', ') logger.Info "Setting up before_filter to #{filter_method_names}" filter_methods_with_logging = filters.

Map { |fm| (fm. To_s + "_with_logging"). To_sym } filters.

Each { |fm| define_method( (fm. To_s + "_with_logging"). To_sym ) { |*args| logger.

Info "Calling before_filter #{fm}" if args. Empty? Send fm else send fm, args end } } before_filter_without_logging(filter_methods_with_logging, &block) end class.

I don't see, why logger. Info ":user_signed_in called" within that method shouldn't work. You even could do puts ":user_signed_in called", which prints that line directly between the output of rspec.

Won't be pretty, but it may be easier than reading the whole test. Log file.

I think you missed the purpose of the question. I want to avoid hunting down the source code of every filter and inserting a Rails. Logger command there.

I was hoping that there might be some hooks in rails to allow tracing of the callback sequence. – bradgonesurfing Feb 13 at 4:03.

Logging - How to log rails controller filters during rspec controller tests - Stack Overflow.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions