Browse files

Updating matcher to support testing class callbacks

  • Loading branch information...
1 parent f39ae25 commit 01aa9716b7b2baa332a434a518e5b654c4d88ec4 @pvertenten committed Feb 12, 2014
Showing with 9 additions and 3 deletions.
  1. +1 −1 Gemfile.lock
  2. +8 −2 lib/shoulda/callback/matchers/active_model.rb
View
2 Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
- shoulda-callback-matchers (0.1.0)
+ shoulda-callback-matchers (0.2.0)
activesupport (>= 3.0.0)
GEM
View
10 lib/shoulda/callback/matchers/active_model.rb
@@ -60,8 +60,14 @@ def matches?(subject)
false
else
callbacks = subject.send(:"_#{@lifecycle}_callbacks").dup
- callbacks = callbacks.select do |callback|
- callback.filter == @method &&
+ callbacks = callbacks.select do |callback|
+ object_match = @method.kind_of?(Class) &&
+ callback.filter.match(/^_callback/) &&
+ subject.respond_to?("#{callback.filter}_object") &&
+ subject.send("#{callback.filter}_object").class == @method
+
+ subject.respond_to?(callback.filter) &&
+ (object_match || callback.filter == @method) &&
callback.kind == @hook &&
matches_conditions?(callback) &&
matches_optional_lifecycle?(callback)

0 comments on commit 01aa971

Please sign in to comment.