Sha256: 1ca151eff9a410a91c453cbaf5c3eb11e098aaf9bad63b51b373d9f76049d4f7

Contents?: true

Size: 1.38 KB

Versions: 9

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

9 entries across 9 versions & 2 rubygems

Version Path
challah-1.0.0.beta3 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
challah-1.0.0.beta2 vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
challah-1.0.0.beta vendor/bundle/gems/shoulda-matchers-1.5.6/spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.5.6 spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.5.5 spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.5.4 spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.5.2 spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.5.1 spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb
shoulda-matchers-1.5.0 spec/shoulda/matchers/active_record/query_the_database_matcher_spec.rb