|
12 | 12 | ]
|
13 | 13 | end
|
14 | 14 |
|
15 |
| - it 'before_filter' do |
16 |
| - controllers.each{ |c| expect(c).to receive(:before_filter).and_return(true) } |
17 |
| - application.before_filter :my_filter, only: :show |
18 |
| - end |
19 |
| - |
20 |
| - it 'skip_before_filter' do |
21 |
| - controllers.each{ |c| expect(c).to receive(:skip_before_filter).and_return(true) } |
22 |
| - application.skip_before_filter :my_filter, only: :show |
23 |
| - end |
24 |
| - |
25 |
| - it 'after_filter' do |
26 |
| - controllers.each{ |c| expect(c).to receive(:after_filter).and_return(true) } |
27 |
| - application.after_filter :my_filter, only: :show |
28 |
| - end |
29 |
| - |
30 |
| - it 'skip after_filter' do |
31 |
| - controllers.each{ |c| expect(c).to receive(:skip_after_filter).and_return(true) } |
32 |
| - application.skip_after_filter :my_filter, only: :show |
33 |
| - end |
34 |
| - |
35 |
| - it 'around_filter' do |
36 |
| - controllers.each{ |c| expect(c).to receive(:around_filter).and_return(true) } |
37 |
| - application.around_filter :my_filter, only: :show |
38 |
| - end |
39 |
| - |
40 |
| - it 'skip_filter' do |
41 |
| - controllers.each{ |c| expect(c).to receive(:skip_filter).and_return(true) } |
42 |
| - application.skip_filter :my_filter, only: :show |
| 15 | + expected_actions = ( |
| 16 | + prefixes = %w(skip append prepend) << nil |
| 17 | + positions = %w(before around after) |
| 18 | + suffixes = %w(filter) |
| 19 | + base = %w(skip_filter) |
| 20 | + if Rails::VERSION::MAJOR >= 4 |
| 21 | + suffixes += %w(action) |
| 22 | + base += %w(skip_action_callback) |
| 23 | + end |
| 24 | + |
| 25 | + prefixes.each_with_object(base) do |prefix, stack| |
| 26 | + positions.each do |position| |
| 27 | + suffixes.each do |suffix| |
| 28 | + stack << [prefix, position, suffix].compact.join("_").to_sym |
| 29 | + end |
| 30 | + end |
| 31 | + end |
| 32 | + ) |
| 33 | + |
| 34 | + expected_actions.each do |action| |
| 35 | + it action do |
| 36 | + args = [:my_filter, { only: :show }] |
| 37 | + controllers.each { |c| expect(c).to receive(action).with(args) } |
| 38 | + application.public_send action, args |
| 39 | + end |
43 | 40 | end
|
44 | 41 | end
|
0 commit comments