Skip to content

Commit

Permalink
Merge pull request #4035 from nebulab/waiting-for-dev/load_defaults
Browse files Browse the repository at this point in the history
Load defaults for the latest Rails minor version in the dummy app
  • Loading branch information
kennyadsl authored May 5, 2021
2 parents 1d7f2c4 + 55bd0e4 commit 69b9a0f
Show file tree
Hide file tree
Showing 14 changed files with 43 additions and 15 deletions.
10 changes: 9 additions & 1 deletion backend/spec/features/admin/products/edit/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
end

click_button "Update"
Spree::Image.first.attachment.blob.update(key: 11)
invalidate_attachment(Spree::Image.first.attachment)
visit current_path
expect(page).to have_xpath("//img[contains(@src, 'assets/noimage/mini')]")
end
Expand Down Expand Up @@ -136,4 +136,12 @@
expect(page).to have_css("thead th", count: 4)
end
end

def invalidate_attachment(attachment)
blob = attachment.blob
blob.variant_records.each do |variant_record|
variant_record.update(variation_digest: SecureRandom.uuid)
end
blob.update(key: SecureRandom.uuid)
end
end
5 changes: 4 additions & 1 deletion core/app/models/spree/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,10 @@ def create_proposed_shipments
raise CannotRebuildShipments.new(I18n.t('spree.cannot_rebuild_shipments_shipments_not_pending'))
else
shipments.destroy_all
self.shipments = Spree::Config.stock.coordinator_class.new(self).shipments
# TODO: We can use `self.shipments#=` instead of `#push` when
# https://github.com/rails/rails/issues/42102 is fixed and we deprecate
# Rails versions with the bug
shipments.push(*Spree::Config.stock.coordinator_class.new(self).shipments)
end
end

Expand Down
1 change: 0 additions & 1 deletion core/app/models/spree/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class Product < Spree::Base

has_many :variants,
-> { where(is_master: false).order(:position) },
inverse_of: :product,
class_name: 'Spree::Variant'

has_many :variants_including_master,
Expand Down
7 changes: 6 additions & 1 deletion core/app/models/spree/stock/simple_coordinator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,16 @@ def build_shipments
packages = split_packages(packages)

# Turn the Stock::Packages into a Shipment with rates
packages.map do |package|
shipments = packages.map do |package|
shipment = package.shipment = package.to_shipment
shipment.shipping_rates = Spree::Config.stock.estimator_class.new.shipping_rates(package)
shipment
end

# Make sure we don't add the proposed shipments to the order
order.shipments = order.shipments - shipments

shipments
end

def split_packages(initial_packages)
Expand Down
2 changes: 1 addition & 1 deletion core/app/models/spree/variant.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Variant < Spree::Base
attr_writer :rebuild_vat_prices
include Spree::DefaultPrice

belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants, optional: false
belongs_to :product, -> { with_discarded }, touch: true, class_name: 'Spree::Product', inverse_of: :variants_including_master, optional: false
belongs_to :tax_category, class_name: 'Spree::TaxCategory', optional: true

delegate :name, :description, :slug, :available_on, :discontinue_on, :discontinued?,
Expand Down
1 change: 1 addition & 0 deletions core/lib/spree/testing_support/dummy_app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def self.setup(gem_root:, lib_name:, auto_migrate: true)
end

class Application < ::Rails::Application
config.load_defaults("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
config.eager_load = false
config.cache_classes = true
config.cache_store = :memory_store
Expand Down
1 change: 1 addition & 0 deletions core/spec/lib/search/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def refute_found(query_string, variant)
described_class.new(variant.sku, scope: Spree::Variant.in_stock).results
).to include variant

variant.stock_items.reload # See https://github.com/rails/rails/issues/42094
variant.stock_items.each { |si| si.set_count_on_hand(0) }
expect(
described_class.new(variant.sku, scope: Spree::Variant.in_stock).results
Expand Down
11 changes: 11 additions & 0 deletions core/spec/lib/spree/core/testing_support/dummy_app_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe DummyApp do
it 'loads default from the Rails version in use' do
expect(
DummyApp::Application.config.loaded_config_version
).to eq("#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}")
end
end
6 changes: 3 additions & 3 deletions core/spec/models/spree/adjustment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

RSpec.describe Spree::Adjustment, type: :model do
let!(:store) { create :store }
let(:order) { Spree::Order.new }
let(:order) { create :order }
let(:line_item) { create :line_item, order: order }

let(:adjustment) { Spree::Adjustment.create!(label: 'Adjustment', adjustable: order, order: order, amount: 5) }
Expand Down Expand Up @@ -43,7 +43,7 @@
end

context '#currency' do
let(:order) { Spree::Order.new currency: 'JPY' }
let(:order) { create :order, currency: 'JPY' }

it 'returns the adjustables currency' do
expect(adjustment.currency).to eq 'JPY'
Expand All @@ -67,7 +67,7 @@
end

context "with currency set to JPY" do
let(:order) { Spree::Order.new currency: 'JPY' }
let(:order) { create :order, currency: 'JPY' }

context "when adjustable is set to an order" do
it "displays in JPY" do
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/order_contents_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

it "ensure shipment calls update_amounts instead of order calling ensure_updated_shipments" do
expect(subject.order).to_not receive(:ensure_updated_shipments)
expect(shipment).to receive(:update_amounts)
expect(shipment).to receive(:update_amounts).at_least(:once)
subject.add(variant, 1, shipment: shipment)
end

Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/payment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
let(:refund_reason) { create(:refund_reason) }

let(:gateway) do
gateway = Spree::PaymentMethod::BogusCreditCard.new(active: true, name: 'Bogus gateway')
gateway = Spree::PaymentMethod::BogusCreditCard.create!(active: true, name: 'Bogus gateway')
allow(gateway).to receive_messages(source_required?: true)
gateway
end
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/product_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class Extension < Spree::Base
it "should set deleted_at value" do
product.discard
expect(product.deleted_at).not_to be_nil
expect(product.variants_including_master).to all(be_discarded)
expect(product.variants_including_master.reload).to all(be_discarded)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion core/spec/models/spree/variant_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@
variant.discard

expect(variant.images).to be_empty
expect(variant.stock_items).to be_empty
expect(variant.stock_items.reload).to be_empty
expect(variant.prices).to be_empty
expect(variant.currently_valid_prices).to be_empty
end
Expand Down
6 changes: 3 additions & 3 deletions frontend/spec/features/taxons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

describe "viewing products", type: :feature, inaccessible: true do
let!(:taxonomy) { create(:taxonomy, name: "Category") }
let!(:super_clothing) { taxonomy.root.children.create(name: "Super Clothing") }
let!(:t_shirts) { super_clothing.children.create(name: "T-Shirts") }
let!(:xxl) { t_shirts.children.create(name: "XXL") }
let!(:super_clothing) { taxonomy.root.children.create!(name: "Super Clothing", taxonomy: taxonomy) }
let!(:t_shirts) { super_clothing.children.create!(name: "T-Shirts", taxonomy: taxonomy) }
let!(:xxl) { t_shirts.children.create!(name: "XXL", taxonomy: taxonomy) }
let!(:product) do
product = create(:product, name: "Superman T-Shirt")
product.taxons << t_shirts
Expand Down

0 comments on commit 69b9a0f

Please sign in to comment.