Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # original idea is by @a_matsuda.
- # it { should filter(:update).by :require_session }
- # => should filter update by require_session
- RSpec::Matchers.define :filter do |action_name|
- action_name = action_name.to_s
- match do
- callbacks = controller._process_action_callbacks.select { |c| c.kind == :before && @method_names.include?(c.filter.to_s)}
- if callbacks.count != @method_names.count || callbacks.empty?
- false
- else
- callbacks.all? do |callback|
- callback.per_key[:if].all?{|c|eval(c)} && !callback.per_key[:unless].any?{|c|eval(c)}
- end
- end
- end
- def by(*method_names)
- @method_names = method_names.map(&:to_s)
- self
- end
- description do
- "filter #{action_name} by #{@method_names.join(', ')}"
- end
- failure_message_for_should do
- "not filter #{action_name} by #{@method_names.join(', ')}"
- end
- end
Add Comment
Please, Sign In to add comment