Skip to content

Commit

Permalink
Style.
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabe Berke-Williams committed Mar 23, 2012
1 parent 0ecb774 commit f841805
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions spec/shoulda/active_record/query_the_database_matcher_spec.rb
@@ -1,9 +1,7 @@
require 'spec_helper'

describe Shoulda::Matchers::ActiveRecord::QueryTheDatabaseMatcher do

if ::ActiveRecord::VERSION::MAJOR == 3 && ::ActiveRecord::VERSION::MINOR >= 1

before do
@parent = define_model :litter do
has_many :kittens
Expand All @@ -13,47 +11,43 @@
end
end

it "should accept the correct number of queries when there is a single query" do
it "accepts the correct number of queries when there is a single query" do
@parent.should query_the_database(1.times).when_calling(:count)
end

it "should accept any number of queries when no number is specified" do
it "accepts any number of queries when no number is specified" do
@parent.should query_the_database.when_calling(:count)
end

it "should reject any number of queries when no number is specified" do
it "rejects any number of queries when no number is specified" do
@parent.should_not query_the_database.when_calling(:to_s)
end

it "should accept the correct number of queries when there are two queries" do
it "accepts the correct number of queries when there are two queries" do
nonsense = lambda do
@parent.create.kittens.create
end
nonsense.should query_the_database(2.times).when_calling(:call)
end

it "should reject the wrong number of queries" do
it "rejects the wrong number of queries" do
@parent.should_not query_the_database(10.times).when_calling(:count)
end

it "should accept fewer than the specified maximum" do
it "accepts fewer than the specified maximum" do
@parent.should query_the_database(5.times).or_less.when_calling(:count)
end

it "should pass arguments to the method to examine" do
it "passes arguments to the method to examine" do
model = stub("Model", :count => nil)
model.expects(:count).with("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 {
lambda do
@parent.should query_the_database(1.times).when_calling(:count)
}.should raise_exception
end.should raise_exception
end

end

end

0 comments on commit f841805

Please sign in to comment.