-
-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix spec failure in jruby and add support for Rails 3.0
- Loading branch information
Showing
2 changed files
with
38 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 31 additions & 40 deletions
71
spec/shoulda/active_record/query_the_database_matcher_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,45 @@ | ||
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 | ||
end | ||
@child = define_model :kitten, :litter_id => :integer do | ||
belongs_to :litter | ||
end | ||
before do | ||
@parent = define_model :litter do | ||
has_many :kittens | ||
end | ||
|
||
it "accepts the correct number of queries when there is a single query" do | ||
@parent.should query_the_database(1.times).when_calling(:count) | ||
@child = define_model :kitten, :litter_id => :integer do | ||
belongs_to :litter | ||
end | ||
end | ||
|
||
it "accepts any number of queries when no number is specified" do | ||
@parent.should query_the_database.when_calling(:count) | ||
end | ||
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 "rejects any number of queries when no number is specified" do | ||
@parent.should_not query_the_database.when_calling(:to_s) | ||
end | ||
it "accepts any number of queries when no number is specified" do | ||
@parent.should query_the_database.when_calling(:count) | ||
end | ||
|
||
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 "rejects any number of queries when no number is specified" do | ||
@parent.should_not query_the_database.when_calling(:to_s) | ||
end | ||
|
||
it "rejects the wrong number of queries" do | ||
@parent.should_not query_the_database(10.times).when_calling(:count) | ||
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 "accepts fewer than the specified maximum" do | ||
@parent.should query_the_database(5.times).or_less.when_calling(:count) | ||
end | ||
it "rejects the wrong number of queries" do | ||
@parent.should_not query_the_database(10.times).when_calling(:count) | ||
end | ||
|
||
it "passes arguments to the method to examine" do | ||
model = stub("Model", :count => nil) | ||
model.should_not query_the_database.when_calling(:count).with("arguments") | ||
model.should have_received(:count).with("arguments") | ||
end | ||
else | ||
it "should raise an exception on Rails < 3.1" do | ||
model = define_model(:litter) | ||
lambda do | ||
model.should query_the_database(1.times).when_calling(:count) | ||
end.should raise_exception(RuntimeError, "Rails 3.1 or greater is required") | ||
end | ||
it "accepts fewer than the specified maximum" do | ||
@parent.should query_the_database(5.times).or_less.when_calling(:count) | ||
end | ||
|
||
it "passes arguments to the method to examine" do | ||
model = stub("Model", :count => nil) | ||
model.should_not query_the_database.when_calling(:count).with("arguments") | ||
model.should have_received(:count).with("arguments") | ||
end | ||
end |