From d9d1913f4336f6ec872fb8e70d2cdd64b17c4f74 Mon Sep 17 00:00:00 2001 From: Anita Graham Date: Fri, 1 Jan 2021 14:37:12 +0800 Subject: [PATCH 1/7] Changed recieved to received Add puma and selenium-webdriver to Gemfile. Upgrade refinery version to 4.1.0 in gemspec Leave Rails at 6.0.0 until 6.1 problem with polymorphic is released (https://github.com/rails/rails/pull/40879, includes a patch for ActiveRecord in the comments) Add rubocop fix for factory values Minor changes to allow for matching first of several page elements and how to click on them. --- Gemfile | 3 +- .../inquiry_mailer/notification.text.erb | 2 +- config/locales/bg.yml | 2 +- config/locales/cs.yml | 2 +- config/locales/de.yml | 2 +- config/locales/en-GB.yml | 2 +- config/locales/en.yml | 2 +- config/locales/es.yml | 2 +- config/locales/fr.yml | 2 +- config/locales/it.yml | 2 +- config/locales/lt.yml | 2 +- config/locales/lv.yml | 2 +- config/locales/nb.yml | 2 +- config/locales/nl.yml | 2 +- config/locales/pl.yml | 2 +- config/locales/pt-BR.yml | 2 +- config/locales/ru.yml | 2 +- config/locales/sk.yml | 2 +- config/locales/sl.yml | 2 +- config/locales/sv.yml | 2 +- config/locales/zh-CN.yml | 2 +- config/locales/zh-TW.yml | 2 +- refinerycms-inquiries.gemspec | 5 +- spec/factories/inquiry.rb | 6 +- .../inquiries/admin/inquiries_spec.rb | 92 ++++---- .../refinery/inquiries/inquiries_spec.rb | 199 ++++++++---------- .../refinery/inquiries/mailer_spec.rb | 5 +- .../models/refinery/inquiries/inquiry_spec.rb | 1 + spec/spec_helper.rb | 9 +- spec/support/spec_helper.rb | 8 + 30 files changed, 188 insertions(+), 182 deletions(-) create mode 100644 spec/support/spec_helper.rb diff --git a/Gemfile b/Gemfile index 940a4fc5..bb8f4fe6 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,8 @@ end group :test do gem 'capybara-email', '~> 3.0' - gem 'poltergeist' + gem 'selenium-webdriver', require: false + gem 'puma' end # Database Configuration diff --git a/app/views/refinery/inquiries/inquiry_mailer/notification.text.erb b/app/views/refinery/inquiries/inquiry_mailer/notification.text.erb index 524f3195..b963843a 100644 --- a/app/views/refinery/inquiries/inquiry_mailer/notification.text.erb +++ b/app/views/refinery/inquiries/inquiry_mailer/notification.text.erb @@ -1,6 +1,6 @@ <%=raw t('.greeting') %>, -<%=raw t('.you_recieved_new_inquiry') %> +<%=raw t('.you_received_new_inquiry') %> <%=raw t('.inquiry_starts') %> diff --git a/config/locales/bg.yml b/config/locales/bg.yml index 6b8ea268..746f78ad 100644 --- a/config/locales/bg.yml +++ b/config/locales/bg.yml @@ -59,7 +59,7 @@ bg: inquiry_mailer: notification: greeting: Здравейте - you_recieved_new_inquiry: Току що получихте ново запитване през Вашия уебсайт. + you_received_new_inquiry: Току що получихте ново запитване през Вашия уебсайт. inquiry_starts: --- Начало на запитването --- inquiry_ends: --- Край на запитването --- from: От diff --git a/config/locales/cs.yml b/config/locales/cs.yml index c813e0f5..4a50cade 100644 --- a/config/locales/cs.yml +++ b/config/locales/cs.yml @@ -59,7 +59,7 @@ cs: inquiry_mailer: notification: greeting: Ahoj - you_recieved_new_inquiry: Právě jsi obdržel nový dotaz na webové stránce. + you_received_new_inquiry: Právě jsi obdržel nový dotaz na webové stránce. inquiry_starts: --- začátek dotazu --- inquiry_ends: --- konec dotazu --- from: Od diff --git a/config/locales/de.yml b/config/locales/de.yml index f20aa1bb..93363537 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -61,7 +61,7 @@ de: inquiry_mailer: notification: greeting: Hallo - you_recieved_new_inquiry: Sie haben eine neue Kontaktanfrage über Ihre Webseite erhalten. + you_received_new_inquiry: Sie haben eine neue Kontaktanfrage über Ihre Webseite erhalten. inquiry_starts: --- Anfang der Kontaktanfrage --- inquiry_ends: --- Ende der Kontaktanfrage --- from: Von diff --git a/config/locales/en-GB.yml b/config/locales/en-GB.yml index 2264522e..7fcd4da6 100644 --- a/config/locales/en-GB.yml +++ b/config/locales/en-GB.yml @@ -59,7 +59,7 @@ en-GB: inquiry_mailer: notification: greeting: Hi there - you_recieved_new_inquiry: You just received a new enquiry on your website. + you_received_new_inquiry: You just received a new enquiry on your website. inquiry_starts: --- enquiry starts --- inquiry_ends: --- enquiry ends --- from: From diff --git a/config/locales/en.yml b/config/locales/en.yml index bef2f019..c521964f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -62,7 +62,7 @@ en: inquiry_mailer: notification: greeting: Hi there - you_recieved_new_inquiry: You just received a new inquiry on your website. + you_received_new_inquiry: You just received a new inquiry on your website. inquiry_starts: --- inquiry starts --- inquiry_ends: --- inquiry ends --- from: From diff --git a/config/locales/es.yml b/config/locales/es.yml index 364ad030..8eddacc2 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -61,7 +61,7 @@ es: inquiry_mailer: notification: greeting: Hola - you_recieved_new_inquiry: Has recibido una nueva consulta en tu web. + you_received_new_inquiry: Has recibido una nueva consulta en tu web. inquiry_starts: --- comienzo de la consulta --- inquiry_ends: --- fin de la consulta --- from: De diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 2ca2a73b..fb57f151 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -63,7 +63,7 @@ fr: inquiry_mailer: notification: greeting: Bonjour - you_recieved_new_inquiry: Vous avez reçu une nouvelle requête sur votre site. + you_received_new_inquiry: Vous avez reçu une nouvelle requête sur votre site. inquiry_starts: --- Début des requêtes --- inquiry_ends: --- Fin des requêtes --- from: De diff --git a/config/locales/it.yml b/config/locales/it.yml index d63aedc7..e5d0f72d 100644 --- a/config/locales/it.yml +++ b/config/locales/it.yml @@ -61,7 +61,7 @@ it: inquiry_mailer: notification: greeting: Ciao a tutti - you_recieved_new_inquiry: Hai appena ricevuto una nuova richiesta sul tuo sito. + you_received_new_inquiry: Hai appena ricevuto una nuova richiesta sul tuo sito. inquiry_starts: --- inizio del messaggio --- inquiry_ends: --- fine del messaggio --- from: Da diff --git a/config/locales/lt.yml b/config/locales/lt.yml index 2fb6e160..e4d23142 100644 --- a/config/locales/lt.yml +++ b/config/locales/lt.yml @@ -60,7 +60,7 @@ lt: inquiry_mailer: notification: greeting: Sveiki - you_recieved_new_inquiry: Jūs katik gavote naują užklausą savo svetainėje. + you_received_new_inquiry: Jūs katik gavote naują užklausą savo svetainėje. inquiry_starts: --- užklausa prasideda --- inquiry_ends: --- užklausa baigiasi --- from: Nuo diff --git a/config/locales/lv.yml b/config/locales/lv.yml index 63980e0e..d1c9a7ba 100644 --- a/config/locales/lv.yml +++ b/config/locales/lv.yml @@ -59,7 +59,7 @@ lv: inquiry_mailer: notification: greeting: Sveiki - you_recieved_new_inquiry: Jūs nupat saņēmāt jaunu pieprasījumu savā mājaslapā. + you_received_new_inquiry: Jūs nupat saņēmāt jaunu pieprasījumu savā mājaslapā. inquiry_starts: --- pieprasījuma sākums --- inquiry_ends: --- pieprasījuma beigas --- from: 'No' diff --git a/config/locales/nb.yml b/config/locales/nb.yml index 5a5398c0..3767a1d8 100644 --- a/config/locales/nb.yml +++ b/config/locales/nb.yml @@ -59,7 +59,7 @@ nb: inquiry_mailer: notification: greeting: Hei - you_recieved_new_inquiry: Du har mottatt en ny forespørsel på nettsiden din. + you_received_new_inquiry: Du har mottatt en ny forespørsel på nettsiden din. inquiry_starts: --- Start på forespørsel --- inquiry_ends: --- Slutt på forespørsel --- from: Fra diff --git a/config/locales/nl.yml b/config/locales/nl.yml index 07a5008c..27d7f51e 100644 --- a/config/locales/nl.yml +++ b/config/locales/nl.yml @@ -59,7 +59,7 @@ nl: inquiry_mailer: notification: greeting: Hallo - you_recieved_new_inquiry: Je hebt een nieuwe vraag ontvangen via je website. + you_received_new_inquiry: Je hebt een nieuwe vraag ontvangen via je website. inquiry_starts: --- begin van de vraag --- inquiry_ends: --- einde van de vraag --- from: Van diff --git a/config/locales/pl.yml b/config/locales/pl.yml index 67098ea0..40e4136a 100644 --- a/config/locales/pl.yml +++ b/config/locales/pl.yml @@ -60,7 +60,7 @@ pl: inquiry_mailer: notification: greeting: Cześć - you_recieved_new_inquiry: Z Twojej strony ktoś właśnie nowe zapytanie. + you_received_new_inquiry: Z Twojej strony ktoś właśnie nowe zapytanie. inquiry_starts: --- początek zapytania --- inquiry_ends: --- koniec zapytania --- from: Od diff --git a/config/locales/pt-BR.yml b/config/locales/pt-BR.yml index d39ec157..d3518999 100644 --- a/config/locales/pt-BR.yml +++ b/config/locales/pt-BR.yml @@ -60,7 +60,7 @@ pt-BR: inquiry_mailer: notification: greeting: Olá - you_recieved_new_inquiry: Você recebeu um novo contato pelo website. + you_received_new_inquiry: Você recebeu um novo contato pelo website. inquiry_starts: --- começo da mensagem --- inquiry_ends: --- fim da mensagem --- from: De diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 4d9b9b39..b51223e2 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -61,7 +61,7 @@ ru: inquiry_mailer: notification: greeting: Здравствуйте - you_recieved_new_inquiry: Вы только что получили новый запрос со своего сайта + you_received_new_inquiry: Вы только что получили новый запрос со своего сайта inquiry_starts: --- начало запроса --- inquiry_ends: --- конец запроса --- from: От diff --git a/config/locales/sk.yml b/config/locales/sk.yml index 01861974..f7be3713 100644 --- a/config/locales/sk.yml +++ b/config/locales/sk.yml @@ -59,7 +59,7 @@ sk: inquiry_mailer: notification: greeting: Ahoj - you_recieved_new_inquiry: Práve si obdržal novú otázku na webovej stránke. + you_received_new_inquiry: Práve si obdržal novú otázku na webovej stránke. inquiry_starts: --- začiatok otázky --- inquiry_ends: --- koniec otázky --- from: Od diff --git a/config/locales/sl.yml b/config/locales/sl.yml index c77ca5dd..f3cd7d02 100644 --- a/config/locales/sl.yml +++ b/config/locales/sl.yml @@ -59,7 +59,7 @@ sl: inquiry_mailer: notification: greeting: Pozdravljeni - you_recieved_new_inquiry: Na vaši spletni strani ste prejeli ste novo povpraševanje. + you_received_new_inquiry: Na vaši spletni strani ste prejeli ste novo povpraševanje. inquiry_starts: --- začetek povpraševanja --- inquiry_ends: --- konec povpraševanja --- from: Od diff --git a/config/locales/sv.yml b/config/locales/sv.yml index e893c440..7205791c 100644 --- a/config/locales/sv.yml +++ b/config/locales/sv.yml @@ -59,7 +59,7 @@ sv: inquiry_mailer: notification: greeting: Hej! - you_recieved_new_inquiry: Du har just mottagit en ny förfrågan på din webbplats. + you_received_new_inquiry: Du har just mottagit en ny förfrågan på din webbplats. inquiry_starts: --- förfrågan börjar --- inquiry_ends: --- förfrågan slutar --- from: Från diff --git a/config/locales/zh-CN.yml b/config/locales/zh-CN.yml index 052d1b73..a22e327f 100644 --- a/config/locales/zh-CN.yml +++ b/config/locales/zh-CN.yml @@ -59,7 +59,7 @@ zh-CN: inquiry_mailer: notification: greeting: 您好 - you_recieved_new_inquiry: 你刚从你的网站收到一条新的咨询. + you_received_new_inquiry: 你刚从你的网站收到一条新的咨询. inquiry_starts: --- 咨询开始处 --- inquiry_ends: --- 咨询结束处 --- from: 表单 diff --git a/config/locales/zh-TW.yml b/config/locales/zh-TW.yml index fab38765..5323603c 100644 --- a/config/locales/zh-TW.yml +++ b/config/locales/zh-TW.yml @@ -59,7 +59,7 @@ zh-TW: inquiry_mailer: notification: greeting: 您好 - you_recieved_new_inquiry: 你剛從你的網站收到一條新的咨詢. + you_received_new_inquiry: 你剛從你的網站收到一條新的咨詢. inquiry_starts: --- 咨詢開始處 --- inquiry_ends: --- 咨詢結束處 --- from: 表單 diff --git a/refinerycms-inquiries.gemspec b/refinerycms-inquiries.gemspec index 4d3a92bd..ed2847ac 100644 --- a/refinerycms-inquiries.gemspec +++ b/refinerycms-inquiries.gemspec @@ -2,7 +2,7 @@ Gem::Specification.new do |s| s.name = %q{refinerycms-inquiries} - s.version = %q{4.0.0} + s.version = %q{4.1.0} s.summary = %q{Inquiry handling functionality for the Refinery CMS project.} s.description = %q{Inquiry handling functionality extracted from Refinery CMS to allow you to have a contact form and manage inquiries in the Refinery backend.} s.homepage = %q{http://refinerycms.com} @@ -14,7 +14,8 @@ Gem::Specification.new do |s| s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- spec/*`.split("\n") - s.add_dependency 'refinerycms-core', '~> 4.0' + s.add_dependency 'refinerycms-core', '~> 4.1' + s.add_dependency 'rails', '~>6.0.0' s.add_dependency 'mobility' s.add_dependency 'refinerycms-settings', '~> 4.0' s.add_dependency 'filters_spam', '~> 0.2' diff --git a/spec/factories/inquiry.rb b/spec/factories/inquiry.rb index c2084209..13f1c73e 100644 --- a/spec/factories/inquiry.rb +++ b/spec/factories/inquiry.rb @@ -2,8 +2,8 @@ FactoryBot.define do factory :inquiry, class: "Refinery::Inquiries::Inquiry" do - name "Refinery" - email "refinery@example.com" - message "Hello..." + name { "Refinery" } + email { "refinery@example.com" } + message { "Hello..." } end end diff --git a/spec/features/refinery/inquiries/admin/inquiries_spec.rb b/spec/features/refinery/inquiries/admin/inquiries_spec.rb index 50ddaf51..06f7a44f 100644 --- a/spec/features/refinery/inquiries/admin/inquiries_spec.rb +++ b/spec/features/refinery/inquiries/admin/inquiries_spec.rb @@ -3,17 +3,20 @@ module Refinery module Inquiries module Admin + describe Inquiry, :type => :feature do refinery_login - let!(:inquiry) do + let(:inquiry) do FactoryBot.create(:inquiry, - :name => "David Jones", - :email => "dave@refinerycms.com", - :message => "Hello, I really like your website. Was it hard to build and maintain or could anyone do it?") + :name => "David Jones", + :email => "dave@refinerycms.com", + :message => "Hello, I really like your website. Was it hard to build and maintain or could anyone do it?") end - context "when no" do + let(:delete_first_inquiry){ -> { find_link("Remove this inquiry forever", match: :first).click } } + + context "when there are no inquiries" do before { Refinery::Inquiries::Inquiry.destroy_all } context "inquiries" do @@ -50,62 +53,65 @@ module Admin end end - describe "index" do - it "shows inquiry list" do - visit refinery.inquiries_admin_inquiries_path + context "when there are inquiries" do + before { inquiry } - expect(page).to have_content("David Jones said Hello, I really like your website. Was it hard to build a...") + describe "index" do + it "shows a list of inquiries" do + visit refinery.inquiries_admin_inquiries_path + expect(page).to have_content("David Jones said Hello, I really like your website. Was it hard to build a...") + end end - end - describe "show" do - it "shows inquiry details" do - visit refinery.inquiries_admin_inquiries_path - - click_link "Read the inquiry" - - expect(page).to have_content("From David Jones [dave@refinerycms.com]") - expect(page).to have_content("Hello, I really like your website. Was it hard to build and maintain or could anyone do it?") - within "#actions" do - expect(page).to have_content("Age") - expect(page).to have_content("Back to all Inquiries") - expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/inquiries']") - expect(page).to have_content("Remove this inquiry forever") - expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/inquiries/#{inquiry.id}']") + describe "show" do + it "shows inquiry details" do + visit refinery.inquiries_admin_inquiries_path + find_link("Read the inquiry", match: :first).click + + expect(page).to have_content("From David Jones [dave@refinerycms.com]") + expect(page).to have_content("Hello, I really like your website. Was it hard to build and maintain or could anyone do it?") + within "#actions" do + expect(page).to have_content("Age") + expect(page).to have_content("Back to all Inquiries") + expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/inquiries']") + expect(page).to have_content("Remove this inquiry forever") + expect(page).to have_selector("a[href='/#{Refinery::Core.backend_route}/inquiries/#{inquiry.id}']") + end end end - end - describe "destroy" do - it "removes inquiry" do - visit refinery.inquiries_admin_inquiries_path + describe "destroy" do + - click_link "Remove this inquiry forever" + it "removes inquiry" do + visit refinery.inquiries_admin_inquiries_path + + expect(delete_first_inquiry).to change(Refinery::Inquiries::Inquiry, :count).by(-1) + expect(page).to have_content("'#{inquiry.name}' was successfully removed.") - expect(page).to have_content("'#{inquiry.name}' was successfully removed.") - expect(Refinery::Inquiries::Inquiry.count).to eq(0) + end end - end - describe "spam" do - it "moves inquiry to spam" do - visit refinery.inquiries_admin_inquiries_path + describe "spam" do + it "moves inquiry to spam" do + visit refinery.inquiries_admin_inquiries_path - click_link "Mark as spam" + find_link("Mark as spam", match: :first).click - within "#actions" do - expect(page).to have_content("Spam (1)") - click_link "Spam (1)" - end + within "#actions" do + expect(page).to have_content("Spam (1)") + click_link "Spam (1)" + end - expect(page).to have_content("David Jones said Hello, I really like your website. Was it hard to build a...") + expect(page).to have_content("David Jones said Hello, I really like your website. Was it hard to build a...") + end end end describe "update who gets notified" do it "sets receiver", :js => true do visit refinery.inquiries_admin_inquiries_path - find("#update_notified").trigger('click') + find_link("update_notified").click within_frame "dialog_iframe" do fill_in "setting_value", :with => "phil@refinerycms.com" @@ -120,7 +126,7 @@ module Admin it "sets message", :js => true do visit refinery.inquiries_admin_inquiries_path - find("#edit_confirmation_email").trigger('click') + find_link("edit_confirmation_email").click within_frame "dialog_iframe" do fill_in "setting[subject[en]]", :with => "subject" diff --git a/spec/features/refinery/inquiries/inquiries_spec.rb b/spec/features/refinery/inquiries/inquiries_spec.rb index 06c1721c..81f0a962 100644 --- a/spec/features/refinery/inquiries/inquiries_spec.rb +++ b/spec/features/refinery/inquiries/inquiries_spec.rb @@ -2,7 +2,18 @@ module Refinery module Inquiries + describe "inquiries", :type => :feature do + + making_an_inquiry = -> (name, email, message) { + ensure_on(refinery.inquiries_new_inquiry_path) + fill_in "Name", :with => name + fill_in "Email", :with => email + fill_in "Message", :with => message + click_button "Send message" + } + + before do # load in seeds we use in migration Refinery::Inquiries::Engine.load_seed @@ -13,15 +24,10 @@ module Inquiries expect(page).to have_selector("form[action='#{refinery.inquiries_inquiries_path}']") end - context "when valid data" do + context "when given valid data" do it "is successful" do visit refinery.inquiries_new_inquiry_path - - fill_in "Name", :with => "Ugis Ozols" - fill_in "Email", :with => "ugis.ozols@refinerycms.com" - fill_in "Message", :with => "Hey, I'm testing!" - click_button "Send message" - + expect { making_an_inquiry("Ugis Ozols", "ugis.ozols@refinerycms.com", "Hey, I'm testing!") }.to change(Refinery::Inquiries::Inquiry, :count).by(1) expect(page.current_path).to eq(refinery.thank_you_inquiries_inquiries_path) expect(page).to have_content("Thank You") @@ -30,147 +36,126 @@ module Inquiries expect(page).to have_content("Return to the home page") expect(page).to have_selector("a[href='/']") end - - expect(Refinery::Inquiries::Inquiry.count).to eq(1) end end - context "when invalid data" do - let(:name_error_message) { "Name can't be blank" } - let(:email_error_message) { "Email is invalid" } - let(:message_error_message) { "Message can't be blank" } + context "when given invalid data" do - it "is not successful" do + it "does not save the inquiry" do visit refinery.inquiries_new_inquiry_path - - click_button "Send message" - - expect(page.current_path).to eq(refinery.inquiries_inquiries_path) - expect(page).to have_content("There were problems with the following fields") - expect(page).to have_content(name_error_message) - expect(page).to have_content(email_error_message) - expect(page).to have_content(message_error_message) - expect(page).to have_no_content("Phone can't be blank") - expect(page).to have_no_content("Company can't be blank") - - expect(Refinery::Inquiries::Inquiry.count).to eq(0) + expect{ making_an_inquiry('my name 😀 ', 'jun!k@ok', '☄︎☀︎☽ ') }.not_to change(Refinery::Inquiries::Inquiry, :count) + expect(page).to have_content("Email is invalid") end - it "displays the error messages in the same order as the fields" do - visit refinery.inquiries_new_inquiry_path - - click_button "Send message" - - expect(page).to have_content(/#{name_error_message}.+#{email_error_message}.+#{message_error_message}/m) - end end + describe 'configuration' do + describe "privacy" do + context "when 'show contact privacy link' setting is false" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_contact_privacy_link).and_return(false) + end - describe "privacy" do - context "when show contact privacy link setting set to false" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_contact_privacy_link).and_return(false) - end - - it "won't show link" do - visit refinery.inquiries_new_inquiry_path + it "won't show link" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_no_content("We value your privacy") - expect(page).to have_no_selector("a[href='/privacy-policy']") + expect(page).to have_no_content("We value your privacy") + expect(page).to have_no_selector("a[href='/privacy-policy']") + end end - end - context "when show contact privacy link setting set to true" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_contact_privacy_link).and_return(true) - end + context "when' show contact privacy link' setting is true" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_contact_privacy_link).and_return(true) + end - it "shows the link" do - visit refinery.inquiries_new_inquiry_path + it "shows the link" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_content("We value your privacy") - expect(page).to have_selector("a[href='/privacy-policy']") + expect(page).to have_content("We value your privacy") + expect(page).to have_selector("a[href='/privacy-policy']") + end end end - end - describe "palceholders" do - context "when show placeholders setting set to false" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_placeholders).and_return(false) - end + describe "placeholders" do + context "when show placeholders setting set to false" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_placeholders).and_return(false) + end - it "won't show placeholders" do - visit refinery.inquiries_new_inquiry_path + it "won't show placeholders" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_no_selector("input[placeholder]") + expect(page).to have_no_selector("input[placeholder]") + end end - end - context "when show placeholders setting set to true" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_placeholders).and_return(true) - end + context "when show placeholders setting set to true" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_placeholders).and_return(true) + end - it "shows the placeholders" do - visit refinery.inquiries_new_inquiry_path + it "shows the placeholders" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_selector("input[placeholder]") + expect(page).to have_selector("input[placeholder]") + end end end - end - describe "phone number" do - context "when show phone numbers setting set to false" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_phone_number_field).and_return(false) - end + describe "phone number" do + context "when 'show phone numbers' setting is false" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_phone_number_field).and_return(false) + end - it "won't show phone number" do - visit refinery.inquiries_new_inquiry_path + it "won't have an input field for phone number" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_no_selector("label", :text => 'Phone') - expect(page).to have_no_selector("#inquiry_phone") + expect(page).to have_no_selector("label", :text => 'Phone') + expect(page).to have_no_selector("#inquiry_phone") + end end - end - context "when show phone numbers setting set to true" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_phone_number_field).and_return(true) - end + context "when 'show phone numbers' setting is true" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_phone_number_field).and_return(true) + end - it "shows the phone number" do - visit refinery.inquiries_new_inquiry_path + it "there is an input field for phone number" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_selector("label", :text => 'Phone') - expect(page).to have_selector("#inquiry_phone") + expect(page).to have_selector("label", :text => 'Phone') + expect(page).to have_selector("#inquiry_phone") + end end end - end - describe "company" do - context "when show company setting set to false" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_company_field).and_return(false) - end + describe "company" do + context "when 'show company' setting is false" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_company_field).and_return(false) + end - it "won't show company" do - visit refinery.inquiries_new_inquiry_path + it "won't show company" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_no_selector("label", :text => 'Company') - expect(page).to have_no_selector("#inquiry_company") + expect(page).to have_no_selector("label", :text => 'Company') + expect(page).to have_no_selector("#inquiry_company") + end end - end - context "when show company setting set to true" do - before(:each) do - allow(Refinery::Inquiries.config).to receive(:show_company_field).and_return(true) - end + context "when 'show company' setting is true" do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:show_company_field).and_return(true) + end - it "shows the company" do - visit refinery.inquiries_new_inquiry_path + it "shows the company" do + visit refinery.inquiries_new_inquiry_path - expect(page).to have_selector("label", :text => 'Company') - expect(page).to have_selector("#inquiry_company") + expect(page).to have_selector("label", :text => 'Company') + expect(page).to have_selector("#inquiry_company") + end end end end diff --git a/spec/features/refinery/inquiries/mailer_spec.rb b/spec/features/refinery/inquiries/mailer_spec.rb index a95cbd83..373550ee 100644 --- a/spec/features/refinery/inquiries/mailer_spec.rb +++ b/spec/features/refinery/inquiries/mailer_spec.rb @@ -23,11 +23,10 @@ module Inquiries it "sends confirmation email" do open_email("ugis.ozols@refinerycms.com") - expect(current_email.from).to eq(["#{Refinery::Inquiries.from_name}@example.com"]) expect(current_email.to).to eq(["ugis.ozols@refinerycms.com"]) - expect(current_email.subject).to eq("Thank you for your inquiry") - expect(current_email.body).to eq("Thank you for your inquiry Ugis Ozols,\n\nThis email is a receipt to confirm we have received your inquiry and we'll be in touch shortly.\n\nThanks.") + expect(current_email.subject).to eq(Refinery::Inquiries::Setting.get(:inquiry_confirmation_subject_en, scoping: :inquiries)) + expect(current_email.body).to eq(Refinery::Inquiries::Setting.get(:inquiry_confirmation_message_en, scoping: :inquiries)) end it "sends notification email" do diff --git a/spec/models/refinery/inquiries/inquiry_spec.rb b/spec/models/refinery/inquiries/inquiry_spec.rb index 04a7c3d4..517d07e8 100644 --- a/spec/models/refinery/inquiries/inquiry_spec.rb +++ b/spec/models/refinery/inquiries/inquiry_spec.rb @@ -61,6 +61,7 @@ module Inquiries end describe "default scope" do + before { Refinery::Inquiries::Inquiry.destroy_all } it "orders by created_at in desc" do inquiry1 = FactoryBot.create(:inquiry, created_at: 1.hour.ago) inquiry2 = FactoryBot.create(:inquiry, created_at: 2.hours.ago) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d18a5ff4..8705fbd9 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -7,8 +7,7 @@ require 'rspec/rails' require 'capybara/rspec' -require 'capybara/poltergeist' -Capybara.javascript_driver = :poltergeist +require 'webdrivers/chromedriver' Rails.backtrace_cleaner.remove_silencers! @@ -18,6 +17,12 @@ config.run_all_when_everything_filtered = true end +Capybara.register_driver :chrome do |app| + Capybara::Selenium::Driver.new(app, browser: :chrome) +end +Capybara.javascript_driver = :chrome + + # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories including factories. ([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p| diff --git a/spec/support/spec_helper.rb b/spec/support/spec_helper.rb new file mode 100644 index 00000000..bad6fa9d --- /dev/null +++ b/spec/support/spec_helper.rb @@ -0,0 +1,8 @@ +def refinery_login + let(:logged_in_user) { Refinery::Core::NilUser.new } +end + +def ensure_on(path) + visit(path) unless current_path == path +end + From a422bea071f6314f80222127db4e374aa7fd7fe7 Mon Sep 17 00:00:00 2001 From: Anita Graham Date: Thu, 28 Jan 2021 17:07:51 +0800 Subject: [PATCH 2/7] Try to get more specific error from Inquiries --- lib/refinery/inquiries/spam_filter.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/refinery/inquiries/spam_filter.rb b/lib/refinery/inquiries/spam_filter.rb index e02462c8..89e02f15 100644 --- a/lib/refinery/inquiries/spam_filter.rb +++ b/lib/refinery/inquiries/spam_filter.rb @@ -1,5 +1,6 @@ require 'httpclient' require 'uri' +require 'English' module Refinery module Inquiries @@ -82,7 +83,7 @@ def send_notification_email! begin InquiryMailer.notification(@inquiry, @request).deliver_now rescue - Rails.logger.warn "There was an error delivering an inquiry notification.\n#{$!}\n" + Rails.logger.warn "There was an error delivering an inquiry notification.\n#{$ERROR_INFO}" end end @@ -91,7 +92,7 @@ def send_confirmation_email! begin InquiryMailer.confirmation(@inquiry, @request).deliver_now rescue - Rails.logger.warn "There was an error delivering an inquiry confirmation:\n#{$!}\n" + Rails.logger.warn "There was an error delivering an inquiry confirmation:\n#{$ERROR_INFO}" end end end From eb32e0d233c5880b8ed5945a7f3cfa16bccfbb6b Mon Sep 17 00:00:00 2001 From: Anita Graham Date: Wed, 20 Jan 2021 18:44:27 +0800 Subject: [PATCH 3/7] Work around a problem with polymorphism at Rails 6.0.3 --- config/initializers/active_record.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 config/initializers/active_record.rb diff --git a/config/initializers/active_record.rb b/config/initializers/active_record.rb new file mode 100644 index 00000000..86792f34 --- /dev/null +++ b/config/initializers/active_record.rb @@ -0,0 +1,12 @@ +module PolymorphicBelongsTo + def valid_options(options) + valid = super + [:polymorphic, :counter_cache, :optional, :default] + valid += [:foreign_type] if options[:polymorphic] + valid += [:ensuring_owner_was] if options[:dependent] == :destroy_async + valid + end +end + +ActiveSupport.on_load :active_record do + ActiveRecord::Associations::Builder::BelongsTo.extend PolymorphicBelongsTo +end From 175d7f87fc5aeacfbff05181b1f5e1163bf3d127 Mon Sep 17 00:00:00 2001 From: Anita Graham Date: Fri, 22 Jan 2021 09:36:46 +0800 Subject: [PATCH 4/7] Use Rails credentials for recaptcha keys --- lib/refinery/inquiries/spam_filter.rb | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/refinery/inquiries/spam_filter.rb b/lib/refinery/inquiries/spam_filter.rb index 89e02f15..a35100ff 100644 --- a/lib/refinery/inquiries/spam_filter.rb +++ b/lib/refinery/inquiries/spam_filter.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'httpclient' require 'uri' require 'English' @@ -17,7 +19,7 @@ def call @valid = true @inquiry.save else - @inquiry.errors.add(:base, ::I18n.t(:captcha_invalid, scope: "refinery.inquiries.spam_filter")) + @inquiry.errors.add(:base, ::I18n.t(:captcha_invalid, scope: 'refinery.inquiries.spam_filter')) end elsif simple_filter? @inquiry.save @@ -55,18 +57,18 @@ def recaptcha_validated? private def recaptcha? - Inquiries.recaptcha_site_key.present? + Inquiries.recaptcha_site_key.present? end - GOOGLE_SITEVERIFY_URL = "https://www.google.com/recaptcha/api/siteverify".freeze + GOOGLE_SITEVERIFY_URL = 'https://www.google.com/recaptcha/api/siteverify' def recaptcha_success? http = HTTPClient.new response = http.get( GOOGLE_SITEVERIFY_URL, - secret: Rails.application.secrets.recaptcha_secret_key, - response: @params["g-recaptcha-response"] + secret: Rails.application.credentials[:recaptcha][:secret_key], + response: @params['g-recaptcha-response'] ) - JSON.parse(response.body)["success"] == true + JSON.parse(response.body)['success'] == true end def simple_filter? @@ -91,8 +93,8 @@ def send_confirmation_email! if Setting.send_confirmation? begin InquiryMailer.confirmation(@inquiry, @request).deliver_now - rescue - Rails.logger.warn "There was an error delivering an inquiry confirmation:\n#{$ERROR_INFO}" + rescue StandardError + Rails.logger.warn "There was an error delivering an inquiry confirmation:\n#{$ERROR_INFO}\n" end end end From d203704c6e04ff23f01c5104940bd8ec2f3faa91 Mon Sep 17 00:00:00 2001 From: Anita Date: Fri, 4 Aug 2023 16:14:27 +0800 Subject: [PATCH 5/7] Add configuration for privacy_link Add test gems/drivers as used for refinerycms Testing: moved 'making_an_inquiry' into spec/support/spec_helper updated spec/spec_helper to match refinerycms --- Gemfile | 8 ++- .../inquiries/inquiries/_form.html.erb | 2 +- lib/refinery/inquiries/configuration.rb | 2 + .../inquiries/admin/inquiries_spec.rb | 4 +- .../refinery/inquiries/inquiries_spec.rb | 26 ++++---- spec/spec_helper.rb | 65 +++++++++++++++++-- spec/support/spec_helper.rb | 7 ++ 7 files changed, 92 insertions(+), 22 deletions(-) diff --git a/Gemfile b/Gemfile index bb8f4fe6..794ed8fb 100644 --- a/Gemfile +++ b/Gemfile @@ -16,8 +16,12 @@ end group :test do gem 'capybara-email', '~> 3.0' - gem 'selenium-webdriver', require: false - gem 'puma' + gem 'generator_spec', '~> 0.9.3' + gem 'launchy' + gem 'coveralls', require: false + gem 'rspec-retry' + gem 'falcon' + gem 'falcon-capybara' end # Database Configuration diff --git a/app/views/refinery/inquiries/inquiries/_form.html.erb b/app/views/refinery/inquiries/inquiries/_form.html.erb index 2bd79988..ebb4e425 100644 --- a/app/views/refinery/inquiries/inquiries/_form.html.erb +++ b/app/views/refinery/inquiries/inquiries/_form.html.erb @@ -50,6 +50,6 @@
<%= f.submit t('.send') %> - <%= link_to t('.privacy_policy'), "/privacy-policy", :id => "privacy_link" if Refinery::Inquiries.show_contact_privacy_link %> + <%= link_to t('.privacy_policy'), Refinery::Inquiries.privacy_link, id: "privacy_link" if Refinery::Inquiries.show_contact_privacy_link %>
<% end %> diff --git a/lib/refinery/inquiries/configuration.rb b/lib/refinery/inquiries/configuration.rb index 69b5a426..9b863640 100644 --- a/lib/refinery/inquiries/configuration.rb +++ b/lib/refinery/inquiries/configuration.rb @@ -8,11 +8,13 @@ module Inquiries config_accessor :show_placeholders config_accessor :show_flash_notice config_accessor :send_notifications_for_inquiries_marked_as_spam + config_accessor :privacy_link config_accessor :from_name config_accessor :post_path, :page_path_new, :page_path_thank_you config_accessor :filter_spam, :recaptcha_site_key self.show_contact_privacy_link = true + self.privacy_link = "/privacy-policy" self.show_company_field = false self.show_phone_number_field = true self.show_placeholders = true diff --git a/spec/features/refinery/inquiries/admin/inquiries_spec.rb b/spec/features/refinery/inquiries/admin/inquiries_spec.rb index 06f7a44f..02f1a232 100644 --- a/spec/features/refinery/inquiries/admin/inquiries_spec.rb +++ b/spec/features/refinery/inquiries/admin/inquiries_spec.rb @@ -14,7 +14,7 @@ module Admin :message => "Hello, I really like your website. Was it hard to build and maintain or could anyone do it?") end - let(:delete_first_inquiry){ -> { find_link("Remove this inquiry forever", match: :first).click } } + let(:delete_first_inquiry){ find_link("Remove this inquiry forever", match: :first).click } context "when there are no inquiries" do before { Refinery::Inquiries::Inquiry.destroy_all } @@ -86,7 +86,7 @@ module Admin it "removes inquiry" do visit refinery.inquiries_admin_inquiries_path - expect(delete_first_inquiry).to change(Refinery::Inquiries::Inquiry, :count).by(-1) + expect { delete_first_inquiry }.to change(Refinery::Inquiries::Inquiry, :count).by(-1) expect(page).to have_content("'#{inquiry.name}' was successfully removed.") end diff --git a/spec/features/refinery/inquiries/inquiries_spec.rb b/spec/features/refinery/inquiries/inquiries_spec.rb index 81f0a962..7cba31a0 100644 --- a/spec/features/refinery/inquiries/inquiries_spec.rb +++ b/spec/features/refinery/inquiries/inquiries_spec.rb @@ -4,16 +4,6 @@ module Refinery module Inquiries describe "inquiries", :type => :feature do - - making_an_inquiry = -> (name, email, message) { - ensure_on(refinery.inquiries_new_inquiry_path) - fill_in "Name", :with => name - fill_in "Email", :with => email - fill_in "Message", :with => message - click_button "Send message" - } - - before do # load in seeds we use in migration Refinery::Inquiries::Engine.load_seed @@ -43,11 +33,12 @@ module Inquiries it "does not save the inquiry" do visit refinery.inquiries_new_inquiry_path - expect{ making_an_inquiry('my name 😀 ', 'jun!k@ok', '☄︎☀︎☽ ') }.not_to change(Refinery::Inquiries::Inquiry, :count) + expect { making_an_inquiry('my name 😀 ', 'jun!k@ok', '☄︎☀︎☽ ') }.not_to change(Refinery::Inquiries::Inquiry, :count) expect(page).to have_content("Email is invalid") end end + describe 'configuration' do describe "privacy" do context "when 'show contact privacy link' setting is false" do @@ -74,6 +65,18 @@ module Inquiries expect(page).to have_content("We value your privacy") expect(page).to have_selector("a[href='/privacy-policy']") end + + context 'when privacy_link has been set to another page' do + before(:each) do + allow(Refinery::Inquiries.config).to receive(:privacy_link).and_return('/corporate/privacy') + end + + it "has a link to the configured page" do + visit refinery.inquiries_new_inquiry_path + + expect(page).to have_selector("a[href='/corporate/privacy']") + end + end end end @@ -162,3 +165,4 @@ module Inquiries end end end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 8705fbd9..163b36b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,31 +1,84 @@ +$VERBOSE = ENV['VERBOSE'] || false + require 'rubygems' +ENGINE_RAILS_ROOT = File.join(File.dirname(__FILE__), '../') unless defined?(ENGINE_RAILS_ROOT) + # Configure Rails Environment ENV["RAILS_ENV"] ||= 'test' +if ENV['TRAVIS'] + require 'coveralls' + Coveralls.wear! +end + require File.expand_path("../dummy/config/environment", __FILE__) require 'rspec/rails' require 'capybara/rspec' require 'webdrivers/chromedriver' +require 'falcon/capybara' +Capybara.server = :falcon + +if ENV['RETRY_COUNT'] + require 'rspec/retry' + RSpec.configure do |config| + # rspec-retry + config.verbose_retry = true + config.default_sleep_interval = 0.33 + config.clear_lets_on_failure = true + config.default_retry_count = ENV["RETRY_COUNT"] + end +end Rails.backtrace_cleaner.remove_silencers! RSpec.configure do |config| config.mock_with :rspec config.filter_run focus: true + config.filter_run js: true if ENV['JS'] == 'true' + config.filter_run js: nil if ENV['JS'] == 'false' config.run_all_when_everything_filtered = true -end + config.include ActionView::TestCase::Behavior, file_path: %r{spec/presenters} + config.infer_spec_type_from_file_location! -Capybara.register_driver :chrome do |app| - Capybara::Selenium::Driver.new(app, browser: :chrome) -end -Capybara.javascript_driver = :chrome + config.use_transactional_fixtures = true + + config.when_first_matching_example_defined(type: :system) do + config.before :suite do + # Preload assets + # This should avoid capybara timeouts, and avoid counting asset compilation + # towards the timing of the first feature spec. + Rails.application.precompiled_assets + end + end + + config.before(:each) do + ::I18n.default_locale = I18n.locale = Mobility.locale = :en + end + config.before(:each, type: :system) do + driven_by :rack_test + end + + config.before(:each, type: :system, js: true) do + driven_by :selenium, using: :headless_chrome, screen_size: [1400, 1080] + end + config.raise_errors_for_deprecations! + unless ENV['FULL_BACKTRACE'] + config.backtrace_exclusion_patterns = %w( + rails actionpack railties capybara activesupport rack warden rspec actionview + activerecord dragonfly benchmark quiet_assets rubygems + ).map { |noisy| /\b#{noisy}\b/ } + end + + # Store last errors so we can run rspec with --only-failures + config.example_status_persistence_file_path = ".rspec_failures" +end # Requires supporting files with custom matchers and macros, etc, # in ./support/ and its subdirectories including factories. -([Rails.root.to_s] | ::Refinery::Plugins.registered.pathnames).map{|p| +([ENGINE_RAILS_ROOT, Rails.root.to_s].uniq | Refinery::Plugins.registered.pathnames).map{ |p| Dir[File.join(p, 'spec', 'support', '**', '*.rb').to_s] }.flatten.sort.each do |support_file| require support_file diff --git a/spec/support/spec_helper.rb b/spec/support/spec_helper.rb index bad6fa9d..a50055c2 100644 --- a/spec/support/spec_helper.rb +++ b/spec/support/spec_helper.rb @@ -6,3 +6,10 @@ def ensure_on(path) visit(path) unless current_path == path end +def making_an_inquiry (name, email, message) + ensure_on(refinery.inquiries_new_inquiry_path) + fill_in "Name", :with => name + fill_in "Email", :with => email + fill_in "Message", :with => message + click_button "Send message" +end From 99fa8ed203897c8344cdf5e9fac8d7ec5b5419ce Mon Sep 17 00:00:00 2001 From: Anita Date: Fri, 4 Aug 2023 16:25:48 +0800 Subject: [PATCH 6/7] Remove Rails 6.0.3 workaround --- config/initializers/active_record.rb | 12 ------------ 1 file changed, 12 deletions(-) delete mode 100644 config/initializers/active_record.rb diff --git a/config/initializers/active_record.rb b/config/initializers/active_record.rb deleted file mode 100644 index 86792f34..00000000 --- a/config/initializers/active_record.rb +++ /dev/null @@ -1,12 +0,0 @@ -module PolymorphicBelongsTo - def valid_options(options) - valid = super + [:polymorphic, :counter_cache, :optional, :default] - valid += [:foreign_type] if options[:polymorphic] - valid += [:ensuring_owner_was] if options[:dependent] == :destroy_async - valid - end -end - -ActiveSupport.on_load :active_record do - ActiveRecord::Associations::Builder::BelongsTo.extend PolymorphicBelongsTo -end From 13ea3a6b491cc82ae65d12cb24d7fa7e068f9045 Mon Sep 17 00:00:00 2001 From: Anita Date: Fri, 4 Aug 2023 16:33:24 +0800 Subject: [PATCH 7/7] Update rails dependency to ~>6.1 --- refinerycms-inquiries.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/refinerycms-inquiries.gemspec b/refinerycms-inquiries.gemspec index ed2847ac..c5c44c84 100644 --- a/refinerycms-inquiries.gemspec +++ b/refinerycms-inquiries.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- spec/*`.split("\n") s.add_dependency 'refinerycms-core', '~> 4.1' - s.add_dependency 'rails', '~>6.0.0' + s.add_dependency 'rails', '~>6.1' s.add_dependency 'mobility' s.add_dependency 'refinerycms-settings', '~> 4.0' s.add_dependency 'filters_spam', '~> 0.2'