Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/sp-145/unified-circleci-test-pip…
Browse files Browse the repository at this point in the history
…eline' into sp-145/unified-circleci-test-pipeline

# Conflicts:
#	.circleci/config.yml
  • Loading branch information
mateus-po committed Jan 8, 2024
2 parents 9fc855f + ffe8201 commit 28d2640
Show file tree
Hide file tree
Showing 19 changed files with 66 additions and 48 deletions.
14 changes: 7 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ jobs:
- run:
name: Send test coverage
command: bash << parameters.run_file_path >>


workflows:
version: 2
Expand All @@ -139,13 +139,13 @@ workflows:
restore_cache_key_2: "spree-dashboard-bundle-v10-ruby-3-0"
ruby_image: circleci/ruby:3.0-node-browsers
redis_image: circleci/redis:6.2-alpine
run_file_path: ./.circleci/bundle_ruby_3_0.sh
run_file_path: ./bin/bundle_ruby_3_0.sh
save_cache_key: spree-dashboard-bundle-v10-ruby-3-0-{{ checksum "Gemfile.lock" }}
- run_test:
name: bundle_ruby_3_2
ruby_image: cimg/ruby:3.2.0-browsers
redis_image: circleci/redis:6.2-alpine
run_file_path: ./.circleci/bundle_ruby_3_2.sh
run_file_path: ./bin/bundle_ruby.sh
save_cache_key: spree-dashboard-bundle-v10-ruby-3-2-{{ checksum "Gemfile.lock" }}
- tests_postgres:
name: tests_ruby_3_2_rails_7_1_postgres
Expand All @@ -155,7 +155,7 @@ workflows:
redis_image: circleci/redis:6.2-alpine
postgres_image: circleci/postgres:12-alpine
store_artefacts: true
run_file_path: ./.circleci/tests_database_ci.sh
run_file_path: ./bin/tests_database_ci.sh
requires:
- bundle_ruby_3_2
- tests_postgres:
Expand All @@ -166,7 +166,7 @@ workflows:
redis_image: circleci/redis:6.2-alpine
postgres_image: circleci/postgres:12-alpine
store_artefacts: true
run_file_path: ./.circleci/tests_database_ci.sh
run_file_path: ./bin/tests_database_ci.sh
requires:
- bundle_ruby_3_0
- tests_mysql:
Expand All @@ -176,7 +176,7 @@ workflows:
redis_image: circleci/redis:6.2-alpine
mysql_image: circleci/mysql:8-ram
store_artefacts: true
run_file_path: ./.circleci/tests_database_ci.sh
run_file_path: ./bin/tests_database_ci.sh
requires:
- bundle_ruby_3_2

