Skip to content

armgit / spree

Public Imported from GitHub
0

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.

Update code reviews.

Matthew Kennedy02d761750e19
diff --git a/api/app/serializers/spree/api/v2/platform/menu_item_serializer.rb b/api/app/serializers/spree/api/v2/platform/menu_item_serializer.rb
index bb18f7836b..a46e3da35e 100644
--- a/api/app/serializers/spree/api/v2/platform/menu_item_serializer.rb
+++ b/api/app/serializers/spree/api/v2/platform/menu_item_serializer.rb
@@ -6,8 +6,8 @@ module Spree
include ::Spree::Api::V2::ResourceSerializerConcern
has_one :image,
- object_method_name: :menu_item_image,
- id_method_name: :menu_item_image_id,
+ object_method_name: :icon,
+ id_method_name: :icon_id,
record_type: :image,
serializer: :image
diff --git a/api/app/serializers/spree/v2/storefront/menu_item_serializer.rb b/api/app/serializers/spree/v2/storefront/menu_item_serializer.rb
index 49db4c9cd3..f155f4f55a 100644
--- a/api/app/serializers/spree/v2/storefront/menu_item_serializer.rb
+++ b/api/app/serializers/spree/v2/storefront/menu_item_serializer.rb
@@ -19,8 +19,8 @@ module Spree
end
has_one :image,
- object_method_name: :menu_item_image,
- id_method_name: :menu_item_image_id,
+ object_method_name: :icon,
+ id_method_name: :icon_id,
record_type: :image,
serializer: :image
diff --git a/backend/app/views/spree/admin/menu_items/_form.html.erb b/backend/app/views/spree/admin/menu_items/_form.html.erb
index a342b42246..bc22b7653f 100644
--- a/backend/app/views/spree/admin/menu_items/_form.html.erb
+++ b/backend/app/views/spree/admin/menu_items/_form.html.erb
@@ -58,24 +58,24 @@
<%= f.error_message_on :subtitle %>
<% end %>
- <% @menu_item.build_menu_item_image unless @menu_item.menu_item_image %>
- <%= f.fields_for :menu_item_image do |menu_item_image_field| %>
- <%= f.field_container :menu_item_image_attachment do %>
- <% unless @menu_item.menu_item_image.new_record? %>
+ <% @menu_item.build_icon unless @menu_item.icon %>
+ <%= f.fields_for :icon do |icon_field| %>
+ <%= f.field_container :icon_attachment do %>
+ <% unless @menu_item.icon.new_record? %>
<div id="menuItemImgContainer" class="my-2">
- <%= image_tag(main_app.url_for(@menu_item.menu_item_image.attachment)) %>
+ <%= image_tag(main_app.url_for(@menu_item.icon.attachment)) %>
</div>
<% end %>
- <div id="<% unless @menu_item.menu_item_image.new_record? %>MenuItemImageButton<% end %>">
- <%= menu_item_image_field.file_field :attachment %>
+ <div id="<% unless @menu_item.icon.new_record? %>MenuItemImageButton<% end %>">
+ <%= icon_field.file_field :attachment %>
</div>
<% end %>
- <%= f.field_container :menu_item_image_alt do %>
- <% unless @menu_item.menu_item_image.new_record? %>
+ <%= f.field_container :icon_alt do %>
+ <% unless @menu_item.icon.new_record? %>
<div class="form-group my-3">
- <%= menu_item_image_field.label :alt, Spree.t('admin.navigation.image_alt_text') %>
- <%= menu_item_image_field.text_field :alt, class: 'form-control' %>
+ <%= icon_field.label :alt, Spree.t('admin.navigation.image_alt_text') %>
+ <%= icon_field.text_field :alt, class: 'form-control' %>
</div>
<% end %>
<% end %>
diff --git a/backend/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb b/backend/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb
index 8357afb58d..9b3d4d188d 100644
--- a/backend/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb
+++ b/backend/app/views/spree/admin/menus/nested_menu_items/_item_bar.html.erb
@@ -14,10 +14,10 @@
<%= "| #{Spree.t('admin.navigation.code')}: #{item.code}" if item.code.present? %>
</small>
</div>
- <% if item.menu_item_image.present? %>
+ <% if item.icon.present? %>
<div class="ml-2">
<div class="menu_items_image_holder">
- <%= image_tag main_app.url_for(item.menu_item_image.attachment) %>
+ <%= image_tag main_app.url_for(item.icon.attachment) %>
</div>
</div>
<% end %>
diff --git a/core/app/helpers/spree/base_helper.rb b/core/app/helpers/spree/base_helper.rb
index 888118878a..7bfad08180 100644
--- a/core/app/helpers/spree/base_helper.rb
+++ b/core/app/helpers/spree/base_helper.rb
@@ -25,24 +25,6 @@ module Spree
to_html
end
- def localized_item_link(item, locale)
- return if item.destination.nil?
-
- output_locale = if locale == current_store.default_locale
- nil
- else
- "/#{locale}"
- end
-
- if Spree::MenuItem::DYNAMIC_RESOURCE_TYPE.include? item.linked_resource_type
- output_locale.to_s + item.destination
- elsif item.linked_resource_type == 'Home Page'
- output_locale || item.destination
- else
- item.destination
- end
- end
-
def display_compare_at_price(product_or_variant)
product_or_variant.
price_in(current_currency).
diff --git a/core/app/models/spree/icon.rb b/core/app/models/spree/icon.rb
new file mode 100644
index 0000000000..63df9ede2c
--- /dev/null
+++ b/core/app/models/spree/icon.rb
@@ -0,0 +1,9 @@
+module Spree
+ class Icon < Spree::Asset
+ has_one_attached :attachment
+
+ ICON_TYPES = %i[png jpg jpeg gif svg]
+
+ validates :attachment, attached: true, content_type: ICON_TYPES
+ end
+end
diff --git a/core/app/models/spree/menu.rb b/core/app/models/spree/menu.rb
index 0e78bf00fd..b911b634ad 100644
--- a/core/app/models/spree/menu.rb
+++ b/core/app/models/spree/menu.rb
@@ -21,7 +21,7 @@ module Spree
end
def set_root
- self.root ||= MenuItem.create!(menu_id: id, name: name, item_type: 'Container', code: "#{name}-root")
+ self.root ||= MenuItem.create!(menu_id: id, name: name, item_type: 'Container')
end
end
end
diff --git a/core/app/models/spree/menu_item.rb b/core/app/models/spree/menu_item.rb
index 00af1eec60..2f6d197e15 100644
--- a/core/app/models/spree/menu_item.rb
+++ b/core/app/models/spree/menu_item.rb
@@ -1,10 +1,11 @@
module Spree
class MenuItem < Spree::Base
+ acts_as_nested_set dependent: :destroy
+
belongs_to :menu
belongs_to :linked_resource, polymorphic: true
- acts_as_nested_set dependent: :destroy
-
+ before_create :ensure_item_belongs_to_root
before_save :reset_link_attributes, :build_path, :paremeterize_code
ITEM_TYPE = %w[Link Promotion Container]
@@ -20,10 +21,9 @@ module Spree
validates :menu, presence: true
validates :item_type, inclusion: { in: ITEM_TYPE }
validates :linked_resource_type, inclusion: { in: LINKED_RESOURCE_TYPE }
- validate :check_for_root, on: :create
- has_one :menu_item_image, as: :viewable, dependent: :destroy, class_name: 'Spree::MenuItemImage'
- accepts_nested_attributes_for :menu_item_image, reject_if: :all_blank
+ has_one :icon, as: :viewable, dependent: :destroy, class_name: 'Spree::Icon'
+ accepts_nested_attributes_for :icon, reject_if: :all_blank
def self.refresh_paths(resorce)
where(linked_resource_type: resorce.class.name, linked_resource_id: resorce.id).each(&:save!)
@@ -69,9 +69,9 @@ module Spree
Spree::Core::Engine.frontend_available?
end
- def check_for_root
+ def ensure_item_belongs_to_root
if menu.try(:root).present? && parent_id.nil?
- errors.add(:root_conflict, Spree.t(:this_menu_already_has_a_root_item))
+ self.parent_id = menu.root.id
end
end
diff --git a/core/app/models/spree/menu_item_image.rb b/core/app/models/spree/menu_item_image.rb
deleted file mode 100644
index ebe961501f..0000000000
--- a/core/app/models/spree/menu_item_image.rb
+++ /dev/null
@@ -1,11 +0,0 @@
-# frozen_string_literal: true
-
-module Spree
- class MenuItemImage < Spree::Asset
- has_one_attached :attachment
-
- MENU_ITEM_IMAGE_TYPES = %i[png jpg jpeg gif svg]
-
- validates :attachment, attached: true, content_type: MENU_ITEM_IMAGE_TYPES
- end
-end
diff --git a/core/spec/helpers/base_helper_spec.rb b/core/spec/helpers/base_helper_spec.rb
index 95ac02e3cb..38267788cd 100644
--- a/core/spec/helpers/base_helper_spec.rb
+++ b/core/spec/helpers/base_helper_spec.rb
@@ -9,56 +9,6 @@ describe Spree::BaseHelper, type: :helper do
allow(controller).to receive(:controller_name).and_return('test')
end
- context 'localized_item_link' do
- let(:menu) { create(:menu, unique_code: 'main-123', store_id: current_store.id) }
- 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') }
-
- context 'when the default language is passed in' do
- it 'returns / for home page' do
- expect(localized_item_link(item_home, 'en')).to eq('/')
- end
-
- it 'returns /t/taxonomy-1/taxon-1 for a taxon' do
- item_taxon.update(linked_resource_id: taxon.id)
- expect(localized_item_link(item_taxon, 'en')).to eq("#{item_taxon.destination}")
- end
-
- it 'returns /products/product-18-4225 for a product' do
- item_product.update(linked_resource_id: product.id)
- expect(localized_item_link(item_product, 'en')).to eq("#{item_product.destination}")
- end
-
- it 'returns https://some-other-website.com for a URL' do
- expect(localized_item_link(item_url, 'en')).to eq("#{item_url.destination}")
- end
- end
-
- context 'with the none default locale passed in (:fr)' do
- it 'returns /fr for home page' do
- expect(localized_item_link(item_home, :fr)).to eq('/fr')
- end
-
- it 'returns /fr/t/taxonomy-1/taxon-1 for a taxon' do
- item_taxon.update(linked_resource_id: taxon.id)
- expect(localized_item_link(item_taxon, :fr)).to eq("/fr#{item_taxon.destination}")
- end
-
- it 'returns /fr/products/product-18-4225 for a product' do
- item_product.update(linked_resource_id: product.id)
- expect(localized_item_link(item_product, 'fr')).to eq("/fr#{item_product.destination}")
- end
-
- it 'returns https://some-other-website.com for a URL' do
- expect(localized_item_link(item_url, 'fr')).to eq("#{item_url.destination}")
- end
- end
- end
-
context 'available_countries' do
let(:country) { create(:country) }
diff --git a/frontend/app/helpers/spree/navigation_helper.rb b/frontend/app/helpers/spree/navigation_helper.rb
index a6296ccc80..3bf1c8561d 100644
--- a/frontend/app/helpers/spree/navigation_helper.rb
+++ b/frontend/app/helpers/spree/navigation_helper.rb
@@ -3,10 +3,19 @@ require 'digest'
module Spree
module NavigationHelper
def spree_navigation_data
- @spree_navigation_data ||= SpreeStorefrontConfig.dig(I18n.locale, :navigation) || SpreeStorefrontConfig.dig(current_store.code, :navigation) || SpreeStorefrontConfig.dig(:default, :navigation) || []
+ ActiveSupport::Deprecation.warn(<<-DEPRECATION, caller)
+ NavigationHelper#spree_navigation_data is deprecated and will be removed in Spree 5.0.
+ Please migrate to the new navigation cms system.
+ DEPRECATION
+
+ @spree_navigation_data ||= SpreeStorefrontConfig.dig(I18n.locale,
+ :navigation) || SpreeStorefrontConfig.dig(current_store.code,
+ :navigation) || SpreeStorefrontConfig.dig(
+ :default, :navigation
+ ) || []
# safeguard for older Spree installs that don't have spree_navigation initializer
# or spree.yml file present
- rescue
+ rescue StandardError
[]
end
@@ -36,7 +45,7 @@ module Spree
# Find a menu by its unique_code
# this method will only return a menu if it is
# available for use in the current store.
- def menu(unique_code)
+ def spree_menu(unique_code)
menu = available_menus.by_unique_code(unique_code)
menu[0]
end
@@ -44,24 +53,40 @@ module Spree
# Returns the root for the menu by unique_code.
# You can use .children to retrieve the top level of menu items,
# or .descendants to retrieve all menu items.
- def root_item_for_menu(unique_code)
- return unless menu(unique_code).present?
+ def spree_root_item_for_menu(unique_code)
+ return unless spree_menu(unique_code).present?
- menu(unique_code).root
+ spree_menu(unique_code).root
end
# Returns only the top level items for the menu by unique_code
- def top_level_items_for_menu(unique_code)
- return unless root_item_for_menu(unique_code).present?
+ def spree_top_level_items_for_menu(unique_code)
+ return unless spree_root_item_for_menu(unique_code).present?
- root_item_for_menu(unique_code).children
+ spree_root_item_for_menu(unique_code).children
end
# Returns all items for the menu by unique_code
- def all_items_for_menu(unique_code)
- return unless root_item_for_menu(unique_code).present?
+ def spree_all_items_for_menu(unique_code)
+ return unless spree_root_item_for_menu(unique_code).present?
+
+ spree_root_item_for_menu(unique_code).descendants
+ end
- root_item_for_menu(unique_code).descendants
+ def spree_localized_item_link(item)
+ return if item.destination.nil?
+
+ output_locale = if locale_param
+ "/#{locale}"
+ end
+
+ if Spree::MenuItem::DYNAMIC_RESOURCE_TYPE.include? item.linked_resource_type
+ output_locale.to_s + item.destination
+ elsif item.linked_resource_type == 'Home Page'
+ "/#{locale_param}"
+ else
+ item.destination
+ end
end
private
diff --git a/frontend/app/views/spree/shared/_footer.html.erb b/frontend/app/views/spree/shared/_footer.html.erb
index ef87170285..081e63e7b4 100644
--- a/frontend/app/views/spree/shared/_footer.html.erb
+++ b/frontend/app/views/spree/shared/_footer.html.erb
@@ -49,17 +49,17 @@
</div>
<div class="row d-none d-xl-flex border-top py-5 text-uppercase footer-spree-menu-links">
- <% if top_level_items_for_menu('spree-all-footer').present? %>
- <% top_level_items_for_menu('spree-all-footer').each do |parent| %>
+ <% if spree_top_level_items_for_menu('spree-all-footer').present? %>
+ <% spree_top_level_items_for_menu('spree-all-footer').each do |parent| %>
<div class="col-3">
<div class="footer-spree-label">
- <%= link_to parent.name, localized_item_link(parent, current_locale) %>
+ <%= link_to parent.name, spree_localized_item_link(parent) %>
</div>
<% parent.children.each do |child| %>
<% if child.code == 'category' && child.item_type == 'Container' %>
<% if child.children.present? %>
<% child.children.each do |category_link| %>
- <div class="pt-2"><%= link_to category_link.name, localized_item_link(category_link, current_locale) %></div>
+ <div class="pt-2"><%= link_to category_link.name, spree_localized_item_link(category_link) %></div>
<% end %>
<% end %>
<% end %>
diff --git a/frontend/app/views/spree/shared/_main_nav_bar.html.erb b/frontend/app/views/spree/shared/_main_nav_bar.html.erb
index 9524466e3f..15e566d7f1 100644
--- a/frontend/app/views/spree/shared/_main_nav_bar.html.erb
+++ b/frontend/app/views/spree/shared/_main_nav_bar.html.erb
@@ -1,16 +1,16 @@
-<% if top_level_items_for_menu('spree-all-main').present? %>
+<% if spree_top_level_items_for_menu('spree-all-main').present? %>
<% category = 'category' %>
<% promo = 'promo' %>
<div class="h-100" role="navigation" aria-label="<%= Spree.t('nav_bar.desktop') %>">
<ul class="nav h-100 main-nav-bar">
- <% top_level_items_for_menu('spree-all-main').each do |parent| %>
+ <% spree_top_level_items_for_menu('spree-all-main').each do |parent| %>
<li class="p-0 nav-item main-nav-bar-category">
<% has_dropdown = parent.children.present? %>
<% dropdown_toggle_class = has_dropdown ? "dropdown-toggle" : "" %>
<% data_attr = has_dropdown ? { toggle: "dropdown" } : {} %>
<% aria_attr = has_dropdown ? { haspopup: true, expanded: false } : {} %>
- <%= link_to(parent.name, localized_item_link(parent, current_locale), class: "nav-link main-nav-bar-item main-nav-bar-category-button #{dropdown_toggle_class}", data: data_attr, aria: aria_attr) %>
+ <%= link_to(parent.name, spree_localized_item_link(parent), class: "nav-link main-nav-bar-item main-nav-bar-category-button #{dropdown_toggle_class}", data: data_attr, aria: aria_attr) %>
<% if has_dropdown %>
<div class="dropdown-menu w-100 shadow main-nav-bar-category-dropdown">
<div class="container p-0 d-flex justify-content-xl-around mx-auto">
@@ -27,7 +27,7 @@
<ul class="pl-0">
<% child.children.each do |category_link| %>
<li>
- <%= link_to category_link.name, localized_item_link(category_link, current_locale), class: "text-uppercase main-nav-bar-category-links dropdown-item truncate" %>
+ <%= link_to category_link.name, spree_localized_item_link(category_link), class: "text-uppercase main-nav-bar-category-links dropdown-item truncate" %>
</li>
<% end %>
</ul>
@@ -39,10 +39,10 @@
<% if child.code == promo && child.item_type == 'Container' %>
<% if child.children.present? %>
<% child.children.each do |promo_banner| %>
- <%= link_to localized_item_link(promo_banner, current_locale), class: "dropdown-item" do %>
+ <%= link_to spree_localized_item_link(promo_banner), class: "dropdown-item" do %>
<div class="category-image text-center my-4 mx-3">
- <% if promo_banner.menu_item_image.present? %>
- <%= image_tag main_app.url_for(promo_banner.menu_item_image.attachment), alt: promo_banner.menu_item_image.alt ,title: promo_banner.subtitle %>
+ <% if promo_banner.icon.present? %>
+ <%= image_tag main_app.url_for(promo_banner.icon.attachment), alt: promo_banner.icon.alt ,title: promo_banner.subtitle %>
<% end %>
<div class="category-box">
<div class="category-box-small-text">
diff --git a/frontend/app/views/spree/shared/_mobile_navigation.html.erb b/frontend/app/views/spree/shared/_mobile_navigation.html.erb
index ce33d86745..a76fe0823f 100644
--- a/frontend/app/views/spree/shared/_mobile_navigation.html.erb
+++ b/frontend/app/views/spree/shared/_mobile_navigation.html.erb
@@ -1,4 +1,4 @@
-<% if top_level_items_for_menu('spree-all-main').present? %>
+<% if spree_top_level_items_for_menu('spree-all-main').present? %>
<div class="position-fixed text-uppercase d-xl-none mobile-navigation" role="navigation" aria-label="<%= Spree.t('nav_bar.mobile') %>">
<div class="container d-flex align-items-center justify-content-between header-spree" data-hook>
<button class="m-0 p-0" id="mobile-navigation-back-button" aria-label="<%= Spree.t('nav_bar.go_to_previous_menu') %>">
@@ -18,9 +18,9 @@
</div>
<ul class="list-unstyled position-relative h-100 mobile-navigation-list">
- <% top_level_items_for_menu('spree-all-main').each do |parent| %>
+ <% spree_top_level_items_for_menu('spree-all-main').each do |parent| %>
<li class="d-flex justify-content-between align-items-center mobile-navigation-list-item">
- <%= link_to parent.name, localized_item_link(parent, current_locale), class: 'w-75' %>
+ <%= link_to parent.name, spree_localized_item_link(parent), class: 'w-75' %>
<% if parent.children.present? %>
<a class="w-25 text-right mobile-navigation-category-link" data-category="<%= parent.name.parameterize %>" href="#" aria-label="<%= Spree.t('go_to_category') %>">
<%= icon(name: 'arrow-right',
@@ -39,7 +39,7 @@
<% if child.children.present? %>
<% child.children.each do |category_link| %>
<li class="d-flex justify-content-between align-items-center mobile-navigation-list-item">
- <%= link_to category_link.name, localized_item_link(category_link, current_locale), class: 'w-75' %>
+ <%= link_to category_link.name, spree_localized_item_link(category_link), class: 'w-75' %>
</li>
<% end %>
<% end %>
diff --git a/frontend/spec/helpers/navigation_helper_spec.rb b/frontend/spec/helpers/navigation_helper_spec.rb
index be67839b6c..610663d308 100644
--- a/frontend/spec/helpers/navigation_helper_spec.rb
+++ b/frontend/spec/helpers/navigation_helper_spec.rb
@@ -5,30 +5,6 @@ module Spree
include Spree::CurrencyHelper
include Spree::LocaleHelper
- # Can't test the old data as it does not exist, will be able to test
- # translation on name at some stage.
- # describe '#spree_navigation_data' do
- # let!(:current_store) { create(:store) }
-
- # context 'fetch via locale' do
- # before { I18n.locale = :fr }
-
- # after { I18n.locale = :en }
-
- # it { expect(spree_navigation_data.first[:title]).to eq('Femmes') }
- # end
-
- # context 'fetch via store code' do
- # before { current_store.update(code: 'fr') }
-
- # it { expect(spree_navigation_data.first[:title]).to eq('Femmes') }
- # end
-
- # context 'fallback to default' do
- # it { expect(spree_navigation_data.first[:title]).to eq('Women') }
- # end
- # end
-
describe '#should_render_internationalization_dropdown?' do
context 'store with multiple currencies' do
let(:current_store) { create(:store, supported_currencies: 'EUR,USD') }
@@ -54,5 +30,55 @@ module Spree
it { expect(should_render_internationalization_dropdown?).to be_falsey }
end
end
+
+ context 'spree_localized_item_link' do
+ let(:menu) { create(:menu, unique_code: 'main-123', store_id: current_store.id) }
+ 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') }
+
+ context 'when the default language is passed in' do
+ it 'returns / for home page' do
+ expect(spree_localized_item_link(item_home)).to eq('/')
+ end
+
+ it 'returns /t/taxonomy-1/taxon-1 for a taxon' do
+ item_taxon.update(linked_resource_id: taxon.id)
+ expect(spree_localized_item_link(item_taxon)).to eq("#{item_taxon.destination}")
+ end
+
+ it 'returns /products/product-18-4225 for a product' do
+ item_product.update(linked_resource_id: product.id)
+ expect(spree_localized_item_link(item_product)).to eq("#{item_product.destination}")
+ end
+
+ it 'returns https://some-other-website.com for a URL' do
+ expect(spree_localized_item_link(item_url)).to eq("#{item_url.destination}")
+ end
+ end
+
+ context 'with the none default locale passed in (:fr)' do
+ it 'returns /fr for home page' do
+ expect(spree_localized_item_link(item_home)).to eq('/fr')
+ end
+
+ it 'returns /fr/t/taxonomy-1/taxon-1 for a taxon' do
+ item_taxon.update(linked_resource_id: taxon.id)
+ expect(spree_localized_item_link(item_taxon)).to eq("/fr#{item_taxon.destination}")
+ end
+
+ it 'returns /fr/products/product-18-4225 for a product' do
+ item_product.update(linked_resource_id: product.id)
+ expect(spree_localized_item_link(item_product)).to eq("/fr#{item_product.destination}")
+ end
+
+ it 'returns https://some-other-website.com for a URL' do
+ expect(spree_localized_item_link(item_url)).to eq("#{item_url.destination}")
+ end
+ end
+ end
end
end