Skip to content
This repository has been archived by the owner on Mar 6, 2024. It is now read-only.

Commit

Permalink
fix: email texts for tokens created on consultation creation (#47)
Browse files Browse the repository at this point in the history
* fix: email texts for tokens created on consultation creation

* chore: bundle updated

* fix: remove HTML tags from default tokens email
  • Loading branch information
darccio committed Feb 23, 2023
1 parent 6f7bd3c commit 4ceb4ba
Show file tree
Hide file tree
Showing 12 changed files with 42 additions and 27 deletions.
20 changes: 10 additions & 10 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ GEM
net-smtp (0.3.3)
net-protocol
nio4r (2.5.8)
nokogiri (1.14.1)
nokogiri (1.14.2)
mini_portile2 (~> 2.8.0)
racc (~> 1.4)
paper_trail (14.0.0)
Expand Down Expand Up @@ -232,26 +232,26 @@ GEM
redcarpet (3.6.0)
redis (5.0.6)
redis-client (>= 0.9.0)
redis-client (0.12.1)
redis-client (0.12.2)
connection_pool
regexp_parser (2.7.0)
request_store (1.5.1)
rack (>= 1.4)
rexml (3.2.5)
rubocop (1.45.1)
rubocop (1.46.0)
json (~> 2.3)
parallel (~> 1.10)
parser (>= 3.2.0.0)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.24.1, < 2.0)
rubocop-ast (>= 1.26.0, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.26.0)
parser (>= 3.2.1.0)
rubocop-minitest (0.27.0)
rubocop (>= 0.90, < 2.0)
rubocop-minitest (0.28.0)
rubocop (>= 1.39, < 2.0)
rubocop-performance (1.16.0)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
Expand All @@ -261,7 +261,7 @@ GEM
rubocop (>= 1.33.0, < 2.0)
ruby-progressbar (1.11.0)
rubyzip (2.3.2)
selenium-webdriver (4.8.0)
selenium-webdriver (4.8.1)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
Expand Down Expand Up @@ -290,9 +290,9 @@ GEM
actionpack (>= 5.2)
activesupport (>= 5.2)
sprockets (>= 3.0.0)
sqlite3 (1.6.0)
sqlite3 (1.6.1)
mini_portile2 (~> 2.8.0)
store_model (1.5.1)
store_model (1.6.0)
activerecord (>= 5.2)
sucker_punch (3.1.0)
concurrent-ruby (~> 1.0)
Expand All @@ -301,7 +301,7 @@ GEM
thor (1.2.1)
tilt (2.0.11)
timecop (0.9.6)
timeout (0.3.1)
timeout (0.3.2)
translate_enum (0.2.0)
activesupport
translation (1.35)
Expand Down
12 changes: 11 additions & 1 deletion app/mailers/consultations_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ class ConsultationsMailer < ApplicationMailer
def default_tokens_email(to, tokens)
@tokens = tokens

mail(to:, template_name: 'default_tokens_email', subject: I18n.t('consultations_mailer.default_tokens_email.subject')) do |format|
mail(to:, template_name: 'default_tokens_email', subject:) do |format|
format.text
end
end

private

def subject
"Tokens created for #{consultation.title}"
end

def consultation
@consultation ||= @tokens.first.consultation
end
end
4 changes: 2 additions & 2 deletions app/views/consultations_mailer/default_tokens_email.text.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<%= t('application_mailer.greeting') %>,

<%= t('consultations_mailer.default_tokens_email').strip %>
<%= t('consultations_mailer.default_tokens_email.body').strip %>
<% @tokens.each do |token| %>
- <%= t('consultations.consultation_token_created', token:, role: token.translated_role) %>
- <%= sanitize t('consultations.consultation_token_created', token:, role: token.translated_role), tags: [] %>
<% end %>
<%= t('application_mailer.complimentary_close', recipient: Rails.configuration.x.asembleo.title).strip %>
2 changes: 1 addition & 1 deletion config/locales/.translation_io
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
# ignore the conflicts and "sync" again, it will fix this file for you.

