Sha256: f3a38a56b969071964ebf92893e193606cb489eb5cf337b3eca35d81c3225cfe

Contents?: true

Size: 1.38 KB

Versions: 28

Compression:

Stored size: 1.38 KB

Contents

require 'spec_helper'

describe Shoulda::Matchers::ActiveRecord::QueryTheDatabaseMatcher do
  before do
    @parent = define_model :litter do
      has_many :kittens
    end
    @child = define_model :kitten, :litter_id => :integer do
      belongs_to :litter
    end
  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 "accepts any number of queries when no number is specified" do
    @parent.should query_the_database.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 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 the wrong number of queries" do
    @parent.should_not query_the_database(10.times).when_calling(:count)
  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

Version data entries

28 entries across 20 versions & 4 rubygems

Version Path
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.4.2/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-0.9.1.beta.3 vendor/bundle/gems/shoulda-matchers-1.4.2/spec/shoulda/active_record/query_the_database_matcher_spec.rb
devise_sociable-0.1.0 vendor/bundle/gems/shoulda-matchers-1.4.2/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-0.9.1.beta vendor/bundle/gems/shoulda-matchers-1.4.2/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-0.9.0 vendor/bundle/gems/shoulda-matchers-1.4.2/spec/shoulda/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.4.2 spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.4.1/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.4.1/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-0.8.3 vendor/bundle/gems/shoulda-matchers-1.4.1/spec/shoulda/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.4.1 spec/shoulda/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.4.0 spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-0.8.1 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/challah-0.8.0.pre/vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.2.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb
challah-rolls-0.1.0 vendor/bundle/gems/shoulda-matchers-1.3.0/spec/shoulda/active_record/query_the_database_matcher_spec.rb