From 56de191d4e145114d41971852421185d165a34f2 Mon Sep 17 00:00:00 2001 From: Matthew Daubert Date: Tue, 20 Mar 2012 21:07:56 -0400 Subject: [PATCH] Test that exception is thrown in Rails < 3.1 AbstractAdapter doesn't provide the required payload information until 3.1. Raising of the exception was moved out of the filter_query method because the exception was being thrown during evaluation of the subscribe block which prevented the eventual call to unsubscribe and potentially failing other unrelated specs. --- .../matchers/active_record/query_the_database_matcher.rb | 3 ++- .../active_record/query_the_database_matcher_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/shoulda/matchers/active_record/query_the_database_matcher.rb b/lib/shoulda/matchers/active_record/query_the_database_matcher.rb index 80cf11f9d..094910db1 100644 --- a/lib/shoulda/matchers/active_record/query_the_database_matcher.rb +++ b/lib/shoulda/matchers/active_record/query_the_database_matcher.rb @@ -44,6 +44,8 @@ def or_less end def matches?(subject) + raise "Rails 3.1 or greater is required" unless rails_3_1? + @queries = [] subscriber = ActiveSupport::Notifications.subscribe('sql.active_record') do |name, started, finished, id, payload| @@ -88,7 +90,6 @@ def friendly_queries end def filter_query(query_name) - raise "Rails 3.1 or greater is required" unless rails_3_1? query_name == 'SCHEMA' end diff --git a/spec/shoulda/active_record/query_the_database_matcher_spec.rb b/spec/shoulda/active_record/query_the_database_matcher_spec.rb index 7473cc0e2..dab145de0 100644 --- a/spec/shoulda/active_record/query_the_database_matcher_spec.rb +++ b/spec/shoulda/active_record/query_the_database_matcher_spec.rb @@ -49,6 +49,14 @@ def self.count(arguments) model.should_not query_the_database.when_calling(:count).with("arguments") end + else + + it "should raise an exception on Rails < 3.1" do + lambda { + @parent.should query_the_database(1.times).when_calling(:count) + }.should raise_exception + end + end end