aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/message_spec.rb46
-rw-r--r--spec/messages_spec.rb6
2 files changed, 49 insertions, 3 deletions
diff --git a/spec/message_spec.rb b/spec/message_spec.rb
new file mode 100644
index 0000000..5564d34
--- /dev/null
+++ b/spec/message_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'rspec'
+require_relative '../lib/chotto/message'
+require_relative '../lib/chotto/helpers'
+
+RSpec.describe Chotto::Message do
+ let(:tags) { [] }
+ let(:msg) { double('Notmuch::Message', tags: tags) }
+
+ let(:subject) { Chotto::Message.new(msg: msg) }
+
+ it 'reads headers' do
+ expect(msg).to receive(:header).with('A-Header')
+
+ subject.a_header
+ end
+
+ describe 'tags' do
+ it 'keeps tags state in memory' do
+ subject.tags << 'tag'
+ expect(subject.tags).to match ['tag']
+
+ subject.tags << 'tag2'
+ expect(subject.tags).to match %w[tag tag2]
+ end
+
+ it 'allows to overwritte entire tags array' do
+ subject.tags = [1, 2, 3, 4]
+ expect(subject.tags).to match [1, 2, 3, 4]
+ end
+ end
+
+ describe 'save!' do
+ let(:tags) { [1, 2, 3] }
+ it 'saves current tag array to db' do
+ expect(msg).to receive(:remove_all_tags)
+ tags.each do |tag|
+ expect(msg).to receive(:add_tag).with(tag)
+ end
+
+ subject.tags = tags
+ subject.save!
+ end
+ end
+end
diff --git a/spec/messages_spec.rb b/spec/messages_spec.rb
index 6a84bc3..ec43379 100644
--- a/spec/messages_spec.rb
+++ b/spec/messages_spec.rb
@@ -1,10 +1,10 @@
# frozen_string_literal: true
require 'rspec'
-require_relative '../lib/some/messages'
+require_relative '../lib/chotto/messages'
-RSpec.describe Some::Messages do
- let(:subject) { Some::Messages.new }
+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)') }