aboutsummaryrefslogtreecommitdiff
path: root/spec/lib/messages_spec.rb
blob: 75509919915a24cfb0ea63c925ac1044c195fd3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# frozen_string_literal: true

require 'rspec'
require_relative '../../lib/chotto/messages'

RSpec.describe Chotto::Messages do
  let(:subject) { Chotto::Messages.new(db: double('Notmuch')) }

  describe 'direct filters' do
    it { expect(subject.filter('from:baltar@battlestar.com').query_string).to eq(' (from:baltar@battlestar.com)') }

    it {
      expect(subject.filter('from:baltar@battlestar.com').filter('ship:galactica').query_string)
        .to eq(' (from:baltar@battlestar.com) and (ship:galactica)')
    }
  end

  describe 'conjuction change' do
    it {
      expect(subject.filter('from:baltar@battlestar.com')
               .or.filter('ship:galactica').query_string).to eq(' (from:baltar@battlestar.com) or (ship:galactica)')
    }

    it {
      expect(subject.filter('from:baltar@battlestar.com')
               .or.filter('ship:galactica')
               .filter('hair:long').query_string)
        .to eq(' (from:baltar@battlestar.com) or (ship:galactica) or (hair:long)')
    }

    it {
      expect(subject.filter('from:baltar@battlestar.com')
               .or.filter('ship:galactica')
               .and.filter('hair:long').query_string)
        .to eq(' (from:baltar@battlestar.com) or (ship:galactica) and (hair:long)')
    }
  end

  describe 'hash filters' do
    context 'with singular values' do
      it { expect(subject.filter(from: 'baltar@battlestar.com').query_string).to eq(' (from:baltar@battlestar.com)') }

      it {
        expect(subject.filter(from: 'baltar@battlestar.com', ship: 'galactica').query_string)
          .to eq(' (from:baltar@battlestar.com) and (ship:galactica)')
      }

      it {
        expect(subject.or.filter(from: 'baltar@battlestar.com', ship: 'galactica').query_string)
          .to eq(' (from:baltar@battlestar.com) or (ship:galactica)')
      }
    end

    context 'with set of values' do
      it {
        expect(subject.filter(from: ['baltar@battlestar.com',
                                     'adama@battestar.com']).query_string)
          .to eq(' (from:baltar@battlestar.com) or (from:adama@battestar.com)')
      }
    end
  end

  context 'advanced filters' do
    it {
      expect(subject.filter(from: ['baltar@battlestar.com', 'adama@battestar.com'])
               .and.filter(ship: 'battlestar')
               .or.filter(ship: 'pegasus').query_string)
        .to eq(' (from:baltar@battlestar.com) or (from:adama@battestar.com) and (ship:battlestar) or (ship:pegasus)')
    }
  end
end