Skip to content

Commit

Permalink
Merge branch 'solidusio:master' into jquery-update
Browse files Browse the repository at this point in the history
  • Loading branch information
cpfergus1 authored Sep 14, 2021
2 parents d438b82 + 8436b81 commit 4062aab
Show file tree
Hide file tree
Showing 50 changed files with 935 additions and 190 deletions.
2 changes: 1 addition & 1 deletion .dockerdev/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ RUN apt-get update -qq \
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

RUN apt-key adv --keyserver ha.pool.sks-keyservers.net --recv-keys 8C718D3B5072E1F5 \
RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 8C718D3B5072E1F5 \
&& echo "deb http://repo.mysql.com/apt/debian/ buster mysql-"$MYSQL_VERSION > /etc/apt/sources.list.d/mysql.list

RUN curl -sSL https://deb.nodesource.com/setup_$NODE_VERSION.x | bash -
Expand Down
180 changes: 179 additions & 1 deletion CHANGELOG.md

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions api/app/controllers/spree/api/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,11 @@ def unauthorized
end

def gateway_error(exception)
@order.errors.add(:base, exception.message)
invalid_resource!(@order)
# Fall back to a blank order if one isn't set, as we only need this for
# its errors interface.
model = @order || Spree::Order.new
model.errors.add(:base, exception.message)
invalid_resource!(model)
end

def parameter_missing_error(exception)
Expand Down
4 changes: 4 additions & 0 deletions api/lib/spree/api/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Engine < Rails::Engine
# Leave initializer empty for backwards-compatibility. Other apps
# might still rely on this event.
initializer "spree.api.environment", before: :load_config_initializers do; end

config.after_initialize do
Spree::Api::Config.check_load_defaults_called('Spree::Api::Config')
end
end
end
end
57 changes: 54 additions & 3 deletions api/spec/controllers/spree/api/base_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

require 'spec_helper'

class FakesController < Spree::Api::BaseController
end

describe Spree::Api::BaseController, type: :controller do
render_views
controller(Spree::Api::BaseController) do
Expand Down Expand Up @@ -141,4 +138,58 @@ def index
end
end
end

describe "#gateway_error" do
before do
request.headers["Accept"] = "application/json"
get :index
end

context "with @order not defined" do
controller(Spree::Api::BaseController) do
def index
raise Spree::Core::GatewayError, "Insufficient Funds"
end

def requires_authentication?
false
end
end

it "returns a 422 status" do
expect(response).to have_http_status(:unprocessable_entity)
end

it "serializes the errors" do
expect(JSON.parse(response.body)["errors"]).to(
match(hash_including({ "base" => ["Insufficient Funds"] }))
)
end
end

context "with @order defined" do
controller(Spree::Api::BaseController) do
def index
@order = Spree::Order.new
@order.errors.add(:email, "isn't cool enough")
raise Spree::Core::GatewayError, "Insufficient Funds"
end

def requires_authentication?
false
end
end

it "returns a 422 status" do
expect(response).to have_http_status(:unprocessable_entity)
end

it "serializes the gateway errors with existing order errors" do
expect(JSON.parse(response.body)["errors"]).to eq({
"base" => ["Insufficient Funds"],
"email" => ["isn't cool enough"],
})
end
end
end
end
7 changes: 3 additions & 4 deletions api/spec/requests/spree/api/payments_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ module Spree
put spree.api_order_payment_path(order, payment), params: { payment: { amount: 'invalid' } }
expect(response.status).to eq(422)
expect(json_response["error"]).to eq("Invalid resource. Please fix errors and try again.")
expect(payment.reload.state).to eq("pending")
end

it "returns a 403 status when the payment is not pending" do
Expand Down Expand Up @@ -186,10 +187,6 @@ module Spree
expect(response.status).to eq(422)
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
expect(json_response["errors"]["base"][0]).to eq "Could not authorize card"
end

