specstar-controllers 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/specstar/controllers.rb +25 -14
  2. metadata +2 -2
@@ -25,7 +25,19 @@ module Specstar
25
25
  }
26
26
  end
27
27
 
28
- def has_skip_before_filter?(controller, filter, actions)
28
+ def has_before_filter_for_action?(controller, filter, action=nil)
29
+ controller._process_action_callbacks.any? { |callback|
30
+ callback.chain.any? { |chain|
31
+ if action
32
+ chain.kind == :before && chain.filter.to_s == filter.to_s && chain.per_key[:if].any? { |item| item.include? "action_name == '#{action}'" }
33
+ else
34
+ chain.kind == :before && chain.filter.to_s == filter.to_s
35
+ end
36
+ }
37
+ }
38
+ end
39
+
40
+ def has_skip_before_filter?(controller, filter, actions=[])
29
41
  if actions.present?
30
42
  actions.all? { |action| has_skip_before_filter_for_action?(controller, filter, action) }
31
43
  else
@@ -33,22 +45,21 @@ module Specstar
33
45
  end
34
46
  end
35
47
 
36
- def has_before_filter?(controller, filter, action=nil)
37
- callbacks = controller.is_a?(ApplicationController) ? controller._process_action_callbacks : controller._dispatch_callbacks
38
- callbacks.select { |callback|
39
- callback.chain.select { |chain|
40
- chain.kind == :before && chain.filter.to_s == filter.to_s && (action.nil? || chain.per_key[:if].include?("action_name == '#{action}'"))
41
- }.size > 0
42
- }.size > 0
48
+ def has_before_filter?(controller, filter, actions=[])
49
+ if actions.present?
50
+ actions.all? { |action| has_before_filter_for_action?(controller, filter, action) }
51
+ else
52
+ has_before_filter_for_action?(controller, filter)
53
+ end
43
54
  end
44
55
 
45
56
  RSpec::Matchers.define :have_skip_before_filter do |filter|
46
57
  chain :only do |actions|
47
- @action = *actions
58
+ @actions = *actions
48
59
  end
49
60
 
50
61
  match do |controller|
51
- has_skip_before_filter?(controller, filter, @action)
62
+ has_skip_before_filter?(controller, filter, @actions)
52
63
  end
53
64
 
54
65
  failure_message_for_should do |controller|
@@ -65,12 +76,12 @@ module Specstar
65
76
  end
66
77
 
67
78
  RSpec::Matchers.define :have_before_filter do |filter|
68
- chain :only do |action|
69
- @action = action
79
+ chain :only do |actions|
80
+ @actions = *actions
70
81
  end
71
82
 
72
83
  match do |controller|
73
- has_before_filter?(controller, filter, @action)
84
+ has_before_filter?(controller, filter, @actions)
74
85
  end
75
86
 
76
87
  failure_message_for_should do |controller|
@@ -87,4 +98,4 @@ module Specstar
87
98
  end
88
99
  end
89
100
  end
90
- end
101
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specstar-controllers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-10-30 00:00:00.000000000 Z
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: sujoyg@gmail.com