diff options
author | mms <git@sapka.me> | 2024-11-22 23:35:51 +0100 |
---|---|---|
committer | mms <git@sapka.me> | 2024-11-22 23:37:42 +0100 |
commit | c2623f1aa3638c988026b28f6a4131df6c61e0c6 (patch) | |
tree | c9a685d2997214bcb90f3659febc56f7ac85cbbb /spec | |
parent | 64ab548e16fdc8fa862e2b432464f3d67f5d9db8 (diff) |
feat: allow to search for thread
Diffstat (limited to 'spec')
-rw-r--r-- | spec/.chotto_spec.rb.swp | bin | 12288 -> 0 bytes | |||
-rw-r--r-- | spec/chotto_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/message_spec.rb | 21 | ||||
-rw-r--r-- | spec/lib/messages_spec.rb | 11 | ||||
-rw-r--r-- | spec/lib/ruleset_spec.rb | 5 |
5 files changed, 35 insertions, 7 deletions
diff --git a/spec/.chotto_spec.rb.swp b/spec/.chotto_spec.rb.swp Binary files differdeleted file mode 100644 index f54f5fd..0000000 --- a/spec/.chotto_spec.rb.swp +++ /dev/null diff --git a/spec/chotto_spec.rb b/spec/chotto_spec.rb index 41d949c..7593a48 100644 --- a/spec/chotto_spec.rb +++ b/spec/chotto_spec.rb @@ -12,7 +12,6 @@ describe Chotto do before do $db_double = db_double # we need to access this double within block evaled elsewhere - p $db_double allow(db_double).to receive(:new).with('/path', mode: Notmuch::MODE_READ_WRITE).and_return(db_instance_double) allow(db_instance_double).to receive(:query).with(' (from:baltar@galactica.com)').and_return(db_query_double) @@ -36,7 +35,7 @@ describe Chotto do end it 'sends the rules to Notmuch - scenario 1' do - expect(message_double).to receive(:tags).and_return([]) + expect(message_double).to receive(:tags) expect(message_double).to receive(:header).with('Subject').and_return('Number Six') expect(message_double).to receive(:remove_all_tags) expect(message_double).to receive(:add_tag).with('todo') @@ -46,7 +45,7 @@ describe Chotto do end it 'sends the rules to Notmuch - scenario 2' do - expect(message_double).to receive(:tags).and_return([]) + expect(message_double).to receive(:tags) expect(message_double).to receive(:header).with('Subject').and_return('Boomer') expect(message_double).to receive(:remove_all_tags) expect(message_double).to receive(:add_tag).with('spam') diff --git a/spec/lib/message_spec.rb b/spec/lib/message_spec.rb index 2605117..8994216 100644 --- a/spec/lib/message_spec.rb +++ b/spec/lib/message_spec.rb @@ -7,8 +7,9 @@ require_relative '../../lib/chotto/helpers' RSpec.describe Chotto::Message do let(:tags) { [] } let(:msg) { double('Notmuch::Message', tags: tags) } + let(:db_double) { double('Chotto::Database') } - let(:subject) { Chotto::Message.new(msg: msg) } + let(:subject) { Chotto::Message.new(msg: msg, db: db_double) } it 'reads headers' do expect(msg).to receive(:header).with('A-Header') @@ -43,4 +44,22 @@ RSpec.describe Chotto::Message do subject.save! end end + + describe 'thread' do + let(:thread_id) { '1' } + let(:tester) { double } + let(:msg_in_thread) { double('Chotto:Message') } + + it 'fetches messages for thread' do + expect(msg).to receive(:thread_id).and_return(thread_id) + expect(db_double).to receive(:search_messages).with("thread:#{thread_id}").and_return([msg_in_thread]) + expect(msg_in_thread).to receive(:tags) + + expect(tester).to receive(:test).with(an_instance_of(Chotto::Message)) + + subject.thread.each do |msg| + tester.test(msg) + end + end + end end diff --git a/spec/lib/messages_spec.rb b/spec/lib/messages_spec.rb index 79551b7..4abc2c6 100644 --- a/spec/lib/messages_spec.rb +++ b/spec/lib/messages_spec.rb @@ -4,7 +4,7 @@ require 'rspec' require_relative '../../lib/chotto/messages' RSpec.describe Chotto::Messages do - let(:subject) { Chotto::Messages.new(db: double('Notmuch')) } + let(:subject) { Chotto::Messages.new(db: double('Notmuch'), only_new: false) } describe 'direct filters' do it { expect(subject.filter('from:baltar@battlestar.com').query_string).to eq(' (from:baltar@battlestar.com)') } @@ -74,4 +74,13 @@ RSpec.describe Chotto::Messages do it { expect(subject.filter('from:baltar@battlestar.com').newest_first.order).to eq('newest_first') } it { expect(subject.filter('from:baltar@battlestar.com').newest_first.oldest_first.order).to eq('oldest_first') } end + + context 'with only_new' do + let(:subject) { Chotto::Messages.new(db: double('Notmuch'), only_new: true) } + + it 'prepends the filter with tag:new' do + expect(subject.filter('from:baltar@battlestar.com').query_string) + .to eq('tag:new AND ( (from:baltar@battlestar.com))') + end + end end diff --git a/spec/lib/ruleset_spec.rb b/spec/lib/ruleset_spec.rb index e7a6904..7b77e3e 100644 --- a/spec/lib/ruleset_spec.rb +++ b/spec/lib/ruleset_spec.rb @@ -7,18 +7,19 @@ require_relative '../../lib/chotto/messages' RSpec.describe Chotto::RuleSet do let(:db) { instance_double('Chotto::Database') } let(:messages) { double('Chotto::Messages', mth: true) } + let(:only_new) { true } let(:rule) do proc do messages.mth end end let(:subject) do - Chotto::RuleSet.new('a name', db, rule) + Chotto::RuleSet.new('a name', db, only_new, rule) end describe '#run' do it 'evaluates the run block' do - expect(Chotto::Messages).to receive(:new).with(db: db).and_return(messages) + expect(Chotto::Messages).to receive(:new).with(db: db, only_new: true).and_return(messages) expect(messages).to receive(:mth) subject.run |