diff --git a/.rubocop.yml b/.rubocop.yml index c2e82f708f2..2bf1f9b60e8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -12,6 +12,8 @@ AllCops: - 'node_modules/**/*' # The parser gem fails to parse this file with out current Ruby version. - 'spec/factories.rb' + # Excluding: inadequate Naming/FileName rule rejects GemFile name with camelcase + - 'engines/web/Gemfile' # OFN SETTINGS # Cop settings that have been agreed upon by the OFN community diff --git a/Gemfile b/Gemfile index b0dbe9e9fb8..84cd7beefbf 100644 --- a/Gemfile +++ b/Gemfile @@ -10,6 +10,8 @@ gem 'i18n-js', '~> 3.0.0' # Patched version. See http://rubysec.com/advisories/CVE-2015-5312/. gem 'nokogiri', '>= 1.6.7.1' +gem 'web', path: './engines/web' + gem 'pg' gem 'spree', github: 'openfoodfoundation/spree', branch: 'step-6a', ref: '69db1c090f3711088d84b524f1b94d25e6d21616' gem 'spree_i18n', github: 'spree/spree_i18n', branch: '1-3-stable' diff --git a/Gemfile.lock b/Gemfile.lock index 039dc1b861b..1809931fb99 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -133,6 +133,11 @@ GIT activemodel (>= 3.0) railties (>= 3.0) +PATH + remote: engines/web + specs: + web (0.0.1) + GEM remote: https://rubygems.org/ specs: @@ -764,6 +769,7 @@ DEPENDENCIES capybara (>= 2.15.4) coffee-rails (~> 3.2.1) compass-rails + web! custom_error_message! daemons dalli diff --git a/app/assets/stylesheets/darkswarm/all.scss b/app/assets/stylesheets/darkswarm/all.scss index b3f5433d8e3..2f73f5e796e 100644 --- a/app/assets/stylesheets/darkswarm/all.scss +++ b/app/assets/stylesheets/darkswarm/all.scss @@ -12,6 +12,7 @@ @import 'base/*'; @import '*'; @import 'pages/*'; +@import '../web/all'; ofn-modal { display: block; diff --git a/app/controllers/angular_templates_controller.rb b/app/controllers/angular_templates_controller.rb deleted file mode 100644 index 44d870cc58e..00000000000 --- a/app/controllers/angular_templates_controller.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AngularTemplatesController < ApplicationController - def show - render params[:id].to_s, layout: nil - end -end diff --git a/app/controllers/api/cookies_consent_controller.rb b/app/controllers/api/cookies_consent_controller.rb deleted file mode 100644 index 89016c20661..00000000000 --- a/app/controllers/api/cookies_consent_controller.rb +++ /dev/null @@ -1,26 +0,0 @@ -module Api - class CookiesConsentController < BaseController - include ActionController::Cookies - respond_to :json - - def show - render json: { cookies_consent: cookies_consent.exists? } - end - - def create - cookies_consent.set - show - end - - def destroy - cookies_consent.destroy - show - end - - private - - def cookies_consent - @cookies_consent ||= CookiesConsent.new(cookies, request.host) - end - end -end diff --git a/app/helpers/cookies_policy_helper.rb b/app/helpers/cookies_policy_helper.rb deleted file mode 100644 index 5bcec92383b..00000000000 --- a/app/helpers/cookies_policy_helper.rb +++ /dev/null @@ -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 diff --git a/app/helpers/footer_links_helper.rb b/app/helpers/footer_links_helper.rb new file mode 100644 index 00000000000..71e8683da0b --- /dev/null +++ b/app/helpers/footer_links_helper.rb @@ -0,0 +1,11 @@ +require 'web/cookies_consent' + +module FooterLinksHelper + def cookies_policy_link + link_to( t( '.footer_data_cookies_policy' ), '', 'cookies-policy-modal' => true, 'cookies-banner' => !Web::CookiesConsent.new(cookies, request.host).exists? && Spree::Config.cookies_consent_banner_toggle) + end + + def privacy_policy_link + link_to( t( '.footer_data_privacy_policy' ), Spree::Config.privacy_policy_url, target: '_blank' ) + end +end diff --git a/app/services/cookies_consent.rb b/app/services/cookies_consent.rb deleted file mode 100644 index 64c4dfa083a..00000000000 --- a/app/services/cookies_consent.rb +++ /dev/null @@ -1,29 +0,0 @@ -class CookiesConsent - COOKIE_NAME = 'cookies_consent'.freeze - - def initialize(cookies, domain) - @cookies = cookies - @domain = domain - end - - def exists? - cookies.key?(COOKIE_NAME) - end - - def destroy - cookies.delete(COOKIE_NAME, domain: domain) - end - - def set - cookies[COOKIE_NAME] = { - value: COOKIE_NAME, - expires: 1.year.from_now, - domain: domain, - httponly: true - } - end - - private - - attr_reader :cookies, :domain -end diff --git a/app/views/layouts/darkswarm.html.haml b/app/views/layouts/darkswarm.html.haml index e3cd92951fc..79d78c67ea0 100644 --- a/app/views/layouts/darkswarm.html.haml +++ b/app/views/layouts/darkswarm.html.haml @@ -19,6 +19,7 @@ %script{src: "//maps.googleapis.com/maps/api/js?libraries=places,geometry#{ ENV['GOOGLE_MAPS_API_KEY'] ? '&key=' + ENV['GOOGLE_MAPS_API_KEY'] : ''} "} = stylesheet_link_tag "darkswarm/all" = javascript_include_tag "darkswarm/all" + = javascript_include_tag "web/all" = render "layouts/i18n_script" = render "layouts/bugherd_script" diff --git a/app/views/shared/_footer.html.haml b/app/views/shared/_footer.html.haml index 9c7126c999b..4142a8fbec1 100644 --- a/app/views/shared/_footer.html.haml +++ b/app/views/shared/_footer.html.haml @@ -140,8 +140,6 @@ = t '.footer_legal_text_html', {content_license: link_to('CC BY-SA 3.0', 'https://creativecommons.org/licenses/by-sa/3.0/'), code_license: link_to('AGPL 3', 'https://tldrlegal.com/license/gnu-affero-general-public-license-v3-(agpl-3.0)' )} %p.text-small %div - - cookies_policy_link = link_to( t( '.footer_data_cookies_policy' ), '', 'cookies-policy-modal' => true, 'cookies-banner' => !CookiesConsent.new(cookies, request.host).exists? && Spree::Config.cookies_consent_banner_toggle) - - privacy_policy_link = link_to( t( '.footer_data_privacy_policy' ), Spree::Config.privacy_policy_url, :target => '_blank' ) - if Spree::Config.privacy_policy_url.present? = t '.footer_data_text_with_privacy_policy_html', {cookies_policy: cookies_policy_link.html_safe, privacy_policy: privacy_policy_link.html_safe } - else diff --git a/config/application.rb b/config/application.rb index 241281d00d1..a872fdfe401 100644 --- a/config/application.rb +++ b/config/application.rb @@ -143,6 +143,7 @@ class Application < Rails::Application config.assets.initialize_on_precompile = true config.assets.precompile += ['iehack.js'] config.assets.precompile += ['admin/all.css', 'admin/*.js', 'admin/**/*.js'] + config.assets.precompile += ['web/all.css', 'web/all.js'] config.assets.precompile += ['darkswarm/all.css', 'darkswarm/all.js'] config.assets.precompile += ['mail/all.css'] config.assets.precompile += ['shared/*'] diff --git a/config/routes.rb b/config/routes.rb index 4f6125c8ac4..bc3fc303f0f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -88,8 +88,6 @@ get '/:id/shop', to: 'enterprises#shop', as: 'enterprise_shop' get "/enterprises/:permalink", to: redirect("/") # Legacy enterprise URL - get "/angular-templates/:id", to: "angular_templates#show", constraints: { name: %r{[\/\w\.]+} } - namespace :api do resources :enterprises do post :update_image, on: :member @@ -109,10 +107,6 @@ get :job_queue end - scope '/cookies' do - resource :consent, only: [:show, :create, :destroy], :controller => "cookies_consent" - end - resources :customers, only: [:index, :update] post '/product_images/:product_id', to: 'product_images#update_product_image' @@ -120,6 +114,9 @@ get 'sitemap.xml', to: 'sitemap#index', defaults: { format: 'xml' } + # Mount Web engine routes + mount Web::Engine, :at => '/' + # Mount Spree's routes mount Spree::Core::Engine, :at => '/' end diff --git a/engines/web/README.md b/engines/web/README.md new file mode 100644 index 00000000000..87945856ef2 --- /dev/null +++ b/engines/web/README.md @@ -0,0 +1,5 @@ +# Web + +This is the rails engine for the Web domain. + +See our wiki for [more info about domains and engines in OFN](https://github.com/openfoodfoundation/openfoodnetwork/wiki/Tech-Doc:-How-OFN-is-organized-in-Domains-using-Rails-Engines). diff --git a/engines/web/app/assets/javascripts/web/all.js b/engines/web/app/assets/javascripts/web/all.js new file mode 100644 index 00000000000..15ebed9422b --- /dev/null +++ b/engines/web/app/assets/javascripts/web/all.js @@ -0,0 +1,13 @@ +// This is a manifest file that'll be compiled into application.js, which will include all the files +// listed below. +// +// Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, +// or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. +// +// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the +// the compiled file. +// +// WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD +// GO AFTER THE REQUIRES BELOW. +// +//= require_tree . diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_controller.js.coffee b/engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_controller.js.coffee similarity index 100% rename from app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_controller.js.coffee rename to engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_controller.js.coffee diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_directive.js.coffee b/engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_directive.js.coffee similarity index 56% rename from app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_directive.js.coffee rename to engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_directive.js.coffee index 0599646cb79..a00354774c8 100644 --- a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_directive.js.coffee +++ b/engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_directive.js.coffee @@ -1,6 +1,7 @@ -Darkswarm.directive 'cookiesBanner', (CookiesBannerService) -> +Darkswarm.directive 'cookiesBanner', (CookiesBannerService, CookiesPolicyModalService) -> restrict: 'A' link: (scope, elm, attr)-> return if not attr.cookiesBanner? || attr.cookiesBanner == 'false' CookiesBannerService.enable() + return if CookiesPolicyModalService.isEnabled() CookiesBannerService.open() diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_service.js.coffee b/engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_service.js.coffee similarity index 86% rename from app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_service.js.coffee rename to engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_service.js.coffee index 139552a2149..c9d2911f73f 100644 --- a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner_service.js.coffee +++ b/engines/web/app/assets/javascripts/web/cookies_banner/cookies_banner_service.js.coffee @@ -4,7 +4,7 @@ Darkswarm.factory "CookiesBannerService", (Navigation, $modal, $location, Redire modalMessage: null isEnabled: false - open: (path, template = 'darkswarm/cookies_banner/cookies_banner.html') => + open: (path, template = 'angular-templates/cookies_banner.html') => return unless @isEnabled @modalInstance = $modal.open templateUrl: template diff --git a/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_controller.js.coffee b/engines/web/app/assets/javascripts/web/cookies_policy/cookies_policy_modal_controller.js.coffee similarity index 100% rename from app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_controller.js.coffee rename to engines/web/app/assets/javascripts/web/cookies_policy/cookies_policy_modal_controller.js.coffee diff --git a/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_directive.js.coffee b/engines/web/app/assets/javascripts/web/cookies_policy/cookies_policy_modal_directive.js.coffee similarity index 100% rename from app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_directive.js.coffee rename to engines/web/app/assets/javascripts/web/cookies_policy/cookies_policy_modal_directive.js.coffee diff --git a/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_service.js.coffee b/engines/web/app/assets/javascripts/web/cookies_policy/cookies_policy_modal_service.js.coffee similarity index 69% rename from app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_service.js.coffee rename to engines/web/app/assets/javascripts/web/cookies_policy/cookies_policy_modal_service.js.coffee index 0f91645cfd8..a988b1eb0fa 100644 --- a/app/assets/javascripts/darkswarm/cookies_policy/cookies_policy_modal_service.js.coffee +++ b/engines/web/app/assets/javascripts/web/cookies_policy/cookies_policy_modal_service.js.coffee @@ -5,7 +5,7 @@ Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location, C modalMessage: null constructor: -> - if $location.path() is @defaultPath || location.pathname is @defaultPath + if @isEnabled() @open '' open: (path = false, template = 'angular-templates/cookies_policy.html') => @@ -13,18 +13,16 @@ Darkswarm.factory "CookiesPolicyModalService", (Navigation, $modal, $location, C templateUrl: template windowClass: "cookies-policy-modal medium" - @closeCookiesBanner() - @onCloseReOpenCookiesBanner() + CookiesBannerService.close() + @onCloseOpenCookiesBanner() selectedPath = path || @defaultPath Navigation.navigate selectedPath - closeCookiesBanner: => - setTimeout -> - CookiesBannerService.close() - , 200 - - onCloseReOpenCookiesBanner: => + onCloseOpenCookiesBanner: => @modalInstance.result.then( -> CookiesBannerService.open(), -> CookiesBannerService.open() ) + + isEnabled: => + $location.path() is @defaultPath || location.pathname is @defaultPath diff --git a/engines/web/app/assets/javascripts/web/web.js b/engines/web/app/assets/javascripts/web/web.js new file mode 100644 index 00000000000..dee720facdc --- /dev/null +++ b/engines/web/app/assets/javascripts/web/web.js @@ -0,0 +1,2 @@ +// Place all the behaviors and hooks related to the matching controller here. +// All this logic will automatically be available in application.js. diff --git a/engines/web/app/assets/stylesheets/web/all.css.scss b/engines/web/app/assets/stylesheets/web/all.css.scss new file mode 100644 index 00000000000..53fb36eef51 --- /dev/null +++ b/engines/web/app/assets/stylesheets/web/all.css.scss @@ -0,0 +1,2 @@ +@import 'web/pages/cookies_banner'; +@import 'web/pages/cookies_policy_modal'; diff --git a/app/assets/stylesheets/darkswarm/pages/cookies_banner.css.scss b/engines/web/app/assets/stylesheets/web/pages/cookies_banner.css.scss similarity index 94% rename from app/assets/stylesheets/darkswarm/pages/cookies_banner.css.scss rename to engines/web/app/assets/stylesheets/web/pages/cookies_banner.css.scss index 62232209771..a655c513a80 100644 --- a/app/assets/stylesheets/darkswarm/pages/cookies_banner.css.scss +++ b/engines/web/app/assets/stylesheets/web/pages/cookies_banner.css.scss @@ -1,4 +1,4 @@ -@import '../branding'; +@import 'darkswarm/branding'; .cookies-banner { background: $dark-grey; diff --git a/app/assets/stylesheets/darkswarm/pages/cookies_policy_modal.css.scss b/engines/web/app/assets/stylesheets/web/pages/cookies_policy_modal.css.scss similarity index 93% rename from app/assets/stylesheets/darkswarm/pages/cookies_policy_modal.css.scss rename to engines/web/app/assets/stylesheets/web/pages/cookies_policy_modal.css.scss index 8cf87b1ebb1..490fe6e529c 100644 --- a/app/assets/stylesheets/darkswarm/pages/cookies_policy_modal.css.scss +++ b/engines/web/app/assets/stylesheets/web/pages/cookies_policy_modal.css.scss @@ -1,4 +1,4 @@ -@import '../branding'; +@import 'darkswarm/branding'; .cookies-policy-modal { background: $disabled-light; diff --git a/engines/web/app/controllers/web/angular_templates_controller.rb b/engines/web/app/controllers/web/angular_templates_controller.rb new file mode 100644 index 00000000000..d8670a46643 --- /dev/null +++ b/engines/web/app/controllers/web/angular_templates_controller.rb @@ -0,0 +1,9 @@ +module Web + class AngularTemplatesController < ApplicationController + helper Web::Engine.helpers + + def show + render params[:id].to_s, layout: nil + end + end +end diff --git a/engines/web/app/controllers/web/api/cookies_consent_controller.rb b/engines/web/app/controllers/web/api/cookies_consent_controller.rb new file mode 100644 index 00000000000..e0ea13bafec --- /dev/null +++ b/engines/web/app/controllers/web/api/cookies_consent_controller.rb @@ -0,0 +1,30 @@ +require_dependency 'web/cookies_consent' + +module Web + module Api + class CookiesConsentController < BaseController + include ActionController::Cookies + respond_to :json + + def show + render json: { cookies_consent: cookies_consent.exists? } + end + + def create + cookies_consent.set + show + end + + def destroy + cookies_consent.destroy + show + end + + private + + def cookies_consent + @cookies_consent ||= Web::CookiesConsent.new(cookies, request.host) + end + end + end +end diff --git a/engines/web/app/controllers/web/application_controller.rb b/engines/web/app/controllers/web/application_controller.rb new file mode 100644 index 00000000000..410b0ae531b --- /dev/null +++ b/engines/web/app/controllers/web/application_controller.rb @@ -0,0 +1,5 @@ +module Web + class ApplicationController < ActionController::Base + protect_from_forgery with: :exception + end +end diff --git a/engines/web/app/helpers/web/cookies_policy_helper.rb b/engines/web/app/helpers/web/cookies_policy_helper.rb new file mode 100644 index 00000000000..0274b2d6c7d --- /dev/null +++ b/engines/web/app/helpers/web/cookies_policy_helper.rb @@ -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=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 +end diff --git a/app/views/angular_templates/_cookies_policy_entry.html.haml b/engines/web/app/views/web/angular_templates/_cookies_policy_entry.html.haml similarity index 100% rename from app/views/angular_templates/_cookies_policy_entry.html.haml rename to engines/web/app/views/web/angular_templates/_cookies_policy_entry.html.haml diff --git a/app/assets/javascripts/darkswarm/cookies_banner/cookies_banner.html.haml b/engines/web/app/views/web/angular_templates/cookies_banner.html.haml similarity index 100% rename from app/assets/javascripts/darkswarm/cookies_banner/cookies_banner.html.haml rename to engines/web/app/views/web/angular_templates/cookies_banner.html.haml diff --git a/app/views/angular_templates/cookies_policy.html.haml b/engines/web/app/views/web/angular_templates/cookies_policy.html.haml similarity index 100% rename from app/views/angular_templates/cookies_policy.html.haml rename to engines/web/app/views/web/angular_templates/cookies_policy.html.haml diff --git a/engines/web/config/routes.rb b/engines/web/config/routes.rb new file mode 100644 index 00000000000..121f3bdd9a0 --- /dev/null +++ b/engines/web/config/routes.rb @@ -0,0 +1,9 @@ +Web::Engine.routes.draw do + namespace :api do + scope '/cookies' do + resource :consent, only: [:show, :create, :destroy], controller: "cookies_consent" + end + end + + get "/angular-templates/:id", to: "angular_templates#show", constraints: { name: %r{[\/\w\.]+} } +end diff --git a/engines/web/lib/web.rb b/engines/web/lib/web.rb new file mode 100644 index 00000000000..613b7630143 --- /dev/null +++ b/engines/web/lib/web.rb @@ -0,0 +1,4 @@ +require "web/engine" + +module Web +end diff --git a/engines/web/lib/web/cookies_consent.rb b/engines/web/lib/web/cookies_consent.rb new file mode 100644 index 00000000000..64f6c0c825e --- /dev/null +++ b/engines/web/lib/web/cookies_consent.rb @@ -0,0 +1,31 @@ +module Web + class CookiesConsent + COOKIE_NAME = 'cookies_consent'.freeze + + def initialize(cookies, domain) + @cookies = cookies + @domain = domain + end + + def exists? + cookies.key?(COOKIE_NAME) + end + + def destroy + cookies.delete(COOKIE_NAME, domain: domain) + end + + def set + cookies[COOKIE_NAME] = { + value: COOKIE_NAME, + expires: 1.year.from_now, + domain: domain, + httponly: true + } + end + + private + + attr_reader :cookies, :domain + end +end diff --git a/engines/web/lib/web/engine.rb b/engines/web/lib/web/engine.rb new file mode 100644 index 00000000000..5285d6726b3 --- /dev/null +++ b/engines/web/lib/web/engine.rb @@ -0,0 +1,5 @@ +module Web + class Engine < ::Rails::Engine + isolate_namespace Web + end +end diff --git a/engines/web/lib/web/version.rb b/engines/web/lib/web/version.rb new file mode 100644 index 00000000000..ae51029b5c3 --- /dev/null +++ b/engines/web/lib/web/version.rb @@ -0,0 +1,3 @@ +module Web + VERSION = "0.0.1".freeze +end diff --git a/engines/web/spec/helpers/cookies_policy_helper_spec.rb b/engines/web/spec/helpers/cookies_policy_helper_spec.rb new file mode 100644 index 00000000000..b4d7f7fdf3f --- /dev/null +++ b/engines/web/spec/helpers/cookies_policy_helper_spec.rb @@ -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 diff --git a/engines/web/spec/spec_helper.rb b/engines/web/spec/spec_helper.rb new file mode 100644 index 00000000000..3306063166c --- /dev/null +++ b/engines/web/spec/spec_helper.rb @@ -0,0 +1,8 @@ +ENV["RAILS_ENV"] = "test" + +require File.expand_path("dummy/config/environment.rb", __dir__) +require "rails/test_help" + +Rails.backtrace_cleaner.remove_silencers! + +Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f } diff --git a/engines/web/web.gemspec b/engines/web/web.gemspec new file mode 100644 index 00000000000..f44ee68909e --- /dev/null +++ b/engines/web/web.gemspec @@ -0,0 +1,13 @@ +$LOAD_PATH.push File.expand_path('lib', __dir__) + +require "web/version" + +Gem::Specification.new do |s| + s.name = "web" + s.version = Web::VERSION + s.authors = ["developers@ofn"] + s.summary = "Web domain of the OFN solution." + + s.files = Dir["{app,config,db,lib}/**/*"] + ["LICENSE.txt", "Rakefile", "README.rdoc"] + s.test_files = Dir["test/**/*"] +end diff --git a/spec/helpers/cookies_policy_helper_spec.rb b/spec/helpers/cookies_policy_helper_spec.rb deleted file mode 100644 index b09f578a32c..00000000000 --- a/spec/helpers/cookies_policy_helper_spec.rb +++ /dev/null @@ -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