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

Load defaults for the latest Rails minor version in the dummy app #4035

Merged
merged 4 commits into from
May 5, 2021
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
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me that this change (and the one in product.rb) are not really related to the issue with ActiveRecord.has_many_inverse, but they've been an issue for a while.

What about moving these changes into their own commit? I think it would give the fix more prominence and make the last commit a bit lighter.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ops, I merged too fast. Sorry, @spaghetticode! 🤦‍♂️

I would have agreed with you for what it's worth. Maybe something we can take into account in the next PRs. Sorry again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing that association solved two test failures:

it "creates with embedded variants" do

  1) Spree::Api::ProductsController as an admin creating a product creates with embedded variants
     Failure/Error: expect(variants.count).to eq(2)
     
       expected: 2
            got: 3
     
       (compared using ==)

  1) variant factory master variant builds a master variant properly
     Failure/Error: expect(product.variants).to be_empty
       expected `#<ActiveRecord::Associations::CollectionProxy []>.empty?` to be truthy, got false

I didn't debug further, though, as I saw that the change made sense.

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 @@ -616,7 +616,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