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.

Migrate Admin Dashboard to use PrefixedIds

Damian Legawiecac9575980718
diff --git a/admin/app/controllers/concerns/spree/admin/order_concern.rb b/admin/app/controllers/concerns/spree/admin/order_concern.rb
index 1505c3aa94..2799125624 100644
--- a/admin/app/controllers/concerns/spree/admin/order_concern.rb
+++ b/admin/app/controllers/concerns/spree/admin/order_concern.rb
@@ -10,7 +10,7 @@ module Spree
protected
def load_order
- @order = current_store.orders.find_by!(number: params[:order_id])
+ @order = current_store.orders.find_by_prefix_id!(params[:order_id])
authorize! action, @order
@order
end
diff --git a/admin/app/controllers/spree/admin/addresses_controller.rb b/admin/app/controllers/spree/admin/addresses_controller.rb
index 9ef82fa037..7362d7c7fa 100644
--- a/admin/app/controllers/spree/admin/addresses_controller.rb
+++ b/admin/app/controllers/spree/admin/addresses_controller.rb
@@ -4,7 +4,7 @@ module Spree
before_action :set_new_address_country, only: :new
def create
- user = Spree.user_class.find(params[:user_id])
+ user = Spree.user_class.find_by_prefix_id!(params[:user_id])
result = create_service.call(
address_params: permitted_resource_params,
diff --git a/admin/app/controllers/spree/admin/admin_users_controller.rb b/admin/app/controllers/spree/admin/admin_users_controller.rb
index 0ca953fec2..cf188a6e2f 100644
--- a/admin/app/controllers/spree/admin/admin_users_controller.rb
+++ b/admin/app/controllers/spree/admin/admin_users_controller.rb
@@ -110,7 +110,7 @@ module Spree
end
def load_admin_user
- @admin_user = Spree.admin_user_class.accessible_by(current_ability).find(params[:id])
+ @admin_user = Spree.admin_user_class.accessible_by(current_ability).find_by_prefix_id!(params[:id])
end
# for self signup flow, we use the minimal layout
diff --git a/admin/app/controllers/spree/admin/api_keys_controller.rb b/admin/app/controllers/spree/admin/api_keys_controller.rb
index 5cd610d08e..efee27f075 100644
--- a/admin/app/controllers/spree/admin/api_keys_controller.rb
+++ b/admin/app/controllers/spree/admin/api_keys_controller.rb
@@ -9,7 +9,7 @@ module Spree
helper 'spree/admin/api_keys'
def revoke
- @object = scope.find(params[:id])
+ @object = scope.find_by_prefix_id!(params[:id])
@object.revoke!(try_spree_current_user)
flash[:success] = Spree.t('admin.api_keys.revoked')
redirect_to spree.admin_api_key_path(@object)
diff --git a/admin/app/controllers/spree/admin/classifications_controller.rb b/admin/app/controllers/spree/admin/classifications_controller.rb
index ae8c59e74e..3840d93837 100644
--- a/admin/app/controllers/spree/admin/classifications_controller.rb
+++ b/admin/app/controllers/spree/admin/classifications_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class ClassificationsController < ResourceController
- belongs_to 'spree/taxon', find_by: :id
+ belongs_to 'spree/taxon', find_by: :permalink
layout 'turbo_rails/frame'
@@ -19,7 +19,7 @@ module Spree
private
def collection_url
- spree.admin_taxon_classifications_path(@parent.id)
+ spree.admin_taxon_classifications_path(@parent)
end
def update_turbo_stream_enabled?
diff --git a/admin/app/controllers/spree/admin/coupon_codes_controller.rb b/admin/app/controllers/spree/admin/coupon_codes_controller.rb
index cec64ccc6c..bcafbc75bb 100644
--- a/admin/app/controllers/spree/admin/coupon_codes_controller.rb
+++ b/admin/app/controllers/spree/admin/coupon_codes_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class CouponCodesController < ResourceController
- belongs_to 'spree/promotion', find_by: :id
+ belongs_to 'spree/promotion', find_by: :prefix_id
include PromotionsBreadcrumbConcern
end
diff --git a/admin/app/controllers/spree/admin/customer_group_users_controller.rb b/admin/app/controllers/spree/admin/customer_group_users_controller.rb
index 14524d8a8d..ec999c6362 100644
--- a/admin/app/controllers/spree/admin/customer_group_users_controller.rb
+++ b/admin/app/controllers/spree/admin/customer_group_users_controller.rb
@@ -33,7 +33,8 @@ module Spree
end
def destroy
- deleted_count = @customer_group.remove_customers([params[:id]])
+ user = Spree.user_class.find_by_prefix_id!(params[:id])
+ deleted_count = @customer_group.remove_customers([user.id])
if deleted_count > 0
flash[:success] = Spree.t(:customer_removed_from_group)
@@ -58,7 +59,7 @@ module Spree
private
def set_customer_group
- @customer_group = current_store.customer_groups.find(params[:customer_group_id])
+ @customer_group = current_store.customer_groups.find_by_prefix_id!(params[:customer_group_id])
end
def model_class
diff --git a/admin/app/controllers/spree/admin/digital_assets_controller.rb b/admin/app/controllers/spree/admin/digital_assets_controller.rb
index 5179326631..256e71da2f 100644
--- a/admin/app/controllers/spree/admin/digital_assets_controller.rb
+++ b/admin/app/controllers/spree/admin/digital_assets_controller.rb
@@ -26,7 +26,7 @@ module Spree
end
def find_resource
- parent.digitals.find(params[:id])
+ parent.digitals.find_by_prefix_id!(params[:id])
end
def create_turbo_stream_enabled?
diff --git a/admin/app/controllers/spree/admin/gift_cards_controller.rb b/admin/app/controllers/spree/admin/gift_cards_controller.rb
index e92ee01bf2..8b9b0fc0be 100644
--- a/admin/app/controllers/spree/admin/gift_cards_controller.rb
+++ b/admin/app/controllers/spree/admin/gift_cards_controller.rb
@@ -1,8 +1,8 @@
module Spree
module Admin
class GiftCardsController < ResourceController
- prepend_before_action :load_user
prepend_before_action :set_user_id_filter, only: :index
+ prepend_before_action :load_user
before_action :add_breadcrumbs
before_action :load_orders, only: :show
@@ -27,10 +27,10 @@ module Spree
end
def set_user_id_filter
- return if params[:user_id].blank?
+ return if @user.blank?
params[:q] ||= {}
- params[:q][:user_id_eq] = params[:user_id] if params[:user_id].present?
+ params[:q][:user_id_eq] = @user.id
end
def location_after_destroy
@@ -42,11 +42,11 @@ module Spree
end
def location_after_save
- spree.admin_gift_card_path(@object.id)
+ spree.admin_gift_card_path(@object)
end
def load_user
- @user = Spree.user_class.find_by(id: params[:user_id]) if params[:user_id].present?
+ @user = Spree.user_class.find_by_prefix_id(params[:user_id]) if params[:user_id].present?
end
def gift_cards_filter_dropdown_value
diff --git a/admin/app/controllers/spree/admin/import_mappings_controller.rb b/admin/app/controllers/spree/admin/import_mappings_controller.rb
index 8bed45ef34..01610579bc 100644
--- a/admin/app/controllers/spree/admin/import_mappings_controller.rb
+++ b/admin/app/controllers/spree/admin/import_mappings_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class ImportMappingsController < ResourceController
- belongs_to 'spree/import', find_by: :number
+ belongs_to 'spree/import', find_by: :prefix_id
def update_turbo_stream_enabled?
true
diff --git a/admin/app/controllers/spree/admin/import_rows_controller.rb b/admin/app/controllers/spree/admin/import_rows_controller.rb
index c8d86ec810..c92525f4a9 100644
--- a/admin/app/controllers/spree/admin/import_rows_controller.rb
+++ b/admin/app/controllers/spree/admin/import_rows_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class ImportRowsController < ResourceController
- belongs_to 'spree/import', find_by: :number
+ belongs_to 'spree/import', find_by: :prefix_id
end
end
end
diff --git a/admin/app/controllers/spree/admin/invitations_controller.rb b/admin/app/controllers/spree/admin/invitations_controller.rb
index d6d9607289..ee55062578 100644
--- a/admin/app/controllers/spree/admin/invitations_controller.rb
+++ b/admin/app/controllers/spree/admin/invitations_controller.rb
@@ -48,7 +48,7 @@ module Spree
# GET /admin/invitations/:id?token=:token
def show
- @invitation = Spree::Invitation.pending.not_expired.find_by!(id: params[:id], token: params[:token])
+ @invitation = Spree::Invitation.pending.not_expired.find_by!(prefix_id: params[:id], token: params[:token])
@parent = @invitation.resource
if try_spree_current_user.present?
@@ -68,7 +68,7 @@ module Spree
# PUT /admin/invitations/:id/accept
def accept
- @invitation = try_spree_current_user.invitations.pending.not_expired.find(params[:id])
+ @invitation = try_spree_current_user.invitations.pending.not_expired.find_by_prefix_id!(params[:id])
authorize! :accept, @invitation
@@ -78,7 +78,7 @@ module Spree
# PUT /admin/invitations/:id/resend
def resend
- @invitation = scope.find(params[:id])
+ @invitation = scope.find_by_prefix_id!(params[:id])
@invitation.resend!
redirect_back fallback_location: spree.admin_invitations_path, notice: Spree.t('invitation_resent')
end
@@ -94,7 +94,7 @@ module Spree
private
def load_invitation
- @invitation = scope.find(params[:id])
+ @invitation = scope.find_by_prefix_id!(params[:id])
end
def load_parent
diff --git a/admin/app/controllers/spree/admin/line_items_controller.rb b/admin/app/controllers/spree/admin/line_items_controller.rb
index 624cf807b6..1ebf04d985 100644
--- a/admin/app/controllers/spree/admin/line_items_controller.rb
+++ b/admin/app/controllers/spree/admin/line_items_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class LineItemsController < Spree::Admin::ResourceController
- belongs_to 'spree/order', find_by: :number
+ belongs_to 'spree/order', find_by: :prefix_id
layout 'turbo_rails/frame'
diff --git a/admin/app/controllers/spree/admin/option_values_controller.rb b/admin/app/controllers/spree/admin/option_values_controller.rb
index 4512b09326..7270eb9dfd 100644
--- a/admin/app/controllers/spree/admin/option_values_controller.rb
+++ b/admin/app/controllers/spree/admin/option_values_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class OptionValuesController < ResourceController
- belongs_to 'spree/option_type', find_by: :id
+ belongs_to 'spree/option_type', find_by: :prefix_id
def select_options
render json: @option_type.option_values.accessible_by(current_ability).to_tom_select_json
diff --git a/admin/app/controllers/spree/admin/orders/adjustments_controller.rb b/admin/app/controllers/spree/admin/orders/adjustments_controller.rb
index d3a6933c1e..525ea8cb90 100644
--- a/admin/app/controllers/spree/admin/orders/adjustments_controller.rb
+++ b/admin/app/controllers/spree/admin/orders/adjustments_controller.rb
@@ -102,12 +102,12 @@ module Spree
end
def load_order
- @order = current_store.orders.find_by!(number: params[:order_id])
+ @order = current_store.orders.find_by_prefix_id!(params[:order_id])
authorize! :update, @order
end
def load_adjustment
- @adjustment = @order.all_adjustments.find(params[:id])
+ @adjustment = @order.all_adjustments.find_by_prefix_id!(params[:id])
authorize! action, @adjustment
end
diff --git a/admin/app/controllers/spree/admin/orders/billing_address_controller.rb b/admin/app/controllers/spree/admin/orders/billing_address_controller.rb
index 22804afb9f..7b208bfec8 100644
--- a/admin/app/controllers/spree/admin/orders/billing_address_controller.rb
+++ b/admin/app/controllers/spree/admin/orders/billing_address_controller.rb
@@ -20,7 +20,7 @@ module Spree
@order.clone_shipping_address
elsif params[:billing_address_id].present?
- @address = Spree::Address.accessible_by(current_ability, :manage).find(params[:billing_address_id])
+ @address = Spree::Address.accessible_by(current_ability, :manage).find_by_prefix_id!(params[:billing_address_id])
@order.bill_address_id = @address.id
else
@order.bill_address_attributes = address_params
@@ -60,7 +60,7 @@ module Spree
if params[:billing_address_type] == 'same_as_shipping'
@order.clone_shipping_address
elsif params[:billing_address_id].present?
- @address = Spree::Address.accessible_by(current_ability, :manage).find(params[:billing_address_id])
+ @address = Spree::Address.accessible_by(current_ability, :manage).find_by_prefix_id!(params[:billing_address_id])
@order.bill_address_id = @address.id
else
@order.bill_address_attributes = address_params
diff --git a/admin/app/controllers/spree/admin/orders/customer_returns_controller.rb b/admin/app/controllers/spree/admin/orders/customer_returns_controller.rb
index 29b68de20e..603dc5956c 100644
--- a/admin/app/controllers/spree/admin/orders/customer_returns_controller.rb
+++ b/admin/app/controllers/spree/admin/orders/customer_returns_controller.rb
@@ -32,7 +32,7 @@ module Spree
end
def find_resource
- current_store.customer_returns.accessible_by(current_ability, :show).find(params[:id])
+ current_store.customer_returns.accessible_by(current_ability, :show).find_by_prefix_id!(params[:id])
end
def load_form_data
diff --git a/admin/app/controllers/spree/admin/orders/shipping_address_controller.rb b/admin/app/controllers/spree/admin/orders/shipping_address_controller.rb
index 0ab4710537..bd82dbf178 100644
--- a/admin/app/controllers/spree/admin/orders/shipping_address_controller.rb
+++ b/admin/app/controllers/spree/admin/orders/shipping_address_controller.rb
@@ -46,7 +46,7 @@ module Spree
def update
if params[:shipping_address_id].present?
- @address = Spree::Address.accessible_by(current_ability, :manage).find(params[:shipping_address_id])
+ @address = Spree::Address.accessible_by(current_ability, :manage).find_by_prefix_id!(params[:shipping_address_id])
@order.ship_address_id = @address.id
else
@order.ship_address_attributes = address_params
diff --git a/admin/app/controllers/spree/admin/orders/user_controller.rb b/admin/app/controllers/spree/admin/orders/user_controller.rb
index 02a4137158..3eee9b2928 100644
--- a/admin/app/controllers/spree/admin/orders/user_controller.rb
+++ b/admin/app/controllers/spree/admin/orders/user_controller.rb
@@ -53,7 +53,7 @@ module Spree
end
def update
- user = Spree.user_class.find(params[:user_id])
+ user = Spree.user_class.find_by_prefix_id!(params[:user_id])
@order.associate_user!(user)
if [email protected]? && @order.line_items.any?
diff --git a/admin/app/controllers/spree/admin/orders_controller.rb b/admin/app/controllers/spree/admin/orders_controller.rb
index 19dce40641..38402579e3 100644
--- a/admin/app/controllers/spree/admin/orders_controller.rb
+++ b/admin/app/controllers/spree/admin/orders_controller.rb
@@ -102,7 +102,7 @@ module Spree
end
def load_order
- @order = scope.includes(:adjustments).find_by!(number: params[:id])
+ @order = scope.includes(:adjustments).find_by_prefix_id!(params[:id])
authorize! action, @order
end
diff --git a/admin/app/controllers/spree/admin/payments_controller.rb b/admin/app/controllers/spree/admin/payments_controller.rb
index 968ce654dc..5bf4f5a72d 100644
--- a/admin/app/controllers/spree/admin/payments_controller.rb
+++ b/admin/app/controllers/spree/admin/payments_controller.rb
@@ -3,7 +3,7 @@ module Spree
class PaymentsController < Spree::Admin::ResourceController
include Spree::Admin::OrderBreadcrumbConcern
- belongs_to 'spree/order', find_by: :number
+ belongs_to 'spree/order', find_by: :prefix_id
before_action :load_data
before_action :proceed_order_state, only: :new
diff --git a/admin/app/controllers/spree/admin/price_list_products_controller.rb b/admin/app/controllers/spree/admin/price_list_products_controller.rb
index ad7575f61d..03f2a4c425 100644
--- a/admin/app/controllers/spree/admin/price_list_products_controller.rb
+++ b/admin/app/controllers/spree/admin/price_list_products_controller.rb
@@ -3,7 +3,7 @@ module Spree
class PriceListProductsController < ResourceController
include BulkOperationsConcern
- belongs_to 'spree/price_list', find_by: :id
+ belongs_to 'spree/price_list', find_by: :prefix_id
before_action :set_price_list
diff --git a/admin/app/controllers/spree/admin/price_rules_controller.rb b/admin/app/controllers/spree/admin/price_rules_controller.rb
index 42ff77e015..a41f496c5d 100644
--- a/admin/app/controllers/spree/admin/price_rules_controller.rb
+++ b/admin/app/controllers/spree/admin/price_rules_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class PriceRulesController < ResourceController
- belongs_to 'spree/price_list', find_by: :id
+ belongs_to 'spree/price_list', find_by: :prefix_id
helper_method :allowed_rule_types
diff --git a/admin/app/controllers/spree/admin/products_controller.rb b/admin/app/controllers/spree/admin/products_controller.rb
index 871dbc6a3a..f954c430dd 100644
--- a/admin/app/controllers/spree/admin/products_controller.rb
+++ b/admin/app/controllers/spree/admin/products_controller.rb
@@ -169,9 +169,11 @@ module Spree
end
@product_variant_ids = {}
+ @product_variant_prefix_ids = {}
@product.variants.includes(:option_values).each do |variant|
@product_variant_ids[variant.human_name] = variant.id.to_s
+ @product_variant_prefix_ids[variant.human_name] = variant.to_param
end
end
diff --git a/admin/app/controllers/spree/admin/promotion_actions_controller.rb b/admin/app/controllers/spree/admin/promotion_actions_controller.rb
index db878e3a22..be2ab8400c 100644
--- a/admin/app/controllers/spree/admin/promotion_actions_controller.rb
+++ b/admin/app/controllers/spree/admin/promotion_actions_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class PromotionActionsController < ResourceController
- belongs_to 'spree/promotion', find_by: :id
+ belongs_to 'spree/promotion', find_by: :prefix_id
helper_method :allowed_action_types
diff --git a/admin/app/controllers/spree/admin/promotion_rules_controller.rb b/admin/app/controllers/spree/admin/promotion_rules_controller.rb
index 1607948184..1679cf9ea5 100644
--- a/admin/app/controllers/spree/admin/promotion_rules_controller.rb
+++ b/admin/app/controllers/spree/admin/promotion_rules_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class PromotionRulesController < ResourceController
- belongs_to 'spree/promotion', find_by: :id
+ belongs_to 'spree/promotion', find_by: :prefix_id
helper_method :allowed_rule_types
diff --git a/admin/app/controllers/spree/admin/promotions_controller.rb b/admin/app/controllers/spree/admin/promotions_controller.rb
index 3d3c2a11ae..0c5341056e 100644
--- a/admin/app/controllers/spree/admin/promotions_controller.rb
+++ b/admin/app/controllers/spree/admin/promotions_controller.rb
@@ -16,7 +16,7 @@ module Spree
# POST /admin/promotions/:id/clone
def clone
- promotion = current_store.promotions.find(params[:id])
+ promotion = current_store.promotions.find_by_prefix_id!(params[:id])
duplicator = Spree::PromotionHandler::PromotionDuplicator.new(promotion)
@new_promo = duplicator.duplicate
diff --git a/admin/app/controllers/spree/admin/refunds_controller.rb b/admin/app/controllers/spree/admin/refunds_controller.rb
index 9dc79dc3c3..f36669e220 100644
--- a/admin/app/controllers/spree/admin/refunds_controller.rb
+++ b/admin/app/controllers/spree/admin/refunds_controller.rb
@@ -3,7 +3,7 @@ module Spree
class RefundsController < ResourceController
include Spree::Admin::OrderBreadcrumbConcern
- belongs_to 'spree/payment', find_by: :number
+ belongs_to 'spree/payment', find_by: :prefix_id
before_action :load_order
before_action :assign_refunder, only: :create
diff --git a/admin/app/controllers/spree/admin/reimbursements_controller.rb b/admin/app/controllers/spree/admin/reimbursements_controller.rb
index 21ef76b6e6..8f63792d4c 100644
--- a/admin/app/controllers/spree/admin/reimbursements_controller.rb
+++ b/admin/app/controllers/spree/admin/reimbursements_controller.rb
@@ -1,7 +1,7 @@
module Spree
module Admin
class ReimbursementsController < ResourceController
- belongs_to 'spree/order', find_by: :number
+ belongs_to 'spree/order', find_by: :prefix_id
before_action :load_simulated_refunds, only: :edit
@@ -16,7 +16,7 @@ module Spree
def build_resource
if params[:build_from_customer_return_id].present?
- customer_return = current_store.customer_returns.find(params[:build_from_customer_return_id])
+ customer_return = current_store.customer_returns.find_by_prefix_id!(params[:build_from_customer_return_id])
Reimbursement.build_from_customer_return(customer_return)
else
diff --git a/admin/app/controllers/spree/admin/resource_controller.rb b/admin/app/controllers/spree/admin/resource_controller.rb
index b1a9573db5..0a4573d733 100644
--- a/admin/app/controllers/spree/admin/resource_controller.rb
+++ b/admin/app/controllers/spree/admin/resource_controller.rb
@@ -128,7 +128,7 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
@parent_data ||= {}
@parent_data[:model_name] = model_name
@parent_data[:model_class] = model_name.to_s.classify.constantize
- @parent_data[:find_by] = options[:find_by] || :id
+ @parent_data[:find_by] = options[:find_by] || :prefix_id
end
end
@@ -187,14 +187,23 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
def parent
if parent_data.present?
base_scope = parent_data[:model_class].try(:for_store, current_store) || parent_data[:model_class]
-
- @parent ||= base_scope.
- # Don't use `find_by_attribute_name` to workaround globalize/globalize#423 bug
- send(:find_by, parent_data[:find_by].to_s => params["#{resource.model_name}_id"])
+ param_value = params["#{resource.model_name}_id"]
+ find_by = parent_data[:find_by]
+ parent_model_class = parent_data[:model_class]
+
+ # Skip prefix_id lookup for FriendlyId models (they use slug for to_param)
+ uses_friendly_id = parent_model_class.respond_to?(:friendly_id_config)
+ use_prefix_id = find_by == :prefix_id &&
+ parent_model_class.column_names.include?('prefix_id') &&
+ !uses_friendly_id
+
+ @parent ||= if use_prefix_id
+ base_scope.find_by_prefix_id!(param_value)
+ else
+ base_scope.find_by!(find_by.to_s => param_value)
+ end
instance_variable_set("@#{resource.model_name}", @parent)
- raise ActiveRecord::RecordNotFound if @parent.nil?
-
@parent
end
end
@@ -204,9 +213,15 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController
parent.send(controller_name)
else
model_class.try(:for_store, current_store) || model_class
- end
+ end
+
+ # Skip prefix_id lookup for FriendlyId models (they use slug for to_param)
+ uses_friendly_id = model_class.respond_to?(:friendly_id_config)
+ use_prefix_id = model_class.column_names.include?('prefix_id') && !uses_friendly_id
- if model_class.try(:friendly)
+ if use_prefix_id
+ base_scope.find_by_prefix_id!(params[:id])
+ elsif uses_friendly_id
base_scope.friendly.find(params[:id])
else
base_scope.find(params[:id])
diff --git a/admin/app/controllers/spree/admin/shipments_controller.rb b/admin/app/controllers/spree/admin/shipments_controller.rb
index c40546982e..6a4487b383 100644
--- a/admin/app/controllers/spree/admin/shipments_controller.rb
+++ b/admin/app/controllers/spree/admin/shipments_controller.rb
@@ -5,7 +5,7 @@ module Spree
layout 'turbo_rails/frame'
- belongs_to 'spree/order', find_by: :number
+ belongs_to 'spree/order', find_by: :prefix_id
before_action :load_variant, only: [:split, :transfer]
before_action :refresh_shipping_rates, only: :edit
@@ -82,7 +82,7 @@ module Spree
end
def find_resource
- record = parent.shipments.find_by!(number: params[:id])
+ record = parent.shipments.find_by_prefix_id!(params[:id])
authorize! action, record
end
@@ -91,7 +91,7 @@ module Spree
end
def load_variant
- @variant = current_store.variants.accessible_by(current_ability, :manage).find(params[:variant_id])
+ @variant = current_store.variants.accessible_by(current_ability, :manage).find_by_prefix_id!(params[:variant_id])
end
def permitted_resource_params
diff --git a/admin/app/controllers/spree/admin/store_credits_controller.rb b/admin/app/controllers/spree/admin/store_credits_controller.rb
index 126b9c131d..7f0aaaa596 100644
--- a/admin/app/controllers/spree/admin/store_credits_controller.rb
+++ b/admin/app/controllers/spree/admin/store_credits_controller.rb
@@ -8,7 +8,7 @@ module Spree
before_action :ensure_unused_store_credit, only: [:update]
def show
- @store_credit = scope.find(params[:id])
+ @store_credit = scope.find_by_prefix_id!(params[:id])
@store_credit_events = @store_credit.store_credit_events.reverse_chronological.includes(:originator, :order)
end
@@ -57,14 +57,14 @@ module Spree
protected
def parent
- @parent ||= Spree.user_class.find_by(id: params[:user_id])
+ @parent ||= Spree.user_class.find_by_prefix_id!(params[:user_id])
end
def parent_data
{
model_name: 'spree/user',
model_class: Spree.user_class,
- find_by: :id
+ find_by: :prefix_id
}
end
diff --git a/admin/app/controllers/spree/admin/taxons_controller.rb b/admin/app/controllers/spree/admin/taxons_controller.rb
index aa673fc6e3..a3b521ce52 100644
--- a/admin/app/controllers/spree/admin/taxons_controller.rb
+++ b/admin/app/controllers/spree/admin/taxons_controller.rb
@@ -49,7 +49,7 @@ module Spree
end
def location_after_save
- spree.edit_admin_taxonomy_taxon_path(@taxon.taxonomy_id, @taxon.id)
+ spree.edit_admin_taxonomy_taxon_path(@taxon.taxonomy, @taxon)
end
def update_turbo_stream_enabled?
@@ -113,7 +113,7 @@ module Spree
add_breadcrumb @taxonomy.name, collection_url
if @object.present? && @object.persisted?
- add_breadcrumb @object.name, spree.edit_admin_taxonomy_taxon_path(@taxonomy, @object.id)
+ add_breadcrumb @object.name, spree.edit_admin_taxonomy_taxon_path(@taxonomy, @object)
end
end
diff --git a/admin/app/controllers/spree/admin/users_controller.rb b/admin/app/controllers/spree/admin/users_controller.rb
index ab6f8d493a..af4869b27a 100644
--- a/admin/app/controllers/spree/admin/users_controller.rb
+++ b/admin/app/controllers/spree/admin/users_controller.rb
@@ -92,7 +92,7 @@ module Spree
end
def find_resource
- model_class.accessible_by(current_ability, :show).find(params[:id])
+ model_class.accessible_by(current_ability, :show).find_by_prefix_id!(params[:id])
end
def collection_url
diff --git a/admin/app/helpers/spree/admin/orders_filters_helper.rb b/admin/app/helpers/spree/admin/orders_filters_helper.rb
index 981c1cf5fa..03dfce2bf2 100644
--- a/admin/app/helpers/spree/admin/orders_filters_helper.rb
+++ b/admin/app/helpers/spree/admin/orders_filters_helper.rb
@@ -37,7 +37,7 @@ module Spree
end
def load_user
- @user = Spree.user_class.find(params[:user_id]) if params[:user_id].present?
+ @user = Spree.user_class.find_by_prefix_id(params[:user_id]) if params[:user_id].present?
end
end
end
diff --git a/admin/app/javascript/spree/admin/controllers/variants_form_controller.js b/admin/app/javascript/spree/admin/controllers/variants_form_controller.js
index 0b981b7f1e..ac14913b09 100644
--- a/admin/app/javascript/spree/admin/controllers/variants_form_controller.js
+++ b/admin/app/javascript/spree/admin/controllers/variants_form_controller.js
@@ -35,6 +35,7 @@ export default class extends CheckboxSelectAll {
currencies: Array,
currencyFormats: Object,
variantIds: Object,
+ variantPrefixIds: Object,
currentStockLocationId: String,
stockLocations: Array,
optionValuesSelectOptions: Array,
@@ -526,12 +527,12 @@ export default class extends CheckboxSelectAll {
const variantTarget = template.querySelector('[data-variants-form-target="variant"]')
variantTarget.dataset.variantName = internalName
- const variantId = this.variantIdsValue[internalName]
- if (variantId) {
+ const variantPrefixId = this.variantPrefixIdsValue?.[internalName] || this.variantIdsValue[internalName]
+ if (variantPrefixId) {
const variantEditButton = variantTarget.querySelector('[data-slot="variantEditButton"]')
if (variantEditButton) {
- variantEditButton.href = `${Spree.adminPath}/products/${this.productIdValue}/variants/${variantId}/edit`
+ variantEditButton.href = `${Spree.adminPath}/products/${this.productIdValue}/variants/${variantPrefixId}/edit`
variantEditButton.classList.remove('invisible')
}
}
diff --git a/admin/app/views/spree/admin/orders/billing_address/_form.html.erb b/admin/app/views/spree/admin/orders/billing_address/_form.html.erb
index 7ff39e6143..22cecb597f 100644
--- a/admin/app/views/spree/admin/orders/billing_address/_form.html.erb
+++ b/admin/app/views/spree/admin/orders/billing_address/_form.html.erb
@@ -9,8 +9,8 @@
<% if @order.user.present? && @order.user.addresses.many? %>
<div data-form="existing_address" class="hidden">
<%= label_tag :billing_address_id, Spree.t(:existing_address), class: 'sr-only' %>
- <%= select_tag :billing_address_id,
- options_for_select(@order.user.addresses.map { |a| [a.to_s.gsub('<br/>', ", "), a.id]}),
+ <%= select_tag :billing_address_id,
+ options_for_select(@order.user.addresses.map { |a| [a.to_s.gsub('<br/>', ", "), a.to_param]}),
{ include_blank: Spree.t(:select_existing_address), class: "form-select", data: { action: 'auto-submit#submit' } } %>
</div>
<% end %>
diff --git a/admin/app/views/spree/admin/orders/shipping_address/_form.html.erb b/admin/app/views/spree/admin/orders/shipping_address/_form.html.erb
index 1b74c8bb3b..1e08297aac 100644
--- a/admin/app/views/spree/admin/orders/shipping_address/_form.html.erb
+++ b/admin/app/views/spree/admin/orders/shipping_address/_form.html.erb
@@ -8,8 +8,8 @@
<div>
<div class="w-full text-center mb-2"><%= Spree.t(:or_select_other_address) %></div>
<%= label_tag :shipping_address_id, Spree.t(:existing_address), class: 'sr-only' %>
- <%= select_tag :shipping_address_id,
- options_for_select(@order.user.addresses.map { |a| [a.to_s.gsub('<br/>', ", "), a.id]}),
+ <%= select_tag :shipping_address_id,
+ options_for_select(@order.user.addresses.map { |a| [a.to_s.gsub('<br/>', ", "), a.to_param]}),
{ include_blank: Spree.t(:select_existing_address), class: "form-select", data: { action: 'auto-submit#submit' } } %>
</div>
<% end %>
diff --git a/admin/app/views/spree/admin/products/form/_variants.html.erb b/admin/app/views/spree/admin/products/form/_variants.html.erb
index 6c501bb4a1..8d36d5e7ab 100644
--- a/admin/app/views/spree/admin/products/form/_variants.html.erb
+++ b/admin/app/views/spree/admin/products/form/_variants.html.erb
@@ -31,6 +31,7 @@
<% if @product_stock.present? %> data-variants-form-stock-value="<%= @product_stock.to_json %>" <% end %>
<% if @product_prices.present? %> data-variants-form-prices-value="<%= @product_prices.to_json %>" <% end %>
<% if @product_variant_ids.present? %> data-variants-form-variant-ids-value="<%= @product_variant_ids.to_json %>" <% end %>
+ <% if @product_variant_prefix_ids.present? %> data-variants-form-variant-prefix-ids-value="<%= @product_variant_prefix_ids.to_json %>" <% end %>
>
<div class="options-creator">
<%= render 'spree/admin/products/form/variants/option_template', option_types_for_select: option_types_for_select %>
diff --git a/admin/app/views/spree/admin/users/_billing.html.erb b/admin/app/views/spree/admin/users/_billing.html.erb
index a4475e191a..073b367aad 100644
--- a/admin/app/views/spree/admin/users/_billing.html.erb
+++ b/admin/app/views/spree/admin/users/_billing.html.erb
@@ -13,7 +13,7 @@
</button>
<% else %>
<%= link_to_with_icon 'plus', Spree.t(:add),
- spree.new_admin_address_path(user_id: @user.id, default_billing: true, type: 'billing'),
+ spree.new_admin_address_path(user_id: @user.to_param, default_billing: true, type: 'billing'),
class: 'btn btn-light btn-sm',
data: { turbo_frame: :new_address_billing } if can?(:create, Spree::Address) && can?(:update, @user) %>
<% end %>
@@ -42,7 +42,7 @@
</div>
<div class="custom-control custom-radio">
- <%= link_to spree.new_admin_address_path(user_id: @user.id, default_billing: true, type: 'billing'), data: { turbo_frame: :new_address_billing } do %>
+ <%= link_to spree.new_admin_address_path(user_id: @user.to_param, default_billing: true, type: 'billing'), data: { turbo_frame: :new_address_billing } do %>
<%= radio_button_tag :user_bill_address_id, nil, false,
id: 'user_bill_address_id_new_address',
class: 'custom-control-input' %>
diff --git a/admin/app/views/spree/admin/users/_shipping.html.erb b/admin/app/views/spree/admin/users/_shipping.html.erb
index f81eeb96a5..659b3eaca5 100644
--- a/admin/app/views/spree/admin/users/_shipping.html.erb
+++ b/admin/app/views/spree/admin/users/_shipping.html.erb
@@ -9,7 +9,7 @@
data: { turbo_frame: :edit_address_shipping } if can?(:update, @user.shipping_address) %>
<% else %>
<%= link_to_with_icon 'plus', Spree.t(:add),
- spree.new_admin_address_path(user_id: @user.id, default_shipping: true, type: 'shipping'),
+ spree.new_admin_address_path(user_id: @user.to_param, default_shipping: true, type: 'shipping'),
class: 'btn btn-light btn-sm',
data: { turbo_frame: :new_address_shipping } if can?(:create, Spree::Address) && can?(:update, @user) %>
<% end %>
diff --git a/admin/spec/controllers/spree/admin/addresses_controller_spec.rb b/admin/spec/controllers/spree/admin/addresses_controller_spec.rb
index a5a4537da9..d477149317 100644
--- a/admin/spec/controllers/spree/admin/addresses_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/addresses_controller_spec.rb
@@ -18,7 +18,7 @@ RSpec.describe Spree::Admin::AddressesController, type: :controller do
describe 'POST #create' do
subject { post :create, params: params, format: :turbo_stream }
- let(:params) { { address: address_params, user_id: user.id, type: 'shipping', default_shipping: true } }
+ let(:params) { { address: address_params, user_id: user.to_param, type: 'shipping', default_shipping: true } }
let(:address_params) do
{
@@ -51,7 +51,7 @@ RSpec.describe Spree::Admin::AddressesController, type: :controller do
end
context 'with default shipping' do
- let(:params) { { address: address_params, user_id: user.id, type: 'shipping', default_shipping: true } }
+ let(:params) { { address: address_params, user_id: user.to_param, type: 'shipping', default_shipping: true } }
it 'creates a new default shipping address' do
expect { subject }.to change(Spree::Address, :count).by(1)
@@ -60,7 +60,7 @@ RSpec.describe Spree::Admin::AddressesController, type: :controller do
end
context 'with default billing' do
- let(:params) { { address: address_params, user_id: user.id, type: 'billing', default_billing: true } }
+ let(:params) { { address: address_params, user_id: user.to_param, type: 'billing', default_billing: true } }
it 'creates a new default billing address' do
expect { subject }.to change(Spree::Address, :count).by(1)
@@ -84,7 +84,7 @@ RSpec.describe Spree::Admin::AddressesController, type: :controller do
let(:address) { create(:address) }
it 'renders the edit address form' do
- get :edit, params: { id: address.id, type: 'shipping' }
+ get :edit, params: { id: address.to_param, type: 'shipping' }
expect(response).to render_template(:edit)
end
end
@@ -93,7 +93,7 @@ RSpec.describe Spree::Admin::AddressesController, type: :controller do
subject { put :update, params: params, format: :turbo_stream }
let(:address) { create(:address, user: user, firstname: 'John', lastname: 'Doe') }
- let(:params) { { id: address.id, address: address_params, type: 'shipping' } }
+ let(:params) { { id: address.to_param, address: address_params, type: 'shipping' } }
let(:address_params) do
{
diff --git a/admin/spec/controllers/spree/admin/admin_users_controller_spec.rb b/admin/spec/controllers/spree/admin/admin_users_controller_spec.rb
index 955818940c..fa5a792f81 100644
--- a/admin/spec/controllers/spree/admin/admin_users_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/admin_users_controller_spec.rb
@@ -72,15 +72,15 @@ RSpec.describe Spree::Admin::AdminUsersController, type: :controller do
describe 'GET #show' do
stub_authorization!
- before { get :show, params: { id: admin_user.id } }
+ before { get :show, params: { id: admin_user.to_param } }
it 'returns a successful response' do
- get :show, params: { id: admin_user.id }
+ get :show, params: { id: admin_user.to_param }
expect(response).to be_successful
end
it 'assigns @admin_user' do
- get :show, params: { id: admin_user.id }
+ get :show, params: { id: admin_user.to_param }
expect(assigns(:admin_user)).to eq(admin_user)
end
@@ -90,7 +90,7 @@ RSpec.describe Spree::Admin::AdminUsersController, type: :controller do
before do
second_store_role
- get :show, params: { id: admin_user.id }
+ get :show, params: { id: admin_user.to_param }
end
it 'assigns @role_users with roles from the current resource' do
@@ -212,7 +212,7 @@ RSpec.describe Spree::Admin::AdminUsersController, type: :controller do
describe 'GET #edit' do
stub_authorization!
- before { get :edit, params: { id: admin_user.id } }
+ before { get :edit, params: { id: admin_user.to_param } }
it 'returns a successful response' do
expect(response).to be_successful
@@ -230,7 +230,7 @@ RSpec.describe Spree::Admin::AdminUsersController, type: :controller do
let(:valid_params) do
{
- id: admin_user.id,
+ id: admin_user.to_param,
admin_user: {
first_name: 'Updated',
last_name: 'Name',
@@ -265,7 +265,7 @@ RSpec.describe Spree::Admin::AdminUsersController, type: :controller do
context 'with invalid parameters' do
let(:invalid_params) do
{
- id: admin_user.id,
+ id: admin_user.to_param,
admin_user: {
email: ''
}
@@ -295,14 +295,14 @@ RSpec.describe Spree::Admin::AdminUsersController, type: :controller do
let!(:other_admin) { create(:admin_user) }
it 'deletes the admin user' do
- expect { delete :destroy, params: { id: admin_user.id } }.to change(Spree.admin_user_class, :count).by(-1)
+ expect { delete :destroy, params: { id: admin_user.to_param } }.to change(Spree.admin_user_class, :count).by(-1)
expect(response).to redirect_to(spree.admin_admin_users_path)
end
end
context 'cannot delete user' do
it 'does not delete the admin user' do
- delete :destroy, params: { id: admin_user.id }
+ delete :destroy, params: { id: admin_user.to_param }
expect(response).to redirect_to(spree.admin_admin_users_path)
expect(admin_user).not_to be_destroyed
end
diff --git a/admin/spec/controllers/spree/admin/api_keys_controller_spec.rb b/admin/spec/controllers/spree/admin/api_keys_controller_spec.rb
index a7a24f9d70..23d60b564a 100644
--- a/admin/spec/controllers/spree/admin/api_keys_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/api_keys_controller_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe Spree::Admin::ApiKeysController, type: :controller do
end
describe 'GET #show' do
- subject(:show) { get :show, params: { id: api_key.id } }
+ subject(:show) { get :show, params: { id: api_key.to_param } }
let(:api_key) { create(:api_key, store: store) }
@@ -129,7 +129,7 @@ RSpec.describe Spree::Admin::ApiKeysController, type: :controller do
end
describe 'GET #edit' do
- subject(:edit) { get :edit, params: { id: api_key.id } }
+ subject(:edit) { get :edit, params: { id: api_key.to_param } }
let(:api_key) { create(:api_key, store: store) }
@@ -147,7 +147,7 @@ RSpec.describe Spree::Admin::ApiKeysController, type: :controller do
end
describe 'PUT #update' do
- subject(:update_key) { put :update, params: { id: api_key.id, api_key: key_params } }
+ subject(:update_key) { put :update, params: { id: api_key.to_param, api_key: key_params } }
let!(:api_key) { create(:api_key, store: store, name: 'Old Name') }
@@ -200,24 +200,11 @@ RSpec.describe Spree::Admin::ApiKeysController, type: :controller do
end
end
- describe 'DELETE #destroy' do
- subject(:destroy_key) { delete :destroy, params: { id: api_key.id } }
-
- let!(:api_key) { create(:api_key, store: store) }
-
- it 'deletes the api key' do
- expect { destroy_key }.to change(Spree::ApiKey, :count).by(-1)
- end
-
- it 'redirects to index' do
- destroy_key
-
- expect(response).to redirect_to(spree.admin_api_keys_path)
- end
- end
+ # NOTE: destroy action is disabled via routes (except: :destroy)
+ # The revoke action should be used instead to deactivate API keys
describe 'PUT #revoke' do
- subject(:revoke_key) { put :revoke, params: { id: api_key.id } }
+ subject(:revoke_key) { put :revoke, params: { id: api_key.to_param } }
let!(:api_key) { create(:api_key, store: store) }
diff --git a/admin/spec/controllers/spree/admin/assets_controller_spec.rb b/admin/spec/controllers/spree/admin/assets_controller_spec.rb
index 70cfb1a951..e359b3940e 100644
--- a/admin/spec/controllers/spree/admin/assets_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/assets_controller_spec.rb
@@ -71,7 +71,7 @@ describe Spree::Admin::AssetsController, type: :controller do
end
describe '#update' do
- subject { put :update, params: { id: image.id, asset: { alt: 'Alt text' } }, as: :turbo_stream }
+ subject { put :update, params: { id: image.to_param, asset: { alt: 'Alt text' } }, as: :turbo_stream }
let!(:image) { create(:image, viewable: product.master) }
@@ -84,7 +84,7 @@ describe Spree::Admin::AssetsController, type: :controller do
end
describe '#destroy' do
- subject { delete :destroy, params: { id: image.id }, format: :turbo_stream }
+ subject { delete :destroy, params: { id: image.to_param }, format: :turbo_stream }
let!(:image) { create(:image, viewable: product.master) }
diff --git a/admin/spec/controllers/spree/admin/classifications_controller_spec.rb b/admin/spec/controllers/spree/admin/classifications_controller_spec.rb
index 8b3898cd1d..654ee55ed6 100644
--- a/admin/spec/controllers/spree/admin/classifications_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/classifications_controller_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe Spree::Admin::ClassificationsController, type: :controller do
]
end
- subject { get :index, params: { taxon_id: taxon.id } }
+ subject { get :index, params: { taxon_id: taxon.to_param } }
it 'returns a successful response' do
subject
@@ -46,7 +46,7 @@ RSpec.describe Spree::Admin::ClassificationsController, type: :controller do
end
describe 'POST #create' do
- subject { post :create, params: { taxon_id: taxon.id, ids: [product1.id, product2.id], format: :turbo_stream } }
+ subject { post :create, params: { taxon_id: taxon.to_param, ids: [product1.id, product2.id], format: :turbo_stream } }
it 'creates classifications' do
expect { subject }.to change(Spree::Classification, :count).by(2)
@@ -61,7 +61,7 @@ RSpec.describe Spree::Admin::ClassificationsController, type: :controller do
describe 'PATCH #update' do
let!(:classification) { create(:classification, taxon: taxon, product: product1, position: 1) }
- subject { patch :update, params: { taxon_id: taxon.id, id: classification.id, classification: { position: 2 }, format: :turbo_stream } }
+ subject { patch :update, params: { taxon_id: taxon.to_param, id: classification.to_param, classification: { position: 2 }, format: :turbo_stream } }
it 'updates the classification' do
expect { subject }.to change { classification.reload.position }.from(1).to(2)
@@ -76,7 +76,7 @@ RSpec.describe Spree::Admin::ClassificationsController, type: :controller do
describe 'DELETE #destroy' do
let!(:classification) { create(:classification, taxon: taxon, product: product1) }
- subject { delete :destroy, params: { taxon_id: taxon.id, id: classification.id, format: :turbo_stream } }
+ subject { delete :destroy, params: { taxon_id: taxon.to_param, id: classification.to_param, format: :turbo_stream } }
it 'destroys the classification' do
expect { subject }.to change(Spree::Classification, :count).by(-1)
diff --git a/admin/spec/controllers/spree/admin/custom_domains_controller_spec.rb b/admin/spec/controllers/spree/admin/custom_domains_controller_spec.rb
index 488edf53b1..4fe5b30789 100644
--- a/admin/spec/controllers/spree/admin/custom_domains_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/custom_domains_controller_spec.rb
@@ -80,7 +80,7 @@ describe Spree::Admin::CustomDomainsController, type: :controller do
end
describe '#edit' do
- subject { get :edit, params: { id: custom_domain.id } }
+ subject { get :edit, params: { id: custom_domain.to_param } }
let!(:custom_domain) { create(:custom_domain, store: store) }
@@ -98,7 +98,7 @@ describe Spree::Admin::CustomDomainsController, type: :controller do
let(:params) do
{
- id: custom_domain.id,
+ id: custom_domain.to_param,
custom_domain: {
url: 'updated-domain.com'
}
@@ -116,7 +116,7 @@ describe Spree::Admin::CustomDomainsController, type: :controller do
context 'with invalid params' do
let(:params) do
{
- id: custom_domain.id,
+ id: custom_domain.to_param,
custom_domain: {
url: ''
}
diff --git a/admin/spec/controllers/spree/admin/customer_group_users_controller_spec.rb b/admin/spec/controllers/spree/admin/customer_group_users_controller_spec.rb
index 07f536c2ee..287a904927 100644
--- a/admin/spec/controllers/spree/admin/customer_group_users_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/customer_group_users_controller_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Spree::Admin::CustomerGroupUsersController, type: :controller do
let(:customer_group) { create(:customer_group, store: store) }
describe 'GET #index' do
- subject(:index) { get :index, params: { customer_group_id: customer_group.id } }
+ subject(:index) { get :index, params: { customer_group_id: customer_group.to_param } }
let(:user1) { create(:user) }
let(:user2) { create(:user) }
@@ -38,7 +38,7 @@ RSpec.describe Spree::Admin::CustomerGroupUsersController, type: :controller do
end
describe 'GET #bulk_new' do
- subject(:bulk_new) { get :bulk_new, params: { customer_group_id: customer_group.id } }
+ subject(:bulk_new) { get :bulk_new, params: { customer_group_id: customer_group.to_param } }
it 'returns success' do
bulk_new
@@ -52,7 +52,7 @@ RSpec.describe Spree::Admin::CustomerGroupUsersController, type: :controller do
end
describe 'POST #create' do
- subject(:create_membership) { post :create, params: { customer_group_id: customer_group.id, user_ids: user_ids } }
+ subject(:create_membership) { post :create, params: { customer_group_id: customer_group.to_param, user_ids: user_ids } }
let(:user1) { create(:user) }
let(:user2) { create(:user) }
@@ -96,7 +96,7 @@ RSpec.describe Spree::Admin::CustomerGroupUsersController, type: :controller do
end
describe 'DELETE #destroy' do
- subject(:destroy_membership) { delete :destroy, params: { customer_group_id: customer_group.id, id: user.id } }
+ subject(:destroy_membership) { delete :destroy, params: { customer_group_id: customer_group.to_param, id: user.to_param } }
let(:user) { create(:user) }
@@ -124,14 +124,14 @@ RSpec.describe Spree::Admin::CustomerGroupUsersController, type: :controller do
let(:other_user) { create(:user) }
it 'sets error flash message' do
- delete :destroy, params: { customer_group_id: customer_group.id, id: other_user.id }
+ delete :destroy, params: { customer_group_id: customer_group.to_param, id: other_user.to_param }
expect(flash[:error]).to eq(Spree.t(:customer_could_not_be_removed_from_group))
end
end
end
describe 'POST #bulk_create' do
- subject(:bulk_create) { post :bulk_create, params: { customer_group_id: customer_group.id, ids: user_ids }, format: :turbo_stream }
+ subject(:bulk_create) { post :bulk_create, params: { customer_group_id: customer_group.to_param, ids: user_ids }, format: :turbo_stream }
let(:user1) { create(:user) }
let(:user2) { create(:user) }
@@ -165,7 +165,7 @@ RSpec.describe Spree::Admin::CustomerGroupUsersController, type: :controller do
end
describe 'DELETE #bulk_destroy' do
- subject(:bulk_destroy) { delete :bulk_destroy, params: { customer_group_id: customer_group.id, ids: user_ids }, format: :turbo_stream }
+ subject(:bulk_destroy) { delete :bulk_destroy, params: { customer_group_id: customer_group.to_param, ids: user_ids }, format: :turbo_stream }
let(:user1) { create(:user) }
let(:user2) { create(:user) }
diff --git a/admin/spec/controllers/spree/admin/customer_groups_controller_spec.rb b/admin/spec/controllers/spree/admin/customer_groups_controller_spec.rb
index 837e893aab..71ab59af15 100644
--- a/admin/spec/controllers/spree/admin/customer_groups_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/customer_groups_controller_spec.rb
@@ -54,7 +54,7 @@ RSpec.describe Spree::Admin::CustomerGroupsController, type: :controller do
end
describe 'GET #show' do
- subject(:show) { get :show, params: { id: customer_group.id } }
+ subject(:show) { get :show, params: { id: customer_group.to_param } }
let(:customer_group) { create(:customer_group, store: store) }
@@ -66,7 +66,7 @@ RSpec.describe Spree::Admin::CustomerGroupsController, type: :controller do
end
describe 'GET #edit' do
- subject(:edit) { get :edit, params: { id: customer_group.id } }
+ subject(:edit) { get :edit, params: { id: customer_group.to_param } }
let(:customer_group) { create(:customer_group, store: store) }
@@ -86,7 +86,7 @@ RSpec.describe Spree::Admin::CustomerGroupsController, type: :controller do
end
it 'updates the customer group' do
- put :update, params: { id: customer_group.id, customer_group: customer_group_params }
+ put :update, params: { id: customer_group.to_param, customer_group: customer_group_params }
customer_group.reload
expect(customer_group.name).to eq('Premium Customers')
@@ -94,7 +94,7 @@ RSpec.describe Spree::Admin::CustomerGroupsController, type: :controller do
end
context 'with turbo_stream format' do
- subject(:update_turbo) { put :update, params: { id: customer_group.id, customer_group: customer_group_params }, format: :turbo_stream }
+ subject(:update_turbo) { put :update, params: { id: customer_group.to_param, customer_group: customer_group_params }, format: :turbo_stream }
it 'returns turbo_stream response' do
update_turbo
@@ -120,7 +120,7 @@ RSpec.describe Spree::Admin::CustomerGroupsController, type: :controller do
end
describe 'DELETE #destroy' do
- subject(:destroy_customer_group) { delete :destroy, params: { id: customer_group.id } }
+ subject(:destroy_customer_group) { delete :destroy, params: { id: customer_group.to_param } }
let!(:customer_group) { create(:customer_group, store: store) }
diff --git a/admin/spec/controllers/spree/admin/digital_assets_controller_spec.rb b/admin/spec/controllers/spree/admin/digital_assets_controller_spec.rb
index 24f0e4af3d..85a2a887ca 100644
--- a/admin/spec/controllers/spree/admin/digital_assets_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/digital_assets_controller_spec.rb
@@ -80,7 +80,7 @@ describe Spree::Admin::DigitalAssetsController, type: :controller do
let(:params) do
{
product_id: product.slug,
- id: digital.id
+ id: digital.to_param
}
end
diff --git a/admin/spec/controllers/spree/admin/exports_controller_spec.rb b/admin/spec/controllers/spree/admin/exports_controller_spec.rb
index 3373c0f435..aa10a7e4a0 100644
--- a/admin/spec/controllers/spree/admin/exports_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/exports_controller_spec.rb
@@ -78,7 +78,7 @@ describe Spree::Admin::ExportsController, type: :controller do
end
describe '#show' do
- subject { get :show, params: { id: export.id } }
+ subject { get :show, params: { id: export.to_param } }
let(:export) { create(:product_export, store: store) }
diff --git a/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb b/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb
index 4fd3060082..f56a972ec3 100644
--- a/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/gift_cards_controller_spec.rb
@@ -19,7 +19,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
end
context 'when user_id parameter is present' do
- subject { get :index, params: { user_id: user.id } }
+ subject { get :index, params: { user_id: user.to_param } }
it 'filters gift cards by user' do
gift_card
@@ -57,7 +57,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
context 'with user_id parameter' do
it 'filters by user' do
- get :index, params: { user_id: user.id }
+ get :index, params: { user_id: user.to_param }
expect(assigns(:collection)).to include(active_gift_card, redeemed_gift_card)
expect(assigns(:collection)).not_to include(expired_gift_card)
@@ -67,7 +67,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
end
describe '#show' do
- subject { get :show, params: { id: gift_card.id } }
+ subject { get :show, params: { id: gift_card.to_param } }
it 'renders the show template' do
subject
@@ -137,7 +137,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
end
context 'when user_id parameter is present' do
- subject { get :new, params: { user_id: user.id } }
+ subject { get :new, params: { user_id: user.to_param } }
it 'loads the user' do
subject
@@ -211,7 +211,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
end
describe '#edit' do
- subject { get :edit, params: { id: gift_card.id } }
+ subject { get :edit, params: { id: gift_card.to_param } }
it 'renders the edit template' do
subject
@@ -228,7 +228,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
describe '#update' do
let(:update_params) do
{
- id: gift_card.id,
+ id: gift_card.to_param,
gift_card: {
amount: 200,
user_id: user.id,
@@ -261,7 +261,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
context 'with invalid parameters' do
let(:invalid_update_params) do
{
- id: gift_card.id,
+ id: gift_card.to_param,
gift_card: {
amount: -200
}
@@ -288,7 +288,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
describe '#destroy' do
let!(:gift_card_to_destroy) { create(:gift_card) }
- subject { delete :destroy, params: { id: gift_card_to_destroy.id } }
+ subject { delete :destroy, params: { id: gift_card_to_destroy.to_param } }
it 'destroys the gift card' do
expect { subject }.to change(Spree::GiftCard, :count).by(-1)
@@ -307,7 +307,7 @@ describe Spree::Admin::GiftCardsController, type: :controller do
context 'when user_id parameter is present' do
let!(:user_gift_card) { create(:gift_card, user: user) }
- subject { delete :destroy, params: { id: user_gift_card.id, user_id: user.id } }
+ subject { delete :destroy, params: { id: user_gift_card.to_param, user_id: user.to_param } }
it 'redirects to the user page' do
subject
diff --git a/admin/spec/controllers/spree/admin/import_rows_controller_spec.rb b/admin/spec/controllers/spree/admin/import_rows_controller_spec.rb
index dc6c134a6b..212eaf7ac3 100644
--- a/admin/spec/controllers/spree/admin/import_rows_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/import_rows_controller_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Spree::Admin::ImportRowsController, type: :controller do
describe 'GET #show' do
it 'renders the show template' do
- get :show, params: { import_id: import.number, id: import_row.id }
+ get :show, params: { import_id: import.to_param, id: import_row.to_param }
expect(response).to render_template(:show)
expect(assigns(:import)).to eq(import)
expect(assigns(:import_row)).to eq(import_row)
diff --git a/admin/spec/controllers/spree/admin/imports_controller_spec.rb b/admin/spec/controllers/spree/admin/imports_controller_spec.rb
index 6ef1749d8f..7c2080ad1f 100644
--- a/admin/spec/controllers/spree/admin/imports_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/imports_controller_spec.rb
@@ -82,7 +82,7 @@ RSpec.describe Spree::Admin::ImportsController, type: :controller do
let!(:mapping) { create(:import_mapping, import: import) }
it 'renders the show template' do
- get :show, params: { id: import.id }
+ get :show, params: { id: import.to_param }
expect(response).to render_template(:show)
expect(assigns(:import)).to eq(import)
expect(assigns(:mappings)).to eq([mapping])
@@ -94,7 +94,7 @@ RSpec.describe Spree::Admin::ImportsController, type: :controller do
let!(:incomplete_row) { create(:import_row, import: import, status: :pending) }
it 'renders the show template' do
- get :show, params: { id: import.id }
+ get :show, params: { id: import.to_param }
expect(response).to render_template(:show)
expect(assigns(:import)).to eq(import)
expect(assigns(:rows)).to eq([row])
@@ -113,7 +113,7 @@ RSpec.describe Spree::Admin::ImportsController, type: :controller do
it 'marks import as completed and redirects to show' do
expect_any_instance_of(Spree::Import).to receive(:complete_mapping!)
- put :complete_mapping, params: { id: import.id }
+ put :complete_mapping, params: { id: import.to_param }
expect(response).to redirect_to(spree.admin_import_path(import))
end
end
@@ -125,7 +125,7 @@ RSpec.describe Spree::Admin::ImportsController, type: :controller do
it 'does not mark import as completed but still redirects to show' do
expect_any_instance_of(Spree::Import).not_to receive(:complete_mapping!)
- put :complete_mapping, params: { id: import.id }
+ put :complete_mapping, params: { id: import.to_param }
expect(response).to redirect_to(spree.admin_import_path(import))
end
end
diff --git a/admin/spec/controllers/spree/admin/integrations_controller_spec.rb b/admin/spec/controllers/spree/admin/integrations_controller_spec.rb
index 578360c2e5..80b6a44184 100644
--- a/admin/spec/controllers/spree/admin/integrations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/integrations_controller_spec.rb
@@ -91,7 +91,7 @@ describe Spree::Admin::IntegrationsController, type: :controller do
let(:integration) { Spree::Integrations::DummyIntegration.create!(store: store, preferred_api_key: 'APIKEY') }
it 'updates integration' do
- put :update, params: { id: integration.id, integration: { preferred_api_key: 'NEWKEY' } }
+ put :update, params: { id: integration.to_param, integration: { preferred_api_key: 'NEWKEY' } }
expect(response).to redirect_to(spree.edit_admin_integration_path(integration))
expect(integration.reload.preferred_api_key).to eq('NEWKEY')
end
@@ -102,12 +102,12 @@ describe Spree::Admin::IntegrationsController, type: :controller do
it 'destroys the integration' do
expect {
- delete :destroy, params: { id: integration.id }
+ delete :destroy, params: { id: integration.to_param }
}.to change(Spree::Integrations::DummyIntegration, :count).by(-1)
end
it 'redirects to index with success flash' do
- delete :destroy, params: { id: integration.id }
+ delete :destroy, params: { id: integration.to_param }
expect(response).to redirect_to(spree.admin_integrations_path)
expect(flash[:success]).to be_present
end
diff --git a/admin/spec/controllers/spree/admin/invitations_controller_spec.rb b/admin/spec/controllers/spree/admin/invitations_controller_spec.rb
index 6ea89e50a9..397e884469 100644
--- a/admin/spec/controllers/spree/admin/invitations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/invitations_controller_spec.rb
@@ -138,7 +138,7 @@ RSpec.describe Spree::Admin::InvitationsController, type: :controller do
context 'when user is the invitee' do
let(:invitation) { create(:invitation, inviter: admin_user, resource: store, invitee: another_user) }
- before { get :show, params: { id: invitation.id, token: token } }
+ before { get :show, params: { id: invitation.to_param, token: token } }
it 'returns a successful response' do
expect(response).to be_successful
@@ -158,7 +158,7 @@ RSpec.describe Spree::Admin::InvitationsController, type: :controller do
context 'when user is not the invitee' do
let(:invitation) { create(:invitation, inviter: admin_user, resource: store, invitee: nil) }
- before { get :show, params: { id: invitation.id, token: token } }
+ before { get :show, params: { id: invitation.to_param, token: token } }
it 'redirects to root path' do
expect(response).to redirect_to(spree.root_path)
@@ -173,7 +173,7 @@ RSpec.describe Spree::Admin::InvitationsController, type: :controller do
context 'when user is not logged in' do
before do
allow(controller).to receive(:try_spree_current_user).and_return(nil)
- get :show, params: { id: invitation.id, token: token }
+ get :show, params: { id: invitation.to_param, token: token }
end
it 'redirects to new admin user path' do
@@ -232,7 +232,7 @@ RSpec.describe Spree::Admin::InvitationsController, type: :controller do
before do
allow(controller).to receive(:current_ability).and_return(Spree.ability_class.new(another_user))
allow(controller).to receive(:try_spree_current_user).and_return(another_user)
- put :accept, params: { id: invitation.id }
+ put :accept, params: { id: invitation.to_param }
end
it 'accepts the invitation' do
@@ -255,11 +255,11 @@ RSpec.describe Spree::Admin::InvitationsController, type: :controller do
it 'calls resend! on the invitation' do
invitation
expect_any_instance_of(Spree::Invitation).to receive(:resend!)
- put :resend, params: { id: invitation.id }
+ put :resend, params: { id: invitation.to_param }
end
it 'redirects to invitations path' do
- put :resend, params: { id: invitation.id }
+ put :resend, params: { id: invitation.to_param }
expect(response).to redirect_to(spree.admin_invitations_path)
expect(flash[:notice]).to eq(Spree.t('invitation_resent'))
end
@@ -271,17 +271,17 @@ RSpec.describe Spree::Admin::InvitationsController, type: :controller do
it 'destroys the invitation' do
invitation # ensure invitation exists
expect {
- delete :destroy, params: { id: invitation.id }
+ delete :destroy, params: { id: invitation.to_param }
}.to change(Spree::Invitation, :count).by(-1)
end
it 'redirects to invitations path' do
- delete :destroy, params: { id: invitation.id }
+ delete :destroy, params: { id: invitation.to_param }
expect(response).to redirect_to(spree.admin_invitations_path)
end
it 'sets a notice flash message' do
- delete :destroy, params: { id: invitation.id }
+ delete :destroy, params: { id: invitation.to_param }
expect(flash[:notice]).not_to be_nil
end
end
diff --git a/admin/spec/controllers/spree/admin/json_previews_controller_spec.rb b/admin/spec/controllers/spree/admin/json_previews_controller_spec.rb
index 736b74e445..7162895e52 100644
--- a/admin/spec/controllers/spree/admin/json_previews_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/json_previews_controller_spec.rb
@@ -17,7 +17,7 @@ RSpec.describe Spree::Admin::JsonPreviewsController, type: :controller do
context 'when resource_type is missing' do
it 'raises ActiveRecord::RecordNotFound' do
expect {
- get :show, params: { id: product.id, resource_type: '' }
+ get :show, params: { id: product.to_param, resource_type: '' }
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/admin/spec/controllers/spree/admin/line_items_controller_spec.rb b/admin/spec/controllers/spree/admin/line_items_controller_spec.rb
index aa66c96dc3..53f9efaa48 100644
--- a/admin/spec/controllers/spree/admin/line_items_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/line_items_controller_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Spree::Admin::LineItemsController, type: :controller do
describe '#new' do
it 'returns a success response' do
- get :new, params: { order_id: order.number }
+ get :new, params: { order_id: order.to_param }
expect(response).to render_template(:new)
end
end
@@ -20,7 +20,7 @@ RSpec.describe Spree::Admin::LineItemsController, type: :controller do
let(:product) { create(:product_in_stock, stores: [store]) }
it 'returns a success response' do
- post :create, params: { order_id: order.number, line_item: { variant_id: product.default_variant.id, quantity: 1 } }
+ post :create, params: { order_id: order.to_param, line_item: { variant_id: product.default_variant.id, quantity: 1 } }
expect(response).to redirect_to(spree.edit_admin_order_path(order, line_item_updated: true))
expect(order.line_items.count).to eq(1)
end
@@ -33,7 +33,7 @@ RSpec.describe Spree::Admin::LineItemsController, type: :controller do
end
it 'returns a success response' do
- post :create, params: { order_id: order.number, line_item: { variant_id: product.default_variant.id, quantity: 1 } }
+ post :create, params: { order_id: order.to_param, line_item: { variant_id: product.default_variant.id, quantity: 1 } }
line_items = order.line_items.last
expect(line_items.price).to eq(89)
@@ -44,21 +44,21 @@ RSpec.describe Spree::Admin::LineItemsController, type: :controller do
describe '#edit' do
it 'returns a success response' do
- get :edit, params: { id: line_item.id, order_id: order.number }
+ get :edit, params: { id: line_item.to_param, order_id: order.to_param }
expect(response).to render_template(:edit)
end
end
describe '#update' do
it 'returns a success response' do
- put :update, params: { id: line_item.id, order_id: order.number, line_item: { quantity: 2 } }
+ put :update, params: { id: line_item.to_param, order_id: order.to_param, line_item: { quantity: 2 } }
expect(response).to redirect_to(spree.edit_admin_order_path(order, line_item_updated: true))
end
end
describe '#destroy' do
it 'returns a success response' do
- delete :destroy, params: { id: line_item.id, order_id: order.number }
+ delete :destroy, params: { id: line_item.to_param, order_id: order.to_param }
expect(response).to redirect_to(spree.edit_admin_order_path(order, line_item_updated: true))
end
end
diff --git a/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb b/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb
index 383b2063ea..73df1e710d 100644
--- a/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/metafield_definitions_controller_spec.rb
@@ -77,7 +77,7 @@ RSpec.describe Spree::Admin::MetafieldDefinitionsController, type: :controller d
describe 'GET #edit' do
it 'renders the edit template' do
- get :edit, params: { id: metafield_definition.id }
+ get :edit, params: { id: metafield_definition.to_param }
expect(response).to render_template(:edit)
expect(assigns(:object)).to eq(metafield_definition)
end
@@ -86,7 +86,7 @@ RSpec.describe Spree::Admin::MetafieldDefinitionsController, type: :controller d
describe 'PUT #update' do
context 'with valid params' do
it 'updates the MetafieldDefinition and redirects' do
- put :update, params: { id: metafield_definition.id, metafield_definition: { name: 'Size' } }
+ put :update, params: { id: metafield_definition.to_param, metafield_definition: { name: 'Size' } }
expect(response).to redirect_to(spree.admin_metafield_definitions_path)
expect(assigns(:object).reload.name).to eq('Size')
expect(flash[:success]).to be_present
@@ -95,7 +95,7 @@ RSpec.describe Spree::Admin::MetafieldDefinitionsController, type: :controller d
context 'with invalid params' do
it 'does not update and re-renders edit' do
- put :update, params: { id: metafield_definition.id, metafield_definition: { name: '' } }
+ put :update, params: { id: metafield_definition.to_param, metafield_definition: { name: '' } }
expect(response).to render_template(:edit)
expect(response).to have_http_status(:unprocessable_entity)
expect(assigns(:object).reload.name).not_to eq('')
@@ -107,7 +107,7 @@ RSpec.describe Spree::Admin::MetafieldDefinitionsController, type: :controller d
it 'destroys the MetafieldDefinition and redirects' do
metafield = create(:metafield_definition, :short_text_field)
expect {
- delete :destroy, params: { id: metafield.id }
+ delete :destroy, params: { id: metafield.to_param }
}.to change(Spree::MetafieldDefinition, :count).by(-1)
expect(response).to redirect_to(spree.admin_metafield_definitions_path)
expect(flash[:success]).to be_present
diff --git a/admin/spec/controllers/spree/admin/metafields_controller_spec.rb b/admin/spec/controllers/spree/admin/metafields_controller_spec.rb
index c6c3b4a835..371e87d012 100644
--- a/admin/spec/controllers/spree/admin/metafields_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/metafields_controller_spec.rb
@@ -42,7 +42,7 @@ RSpec.describe Spree::Admin::MetafieldsController, type: :controller do
context 'when resource_type is missing' do
it 'raises ActiveRecord::RecordNotFound' do
expect {
- get :edit, params: { id: product.id, resource_type: '' }
+ get :edit, params: { id: product.to_param, resource_type: '' }
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -110,7 +110,7 @@ RSpec.describe Spree::Admin::MetafieldsController, type: :controller do
context 'when resource_type is missing' do
it 'raises ActiveRecord::RecordNotFound' do
expect {
- put :update, format: :turbo_stream, params: { id: product.id, resource_type: '', product: metafield_attributes }
+ put :update, format: :turbo_stream, params: { id: product.to_param, resource_type: '', product: metafield_attributes }
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -118,7 +118,7 @@ RSpec.describe Spree::Admin::MetafieldsController, type: :controller do
context 'when resource_type is invalid' do
it 'raises ActiveRecord::RecordNotFound' do
expect {
- put :update, format: :turbo_stream, params: { resource_type: 'InvalidType', id: product.id, product: metafield_attributes }
+ put :update, format: :turbo_stream, params: { resource_type: 'InvalidType', id: product.to_param, product: metafield_attributes }
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/admin/spec/controllers/spree/admin/newsletter_subscribers_controller_spec.rb b/admin/spec/controllers/spree/admin/newsletter_subscribers_controller_spec.rb
index 9fc46131b7..b114b0189d 100644
--- a/admin/spec/controllers/spree/admin/newsletter_subscribers_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/newsletter_subscribers_controller_spec.rb
@@ -20,7 +20,7 @@ RSpec.describe Spree::Admin::NewsletterSubscribersController, type: :controller
it 'destroys the newsletter subscriber and redirects' do
expect {
- delete :destroy, params: { id: newsletter_subscriber.id }
+ delete :destroy, params: { id: newsletter_subscriber.to_param }
}.to change(Spree::NewsletterSubscriber, :count).by(-1)
expect(response).to redirect_to(admin_newsletter_subscribers_path)
end
diff --git a/admin/spec/controllers/spree/admin/option_types_controller_spec.rb b/admin/spec/controllers/spree/admin/option_types_controller_spec.rb
index 6c42064fad..be5541168c 100644
--- a/admin/spec/controllers/spree/admin/option_types_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/option_types_controller_spec.rb
@@ -62,12 +62,12 @@ describe Spree::Admin::OptionTypesController, type: :controller do
let!(:option_type) { create(:option_type) }
it 'responds successfully' do
- get :edit, params: { id: option_type.id }
+ get :edit, params: { id: option_type.to_param }
expect(response).to be_successful
end
it 'builds a new option value if none exist' do
- get :edit, params: { id: option_type.id }
+ get :edit, params: { id: option_type.to_param }
expect(assigns(:option_type).option_values.select(&:new_record?).count).to eq(1)
end
end
@@ -77,7 +77,7 @@ describe Spree::Admin::OptionTypesController, type: :controller do
let!(:option_value) { create(:option_value, option_type: option_type, position: 1) }
let(:params) do
{
- id: option_type.id,
+ id: option_type.to_param,
option_type: {
name: 'updated-name',
presentation: 'Updated Name',
@@ -124,12 +124,12 @@ describe Spree::Admin::OptionTypesController, type: :controller do
it 'destroys the option type' do
expect {
- delete :destroy, params: { id: option_type.id }
+ delete :destroy, params: { id: option_type.to_param }
}.to change(Spree::OptionType, :count).by(-1)
end
it 'redirects to index with success flash' do
- delete :destroy, params: { id: option_type.id }
+ delete :destroy, params: { id: option_type.to_param }
expect(response).to redirect_to(spree.admin_option_types_path)
expect(flash[:success]).to be_present
end
diff --git a/admin/spec/controllers/spree/admin/option_values_controller_spec.rb b/admin/spec/controllers/spree/admin/option_values_controller_spec.rb
index 010e368826..d09bda8433 100644
--- a/admin/spec/controllers/spree/admin/option_values_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/option_values_controller_spec.rb
@@ -18,8 +18,8 @@ RSpec.describe Spree::Admin::OptionValuesController do
before do
patch :update, params: {
- option_type_id: option_type.id,
- id: option_value.id,
+ option_type_id: option_type.to_param,
+ id: option_value.to_param,
option_value: option_value_params,
format: :turbo_stream
}
@@ -40,7 +40,7 @@ RSpec.describe Spree::Admin::OptionValuesController do
before do
option_value
create_list(:option_value, 3, option_type: option_type)
- get :select_options, params: { option_type_id: option_type.id, format: :json }
+ get :select_options, params: { option_type_id: option_type.to_param, format: :json }
end
it 'returns success status' do
diff --git a/admin/spec/controllers/spree/admin/orders/adjustments_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/adjustments_controller_spec.rb
index ae2e9c63c6..4f3c476b50 100644
--- a/admin/spec/controllers/spree/admin/orders/adjustments_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders/adjustments_controller_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
let(:order) { create(:order_with_line_items, store: store) }
describe '#new' do
- subject { get :new, params: { order_id: order.number } }
+ subject { get :new, params: { order_id: order.to_param } }
it 'returns a success response' do
subject
@@ -21,7 +21,7 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
let(:adjustment_params) { { label: 'Test Adjustment', amount: -10.00 } }
context 'with turbo_stream format' do
- subject { post :create, params: { order_id: order.number, adjustment: adjustment_params }, format: :turbo_stream }
+ subject { post :create, params: { order_id: order.to_param, adjustment: adjustment_params }, format: :turbo_stream }
it 'creates a new adjustment on order' do
expect { subject }.to change { order.adjustments.reload.count }.by(1)
@@ -35,7 +35,7 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
end
describe '#edit' do
- subject { get :edit, params: { order_id: order.number, id: adjustment.id } }
+ subject { get :edit, params: { order_id: order.to_param, id: adjustment.to_param } }
let(:adjustment) { create(:adjustment, adjustable: order, order: order, label: 'Manual', amount: -5) }
@@ -51,7 +51,7 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
let(:update_params) { { label: 'Updated Label', amount: -15.00 } }
context 'with turbo_stream format' do
- subject { put :update, params: { order_id: order.number, id: adjustment.id, adjustment: update_params }, format: :turbo_stream }
+ subject { put :update, params: { order_id: order.to_param, id: adjustment.to_param, adjustment: update_params }, format: :turbo_stream }
it 'updates the adjustment' do
subject
@@ -70,7 +70,7 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
let!(:adjustment) { create(:adjustment, adjustable: order, order: order, label: 'Manual', amount: -5) }
context 'with turbo_stream format' do
- subject { delete :destroy, params: { order_id: order.number, id: adjustment.id }, format: :turbo_stream }
+ subject { delete :destroy, params: { order_id: order.to_param, id: adjustment.to_param }, format: :turbo_stream }
it 'destroys the adjustment' do
expect { subject }.to change { Spree::Adjustment.count }.by(-1)
@@ -88,7 +88,7 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
let(:adjustment) { create(:adjustment, adjustable: order, order: order, label: 'Manual', amount: -5, state: 'open') }
it 'closes the adjustment' do
- put :toggle_state, params: { order_id: order.number, id: adjustment.id }
+ put :toggle_state, params: { order_id: order.to_param, id: adjustment.to_param }
adjustment.reload
expect(adjustment.state).to eq('closed')
end
@@ -98,7 +98,7 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
let(:adjustment) { create(:adjustment, adjustable: order, order: order, label: 'Manual', amount: -5, state: 'closed') }
it 'opens the adjustment' do
- put :toggle_state, params: { order_id: order.number, id: adjustment.id }
+ put :toggle_state, params: { order_id: order.to_param, id: adjustment.to_param }
adjustment.reload
expect(adjustment.state).to eq('open')
end
@@ -106,13 +106,13 @@ RSpec.describe Spree::Admin::Orders::AdjustmentsController do
it 'redirects to order edit page with HTML format' do
adjustment = create(:adjustment, adjustable: order, order: order, label: 'Manual', amount: -5)
- put :toggle_state, params: { order_id: order.number, id: adjustment.id }
+ put :toggle_state, params: { order_id: order.to_param, id: adjustment.to_param }
expect(response).to redirect_to(spree.edit_admin_order_path(order))
end
it 'responds with turbo_stream format' do
adjustment = create(:adjustment, adjustable: order, order: order, label: 'Manual', amount: -5)
- put :toggle_state, params: { order_id: order.number, id: adjustment.id }, format: :turbo_stream
+ put :toggle_state, params: { order_id: order.to_param, id: adjustment.to_param }, format: :turbo_stream
expect(response.media_type).to eq('text/vnd.turbo-stream.html')
end
end
diff --git a/admin/spec/controllers/spree/admin/orders/customer_returns_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/customer_returns_controller_spec.rb
index c4cfb9c7ac..afcb6b00c9 100644
--- a/admin/spec/controllers/spree/admin/orders/customer_returns_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders/customer_returns_controller_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Spree::Admin::Orders::CustomerReturnsController do
let!(:return_item) { create(:return_item, return_authorization: return_authorization, inventory_unit: order.inventory_units.shipped.first) }
describe '#new' do
- subject { get :new, params: { order_id: order.number } }
+ subject { get :new, params: { order_id: order.to_param } }
before { subject }
@@ -25,7 +25,7 @@ RSpec.describe Spree::Admin::Orders::CustomerReturnsController do
describe '#create' do
subject do
post :create, params: {
- order_id: order.number,
+ order_id: order.to_param,
customer_return: {
stock_location_id: order.shipments.first.stock_location.id,
return_items_attributes: {
@@ -59,7 +59,7 @@ RSpec.describe Spree::Admin::Orders::CustomerReturnsController do
end
describe '#edit' do
- subject { get :edit, params: { order_id: order.number, id: customer_return.id } }
+ subject { get :edit, params: { order_id: order.to_param, id: customer_return.to_param } }
let(:customer_return) { create(:customer_return_without_return_items, return_items: [return_item]) }
@@ -82,8 +82,8 @@ RSpec.describe Spree::Admin::Orders::CustomerReturnsController do
describe '#update' do
subject do
put :update, params: {
- order_id: order.number,
- id: customer_return.id,
+ order_id: order.to_param,
+ id: customer_return.to_param,
customer_return: {
return_items_attributes: {
1 => {
diff --git a/admin/spec/controllers/spree/admin/orders/order_promotions_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/order_promotions_controller_spec.rb
index 2d426454dc..1ceaf62096 100644
--- a/admin/spec/controllers/spree/admin/orders/order_promotions_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders/order_promotions_controller_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Spree::Admin::Orders::OrderPromotionsController do
let(:order) { create(:order_with_line_items, store: store) }
describe '#new' do
- subject { get :new, params: { order_id: order.number } }
+ subject { get :new, params: { order_id: order.to_param } }
it 'returns a success response' do
subject
@@ -18,7 +18,7 @@ RSpec.describe Spree::Admin::Orders::OrderPromotionsController do
end
describe '#create' do
- subject { post :create, params: { order_id: order.number, coupon_code: coupon_code }, format: :turbo_stream }
+ subject { post :create, params: { order_id: order.to_param, coupon_code: coupon_code }, format: :turbo_stream }
context 'with valid coupon code' do
let(:promotion) { create(:promotion, :with_order_adjustment, code: 'TESTCODE', stores: [store]) }
@@ -75,7 +75,7 @@ RSpec.describe Spree::Admin::Orders::OrderPromotionsController do
end
describe '#destroy' do
- subject { delete :destroy, params: { order_id: order.number, id: order_promotion.id }, format: :turbo_stream }
+ subject { delete :destroy, params: { order_id: order.to_param, id: order_promotion.id }, format: :turbo_stream }
context 'with valid applied promotion' do
let(:promotion) { create(:promotion, :with_order_adjustment, code: 'REMOVE', stores: [store]) }
diff --git a/admin/spec/controllers/spree/admin/orders/payment_links_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/payment_links_controller_spec.rb
index a331397c6c..3457cec9c5 100644
--- a/admin/spec/controllers/spree/admin/orders/payment_links_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders/payment_links_controller_spec.rb
@@ -7,7 +7,7 @@ RSpec.describe Spree::Admin::Orders::PaymentLinksController, type: :controller d
let(:order) { create(:order_with_line_items, state: 'payment') }
describe 'POST #create' do
- subject { post :create, params: { order_id: order.number } }
+ subject { post :create, params: { order_id: order.to_param } }
context 'when frontend is available' do
let(:payment_url) { "http://shop.com/checkout/#{order.token}/payment" }
diff --git a/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb
index c5b796d064..5a23543a94 100644
--- a/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders/return_authorizations_controller_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
let!(:reimbursement_type) { create(:reimbursement_type) }
describe '#new' do
- subject { get :new, params: { order_id: order.number } }
+ subject { get :new, params: { order_id: order.to_param } }
before { subject }
@@ -29,7 +29,7 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
describe '#create' do
subject do
post :create, params: {
- order_id: order.number,
+ order_id: order.to_param,
return_authorization: {
memo: 'Test memo',
return_authorization_reason_id: reason.id,
@@ -64,7 +64,7 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
end
describe '#edit' do
- subject { get :edit, params: { order_id: order.number, id: return_authorization.id } }
+ subject { get :edit, params: { order_id: order.to_param, id: return_authorization.to_param } }
before { subject }
@@ -87,8 +87,8 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
let(:params) do
{
- order_id: order.number,
- id: return_authorization.id,
+ order_id: order.to_param,
+ id: return_authorization.to_param,
return_authorization: {
memo: 'Updated memo',
return_items_attributes: {
@@ -117,8 +117,8 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
context 'when _destroy is set to true' do
let(:params) do
{
- order_id: order.number,
- id: return_authorization.id,
+ order_id: order.to_param,
+ id: return_authorization.to_param,
return_authorization: { return_items_attributes: { '0' => { id: return_item.id, _destroy: true } } }
}
end
@@ -132,7 +132,7 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
end
describe '#show' do
- subject { get :show, params: { order_id: order.number, id: return_authorization.id } }
+ subject { get :show, params: { order_id: order.to_param, id: return_authorization.to_param } }
before { subject }
@@ -142,7 +142,7 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
end
describe '#load_return_authorization_reasons' do
- subject { get :new, params: { order_id: order.number } }
+ subject { get :new, params: { order_id: order.to_param } }
let!(:active_reason) { create(:return_authorization_reason) }
let!(:inactive_reason) { create(:return_authorization_reason, active: false) }
@@ -159,7 +159,7 @@ RSpec.describe Spree::Admin::Orders::ReturnAuthorizationsController do
end
it 'includes the inactive reason when editing' do
- get :edit, params: { order_id: order.number, id: return_authorization.id }
+ get :edit, params: { order_id: order.to_param, id: return_authorization.to_param }
expect(assigns(:reasons)).to include(active_reason)
expect(assigns(:reasons)).to include(inactive_reason)
end
diff --git a/admin/spec/controllers/spree/admin/orders/user_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/user_controller_spec.rb
index 21408e94d1..1085370d85 100644
--- a/admin/spec/controllers/spree/admin/orders/user_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders/user_controller_spec.rb
@@ -19,7 +19,7 @@ RSpec.describe Spree::Admin::Orders::UserController, type: :controller do
let!(:existing_user) { create(:user, email: user_params[:email]) }
it 'updates user with new details' do
- post :create, params: { user: user_params, order_id: order.number }, as: :turbo_stream
+ post :create, params: { user: user_params, order_id: order.to_param }, as: :turbo_stream
expect(order.reload.user).to eq(existing_user)
expect(order.email).to eq(existing_user.email)
@@ -33,7 +33,7 @@ RSpec.describe Spree::Admin::Orders::UserController, type: :controller do
context 'when user does not exist' do
it 'saves user' do
- post :create, params: { user: user_params, order_id: order.number }, as: :turbo_stream
+ post :create, params: { user: user_params, order_id: order.to_param }, as: :turbo_stream
new_user = Spree.user_class.find_by(email: user_params[:email])
@@ -52,7 +52,7 @@ RSpec.describe Spree::Admin::Orders::UserController, type: :controller do
let!(:existing_user) { create(:user, email: user_params[:email]) }
it 'associates new user with order' do
- put :update, params: { user_id: existing_user.id, order_id: order.number }, as: :turbo_stream
+ put :update, params: { user_id: existing_user.to_param, order_id: order.to_param }, as: :turbo_stream
expect(order.reload.user).to eq(existing_user)
expect(order.email).to eq(existing_user.email)
@@ -60,7 +60,7 @@ RSpec.describe Spree::Admin::Orders::UserController, type: :controller do
end
describe '#destroy' do
- subject { delete :destroy, params: { order_id: order.number }, as: :turbo_stream }
+ subject { delete :destroy, params: { order_id: order.to_param }, as: :turbo_stream }
let!(:existing_user) { create(:user, email: user_params[:email]) }
diff --git a/admin/spec/controllers/spree/admin/orders_controller_spec.rb b/admin/spec/controllers/spree/admin/orders_controller_spec.rb
index 2f8aabbb08..0aa57c4b9a 100644
--- a/admin/spec/controllers/spree/admin/orders_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/orders_controller_spec.rb
@@ -188,7 +188,7 @@ RSpec.describe Spree::Admin::OrdersController, type: :controller do
end
describe '#edit' do
- subject { get :edit, params: { id: order.number } }
+ subject { get :edit, params: { id: order.to_param } }
let(:order) { create(:order_ready_to_ship, total: 100, with_payment: false, store: store) }
it 'redirects to the show page' do
subject
@@ -197,7 +197,7 @@ RSpec.describe Spree::Admin::OrdersController, type: :controller do
end
describe '#show' do
- subject { get :show, params: { id: order.number } }
+ subject { get :show, params: { id: order.to_param } }
let(:order) { create(:order_ready_to_ship, total: 100, with_payment: false, store: store) }
@@ -233,7 +233,7 @@ RSpec.describe Spree::Admin::OrdersController, type: :controller do
end
describe '#cancel' do
- subject(:cancel) { put :cancel, params: { id: order.number } }
+ subject(:cancel) { put :cancel, params: { id: order.to_param } }
let(:order) { create(:order_ready_to_ship, store: store) }
@@ -247,7 +247,7 @@ RSpec.describe Spree::Admin::OrdersController, type: :controller do
end
describe '#resend' do
- subject { put :resend, params: { id: order.number } }
+ subject { put :resend, params: { id: order.to_param } }
context 'for a complete order' do
let(:order) { create(:order_ready_to_ship, store: store) }
@@ -269,7 +269,7 @@ RSpec.describe Spree::Admin::OrdersController, type: :controller do
end
describe '#destroy' do
- subject { delete :destroy, params: { id: order.number } }
+ subject { delete :destroy, params: { id: order.to_param } }
context 'for a completed order' do
let!(:order) { create(:order_ready_to_ship, with_payment: true, store: store) }
@@ -299,7 +299,7 @@ RSpec.describe Spree::Admin::OrdersController, type: :controller do
context 'updating internal_note' do
subject do
- put :update, params: { id: order.number, order: { internal_note: internal_note_content } }, format: :turbo_stream
+ put :update, params: { id: order.to_param, order: { internal_note: internal_note_content } }, format: :turbo_stream
end
let(:internal_note_content) { 'This is a test internal note for the order.' }
diff --git a/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rb
index 79f4235a98..1f04ef8db6 100644
--- a/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rb
@@ -66,7 +66,7 @@ describe Spree::Admin::PaymentMethodsController, type: :controller do
end
describe '#update' do
- subject { put :update, params: { id: payment_method.id, payment_method: payment_method_params } }
+ subject { put :update, params: { id: payment_method.to_param, payment_method: payment_method_params } }
let(:payment_method) { create(:credit_card_payment_method) }
let(:payment_method_params) do
diff --git a/admin/spec/controllers/spree/admin/payments_controller_spec.rb b/admin/spec/controllers/spree/admin/payments_controller_spec.rb
index 3e067e1bdd..90c4f2adc5 100644
--- a/admin/spec/controllers/spree/admin/payments_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/payments_controller_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
describe 'PUT #capture' do
subject { put :capture, params: params }
- let(:params) { { order_id: order.number, id: payment.id } }
+ let(:params) { { order_id: order.to_param, id: payment.to_param } }
let(:payment) { create(:payment, order: order, payment_method: payment_method, amount: order.total) }
it 'captures unprocessed payment' do
@@ -37,7 +37,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
describe 'PUT #void' do
subject { put :void, params: params }
- let(:params) { { order_id: order.number, id: payment.id } }
+ let(:params) { { order_id: order.to_param, id: payment.to_param } }
let(:payment) { create(:payment, order: order, payment_method: payment_method, amount: order.total, state: 'completed') }
it 'voids completed payment' do
@@ -65,7 +65,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
describe 'GET #new' do
subject { get :new, params: params }
- let(:params) { { order_id: order.number } }
+ let(:params) { { order_id: order.to_param } }
context 'when order can transition to payment state' do
let(:order) { create(:order_ready_to_ship, state: 'delivery') }
@@ -79,7 +79,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
context 'when specific payment method is requested' do
let(:specific_payment_method) { create(:credit_card_payment_method, display_on: 'back_end') }
- let(:params) { { order_id: order.number, payment_method_id: specific_payment_method.id } }
+ let(:params) { { order_id: order.to_param, payment_method_id: specific_payment_method.id } }
before do
create(:credit_card_payment_method, display_on: 'back_end')
@@ -106,7 +106,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
context 'when payment method requires source' do
let(:payment_method) { create(:credit_card_payment_method, display_on: 'back_end') }
- let(:params) { { order_id: order.number, payment_method_id: payment_method.id } }
+ let(:params) { { order_id: order.to_param, payment_method_id: payment_method.id } }
it 'builds a new source' do
subject
@@ -116,7 +116,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
context 'when payment method does not require source' do
let(:payment_method) { create(:check_payment_method, display_on: 'back_end') }
- let(:params) { { order_id: order.number, payment_method_id: payment_method.id } }
+ let(:params) { { order_id: order.to_param, payment_method_id: payment_method.id } }
it 'does not build a source' do
subject
@@ -134,7 +134,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
end
context 'with invalid params' do
- let(:params) { { order_id: order.number, payment: { amount: order.total, payment_method_id: payment_method.id.to_s } } }
+ let(:params) { { order_id: order.to_param, payment: { amount: order.total, payment_method_id: payment_method.id.to_s } } }
it 'does not create a payment' do
subject
@@ -149,7 +149,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
context 'with a valid credit card' do
let(:params) do
{
- order_id: order.number,
+ order_id: order.to_param,
card: 'new',
payment: {
amount: order.total,
@@ -178,7 +178,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
let(:params) do
{
- order_id: order.number,
+ order_id: order.to_param,
payment: {
amount: order.total,
payment_method_id: payment_method.id.to_s,
@@ -203,7 +203,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
context 'with an invalid credit card' do
let(:params) do
{
- order_id: order.number,
+ order_id: order.to_param,
card: 'new',
payment: {
amount: order.total,
@@ -236,7 +236,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
let(:params) do
{
- order_id: order.number,
+ order_id: order.to_param,
card: 'new',
payment: {
amount: order.total,
@@ -267,7 +267,7 @@ RSpec.describe Spree::Admin::PaymentsController, type: :controller do
let(:params) do
{
- order_id: order.number,
+ order_id: order.to_param,
payment: {
amount: '12.34',
payment_method_id: payment_method.id.to_s,
diff --git a/admin/spec/controllers/spree/admin/policies_controller_spec.rb b/admin/spec/controllers/spree/admin/policies_controller_spec.rb
index 9e451a6946..854945bc79 100644
--- a/admin/spec/controllers/spree/admin/policies_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/policies_controller_spec.rb
@@ -66,7 +66,7 @@ RSpec.describe Spree::Admin::PoliciesController, type: :controller do
end
describe 'GET #edit' do
- subject(:edit) { get :edit, params: { id: policy.id } }
+ subject(:edit) { get :edit, params: { id: policy.to_param } }
let(:policy) { create(:policy, owner: store) }
@@ -77,7 +77,7 @@ RSpec.describe Spree::Admin::PoliciesController, type: :controller do
end
describe 'PUT #update' do
- subject(:update_policy) { put :update, params: { id: policy.id, policy: policy_params } }
+ subject(:update_policy) { put :update, params: { id: policy.to_param, policy: policy_params } }
let!(:policy) { create(:policy, owner: store) }
let(:policy_params) do
@@ -100,7 +100,7 @@ RSpec.describe Spree::Admin::PoliciesController, type: :controller do
end
describe 'DELETE #destroy' do
- subject(:destroy_policy) { delete :destroy, params: { id: policy.id } }
+ subject(:destroy_policy) { delete :destroy, params: { id: policy.to_param } }
let!(:policy) { create(:policy, owner: store) }
diff --git a/admin/spec/controllers/spree/admin/post_categories_controller_spec.rb b/admin/spec/controllers/spree/admin/post_categories_controller_spec.rb
index 7499536144..be8c57dbd8 100644
--- a/admin/spec/controllers/spree/admin/post_categories_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/post_categories_controller_spec.rb
@@ -74,7 +74,7 @@ RSpec.describe Spree::Admin::PostCategoriesController, type: :controller do
end
describe 'GET #edit' do
- subject(:edit) { get :edit, params: { id: post_category.id } }
+ subject(:edit) { get :edit, params: { id: post_category.to_param } }
let(:post_category) { create(:post_category) }
@@ -85,7 +85,7 @@ RSpec.describe Spree::Admin::PostCategoriesController, type: :controller do
end
describe 'PUT #update' do
- subject(:update_category) { put :update, params: { id: post_category.id, post_category: post_category_params } }
+ subject(:update_category) { put :update, params: { id: post_category.to_param, post_category: post_category_params } }
let!(:post_category) { create(:post_category, store: store) }
let(:post_category_params) do
@@ -107,7 +107,7 @@ RSpec.describe Spree::Admin::PostCategoriesController, type: :controller do
end
describe 'DELETE #destroy' do
- subject(:destroy_category) { delete :destroy, params: { id: post_category.id } }
+ subject(:destroy_category) { delete :destroy, params: { id: post_category.to_param } }
let!(:post_category) { create(:post_category, store: store) }
diff --git a/admin/spec/controllers/spree/admin/posts_controller_spec.rb b/admin/spec/controllers/spree/admin/posts_controller_spec.rb
index 23bdf89be5..ce2b519437 100644
--- a/admin/spec/controllers/spree/admin/posts_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/posts_controller_spec.rb
@@ -88,7 +88,7 @@ RSpec.describe Spree::Admin::PostsController, type: :controller do
end
describe 'GET #edit' do
- subject(:edit) { get :edit, params: { id: post.id } }
+ subject(:edit) { get :edit, params: { id: post.to_param } }
let(:post) { create(:post) }
@@ -99,7 +99,7 @@ RSpec.describe Spree::Admin::PostsController, type: :controller do
end
describe 'PUT #update' do
- subject(:update_post) { put :update, params: { id: post.id, post: post_params } }
+ subject(:update_post) { put :update, params: { id: post.to_param, post: post_params } }
let!(:post) { create(:post, store: store) }
let(:post_params) do
@@ -136,7 +136,7 @@ RSpec.describe Spree::Admin::PostsController, type: :controller do
end
describe 'DELETE #destroy' do
- subject(:destroy_post) { delete :destroy, params: { id: post.id } }
+ subject(:destroy_post) { delete :destroy, params: { id: post.to_param } }
let!(:post) { create(:post, store: store) }
diff --git a/admin/spec/controllers/spree/admin/price_list_products_controller_spec.rb b/admin/spec/controllers/spree/admin/price_list_products_controller_spec.rb
index 4ad6dee75c..2d52e99fa1 100644
--- a/admin/spec/controllers/spree/admin/price_list_products_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/price_list_products_controller_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
let(:price_list) { create(:price_list, store: store) }
describe 'GET #index' do
- subject(:index) { get :index, params: { price_list_id: price_list.id } }
+ subject(:index) { get :index, params: { price_list_id: price_list.to_param } }
let(:product1) { create(:product, stores: [store]) }
let(:product2) { create(:product, stores: [store]) }
@@ -29,7 +29,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
end
describe 'GET #bulk_new' do
- subject(:bulk_new_action) { get :bulk_new, params: { price_list_id: price_list.id } }
+ subject(:bulk_new_action) { get :bulk_new, params: { price_list_id: price_list.to_param } }
it 'renders the new products drawer' do
bulk_new_action
@@ -52,7 +52,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
let(:params) do
{
- price_list_id: price_list.id,
+ price_list_id: price_list.to_param,
ids: [product1.id, product2.id]
}
end
@@ -109,7 +109,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
let(:params) do
{
- price_list_id: price_list.id,
+ price_list_id: price_list.to_param,
ids: [product_with_variants.id]
}
end
@@ -125,7 +125,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
let(:params) do
{
- price_list_id: price_list.id,
+ price_list_id: price_list.to_param,
ids: [product_master_only.id]
}
end
@@ -140,7 +140,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
end
context 'with empty ids' do
- let(:params) { { price_list_id: price_list.id, ids: [] } }
+ let(:params) { { price_list_id: price_list.to_param, ids: [] } }
it 'does not create any prices' do
expect { bulk_create }.not_to change(Spree::Price.for_price_list(price_list), :count)
@@ -160,7 +160,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
let(:params) do
{
- price_list_id: price_list.id,
+ price_list_id: price_list.to_param,
ids: [product1.id, product2.id]
}
end
@@ -184,7 +184,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
let(:params) do
{
- price_list_id: price_list.id,
+ price_list_id: price_list.to_param,
ids: [product_with_variants.id]
}
end
@@ -195,7 +195,7 @@ RSpec.describe Spree::Admin::PriceListProductsController, type: :controller do
end
context 'with empty ids' do
- let(:params) { { price_list_id: price_list.id, ids: [] } }
+ let(:params) { { price_list_id: price_list.to_param, ids: [] } }
it 'does not remove any prices' do
expect { bulk_destroy }.not_to change(Spree::Price.for_price_list(price_list), :count)
diff --git a/admin/spec/controllers/spree/admin/price_lists_controller_spec.rb b/admin/spec/controllers/spree/admin/price_lists_controller_spec.rb
index 7edb37e7a1..6c38dcae25 100644
--- a/admin/spec/controllers/spree/admin/price_lists_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/price_lists_controller_spec.rb
@@ -21,7 +21,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
end
describe 'GET #show' do
- subject(:show) { get :show, params: { id: price_list.id } }
+ subject(:show) { get :show, params: { id: price_list.to_param } }
it 'renders the show page' do
show
@@ -41,7 +41,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
end
describe 'GET #edit_prices' do
- subject(:edit_prices) { get :edit_prices, params: { id: price_list.id, currency: currency } }
+ subject(:edit_prices) { get :edit_prices, params: { id: price_list.to_param, currency: currency } }
let(:currency) { 'USD' }
let(:product) { create(:product, stores: [store]) }
@@ -69,7 +69,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
end
context 'without currency param' do
- subject(:edit_prices) { get :edit_prices, params: { id: price_list.id } }
+ subject(:edit_prices) { get :edit_prices, params: { id: price_list.to_param } }
it 'uses the store default currency' do
edit_prices
@@ -88,7 +88,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
let(:params) do
{
- id: price_list.id,
+ id: price_list.to_param,
price_list: {
prices_attributes: {
'0' => {
@@ -130,7 +130,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
let(:params) do
{
- id: price_list.id,
+ id: price_list.to_param,
price_list: {
prices_attributes: {
'0' => { id: price.id, variant_id: variant.id, currency: 'USD', amount: '25.99' },
@@ -153,7 +153,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
context 'when setting amount to blank on existing price' do
let(:params) do
{
- id: price_list.id,
+ id: price_list.to_param,
price_list: {
prices_attributes: {
'0' => { id: price.id, variant_id: variant.id, currency: 'USD', amount: '' }
@@ -172,7 +172,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
end
describe 'PUT #activate' do
- subject(:activate) { put :activate, params: { id: price_list.id } }
+ subject(:activate) { put :activate, params: { id: price_list.to_param } }
context 'when price list has no starts_at' do
let(:price_list) { create(:price_list, store: store, status: 'draft', starts_at: nil) }
@@ -234,7 +234,7 @@ RSpec.describe Spree::Admin::PriceListsController, type: :controller do
end
describe 'PUT #deactivate' do
- subject(:deactivate) { put :deactivate, params: { id: price_list.id } }
+ subject(:deactivate) { put :deactivate, params: { id: price_list.to_param } }
context 'when price list is active' do
let(:price_list) { create(:price_list, store: store, status: 'active') }
diff --git a/admin/spec/controllers/spree/admin/price_rules_controller_spec.rb b/admin/spec/controllers/spree/admin/price_rules_controller_spec.rb
index 3e7e6985f8..22099f45f8 100644
--- a/admin/spec/controllers/spree/admin/price_rules_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/price_rules_controller_spec.rb
@@ -9,7 +9,7 @@ RSpec.describe Spree::Admin::PriceRulesController, type: :controller do
describe 'GET #new' do
context 'without type parameter' do
- subject { get :new, params: { price_list_id: price_list.id } }
+ subject { get :new, params: { price_list_id: price_list.to_param } }
it 'renders the rule type selection' do
subject
@@ -21,7 +21,7 @@ RSpec.describe Spree::Admin::PriceRulesController, type: :controller do
end
context 'with type parameter' do
- subject { get :new, params: { price_list_id: price_list.id, price_rule: { type: 'Spree::PriceRules::ZoneRule' } } }
+ subject { get :new, params: { price_list_id: price_list.to_param, price_rule: { type: 'Spree::PriceRules::ZoneRule' } } }
it 'renders the form for the selected type' do
subject
@@ -37,7 +37,7 @@ RSpec.describe Spree::Admin::PriceRulesController, type: :controller do
let(:params) do
{
- price_list_id: price_list.id,
+ price_list_id: price_list.to_param,
price_rule: {
type: 'Spree::PriceRules::VolumeRule',
preferred_min_quantity: 10,
@@ -69,7 +69,7 @@ RSpec.describe Spree::Admin::PriceRulesController, type: :controller do
end
describe 'GET #edit' do
- subject { get :edit, params: { price_list_id: price_list.id, id: price_rule.id } }
+ subject { get :edit, params: { price_list_id: price_list.to_param, id: price_rule.to_param } }
let!(:price_rule) { create(:volume_price_rule, price_list: price_list) }
@@ -88,8 +88,8 @@ RSpec.describe Spree::Admin::PriceRulesController, type: :controller do
let(:params) do
{
- price_list_id: price_list.id,
- id: price_rule.id,
+ price_list_id: price_list.to_param,
+ id: price_rule.to_param,
price_rule: {
preferred_min_quantity: 20
}
@@ -111,7 +111,7 @@ RSpec.describe Spree::Admin::PriceRulesController, type: :controller do
end
describe 'DELETE #destroy' do
- subject { delete :destroy, params: { price_list_id: price_list.id, id: price_rule.id } }
+ subject { delete :destroy, params: { price_list_id: price_list.to_param, id: price_rule.to_param } }
let!(:price_rule) { create(:volume_price_rule, price_list: price_list) }
diff --git a/admin/spec/controllers/spree/admin/products_controller_spec.rb b/admin/spec/controllers/spree/admin/products_controller_spec.rb
index 4988e1b560..2a87e9cc62 100644
--- a/admin/spec/controllers/spree/admin/products_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/products_controller_spec.rb
@@ -1232,7 +1232,7 @@ RSpec.describe Spree::Admin::ProductsController, type: :controller do
end
describe 'PUT #clone' do
- subject(:clone_request) { put :clone, params: { id: product.id } }
+ subject(:clone_request) { put :clone, params: { id: product.to_param } }
let!(:product) { create(:product, name: 'Product to clone', stores: [store], status: 'active') }
let(:cloned_product) { Spree::Product.find_by(name: 'COPY OF Product to clone') }
diff --git a/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rb b/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rb
index 91ec0decff..ead0da80a3 100644
--- a/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
describe 'GET #new' do
it 'returns a successful response' do
- get :new, params: { promotion_id: promotion.id }
+ get :new, params: { promotion_id: promotion.to_param }
expect(response).to be_successful
end
@@ -23,12 +23,12 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
let(:action_type) { 'Spree::Promotion::Actions::CreateAdjustment' }
it 'returns a successful response' do
- get :new, params: { promotion_id: promotion.id, promotion_action: { type: action_type } }
+ get :new, params: { promotion_id: promotion.to_param, promotion_action: { type: action_type } }
expect(response).to be_successful
end
it 'loads the correct action type' do
- get :new, params: { promotion_id: promotion.id, promotion_action: { type: action_type } }
+ get :new, params: { promotion_id: promotion.to_param, promotion_action: { type: action_type } }
expect(assigns(:promotion_action).class).to eq(action_type.constantize)
end
end
@@ -50,7 +50,7 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
it 'creates a new promotion action' do
expect {
- post :create, params: { promotion_id: promotion.id, promotion_action: action_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_action: action_params }
}.to change(Spree::PromotionAction, :count).by(1)
expect(assigns(:promotion_action).calculator.preferred_amount).to eq(20.0)
@@ -58,7 +58,7 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
end
it 'redirects to the promotion page' do
- post :create, params: { promotion_id: promotion.id, promotion_action: action_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_action: action_params }
expect(response).to redirect_to(spree.admin_promotion_path(promotion))
end
@@ -67,7 +67,7 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
it 'raises an error' do
expect {
- post :create, params: { promotion_id: promotion.id, promotion_action: action_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_action: action_params }
}.to raise_error('Unknown promotion action type')
end
end
@@ -77,12 +77,12 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
let!(:promotion_action) { create(:promotion_action_create_adjustment, promotion: promotion) }
it 'returns a successful response' do
- get :edit, params: { promotion_id: promotion.id, id: promotion_action.id }
+ get :edit, params: { promotion_id: promotion.to_param, id: promotion_action.to_param }
expect(response).to be_successful
end
it 'assigns the promotion action' do
- get :edit, params: { promotion_id: promotion.id, id: promotion_action.id }
+ get :edit, params: { promotion_id: promotion.to_param, id: promotion_action.to_param }
expect(assigns(:promotion_action)).to eq(promotion_action)
end
end
@@ -100,13 +100,13 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
end
it 'updates the promotion action' do
- patch :update, params: { promotion_id: promotion.id, id: promotion_action.id, promotion_action: update_params }
+ patch :update, params: { promotion_id: promotion.to_param, id: promotion_action.to_param, promotion_action: update_params }
calculator.reload
expect(calculator.preferred_amount).to eq(20.0)
end
it 'redirects to the promotion page' do
- patch :update, params: { promotion_id: promotion.id, id: promotion_action.id, promotion_action: update_params }
+ patch :update, params: { promotion_id: promotion.to_param, id: promotion_action.to_param, promotion_action: update_params }
expect(response).to redirect_to(spree.admin_promotion_path(promotion))
end
@@ -130,7 +130,7 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
end
it 'sets the promotion action line items' do
- patch :update, params: { promotion_id: promotion.id, id: promotion_action.id, promotion_action: action_params }
+ patch :update, params: { promotion_id: promotion.to_param, id: promotion_action.to_param, promotion_action: action_params }
expect(assigns(:promotion_action).promotion_action_line_items.first.variant_id).to eq(variant.id)
expect(assigns(:promotion_action).promotion_action_line_items.first.quantity).to eq(2)
end
@@ -142,19 +142,19 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller do
it 'destroys the promotion action' do
expect {
- delete :destroy, params: { promotion_id: promotion.id, id: promotion_action.id }
+ delete :destroy, params: { promotion_id: promotion.to_param, id: promotion_action.to_param }
}.to change(Spree::PromotionAction, :count).by(-1)
end
it 'redirects to the promotion page' do
- delete :destroy, params: { promotion_id: promotion.id, id: promotion_action.id }
+ delete :destroy, params: { promotion_id: promotion.to_param, id: promotion_action.to_param }
expect(response).to redirect_to(spree.admin_promotion_path(promotion))
end
end
describe 'helper methods' do
it 'provides allowed_action_types' do
- get :new, params: { promotion_id: promotion.id }
+ get :new, params: { promotion_id: promotion.to_param }
expect(controller.send(:allowed_action_types)).to eq(Spree.promotions.actions)
end
end
diff --git a/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rb b/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rb
index c2f884175e..6b2b88141c 100644
--- a/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rb
@@ -11,7 +11,7 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
describe 'GET #new' do
it 'returns a successful response' do
- get :new, params: { promotion_id: promotion.id }
+ get :new, params: { promotion_id: promotion.to_param }
expect(response).to be_successful
end
@@ -19,12 +19,12 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
let(:rule_type) { 'Spree::Promotion::Rules::Product' }
it 'returns a successful response' do
- get :new, params: { promotion_id: promotion.id, promotion_rule: { type: rule_type } }
+ get :new, params: { promotion_id: promotion.to_param, promotion_rule: { type: rule_type } }
expect(response).to be_successful
end
it 'loads the correct rule type' do
- get :new, params: { promotion_id: promotion.id, promotion_rule: { type: rule_type } }
+ get :new, params: { promotion_id: promotion.to_param, promotion_rule: { type: rule_type } }
expect(assigns(:promotion_rule).class).to eq(rule_type.constantize)
end
end
@@ -41,12 +41,12 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
it 'creates a new promotion rule' do
expect {
- post :create, params: { promotion_id: promotion.id, promotion_rule: rule_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_rule: rule_params }
}.to change(Spree::PromotionRule, :count).by(1)
end
it 'redirects to the promotion page' do
- post :create, params: { promotion_id: promotion.id, promotion_rule: rule_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_rule: rule_params }
expect(response).to redirect_to(spree.admin_promotion_path(promotion))
end
@@ -55,7 +55,7 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
it 'raises an error' do
expect {
- post :create, params: { promotion_id: promotion.id, promotion_rule: rule_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_rule: rule_params }
}.to raise_error('Unknown promotion rule type')
end
end
@@ -70,12 +70,12 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
it 'creates a new promotion rule' do
expect {
- post :create, params: { promotion_id: promotion.id, promotion_rule: rule_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_rule: rule_params }
}.to change(Spree::PromotionRule, :count).by(1)
end
it 'sets the preferences' do
- post :create, params: { promotion_id: promotion.id, promotion_rule: rule_params }
+ post :create, params: { promotion_id: promotion.to_param, promotion_rule: rule_params }
expect(assigns(:promotion_rule).preferred_country_iso).to eq('US')
end
end
@@ -85,12 +85,12 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
let!(:promotion_rule) { create(:promotion_rule_user, promotion: promotion) }
it 'returns a successful response' do
- get :edit, params: { promotion_id: promotion.id, id: promotion_rule.id }
+ get :edit, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param }
expect(response).to be_successful
end
it 'assigns the promotion rule' do
- get :edit, params: { promotion_id: promotion.id, id: promotion_rule.id }
+ get :edit, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param }
expect(assigns(:promotion_rule)).to eq(promotion_rule)
end
@@ -98,7 +98,7 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
let!(:promotion_rule) { create(:promotion_rule_option_value, promotion: promotion) }
it 'returns a successful response' do
- get :edit, params: { promotion_id: promotion.id, id: promotion_rule.id }
+ get :edit, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param }
expect(response).to be_successful
end
end
@@ -113,13 +113,13 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
end
it 'updates the promotion rule' do
- patch :update, params: { promotion_id: promotion.id, id: promotion_rule.id, promotion_rule: update_params }
+ patch :update, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param, promotion_rule: update_params }
promotion_rule.reload
expect(promotion_rule.user_ids).to include(user.id)
end
it 'redirects to the promotion page' do
- patch :update, params: { promotion_id: promotion.id, id: promotion_rule.id, promotion_rule: update_params }
+ patch :update, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param, promotion_rule: update_params }
expect(response).to redirect_to(spree.admin_promotion_path(promotion))
end
@@ -134,7 +134,7 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
end
it 'updates the promotion rule' do
- patch :update, params: { promotion_id: promotion.id, id: promotion_rule.id, promotion_rule: rule_params }
+ patch :update, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param, promotion_rule: rule_params }
promotion_rule.reload
expect(promotion_rule.preferred_eligible_values).to include(option_value.id.to_s)
end
@@ -151,7 +151,7 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
end
it 'updates the promotion rule with array preference' do
- patch :update, params: { promotion_id: promotion.id, id: promotion_rule.id, promotion_rule: rule_params }
+ patch :update, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param, promotion_rule: rule_params }
promotion_rule.reload
expect(promotion_rule.preferred_customer_group_ids).to include(customer_group.id.to_s, other_customer_group.id.to_s)
end
@@ -163,19 +163,19 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do
it 'destroys the promotion rule' do
expect {
- delete :destroy, params: { promotion_id: promotion.id, id: promotion_rule.id }
+ delete :destroy, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param }
}.to change(Spree::PromotionRule, :count).by(-1)
end
it 'redirects to the promotion page' do
- delete :destroy, params: { promotion_id: promotion.id, id: promotion_rule.id }
+ delete :destroy, params: { promotion_id: promotion.to_param, id: promotion_rule.to_param }
expect(response).to redirect_to(spree.admin_promotion_path(promotion))
end
end
describe 'helper methods' do
it 'provides allowed_rule_types' do
- get :new, params: { promotion_id: promotion.id }
+ get :new, params: { promotion_id: promotion.to_param }
expect(controller.send(:allowed_rule_types)).to eq(Spree.promotions.rules)
end
end
diff --git a/admin/spec/controllers/spree/admin/promotions_controller_spec.rb b/admin/spec/controllers/spree/admin/promotions_controller_spec.rb
index 7c1b1ef2f3..ac46f5336b 100644
--- a/admin/spec/controllers/spree/admin/promotions_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/promotions_controller_spec.rb
@@ -31,12 +31,12 @@ RSpec.describe Spree::Admin::PromotionsController, type: :controller do
let!(:promotion_rule) { create(:promotion_rule_product, promotion: promotion) }
it 'returns a successful response' do
- get :show, params: { id: promotion.id }
+ get :show, params: { id: promotion.to_param }
expect(response).to be_successful
end
it 'assigns the promotion' do
- get :show, params: { id: promotion.id }
+ get :show, params: { id: promotion.to_param }
expect(assigns[:promotion]).to eq(promotion)
end
end
@@ -113,12 +113,12 @@ RSpec.describe Spree::Admin::PromotionsController, type: :controller do
let!(:promotion) { create(:promotion, stores: [store]) }
it 'returns a successful response' do
- get :edit, params: { id: promotion.id }
+ get :edit, params: { id: promotion.to_param }
expect(response).to be_successful
end
it 'loads form data' do
- get :edit, params: { id: promotion.id }
+ get :edit, params: { id: promotion.to_param }
expect(assigns[:promotion_rules]).not_to be_empty
expect(assigns[:rule_types]).not_to be_empty
end
@@ -129,12 +129,12 @@ RSpec.describe Spree::Admin::PromotionsController, type: :controller do
let(:promotion_params) { { name: 'Updated Name' } }
it 'updates the promotion' do
- patch :update, params: { id: promotion.id, promotion: promotion_params }
+ patch :update, params: { id: promotion.to_param, promotion: promotion_params }
expect(promotion.reload.name).to eq('Updated Name')
end
it 'redirects to the edit page' do
- patch :update, params: { id: promotion.id, promotion: promotion_params }
+ patch :update, params: { id: promotion.to_param, promotion: promotion_params }
expect(response).to redirect_to(spree.admin_promotion_path(promotion))
end
end
@@ -145,17 +145,17 @@ RSpec.describe Spree::Admin::PromotionsController, type: :controller do
context 'when cloning succeeds' do
it 'creates a duplicate promotion' do
expect {
- post :clone, params: { id: promotion.id }
+ post :clone, params: { id: promotion.to_param }
}.to change(Spree::Promotion, :count).by(1)
end
it 'redirects to the new promotion' do
- post :clone, params: { id: promotion.id }
+ post :clone, params: { id: promotion.to_param }
expect(response).to redirect_to(spree.admin_promotion_path(assigns[:new_promo]))
end
it 'sets a success flash message' do
- post :clone, params: { id: promotion.id }
+ post :clone, params: { id: promotion.to_param }
expect(flash[:success]).to eq(Spree.t('promotion_cloned'))
end
end
@@ -168,12 +168,12 @@ RSpec.describe Spree::Admin::PromotionsController, type: :controller do
end
it 'redirects to promotions index' do
- post :clone, params: { id: promotion.id }
+ post :clone, params: { id: promotion.to_param }
expect(response).to redirect_to(spree.admin_promotions_path)
end
it 'sets an error flash message' do
- post :clone, params: { id: promotion.id }
+ post :clone, params: { id: promotion.to_param }
expect(flash[:error]).to include('Error message')
end
end
diff --git a/admin/spec/controllers/spree/admin/refunds_controller_spec.rb b/admin/spec/controllers/spree/admin/refunds_controller_spec.rb
index 60bbab5916..37f0edfc5b 100644
--- a/admin/spec/controllers/spree/admin/refunds_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/refunds_controller_spec.rb
@@ -44,7 +44,7 @@ describe Spree::Admin::RefundsController, type: :controller do
end
describe '#update' do
- subject { put :update, params: { id: refund.id, order_id: order.to_param, payment_id: payment.to_param, refund: { refund_reason_id: refund_reason.id.to_s } } }
+ subject { put :update, params: { id: refund.to_param, order_id: order.to_param, payment_id: payment.to_param, refund: { refund_reason_id: refund_reason.id.to_s } } }
let(:refund) { create(:refund, amount: 10, payment: payment) }
let(:refund_reason) { create(:refund_reason) }
diff --git a/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb b/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb
index 8cf3113729..231da8b1bf 100644
--- a/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/reimbursements_controller_spec.rb
@@ -13,7 +13,7 @@ describe Spree::Admin::ReimbursementsController, type: :controller do
describe '#create' do
context 'when build_from_customer_return_id is present' do
subject do
- post :create, params: { order_id: order.to_param, build_from_customer_return_id: customer_return.id }
+ post :create, params: { order_id: order.to_param, build_from_customer_return_id: customer_return.to_param }
end
let(:order) { create(:order) }
diff --git a/admin/spec/controllers/spree/admin/reports_controller_spec.rb b/admin/spec/controllers/spree/admin/reports_controller_spec.rb
index 341a772dcf..ab452c01dc 100644
--- a/admin/spec/controllers/spree/admin/reports_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/reports_controller_spec.rb
@@ -142,7 +142,7 @@ describe Spree::Admin::ReportsController, type: :controller do
allow_any_instance_of(Spree::Reports::SalesTotal).to receive_message_chain(:attachment, :url).and_return('http://example.com/test.csv')
end
- subject { get :show, params: { id: report.id } }
+ subject { get :show, params: { id: report.to_param } }
it 'downloads the export' do
subject
diff --git a/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb b/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb
index fa04f65b5d..f9efd99c1a 100644
--- a/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/return_authorizations_controller_spec.rb
@@ -39,7 +39,7 @@ RSpec.describe Spree::Admin::ReturnAuthorizationsController do
let(:return_authorization) { return_authorizations.first }
let!(:return_item) { create(:return_item, return_authorization: return_authorization, inventory_unit: order.inventory_units.shipped.first) }
- subject { put :cancel, params: { id: return_authorization.id } }
+ subject { put :cancel, params: { id: return_authorization.to_param } }
it 'cancels the return authorization' do
expect { subject }.to change { return_authorization.reload.state }.from('authorized').to('canceled')
@@ -59,7 +59,7 @@ RSpec.describe Spree::Admin::ReturnAuthorizationsController do
describe '#destroy' do
let(:return_authorization) { return_authorizations.first }
- subject { delete :destroy, params: { id: return_authorization.id } }
+ subject { delete :destroy, params: { id: return_authorization.to_param } }
it 'destroys the return authorization' do
expect { subject }.to change(Spree::ReturnAuthorization, :count).by(-1)
diff --git a/admin/spec/controllers/spree/admin/role_users_controller_spec.rb b/admin/spec/controllers/spree/admin/role_users_controller_spec.rb
index 53499ee7cb..78be211870 100644
--- a/admin/spec/controllers/spree/admin/role_users_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/role_users_controller_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Spree::Admin::RoleUsersController, type: :controller do
describe '#destroy' do
it 'deletes the role user' do
- delete :destroy, params: { id: role_user.id, store_id: store.id }
+ delete :destroy, params: { id: role_user.to_param, store_id: store.id }
expect(response).to redirect_to(spree.admin_admin_users_path)
expect(flash[:notice]).to eq("Role user \"#{role_user.user.name}\" has been successfully removed!")
diff --git a/admin/spec/controllers/spree/admin/roles_controller_spec.rb b/admin/spec/controllers/spree/admin/roles_controller_spec.rb
index 8d39a33235..159f4c81bd 100644
--- a/admin/spec/controllers/spree/admin/roles_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/roles_controller_spec.rb
@@ -49,7 +49,7 @@ RSpec.describe Spree::Admin::RolesController, type: :controller do
let!(:role) { create(:role) }
it 'renders the edit role form' do
- get :edit, params: { id: role.id }
+ get :edit, params: { id: role.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
@@ -60,7 +60,7 @@ RSpec.describe Spree::Admin::RolesController, type: :controller do
let!(:role) { create(:role, name: 'Default Role') }
it 'updates the role' do
- put :update, params: { id: role.id, role: { name: 'Updated Role' } }
+ put :update, params: { id: role.to_param, role: { name: 'Updated Role' } }
expect(response).to redirect_to(spree.edit_admin_role_path(role))
expect(role.reload.name).to eq('Updated Role')
@@ -71,7 +71,7 @@ RSpec.describe Spree::Admin::RolesController, type: :controller do
let!(:role) { create(:role) }
it 'deletes the role' do
- delete :destroy, params: { id: role.id }
+ delete :destroy, params: { id: role.to_param }
expect(response).to redirect_to(spree.admin_roles_path)
expect { role.reload }.to raise_error(ActiveRecord::RecordNotFound)
diff --git a/admin/spec/controllers/spree/admin/shipments_controller_spec.rb b/admin/spec/controllers/spree/admin/shipments_controller_spec.rb
index 6af8981541..89f7258b07 100644
--- a/admin/spec/controllers/spree/admin/shipments_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/shipments_controller_spec.rb
@@ -12,7 +12,7 @@ RSpec.describe Spree::Admin::ShipmentsController, type: :controller do
describe 'PUT #update' do
context 'when update is successful' do
before do
- put :update, params: { order_id: order.number, id: shipment.number, shipment: shipment_params }
+ put :update, params: { order_id: order.to_param, id: shipment.to_param, shipment: shipment_params }
end
it 'updates shipment' do
@@ -37,7 +37,7 @@ RSpec.describe Spree::Admin::ShipmentsController, type: :controller do
end
it 'ships the shipment' do
- post :ship, params: { order_id: order.number, id: shipment.number }
+ post :ship, params: { order_id: order.to_param, id: shipment.to_param }
expect(shipment.reload.state).to eq('shipped')
end
end
@@ -49,7 +49,7 @@ RSpec.describe Spree::Admin::ShipmentsController, type: :controller do
end
it 'flashes error' do
- post :ship, params: { order_id: order.number, id: shipment.number }
+ post :ship, params: { order_id: order.to_param, id: shipment.to_param }
expect(flash[:error]).to eq(Spree.t(:cannot_ship))
end
end
diff --git a/admin/spec/controllers/spree/admin/shipping_categories_controller_spec.rb b/admin/spec/controllers/spree/admin/shipping_categories_controller_spec.rb
index 3b38732487..81c67e5158 100644
--- a/admin/spec/controllers/spree/admin/shipping_categories_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/shipping_categories_controller_spec.rb
@@ -49,7 +49,7 @@ RSpec.describe Spree::Admin::ShippingCategoriesController, type: :controller do
let!(:shipping_category) { create(:shipping_category) }
it 'renders the edit shipping category form' do
- get :edit, params: { id: shipping_category.id }
+ get :edit, params: { id: shipping_category.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
@@ -60,7 +60,7 @@ RSpec.describe Spree::Admin::ShippingCategoriesController, type: :controller do
let!(:shipping_category) { create(:shipping_category, name: 'Default Category') }
it 'updates the shipping category' do
- put :update, params: { id: shipping_category.id, shipping_category: { name: 'Updated Category' } }
+ put :update, params: { id: shipping_category.to_param, shipping_category: { name: 'Updated Category' } }
expect(response).to redirect_to(spree.edit_admin_shipping_category_path(shipping_category))
expect(shipping_category.reload.name).to eq('Updated Category')
@@ -71,7 +71,7 @@ RSpec.describe Spree::Admin::ShippingCategoriesController, type: :controller do
let!(:shipping_category) { create(:shipping_category) }
it 'deletes the shipping category' do
- delete :destroy, params: { id: shipping_category.id }
+ delete :destroy, params: { id: shipping_category.to_param }
expect(response).to redirect_to(spree.admin_shipping_categories_path)
expect { shipping_category.reload }.to raise_error(ActiveRecord::RecordNotFound)
diff --git a/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rb b/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rb
index d4264dcca5..8bc8076c9b 100644
--- a/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rb
@@ -46,7 +46,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do
let(:shipping_method) { create(:shipping_method) }
it 'renders the edit template' do
- get :edit, params: { id: shipping_method.id }
+ get :edit, params: { id: shipping_method.to_param }
expect(response.status).to eq(200)
end
end
@@ -71,7 +71,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do
end
it 'updates the shipping method' do
- put :update, params: { id: shipping_method.id, shipping_method: new_attributes }
+ put :update, params: { id: shipping_method.to_param, shipping_method: new_attributes }
shipping_method.reload
expect(shipping_method.name).to eq('Updated Method')
@@ -89,7 +89,7 @@ describe Spree::Admin::ShippingMethodsController, type: :controller do
it 'deletes the shipping method' do
expect {
- delete :destroy, params: { id: shipping_method.id }
+ delete :destroy, params: { id: shipping_method.to_param }
}.to change(Spree::ShippingMethod, :count).by(-1)
expect(response).to redirect_to(spree.admin_shipping_methods_path)
diff --git a/admin/spec/controllers/spree/admin/stock_items_controller_spec.rb b/admin/spec/controllers/spree/admin/stock_items_controller_spec.rb
index d333d36783..9001b857e3 100644
--- a/admin/spec/controllers/spree/admin/stock_items_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/stock_items_controller_spec.rb
@@ -79,7 +79,7 @@ RSpec.describe Spree::Admin::StockItemsController, type: :controller do
subject(:update) { patch :update, params: params, format: :turbo_stream }
- let(:params) { { id: stock_item.id, stock_item: { backorderable: true, count_on_hand: 99 } } }
+ let(:params) { { id: stock_item.to_param, stock_item: { backorderable: true, count_on_hand: 99 } } }
it 'updates the stock item' do
update
diff --git a/admin/spec/controllers/spree/admin/stock_locations_controller_spec.rb b/admin/spec/controllers/spree/admin/stock_locations_controller_spec.rb
index 277727c183..095a156640 100644
--- a/admin/spec/controllers/spree/admin/stock_locations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/stock_locations_controller_spec.rb
@@ -57,7 +57,7 @@ RSpec.describe Spree::Admin::StockLocationsController, type: :controller do
let!(:stock_location) { create(:stock_location) }
it 'renders the edit stock location form' do
- get :edit, params: { id: stock_location.id }
+ get :edit, params: { id: stock_location.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
@@ -68,7 +68,7 @@ RSpec.describe Spree::Admin::StockLocationsController, type: :controller do
let!(:stock_location) { create(:stock_location, name: 'Main Warehouse') }
it 'updates the stock location' do
- put :update, params: { id: stock_location.id, stock_location: { name: 'New Warehouse' } }
+ put :update, params: { id: stock_location.to_param, stock_location: { name: 'New Warehouse' } }
expect(response).to redirect_to(spree.edit_admin_stock_location_path(stock_location))
expect(stock_location.reload.name).to eq('New Warehouse')
@@ -80,7 +80,7 @@ RSpec.describe Spree::Admin::StockLocationsController, type: :controller do
it 'marks the stock location as default' do
expect {
- put :mark_as_default, params: { id: stock_location.id }
+ put :mark_as_default, params: { id: stock_location.to_param }
}.to change { stock_location.reload.default }.from(false).to(true)
expect(response).to redirect_to(spree.admin_stock_locations_path)
@@ -92,7 +92,7 @@ RSpec.describe Spree::Admin::StockLocationsController, type: :controller do
it 'deletes the stock location' do
expect {
- delete :destroy, params: { id: stock_location.id }
+ delete :destroy, params: { id: stock_location.to_param }
}.to change(Spree::StockLocation, :count).by(-1)
expect(response).to redirect_to(spree.admin_stock_locations_path)
diff --git a/admin/spec/controllers/spree/admin/store_credit_categories_controller_spec.rb b/admin/spec/controllers/spree/admin/store_credit_categories_controller_spec.rb
index 9dd09bb7e3..3b00a1b48e 100644
--- a/admin/spec/controllers/spree/admin/store_credit_categories_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/store_credit_categories_controller_spec.rb
@@ -49,7 +49,7 @@ RSpec.describe Spree::Admin::StoreCreditCategoriesController, type: :controller
let!(:store_credit_category) { create(:store_credit_category) }
it 'renders the edit store credit category form' do
- get :edit, params: { id: store_credit_category.id }
+ get :edit, params: { id: store_credit_category.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
@@ -60,7 +60,7 @@ RSpec.describe Spree::Admin::StoreCreditCategoriesController, type: :controller
let!(:store_credit_category) { create(:store_credit_category, name: 'Gift Card') }
it 'updates the store credit category' do
- put :update, params: { id: store_credit_category.id, store_credit_category: { name: 'Updated Category' } }
+ put :update, params: { id: store_credit_category.to_param, store_credit_category: { name: 'Updated Category' } }
expect(response).to redirect_to(spree.edit_admin_store_credit_category_path(store_credit_category))
expect(store_credit_category.reload.name).to eq('Updated Category')
@@ -71,7 +71,7 @@ RSpec.describe Spree::Admin::StoreCreditCategoriesController, type: :controller
let!(:store_credit_category) { create(:store_credit_category) }
it 'deletes the store credit category' do
- delete :destroy, params: { id: store_credit_category.id }
+ delete :destroy, params: { id: store_credit_category.to_param }
expect(response).to redirect_to(spree.admin_store_credit_categories_path)
expect { store_credit_category.reload }.to raise_error(ActiveRecord::RecordNotFound)
diff --git a/admin/spec/controllers/spree/admin/store_credits_controller_spec.rb b/admin/spec/controllers/spree/admin/store_credits_controller_spec.rb
index ba0042d4df..8bfb183c49 100644
--- a/admin/spec/controllers/spree/admin/store_credits_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/store_credits_controller_spec.rb
@@ -15,7 +15,7 @@ RSpec.describe Spree::Admin::StoreCreditsController, type: :controller do
let!(:other_store_credits) { create_list(:store_credit, 3) }
it 'renders the list of store credits' do
- get :index, params: { user_id: user.id }
+ get :index, params: { user_id: user.to_param }
expect(response).to be_successful
expect(response).to render_template(:index)
@@ -29,7 +29,7 @@ RSpec.describe Spree::Admin::StoreCreditsController, type: :controller do
let!(:store_credit_events) { create_list(:store_credit_auth_event, 3, store_credit: store_credit) }
it 'renders the store credit show page' do
- get :show, params: { user_id: user.id, id: store_credit.id }
+ get :show, params: { user_id: user.to_param, id: store_credit.to_param }
expect(response).to be_successful
expect(response).to render_template(:show)
@@ -38,7 +38,7 @@ RSpec.describe Spree::Admin::StoreCreditsController, type: :controller do
describe 'GET #new' do
it 'renders the new store credit form' do
- get :new, params: { user_id: user.id }
+ get :new, params: { user_id: user.to_param }
expect(response).to be_successful
expect(response).to render_template(:new)
@@ -46,7 +46,7 @@ RSpec.describe Spree::Admin::StoreCreditsController, type: :controller do
end
describe 'POST #create' do
- subject { post :create, params: { user_id: user.id, store_credit: store_credit_params } }
+ subject { post :create, params: { user_id: user.to_param, store_credit: store_credit_params } }
let(:store_credit_params) { { amount: 100, currency: 'USD' } }
@@ -80,7 +80,7 @@ RSpec.describe Spree::Admin::StoreCreditsController, type: :controller do
let(:store_credit) { create(:store_credit, user: user) }
it 'renders the edit store credit form' do
- get :edit, params: { user_id: user.id, id: store_credit.id }
+ get :edit, params: { user_id: user.to_param, id: store_credit.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
@@ -88,7 +88,7 @@ RSpec.describe Spree::Admin::StoreCreditsController, type: :controller do
end
describe 'PUT #update' do
- subject { put :update, params: { user_id: user.id, id: store_credit.id, store_credit: store_credit_params } }
+ subject { put :update, params: { user_id: user.to_param, id: store_credit.to_param, store_credit: store_credit_params } }
let(:store_credit) { create(:store_credit, user: user) }
let(:store_credit_params) { { amount: 200 } }
@@ -114,7 +114,7 @@ RSpec.describe Spree::Admin::StoreCreditsController, type: :controller do
end
describe 'DELETE #destroy' do
- subject { delete :destroy, params: { user_id: user.id, id: store_credit.id } }
+ subject { delete :destroy, params: { user_id: user.to_param, id: store_credit.to_param } }
let(:store_credit) { create(:store_credit, user: user) }
diff --git a/admin/spec/controllers/spree/admin/stores_controller_spec.rb b/admin/spec/controllers/spree/admin/stores_controller_spec.rb
index fde91192b0..4dd558149c 100644
--- a/admin/spec/controllers/spree/admin/stores_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/stores_controller_spec.rb
@@ -65,7 +65,7 @@ describe Spree::Admin::StoresController do
end
describe 'PUT #update' do
- subject { patch :update, params: { id: store.id, store: store_params, **other_params } }
+ subject { patch :update, params: { id: store.to_param, store: store_params, **other_params } }
let(:store_params) do
{
diff --git a/admin/spec/controllers/spree/admin/tax_categories_controller_spec.rb b/admin/spec/controllers/spree/admin/tax_categories_controller_spec.rb
index d57eb81cbd..74968eb2ab 100644
--- a/admin/spec/controllers/spree/admin/tax_categories_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/tax_categories_controller_spec.rb
@@ -57,7 +57,7 @@ RSpec.describe Spree::Admin::TaxCategoriesController, type: :controller do
let!(:tax_category) { create(:tax_category) }
it 'renders the edit tax category form' do
- get :edit, params: { id: tax_category.id }
+ get :edit, params: { id: tax_category.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
@@ -68,7 +68,7 @@ RSpec.describe Spree::Admin::TaxCategoriesController, type: :controller do
let!(:tax_category) { create(:tax_category, name: 'General Category') }
it 'updates the tax category' do
- put :update, params: { id: tax_category.id, tax_category: { name: 'Updated Category' } }
+ put :update, params: { id: tax_category.to_param, tax_category: { name: 'Updated Category' } }
expect(response).to redirect_to(spree.edit_admin_tax_category_path(tax_category))
expect(tax_category.reload.name).to eq('Updated Category')
@@ -79,7 +79,7 @@ RSpec.describe Spree::Admin::TaxCategoriesController, type: :controller do
let!(:tax_category) { create(:tax_category) }
it 'deletes the tax category' do
- delete :destroy, params: { id: tax_category.id }
+ delete :destroy, params: { id: tax_category.to_param }
expect(response).to redirect_to(spree.admin_tax_categories_path)
expect(tax_category.reload).to be_deleted
diff --git a/admin/spec/controllers/spree/admin/tax_rates_controller_spec.rb b/admin/spec/controllers/spree/admin/tax_rates_controller_spec.rb
index 9655ba1426..5bc9579021 100644
--- a/admin/spec/controllers/spree/admin/tax_rates_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/tax_rates_controller_spec.rb
@@ -65,7 +65,7 @@ RSpec.describe Spree::Admin::TaxRatesController, type: :controller do
let!(:tax_rate) { create(:tax_rate) }
it 'renders the edit tax rate form' do
- get :edit, params: { id: tax_rate.id }
+ get :edit, params: { id: tax_rate.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
@@ -76,7 +76,7 @@ RSpec.describe Spree::Admin::TaxRatesController, type: :controller do
let!(:tax_rate) { create(:tax_rate, name: 'General Tax') }
it 'updates the tax rate' do
- put :update, params: { id: tax_rate.id, tax_rate: { name: 'EU Tax' } }
+ put :update, params: { id: tax_rate.to_param, tax_rate: { name: 'EU Tax' } }
expect(response).to redirect_to(spree.edit_admin_tax_rate_path(tax_rate))
expect(tax_rate.reload.name).to eq('EU Tax')
@@ -87,7 +87,7 @@ RSpec.describe Spree::Admin::TaxRatesController, type: :controller do
let!(:tax_rate) { create(:tax_rate) }
it 'deletes the tax rate' do
- delete :destroy, params: { id: tax_rate.id }
+ delete :destroy, params: { id: tax_rate.to_param }
expect(response).to redirect_to(spree.admin_tax_rates_path)
expect(tax_rate.reload).to be_deleted
@@ -127,7 +127,7 @@ RSpec.describe Spree::Admin::TaxRatesController, type: :controller do
let!(:tax_rate) { create(:tax_rate, amount: 0.05) }
it 'updates tax rate amount from percentage' do
- put :update, params: { id: tax_rate.id, tax_rate: { amount_percentage: 10.5 } }
+ put :update, params: { id: tax_rate.to_param, tax_rate: { amount_percentage: 10.5 } }
expect(response).to redirect_to(spree.edit_admin_tax_rate_path(tax_rate))
expect(tax_rate.reload.amount).to eq(0.105)
diff --git a/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rb b/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rb
index c9ec09fe67..061de357b8 100644
--- a/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rb
@@ -39,7 +39,7 @@ describe Spree::Admin::TaxonomiesController do
let(:taxonomy) { create(:taxonomy) }
before do
- get :edit, params: { id: taxonomy.id }
+ get :edit, params: { id: taxonomy.to_param }
end
it 'renders edit taxonomy view' do
@@ -49,7 +49,7 @@ describe Spree::Admin::TaxonomiesController do
end
describe '#update' do
- subject { put :update, params: { id: taxonomy.id, taxonomy: { name: 'New Name' } } }
+ subject { put :update, params: { id: taxonomy.to_param, taxonomy: { name: 'New Name' } } }
let(:taxonomy) { create(:taxonomy) }
@@ -60,7 +60,7 @@ describe Spree::Admin::TaxonomiesController do
end
context 'update position' do
- subject { put :update, params: { id: taxonomy.id, taxonomy: { position: 2 } }, format: :turbo_stream }
+ subject { put :update, params: { id: taxonomy.to_param, taxonomy: { position: 2 } }, format: :turbo_stream }
it 'updates the taxonomy position' do
subject
@@ -70,7 +70,7 @@ describe Spree::Admin::TaxonomiesController do
end
describe '#destroy' do
- subject { delete :destroy, params: { id: taxonomy.id } }
+ subject { delete :destroy, params: { id: taxonomy.to_param } }
let!(:taxonomy) { create(:taxonomy) }
diff --git a/admin/spec/controllers/spree/admin/taxons_controller_spec.rb b/admin/spec/controllers/spree/admin/taxons_controller_spec.rb
index 5dfde46bcc..f1534ac9a0 100644
--- a/admin/spec/controllers/spree/admin/taxons_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/taxons_controller_spec.rb
@@ -12,12 +12,12 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
let(:taxon) { create(:taxon, taxonomy: taxonomy) }
it 'returns a successful response' do
- get :new, params: { taxonomy_id: taxonomy.id, taxon: { parent_id: taxon.id } }
+ get :new, params: { taxonomy_id: taxonomy.to_param, taxon: { parent_id: taxon.id } }
expect(response).to be_successful
end
it 'assigns the parent taxon' do
- get :new, params: { taxonomy_id: taxonomy.id, taxon: { parent_id: taxon.id } }
+ get :new, params: { taxonomy_id: taxonomy.to_param, taxon: { parent_id: taxon.id } }
expect(assigns(:taxon).parent).to eq(taxon)
end
end
@@ -29,7 +29,7 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
it 'returns a successful response' do
expect {
post :create, params: {
- taxonomy_id: taxonomy.id,
+ taxonomy_id: taxonomy.to_param,
taxon: {
parent_id: parent_taxon.id,
name: 'Automatic Taxon',
@@ -49,7 +49,7 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
expect(taxon.taxon_rules.first.match_policy).to eq('is_equal_to')
expect(taxon.parent).to eq(parent_taxon)
- expect(response).to redirect_to(spree.edit_admin_taxonomy_taxon_path(taxonomy.id, taxon.id))
+ expect(response).to redirect_to(spree.edit_admin_taxonomy_taxon_path(taxonomy, taxon))
end
end
end
@@ -58,8 +58,8 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
let(:taxon) { create(:taxon, taxonomy: taxonomy) }
it 'redirects to the edit page' do
- get :show, params: { taxonomy_id: taxonomy.id, id: taxon.id }
- expect(response).to redirect_to(spree.edit_admin_taxonomy_taxon_path(taxonomy.id, taxon.id))
+ get :show, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param }
+ expect(response).to redirect_to(spree.edit_admin_taxonomy_taxon_path(taxonomy, taxon))
end
end
@@ -67,7 +67,7 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
let(:taxon) { create(:taxon, taxonomy: taxonomy) }
it 'returns a successful response' do
- get :edit, params: { taxonomy_id: taxonomy.id, id: taxon.id }
+ get :edit, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param }
expect(response).to be_successful
end
end
@@ -78,7 +78,7 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
it 'returns a successful response' do
put :update, params: {
- taxonomy_id: taxonomy.id, id: taxon.id,
+ taxonomy_id: taxonomy.to_param, id: taxon.to_param,
taxon: {
name: 'New Name',
description: 'New Description',
@@ -100,7 +100,7 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
]
}
}
- expect(response).to redirect_to(spree.edit_admin_taxonomy_taxon_path(taxonomy.id, taxon.id))
+ expect(response).to redirect_to(spree.edit_admin_taxonomy_taxon_path(taxonomy, taxon))
expect(taxon.reload.name).to eq('New Name')
expect(taxon.description.to_plain_text).to eq('New Description')
@@ -114,14 +114,14 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
context 'when permalink_part is present' do
context 'and no parent taxon' do
it 'sets the permalink from permalink_part param' do
- put :update, params: { taxonomy_id: taxonomy.id, id: taxonomy.root.id, permalink_part: 'new-permalink' }
+ put :update, params: { taxonomy_id: taxonomy.to_param, id: taxonomy.root.to_param, permalink_part: 'new-permalink' }
expect(taxonomy.root.reload.permalink).to eq('new-permalink')
end
end
context 'and parent taxon is present' do
it 'sets the permalink from root permalink and permalink_part param' do
- put :update, params: { taxonomy_id: taxonomy.id, id: taxon.id, permalink_part: 'new-permalink' }
+ put :update, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param, permalink_part: 'new-permalink' }
expect(taxon.reload.permalink).to eq("#{taxonomy.root.permalink}/new-permalink")
end
end
@@ -133,12 +133,12 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
let(:new_parent) { create(:taxon, taxonomy: taxonomy) }
it 'returns a successful response' do
- put :reposition, params: { taxonomy_id: taxonomy.id, id: taxon.id, taxon: { new_parent_id: new_parent.id, new_position_idx: 0 } }
+ put :reposition, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param, taxon: { new_parent_id: new_parent.id, new_position_idx: 0 } }
expect(response).to be_successful
end
it 'repositions the taxon' do
- put :reposition, params: { taxonomy_id: taxonomy.id, id: taxon.id, taxon: { new_parent_id: new_parent.id, new_position_idx: 0 } }
+ put :reposition, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param, taxon: { new_parent_id: new_parent.id, new_position_idx: 0 } }
expect(taxon.reload.parent).to eq(new_parent)
end
end
@@ -147,7 +147,7 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller do
let!(:taxon) { create(:taxon, taxonomy: taxonomy) }
it 'removes the taxon from the database' do
- expect { delete :destroy, params: { taxonomy_id: taxonomy.id, id: taxon.id }, format: :turbo_stream }.to change(Spree::Taxon, :count).by(-1)
+ expect { delete :destroy, params: { taxonomy_id: taxonomy.to_param, id: taxon.to_param }, format: :turbo_stream }.to change(Spree::Taxon, :count).by(-1)
end
end
diff --git a/admin/spec/controllers/spree/admin/translations_controller_spec.rb b/admin/spec/controllers/spree/admin/translations_controller_spec.rb
index 3d1f98848a..528946a7f8 100644
--- a/admin/spec/controllers/spree/admin/translations_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/translations_controller_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Spree::Admin::TranslationsController, type: :controller do
describe 'GET #edit' do
it 'assigns @object and renders the edit template' do
- get :edit, params: { resource_type: resource_type, id: product.id, translation_locale: translation_locale }
+ get :edit, params: { resource_type: resource_type, id: product.to_param, translation_locale: translation_locale }
expect(response).to render_template(:edit)
expect(assigns(:object)).to eq(product)
expect(assigns(:locales)).to include('fr')
@@ -26,7 +26,7 @@ RSpec.describe Spree::Admin::TranslationsController, type: :controller do
context 'when resource_type is missing' do
it 'raises ActiveRecord::RecordNotFound' do
expect {
- get :edit, params: { id: product.id, resource_type: '', translation_locale: translation_locale }
+ get :edit, params: { id: product.to_param, resource_type: '', translation_locale: translation_locale }
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
@@ -34,7 +34,7 @@ RSpec.describe Spree::Admin::TranslationsController, type: :controller do
context 'when resource_type is invalid' do
it 'raises ActiveRecord::RecordNotFound' do
expect {
- get :edit, params: { resource_type: 'InvalidType', id: product.id, translation_locale: translation_locale }
+ get :edit, params: { resource_type: 'InvalidType', id: product.to_param, translation_locale: translation_locale }
}.to raise_error(ActiveRecord::RecordNotFound)
end
end
diff --git a/admin/spec/controllers/spree/admin/users_controller_spec.rb b/admin/spec/controllers/spree/admin/users_controller_spec.rb
index 84f6d6d70e..cf2cfb8e33 100644
--- a/admin/spec/controllers/spree/admin/users_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/users_controller_spec.rb
@@ -106,7 +106,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
let!(:order) { create(:completed_order_with_totals, user: user) }
it 'renders the user page with last order data' do
- get :show, params: { id: user.id }
+ get :show, params: { id: user.to_param }
expect(response).to have_http_status(:ok)
expect(response).to render_template(:show)
@@ -129,7 +129,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
let(:user) { create(:user) }
it 'renders the edit user form' do
- get :edit, params: { id: user.id }
+ get :edit, params: { id: user.to_param }
expect(response).to have_http_status(:ok)
expect(response).to render_template(:edit)
@@ -148,7 +148,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
let!(:user) { create(:user, tag_list: ['Tag 1']) }
it 'removes tags successfully' do
- put :update, params: { id: user.id, user: { last_name: 'Test' } }
+ put :update, params: { id: user.to_param, user: { last_name: 'Test' } }
expect(user.reload.tag_list).to be_empty
expect(user.reload.last_name).to eq('Test')
@@ -168,7 +168,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
it 'does not clear existing roles' do
expect(user.spree_roles).to include(role)
- put :update, params: { id: user.id, user: { last_name: 'Test', spree_role_ids: [''] } }
+ put :update, params: { id: user.to_param, user: { last_name: 'Test', spree_role_ids: [''] } }
expect(user.reload.last_name).to eq('Test')
expect(user.spree_roles).to include(role)
@@ -178,7 +178,7 @@ RSpec.describe Spree::Admin::UsersController, type: :controller do
context 'updating internal_note' do
subject do
- put :update, params: { id: user.id, user: { internal_note: internal_note_content } }, format: :turbo_stream
+ put :update, params: { id: user.to_param, user: { internal_note: internal_note_content } }, format: :turbo_stream
end
let(:user) { create(:user) }
diff --git a/admin/spec/controllers/spree/admin/variants_controller_spec.rb b/admin/spec/controllers/spree/admin/variants_controller_spec.rb
index 8e726327df..06ca61e458 100644
--- a/admin/spec/controllers/spree/admin/variants_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/variants_controller_spec.rb
@@ -117,7 +117,7 @@ RSpec.describe Spree::Admin::VariantsController, type: :controller do
end
describe 'GET #edit' do
- subject(:edit) { get :edit, params: { id: variant.id, product_id: product.slug } }
+ subject(:edit) { get :edit, params: { id: variant.to_param, product_id: product.slug } }
it 'renders the variant edit page' do
edit
@@ -128,7 +128,7 @@ RSpec.describe Spree::Admin::VariantsController, type: :controller do
describe 'PUT #update' do
let(:variant_params) do
{
- id: variant.id,
+ id: variant.to_param,
product_id: product.slug,
variant: {
sku: 'SKU123456',
@@ -164,7 +164,7 @@ RSpec.describe Spree::Admin::VariantsController, type: :controller do
context 'with multiple currencies' do
let(:variant_params) do
{
- id: variant.id,
+ id: variant.to_param,
product_id: product.slug,
variant: {
prices_attributes: {
@@ -204,7 +204,7 @@ RSpec.describe Spree::Admin::VariantsController, type: :controller do
let(:variant_params) do
{
- id: variant.id,
+ id: variant.to_param,
product_id: product.slug,
variant: {
stock_items_attributes: {
@@ -230,7 +230,7 @@ RSpec.describe Spree::Admin::VariantsController, type: :controller do
context 'disabling track inventory' do
let(:variant_params) do
{
- id: variant.id,
+ id: variant.to_param,
product_id: product.slug,
variant: { track_inventory: '0' }
}
@@ -248,7 +248,7 @@ RSpec.describe Spree::Admin::VariantsController, type: :controller do
describe 'DELETE #destroy' do
it 'should destroy the variant' do
- delete :destroy, params: { product_id: product.slug, id: variant.id }
+ delete :destroy, params: { product_id: product.slug, id: variant.to_param }
expect(response).to redirect_to(spree.edit_admin_product_path(product))
end
end
diff --git a/admin/spec/controllers/spree/admin/webhook_deliveries_controller_spec.rb b/admin/spec/controllers/spree/admin/webhook_deliveries_controller_spec.rb
index 65838b207e..84b9d2f2a3 100644
--- a/admin/spec/controllers/spree/admin/webhook_deliveries_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/webhook_deliveries_controller_spec.rb
@@ -10,7 +10,7 @@ RSpec.describe Spree::Admin::WebhookDeliveriesController, type: :controller do
let(:webhook_endpoint) { create(:webhook_endpoint, store: store) }
describe 'GET #index' do
- subject(:index) { get :index, params: { webhook_endpoint_id: webhook_endpoint.id } }
+ subject(:index) { get :index, params: { webhook_endpoint_id: webhook_endpoint.to_param } }
let!(:deliveries) { create_list(:webhook_delivery, 3, webhook_endpoint: webhook_endpoint) }
let!(:other_endpoint_deliveries) { create_list(:webhook_delivery, 2) }
@@ -52,7 +52,7 @@ RSpec.describe Spree::Admin::WebhookDeliveriesController, type: :controller do
let!(:new_delivery) { create(:webhook_delivery, webhook_endpoint: ordering_endpoint, created_at: 1.hour.ago) }
it 'orders deliveries by created_at descending' do
- get :index, params: { webhook_endpoint_id: ordering_endpoint.id }
+ get :index, params: { webhook_endpoint_id: ordering_endpoint.to_param }
collection = assigns[:collection]
expect(collection.first).to eq(new_delivery)
@@ -62,7 +62,7 @@ RSpec.describe Spree::Admin::WebhookDeliveriesController, type: :controller do
end
describe 'GET #show' do
- subject(:show) { get :show, params: { webhook_endpoint_id: webhook_endpoint.id, id: delivery.id } }
+ subject(:show) { get :show, params: { webhook_endpoint_id: webhook_endpoint.to_param, id: delivery.to_param } }
let(:delivery) { create(:webhook_delivery, :successful, webhook_endpoint: webhook_endpoint) }
diff --git a/admin/spec/controllers/spree/admin/webhook_endpoints_controller_spec.rb b/admin/spec/controllers/spree/admin/webhook_endpoints_controller_spec.rb
index 953c3a4f82..e28f8b6ce6 100644
--- a/admin/spec/controllers/spree/admin/webhook_endpoints_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/webhook_endpoints_controller_spec.rb
@@ -28,7 +28,7 @@ RSpec.describe Spree::Admin::WebhookEndpointsController, type: :controller do
end
describe 'GET #show' do
- subject(:show) { get :show, params: { id: webhook_endpoint.id } }
+ subject(:show) { get :show, params: { id: webhook_endpoint.to_param } }
let(:webhook_endpoint) { create(:webhook_endpoint, store: store) }
@@ -134,7 +134,7 @@ RSpec.describe Spree::Admin::WebhookEndpointsController, type: :controller do
end
describe 'GET #edit' do
- subject(:edit) { get :edit, params: { id: webhook_endpoint.id } }
+ subject(:edit) { get :edit, params: { id: webhook_endpoint.to_param } }
let(:webhook_endpoint) { create(:webhook_endpoint, store: store) }
@@ -152,7 +152,7 @@ RSpec.describe Spree::Admin::WebhookEndpointsController, type: :controller do
end
describe 'PUT #update' do
- subject(:update_endpoint) { put :update, params: { id: webhook_endpoint.id, webhook_endpoint: endpoint_params } }
+ subject(:update_endpoint) { put :update, params: { id: webhook_endpoint.to_param, webhook_endpoint: endpoint_params } }
let!(:webhook_endpoint) { create(:webhook_endpoint, store: store, url: 'https://old.example.com/webhook', active: true) }
@@ -209,7 +209,7 @@ RSpec.describe Spree::Admin::WebhookEndpointsController, type: :controller do
end
describe 'DELETE #destroy' do
- subject(:destroy_endpoint) { delete :destroy, params: { id: webhook_endpoint.id } }
+ subject(:destroy_endpoint) { delete :destroy, params: { id: webhook_endpoint.to_param } }
let!(:webhook_endpoint) { create(:webhook_endpoint, store: store) }
diff --git a/admin/spec/controllers/spree/admin/zones_controller_spec.rb b/admin/spec/controllers/spree/admin/zones_controller_spec.rb
index 2aa331b8d6..9f66b29ed1 100644
--- a/admin/spec/controllers/spree/admin/zones_controller_spec.rb
+++ b/admin/spec/controllers/spree/admin/zones_controller_spec.rb
@@ -84,7 +84,7 @@ RSpec.describe Spree::Admin::ZonesController do
let!(:zone) { create(:zone) }
it 'renders the edit template' do
- get :edit, params: { id: zone.id }
+ get :edit, params: { id: zone.to_param }
expect(response).to be_successful
expect(response).to render_template(:edit)
expect(assigns(:zone)).to eq(zone)
@@ -95,7 +95,7 @@ RSpec.describe Spree::Admin::ZonesController do
let!(:zone) { create(:zone, name: 'Old Name') }
it 'updates the zone' do
- put :update, params: { id: zone.id, zone: { name: 'New Name' } }
+ put :update, params: { id: zone.to_param, zone: { name: 'New Name' } }
expect(zone.reload.name).to eq('New Name')
end
@@ -105,7 +105,7 @@ RSpec.describe Spree::Admin::ZonesController do
let!(:zone) { create(:zone) }
it 'deletes the zone' do
- expect { delete :destroy, params: { id: zone.id } }.to change(Spree::Zone, :count).by(-1)
+ expect { delete :destroy, params: { id: zone.to_param } }.to change(Spree::Zone, :count).by(-1)
expect(response).to redirect_to(spree.admin_zones_path)
expect(Spree::Zone.find_by(id: zone.id)).to be_nil
diff --git a/api/app/controllers/concerns/spree/api/v3/order_concern.rb b/api/app/controllers/concerns/spree/api/v3/order_concern.rb
index 869067013d..75c4fdc594 100644
--- a/api/app/controllers/concerns/spree/api/v3/order_concern.rb
+++ b/api/app/controllers/concerns/spree/api/v3/order_concern.rb
@@ -10,6 +10,10 @@ module Spree
authorize!(:update, @parent, order_token)
end
+ def set_parent
+ @parent = current_store.orders.find_by!(prefix_id: params[:order_id]) if params[:order_id].present?
+ end
+
protected
def order_token
diff --git a/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb b/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb
index f40ba2ef5b..feff807b30 100644
--- a/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders/line_items_controller.rb
@@ -61,10 +61,6 @@ module Spree
protected
- def set_parent
- @parent = current_store.orders.friendly.find(params[:order_id])
- end
-
def parent_association
:line_items
end
diff --git a/api/app/controllers/spree/api/v3/store/orders_controller.rb b/api/app/controllers/spree/api/v3/store/orders_controller.rb
index 943c8b5f46..192509ba6a 100644
--- a/api/app/controllers/spree/api/v3/store/orders_controller.rb
+++ b/api/app/controllers/spree/api/v3/store/orders_controller.rb
@@ -82,7 +82,7 @@ module Spree
# Override set_resource to use friendly finder and order_token authorization
def set_resource
- @order = current_store.orders.friendly.find(params[:id])
+ @order = current_store.orders.find_by!(prefix_id: params[:id])
@resource = @order
authorize_resource!(@order)
end
diff --git a/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb
index 5eec7536a4..0b734fe7da 100644
--- a/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/orders/line_items_controller_spec.rb
@@ -17,9 +17,9 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
describe 'POST #create' do
it 'adds a line item to the order' do
- expect {
- post :create, params: { order_id: order.number, line_item: { variant_id: variant.prefix_id, quantity: 2 } }
- }.to change(Spree::LineItem, :count).by(1)
+ expect do
+ post :create, params: { order_id: order.to_param, line_item: { variant_id: variant.prefix_id, quantity: 2 } }
+ end.to change(Spree::LineItem, :count).by(1)
expect(response).to have_http_status(:created)
expect(json_response['variant_id']).to eq(variant.prefix_id)
@@ -27,14 +27,14 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
end
it 'defaults quantity to 1' do
- post :create, params: { order_id: order.number, line_item: { variant_id: variant.prefix_id } }
+ post :create, params: { order_id: order.to_param, line_item: { variant_id: variant.prefix_id } }
expect(response).to have_http_status(:created)
expect(json_response['quantity']).to eq(1)
end
it 'updates order totals' do
- post :create, params: { order_id: order.number, line_item: { variant_id: variant.prefix_id, quantity: 2 } }
+ post :create, params: { order_id: order.to_param, line_item: { variant_id: variant.prefix_id, quantity: 2 } }
expect(order.reload.item_total).to be > 0
end
@@ -46,13 +46,13 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'adds line item with valid order token' do
request.headers['X-Spree-Order-Token'] = guest_order.token
- post :create, params: { order_id: guest_order.number, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
+ post :create, params: { order_id: guest_order.to_param, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:created)
end
it 'returns forbidden without order token' do
- post :create, params: { order_id: guest_order.number, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
+ post :create, params: { order_id: guest_order.to_param, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -62,7 +62,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
context 'validation errors' do
it 'returns error for invalid variant' do
- post :create, params: { order_id: order.number, line_item: { variant_id: 0, quantity: 1 } }
+ post :create, params: { order_id: order.to_param, line_item: { variant_id: 0, quantity: 1 } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('variant_not_found')
@@ -82,7 +82,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'returns forbidden for other users order' do
other_order = create(:order, store: store)
- post :create, params: { order_id: other_order.number, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
+ post :create, params: { order_id: other_order.to_param, line_item: { variant_id: variant.prefix_id, quantity: 1 } }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -94,7 +94,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
let!(:line_item) { create(:line_item, order: order, variant: variant, quantity: 1) }
it 'updates line item quantity' do
- patch :update, params: { order_id: order.number, id: line_item.prefix_id, line_item: { quantity: 5 } }
+ patch :update, params: { order_id: order.to_param, id: line_item.prefix_id, line_item: { quantity: 5 } }
expect(response).to have_http_status(:ok)
expect(line_item.reload.quantity).to eq(5)
@@ -102,14 +102,14 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
it 'updates order totals' do
original_total = order.item_total
- patch :update, params: { order_id: order.number, id: line_item.prefix_id, line_item: { quantity: 5 } }
+ patch :update, params: { order_id: order.to_param, id: line_item.prefix_id, line_item: { quantity: 5 } }
expect(order.reload.item_total).to be > original_total
end
context 'error handling' do
it 'returns not found for non-existent line item' do
- patch :update, params: { order_id: order.number, id: 0, line_item: { quantity: 5 } }
+ patch :update, params: { order_id: order.to_param, id: 0, line_item: { quantity: 5 } }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('line_item_not_found')
@@ -120,7 +120,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
other_order = create(:order, store: store)
other_line_item = create(:line_item, order: other_order, variant: variant)
- patch :update, params: { order_id: other_order.number, id: other_line_item.prefix_id, line_item: { quantity: 5 } }
+ patch :update, params: { order_id: other_order.to_param, id: other_line_item.prefix_id, line_item: { quantity: 5 } }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -132,23 +132,23 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
let!(:line_item) { create(:line_item, order: order, variant: variant) }
it 'removes line item from order' do
- expect {
- delete :destroy, params: { order_id: order.number, id: line_item.prefix_id }
- }.to change(Spree::LineItem, :count).by(-1)
+ expect do
+ delete :destroy, params: { order_id: order.to_param, id: line_item.prefix_id }
+ end.to change(Spree::LineItem, :count).by(-1)
expect(response).to have_http_status(:no_content)
end
it 'updates order totals' do
order.update_columns(item_total: 100)
- delete :destroy, params: { order_id: order.number, id: line_item.prefix_id }
+ delete :destroy, params: { order_id: order.to_param, id: line_item.prefix_id }
expect(order.reload.item_total).to eq(0)
end
context 'error handling' do
it 'returns not found for non-existent line item' do
- delete :destroy, params: { order_id: order.number, id: 0 }
+ delete :destroy, params: { order_id: order.to_param, id: 0 }
expect(response).to have_http_status(:not_found)
expect(json_response['error']['code']).to eq('line_item_not_found')
@@ -159,7 +159,7 @@ RSpec.describe Spree::Api::V3::Store::Orders::LineItemsController, type: :contro
other_order = create(:order, store: store)
other_line_item = create(:line_item, order: other_order, variant: variant)
- delete :destroy, params: { order_id: other_order.number, id: other_line_item.prefix_id }
+ delete :destroy, params: { order_id: other_order.to_param, id: other_line_item.prefix_id }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
diff --git a/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb b/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb
index a144f45ba9..4a3ac7636a 100644
--- a/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb
+++ b/api/spec/controllers/spree/api/v3/store/orders_controller_spec.rb
@@ -11,9 +11,9 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
describe 'POST #create' do
it 'creates a new cart' do
- expect {
+ expect do
post :create
- }.to change(Spree::Order, :count).by(1)
+ end.to change(Spree::Order, :count).by(1)
expect(response).to have_http_status(:created)
expect(json_response['number']).to be_present
@@ -103,7 +103,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
end
it 'returns the order' do
- get :show, params: { id: order.number }
+ get :show, params: { id: order.to_param }
expect(response).to have_http_status(:ok)
expect(json_response['number']).to eq(order.number)
@@ -111,7 +111,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
end
it 'returns order with expected attributes' do
- get :show, params: { id: order.number }
+ get :show, params: { id: order.to_param }
expect(json_response['id']).to eq(order.prefix_id)
expect(json_response['number']).to eq(order.number)
@@ -123,7 +123,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
it 'returns the order for guest with valid token' do
request.headers['X-Spree-Order-Token'] = guest_order.token
- get :show, params: { id: guest_order.number }
+ get :show, params: { id: guest_order.to_param }
expect(response).to have_http_status(:ok)
expect(json_response['number']).to eq(guest_order.number)
@@ -131,7 +131,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
it 'returns forbidden with invalid token' do
request.headers['X-Spree-Order-Token'] = 'invalid'
- get :show, params: { id: guest_order.number }
+ get :show, params: { id: guest_order.to_param }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -139,7 +139,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
end
it 'returns forbidden without token' do
- get :show, params: { id: guest_order.number }
+ get :show, params: { id: guest_order.to_param }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -161,7 +161,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
it 'returns forbidden for other users order' do
other_order = create(:order_with_line_items, store: store)
- get :show, params: { id: other_order.number }
+ get :show, params: { id: other_order.to_param }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
@@ -178,14 +178,14 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
end
it 'updates the order email' do
- patch :update, params: { id: order.number, order: { email: '[email protected]' } }
+ patch :update, params: { id: order.to_param, order: { email: '[email protected]' } }
expect(response).to have_http_status(:ok)
expect(order.reload.email).to eq('[email protected]')
end
it 'updates special instructions' do
- patch :update, params: { id: order.number, order: { special_instructions: 'Leave at door' } }
+ patch :update, params: { id: order.to_param, order: { special_instructions: 'Leave at door' } }
expect(response).to have_http_status(:ok)
expect(order.reload.special_instructions).to eq('Leave at door')
@@ -197,7 +197,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
it 'updates order for guest with valid token' do
request.headers['X-Spree-Order-Token'] = guest_order.token
- patch :update, params: { id: guest_order.number, order: { email: '[email protected]' } }
+ patch :update, params: { id: guest_order.to_param, order: { email: '[email protected]' } }
expect(response).to have_http_status(:ok)
expect(guest_order.reload.email).to eq('[email protected]')
@@ -211,7 +211,7 @@ RSpec.describe Spree::Api::V3::Store::OrdersController, type: :controller do
it 'returns forbidden for other users order' do
other_order = create(:order_with_line_items, store: store)
- patch :update, params: { id: other_order.number, order: { email: '[email protected]' } }
+ patch :update, params: { id: other_order.to_param, order: { email: '[email protected]' } }
expect(response).to have_http_status(:forbidden)
expect(json_response['error']['code']).to eq('access_denied')
diff --git a/core/app/models/concerns/spree/number_as_param.rb b/core/app/models/concerns/spree/number_as_param.rb
index 13011d9162..f96964d78a 100644
--- a/core/app/models/concerns/spree/number_as_param.rb
+++ b/core/app/models/concerns/spree/number_as_param.rb
@@ -3,9 +3,11 @@ module Spree
extend ActiveSupport::Concern
included do
- extend FriendlyId
-
- friendly_id :number
+ Spree::Deprecation.warn(
+ 'Spree::NumberAsParam is deprecated and will be removed in Spree 6.0. ' \
+ 'Models now use Spree::PrefixedId with prefix_id column instead. ' \
+ 'This concern no longer provides any functionality and can be safely removed.'
+ )
end
end
end
diff --git a/core/app/models/concerns/spree/prefixed_id.rb b/core/app/models/concerns/spree/prefixed_id.rb
index 5cf4f54f99..f1177108c7 100644
--- a/core/app/models/concerns/spree/prefixed_id.rb
+++ b/core/app/models/concerns/spree/prefixed_id.rb
@@ -29,6 +29,15 @@ module Spree
self.prefix_id = nil if respond_to?(:prefix_id=)
end
+ # Use prefix_id for URL params when available
+ # Skip if FriendlyId is used (it has its own to_param using slug)
+ # Skip if model doesn't have the prefix_id column
+ def to_param
+ return super if self.class.respond_to?(:friendly_id_config)
+ return super unless self.class.column_names.include?('prefix_id')
+ prefix_id.presence || super
+ end
+
class_methods do
def has_prefix_id(prefix)
self._prefix_id_prefix = prefix.to_s
diff --git a/core/app/models/spree/export.rb b/core/app/models/spree/export.rb
index 8f2e7c5af3..5c3a8d293b 100644
--- a/core/app/models/spree/export.rb
+++ b/core/app/models/spree/export.rb
@@ -8,7 +8,6 @@ module Spree
include Spree::SingleStoreResource
include Spree::NumberIdentifier
- include Spree::NumberAsParam
include Spree::VendorConcern if defined?(Spree::VendorConcern)
include Spree::Core::NumberGenerator.new(prefix: 'EF')
diff --git a/core/app/models/spree/import.rb b/core/app/models/spree/import.rb
index 264f2c68d2..063f2fe551 100644
--- a/core/app/models/spree/import.rb
+++ b/core/app/models/spree/import.rb
@@ -5,8 +5,6 @@ module Spree
has_prefix_id :imp
include Spree::NumberIdentifier
- include Spree::NumberAsParam
-
include Spree::Core::NumberGenerator.new(prefix: 'IM')
publishes_lifecycle_events
diff --git a/core/app/models/spree/order.rb b/core/app/models/spree/order.rb
index eeb3372e86..6a7c5687dd 100644
--- a/core/app/models/spree/order.rb
+++ b/core/app/models/spree/order.rb
@@ -28,7 +28,6 @@ module Spree
include Spree::Order::GiftCard
include Spree::NumberIdentifier
- include Spree::NumberAsParam
include Spree::SingleStoreResource
publishes_lifecycle_events
diff --git a/core/app/models/spree/payment.rb b/core/app/models/spree/payment.rb
index 90c5200b41..139f60d15a 100644
--- a/core/app/models/spree/payment.rb
+++ b/core/app/models/spree/payment.rb
@@ -6,7 +6,6 @@ module Spree
include Spree::Core::NumberGenerator.new(prefix: 'P', letters: true, length: 7)
include Spree::NumberIdentifier
- include Spree::NumberAsParam
include Spree::Metafields
include Spree::Metadata
if defined?(Spree::Security::Payments)
diff --git a/core/app/models/spree/shipment.rb b/core/app/models/spree/shipment.rb
index fc030fc856..a12924533e 100644
--- a/core/app/models/spree/shipment.rb
+++ b/core/app/models/spree/shipment.rb
@@ -6,7 +6,6 @@ module Spree
include Spree::Core::NumberGenerator.new(prefix: 'H', length: 11)
include Spree::NumberIdentifier
- include Spree::NumberAsParam
include Spree::Metafields
include Spree::Metadata
if defined?(Spree::Security::Shipments)
diff --git a/core/app/models/spree/stock_transfer.rb b/core/app/models/spree/stock_transfer.rb
index 4ec5148e79..05fd3fc1d3 100644
--- a/core/app/models/spree/stock_transfer.rb
+++ b/core/app/models/spree/stock_transfer.rb
@@ -4,7 +4,6 @@ module Spree
include Spree::Core::NumberGenerator.new(prefix: 'T')
include Spree::NumberIdentifier
- include Spree::NumberAsParam
include Spree::Metafields
include Spree::Metadata