diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d8500c17..528faa9e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -25,9 +25,13 @@ jobs: - name: Make db folder run: mkdir .db - name: Init Odoo Database - run: docker-compose -f ci.docker-compose.yml run --rm --service-ports odoo odoo --stop-after-init + run: docker compose -f ci.docker-compose.yml run --rm --service-ports odoo odoo --stop-after-init + - name: Flag as safe + run: git config --global --add safe.directory /home/runner/work/locomotive-shopinvader/locomotive-shopinvader - name: Install Shopinvader Gems - run: docker-compose -f ci.docker-compose.yml run --rm --service-ports shopinvader bundle install + run: docker compose -f ci.docker-compose.yml run --rm --service-ports shopinvader bundle install + - name: Set Algolia key in template/config/site.yml + run: sed -i "s/ALGOLIA-API-KEY/${ALGOLIA_API_KEY}/g" spec/integration/template/config/site.yml - name: Run Test - run: docker-compose -f ci.docker-compose.yml run -e ALGOLIA_API_KEY=$ALGOLIA_API_KEY --rm --service-ports shopinvader bundle exec rake spec + run: docker compose -f ci.docker-compose.yml run -e ALGOLIA_API_KEY=$ALGOLIA_API_KEY --rm --service-ports shopinvader bundle exec rake spec - uses: codecov/codecov-action@v2 diff --git a/Gemfile b/Gemfile index dbb9aa76..75d5a43c 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ git_source(:github) { |repo| "https://github.com/#{repo}.git" } # Specify your gem's dependencies in shop_invader.gemspec gemspec -gem 'locomotivecms_steam', '=1.6.0' +gem 'locomotivecms_steam', github: 'locomotivecms/steam', branch: 'master' gem 'faraday' gem 'algoliasearch' gem 'elasticsearch' diff --git a/Rakefile b/Rakefile index 90cb7f71..e857dca2 100644 --- a/Rakefile +++ b/Rakefile @@ -7,6 +7,7 @@ require 'json' task :clear do puts "\nClear partner generated from previous test\n".green + `psql -c "DELETE FROM shopinvader_partner WHERE record_id in (SELECT id FROM res_partner WHERE email ILIKE '%rspec%' OR name ILIKE '%RSPEC')"` `psql -c "DELETE FROM res_partner WHERE email ILIKE '%rspec%' OR name ILIKE '%RSPEC'"` end diff --git a/ci.docker-compose.yml b/ci.docker-compose.yml index e90a29f2..fbf4a619 100644 --- a/ci.docker-compose.yml +++ b/ci.docker-compose.yml @@ -5,7 +5,7 @@ services: - POSTGRES_DB=db - POSTGRES_PASSWORD=odoo volumes: - - db/:/var/lib/postgresql/data + - db:/var/lib/postgresql/data image: postgres:13 elastic: image: docker.elastic.co/elasticsearch/elasticsearch:7.0.0 @@ -44,9 +44,10 @@ services: - PGUSER=odoo - PGDATABASE=odoo-shopinvader-demo - PGPASSWORD=odoo - - ALGOLIA_APP_ID=C04JR8U8Y1 + - ALGOLIA_APP_ID=GH41KF783Z - ELASTIC_IP=127.0.0.1 - ELASTIC_PORT=9200 + - ALGOLIA_API_KEY=$ALGOLIA_API_KEY volumes: - .:/home/runner/work/locomotive-shopinvader/locomotive-shopinvader - ./bundle:/usr/local/bundle @@ -57,4 +58,4 @@ services: volumes: esdata: db: -version: '3' +version: "3.8" diff --git a/lib/shop_invader/liquid/tags/erp.rb b/lib/shop_invader/liquid/tags/erp.rb index 93e4c390..d8c0db04 100644 --- a/lib/shop_invader/liquid/tags/erp.rb +++ b/lib/shop_invader/liquid/tags/erp.rb @@ -5,22 +5,26 @@ module Tags class Erp < ::Liquid::Tag - include Concerns::Attributes + include Concerns::AttributesParser + include Concerns::AttributesEvaluator Base = "(#{::Liquid::VariableSignature}+)\s*(#{::Liquid::QuotedString}|#{::Liquid::VariableSignature}+)" Syntax = /#{Base}/o SyntaxWith = /#{Base}\s*with\s*(.*)?/o SyntaxAs = /#{Base}\s*as\s*(#{::Liquid::VariableSignature}+)/o SyntaxAsWith = /#{Base}\s*as\s*(#{::Liquid::VariableSignature}+)\s*with\s*(.*)?/o + attr_reader :attributes, :attributes_var_name def initialize(tag_name, markup, options) + super + syntax_error = false if markup =~ SyntaxAsWith @method_name, service_path, @to = $1, $2, $3 - parse_attributes($4) + @attributes = parse_markup($4) elsif markup =~ SyntaxWith @method_name, service_path = $1, $2 - parse_attributes($3) + @attributes = parse_markup($3) elsif markup =~ SyntaxAs @method_name, service_path, @to = $1, $2, $3 elsif markup =~ Syntax @@ -46,16 +50,20 @@ def initialize(tag_name, markup, options) end def render(context) - if @raw_attributes - evaluate_attributes(context) - end @context = context - if instance_variable_defined?(:@variable_service_path) - @service_path = context[@variable_service_path] - end - result = service.call(@method_name, @service_path, @attributes) - if @to - context.scopes.last[@to] = result + context.stack do + if @attributes + attrs = evaluate_attributes(context) + else + attrs = nil + end + if instance_variable_defined?(:@variable_service_path) + @service_path = context[@variable_service_path] + end + result = service.call(@method_name, @service_path, attrs) + if @to + context.scopes.last[@to] = result + end end nil end diff --git a/lib/shop_invader/middlewares/helpers.rb b/lib/shop_invader/middlewares/helpers.rb index 3cb3a72c..b87e5a9b 100644 --- a/lib/shop_invader/middlewares/helpers.rb +++ b/lib/shop_invader/middlewares/helpers.rb @@ -17,7 +17,7 @@ def render_response(content, code = 200, type = nil) private def set_200_header(headers) - headers['Cache-Control'] = env['steam.cache_control'] || "max-age=0, private, must-revalidate" + headers['cache-control'] = env['steam.cache_control'] || "max-age=0, private, must-revalidate" # Always inject a vary on accept-language for the header # if the site have multiple lang on the home page diff --git a/odoo/Dockerfile-12 b/odoo/Dockerfile-12 index 87d17344..bcdfab5e 100644 --- a/odoo/Dockerfile-12 +++ b/odoo/Dockerfile-12 @@ -1,4 +1,4 @@ -FROM ghcr.io/acsone/odoo-bedrock:12.0-py37-latest +FROM ghcr.io/acsone/odoo-bedrock:12.0-py37-focal-latest RUN set -e \ && apt update \ diff --git a/spec/integration/server/auth_spec.rb b/spec/integration/server/auth_spec.rb index 9c7a1689..abfd69e9 100644 --- a/spec/integration/server/auth_spec.rb +++ b/spec/integration/server/auth_spec.rb @@ -93,8 +93,8 @@ def app sign_in(params) expect(last_response.status).to eq 301 expect(last_response.location).to eq '/account/customer' - expect(last_response.headers['Set-Cookie']).to include 'customer=' - expect(last_response.headers['Set-Cookie']).to include 'cart=' + expect(last_response.headers['Set-Cookie'][1]).to include 'cart=' + expect(last_response.headers['Set-Cookie'][2]).to include 'customer=' # TODO FIX ODOO in order to get back this test green #expect(session).to include "erp_cart_id" expect(session).to include "store_customer" diff --git a/spec/integration/template/config/site.yml b/spec/integration/template/config/site.yml index 617aca4d..551fbdd5 100644 --- a/spec/integration/template/config/site.yml +++ b/spec/integration/template/config/site.yml @@ -31,8 +31,8 @@ metafields: logo: "/samples/assets/shop-logo.png" noimage: "/samples/assets/no-image.jpg" algolia: - application_id: 'C04JR8U8Y1' - api_key: "610bbcca628ecb66a8e3ec44483c9b33" + application_id: 'GH41KF783Z' + api_key: "ALGOLIA-API-KEY" indices: > [ { "name": "categories", "index": "ci_shopinvader_category" }, diff --git a/spec/liquid/tags/erp_spec.rb b/spec/liquid/tags/erp_spec.rb index 047f08a6..62b8d2a6 100644 --- a/spec/liquid/tags/erp_spec.rb +++ b/spec/liquid/tags/erp_spec.rb @@ -43,14 +43,14 @@ describe 'validates syntax with params' do let(:source) { "{% erp get 'sale_order' with foo: 'bar' %}" } - let(:params) { ['GET', 'sale_order', {'foo': 'bar'}]} + let(:params) { ['GET', 'sale_order', {'foo'=> 'bar'}]} it { expect { subject }.not_to raise_exception } it { is_expected.to eq '' } end describe 'validates syntax with params and result and render it' do let(:source) { "{% erp get 'sale_order' as sale with foo: 'bar' %}{{ sale }}" } - let(:params) { ['GET', 'sale_order', {'foo': 'bar'}]} + let(:params) { ['GET', 'sale_order', {'foo'=> 'bar'}]} it { expect { subject }.not_to raise_exception } it { is_expected.to eq '{"name"=>"SO42", "total"=>42}' } end @@ -58,7 +58,7 @@ describe 'validates syntax with dynamic params and result and render it' do let(:assigns) { { 'params' => Locomotive::Steam::Liquid::Drops::Params.new({ foo: 'bar' }) } } let(:source) { "{% erp get 'sale_order' as sale with foo: params.foo %}{{ sale }}" } - let(:params) { ['GET', 'sale_order', {'foo': 'bar'}]} + let(:params) { ['GET', 'sale_order', {'foo'=> 'bar'}]} it { expect { subject }.not_to raise_exception } it { is_expected.to eq '{"name"=>"SO42", "total"=>42}' } end diff --git a/spec/liquid/tags/path_to_spec.rb b/spec/liquid/tags/path_to_spec.rb index e4c645ba..d5d6039a 100644 --- a/spec/liquid/tags/path_to_spec.rb +++ b/spec/liquid/tags/path_to_spec.rb @@ -28,13 +28,6 @@ it { is_expected.to eq '/ipad-pro' } - context 'with a different template (old syntax)' do - - let(:source) { "{% path_to product, with: on_sale_product %}" } - it { is_expected.to eq '/on-sale/ipad-pro' } - - end - context 'with a different template' do let(:source) { "{% path_to product, with: 'on_sale_product' %}" } diff --git a/spec/middlewares/erp_proxy_spec.rb b/spec/middlewares/erp_proxy_spec.rb index 7bafa247..4f03664f 100644 --- a/spec/middlewares/erp_proxy_spec.rb +++ b/spec/middlewares/erp_proxy_spec.rb @@ -55,7 +55,7 @@ context "In json" do it 'return a 403' do expect(services.recaptcha).to receive(:verify).with('foo').and_return(false) - is_expected.to eq [403, {"Content-Type"=>"application/json"}, ["{'recaptcha_invalid': true}"]] + is_expected.to eq [403, {"content-type"=>"application/json"}, ["{'recaptcha_invalid': true}"]] end end @@ -63,7 +63,7 @@ let(:path) { 'invader/customer/create' } it 'return a 403' do expect(services.recaptcha).to receive(:verify).with('foo').and_return(false) - is_expected.to eq [403, {"Content-Type"=>"application/json"}, ["{'recaptcha_invalid': true}"]] + is_expected.to eq [403, {"content-type"=>"application/json"}, ["{'recaptcha_invalid': true}"]] end end @@ -73,7 +73,7 @@ it 'return a redirection' do expect(services.recaptcha).to receive(:verify).with('foo').and_return(false) - is_expected.to eq [302, {"Content-Type"=>"text/html", "Location"=>"http://bar"}, []] + is_expected.to eq [302, {"content-type"=>"text/html", "location"=>"http://bar"}, []] end end @@ -82,7 +82,7 @@ let(:params) { {'invader_error_url': 'http://bar', 'g-recaptcha-response': 'foo'} } it 'return a redirection' do expect(services.recaptcha).to receive(:verify).with('foo').and_return(false) - is_expected.to eq [302, {"Content-Type"=>"text/html", "Location"=>"http://bar"}, []] + is_expected.to eq [302, {"content-type"=>"text/html", "location"=>"http://bar"}, []] end end end diff --git a/spec/support/helpers.rb b/spec/support/helpers.rb index 03ad1896..233880ae 100644 --- a/spec/support/helpers.rb +++ b/spec/support/helpers.rb @@ -94,6 +94,5 @@ def default_fixture_site_path config.adapter = { name: :filesystem, path: default_fixture_site_path } config.asset_path = File.expand_path(File.join(default_fixture_site_path, 'public')) config.serve_assets = true - config.minify_assets = true end