Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update steam #87

Merged
merged 3 commits into from
Oct 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 4 additions & 3 deletions ci.docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -57,4 +58,4 @@ services:
volumes:
esdata:
db:
version: '3'
version: "3.8"
32 changes: 20 additions & 12 deletions lib/shop_invader/liquid/tags/erp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/shop_invader/middlewares/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion odoo/Dockerfile-12
Original file line number Diff line number Diff line change
@@ -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 \
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/server/auth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions spec/integration/template/config/site.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand Down
6 changes: 3 additions & 3 deletions spec/liquid/tags/erp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,22 @@

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

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
Expand Down
7 changes: 0 additions & 7 deletions spec/liquid/tags/path_to_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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' %}" }
Expand Down
8 changes: 4 additions & 4 deletions spec/middlewares/erp_proxy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,15 @@
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

context "With full path" do
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

Expand All @@ -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

Expand All @@ -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
Expand Down
1 change: 0 additions & 1 deletion spec/support/helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Loading