diff --git a/Gemfile b/Gemfile index 940a4fc5..794ed8fb 100644 --- a/Gemfile +++ b/Gemfile @@ -16,7 +16,12 @@ end group :test do gem 'capybara-email', '~> 3.0' - gem 'poltergeist' + 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/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/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/lib/refinery/inquiries/spam_filter.rb b/lib/refinery/inquiries/spam_filter.rb index e02462c8..a35100ff 100644 --- a/lib/refinery/inquiries/spam_filter.rb +++ b/lib/refinery/inquiries/spam_filter.rb @@ -1,5 +1,8 @@ +# frozen_string_literal: true + require 'httpclient' require 'uri' +require 'English' module Refinery module Inquiries @@ -16,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 @@ -54,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? @@ -82,7 +85,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 @@ -90,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#{$!}\n" + rescue StandardError + Rails.logger.warn "There was an error delivering an inquiry confirmation:\n#{$ERROR_INFO}\n" end end end diff --git a/refinerycms-inquiries.gemspec b/refinerycms-inquiries.gemspec index 4d3a92bd..c5c44c84 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.1' 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..02f1a232 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..7cba31a0 100644 --- a/spec/features/refinery/inquiries/inquiries_spec.rb +++ b/spec/features/refinery/inquiries/inquiries_spec.rb @@ -2,6 +2,7 @@ module Refinery module Inquiries + describe "inquiries", :type => :feature do before do # load in seeds we use in migration @@ -13,15 +14,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,150 +26,143 @@ 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 + end - click_button "Send message" + 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 - expect(page).to have_content(/#{name_error_message}.+#{email_error_message}.+#{message_error_message}/m) - end - end + it "won't show link" do + visit refinery.inquiries_new_inquiry_path - 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) + expect(page).to have_no_content("We value your privacy") + expect(page).to have_no_selector("a[href='/privacy-policy']") + end end - it "won't show link" do - visit refinery.inquiries_new_inquiry_path + 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 - expect(page).to have_no_content("We value your privacy") - expect(page).to have_no_selector("a[href='/privacy-policy']") - end - end + it "shows the link" do + visit refinery.inquiries_new_inquiry_path - 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 + expect(page).to have_content("We value your privacy") + expect(page).to have_selector("a[href='/privacy-policy']") + end - it "shows the link" do - visit refinery.inquiries_new_inquiry_path + 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 - expect(page).to have_content("We value your privacy") - expect(page).to have_selector("a[href='/privacy-policy']") + 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 - 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 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..163b36b6 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,26 +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 'capybara/poltergeist' -Capybara.javascript_driver = :poltergeist +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 + config.include ActionView::TestCase::Behavior, file_path: %r{spec/presenters} + config.infer_spec_type_from_file_location! + + 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 new file mode 100644 index 00000000..a50055c2 --- /dev/null +++ b/spec/support/spec_helper.rb @@ -0,0 +1,15 @@ +def refinery_login + let(:logged_in_user) { Refinery::Core::NilUser.new } +end + +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