diff options
Diffstat (limited to 'spec/lib')
-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 |
3 files changed, 33 insertions, 4 deletions
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 |