-
- <%= label_tag(:email_address, 'Ignore this text box. It is used to detect spammers. If you enter anything into this text box, your message will not be sent.') %>
- <%= email_field_tag :email_address %>
- <%= text_field_tag :user_agent %>
- <%= text_field_tag :viewport %>
-
-
diff --git a/config/importmap.rb b/config/importmap.rb
index 853d894c..499c4e55 100644
--- a/config/importmap.rb
+++ b/config/importmap.rb
@@ -1,7 +1,6 @@
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
-pin "jquery", to: "https://ga.jspm.io/npm:jquery@3.6.1/dist/jquery.js"
pin "bootstrap", to: "https://ga.jspm.io/npm:bootstrap@5.2.3/dist/js/bootstrap.esm.js"
pin "@popperjs/core", to: "https://ga.jspm.io/npm:@popperjs/core@2.11.6/lib/index.js"
pin "@hotwired/stimulus", to: "stimulus.min.js", preload: true
diff --git a/spec/controller/feedback_forms_controller_spec.rb b/spec/controller/feedback_forms_controller_spec.rb
index 1d3a1cd2..0f643719 100644
--- a/spec/controller/feedback_forms_controller_spec.rb
+++ b/spec/controller/feedback_forms_controller_spec.rb
@@ -3,52 +3,45 @@
RSpec.describe FeedbackFormsController, type: :controller do
before do
allow(Settings.feedback).to receive(:email_to).and_return('feedback@example.com')
+ allow(controller).to receive(:verify_recaptcha).and_return(verify)
+ allow(controller).to receive(:current_user).and_return(current_user)
+ allow(FeedbackMailer).to receive(:submit_feedback).and_return(mailer)
end
- describe 'format json' do
- it 'returns json success' do
- post :create, params: { url: 'http://test.host/', message: 'Hello Kittenz', format: 'json' }
- expect(flash[:success]).to eq 'Thank you! Your feedback has been sent.'
- end
-
- it 'returns html success' do
- post :create, params: { url: 'http://test.host/', message: 'Hello Kittenz' }
- expect(flash[:success]).to eq 'Thank you! Your feedback has been sent.'
- end
- end
+ let(:verify) { false }
+ let(:current_user) { nil }
+ let(:mailer) { instance_double(ActionMailer::MessageDelivery, deliver_now: true) }
describe 'validate' do
- it 'returns an error if no message is sent' do
- post :create, params: { url: 'http://test.host/', message: '', email_address: '' }
- expect(flash[:error]).to eq FeedbackFormsController::MESSAGE_BLANK_MESSAGE
- end
-
- it 'returns an error if a bot fills in the email_address field (email is correct field)' do
- post :create, params: { message: 'I am spamming you!', url: 'http://test.host/', email_address: 'spam!' }
- expect(flash[:error]).to eq FeedbackFormsController::EMAIL_PRESENT_MESSAGE
+ context 'when the user is not logged in and captcha fails' do
+ it 'returns an error if the recaptcha is incorrect' do
+ post :create, params: { message: 'I am spamming you!', url: 'http://test.host/' }
+ expect(flash[:error]).to eq 'You must pass the reCAPTCHA challenge'
+ expect(FeedbackMailer).not_to have_received(:submit_feedback)
+ end
end
- context 'when the user is not logged in' do
- before do
- allow(controller).to receive(:verify_recaptcha).and_return(false)
- end
+ context 'when the user is not logged in and captcha succeeds' do
+ let(:verify) { true }
- it 'returns an error if the recaptcha is incorrect' do
+ it 'returns success and sends email' do
post :create, params: { message: 'I am spamming you!', url: 'http://test.host/' }
- expect(flash[:error]).to eq FeedbackFormsController::RECAPTCHA_MESSAGE
+
+ expect(flash[:success]).to eq 'Thank you! Your feedback has been sent.'
+ expect(controller).to have_received(:verify_recaptcha)
+ expect(FeedbackMailer).to have_received(:submit_feedback)
end
end
context 'when the user is logged in' do
- before do
- allow(controller).to receive(:current_user).and_return('any truthy value, really')
- allow(controller).to receive(:verify_recaptcha)
- end
+ let(:current_user) { 'chester' }
- it 'does not care if the recaptcha is incorrect' do
+ it 'returns success and sends email' do
post :create, params: { message: 'I am spamming you!', url: 'http://test.host/' }
expect(flash[:error]).to be_nil
+ expect(flash[:success]).to eq 'Thank you! Your feedback has been sent.'
expect(controller).not_to have_received(:verify_recaptcha)
+ expect(FeedbackMailer).to have_received(:submit_feedback)
end
end
end