it "does not raise a stack level error" do
skip "Investigate why a payment.reload after the request raises 'stack level too deep'"
expect(payment.reload.state).to eq("failed")
end
end
Expand All @@ -213,6 +210,7 @@ module Spree
expect(response.status).to eq(422)
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
expect(payment.reload.state).to eq("failed")
end
end
end
Expand All @@ -235,6 +233,7 @@ module Spree
expect(response.status).to eq(422)
expect(json_response["error"]).to eq "Invalid resource. Please fix errors and try again."
expect(json_response["errors"]["base"][0]).to eq "Insufficient funds"
expect(payment.reload.state).to eq("failed")
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ def load_stock_management_data

def variant_scope
scope = Spree::Variant.accessible_by(current_ability)
scope = scope.where(product: @product) if @product
if @product
scope = scope.where(
product: @product,
is_master: !@product.has_variants?
)
end
scope = scope.order(:sku)
scope
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</div>
</div>

<% if product.variants.discarded.any? %>
<% if product.variants.with_discarded.discarded.any? %>
<div class="col-2">
<div class="field checkbox">
<label>
Expand Down
2 changes: 1 addition & 1 deletion backend/app/views/spree/admin/variants/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
<% end %>
<% end %>

<% if @variants.any? || @product.variants.discarded.any? %>
<% if @product.variants.with_discarded.any? %>
<%= render "table_filter", product: @product %>
<%= render "table", variants: @variants %>
<% else %>
Expand Down
4 changes: 4 additions & 0 deletions backend/lib/spree/backend/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ class Engine < ::Rails::Engine
# Leave initializer empty for backwards-compatability. Other apps
# might still rely on this event.
initializer "spree.backend.environment", before: :load_config_initializers do; end

config.after_initialize do
Spree::Backend::Config.check_load_defaults_called('Spree::Backend::Config')
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,45 @@ module Admin
describe "#index" do
let!(:variant_1) { create(:variant) }
let!(:variant_2) { create(:variant) }
let!(:product_1) { create(:product) }
let!(:product_2) { create(:product) }
let!(:variant_3) { create(:variant, product: product_2) }
let!(:variant_4) { create(:variant, product: product_2) }

context "with product_slug param" do
it "scopes the variants by the product" do
get :index, params: { product_slug: variant_1.product.slug }
expect(assigns(:variants)).to include variant_1
expect(assigns(:variants)).not_to include variant_2
expect(assigns(:variants)).to contain_exactly(variant_1)
end

context "when a product with no variants is requested" do
it "returns the master variant of the product" do
get :index, params: { product_slug: product_1.slug }
expect(assigns(:variants)).to contain_exactly(product_1.master)
end
end

context "when a product with variants is requested" do
it "returns only the variants of the product" do
get :index, params: { product_slug: product_2.slug }
expect(assigns(:variants)).to contain_exactly(variant_3, variant_4)
end
end
end

context "without product_slug params" do
it "allows all accessible variants to be returned" do
get :index
expect(assigns(:variants)).to include variant_1
expect(assigns(:variants)).to include variant_2
expect(assigns(:variants)).to contain_exactly(
variant_1,
variant_1.product.master,
variant_2,
variant_2.product.master,
product_1.master,
product_2.master,
variant_3,
variant_4
)
end
end
end
Expand Down
22 changes: 22 additions & 0 deletions backend/spec/features/admin/products/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,28 @@
end
end
end

context 'displaying discarded variants' do
let!(:existing_variant) { create(:variant, sku: 'existing_variant_sku', product: product) }
let!(:discarded_variant) { create(:variant, sku: 'discarded_variant_sku', product: product) }

before { discarded_variant.discard! }

it 'does not display deleted variants by default' do
visit spree.admin_product_variants_path(product)

expect(page).to have_content(existing_variant.sku)
expect(page).not_to have_content(discarded_variant.sku)
end

it 'allows to display deleted variants with a filter' do
visit spree.admin_product_variants_path(product)
check 'Show Deleted Variants'
click_button 'search'

