diff --git a/Gemfile.lock b/Gemfile.lock index 0834cd7..c4c3eef 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,6 +1,6 @@ GIT remote: https://github.com/HubFeenixMakers/merged - revision: b44c29ff50bbfc07b04a6064804ac3684eed151d + revision: 5b0ccafc0e78cc72d95865abf001c7b65b69a96f specs: merged (0.1.0) active_hash @@ -146,7 +146,7 @@ GEM formatador (1.1.0) friendly_id (5.5.0) activerecord (>= 4.0.0) - git (1.13.1) + git (1.13.2) addressable (~> 2.8) rchardet (~> 1.8) globalid (1.1.0) @@ -224,7 +224,7 @@ GEM crass (~> 1.0.2) nokogiri (>= 1.5.9) lumberjack (1.2.8) - mail (2.8.0.1) + mail (2.8.1) mini_mime (>= 0.1.1) net-imap net-pop @@ -256,7 +256,7 @@ GEM net-protocol netrc (0.11.0) nio4r (2.5.8) - nokogiri (1.14.0-x86_64-linux) + nokogiri (1.14.1-x86_64-linux) racc (~> 1.4) notiffany (0.1.3) nenv (~> 0.1) diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 3c34c81..c1d6835 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: "from@example.com" + default from: "info@hubfeenix.fi" , bcc: "info@hubfeenix.fi" layout "mailer" end diff --git a/app/mailers/form_mailer.rb b/app/mailers/form_mailer.rb new file mode 100644 index 0000000..f6073e1 --- /dev/null +++ b/app/mailers/form_mailer.rb @@ -0,0 +1,8 @@ +class FormMailer < ApplicationMailer + default from: "info@hubfeenix.fi" , bcc: "info@hubfeenix.fi" + + def received(data) + @data = data + mail(subject: "We have received your request") + end +end diff --git a/app/views/form_mailer/received.html.haml b/app/views/form_mailer/received.html.haml new file mode 100644 index 0000000..bf49b94 --- /dev/null +++ b/app/views/form_mailer/received.html.haml @@ -0,0 +1,21 @@ +%h1 Hello + = @data["name"] + +%p + This is an automated message confirming that we have receievd your request + +%p + Your form input is listed below. If you need to amend or correct, you may reply + to this email. + +%p + You will hear from us in the next few days + +%p + Your friendly Feenix Bot + +%h3 Data received + +- @data.each do |name , value| + %p + = "#{name}: #{value}" diff --git a/app/views/form_mailer/received.text.haml b/app/views/form_mailer/received.text.haml new file mode 100644 index 0000000..d9ece37 --- /dev/null +++ b/app/views/form_mailer/received.text.haml @@ -0,0 +1,17 @@ +="Hello #{@data['name']}" + +This is an automated message confirming that we have receievd your request + +Your form input is listed below. If you need to amend or correct, you may reply +to this email. + +You will hear from us in the next few days + +Your friendly Feenix Bot + + +Data received +------------- + +- @data.each do |name , value| + = "#{name}: #{value}" diff --git a/lib/form_handler.rb b/lib/form_handler.rb index 35bbd50..fe7f10f 100644 --- a/lib/form_handler.rb +++ b/lib/form_handler.rb @@ -1,10 +1,11 @@ class FormHandler def handle_form(section , data ) - puts "Section on page : #{section.page.name}" + @data = data data.each do |name , value| puts "#{name}: #{value}" end + FormMailer.received(data).deliver_later end end diff --git a/test/mailers/form_mailer_test.rb b/test/mailers/form_mailer_test.rb new file mode 100644 index 0000000..c6ebe76 --- /dev/null +++ b/test/mailers/form_mailer_test.rb @@ -0,0 +1,12 @@ +require "test_helper" + +class FormMailerTest < ActionMailer::TestCase + test "received" do + mail = FormMailer.received + assert_equal "Received", mail.subject + assert_equal ["to@example.org"], mail.to + assert_equal ["from@example.com"], mail.from + assert_match "Hi", mail.body.encoded + end + +end diff --git a/test/mailers/previews/form_mailer_preview.rb b/test/mailers/previews/form_mailer_preview.rb new file mode 100644 index 0000000..b8ddd32 --- /dev/null +++ b/test/mailers/previews/form_mailer_preview.rb @@ -0,0 +1,9 @@ +# Preview all emails at http://localhost:3000/rails/mailers/form_mailer +class FormMailerPreview < ActionMailer::Preview + + # Preview this email at http://localhost:3000/rails/mailers/form_mailer/received + def received + FormMailer.received + end + +end