Moved cookies_policy_helper to Web engine and respective spec

This commit is contained in:
luisramos0
2018-09-17 13:53:19 +01:00
parent 95f2f92cf3
commit c22ac0086b
4 changed files with 75 additions and 72 deletions

View File

@@ -1,21 +0,0 @@
module CookiesPolicyHelper
def render_cookie_entry(cookie_name, cookie_desc, cookie_domain = nil)
render partial: 'cookies_policy_entry',
locals: { cookie_name: cookie_name,
cookie_desc: cookie_desc,
cookie_domain: cookie_domain }
end
def matomo_iframe_src
"#{Spree::Config.matomo_url}"\
"/index.php?module=CoreAdminHome&action=optOut"\
"&language=#{locale_language}"\
"&backgroundColor=&fontColor=222222&fontSize=16px&fontFamily=%22Roboto%22%2C%20Arial%2C%20sans-serif"
end
# removes country from locale if needed
# for example, both locales en and en_GB return language en
def locale_language
I18n.locale[0..1]
end
end

View File

@@ -0,0 +1,23 @@
module Web
module CookiesPolicyHelper
def render_cookie_entry(cookie_name, cookie_desc, cookie_domain = nil)
render partial: 'cookies_policy_entry',
locals: { cookie_name: cookie_name,
cookie_desc: cookie_desc,
cookie_domain: cookie_domain }
end
def matomo_iframe_src
"#{Spree::Config.matomo_url}"\
"/index.php?module=CoreAdminome&action=optOut"\
"&language=#{locale_language}"\
"&backgroundColor=&fontColor=222222&fontSize=16px&fontFamily=%22Roboto%22%2C%20Arial%2C%20sans-serif"
end
# removes country from locale if needed
# for example, both locales en and en_GB return language en
def locale_language
I18n.locale[0..1]
end
end
end

View File

@@ -0,0 +1,52 @@
require 'spec_helper'
module Web
describe CookiesPolicyHelper, type: :helper do
# keeps global state unchanged
around do |example|
original_locale = I18n.locale
original_matomo_url = Spree::Config.matomo_url
example.run
Spree::Config.matomo_url = original_matomo_url
I18n.locale = original_locale
end
describe "matomo optout iframe src" do
describe "when matomo url is set" do
before do
Spree::Config.matomo_url = "http://matomo.org/"
end
scenario "includes the matomo URL" do
expect(helper.matomo_iframe_src).to include Spree::Config.matomo_url
end
scenario "is not equal to the matomo URL" do
expect(helper.matomo_iframe_src).to_not eq Spree::Config.matomo_url
end
end
scenario "is not nil, when matomo url is nil" do
Spree::Config.matomo_url = nil
expect(helper.matomo_iframe_src).to_not eq nil
end
end
describe "language from locale" do
scenario "when locale is the language" do
I18n.locale = "en"
expect(helper.locale_language).to eq "en"
end
scenario "is empty when locale is empty" do
I18n.locale = ""
expect(helper.locale_language).to be_empty
end
scenario "is only the language, when locale includes country" do
I18n.locale = "en_GB"
expect(helper.locale_language).to eq "en"
end
end
end
end

View File

@@ -1,51 +0,0 @@
require 'spec_helper'
describe CookiesPolicyHelper, type: :helper do
# keeps global state unchanged
around do |example|
original_locale = I18n.locale
original_matomo_url = Spree::Config.matomo_url
example.run
Spree::Config.matomo_url = original_matomo_url
I18n.locale = original_locale
end
describe "matomo optout iframe src" do
describe "when matomo url is set" do
before do
Spree::Config.matomo_url = "http://matomo.org/"
end
scenario "includes the matomo URL" do
expect(helper.matomo_iframe_src).to include Spree::Config.matomo_url
end
scenario "is not equal to the matomo URL" do
expect(helper.matomo_iframe_src).to_not eq Spree::Config.matomo_url
end
end
scenario "is not nil, when matomo url is nil" do
Spree::Config.matomo_url = nil
expect(helper.matomo_iframe_src).to_not eq nil
end
end
describe "language from locale" do
scenario "when locale is the language" do
I18n.locale = "en"
expect(helper.locale_language).to eq "en"
end
scenario "is empty when locale is empty" do
I18n.locale = ""
expect(helper.locale_language).to be_empty
end
scenario "is only the language, when locale includes country" do
I18n.locale = "en_GB"
expect(helper.locale_language).to eq "en"
end
end
end