Sha256: eb46776c84a750daa38b3933e90e8507542927abf00370971e231d68c7d06c37

Contents?: true

Size: 1.23 KB

Versions: 15

Compression:

Stored size: 1.23 KB

Contents

# frozen_string_literal: true

require 'spec_helper'

describe ThinkingSphinx::Scopes do
  let(:model) {
    Class.new do
      include ThinkingSphinx::Scopes

      def self.search(query = nil, options = {})
        ThinkingSphinx::Search.new(query, options)
      end
    end
  }

  describe '#method_missing' do
    before :each do
      model.sphinx_scopes[:foo] = Proc.new { {:with => {:foo => :bar}} }
    end

    it "implements respond_to" do
      expect(model).to respond_to(:foo)
    end

    it "creates new search" do
      expect(model.foo.class).to eq(ThinkingSphinx::Search)
    end

    it "passes block result to constructor" do
      expect(model.foo.options[:with]).to eq({:foo => :bar})
    end

    it "passes non-scopes through to the standard method error call" do
      expect { model.bar }.to raise_error(NoMethodError)
    end
  end

  describe '#sphinx_scope' do
    it "saves the given block with a name" do
      model.sphinx_scope(:foo) { 27 }
      expect(model.sphinx_scopes[:foo].call).to eq(27)
    end
  end

  describe '#default_sphinx_scope' do
    it "gets and sets the default scope depending on the argument" do
      model.default_sphinx_scope :foo
      expect(model.default_sphinx_scope).to eq(:foo)
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
thinking-sphinx-5.6.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.5.1 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.5.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.4.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.3.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.2.1 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.2.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.1.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-5.0.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-4.4.1 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-4.4.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-4.3.2 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-4.3.1 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-4.3.0 spec/thinking_sphinx/scopes_spec.rb
thinking-sphinx-4.2.0 spec/thinking_sphinx/scopes_spec.rb