4 changes: 2 additions & 2 deletions app/assets/javascripts/spree/backend/global/tinymce.es6
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ document.addEventListener("spree:load", function() {
tinymce.init({
selector: '.spree-rte',
plugins: [
'image table paste code link table'
'image table paste code link table lists'
],
menubar: false,
toolbar: 'undo redo | styleselect | bold italic link forecolor backcolor | alignleft aligncenter alignright alignjustify | table | bullist numlist outdent indent | code '
Expand All @@ -14,7 +14,7 @@ document.addEventListener("spree:load", function() {
selector: '.spree-rte-simple',
menubar: false,
plugins: [
'image table paste link table'
'image table paste link table lists'
],
toolbar: 'undo redo | styleselect | bold italic link forecolor backcolor | alignleft aligncenter alignright alignjustify | table | bullist numlist outdent indent'
});
Expand Down
22 changes: 0 additions & 22 deletions app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class ProductsController < ResourceController
before_action :set_product_defaults, only: :new

create.before :create_before
create.before :fix_option_values_params_rails_7_1
update.before :update_before
update.before :skip_updating_status
update.after :update_status
Expand Down Expand Up @@ -168,27 +167,6 @@ def create_before
@prototype = Spree::Prototype.find(params[:product][:prototype_id])
end

def fix_option_values_params_rails_7_1
raise 'Verify if the patch is still needed' if Rails::VERSION::STRING >= '7.2.0'

if Rails::VERSION::STRING >= '7.1.0'
# This is a rather ugly fix for an issue with Rails 7.1.0 and 7.1.1
# As an example, a form field with name = option_values_hash[1][] and value = 5
# gets parsed incorrectly and is visible via params as the following structure
# { 'option_values_hash[1' => { '][]' => 5 } }
# This patch fixes that behavior to ensure compatibility with the existing templates
option_values_hash_keys = params[:product].keys.select { |e| e.starts_with?('option_values_hash[') }
option_values_hash = {}
option_values_hash_keys.each do |key|
value = params[:product].delete(key)
fixed_key = key.gsub(/option_values_hash\[/, '')
option_values_hash[fixed_key] ||= []
option_values_hash[fixed_key] << value['][]']
end
params[:product][:option_values_hash] = option_values_hash if option_values_hash.present?
end
end

def update_before
# NOTE: we only reset the product properties if we're receiving a post
# from the form on that tab
Expand Down
5 changes: 3 additions & 2 deletions app/views/spree/admin/payment_methods/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@
</div>
</div>

<% unless @object.new_record? %>
<div class="col-12 col-md-6">
<div class="card mb-3">
<div class="card-header">
<h5 class="mb-0"><%= Spree.t(:payment_provider_settings) %></h5>
</div>
<div class="card-body">
<div id="preference-settings" data-hook class="form-group">
<% unless @object.new_record? %>
<% if preference_fields(@object, f).empty? %>
<%= Spree.t('no_payment_provider_settings_message') %>
<% end %>
Expand All @@ -72,10 +72,11 @@
<% if @object.respond_to?(:preferences) %>
<div id="gateway-settings-warning" class="info warning"><%= Spree.t(:provider_settings_warning) %></div>
<% end %>
<% end %>
</div>
</div>
</div>
</div>
<% end %>

</div>
</div>
4 changes: 2 additions & 2 deletions app/views/spree/admin/prototypes/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<% ot.option_values.each do |ov| %>
<li>
<%= label_tag "option_value_#{ov.id}" do %>
<%= check_box_tag "product[option_values_hash[#{ot.id}]][]", ov.id, params[:product] && (params[:product][:option_values_hash] || {}).values.flatten.include?(ov.id.to_s), id: "option_value_#{ov.id}", class: "option-value" %>
<%= check_box_tag "product[option_values_hash][#{ot.id}][]", ov.id, params[:product] && (params[:product][:option_values_hash] || {}).values.flatten.include?(ov.id.to_s), id: "option_value_#{ov.id}", class: "option-value" %>
<div class="option-value__color" style="--presentation: <%= ov.presentation %>"></div>
<% end %>
</li>
Expand All @@ -23,7 +23,7 @@
<ul class="option-type-values">
<% ot.option_values.each do |ov| %>
<li>
<%= check_box_tag "product[option_values_hash[#{ot.id}]][]", ov.id, params[:product] && (params[:product][:option_values_hash] || {}).values.flatten.include?(ov.id.to_s), id: "option_value_#{ov.id}", class: "option-value" %>
<%= check_box_tag "product[option_values_hash][#{ot.id}][]", ov.id, params[:product] && (params[:product][:option_values_hash] || {}).values.flatten.include?(ov.id.to_s), id: "option_value_#{ov.id}", class: "option-value" %>
<%= label_tag "option_value_#{ov.id}", ov.presentation %>
</li>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/spree/admin/shared/_version.html.erb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<% if can?(:admin, current_store) && Spree::Backend::Config[:admin_show_version] %>
<% if can?(:admin, current_store) && Spree::Backend::RuntimeConfig[:admin_show_version] %>
<p
class="spree-version ml-3 my-3"
aria-label="Spree Commerce version">
Expand Down
11 changes: 11 additions & 0 deletions app/views/spree/admin/webhooks_subscribers/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<% if defined?(Spree::Vendor) && can?(:manage, Spree::Vendor) && !current_spree_vendor %>
<th><%= Spree.t(:vendor) %></th>
<% end %>
<th><%= Spree.t('admin.webhooks_subscribers.secret_key') %></th>
<th><%= Spree.t('admin.active') %></th>
<th><%= Spree.t('admin.webhooks_subscribers.subscriptions') %></th>
<th><%= Spree.t('admin.webhooks_subscribers.time_of_last_event') %></th>
Expand All @@ -31,6 +32,16 @@
<%= link_to webhooks_subscriber.vendor.name, spree.admin_vendor_path(webhooks_subscriber.vendor) if webhooks_subscriber.vendor.present? %>
</td>
<% end %>
<td>
<div class="input-group" data-controller="password-toggle">
<%= password_field_tag :password, webhooks_subscriber.secret_key, class: 'form-control unhide text-muted border-0 shadow-none bg-transparent', data: { password_toggle_target: 'unhide' }, readonly: true %>
<div class="input-group-append">
<%= button_tag class: 'btn btn-link rounded', data: { action: 'click->password-toggle#password' } do %>
<%= svg_icon name: "view.svg", width: '18', height: '18' %>
<% end %>
</div>
</div>
</td>
<td><%= active_badge(webhooks_subscriber.active) %></td>
<td><%= webhooks_subscriber.subscriptions&.sort&.join(', ') %></td>
<td><%= webhooks_subscriber.events.order(:created_at).last&.created_at %></td>
Expand Down
3 changes: 3 additions & 0 deletions bin/bundle_ruby.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
sudo apt-get update && sudo apt-get install libvips42
bundle config --local path vendor/bundle
bundle check || bundle install
4 changes: 4 additions & 0 deletions bin/bundle_ruby_3_0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4EB27DB2A3B88B8B
sudo apt-get update && sudo apt-get install libvips
bundle config --local path vendor/bundle
bundle check || bundle install
10 changes: 10 additions & 0 deletions bin/tests_database_ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
sudo apt-get update && sudo apt-get install libvips42
bundle config --local path vendor/bundle
bundle check || bundle install
bundle exec rake test_app
cd spec/dummy && yarn unlink @spree/dashboard
TESTFILES=$(circleci tests glob "spec/**/*_spec.rb" | circleci tests split --split-by=timings)
bundle exec rspec --format documentation \
--format RspecJunitFormatter \
-o ~/rspec/rspec.xml \
-- ${TESTFILES}
2 changes: 0 additions & 2 deletions lib/spree/backend/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
module Spree
module Backend
class Configuration < Preferences::Configuration
preference :admin_path, :string, default: '/admin'
preference :admin_products_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_orders_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_properties_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_promotions_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_customer_returns_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_users_per_page, :integer, default: Kaminari.config.default_per_page
preference :admin_show_version, :boolean, default: true
preference :locale, :string
preference :variants_per_page, :integer, default: Kaminari.config.default_per_page
preference :menus_per_page, :integer, default: Kaminari.config.default_per_page
Expand Down
2 changes: 2 additions & 0 deletions lib/spree/backend/engine.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require_relative 'configuration'
require_relative 'runtime_configuration'

module Spree
module Backend
Expand All @@ -9,6 +10,7 @@ class Engine < ::Rails::Engine

initializer 'spree.backend.environment', before: :load_config_initializers do |app|
Spree::Backend::Config = Spree::Backend::Configuration.new
Spree::Backend::RuntimeConfig = Spree::Backend::RuntimeConfiguration.new
app.config.spree_backend = Environment.new
end

Expand Down
8 changes: 8 additions & 0 deletions lib/spree/backend/runtime_configuration.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module Spree
module Backend
class RuntimeConfiguration < ::Spree::Preferences::RuntimeConfiguration
preference :admin_path, :string, default: '/admin'
preference :admin_show_version, :boolean, default: true
end
end
end
4 changes: 2 additions & 2 deletions lib/spree_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

module Spree
def self.admin_path
Spree::Backend::Config[:admin_path]
Spree::Backend::RuntimeConfig[:admin_path]
end

# Used to configure admin_path for Spree
Expand All @@ -13,6 +13,6 @@ def self.admin_path
# Spree.admin_path = '/custom-path'

def self.admin_path=(path)
Spree::Backend::Config[:admin_path] = path
Spree::Backend::RuntimeConfig[:admin_path] = path
end
end
2 changes: 1 addition & 1 deletion spec/features/admin/homepage_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
end

context 'if turned off' do
before { Spree::Backend::Config[:admin_show_version] = false }
before { Spree::Backend::RuntimeConfig[:admin_show_version] = false }

it 'is not displayed' do
visit spree.admin_path
Expand Down
1 change: 0 additions & 1 deletion spec/features/admin/orders/customer_details_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ def expect_form_value(selector, value)
context 'editing an order' do
before do
configure_spree_preferences do |config|
config.default_country_id = country.id
config.company = true
end

Expand Down
9 changes: 7 additions & 2 deletions spec/features/admin/products/products_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,8 @@ def build_option_type_with_values(name, values)

let(:prototype) do
size = build_option_type_with_values('size', %w(Small Medium Large))
FactoryBot.create(:prototype, name: 'Size', option_types: [size])
length = build_option_type_with_values('length', %w(Short, Long))
FactoryBot.create(:prototype, name: 'Size', option_types: [size, length])
end

let(:option_values_hash) do
Expand Down Expand Up @@ -252,14 +253,18 @@ def build_option_type_with_values(name, values)
fill_in 'product_price', with: '100'

find('[name="product[prototype_id]"]').find(:option, 'Size').select_option
check 'Small'
check 'Medium'
check 'Large'
check 'Short'
check 'Long'
find('[name="product[shipping_category_id]"]').find(:option, @shipping_category.name).select_option

click_button 'Create'

expect(page).to have_content('successfully created!')
expect(page).to have_field(id: 'product_status', with: 'draft')
expect(Spree::Product.last.variants.length).to eq(1)
expect(Spree::Product.last.variants.length).to eq(6)
end

it 'does not display variants when prototype does not contain option types' do
Expand Down
4 changes: 2 additions & 2 deletions spec/lib/spree/core_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

describe Spree do
describe '.admin_path' do
it { expect(described_class.admin_path).to eq(Spree::Backend::Config[:admin_path]) }
it { expect(described_class.admin_path).to eq(Spree::Backend::RuntimeConfig[:admin_path]) }
end

describe '.admin_path=' do
Expand All @@ -18,6 +18,6 @@
end

it { expect(described_class.admin_path).to eq(new_admin_path) }
it { expect(Spree::Backend::Config[:admin_path]).to eq(new_admin_path) }
it { expect(Spree::Backend::RuntimeConfig[:admin_path]).to eq(new_admin_path) }
end
end
3 changes: 1 addition & 2 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@
reset_spree_preferences

country = create(:country, name: 'United States of America', iso_name: 'UNITED STATES', iso: 'US', states_required: true)
Spree::Config[:default_country_id] = country.id

create(:store, default: true)
create(:store, default_country: country, default: true)
end

config.after(:each, type: :feature) do |example|
Expand Down

0 comments on commit 28d2640

Please sign in to comment.