Sha256: 2be9578c34d294a700bb8ee3927a2d11e1f5adf97770e88bcff71e94bbea75de

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

# Sunspot::NullResult [![Build Status](https://travis-ci.org/Absolventa/sunspot_null-result.svg?branch=master)](https://travis-ci.org/Absolventa/sunspot_null-result)

Interface taken from `Sunspot::Rails::StubSessionProxy::PaginatesCollection` of
[sunspot-rails](https://github.com/sunspot/sunspot/tree/master/sunspot_rails).

It adds the option to inject records to mimic actual search results (and yes,
thus making fun of the "Null" gem name).

## Installation

Add this line to your application's Gemfile:

```ruby
gem 'sunspot-null_result'
```

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install sunspot-null_result

## Usage

RSpec examples:

```ruby
RSpec.describe 'stubbed Solr result' do
  let(:search) { Sunspot::NullResult.new(records) }
  before { allow(MyModel).to receive(:search).and_return(search) }

  context 'with no records' do
    let(:records) { [] }
    # …

    it 'supports grouping' do
      # …
      expect(search.group(:my_attribute)).to eql []
    end
  end

  context 'with some records' do
    let(:records) { [MyModel.new, MyModel.new] }
    # …

    it 'supports grouping' do
      # …
      expect(search.group(:my_attribute)).not_to be_empty
    end
  end
end
```

Rescue case for unavailable Solr server, e.g. Websolr having issues.

```ruby
class ApplicationController < ActionController::Base

  rescue_from RSolr::Error::Http do |exception|
    # Handle exception so that a complete server shutdown
    # doesn't go unnoticed. Your app may still work using:

    failover_records = MyModel.last(10)
    Sunspot::NullResult.new(failover_records)
  end

  # …
end
```

## Changelog

### HEAD (not yet released)

### v0.3.0
* Support Sunspot grouping

### v0.2.0
* Allow setting of pagination options and calculate dependent values accordingly

### v0.1.0
* Initial working release


## License

The gem is available as free and open source software under the terms of the
[MIT License](http://opensource.org/licenses/MIT).

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sunspot-null_result-0.3.0 README.md