From c2623f1aa3638c988026b28f6a4131df6c61e0c6 Mon Sep 17 00:00:00 2001 From: mms Date: Fri, 22 Nov 2024 23:35:51 +0100 Subject: feat: allow to search for thread --- spec/lib/message_spec.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'spec/lib/message_spec.rb') 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 -- cgit v1.2.3