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

Run tests with Rails 7.1 #281

Merged
merged 8 commits into from
Oct 30, 2023
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
11 changes: 6 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ defaults: &defaults
BUNDLE_JOBS: 4
BUNDLE_RETRY: 3
BUNDLE_PATH: ~/spree/vendor/bundle
RAILS_VERSION: '~> 7.0.0'
RAILS_VERSION: '~> 7.1.0'
working_directory: ~/spree
docker:
- image: &ruby_3_0_image circleci/ruby:3.0-node-browsers
Expand Down Expand Up @@ -159,14 +159,15 @@ jobs:
DB: postgres
DB_HOST: localhost
DB_USERNAME: postgres
RAILS_VERSION: '~> 7.0.0'
docker:
- image: *ruby_3_0_image
- image: &postgres_image circleci/postgres:12-alpine
environment:
POSTGRES_USER: postgres
- image: *redis_image

tests_ruby_3_2_rails_7_0_postgres:
tests_ruby_3_2_rails_7_1_postgres:
<<: *run_tests_3_2
environment:
<<: *environment
Expand All @@ -178,7 +179,7 @@ jobs:
- image: *postgres_image
- image: *redis_image

tests_ruby_3_2_rails_7_0_mysql:
tests_ruby_3_2_rails_7_1_mysql:
<<: *run_tests_3_2
environment:
<<: *environment
Expand All @@ -198,12 +199,12 @@ workflows:
jobs:
- bundle_ruby_3_0
- bundle_ruby_3_2
- tests_ruby_3_2_rails_7_0_postgres:
- tests_ruby_3_2_rails_7_1_postgres:
requires:
- bundle_ruby_3_2
- tests_ruby_3_0_rails_7_0_postgres:
requires:
- bundle_ruby_3_0
- tests_ruby_3_2_rails_7_0_mysql:
- tests_ruby_3_2_rails_7_1_mysql:
requires:
- bundle_ruby_3_2
7 changes: 3 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw]
actionmailer actionpack actionview activejob activemodel activerecord
activestorage activesupport railties
].each do |rails_gem|
gem rails_gem, ENV.fetch('RAILS_VERSION', '~> 7.0.0'), require: false
gem rails_gem, ENV.fetch('RAILS_VERSION', '~> 7.1.0'), require: false
end

platforms :jruby do
Expand All @@ -30,8 +30,8 @@ group :test do
gem 'email_spec'
gem 'factory_bot_rails', '~> 6.0'
gem 'multi_json'
gem 'rspec-activemodel-mocks', '~> 1.0'
gem 'rspec-rails', '~> 5.0'
gem 'rspec-activemodel-mocks'
gem 'rspec-rails'
gem 'rspec-retry'
gem 'rspec_junit_formatter'
gem 'rswag-specs'
Expand All @@ -50,7 +50,6 @@ group :test, :development do
gem 'rubocop', require: false
gem 'rubocop-rspec', require: false
gem 'pry-byebug'
gem 'webdrivers'
gem 'selenium-webdriver'
gem 'puma'
gem 'ffaker'
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/spree/backend/stock_transfer.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ document.addEventListener("spree:load", function() {

TransferVariants.prototype._search_transfer_stock_items = function () {
var stockLocationId = $('#transfer_source_location_id').val()
return this.build_select(Spree.routes.stock_items_api_v2 + '?filter[stock_location_id_eq]=' + stockLocationId + '&include=variant', 'variant_product_name_or_variant_sku_cont')
return this.build_select(Spree.routes.stock_items_api_v2 + '?filter[stock_location_id_eq]=' + stockLocationId + '&include=variant', 'variants_product_name_or_variants_sku_cont')
}

TransferVariants.prototype.format_variant_result = function (result) {
Expand Down
22 changes: 22 additions & 0 deletions app/controllers/spree/admin/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ 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 @@ -167,6 +168,27 @@ 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
3 changes: 2 additions & 1 deletion spec/features/admin/stock_transfer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@
visit spree.admin_stock_transfers_path
click_on 'New Stock Transfer'

expected_select_item = "#{variant.name} - #{variant.sku} (#{variant.options_text})"
select2_open label: 'Variant'
select2_search variant.sku, from: 'Variant'
select2_select variant.name, from: 'Variant', match: :first
select2_select expected_select_item, from: 'Variant', match: :first

content = "#{variant.name} (#{variant.options_text}) - #{variant.sku}"
expect(page).to have_content(content)
Expand Down
1 change: 0 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
require 'spree/api/testing_support/factories'

require 'spree/core/controller_helpers/strong_parameters'
require 'webdrivers'

RSpec.configure do |config|
config.color = true
Expand Down