diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index c209ca6f7bfba28e0ba5703396f89d32bdd83ebd..1d8b132d1ec458207b1f6bdb62a4521081ee1762 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -32,7 +32,7 @@ test: stage: test script: - bundle exec rake db:migrate:reset RAILS_ENV=test - - rake spec:acceptance + - bundle exec rake spec:acceptance tags: - ruby - postgres diff --git a/app/controllers/v1/contacts_controller.rb b/app/controllers/v1/contacts_controller.rb index d1e589b425c6a77f931d9036f71b966822524c5d..37246084fa5b94dafe8f919c3f31d3d9e47952d2 100644 --- a/app/controllers/v1/contacts_controller.rb +++ b/app/controllers/v1/contacts_controller.rb @@ -18,6 +18,7 @@ class V1::ContactsController < ApplicationController def create @contact = Contact.new(contact_params) if @contact.save + ContactsMailer.new_contact_received(@contact).deliver_now render json: @contact, status: :created else render json: @contact.errors, status: :unprocessable_entity @@ -27,6 +28,7 @@ class V1::ContactsController < ApplicationController # PATCH/PUT v1/contacts/1 def update if @contact.update(contact_params) + ContactsMailer.contact_updated(@contact).deliver_now render json: @contact else render json: @contact.errors, status: :unprocessable_entity diff --git a/app/controllers/v1/suggestions_controller.rb b/app/controllers/v1/suggestions_controller.rb index b12c6d7078f53dfdf68a69ea4b47a5a0c150cee8..79dfacdbd296937fde2dc193358e1c7d5d1df857 100644 --- a/app/controllers/v1/suggestions_controller.rb +++ b/app/controllers/v1/suggestions_controller.rb @@ -19,6 +19,7 @@ class V1::SuggestionsController < ApplicationController @suggestion = Suggestion.new(suggestion_params) if @suggestion.save + SuggestionsMailer.new_suggestion_received(@suggestion).deliver_now render json: @suggestion, status: :created else render json: @suggestion.errors, status: :unprocessable_entity @@ -28,6 +29,7 @@ class V1::SuggestionsController < ApplicationController # PATCH/PUT v1/suggestions/1 def update if @suggestion.update(suggestion_params) + SuggestionsMailer.suggestion_updated(@suggestion).deliver_now render json: @suggestion else render json: @suggestion.errors, status: :unprocessable_entity diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239d139960190594225e0134fe1a5c05370..4ff71b5d33e509b5d1b306eb2b6dae019b0c95fa 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,5 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' - layout 'mailer' + default to: 'portalmec_tec@inf.ufpr.br' + default from: 'portalmec@inf.ufpr.br' + #layout 'mailer' end diff --git a/app/mailers/contacts_mailer.rb b/app/mailers/contacts_mailer.rb new file mode 100644 index 0000000000000000000000000000000000000000..e485608d246cbacab6e5967df0c5ad1988bf3aea --- /dev/null +++ b/app/mailers/contacts_mailer.rb @@ -0,0 +1,14 @@ +class ContactsMailer < ApplicationMailer + + def new_contact_received(contact) + @contact = contact + @subject = "Contato de " + @contact.name + mail(subject: @subject) + end + + def contact_updated(contact) + @contact = contact + @subject = "O contato de " + @contact.name + " foi atualizado" + mail(subject: @subject) + end +end diff --git a/app/mailers/suggestions_mailer.rb b/app/mailers/suggestions_mailer.rb new file mode 100644 index 0000000000000000000000000000000000000000..b6545b69cfc64d6e9002f65f435916219e5e766a --- /dev/null +++ b/app/mailers/suggestions_mailer.rb @@ -0,0 +1,14 @@ +class SuggestionsMailer < ApplicationMailer + + def new_suggestion_received(suggestion) + @suggestion = suggestion + @subject = "Sugestão de " + @suggestion.name + mail(subject: @subject) + end + + def suggestion_updated(suggestion) + @suggestion = suggestion + @subject = "A sugestão de " + @suggestion.name + " foi atualizada" + mail(subject: @subject) + end +end diff --git a/app/views/contacts_mailer/contact_updated.html.erb b/app/views/contacts_mailer/contact_updated.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..fba5ea866e8990f0a1bf6b3a2f549cefef952986 --- /dev/null +++ b/app/views/contacts_mailer/contact_updated.html.erb @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style>/* Email styles need to be inline */</style> + </head> + <body> + <h2>Nome do contato: <%= @contact.name %></h1> + <h2>Email do contato: <%= @contact.email %></h1> + <h2>Mensagem: <%= @contact.message %></h1> + </body> +</html> diff --git a/app/views/contacts_mailer/new_contact_received.html.erb b/app/views/contacts_mailer/new_contact_received.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..fba5ea866e8990f0a1bf6b3a2f549cefef952986 --- /dev/null +++ b/app/views/contacts_mailer/new_contact_received.html.erb @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style>/* Email styles need to be inline */</style> + </head> + <body> + <h2>Nome do contato: <%= @contact.name %></h1> + <h2>Email do contato: <%= @contact.email %></h1> + <h2>Mensagem: <%= @contact.message %></h1> + </body> +</html> diff --git a/app/views/suggestions_mailer/new_suggestion_received.html.erb b/app/views/suggestions_mailer/new_suggestion_received.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a0a08db307cc65caa4a8ddbabb192937113db04c --- /dev/null +++ b/app/views/suggestions_mailer/new_suggestion_received.html.erb @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style>/* Email styles need to be inline */</style> + </head> + <body> + <h2>Nome: <%= @suggestion.name %></h1> + <h2>Link: <%= @suggestion.link %></h1> + <h2>Descrição: <%= @suggestion.description %></h1> + </body> +</html> diff --git a/app/views/suggestions_mailer/suggestion_updated.html.erb b/app/views/suggestions_mailer/suggestion_updated.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a0a08db307cc65caa4a8ddbabb192937113db04c --- /dev/null +++ b/app/views/suggestions_mailer/suggestion_updated.html.erb @@ -0,0 +1,12 @@ +<!DOCTYPE html> +<html> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> + <style>/* Email styles need to be inline */</style> + </head> + <body> + <h2>Nome: <%= @suggestion.name %></h1> + <h2>Link: <%= @suggestion.link %></h1> + <h2>Descrição: <%= @suggestion.description %></h1> + </body> +</html>