Sha256: 12a79c0757748acfaa8b0ed1904ef004edbd151939cf214a82306a9009c49646

Contents?: true

Size: 1.12 KB

Versions: 2

Compression:

Stored size: 1.12 KB

Contents

# frozen_string_literal: true

RSpec.describe Pursuit::SearchTermParser do
  subject(:parser) { described_class.new(query, keys: keys) }

  let(:keys) { %w[title description rating stock_status] }
  let(:query) do
    "plain title!='Socks' description*=\"green\" stock_status==in_stock shirt rating>=2 other*=thing rating<5"
  end

  describe '#unkeyed_term' do
    subject(:unkeyed_term) { parser.unkeyed_term }

    it 'is expected to eq the correct unkeyed term' do
      expect(unkeyed_term).to eq('plain shirt other*=thing')
    end
  end

  describe '#keyed_terms' do
    subject(:keyed_terms) { parser.keyed_terms }

    it 'is expected to eq the correct keyed terms' do
      expect(keyed_terms).to eq(
        [
          Pursuit::SearchTermParser::KeyedTerm.new('title', '!=', 'Socks'),
          Pursuit::SearchTermParser::KeyedTerm.new('description', '*=', 'green'),
          Pursuit::SearchTermParser::KeyedTerm.new('stock_status', '==', 'in_stock'),
          Pursuit::SearchTermParser::KeyedTerm.new('rating', '>=', '2'),
          Pursuit::SearchTermParser::KeyedTerm.new('rating', '<', '5')
        ]
      )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
pursuit-0.4.5 spec/lib/pursuit/search_term_parser_spec.rb
pursuit-0.4.3 spec/lib/pursuit/search_term_parser_spec.rb