FIX: Partial reply key search in email sent logs.
Follow up to c85b9c6ed3
This commit is contained in:
parent
35b59cfa78
commit
e9b2018bc8
|
@ -32,7 +32,7 @@ class Admin::EmailController < Admin::AdminController
|
|||
|
||||
if params[:reply_key].present?
|
||||
email_logs = email_logs.where(
|
||||
"CAST (post_reply_keys.reply_key AS VARCHAR) ILIKE ?", "%#{params[:reply_key]}%"
|
||||
"post_reply_keys.reply_key::TEXT ILIKE ?", "%#{params[:reply_key]}%"
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -73,10 +73,6 @@ class EmailLog < ActiveRecord::Base
|
|||
.first
|
||||
end
|
||||
|
||||
def bounce_key
|
||||
super&.delete('-')
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# == Schema Information
|
||||
|
|
|
@ -8,12 +8,8 @@ class PostReplyKey < ActiveRecord::Base
|
|||
validates :user_id, presence: true
|
||||
validates :reply_key, presence: true
|
||||
|
||||
def reply_key
|
||||
super&.delete('-')
|
||||
end
|
||||
|
||||
def self.generate_reply_key
|
||||
SecureRandom.hex(16)
|
||||
SecureRandom.uuid
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -12,6 +12,6 @@ class EmailLogSerializer < ApplicationSerializer
|
|||
end
|
||||
|
||||
def reply_key
|
||||
@options[:reply_keys][[object.post_id, object.user_id]].delete("-")
|
||||
@options[:reply_keys][[object.post_id, object.user_id]]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -103,8 +103,7 @@ describe EmailLog do
|
|||
.pluck("bounce_key::text")
|
||||
.first
|
||||
|
||||
expect(raw_key).to_not eq(hex)
|
||||
expect(raw_key.delete('-')).to eq(hex)
|
||||
expect(raw_key).to eq(hex)
|
||||
expect(EmailLog.find(email_log.id).bounce_key).to eq(hex)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require 'rails_helper'
|
|||
RSpec.describe PostReplyKey do
|
||||
describe "#reply_key" do
|
||||
it "should format the reply_key correctly" do
|
||||
hex = SecureRandom.hex
|
||||
hex = SecureRandom.uuid
|
||||
post_reply_key = Fabricate(:post_reply_key,
|
||||
reply_key: hex
|
||||
)
|
||||
|
@ -12,8 +12,7 @@ RSpec.describe PostReplyKey do
|
|||
.pluck("reply_key::text")
|
||||
.first
|
||||
|
||||
expect(raw_key).to_not eq(hex)
|
||||
expect(raw_key.delete('-')).to eq(hex)
|
||||
expect(raw_key).to eq(hex)
|
||||
expect(PostReplyKey.find(post_reply_key.id).reply_key).to eq(hex)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -58,6 +58,32 @@ describe Admin::EmailController do
|
|||
expect(log["id"]).to eq(email_log.id)
|
||||
expect(log["reply_key"]).to eq(post_reply_key.reply_key)
|
||||
end
|
||||
|
||||
it 'should be able to filter by reply key' do
|
||||
email_log_2 = Fabricate(:email_log, post: post)
|
||||
|
||||
post_reply_key_2 = Fabricate(:post_reply_key,
|
||||
post: post,
|
||||
user: email_log_2.user,
|
||||
reply_key: "2d447423-c625-4fb9-8717-ff04ac60eee8"
|
||||
)
|
||||
|
||||
[
|
||||
"17-ff04",
|
||||
"2d447423-c625-4fb9-8717-ff04ac60eee8"
|
||||
].each do |reply_key|
|
||||
get "/admin/email/sent.json", params: {
|
||||
reply_key: reply_key
|
||||
}
|
||||
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
logs = JSON.parse(response.body)
|
||||
|
||||
expect(logs.size).to eq(1)
|
||||
expect(logs.first["reply_key"]).to eq(post_reply_key_2.reply_key)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#skipped' do
|
||||
|
|
Loading…
Reference in New Issue