specstar-controllers 0.1.1 → 0.2.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/specstar/controllers.rb +44 -22
  3. metadata +7 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 307878cf1e13e950b35b328ce0bf7fbe6eb250f4
4
- data.tar.gz: 439b8adff7ba7bd37e3ce7646b700c6b39fc5e78
3
+ metadata.gz: f7a385633a32305657451773a60dd9db36ca7bd9
4
+ data.tar.gz: f9f514f12b7ee4bb1f90553ee4ea4cdae3b929a4
5
5
  SHA512:
6
- metadata.gz: 91badea2d8592b29942131730a3498b44acf4ab1d4b3b1871d70ecec2ffcc433badb189726187bbbda5ce81f448f7fd2bc6b740a5608e94909600b31f97cf0de
7
- data.tar.gz: 34b50ab2fca0ab630de5f939a5e89d2aeb86bc4cddb6a357aef82567e597368b41cea018796df4a93c9fe510ff653c3ecc664ada44edd8d26a335a45fe19f0c2
6
+ metadata.gz: fb321f8f6dc9e08bfbcbfe0dd367a517eabbd4fe8ca95593fa61dfca30c45bf5d17830fa106b71d7a13e21b01573685d6467f3baa2ba1be337b4f0fa9f3431a1
7
+ data.tar.gz: ea8687d07dc2782fe49df70d67d51aa3b82149155c8c905f11f9cab3c77e2b998d6f93e40d10334e351567d58364a01b416c27edd2b92fb0f126344a7ed5be2e
@@ -35,16 +35,6 @@ module Specstar
35
35
  }
36
36
  end
37
37
 
38
- def has_before_filter_for_action?(controller, filter, action=nil)
39
- controller._process_action_callbacks.any? { |callback|
40
- if action
41
- callback.kind == :before && callback.filter.to_s == filter.to_s && callback.per_key[:if].any? { |item| item.include? "action_name == '#{action}'" }
42
- else
43
- callback.kind == :before && callback.filter.to_s == filter.to_s
44
- end
45
- }
46
- end
47
-
48
38
  def has_skip_before_filter?(controller, filter, actions=[])
49
39
  if actions.present?
50
40
  actions.all? { |action| has_skip_before_filter_for_action?(controller, filter, action) }
@@ -53,14 +43,42 @@ module Specstar
53
43
  end
54
44
  end
55
45
 
56
- def has_before_filter?(controller, filter, actions=[])
57
- if actions.present?
58
- actions.all? { |action| has_before_filter_for_action?(controller, filter, action) }
46
+ def callback_matches?(callback, condition, actions)
47
+ field = "@#{condition}"
48
+
49
+ if actions.size > 0
50
+ actions.all? { |a|
51
+ callback.instance_variable_get(field).any? { |item| item.include? "action_name == '#{a}'" }
52
+ }
59
53
  else
60
- has_before_filter_for_action?(controller, filter)
54
+ callback.instance_variable_get(field).empty?
61
55
  end
62
56
  end
63
57
 
58
+ def has_before_filter?(controller, filter, options={})
59
+ result = true
60
+
61
+ if options.include?(:only)
62
+ result = controller._process_action_callbacks.any? { |callback|
63
+ callback.kind == :before && callback.filter.to_s == filter.to_s && callback_matches?(callback, :if, options[:only])
64
+ }
65
+ end
66
+
67
+ if result && options.include?(:except)
68
+ result = controller._process_action_callbacks.any? { |callback|
69
+ callback.kind == :before && callback.filter.to_s == filter.to_s && callback_matches?(callback, :unless, options[:except])
70
+ }
71
+ end
72
+
73
+ if result && options.blank?
74
+ result = controller._process_action_callbacks.any? { |callback|
75
+ callback.kind == :before && callback.filter.to_s == filter.to_s
76
+ }
77
+ end
78
+
79
+ result
80
+ end
81
+
64
82
  RSpec::Matchers.define :have_skip_before_filter do |filter|
65
83
  chain :only do |actions|
66
84
  @actions = *actions
@@ -83,21 +101,25 @@ module Specstar
83
101
  end
84
102
  end
85
103
 
86
- RSpec::Matchers.define :have_before_filter do |filter|
87
- chain :only do |actions|
88
- @actions = *actions
89
- end
90
-
104
+ RSpec::Matchers.define :have_before_filter do |filter, options={}|
91
105
  match do |controller|
92
- has_before_filter?(controller, filter, @actions)
106
+ has_before_filter?(controller, filter, options)
93
107
  end
94
108
 
95
109
  failure_message do |controller|
96
- "Expected #{controller.class.name} to have a before filter '#{filter}'."
110
+ if options
111
+ "Expected #{controller.class.name} to have a before_filter #{filter} with #{options}."
112
+ else
113
+ "Expected #{controller.class.name} to have a before_filter #{filter}."
114
+ end
97
115
  end
98
116
 
99
117
  failure_message_when_negated do |controller|
100
- "Expected #{controller.class.name} not to have a before filter '#{filter}'."
118
+ if options
119
+ "Expected #{controller.class.name} not to have a before_filter #{filter} with #{options}."
120
+ else
121
+ "Expected #{controller.class.name} not to have a before_filter #{filter}."
122
+ end
101
123
  end
102
124
 
103
125
  description do
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: specstar-controllers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sujoy Gupta
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-26 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '3.1'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '3.1'
27
27
  description:
@@ -40,17 +40,17 @@ require_paths:
40
40
  - lib
41
41
  required_ruby_version: !ruby/object:Gem::Requirement
42
42
  requirements:
43
- - - '>='
43
+ - - ">="
44
44
  - !ruby/object:Gem::Version
45
45
  version: '0'
46
46
  required_rubygems_version: !ruby/object:Gem::Requirement
47
47
  requirements:
48
- - - '>='
48
+ - - ">="
49
49
  - !ruby/object:Gem::Version
50
50
  version: '0'
51
51
  requirements: []
52
52
  rubyforge_project:
53
- rubygems_version: 2.1.4
53
+ rubygems_version: 2.4.6
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: RSpec helpers for controllers.