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
Add more tests.
Matthew Kennedy5144619e88b7
diff --git a/core/spec/models/spree/menu_item_spec.rb b/core/spec/models/spree/menu_item_spec.rbindex 92385324df..968d270b2e 100644--- a/core/spec/models/spree/menu_item_spec.rb+++ b/core/spec/models/spree/menu_item_spec.rb@@ -1,43 +1,80 @@require 'spec_helper'describe Spree::MenuItem, type: :model do- describe 'validates name' do- let!(:menu) { create(:menu, name: 'Main Menu') }+ let!(:menu) { create(:menu, name: 'Main Menu') }+ describe 'validates name' doit 'returns presence error when no name is given' do- expect(described_class.new(name: '', menu_id: menu.id, item_type: 'Link')).not_to be_valid+ expect(described_class.new(name: '', menu_id: menu.id, parent_id: menu.root.id, item_type: 'Link')).not_to be_validendenddescribe 'validates menu_id presence and integer_only' do- let!(:menu) { create(:menu, name: 'Main Menu') }-it 'returns error when no menu id is passed' do- expect(described_class.new(name: 'Main Menu', item_type: 'Link')).not_to be_valid+ expect(described_class.new(name: 'Menu Item', item_type: 'Link', parent_id: menu.root.id)).not_to be_validendit 'returns error when no menu id is not an integer' do- expect(described_class.new(name: 'Main Menu', menu_id: 'string', item_type: 'Link')).not_to be_valid+ expect(described_class.new(name: 'Menu Item', menu_id: 'string', item_type: 'Link', parent_id: menu.root.id)).not_to be_validendit 'returns success when no menu id an integer' do- expect(described_class.new(name: 'Main Menu', item_type: 'Link', menu_id: menu.id)).to be_valid+ expect(described_class.new(name: 'Menu Item', item_type: 'Link', menu_id: menu.id, parent_id: menu.root.id)).to be_validendenddescribe 'validates item_type' do- let!(:menu) { create(:menu, name: 'Main Menu') }-it 'returns error when the item_type is not in the list' do- expect(described_class.new(name: 'Main Menu', menu_id: menu.id, item_type: 'Linkker')).not_to be_valid+ expect(described_class.new(name: 'Menu Item', menu_id: menu.id, item_type: 'Linkker', parent_id: menu.root.id)).not_to be_validendenddescribe 'validates linked_resource_type' do- let!(:menu) { create(:menu, name: 'Main Menu') }-it 'returns error when the linked_resource_type is not in the list' do- expect(described_class.new(name: 'Main Menu', menu_id: menu.id, item_type: 'Link', linked_resource_type: 'Purple')).not_to be_valid+ expect(described_class.new(name: 'Menu Item', menu_id: menu.id, item_type: 'Link', linked_resource_type: 'Purple', parent_id: menu.root.id)).not_to be_valid+ end+ end++ describe '#build_path' do+ let(:product) { create(:product) }+ let(:taxon) { create(:taxon) }+ let(:item_url) { create(:menu_item, name: 'URL To Random Site', item_type: 'Link', menu_id: menu.id, parent_id: menu.root.id, linked_resource_type: 'URL', destination: 'https://some-other-website.com') }+ let(:item_home) { create(:menu_item, name: 'Home', item_type: 'Link', menu_id: menu.id, parent_id: menu.root.id, linked_resource_type: 'Home Page') }+ let(:item_product) { create(:menu_item, name: product.name, item_type: 'Link', menu_id: menu.id, parent_id: menu.root.id, linked_resource_type: 'Spree::Product') }+ let(:item_taxon) { create(:menu_item, name: taxon.name, item_type: 'Link', menu_id: menu.id, parent_id: menu.root.id, linked_resource_type: 'Spree::Taxon') }++ it 'returns taxon path' do+ item_taxon.update(linked_resource_id: taxon.id)++ expect(item_taxon.destination).to eql "/t/#{taxon.permalink}"+ end++ it 'returns product path' do+ item_product.update(linked_resource_id: product.id)++ expect(item_product.destination).to eql "/products/#{product.slug}"+ end++ it 'returns root path' do+ expect(item_home.destination).to eql '/'+ end++ it 'returns URL path' do+ expect(item_url.destination).to eql 'https://some-other-website.com'+ end+ end++ describe 'paremeterize_code' do+ let(:item) { create(:menu_item, name: 'URL', item_type: 'Link', menu_id: menu.id, parent_id: menu.root.id, linked_resource_type: 'URL', code: 'My Fantastic Code') }++ it 'paramatizes a code when one is given' do+ expect(item.code).to eql 'my-fantastic-code'+ end+ end++ describe 'check_for_root' do+ it 'does not validate the Menu Item' do+ expect(described_class.new(name: 'Menu Item', menu_id: menu.id, item_type: 'Link', parent_id: nil)).not_to be_validendendend