---
timestamp: 1676137604
timestamp: 1677182682
8 changes: 4 additions & 4 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,10 @@ en:
consultation_closed: The consultation is closed.
consultation_deleted: Consultation deleted.
consultations_mailer:
default_tokens_email: |
Hello,
The following tokens were created:
default_tokens_email:
subject: Tokens created for %{consultation.title}
body: |
The following tokens were created:
errors:
bad_request: Bad request
you_can_only_choose_up_to: You can only choose up to %{e_max_options} options.
Expand Down
4 changes: 2 additions & 2 deletions config/locales/gettext/app.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ msgid ""
msgstr ""
"Project-Id-Version: asembleo 1.0\n"
"Report-Msgid-Bugs-To: contact@translation.io\n"
"POT-Creation-Date: 2023-02-11 18:46+0100\n"
"PO-Revision-Date: 2023-02-11 18:46+0100\n"
"POT-Creation-Date: 2023-02-23 21:04+0100\n"
"PO-Revision-Date: 2023-02-23 21:04+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
"Language: \n"
Expand Down
Binary file modified config/locales/gettext/en/LC_MESSAGES/app.mo
Binary file not shown.
4 changes: 2 additions & 2 deletions config/locales/gettext/en/app.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: asembleo 1.0\n"
"Report-Msgid-Bugs-To: contact@translation.io\n"
"POT-Creation-Date: 2023-02-11 18:46+0100\n"
"PO-Revision-Date: 2023-02-11 18:46+0100\n"
"POT-Creation-Date: 2023-02-23 21:04+0100\n"
"PO-Revision-Date: 2023-02-23 21:04+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: English\n"
"Language: en\n"
Expand Down
Binary file modified config/locales/gettext/es/LC_MESSAGES/app.mo
Binary file not shown.
4 changes: 2 additions & 2 deletions config/locales/gettext/es/app.po
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ msgid ""
msgstr ""
"Project-Id-Version: asembleo 1.0\n"
"Report-Msgid-Bugs-To: contact@translation.io\n"
"POT-Creation-Date: 2023-02-11 18:46+0100\n"
"PO-Revision-Date: 2023-02-11 18:46+0100\n"
"POT-Creation-Date: 2023-02-23 21:04+0100\n"
"PO-Revision-Date: 2023-02-23 21:04+0100\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: Spanish\n"
"Language: es\n"
Expand Down
3 changes: 3 additions & 0 deletions config/locales/translation.es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,7 @@ es:
upload:
token:
exhausted:
footer:
consultations:
consultation_token_created:
consultation_create:
Expand Down Expand Up @@ -361,3 +362,5 @@ es:
complimentary_close:
consultations_mailer:
default_tokens_email:
subject:
body:
8 changes: 5 additions & 3 deletions test/mailers/consultations_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@
class ConsultationsMailerTest < ActionMailer::TestCase
test 'generate default tokens mail' do
to = 'user@coopanio.com'
tokens = [create(:token, role: :admin), create(:token, role: :manager)]
consultation = create(:consultation)
tokens = [create(:token, consultation:, role: :admin), create(:token, consultation:, role: :manager)]
email = ConsultationsMailer.default_tokens_email(to, tokens)

assert_equal [to], email.to
assert_includes email.body.to_s, "- Admin token is <strong>#{tokens.first}</strong>."
assert_includes email.body.to_s, "- Manager token is <strong>#{tokens.second}</strong>."
assert_equal "Tokens created for #{consultation.title}", email.subject
assert_includes email.body.to_s, "- Admin token is #{tokens.first}."
assert_includes email.body.to_s, "- Manager token is #{tokens.second}."
assert_includes email.body.to_s, "Thanks,\n#{Rails.configuration.x.asembleo.title}"
end
end

0 comments on commit 4ceb4ba

Please sign in to comment.