Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Fix broken test for touch after create, add tests for level of newly added items.
Matthew Kennedy46a3bacc7ef9
diff --git a/backend/app/views/spree/admin/menu_items/_form.html.erb b/backend/app/views/spree/admin/menu_items/_form.html.erbindex 7a5fff1ccf..456100ae34 100644--- a/backend/app/views/spree/admin/menu_items/_form.html.erb+++ b/backend/app/views/spree/admin/menu_items/_form.html.erb@@ -21,7 +21,7 @@</small><% end %>- <%= f.field_container :parent_id, class: ['form-group'] do %>+ <%= f.field_container :parent_id, class: ['form-group'] do %><%= f.label :parent_id, Spree.t('admin.navigation.nested_under') %><%= f.select :parent_id, nested_set_options(@menu.menu_items, @menu_item) {|i| "#{'-' * i.level} #{i.name}" }, {include_blank: false}, {class: 'select2'} %><%= f.error_message_on :parent_id %>diff --git a/core/app/models/spree/menu_item.rb b/core/app/models/spree/menu_item.rbindex e6c12a80c3..9c1fdba13d 100644--- a/core/app/models/spree/menu_item.rb+++ b/core/app/models/spree/menu_item.rb@@ -5,7 +5,7 @@ module Spreebelongs_to :menu, touch: truebelongs_to :linked_resource, polymorphic: true- around_create :ensure_item_belongs_to_root+ before_create :ensure_item_belongs_to_rootbefore_save :reset_link_attributes, :build_path, :paremeterize_codeafter_save :touch_ancestors_and_menu@@ -75,11 +75,9 @@ module Spreedef ensure_item_belongs_to_rootif menu.try(:root).present? && parent_id.nil?self.parent = menu.root- end-- yield- move_to_child_of(menu.root) unless root+ store_new_parent+ endenddef touch_ancestors_and_menudiff --git a/core/spec/models/spree/menu_item_spec.rb b/core/spec/models/spree/menu_item_spec.rbindex d7539fde6e..79d74898c4 100644--- a/core/spec/models/spree/menu_item_spec.rb+++ b/core/spec/models/spree/menu_item_spec.rb@@ -103,7 +103,7 @@ describe Spree::MenuItem, type: :model doitem_taxon.update(linked_resource: taxon)item_taxon.update(linked_resource_id: nil)- expect(item_taxon.destination).to eql nil+ expect(item_taxon.destination).to be nilendit 'returns product path' do@@ -116,7 +116,7 @@ describe Spree::MenuItem, type: :model doitem_product.update(linked_resource: product)item_product.update(linked_resource_id: nil)- expect(item_product.destination).to eql nil+ expect(item_product.destination).to be nilendit 'returns root path' do@@ -137,11 +137,19 @@ describe Spree::MenuItem, type: :model doenddescribe '.ensure_item_belongs_to_root' do- let(:item_x) { create(:menu_item, name: 'URL', item_type: 'Link', menu: menu, parent: menu.root, linked_resource_type: 'URL', code: 'My Fantastic Code') }+ let(:item_x) { create(:menu_item, name: 'URL', item_type: 'Link', menu: menu, linked_resource_type: 'URL', code: 'My Fantastic Code') }it 'Sets new items parent_id to root.id' doexpect(item_x.parent_id).to eql menu.root.idend++ it 'is not a root' do+ expect(item_x.root?).to be false+ end++ it 'is level 1' do+ expect(item_x.level).to eql 1+ endenddescribe 'touch menu and store' do