expect(page).to have_content(discarded_variant.sku)
end
end
end

context "editing existent variant" do
Expand Down
8 changes: 4 additions & 4 deletions core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class CannotRebuildShipments < StandardError; end
end

self.whitelisted_ransackable_associations = %w[shipments user order_promotions promotions bill_address ship_address line_items]
self.whitelisted_ransackable_attributes = %w[bill_address_name completed_at created_at email number state payment_state shipment_state total store_id]
self.whitelisted_ransackable_attributes = %w[completed_at created_at email number state payment_state shipment_state total store_id]

attr_reader :coupon_code
attr_accessor :temporary_address
Expand Down Expand Up @@ -269,15 +269,15 @@ def all_inventory_units_returned?
end

def contents
@contents ||= Spree::OrderContents.new(self)
@contents ||= Spree::Config.order_contents_class.new(self)
end

def shipping
@shipping ||= Spree::OrderShipping.new(self)
@shipping ||= Spree::Config.order_shipping_class.new(self)
end

def cancellations
@cancellations ||= Spree::OrderCancellations.new(self)
@cancellations ||= Spree::Config.order_cancellations_class.new(self)
end

# Associates the specified user with the order.
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/price.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Price < Spree::Base
delegate :tax_rates, to: :variant

validate :check_price
validates :amount, allow_nil: true, numericality: {
validates :amount, numericality: {
greater_than_or_equal_to: 0,
less_than_or_equal_to: MAXIMUM_AMOUNT
}
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/shipping_rate_tax.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Spree
# @attr [Spree::ShippingRate] shipping_rate The shipping rate to be taxed
# @attr [Spree::TaxRate] tax_rate The tax rate used to calculate the tax amount
# @since 1.3.0
# @see Spree::Tax::ShippingRateTaxer
# @see Spree::Stock::Estimator
class ShippingRateTax < Spree::Base
belongs_to :shipping_rate, class_name: "Spree::ShippingRate", optional: true
belongs_to :tax_rate, class_name: "Spree::TaxRate", optional: true
Expand Down
24 changes: 0 additions & 24 deletions core/app/models/spree/tax/shipping_rate_taxer.rb

This file was deleted.

2 changes: 1 addition & 1 deletion core/app/models/spree/tax_calculator/shipping_rate.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module TaxCalculator
# looking to provide their own calculator should adhere to the API of this
# class.
#
# @see Spree::Tax::ShippingRateTaxer
# @see Spree::Stock::Estimator
class ShippingRate
include Spree::Tax::TaxHelpers

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class ChangeColumnNullOnPrices < ActiveRecord::Migration[5.2]
def change
change_column_null(:spree_prices, :amount, false)
end
end
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# Configure Solidus Preferences
# See http://docs.solidus.io/Spree/AppConfiguration.html for details

# Solidus version defaults for preferences that are not overridden
Spree.load_defaults '<%= Spree.solidus_version %>'

Spree.config do |config|
# Core:

# Solidus version defaults for preferences that are not overridden
config.load_defaults '<%= Spree.solidus_version %>'

# Default currency for new sites
config.currency = "USD"

Expand Down Expand Up @@ -65,14 +64,12 @@ end

<% if defined?(Spree::Frontend::Engine) -%>
Spree::Frontend::Config.configure do |config|
config.load_defaults '<%= Spree.solidus_version %>'
config.locale = 'en'
end
<% end -%>

<% if defined?(Spree::Backend::Engine) -%>
Spree::Backend::Config.configure do |config|
config.load_defaults '<%= Spree.solidus_version %>'
config.locale = 'en'

# Uncomment and change the following configuration if you want to add
Expand All @@ -88,7 +85,6 @@ end

<% if defined?(Spree::Api::Engine) -%>
Spree::Api::Config.configure do |config|
config.load_defaults '<%= Spree.solidus_version %>'
config.requires_authentication = true
end
<% end -%>
Expand Down
Loading

0 comments on commit 4062aab

Please sign in to comment.