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.
This commit is contained in:
Matthew Daubert 2012-03-20 21:07:56 -04:00 committed by Gabe Berke-Williams
parent 8e7fbc553b
commit 56de191d4e
2 changed files with 10 additions and 1 deletions

View File

@ -44,6 +44,8 @@ module Shoulda # :nodoc:
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 @@ module Shoulda # :nodoc:
end
def filter_query(query_name)
raise "Rails 3.1 or greater is required" unless rails_3_1?
query_name == 'SCHEMA'
end

View File

@ -49,6 +49,14 @@ describe Shoulda::Matchers::ActiveRecord::QueryTheDatabaseMatcher do
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