-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #463 from IgorMonardez/issue_405
Issue 405
- Loading branch information
Showing
9 changed files
with
90 additions
and
6 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 |
---|---|---|
|
@@ -7,13 +7,16 @@ | |
class CustomVariable < ApplicationRecord | ||
has_paper_trail | ||
|
||
SAPOS_MAIL = "[email protected]" | ||
|
||
VARIABLES = { | ||
"single_advisor_points" => :text, | ||
"multiple_advisor_points" => :text, | ||
"program_level" => :text, | ||
"identity_issuing_country" => :text, | ||
"class_schedule_text" => :text, | ||
"redirect_email" => :text, | ||
"reply_to" => :text, | ||
"notification_footer" => :text, | ||
"minimum_grade_for_approval" => :text, | ||
"grade_of_disapproval_for_absence" => :text, | ||
|
@@ -59,6 +62,12 @@ def self.redirect_email | |
config.blank? ? nil : (config.value || "") | ||
end | ||
|
||
def self.reply_to | ||
default = ActionMailer::Base.default[:from] | ||
config = CustomVariable.find_by_variable(:reply_to) | ||
config.blank? ? default : (config.value || default) | ||
end | ||
|
||
def self.notification_footer | ||
config = CustomVariable.find_by_variable(:notification_footer) | ||
config.blank? ? "" : config.value | ||
|
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
8 changes: 8 additions & 0 deletions
8
db/migrate/20240517150433_add_reply_to_to_notification_logs.rb
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,8 @@ | ||
class AddReplyToToNotificationLogs < ActiveRecord::Migration[7.0] | ||
def up | ||
add_column :notification_logs, :reply_to, :string, limit: 255 | ||
end | ||
def down | ||
remove_column :notification_logs, :reply_to | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
{ description: "País padrão de emissão da identidade", variable: "identity_issuing_country", value: "Brasil" }, | ||
{ description: "Texto no final do quadro de horários", variable: "class_schedule_text", value: "Alunos interessados em cursar disciplinas de Tópicos Avançados devem consultar os respectivos professores antes da matrícula." }, | ||
{ description: "E-mail de redirecionamento para as notificações", variable: "redirect_email", value: "" }, | ||
{ description: "E-mail das resposta de emails automáticos", variable: "reply_to", value: "[email protected]"}, | ||
{ description: "Texto de rodapé da notificação", | ||
variable: "notification_footer", | ||
value: <<~TEXT | ||
|
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 |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
variable: "single_advisor_points" | ||
) | ||
end | ||
let(:default_from) { ActionMailer::Base.default[:from]} | ||
subject { custom_variable } | ||
describe "Validations" do | ||
it { should be_valid } | ||
|
@@ -136,6 +137,31 @@ | |
end | ||
end | ||
|
||
context "reply_to" do | ||
it "should return default value when there is no variable defined" do | ||
config = CustomVariable.find_by_variable(:reply_to) | ||
config.delete unless config.nil? | ||
|
||
expect(CustomVariable.reply_to).to eq(default_from) | ||
end | ||
|
||
it "should return default value when the value is nil" do | ||
config = CustomVariable.find_by_variable(:reply_to) | ||
config.delete unless config.nil? | ||
@destroy_later << CustomVariable.create(variable: :reply_to, value: nil) | ||
|
||
expect(CustomVariable.reply_to).to eq(default_from) | ||
end | ||
|
||
it "should return value when the values is defined" do | ||
config = CustomVariable.find_by_variable(:reply_to) | ||
config.delete unless config.nil? | ||
@destroy_later << CustomVariable.create(variable: :reply_to, value: "[email protected]") | ||
|
||
expect(CustomVariable.reply_to).to eq("[email protected]") | ||
end | ||
end | ||
|
||
context "notification_footer" do | ||
it "should return '' when there is no variable defined" do | ||
config = CustomVariable.find_by_variable(:notification_footer) | ||
|
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
subject: "Title", | ||
) | ||
end | ||
let(:default_from) { ActionMailer::Base.default[:from] } | ||
subject { email_template } | ||
describe "Validations" do | ||
it { should be_valid } | ||
|
@@ -93,7 +94,7 @@ | |
} | ||
template.update_mailer_headers(headers) | ||
expect(headers).to eq({ | ||
to: "a", subject: "b", body: "c", | ||
to: "a", subject: "b", body: "c", reply_to: default_from, | ||
skip_message: true, skip_footer: true | ||
}) | ||
end | ||
|
@@ -106,11 +107,38 @@ | |
} | ||
template.update_mailer_headers(headers) | ||
expect(headers).to eq({ | ||
to: "[email protected]", subject: "b (Originalmente para a)", body: "c", | ||
to: "[email protected]", subject: "b (Originalmente para a)", body: "c", reply_to: default_from, | ||
skip_message: false, skip_footer: true, skip_redirect: true | ||
}) | ||
CustomVariable.delete_all | ||
end | ||
it "should have 'reply_to' equal to variable reply_to attribute when variable is set" do | ||
FactoryBot.create(:custom_variable, variable: "reply_to", value: "[email protected]") | ||
template = EmailTemplate.load_template("accomplishments:email_to_advisor") | ||
|
||
headers = { | ||
to: "a", subject: "b", body: "c" | ||
} | ||
template.update_mailer_headers(headers) | ||
expect(headers).to eq({ | ||
reply_to: "[email protected]", subject: "b", body: "c", to: "a", | ||
skip_message: false, skip_footer: true | ||
}) | ||
CustomVariable.delete_all | ||
end | ||
it "should have 'reply_to' equal to default[:from] when variable isnt set" do | ||
template = EmailTemplate.load_template("accomplishments:email_to_advisor") | ||
|
||
headers = { | ||
to: "a", subject: "b", body: "c" | ||
} | ||
template.update_mailer_headers(headers) | ||
expect(headers).to eq({ | ||
reply_to: default_from, subject: "b", body: "c", to: "a", | ||
skip_message: false, skip_footer: true | ||
}) | ||
CustomVariable.delete_all | ||
end | ||
end | ||
describe "prepare_message" do | ||
it "should use the ERB formating in all fields" do | ||
|
@@ -122,6 +150,7 @@ | |
to: "t1", | ||
subject: "s1", | ||
body: "b1", | ||
reply_to: default_from, | ||
skip_footer: true, | ||
skip_message: true, | ||
}) | ||
|