controller_filter_logging 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +4 -0
- data/lib/controller_filter_logging.rb +15 -12
- data/lib/controller_filter_logging/version.rb +1 -1
- data/spec/lib/controller_filter_logging_spec.rb +48 -0
- data/spec/spec_helper.rb +11 -0
- metadata +9 -6
data/Gemfile
CHANGED
@@ -1,12 +1,8 @@
|
|
1
|
+
require 'abstract_controller'
|
2
|
+
|
1
3
|
module AbstractController::Callbacks::ClassMethods
|
2
4
|
def before_filter_with_logging(*args, &block)
|
3
|
-
|
4
|
-
Rails.logger.debug("Can't log filters with blocks: #{caller[0..3].join("\n")}")
|
5
|
-
before_filter_without_logging *args, &block
|
6
|
-
else
|
7
|
-
filter_name = args.shift
|
8
|
-
before_filter_without_logging create_logging_filter(filter_name), *args
|
9
|
-
end
|
5
|
+
handle_filter(:before_filter, *args, &block)
|
10
6
|
end
|
11
7
|
alias_method_chain :before_filter, :logging
|
12
8
|
|
@@ -15,16 +11,22 @@ module AbstractController::Callbacks::ClassMethods
|
|
15
11
|
end
|
16
12
|
alias_method_chain :skip_before_filter, :logging
|
17
13
|
|
18
|
-
def prepend_before_filter_with_logging(
|
14
|
+
def prepend_before_filter_with_logging(*args, &block)
|
15
|
+
handle_filter(:prepend_before_filter, *args, &block)
|
16
|
+
end
|
17
|
+
alias_method_chain :prepend_before_filter, :logging
|
18
|
+
|
19
|
+
private
|
20
|
+
def handle_filter(type, *args, &block)
|
21
|
+
method = "#{type}_without_logging"
|
19
22
|
if block_given?
|
20
23
|
Rails.logger.debug("Can't log filters with blocks: #{caller[0..3].join("\n")}")
|
21
|
-
|
24
|
+
send(method, *args, &block)
|
22
25
|
else
|
23
|
-
|
24
|
-
|
26
|
+
filter_name = args.shift
|
27
|
+
send(method, create_logging_filter(filter_name), *args)
|
25
28
|
end
|
26
29
|
end
|
27
|
-
alias_method_chain :prepend_before_filter, :logging
|
28
30
|
|
29
31
|
def create_logging_filter(filter_name)
|
30
32
|
name = "#{filter_name.to_s.gsub(%r{[?!]}, '')}_with_logging"
|
@@ -40,4 +42,5 @@ module AbstractController::Callbacks::ClassMethods
|
|
40
42
|
end
|
41
43
|
name.to_sym
|
42
44
|
end
|
45
|
+
|
43
46
|
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'action_controller'
|
3
|
+
|
4
|
+
require 'controller_filter_logging'
|
5
|
+
|
6
|
+
describe 'controller_filter_logging' do
|
7
|
+
describe '#before_filter_with_logging' do
|
8
|
+
context 'with block' do
|
9
|
+
it "should warn and pass through to the block" do
|
10
|
+
Rails.logger.expects(:debug).once
|
11
|
+
|
12
|
+
controller = Class.new(ActionController::Base) do
|
13
|
+
attr_reader :called
|
14
|
+
|
15
|
+
before_filter do
|
16
|
+
@called = true
|
17
|
+
end
|
18
|
+
end.new
|
19
|
+
|
20
|
+
controller.run_callbacks(:process_action)
|
21
|
+
controller.called.should be_true
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should run the block and log the results" do
|
25
|
+
result = 12345
|
26
|
+
|
27
|
+
Rails.logger.expects(:debug).with("Entering before_filter: test")
|
28
|
+
Rails.logger.expects(:debug).with(" result: #{result}")
|
29
|
+
|
30
|
+
controller = Class.new(ActionController::Base) do
|
31
|
+
attr_reader :called
|
32
|
+
|
33
|
+
before_filter :test
|
34
|
+
|
35
|
+
private
|
36
|
+
def test
|
37
|
+
@called = 12345
|
38
|
+
end
|
39
|
+
end.new
|
40
|
+
|
41
|
+
controller.run_callbacks(:process_action)
|
42
|
+
controller.called.should == result
|
43
|
+
controller.methods.should include(:test_with_logging)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: controller_filter_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jon Moses
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-10 00:00:00 -04:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -37,6 +37,8 @@ files:
|
|
37
37
|
- init.rb
|
38
38
|
- lib/controller_filter_logging.rb
|
39
39
|
- lib/controller_filter_logging/version.rb
|
40
|
+
- spec/lib/controller_filter_logging_spec.rb
|
41
|
+
- spec/spec_helper.rb
|
40
42
|
has_rdoc: true
|
41
43
|
homepage: ""
|
42
44
|
licenses: []
|
@@ -71,5 +73,6 @@ rubygems_version: 1.3.7
|
|
71
73
|
signing_key:
|
72
74
|
specification_version: 3
|
73
75
|
summary: Bring back controller filter logging to rails 3
|
74
|
-
test_files:
|
75
|
-
|
76
|
+
test_files:
|
77
|
+
- spec/lib/controller_filter_logging_spec.rb
|
78
|
+
- spec/spec_helper.rb
|