From eb2bdacd5c5df089e0ce4e9c04991acafa11d425 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 25 Mar 2020 15:36:06 -0300 Subject: [PATCH] usar el nombre del sitio y no el hostname --- app/controllers/api/v1/contact_controller.rb | 6 +++++- test/controllers/api/v1/contact_controller_test.rb | 10 ++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/v1/contact_controller.rb b/app/controllers/api/v1/contact_controller.rb index 429136fd..52ce52df 100644 --- a/app/controllers/api/v1/contact_controller.rb +++ b/app/controllers/api/v1/contact_controller.rb @@ -64,9 +64,13 @@ module Api render html: body(:gave_consent), status: status end + def site_id + params[:site_id].gsub(/\.#{Site.domain}\z/, '') + end + # Encuentra el sitio def site - @site ||= Site.find_by(name: params[:site_id]) + @site ||= Site.find_by(name: site_id) end # ParĂ¡metros limpios diff --git a/test/controllers/api/v1/contact_controller_test.rb b/test/controllers/api/v1/contact_controller_test.rb index 815bb6c1..1a525bcb 100644 --- a/test/controllers/api/v1/contact_controller_test.rb +++ b/test/controllers/api/v1/contact_controller_test.rb @@ -65,11 +65,15 @@ module Api end test 'enviar un mensaje genera correos' do + ActionMailer::Base.deliveries.clear + + redirect = "#{@site.url}/?thanks" + 10.times do create :rol, site: @site end - post v1_site_contact_url(@site), + post v1_site_contact_url(site_id: @site.hostname), headers: { Origin: @site.url }, @@ -79,9 +83,11 @@ module Api contact: SecureRandom.hex, from: "#{SecureRandom.hex}@sutty.nl", body: SecureRandom.hex, - gdpr: true + gdpr: true, + redirect: redirect } + assert_equal redirect, response.headers['Location'] assert_equal 2, ActionMailer::Base.deliveries.size end end