From 2da68fa1779b3c6f680a00413520b53288fb4bd2 Mon Sep 17 00:00:00 2001 From: Ryan Lue Date: Tue, 19 Jun 2018 11:53:00 +0800 Subject: [PATCH] Add minimal test for existing followup search feature --- app/models/channel/email_parser.rb | 2 +- spec/models/channel/email_parser_spec.rb | 34 ++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 spec/models/channel/email_parser_spec.rb diff --git a/app/models/channel/email_parser.rb b/app/models/channel/email_parser.rb index ad91a04ee..a475bc463 100644 --- a/app/models/channel/email_parser.rb +++ b/app/models/channel/email_parser.rb @@ -134,7 +134,7 @@ returns UserInfo.current_user_id = 1 filters = {} Setting.where(area: 'Postmaster::PreFilter').order(:name).each do |setting| - filters[setting.name] = Kernel.const_get(Setting.get(setting.name)) + filters[setting.name] = Setting.get(setting.name).constantize end filters.each do |key, backend| Rails.logger.debug { "run postmaster pre filter #{key}: #{backend}" } diff --git a/spec/models/channel/email_parser_spec.rb b/spec/models/channel/email_parser_spec.rb new file mode 100644 index 000000000..85b1017c0 --- /dev/null +++ b/spec/models/channel/email_parser_spec.rb @@ -0,0 +1,34 @@ +require 'rails_helper' + +RSpec.describe Channel::EmailParser, type: :model do + let(:ticket) { create(:ticket) } + let(:mail_file) { Rails.root.join('test', 'data', 'mail', 'mail001.box') } + let(:raw_mail) { File.read(mail_file).sub(/(?<=^Subject: ).*$/, test_string) } + let(:test_string) do + Setting.get('ticket_hook') + Setting.get('ticket_hook_divider') + ticket.number + end + + describe '#process' do + context 'when email subject contains ticket reference' do + it 'adds message to ticket' do + expect { described_class.new.process({}, raw_mail) } + .to change { ticket.articles.length } + end + end + + context 'when configured to search body' do + before { Setting.set('postmaster_follow_up_search_in', 'body') } + + context 'when body contains ticket reference' do + context 'in visible text' do + let(:raw_mail) { File.read(mail_file).sub(/Hallo =\nMartin,(?=)/, test_string) } + + it 'adds message to ticket' do + expect { described_class.new.process({}, raw_mail) } + .to change { ticket.articles.length } + end + end + end + end + end +end