Skip to content

Commit

Permalink
Test that exception is thrown in Rails < 3.1
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MDaubs authored and Gabe Berke-Williams committed Mar 23, 2012
1 parent 8e7fbc5 commit 56de191
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
Expand Up @@ -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|
Expand Down Expand Up @@ -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

Expand Down
8 changes: 8 additions & 0 deletions spec/shoulda/active_record/query_the_database_matcher_spec.rb
Expand Up @@ -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

0 comments on commit 56de191

Please sign in to comment.