-
Notifications
You must be signed in to change notification settings - Fork 0
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 #123 from TreinaDev/feature/lider-recebe-email-de-…
…solicitacao Feature/lider recebe email de solicitacao
- Loading branch information
Showing
6 changed files
with
73 additions
and
4 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,11 @@ | ||
class ProposalMailer < ApplicationMailer | ||
default from: '[email protected]' | ||
|
||
def notify_leader | ||
@proposal = params[:proposal] | ||
@project = @proposal.project | ||
@leader = @project.user | ||
|
||
mail to: @leader.email, subject: t('.subject') | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<main> | ||
<h1><%= t '.project_received_a_new_proposal', project_title: @project.title %> </h1> | ||
|
||
<p><%= t '.proposer', email: @proposal.email %></p> | ||
<p><%= t '.message', message: @proposal.message %></p> | ||
|
||
<%= link_to t('.view_proposal'), | ||
project_portfoliorrr_profile_url(@project, @proposal.profile_id) %> | ||
</main> | ||
|
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 @@ | ||
pt-BR: | ||
proposal_mailer: | ||
notify_leader: | ||
subject: Nova solicitação para seu projeto! | ||
project_received_a_new_proposal: Seu projeto %{project_title} recebeu uma nova solicitação! | ||
proposer: "Solicitante: %{email}" | ||
message: "Mensagem: %{message}" | ||
view_proposal: Visualizar solicitação |
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,25 @@ | ||
require 'rails_helper' | ||
|
||
RSpec.describe ProposalMailer, type: :mailer do | ||
describe '#notify_leader' do | ||
it 'envia email para o líder do projeto com sucesso' do | ||
leader = create :user, email: '[email protected]' | ||
project = create :project, user: leader, | ||
title: 'Canal de Youtube' | ||
proposal = create :proposal, project:, | ||
message: 'Gostaria de participar', | ||
email: '[email protected]' | ||
|
||
mail = ProposalMailer.with(proposal:).notify_leader | ||
|
||
expect(mail.to).to include '[email protected]' | ||
expect(mail.subject).to include 'Nova solicitação para seu projeto!' | ||
expect(mail.body.encoded).to include 'Seu projeto Canal de Youtube recebeu uma nova solicitação!' | ||
expect(mail.body.encoded).to include 'Solicitante: [email protected]' | ||
expect(mail.body.encoded).to include 'Mensagem: Gostaria de participar' | ||
link = project_portfoliorrr_profile_url project, proposal.profile_id | ||
button = "<a href=\"#{link}\">Visualizar solicitação</a>" | ||
expect(mail.body.encoded).to include button | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
message: 'Gostaria de participar!', | ||
email: '[email protected]' | ||
} } | ||
mail = double 'mail', deliver: true | ||
mailer = double 'ProposalMailer' | ||
allow(ProposalMailer).to receive(:with).and_return mailer | ||
allow(mailer).to receive(:notify_leader).and_return mail | ||
|
||
post(api_v1_proposals_path, params:) | ||
|
||
|
@@ -26,6 +30,7 @@ | |
expect(Proposal.last.message).to eq 'Gostaria de participar!' | ||
expect(Proposal.last.email).to eq '[email protected]' | ||
expect(Proposal.last.status).to eq 'pending' | ||
expect(mail).to have_received :deliver | ||
end | ||
|
||
context 'sem sucesso' do | ||
|
@@ -40,13 +45,18 @@ | |
profile_id: contributor_portfoliorrr_profile_id, | ||
email: '[email protected]' | ||
} } | ||
mail = double 'mail', deliver: true | ||
mailer = double 'ProposalMailer' | ||
allow(ProposalMailer).to receive(:with).and_return mailer | ||
allow(mailer).to receive(:notify_leader).and_return mail | ||
|
||
post(api_v1_proposals_path, params:) | ||
|
||
expect(Proposal.count).to eq 0 | ||
json_response = JSON.parse(response.body) | ||
expect(response).to have_http_status :conflict | ||
expect(json_response['errors']).to eq ['Usuário já faz parte deste projeto'] | ||
expect(mail).not_to have_received :deliver | ||
end | ||
|
||
it 'se já existe uma solicitação pendente' do | ||
|