Sha256: b07c017a0457215b3516b03192623c970b7e088afe215d1c16d1c5c1f5038669

Contents?: true

Size: 918 Bytes

Versions: 19

Compression:

Stored size: 918 Bytes

Contents

require 'test_helper'
require 'lazy_document'

class UserModel; end

class LazyDocumentTest < Test::Unit::TestCase
  context "With a lazy document" do
    setup do
      @record = stub(:record)
      @record.stubs(:is_valid?).returns true
      UserModel.stubs(:find).returns @record
      @document = ActsAsSolr::LazyDocument.new(1, UserModel)
    end
    
    context "with an uninitialized document" do
      should "fetch the record from the database" do
        UserModel.expects(:find).with(1).returns(@record)
        @document.is_valid?
      end
    end
    
    context "with an initialized document" do
      should "not fetch the record again" do
        @document.is_valid?
        @document.expects(:find).never
        @document.is_valid?
      end
      
      should "reroute the calls to the record" do
        @record.expects(:is_valid?).once
        @document.is_valid?
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 3 rubygems

Version Path
onemorecloud-websolr-rails-1.1.1 test/unit/lazy_document_shoulda.rb
onemorecloud-websolr-rails-1.3.3 test/unit/lazy_document_shoulda.rb
onemorecloud-websolr-rails-1.4.0 test/unit/lazy_document_shoulda.rb
onemorecloud-websolr-rails-1.4.1 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.3.3 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.3.2 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.3.1 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.3.0 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.2.0 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.1.3 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.1.2 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.1.1 test/unit/lazy_document_shoulda.rb
acts_as_solr-1.0.0 test/unit/lazy_document_shoulda.rb
onemorecloud-websolr-rails-1.4.6 test/unit/lazy_document_shoulda.rb
onemorecloud-websolr-rails-1.4.5 test/unit/lazy_document_shoulda.rb
onemorecloud-websolr-rails-1.4.4 test/unit/lazy_document_shoulda.rb
websolr-rails-1.4.4 test/unit/lazy_document_shoulda.rb
onemorecloud-websolr-rails-1.4.3 test/unit/lazy_document_shoulda.rb
websolr-rails-1.4.3 test/unit/lazy_document_shoulda.rb