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

[pull] main from solidusio:main #406

Merged
merged 18 commits into from
May 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
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
9 changes: 5 additions & 4 deletions .dockerdev/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION-slim-buster
FROM ruby:$RUBY_VERSION-slim-bookworm

ARG PG_VERSION
ARG MYSQL_VERSION
Expand All @@ -14,6 +14,7 @@ RUN apt-get update -qq \
git \
imagemagick \
libvips \
libffi-dev \
libmariadb-dev \
sqlite3 \
libsqlite3-dev \
Expand All @@ -22,10 +23,10 @@ RUN apt-get update -qq \
&& rm -rf /var/cache/apt/lists/*

RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ buster-pgdg main' $PG_VERSION > /etc/apt/sources.list.d/pgdg.list
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ bookworm-pgdg main' $PG_VERSION > /etc/apt/sources.list.d/pgdg.list

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 467b942d3a79bd29 \
&& echo "deb http://repo.mysql.com/apt/debian/ buster mysql-"$MYSQL_VERSION > /etc/apt/sources.list.d/mysql.list
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys B7B3B788A8D3785C \
&& echo "deb http://repo.mysql.com/apt/debian/ bookworm mysql-"$MYSQL_VERSION > /etc/apt/sources.list.d/mysql.list

RUN curl -sSL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -

Expand Down
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ group :backend do
gem 'capybara', '~> 3.13', require: false
gem 'capybara-screenshot', '>= 1.0.18', require: false
gem 'selenium-webdriver', require: false
gem 'webdrivers', require: false

# JavaScript testing
gem 'teaspoon', require: false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,20 @@

<%= page_with_sidebar_aside do %>
<%= render component('ui/panel').new(title: "Publishing") do %>
<%= render component("ui/forms/field").text_field(f, :available_on, hint: t(".available_on_html"), type: :date) %>
<%= render component("ui/forms/field").text_field(f, :discontinue_on, hint: t(".discontinue_on_html"), type: :date) %>

<%= render component("ui/forms/field").text_field(
f,
:available_on,
hint: t(".available_on_html"),
type: :date,
value: f.object.available_on&.to_date
) %>
<%= render component("ui/forms/field").text_field(
f,
:discontinue_on,
hint: t(".discontinue_on_html"),
type: :date,
value: f.object.discontinue_on&.to_date
) %>
<label class="flex gap-2 items-center">
<%= render component("ui/forms/checkbox").new(
name: "#{f.object_name}[promotionable]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ class SolidusAdmin::Products::Status::Component < SolidusAdmin::BaseComponent
available: :green,
discontinued: :yellow,
deleted: :red,
unavailable: :yellow
}.freeze

def self.from_product(product)
Expand All @@ -13,8 +14,10 @@ def self.from_product(product)
:deleted
elsif product.discontinued?
:discontinued
else
elsif product.available?
:available
else
:unavailable
end

new(status: status)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ en:
available: 'Available'
discontinued: 'Discontinued'
deleted: 'Deleted'
unavailable: 'Unavailable'
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,11 @@

expect(page).to have_css("input[type='number'][name='name'][value='value']")
end

it "renders a date input" do
render_inline(described_class.new(type: :date, name: "name", value: "2020-01-01"))

expect(page).to have_css("input[type='date'][name='name'][value='2020-01-01']")
end
end
end
1 change: 0 additions & 1 deletion admin/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
require "capybara/rspec"
require 'capybara-screenshot/rspec'
require "selenium/webdriver"
require 'webdrivers'
Capybara.save_path = ENV['CIRCLE_ARTIFACTS'] if ENV['CIRCLE_ARTIFACTS']
Capybara.exact = true
Capybara.disable_animation = true
Expand Down
1 change: 0 additions & 1 deletion backend/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
Capybara.exact = true

require "selenium/webdriver"
require 'webdrivers'

Capybara.register_driver :selenium_chrome_headless do |app|
browser_options = ::Selenium::WebDriver::Chrome::Options.new
Expand Down
1 change: 0 additions & 1 deletion backend/spec/teaspoon_env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
ENV['RAILS_ENV'] = 'test'

require 'teaspoon/driver/selenium'
require 'webdrivers'

# Similar to setup described in
# https://github.com/jejacks0n/teaspoon/wiki/Micro-Applications
Expand Down
9 changes: 9 additions & 0 deletions core/app/models/spree/null_promotion_advertiser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

module Spree
class NullPromotionAdvertiser
def self.for_product(_product)
[]
end
end
end
3 changes: 1 addition & 2 deletions core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,7 @@ def set_property(property_name, property_value)

# @return [Array] all advertised and not-rejected promotions
def possible_promotions
promotion_ids = promotion_rules.map(&:promotion_id).uniq
Spree::Promotion.advertised.where(id: promotion_ids).reject(&:inactive?)
Spree::Config.promotions.advertiser_class.for_product(self)
end

# The number of on-hand stock items; Infinity if any variant does not track
Expand Down
10 changes: 10 additions & 0 deletions core/app/models/spree/promotion_advertiser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

module Spree
class PromotionAdvertiser
def self.for_product(product)
promotion_ids = product.promotion_rules.map(&:promotion_id).uniq
Spree::Promotion.advertised.where(id: promotion_ids).reject(&:inactive?)
end
end
end
13 changes: 6 additions & 7 deletions core/lib/spree/app_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -422,12 +422,6 @@ def payment_canceller
)
end

# Allow switching out the promotion configuration class
#
# @!attribute [rw] promotion_configuration_class
# @return [Class] a class instance that fulfils the interface of a promo configuration
class_name_attribute :promotion_configuration_class, default: 'Spree::Core::PromotionConfiguration'

# Allows providing your own class for adding payment sources to a user's
# "wallet" after an order moves to the complete state.
#
Expand Down Expand Up @@ -594,8 +588,13 @@ def stock
@stock_configuration ||= Spree::Core::StockConfiguration.new
end

# Allows providing your own promotion configuration instance
# @!attribute [rw] promotions
# @return [Spree::Core::PromotionConfiguration] an object that conforms to the API of
# the standard promotion configuration class Spree::Core::PromotionConfiguration.
attr_writer :promotions
def promotions
@promotion_configuration ||= promotion_configuration_class.new
@promotions ||= Spree::Core::PromotionConfiguration.new
end

class << self
Expand Down
8 changes: 8 additions & 0 deletions core/lib/spree/core/null_promotion_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ class NullPromotionConfiguration < Spree::Preferences::Configuration
# Spree::NullPromotionHandler.
class_name_attribute :shipping_promotion_handler_class, default: 'Spree::NullPromotionHandler'

# Allows providing a different promotion advertiser.
# @!attribute [rw] advertiser_class
# @see Spree::NullPromotionAdvertiser
# @return [Class] an object that conforms to the API of
# the standard promotion advertiser class
# Spree::NullPromotionAdvertiser.
class_name_attribute :advertiser_class, default: 'Spree::NullPromotionAdvertiser'

# !@attribute [rw] promotion_api_attributes
# @return [Array<Symbol>] Attributes to be returned by the API for a promotion
preference :promotion_api_attributes, :array, default: []
Expand Down
8 changes: 8 additions & 0 deletions core/lib/spree/core/promotion_configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ class PromotionConfiguration < Spree::Preferences::Configuration
# Spree::PromotionHandler::Coupon.
class_name_attribute :coupon_code_handler_class, default: 'Spree::PromotionHandler::Coupon'

# Allows providing a different promotion advertiser.
# @!attribute [rw] advertiser_class
# @see Spree::PromotionAdvertiser
# @return [Class] an object that conforms to the API of
# the standard promotion advertiser class
# Spree::PromotionAdvertiser.
class_name_attribute :advertiser_class, default: 'Spree::PromotionAdvertiser'

add_class_set :rules, default: %w[
Spree::Promotion::Rules::ItemTotal
Spree::Promotion::Rules::Product
Expand Down
4 changes: 2 additions & 2 deletions core/lib/spree/testing_support/dummy_app/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

db_host =
case adapter
when 'mysql' then ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
when 'postgres' then ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
when 'mysql2' then ENV['DB_MYSQL_HOST'] || ENV['DB_HOST']
when 'postgresql' then ENV['DB_POSTGRES_HOST'] || ENV['DB_HOST']
else ENV['DB_HOST']
end

Expand Down
2 changes: 1 addition & 1 deletion core/spec/lib/spree/app_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
end

it "uses core's promotion configuration class by default" do
expect(prefs.promotion_configuration_class).to eq Spree::Core::PromotionConfiguration
expect(prefs.promotions).to be_a Spree::Core::PromotionConfiguration
end

context "deprecated preferences" do
Expand Down
4 changes: 4 additions & 0 deletions core/spec/lib/spree/core/null_promotion_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@
it "uses the null promotion handler as the shipping promo handler" do
expect(config.shipping_promotion_handler_class).to eq Spree::NullPromotionHandler
end

it "uses the null promotion advertiser class by default" do
expect(config.advertiser_class).to eq Spree::NullPromotionAdvertiser
end
end
4 changes: 4 additions & 0 deletions core/spec/lib/spree/core/promotion_configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@
expect(config.promotion_finder_class).to eq Spree::PromotionFinder
end

it "uses promotion advertiser class by default" do
expect(config.advertiser_class).to eq Spree::PromotionAdvertiser
end

describe "#calculators" do
subject { config.calculators[promotion_action] }

Expand Down
12 changes: 12 additions & 0 deletions core/spec/models/spree/null_promotion_advertiser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Spree::PromotionAdvertiser, type: :model do
describe ".for_product" do
subject { described_class.for_product(product) }
let(:product) { create(:product) }

it { is_expected.to eq([]) }
end
end
20 changes: 8 additions & 12 deletions core/spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -499,20 +499,16 @@ class Extension < Spree::Base
expect(Spree::Property.where(name: 'foo').first.presentation).to eq("Foo's Presentation Name")
expect(Spree::Property.where(name: 'bar').first.presentation).to eq("bar")
end
end

# Regression test for https://github.com/spree/spree/issues/4416
context "#possible_promotions" do
let!(:promotion) { create(:promotion, :with_action, advertise: true, starts_at: 1.day.ago) }
let!(:rule) do
Spree::Promotion::Rules::Product.create(
promotion: promotion,
products: [product]
)
end
context "#possible_promotions" do
let(:product) { create(:product) }

it "lists the promotion as a possible promotion" do
expect(product.possible_promotions).to include(promotion)
end
subject { product.possible_promotions }

it "calls the configured promotion advertiser class" do
expect(Spree::Config.promotions.advertiser_class).to receive(:for_product).with(product)
subject
end
end

Expand Down
22 changes: 22 additions & 0 deletions core/spec/models/spree/promotion_advertiser_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe Spree::PromotionAdvertiser, type: :model do
describe ".for_product" do
subject { described_class.for_product(product) }

let(:product) { create(:product) }
let!(:promotion) { create(:promotion, :with_action, advertise: true, starts_at: 1.day.ago) }
let!(:rule) do
Spree::Promotion::Rules::Product.create(
promotion: promotion,
products: [product]
)
end

it "lists the promotion as a possible promotion" do
expect(subject).to include(promotion)
end
end
end
3 changes: 2 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,14 @@ services:
- postgres:/var/lib/postgresql/data:cached

app:
shm_size: '256mb'
build:
context: .dockerdev
dockerfile: Dockerfile
args:
RUBY_VERSION: "3.1"
PG_VERSION: 13
NODE_VERSION: 14
NODE_VERSION: 20
MYSQL_VERSION: "8.0"
BUNDLER_VERSION: 2
image: solidus-4.4.0.dev
Expand Down
Loading