-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: guessed mail don't go to holding pen
Now, the 'Guessing' mechanism will be used when a mail is received. If there is only one guess produced by this mechanism, then the mail will go straight to that guess's IR
- Loading branch information
1 parent
c41bf9c
commit 1577b4c
Showing
9 changed files
with
327 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
require 'text' | ||
|
||
## | ||
# A guess at which info request a incoming message should be associated to | ||
# | ||
class Guess | ||
attr_reader :info_request, :components | ||
|
||
def initialize(info_request, **components) | ||
@info_request = info_request | ||
@components = components | ||
end | ||
|
||
def [](key) | ||
components[key] | ||
end | ||
|
||
def id_score | ||
return 1 unless self[:id] | ||
similarity(self[:id], info_request.id) | ||
end | ||
|
||
def idhash_score | ||
return 1 unless self[:idhash] | ||
similarity(self[:idhash], info_request.idhash) | ||
end | ||
|
||
def ==(other) | ||
info_request == other.info_request && components == other.components | ||
end | ||
|
||
def match_method | ||
components.keys.first | ||
end | ||
|
||
private | ||
|
||
def similarity(a, b) | ||
Text::WhiteSimilarity.similarity(a.to_s, b.to_s) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,26 +127,6 @@ | |
expect(page).to have_content "Only the authority can reply to this request" | ||
end | ||
end | ||
|
||
it "guesses a misdirected request" do | ||
info_request = FactoryBot.create(:info_request, | ||
allow_new_responses_from: 'authority_only', | ||
handle_rejected_responses: 'holding_pen') | ||
mail_to = "request-#{info_request.id}[email protected]" | ||
receive_incoming_mail('incoming-request-plain.email', email_to: mail_to) | ||
interesting_email = last_holding_pen_mail | ||
|
||
# now we add another message to the queue, which we're not interested in | ||
receive_incoming_mail('incoming-request-plain.email', | ||
email_to: info_request.incoming_email, | ||
email_from: "") | ||
expect(holding_pen_messages.length).to eq(2) | ||
using_session(@admin) do | ||
visit admin_raw_email_path interesting_email | ||
expect(page).to have_content "Could not identify the request" | ||
expect(page).to have_content info_request.title | ||
end | ||
end | ||
end | ||
|
||
describe 'generating an upload url' do | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Guess do | ||
let(:info_request) do | ||
FactoryBot.create(:info_request, id: 100, idhash: '4e637388') | ||
end | ||
|
||
describe 'with a subject line given' do | ||
let(:guess) { described_class.new(info_request, subject: 'subject_line') } | ||
|
||
it 'returns an id_score of 1' do | ||
Check warning on line 11 in spec/models/guess_spec.rb GitHub Actions / build
|
||
expect(guess.id_score).to eq(1) | ||
end | ||
|
||
it 'returns an idhash_score of 1' do | ||
expect(guess.idhash_score).to eq(1) | ||
end | ||
end | ||
|
||
describe 'with an id given' do | ||
let(:guess_1) { described_class.new(info_request, id: 100) } | ||
let(:guess_2) { described_class.new(info_request, id: 456) } | ||
let(:guess_3) { described_class.new(info_request, id: 109) } | ||
|
||
it 'returns an id_score of 1 when it is correct' do | ||
expect(guess_1.id_score).to eq(1.0) | ||
end | ||
|
||
it 'returns an id_score of 0 when there is no similarity' do | ||
expect(guess_2.id_score).to eq(0.0) | ||
end | ||
|
||
it 'returns a value between 0 and 1 when there is some similarity' do | ||
expect(guess_3.id_score).to be_between(0, 1).exclusive | ||
end | ||
end | ||
|
||
describe 'with an idhash given' do | ||
let(:guess_1) { described_class.new(info_request, idhash: '4e637388') } | ||
let(:guess_2) { described_class.new(info_request, idhash: '12345678') } | ||
let(:guess_3) { described_class.new(info_request, idhash: '4e637399') } | ||
|
||
it 'returns an idhash_score of 1 when it is correct' do | ||
expect(guess_1.idhash_score).to eq(1.0) | ||
end | ||
|
||
it 'returns an idhash_score of 0 when there is no similarity' do | ||
expect(guess_2.idhash_score).to eq(0.0) | ||
end | ||
|
||
it 'returns a value between 0 and 1 when there is some similarity' do | ||
expect(guess_3.idhash_score).to be_between(0, 1).exclusive | ||
end | ||
end | ||
end |
Oops, something went wrong.