Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Enforce strong parameters across admin
Damian Legawiec330fb2389e38
diff --git a/admin/app/controllers/spree/admin/addresses_controller.rb b/admin/app/controllers/spree/admin/addresses_controller.rbindex f078b3189f..a4edc8fea8 100644--- a/admin/app/controllers/spree/admin/addresses_controller.rb+++ b/admin/app/controllers/spree/admin/addresses_controller.rb@@ -81,6 +81,10 @@ module Spreespree.admin_users_urlendend++ def permitted_resource_params+ params.require(:address).permit(Spree::PermittedAttributes.address_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/classifications_controller.rb b/admin/app/controllers/spree/admin/classifications_controller.rbindex 98e08f60af..74ed18256b 100644--- a/admin/app/controllers/spree/admin/classifications_controller.rb+++ b/admin/app/controllers/spree/admin/classifications_controller.rb@@ -69,6 +69,10 @@ module Spreesort_orders.fetch(sort_order.to_s, 'manual')end++ def permitted_resource_params+ params.require(:classification).permit(Spree::PermittedAttributes.classification_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/exports_controller.rb b/admin/app/controllers/spree/admin/exports_controller.rbindex d6d4dd956b..4302194aa3 100644--- a/admin/app/controllers/spree/admin/exports_controller.rb+++ b/admin/app/controllers/spree/admin/exports_controller.rb@@ -40,8 +40,12 @@ module Spreeenddef assign_params- @object.type = params.dig(:export, :type) if Spree::Export.available_types.map(&:to_s).include?(params.dig(:export, :type))- @object.search_params = params.dig(:export, :search_params)+ @object.type = permitted_resource_params[:type] if Spree::Export.available_types.map(&:to_s).include?(permitted_resource_params[:type])+ @object.search_params = permitted_resource_params[:search_params]+ end++ def permitted_resource_params+ params.require(:export).permit(permitted_export_attributes)endendenddiff --git a/admin/app/controllers/spree/admin/integrations_controller.rb b/admin/app/controllers/spree/admin/integrations_controller.rbindex a3855e7556..49c182eae9 100644--- a/admin/app/controllers/spree/admin/integrations_controller.rb+++ b/admin/app/controllers/spree/admin/integrations_controller.rb@@ -52,6 +52,10 @@ module Spreerender action == :create ? :new : :edit, status: :unprocessable_entityendend++ def permitted_resource_params+ params.require(:integration).permit(*permitted_integration_attributes + @object.preferences.keys.map { |key| "preferred_#{key}" })+ endendendenddiff --git a/admin/app/controllers/spree/admin/invitations_controller.rb b/admin/app/controllers/spree/admin/invitations_controller.rbindex 28e7a89cb2..7e88d4e662 100644--- a/admin/app/controllers/spree/admin/invitations_controller.rb+++ b/admin/app/controllers/spree/admin/invitations_controller.rb@@ -113,7 +113,7 @@ module Spreeenddef permitted_params- params.require(:invitation).permit(:email, :expires_at, :role_id)+ params.require(:invitation).permit(Spree::PermittedAttributes.invitation_attributes)enddef choose_layoutdiff --git a/admin/app/controllers/spree/admin/line_items_controller.rb b/admin/app/controllers/spree/admin/line_items_controller.rbindex 9656111ce0..88ec511c0b 100644--- a/admin/app/controllers/spree/admin/line_items_controller.rb+++ b/admin/app/controllers/spree/admin/line_items_controller.rb@@ -116,6 +116,10 @@ module Spreemodel_class.newendend++ def permitted_resource_params+ params.require(:line_item).permit(permitted_line_item_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/oauth_applications_controller.rb b/admin/app/controllers/spree/admin/oauth_applications_controller.rbindex 21de825d17..435b896447 100644--- a/admin/app/controllers/spree/admin/oauth_applications_controller.rb+++ b/admin/app/controllers/spree/admin/oauth_applications_controller.rb@@ -3,6 +3,8 @@ module Spreeclass OauthApplicationsController < ResourceControllerbefore_action :set_default_scopes, only: [:new, :edit]+ add_breadcrumb Spree.t(:developers), :admin_oauth_applications_path+privatedef collection@@ -22,6 +24,10 @@ module Spreedef set_default_scopes@object.scopes = 'admin' if @object.scopes.blank?end++ def permitted_resource_params+ params.require(:oauth_application).permit(:name, :scopes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/option_types_controller.rb b/admin/app/controllers/spree/admin/option_types_controller.rbindex da507a8335..2e24e52713 100644--- a/admin/app/controllers/spree/admin/option_types_controller.rb+++ b/admin/app/controllers/spree/admin/option_types_controller.rb@@ -29,6 +29,10 @@ module Spreeadd_breadcrumb @option_type.presentation, spree.edit_admin_option_type_path(@option_type)endend++ def permitted_resource_params+ params.require(:option_type).permit(permitted_option_type_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/option_values_controller.rb b/admin/app/controllers/spree/admin/option_values_controller.rbindex d535ab723e..c1f237ca9e 100644--- a/admin/app/controllers/spree/admin/option_values_controller.rb+++ b/admin/app/controllers/spree/admin/option_values_controller.rb@@ -16,6 +16,10 @@ module Spreedef location_after_savespree.edit_admin_option_type_path(@parent)end++ def permitted_resource_params+ params.require(:option_value).permit(permitted_option_value_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb b/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rbindex 5f5752d6f5..0f567fbccc 100644--- a/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb+++ b/admin/app/controllers/spree/admin/orders/return_authorizations_controller.rb@@ -84,6 +84,10 @@ module Spreedef model_classSpree::ReturnAuthorizationend++ def permitted_resource_params+ params.require(:return_authorization).permit(permitted_return_authorization_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/page_links_controller.rb b/admin/app/controllers/spree/admin/page_links_controller.rbindex 2e1337b012..068e63ea2b 100644--- a/admin/app/controllers/spree/admin/page_links_controller.rb+++ b/admin/app/controllers/spree/admin/page_links_controller.rb@@ -38,6 +38,15 @@ module Spree@page_link.linkable_type ||= @parent.default_linkable_type@page_link.linkable ||= @parent.default_linkable_resourceend++ # for create action we don't pass the page_link at all+ def permitted_resource_params+ if params[:page_link].present?+ params.require(:page_link).permit(permitted_page_link_attributes)+ else+ {}+ end+ endendendenddiff --git a/admin/app/controllers/spree/admin/page_sections_controller.rb b/admin/app/controllers/spree/admin/page_sections_controller.rbindex 21a8ee3de8..ab8b984a3b 100644--- a/admin/app/controllers/spree/admin/page_sections_controller.rb+++ b/admin/app/controllers/spree/admin/page_sections_controller.rb@@ -69,6 +69,10 @@ module Spree[]endend++ def permitted_resource_params+ params.require(:page_section).permit(permitted_page_section_attributes + @object.preferences.keys.map { |key| "preferred_#{key}" })+ endendendenddiff --git a/admin/app/controllers/spree/admin/pages_controller.rb b/admin/app/controllers/spree/admin/pages_controller.rbindex eb6f12847c..81db90a844 100644--- a/admin/app/controllers/spree/admin/pages_controller.rb+++ b/admin/app/controllers/spree/admin/pages_controller.rb@@ -38,6 +38,10 @@ module Spree@search = @collection.ransack(params[:q])@collection = @search.result.page(params[:page]).per(params[:per_page])end++ def permitted_resource_params+ params.require(:page).permit(permitted_page_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/payment_methods_controller.rb b/admin/app/controllers/spree/admin/payment_methods_controller.rbindex 92d7dc104a..90f8c6b434 100644--- a/admin/app/controllers/spree/admin/payment_methods_controller.rb+++ b/admin/app/controllers/spree/admin/payment_methods_controller.rb@@ -47,6 +47,10 @@ module Spreedef allowed_payment_typesRails.application.config.spree.payment_methodsend++ def permitted_resource_params+ params.require(:payment_method).permit(permitted_payment_method_attributes + @object.preferences.keys.map { |key| "preferred_#{key}" })+ endendendenddiff --git a/admin/app/controllers/spree/admin/products_controller.rb b/admin/app/controllers/spree/admin/products_controller.rbindex b086306e7f..29b10b0796 100644--- a/admin/app/controllers/spree/admin/products_controller.rb+++ b/admin/app/controllers/spree/admin/products_controller.rb@@ -283,14 +283,6 @@ module Spreeclone_admin_product_url resourceend- def permitted_resource_params- if cannot?(:activate, @product) && @new_status&.to_sym == :active- super.except(:status, :make_active_at).permit!- else- super- end- end-privatedef variant_stock_includes@@ -361,6 +353,16 @@ module Spreenew_slug = permitted_resource_params[:slug]permitted_resource_params[:slug] = @product.ensure_slug_is_unique(new_slug)end++ def permitted_resource_params+ @permitted_resource_params ||= begin+ if cannot?(:activate, @product) && @new_status&.to_sym == :active+ params.require(:product).permit(permitted_product_attributes).except(:status, :make_active_at)+ else+ params.require(:product).permit(permitted_product_attributes)+ end+ end+ endendendenddiff --git a/admin/app/controllers/spree/admin/promotion_actions_controller.rb b/admin/app/controllers/spree/admin/promotion_actions_controller.rbindex d70c8c165f..d5f75de39a 100644--- a/admin/app/controllers/spree/admin/promotion_actions_controller.rb+++ b/admin/app/controllers/spree/admin/promotion_actions_controller.rb@@ -46,6 +46,10 @@ module Spree@promotion_action.calculator_type = @promotion_action.class.calculators.first.nameendend++ def permitted_resource_params+ params.require(:promotion_action).permit(permitted_promotion_action_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/promotion_rules_controller.rb b/admin/app/controllers/spree/admin/promotion_rules_controller.rbindex 9a5c8778a7..06a13d0bf6 100644--- a/admin/app/controllers/spree/admin/promotion_rules_controller.rb+++ b/admin/app/controllers/spree/admin/promotion_rules_controller.rb@@ -38,6 +38,10 @@ module Spreedef collection_urlspree.admin_promotion_path(parent)end++ def permitted_resource_params+ params.require(:promotion_rule).permit(*permitted_promotion_rule_attributes + @object.preferences.keys.map { |key| "preferred_#{key}" })+ endendendenddiff --git a/admin/app/controllers/spree/admin/promotions_controller.rb b/admin/app/controllers/spree/admin/promotions_controller.rbindex c0eaeae5e4..1c890c5ab3 100644--- a/admin/app/controllers/spree/admin/promotions_controller.rb+++ b/admin/app/controllers/spree/admin/promotions_controller.rb@@ -58,6 +58,10 @@ module Spree@collectionend++ def permitted_resource_params+ params.require(:promotion).permit(permitted_promotion_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/properties_controller.rb b/admin/app/controllers/spree/admin/properties_controller.rbindex 43740e6ae3..540b5111b5 100644--- a/admin/app/controllers/spree/admin/properties_controller.rb+++ b/admin/app/controllers/spree/admin/properties_controller.rb@@ -29,6 +29,10 @@ module Spreeadd_breadcrumb @property.presentation, spree.edit_admin_property_path(@property)endend++ def permitted_resource_params+ params.require(:property).permit(permitted_property_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/refunds_controller.rb b/admin/app/controllers/spree/admin/refunds_controller.rbindex 71b2cc7cb4..e8422c781b 100644--- a/admin/app/controllers/spree/admin/refunds_controller.rb+++ b/admin/app/controllers/spree/admin/refunds_controller.rb@@ -38,6 +38,10 @@ module Spreedef assign_refunder@refund.refunder = try_spree_current_userend++ def permitted_resource_params+ params.require(:refund).permit(permitted_refund_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/reports_controller.rb b/admin/app/controllers/spree/admin/reports_controller.rbindex 83251e8c1d..4fdfe16da5 100644--- a/admin/app/controllers/spree/admin/reports_controller.rb+++ b/admin/app/controllers/spree/admin/reports_controller.rb@@ -53,6 +53,10 @@ module Spreedef allowed_report_typesRails.application.config.spree.reports.map(&:to_s)end++ def permitted_resource_params+ params.require(:report).permit(permitted_report_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/resource_controller.rb b/admin/app/controllers/spree/admin/resource_controller.rbindex d96959d162..4782520453 100644--- a/admin/app/controllers/spree/admin/resource_controller.rb+++ b/admin/app/controllers/spree/admin/resource_controller.rb@@ -294,7 +294,7 @@ class Spree::Admin::ResourceController < Spree::Admin::BaseController## Other controllers can, should, override it to set custom logicdef permitted_resource_params- params[resource.object_name].present? ? params.require(resource.object_name).permit! : ActionController::Parameters.new+ raise NotImplementedError, "You must implement the permitted_resource_params method"enddef collection_actionsdiff --git a/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rb b/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rbindex fd7a7b135d..7f58f048de 100644--- a/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rb+++ b/admin/app/controllers/spree/admin/return_authorization_reasons_controller.rb@@ -1,6 +1,11 @@module Spreemodule Adminclass ReturnAuthorizationReasonsController < ResourceController+ private++ def permitted_resource_params+ params.require(:return_authorization_reason).permit(permitted_return_authorization_reason_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/return_authorizations_controller.rb b/admin/app/controllers/spree/admin/return_authorizations_controller.rbindex 21fd57b4af..1cacc562df 100644--- a/admin/app/controllers/spree/admin/return_authorizations_controller.rb+++ b/admin/app/controllers/spree/admin/return_authorizations_controller.rb@@ -11,6 +11,10 @@ module Spreeprivate+ def permitted_resource_params+ params.require(:return_authorization).permit(permitted_return_authorization_attributes)+ end+def location_after_destroyspree.edit_admin_order_path(@return_authorization.order)enddiff --git a/admin/app/controllers/spree/admin/return_items_controller.rb b/admin/app/controllers/spree/admin/return_items_controller.rbindex 285fa53278..ba1e127c0d 100644--- a/admin/app/controllers/spree/admin/return_items_controller.rb+++ b/admin/app/controllers/spree/admin/return_items_controller.rb@@ -1,9 +1,15 @@module Spreemodule Adminclass ReturnItemsController < ResourceController+ private+def location_after_savespree.edit_admin_order_customer_return_path(@return_item.customer_return.order, @return_item.customer_return)end++ def permitted_resource_params+ params.require(:return_item).permit(permitted_return_item_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/roles_controller.rb b/admin/app/controllers/spree/admin/roles_controller.rbindex ed351a888c..91a73b1954 100644--- a/admin/app/controllers/spree/admin/roles_controller.rb+++ b/admin/app/controllers/spree/admin/roles_controller.rb@@ -3,6 +3,12 @@ module Spreeclass RolesController < ResourceControlleradd_breadcrumb Spree.t(:users), :admin_admin_users_pathadd_breadcrumb Spree.t(:roles), :admin_roles_path++ private++ def permitted_resource_params+ params.require(:role).permit(permitted_role_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/shipping_categories_controller.rb b/admin/app/controllers/spree/admin/shipping_categories_controller.rbindex c3eee1f92d..30cd1de8b9 100644--- a/admin/app/controllers/spree/admin/shipping_categories_controller.rb+++ b/admin/app/controllers/spree/admin/shipping_categories_controller.rb@@ -2,6 +2,12 @@ module Spreemodule Adminclass ShippingCategoriesController < ResourceControlleradd_breadcrumb Spree.t(:shipping_categories), :admin_shipping_categories_path++ private++ def permitted_resource_params+ params.require(:shipping_category).permit(permitted_shipping_category_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/shipping_methods_controller.rb b/admin/app/controllers/spree/admin/shipping_methods_controller.rbindex 6e84dd3dd7..bc5d9c07a6 100644--- a/admin/app/controllers/spree/admin/shipping_methods_controller.rb+++ b/admin/app/controllers/spree/admin/shipping_methods_controller.rb@@ -26,6 +26,10 @@ module Spreedef update_turbo_stream_enabled?trueend++ def permitted_resource_params+ params.require(:shipping_method).permit(permitted_shipping_method_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/stock_items_controller.rb b/admin/app/controllers/spree/admin/stock_items_controller.rbindex 0b32cef580..b10f71536f 100644--- a/admin/app/controllers/spree/admin/stock_items_controller.rb+++ b/admin/app/controllers/spree/admin/stock_items_controller.rb@@ -29,6 +29,10 @@ module Spreeadd_breadcrumb Spree.t(:stock), spree.admin_stock_items_pathadd_breadcrumb Spree.t(:stock_items), spree.admin_stock_items_pathend++ def permitted_resource_params+ params.require(:stock_item).permit(permitted_stock_item_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/stock_locations_controller.rb b/admin/app/controllers/spree/admin/stock_locations_controller.rbindex c58bd8a6ab..5cddc62602 100644--- a/admin/app/controllers/spree/admin/stock_locations_controller.rb+++ b/admin/app/controllers/spree/admin/stock_locations_controller.rb@@ -5,6 +5,7 @@ module Spreeadd_breadcrumb Spree.t(:stock_locations), :admin_stock_locations_path+ # PUT /admin/stock_locations/:id/mark_as_defaultdef mark_as_default@stock_location.update(default: true)@@ -21,6 +22,10 @@ module Spreedef set_country@stock_location.country = current_store.default_countryend++ def permitted_resource_params+ params.require(:stock_location).permit(permitted_stock_location_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/stock_transfers_controller.rb b/admin/app/controllers/spree/admin/stock_transfers_controller.rbindex d41919bec3..5d424bf238 100644--- a/admin/app/controllers/spree/admin/stock_transfers_controller.rb+++ b/admin/app/controllers/spree/admin/stock_transfers_controller.rb@@ -26,8 +26,7 @@ module Spreeenddef permitted_resource_params- params.require(:stock_transfer).permit(:source_location_id, :destination_location_id, :reference,- stock_movements_attributes: [:variant_id, :quantity, :originator_id, :stock_item_id])+ params.require(:stock_transfer).permit(permitted_stock_transfer_attributes)enddef prepare_paramsdiff --git a/admin/app/controllers/spree/admin/store_credit_categories_controller.rb b/admin/app/controllers/spree/admin/store_credit_categories_controller.rbindex cb40f19e62..fe6974e8c5 100644--- a/admin/app/controllers/spree/admin/store_credit_categories_controller.rb+++ b/admin/app/controllers/spree/admin/store_credit_categories_controller.rb@@ -1,6 +1,11 @@module Spreemodule Adminclass StoreCreditCategoriesController < ResourceController+ private++ def permitted_resource_params+ params.require(:store_credit_category).permit(permitted_store_credit_category_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/tax_categories_controller.rb b/admin/app/controllers/spree/admin/tax_categories_controller.rbindex c7219e00b3..b6f6f6985e 100644--- a/admin/app/controllers/spree/admin/tax_categories_controller.rb+++ b/admin/app/controllers/spree/admin/tax_categories_controller.rb@@ -2,6 +2,12 @@ module Spreemodule Adminclass TaxCategoriesController < ResourceControlleradd_breadcrumb Spree.t(:tax_categories), :admin_tax_categories_path++ private++ def permitted_resource_params+ params.require(:tax_category).permit(permitted_tax_category_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/tax_rates_controller.rb b/admin/app/controllers/spree/admin/tax_rates_controller.rbindex 1d66d83071..7d180c64e5 100644--- a/admin/app/controllers/spree/admin/tax_rates_controller.rb+++ b/admin/app/controllers/spree/admin/tax_rates_controller.rb@@ -17,6 +17,10 @@ module Spree@available_categories = Spree::TaxCategory.order(:name)@calculators = Spree::TaxRate.calculators.sort_by(&:name)end++ def permitted_resource_params+ params.require(:tax_rate).permit(permitted_tax_rate_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/taxonomies_controller.rb b/admin/app/controllers/spree/admin/taxonomies_controller.rbindex 0e66ffc8b7..1782b59508 100644--- a/admin/app/controllers/spree/admin/taxonomies_controller.rb+++ b/admin/app/controllers/spree/admin/taxonomies_controller.rb@@ -27,6 +27,10 @@ module Spreeadd_breadcrumb @taxonomy.name, spree.admin_taxonomy_path(@taxonomy)endend++ def permitted_resource_params+ params.require(:taxonomy).permit(permitted_taxonomy_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/taxons_controller.rb b/admin/app/controllers/spree/admin/taxons_controller.rbindex 77f2663323..1926880d6e 100644--- a/admin/app/controllers/spree/admin/taxons_controller.rb+++ b/admin/app/controllers/spree/admin/taxons_controller.rb@@ -112,6 +112,10 @@ module Spreeadd_breadcrumb @object.name, spree.edit_admin_taxonomy_taxon_path(@taxonomy, @object.id)endend++ def permitted_resource_params+ params.require(:taxon).permit(permitted_taxon_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/themes_controller.rb b/admin/app/controllers/spree/admin/themes_controller.rbindex b06b659f71..5b1f13f0a5 100644--- a/admin/app/controllers/spree/admin/themes_controller.rb+++ b/admin/app/controllers/spree/admin/themes_controller.rb@@ -73,6 +73,10 @@ module Spreedef collectionsuper.without_previews.order(default: :desc).includes(screenshot_attachment: :blob)end++ def permitted_resource_params+ params.require(:theme).permit(permitted_theme_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/variants_controller.rb b/admin/app/controllers/spree/admin/variants_controller.rbindex 9ec66453a4..f05790836e 100644--- a/admin/app/controllers/spree/admin/variants_controller.rb+++ b/admin/app/controllers/spree/admin/variants_controller.rb@@ -94,6 +94,10 @@ module Spreeadd_breadcrumb @variant.human_name, spree.edit_admin_product_variant_path(@product, @variant)endend++ def permitted_resource_params+ params.require(:variant).permit(permitted_variant_attributes)+ endendendenddiff --git a/admin/app/controllers/spree/admin/zones_controller.rb b/admin/app/controllers/spree/admin/zones_controller.rbindex af187ae3a0..bfe9d467be 100644--- a/admin/app/controllers/spree/admin/zones_controller.rb+++ b/admin/app/controllers/spree/admin/zones_controller.rb@@ -33,6 +33,10 @@ module Spree@states = @selected_country&.states&.order(:name) || Spree::State.none@zones = Zone.order(:name)end++ def permitted_resource_params+ params.require(:zone).permit(permitted_zone_attributes)+ endendendenddiff --git a/admin/app/views/spree/admin/page_links/_list.html.erb b/admin/app/views/spree/admin/page_links/_list.html.erbindex 9e7b3708f7..9e98bc77b0 100644--- a/admin/app/views/spree/admin/page_links/_list.html.erb+++ b/admin/app/views/spree/admin/page_links/_list.html.erb@@ -26,9 +26,9 @@<% if show_add_link_button %><% if parent.is_a?(Spree::PageSection) %>- <% add_url = admin_page_section_links_path(parent) %>+ <% add_url = spree.admin_page_section_links_path(parent) %><% elsif parent.is_a?(Spree::PageBlock) %>- <% add_url = admin_page_section_block_links_path(parent.section, parent) %>+ <% add_url = spree.admin_page_section_block_links_path(parent.section, parent) %><% end %><%= link_to_with_icon 'plus', 'Add link', add_url, class: 'btn btn-primary w-100', data: { turbo_method: :post } if add_url && can?(:create, Spree::PageLink.new(parent: parent)) %>diff --git a/admin/app/views/spree/admin/zones/_form.html.erb b/admin/app/views/spree/admin/zones/_form.html.erbindex 44ef21db4b..a8aa65b88e 100644--- a/admin/app/views/spree/admin/zones/_form.html.erb+++ b/admin/app/views/spree/admin/zones/_form.html.erb@@ -17,26 +17,22 @@<%= zone_form.text_field :description, class: 'form-control' %></div>- <div class="form-group checkbox">- <%= label_tag "zone[#{:default_tax}" do %>- <%= zone_form.check_box :default_tax %>- <%= Spree.t(:default_tax_zone) %>- <% end %>+ <div class="form-group">+ <div class="custom-control custom-checkbox">+ <%= zone_form.check_box :default_tax, class: 'custom-control-input' %>+ <%= zone_form.label :default_tax, Spree.t(:default_tax_zone), class: 'custom-control-label' %>+ </div></div><div class="form-group"><strong><%= Spree.t(:type) %></strong>- <div class="radio my-2">- <%= label_tag :country_based do %>- <%= zone_form.radio_button :kind, :country, id: 'country_based', data: { action: 'auto-submit#submit' } %>- <%= Spree.t(:country_based) %>- <% end %>+ <div class="custom-control custom-radio my-2">+ <%= zone_form.radio_button :kind, :country, id: 'country_based', class: 'custom-control-input', data: { action: 'auto-submit#submit' } %>+ <%= label_tag :country_based, Spree.t(:country_based), class: 'custom-control-label' %></div>- <div class="radio my-2">- <%= label_tag :state_based do %>- <%= zone_form.radio_button :kind, :state, id: 'state_based', data: { action: 'auto-submit#submit' } %>- <%= Spree.t(:state_based) %>- <% end %>+ <div class="custom-control custom-radio my-2">+ <%= zone_form.radio_button :kind, :state, id: 'state_based', class: 'custom-control-input', data: { action: 'auto-submit#submit' } %>+ <%= label_tag :state_based, Spree.t(:state_based), class: 'custom-control-label' %></div></div></div>diff --git a/admin/spec/controllers/spree/admin/classifications_controller_spec.rb b/admin/spec/controllers/spree/admin/classifications_controller_spec.rbindex 30e87e4848..fbb7b0f59b 100644--- a/admin/spec/controllers/spree/admin/classifications_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/classifications_controller_spec.rb@@ -58,6 +58,21 @@ RSpec.describe Spree::Admin::ClassificationsController, type: :controller doendend+ 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 } }++ it 'updates the classification' do+ expect { subject }.to change { classification.reload.position }.from(1).to(2)+ end++ it 'returns a successful response' do+ subject+ expect(response).to have_http_status(:success)+ end+ end+describe 'DELETE #destroy' dolet!(:classification) { create(:classification, taxon: taxon, product: product1) }diff --git a/admin/spec/controllers/spree/admin/integrations_controller_spec.rb b/admin/spec/controllers/spree/admin/integrations_controller_spec.rbnew file mode 100644index 0000000000..989ce7fdd0--- /dev/null+++ b/admin/spec/controllers/spree/admin/integrations_controller_spec.rb@@ -0,0 +1,114 @@+require 'spec_helper'++module Spree+ module Integrations+ class DummyIntegration < Spree::Integration+ validates :preferred_api_key, presence: true++ preference :api_key, :string++ def can_connect?+ true+ end+ end+ end+end++describe Spree::Admin::IntegrationsController, type: :controller do+ stub_authorization!++ let(:store) { Spree::Store.default }+ let(:integration_type) { Spree::Integrations::DummyIntegration }++ before do+ allow(Rails.application.config.spree).to receive(:integrations).and_return([integration_type])+ allow_any_instance_of(described_class).to receive(:current_store).and_return(store)+ end++ describe 'GET #new' do+ context 'without integration type param' do+ it 'redirects to integrations path' do+ get :new+ expect(response).to redirect_to(spree.admin_integrations_path)+ end+ end++ context 'with integration type param' do+ it 'renders new template' do+ get :new, params: { integration: { type: integration_type } }+ expect(response).to render_template(:new)+ end+ end++ context 'when integration already exists for store' do+ before do+ Spree::Integrations::DummyIntegration.create!(store: store, preferred_api_key: 'APIKEY')+ end++ it 'redirects to integrations path' do+ get :new, params: { integration: { type: integration_type } }+ expect(response).to redirect_to(spree.admin_integrations_path)+ end+ end+ end++ describe 'POST #create' do+ context 'with invalid integration type' do+ it 'redirects with error' do+ post :create, params: { integration: { type: 'Invalid' } }+ expect(response).to redirect_to(spree.admin_integrations_path)+ expect(flash[:error]).to be_present+ end+ end++ context 'with valid integration type' do+ it 'creates new integration' do+ expect {+ post :create, params: { integration: { type: integration_type, preferred_api_key: 'APIKEY' } }+ }.to change(Spree::Integrations::DummyIntegration, :count).by(1)++ integration = Spree::Integrations::DummyIntegration.first+ expect(response).to redirect_to(spree.edit_admin_integration_path(integration))+ expect(integration.preferred_api_key).to eq('APIKEY')+ end+ end++ context 'when integration cannot connect' do+ before do+ allow_any_instance_of(integration_type).to receive(:can_connect?).and_return(false)+ end++ it 'renders new with error' do+ post :create, params: { integration: { type: integration_type, preferred_api_key: 'WRONGKEY' } }+ expect(response).to render_template(:new)+ expect(response.status).to eq(422)+ end+ end+ end++ describe 'PUT #update' 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' } }+ expect(response).to redirect_to(spree.edit_admin_integration_path(integration))+ expect(integration.reload.preferred_api_key).to eq('NEWKEY')+ end+ end++ describe 'DELETE #destroy' do+ let!(:integration) { Spree::Integrations::DummyIntegration.create!(store: store, preferred_api_key: 'APIKEY') }++ it 'destroys the integration' do+ expect {+ delete :destroy, params: { id: integration.id }+ }.to change(Spree::Integrations::DummyIntegration, :count).by(-1)+ end++ it 'redirects to index with success flash' do+ delete :destroy, params: { id: integration.id }+ expect(response).to redirect_to(spree.admin_integrations_path)+ expect(flash[:success]).to be_present+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/oauth_applications_controller_spec.rb b/admin/spec/controllers/spree/admin/oauth_applications_controller_spec.rbnew file mode 100644index 0000000000..8224d58886--- /dev/null+++ b/admin/spec/controllers/spree/admin/oauth_applications_controller_spec.rb@@ -0,0 +1,116 @@+require 'spec_helper'++describe Spree::Admin::OauthApplicationsController, type: :controller do+ stub_authorization!++ render_views++ describe '#index' do+ let!(:oauth_application) { create(:oauth_application) }++ it 'responds successfully' do+ get :index+ expect(response).to be_successful+ end+ end++ describe '#new' do+ it 'responds successfully' do+ get :new+ expect(response).to be_successful+ end++ it 'sets default scopes to admin' do+ get :new+ expect(assigns(:object).scopes.to_s).to eq('admin')+ end+ end++ describe '#create' do+ let(:params) do+ {+ oauth_application: {+ name: 'Test App',+ scopes: 'admin read'+ }+ }+ end++ it 'creates a new oauth application' do+ expect {+ post :create, params: params+ }.to change(Spree::OauthApplication, :count).by(1)+ end++ it 'sets the attributes' do+ post :create, params: params+ oauth_app = Spree::OauthApplication.last+ expect(oauth_app.name).to eq('Test App')+ expect(oauth_app.scopes.to_s).to eq('admin read')+ end++ it 'redirects to index with success flash' do+ post :create, params: params+ oauth_app = Spree::OauthApplication.last+ expect(response).to redirect_to(spree.edit_admin_oauth_application_path(oauth_app))+ expect(flash[:success]).to be_present+ end+ end++ describe '#edit' do+ let!(:oauth_application) { create(:oauth_application) }++ it 'responds successfully' do+ get :edit, params: { id: oauth_application.id }+ expect(response).to be_successful+ end++ it 'sets default scopes to admin if blank' do+ oauth_application.update(scopes: '')+ get :edit, params: { id: oauth_application.id }+ expect(assigns(:object).scopes.to_s).to eq('admin')+ end+ end++ describe '#update' do+ let!(:oauth_application) { create(:oauth_application) }+ let(:params) do+ {+ id: oauth_application.id,+ oauth_application: {+ name: 'Updated App',+ scopes: 'admin write'+ }+ }+ end++ it 'updates the oauth application' do+ put :update, params: params+ oauth_application.reload+ expect(oauth_application.name).to eq('Updated App')+ expect(oauth_application.scopes.to_s).to eq('admin write')+ end++ it 'redirects to index with success flash' do+ put :update, params: params+ expect(response).to redirect_to(spree.edit_admin_oauth_application_path(oauth_application))+ expect(flash[:success]).to be_present+ end+ end++ describe '#destroy' do+ let!(:oauth_application) { create(:oauth_application) }++ it 'destroys the oauth application' do+ expect {+ delete :destroy, params: { id: oauth_application.id }+ }.to change(Spree::OauthApplication, :count).by(-1)+ end++ it 'redirects to index with success flash' do+ delete :destroy, params: { id: oauth_application.id }+ expect(response).to redirect_to(spree.admin_oauth_applications_path)+ expect(flash[:success]).to be_present+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/option_types_controller_spec.rb b/admin/spec/controllers/spree/admin/option_types_controller_spec.rbnew file mode 100644index 0000000000..6c42064fad--- /dev/null+++ b/admin/spec/controllers/spree/admin/option_types_controller_spec.rb@@ -0,0 +1,137 @@+require 'spec_helper'++describe Spree::Admin::OptionTypesController, type: :controller do+ stub_authorization!++ render_views++ describe '#index' do+ let!(:option_type) { create(:option_type) }++ it 'responds successfully' do+ get :index+ expect(response).to be_successful+ end+ end++ describe '#new' do+ it 'responds successfully' do+ get :new+ expect(response).to be_successful+ end+ end++ describe '#create' do+ let(:params) do+ {+ option_type: {+ name: 'test-option-type',+ presentation: 'Test Option Type',+ option_values_attributes: [+ {+ name: 'test-option-value',+ presentation: 'Test Option Value'+ }+ ]+ }+ }+ end++ it 'creates a new option type' do+ expect {+ post :create, params: params+ }.to change(Spree::OptionType, :count).by(1).and change(Spree::OptionValue, :count).by(1)+ end++ it 'sets the attributes' do+ post :create, params: params+ option_type = Spree::OptionType.last+ expect(option_type.name).to eq('test-option-type')+ expect(option_type.presentation).to eq('Test Option Type')+ expect(option_type.option_values.first.name).to eq('test-option-value')+ end++ it 'redirects to edit with success flash' do+ post :create, params: params+ expect(response).to redirect_to(spree.edit_admin_option_type_path(Spree::OptionType.last))+ expect(flash[:success]).to be_present+ end+ end++ describe '#edit' do+ let!(:option_type) { create(:option_type) }++ it 'responds successfully' do+ get :edit, params: { id: option_type.id }+ expect(response).to be_successful+ end++ it 'builds a new option value if none exist' do+ get :edit, params: { id: option_type.id }+ expect(assigns(:option_type).option_values.select(&:new_record?).count).to eq(1)+ end+ end++ describe '#update' do+ let!(:option_type) { create(:option_type, filterable: false) }+ let!(:option_value) { create(:option_value, option_type: option_type, position: 1) }+ let(:params) do+ {+ id: option_type.id,+ option_type: {+ name: 'updated-name',+ presentation: 'Updated Name',+ position: 3,+ filterable: true,+ option_values_attributes: [+ {+ id: option_value.id,+ name: 'updated-option-value',+ presentation: 'Updated Option Value',+ position: 2+ },+ {+ name: 'new-option-value',+ presentation: 'New Option Value',+ position: 1+ }+ ]+ }+ }+ end++ it 'updates the option type and option value' do+ put :update, params: params+ option_type.reload+ expect(option_type.name).to eq('updated-name')+ expect(option_type.presentation).to eq('Updated Name')+ expect(option_type.position).to eq(3)+ expect(option_type.filterable).to be_truthy+ expect(option_type.option_values.count).to eq(2)+ expect(option_type.option_values.first.name).to eq('new-option-value')+ expect(option_type.option_values.last.name).to eq('updated-option-value')+ end++ it 'redirects to edit with success flash' do+ put :update, params: params+ expect(response).to redirect_to(spree.edit_admin_option_type_path(option_type))+ expect(flash[:success]).to be_present+ end+ end++ describe '#destroy' do+ let!(:option_type) { create(:option_type) }++ it 'destroys the option type' do+ expect {+ delete :destroy, params: { id: option_type.id }+ }.to change(Spree::OptionType, :count).by(-1)+ end++ it 'redirects to index with success flash' do+ delete :destroy, params: { id: option_type.id }+ expect(response).to redirect_to(spree.admin_option_types_path)+ expect(flash[:success]).to be_present+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/option_values_controller_spec.rb b/admin/spec/controllers/spree/admin/option_values_controller_spec.rbnew file mode 100644index 0000000000..efc8af7d6f--- /dev/null+++ b/admin/spec/controllers/spree/admin/option_values_controller_spec.rb@@ -0,0 +1,64 @@+require 'spec_helper'++RSpec.describe Spree::Admin::OptionValuesController do+ stub_authorization!++ render_views++ let(:option_type) { create(:option_type) }+ let(:option_value) { create(:option_value, option_type: option_type) }++ describe 'PATCH #update' do+ context 'with turbo_stream format' do+ let(:option_value_params) do+ {+ position: 2+ }+ end++ before do+ patch :update, params: {+ option_type_id: option_type.id,+ id: option_value.id,+ option_value: option_value_params,+ format: :turbo_stream+ }+ end++ it 'updates the option value' do+ option_value.reload+ expect(option_value.position).to eq(2)+ end++ it 'returns success status' do+ expect(response).to be_successful+ end+ end+ end++ describe 'GET #select_options' 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 }+ end++ it 'returns success status' do+ expect(response).to be_successful+ end++ it 'returns JSON format' do+ expect(response.content_type).to include('application/json')+ end++ it 'returns option values in tom select format' do+ json_response = JSON.parse(response.body)+ expect(json_response).to be_an(Array)+ expect(json_response.first).to eq({+ id: option_value.id,+ name: option_value.presentation+ }.stringify_keys)+ expect(json_response.length).to eq(4)+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/orders/user_controller_spec.rb b/admin/spec/controllers/spree/admin/orders/user_controller_spec.rbindex 6fa860d21c..21408e94d1 100644--- a/admin/spec/controllers/spree/admin/orders/user_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/orders/user_controller_spec.rb@@ -2,6 +2,7 @@ require 'spec_helper'RSpec.describe Spree::Admin::Orders::UserController, type: :controller dostub_authorization!+ render_viewslet(:order) { create(:order, user: nil, email: nil) }let(:user_params) dodiff --git a/admin/spec/controllers/spree/admin/page_links_controller_spec.rb b/admin/spec/controllers/spree/admin/page_links_controller_spec.rbindex bf951790bd..7e922f7d37 100644--- a/admin/spec/controllers/spree/admin/page_links_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/page_links_controller_spec.rb@@ -82,13 +82,14 @@ RSpec.describe Spree::Admin::PageLinksController, type: :controller dodescribe '#update' dosubject :post_update do- post :update, params: { id: page_link.id, page_link: { label: 'New Label' } }, as: :turbo_stream+ post :update, params: { id: page_link.id, page_link: { label: 'New Label', position: 2 } }, as: :turbo_streamendlet(:page_link) { create(:page_link) }it 'updates the page link' doexpect { post_update }.to change { page_link.reload.label }.to 'New Label'+ expect(page_link.reload.position).to eq(2)endit 'renders the update template' dodiff --git a/admin/spec/controllers/spree/admin/page_sections_controller_spec.rb b/admin/spec/controllers/spree/admin/page_sections_controller_spec.rbindex 5764bd6945..576e6eb27c 100644--- a/admin/spec/controllers/spree/admin/page_sections_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/page_sections_controller_spec.rb@@ -13,6 +13,13 @@ RSpec.describe Spree::Admin::PageSectionsController, type: :controller dosession[:theme_preview_id] = theme.idend+ describe '#new' do+ it 'renders the new template' do+ get :new, params: { page_id: page.id }+ expect(response).to render_template(:new)+ end+ end+describe '#create' dosubject { post :create, params: params, format: :turbo_stream }@@ -53,6 +60,22 @@ RSpec.describe Spree::Admin::PageSectionsController, type: :controller doendend+ describe '#update' do+ let!(:page_section) { create(:header_page_section, pageable: theme) }++ it 'updates the page section' do+ put :update, params: { id: page_section.id, page_section: { preferred_top_padding: 100 } }, format: :turbo_stream++ expect(page_section.reload.preferred_top_padding).to eq(100)+ end++ it 'can attach an asset' do+ put :update, params: { id: page_section.id, page_section: { asset: fixture_file_upload('logo.png', 'image/png') } }, format: :turbo_stream++ expect(page_section.reload.asset).to be_attached+ end+ end+describe '#destroy' docontext 'when page section can be deleted' dolet!(:page_section) { create(:featured_taxon_page_section, pageable: page) }diff --git a/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rb b/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rbindex 7ead75b795..79f4235a98 100644--- a/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/payment_methods_controller_spec.rb@@ -3,6 +3,8 @@ require 'spec_helper'describe Spree::Admin::PaymentMethodsController, type: :controller dostub_authorization!+ render_views+describe '#index' doit 'renders the index template' doget :index@@ -32,8 +34,34 @@ describe Spree::Admin::PaymentMethodsController, type: :controller doenddescribe '#create' do+ let(:payment_method_params) do+ {+ name: 'Bogus Gateway',+ type: 'Spree::Gateway::Bogus',+ description: 'Bogus Gateway Description',+ active: true,+ display_on: 'both',+ auto_capture: true,+ position: 1,+ preferred_dummy_key: 'DUMMY_KEY',+ preferred_dummy_secret_key: 'DUMMY_SECRET_KEY'+ }+ end+it 'creates the payment method' do- expect { post :create, params: { payment_method: { type: 'Spree::Gateway::Bogus' } } }.to change(Spree::Gateway::Bogus, :count).by(1)+ expect { post :create, params: { payment_method: payment_method_params } }.to change(Spree::Gateway::Bogus, :count).by(1)++ payment_method = Spree::Gateway::Bogus.last+ expect(payment_method.name).to eq('Bogus Gateway')+ expect(payment_method.description).to eq('Bogus Gateway Description')+ expect(payment_method.active).to be_truthy+ expect(payment_method.display_on).to eq('both')+ expect(payment_method.auto_capture).to be_truthy+ expect(payment_method.position).to eq(1)+ expect(payment_method.preferred_dummy_key).to eq('DUMMY_KEY')+ expect(payment_method.preferred_dummy_secret_key).to eq('DUMMY_SECRET_KEY')++ expect(response).to redirect_to(spree.edit_admin_payment_method_path(payment_method))endend@@ -52,6 +80,8 @@ describe Spree::Admin::PaymentMethodsController, type: :controller doexpect { subject }.to change { payment_method.reload.preferred_dummy_key }.to('NEW_VALUE').and(change { payment_method.reload.preferred_dummy_secret_key }.to('NEW_SECRET_VALUE'))++ expect(response).to redirect_to(spree.edit_admin_payment_method_path(payment_method))endcontext 'for empty password type preference' do@@ -67,5 +97,41 @@ describe Spree::Admin::PaymentMethodsController, type: :controller doexpect(payment_method.preferred_dummy_secret_key).to eq('SECRETKEY123')endend++ context 'changing position' do+ let(:payment_method_params) do+ {+ position: 2+ }+ end++ it 'updates the payment method' do+ expect { subject }.to change { payment_method.reload.position }.to(2)+ end+ end++ context 'changing display_on' do+ let(:payment_method_params) do+ {+ display_on: 'back_end'+ }+ end++ it 'updates the payment method' do+ expect { subject }.to change { payment_method.reload.display_on }.to('back_end')+ end+ end++ context 'changing active' do+ let(:payment_method_params) do+ {+ active: false+ }+ end++ it 'updates the payment method' do+ expect { subject }.to change { payment_method.reload.active }.to(false)+ end+ endendenddiff --git a/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rb b/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rbindex 898d12bcf8..05f41edd97 100644--- a/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/promotion_actions_controller_spec.rb@@ -38,7 +38,13 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller dolet(:action_type) { 'Spree::Promotion::Actions::CreateAdjustment' }let(:action_params) do{- type: action_type+ type: action_type,+ calculator_type: 'Spree::Calculator::FlatRate',+ calculator_attributes: {+ type: 'Spree::Calculator::FlatRate',+ preferred_amount: 20.0,+ preferred_currency: 'EUR'+ }}end@@ -46,6 +52,9 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller doexpect {post :create, params: { promotion_id: promotion.id, promotion_action: action_params }}.to change(Spree::PromotionAction, :count).by(1)++ expect(assigns(:promotion_action).calculator.preferred_amount).to eq(20.0)+ expect(assigns(:promotion_action).calculator.preferred_currency).to eq('EUR')endit 'redirects to the promotion page' do@@ -100,6 +109,32 @@ RSpec.describe Spree::Admin::PromotionActionsController, type: :controller dopatch :update, params: { promotion_id: promotion.id, id: promotion_action.id, promotion_action: update_params }expect(response).to redirect_to(spree.admin_promotion_path(promotion))end++ context 'create line items type' do+ let!(:promotion_action) { create(:promotion_action_create_line_items, promotion: promotion) }+ let(:action_type) { 'Spree::Promotion::Actions::CreateLineItems' }+ let(:product) { create(:product, stores: [store]) }+ let(:variant) { create(:variant, product: product) }+ let(:action_params) do+ {+ type: action_type,+ promotion_action_line_items_attributes: {+ '0' => {+ promotion_action_id: promotion_action.id,+ variant_id: variant.id,+ quantity: 2,+ _destroy: nil+ }+ }+ }+ end++ it 'sets the promotion action line items' do+ patch :update, params: { promotion_id: promotion.id, id: promotion_action.id, 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+ endenddescribe 'DELETE #destroy' dodiff --git a/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rb b/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rbindex 9c6b42de1e..825db3236e 100644--- a/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/promotion_rules_controller_spec.rb@@ -63,6 +63,26 @@ RSpec.describe Spree::Admin::PromotionRulesController, type: :controller do}.to raise_error('Unknown promotion rule type')endend++ context 'with preferences' do+ let(:rule_params) do+ {+ type: 'Spree::Promotion::Rules::Country',+ preferred_country_iso: 'US'+ }+ end++ it 'creates a new promotion rule' do+ expect {+ post :create, params: { promotion_id: promotion.id, 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 }+ expect(assigns(:promotion_rule).preferred_country_iso).to eq('US')+ end+ endenddescribe 'GET #edit' dodiff --git a/admin/spec/controllers/spree/admin/promotions_controller_spec.rb b/admin/spec/controllers/spree/admin/promotions_controller_spec.rbindex 10ca4d4757..321bb51669 100644--- a/admin/spec/controllers/spree/admin/promotions_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/promotions_controller_spec.rb@@ -97,6 +97,38 @@ RSpec.describe Spree::Admin::PromotionsController, type: :controller dopost :create, params: { promotion: promotion_params }expect(response).to redirect_to(spree.admin_promotion_path(assigns[:promotion]))end++ context 'multi code promotion' do+ let(:promotion_params) do+ {+ name: 'New Promotion',+ kind: 'coupon_code',+ number_of_codes: 10,+ multi_codes: true,+ code_prefix: 'PRM'+ }+ end++ it 'creates a new promotion' do+ expect {+ post :create, params: { promotion: promotion_params }+ }.to change(Spree::Promotion, :count).by(1)+ promotion = Spree::Promotion.last+ expect(promotion.name).to eq('New Promotion')+ expect(promotion.kind).to eq('coupon_code')+ expect(promotion.code_prefix).to eq('PRM')+ expect(promotion.multi_codes).to be_truthy+ expect(promotion.number_of_codes).to eq(10)+ end++ it 'creates the correct number of coupon codes' do+ expect {+ post :create, params: { promotion: promotion_params }+ }.to change(Spree::CouponCode, :count).by(10)+ promotion = Spree::Promotion.last+ expect(promotion.coupon_codes.count).to eq(10)+ end+ endenddescribe 'GET #edit' dodiff --git a/admin/spec/controllers/spree/admin/properties_controller_spec.rb b/admin/spec/controllers/spree/admin/properties_controller_spec.rbindex dba2c0985b..b732cc09c8 100644--- a/admin/spec/controllers/spree/admin/properties_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/properties_controller_spec.rb@@ -25,7 +25,14 @@ describe Spree::Admin::PropertiesController, type: :controller dodescribe '#create ' doit 'creates a property' do- expect { post :create, params: {property: {name: 'New Property', presentation: 'New Presentation'}} }.to change(Spree::Property, :count).by(1)+ expect { post :create, params: {property: {name: 'New Property', presentation: 'New Presentation', kind: 'long_text', display_on: 'both'}} }.to change(Spree::Property, :count).by(1)+ property = Spree::Property.last+ expect(property.name).to eq('new-property')+ expect(property.presentation).to eq('New Presentation')+ expect(property.kind).to eq('long_text')+ expect(property.display_on).to eq('both')++ expect(response).to redirect_to(spree.edit_admin_property_path(property))endenddiff --git a/admin/spec/controllers/spree/admin/refunds_controller_spec.rb b/admin/spec/controllers/spree/admin/refunds_controller_spec.rbindex 41502d83be..c57750f428 100644--- a/admin/spec/controllers/spree/admin/refunds_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/refunds_controller_spec.rb@@ -10,25 +10,29 @@ describe Spree::Admin::RefundsController, type: :controller doallow(controller).to receive(:current_ability).and_return(Spree::Dependencies.ability_class.constantize.new(user))end+ let(:order) { create(:completed_order_with_totals) }+ let(:payment) { create(:payment, amount: payment_amount, order: order) }+ let(:payment_amount) { amount * 2 }+ let(:amount) { 10.0 }+describe '#create' docontext 'when successful' dosubject dopost :create, params: {refund: { amount: amount.to_s, refund_reason_id: refund_reason.id.to_s },- order_id: payment.order.to_param,+ order_id: order.to_param,payment_id: payment.to_param}endlet!(:refund_reason) { create(:refund_reason) }- let(:payment) { create(:payment, amount: payment_amount, order: create(:completed_order_with_totals)) }- let(:payment_amount) { amount * 2 }- let(:amount) { 10.0 }let(:amount_in_cents) { amount * 100 }let(:authorization) { generate(:refund_transaction_id) }it 'creates refund' doexpect { subject }.to change { Spree::Refund.count }.from(0).to(1)++ expect(response).to redirect_to spree.edit_admin_order_path(payment.order)endit 'assigns refunder to created refund' do@@ -38,4 +42,17 @@ describe Spree::Admin::RefundsController, type: :controller doendendend++ 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 } } }++ let(:refund) { create(:refund, amount: 10, payment: payment) }+ let(:refund_reason) { create(:refund_reason) }++ it 'updates the refund' do+ subject++ expect(response).to redirect_to spree.edit_admin_order_path(refund.payment.order)+ end+ endenddiff --git a/admin/spec/controllers/spree/admin/reports_controller_spec.rb b/admin/spec/controllers/spree/admin/reports_controller_spec.rbindex 8beba53b3f..77e4c2d9c1 100644--- a/admin/spec/controllers/spree/admin/reports_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/reports_controller_spec.rb@@ -3,6 +3,8 @@ require 'spec_helper'describe Spree::Admin::ReportsController, type: :controller dostub_authorization!+ render_views+let(:store) { @default_store }describe '#index' do@@ -50,7 +52,7 @@ describe Spree::Admin::ReportsController, type: :controller do}end- subject { post :create, params: { report: report_params } }+ subject { post :create, params: { report: report_params }, format: :turbo_stream }it 'creates a new report' doexpect { subject }.to change(Spree::Report, :count).by(1)diff --git a/admin/spec/controllers/spree/admin/resource_controller_spec.rb b/admin/spec/controllers/spree/admin/resource_controller_spec.rbindex e8c93d199e..4d5056d782 100644--- a/admin/spec/controllers/spree/admin/resource_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/resource_controller_spec.rb@@ -6,6 +6,10 @@ module Spreedef model_classSpree::DummyModelend++ def permitted_resource_params+ params.require(:dummy_model).permit(:name)+ endendendend@@ -35,18 +39,6 @@ describe Spree::Admin::DummyModelsController, type: :controller doit 'creates the resource' doexpect { subject }.to change { Spree::DummyModel.count }.by(1)end-- context 'without any parameters' do- let(:params) { {} }-- before do- allow_any_instance_of(Spree::DummyModel).to receive(:name).and_return('some name')- end-- it 'creates the resource' do- expect { subject }.to change { Spree::DummyModel.count }.by(1)- end- endenddescribe '#update' dodiff --git a/admin/spec/controllers/spree/admin/roles_controller_spec.rb b/admin/spec/controllers/spree/admin/roles_controller_spec.rbnew file mode 100644index 0000000000..40e7067d48--- /dev/null+++ b/admin/spec/controllers/spree/admin/roles_controller_spec.rb@@ -0,0 +1,80 @@+require 'spec_helper'++RSpec.describe Spree::Admin::RolesController, type: :controller do+ stub_authorization!+ render_views++ describe 'GET #index' do+ let!(:roles) { create_list(:role, 3) }++ it 'renders the list of roles' do+ get :index++ expect(response).to be_successful+ expect(response).to render_template(:index)++ expect(assigns(:roles)).to contain_exactly(*roles)+ end+ end++ describe 'GET #new' do+ it 'renders the new role form' do+ get :new++ expect(response).to be_successful+ expect(response).to render_template(:new)+ end+ end++ describe 'POST #create' do+ let(:role_params) do+ {+ name: 'Default Role'+ }+ end++ let(:role) { Spree::Role.last }++ it 'creates a new role' do+ post :create, params: { role: role_params }++ expect(response).to redirect_to(spree.edit_admin_role_path(role))++ expect(role).to be_persisted+ expect(role.name).to eq('Default Role')+ end+ end++ describe 'GET #edit' do+ let!(:role) { create(:role) }++ it 'renders the edit role form' do+ get :edit, params: { id: role.id }++ expect(response).to be_successful+ expect(response).to render_template(:edit)+ end+ end++ describe 'PUT #update' do+ let!(:role) { create(:role, name: 'Default Role') }++ it 'updates the role' do+ put :update, params: { id: role.id, role: { name: 'Updated Role' } }++ expect(response).to redirect_to(spree.edit_admin_role_path(role))+ expect(role.reload.name).to eq('Updated Role')+ end+ end++ describe 'DELETE #destroy' do+ let!(:role) { create(:role) }++ it 'deletes the role' do+ delete :destroy, params: { id: role.id }++ expect(response).to redirect_to(spree.admin_roles_path)+ expect { role.reload }.to raise_error(ActiveRecord::RecordNotFound)+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/shipping_categories_controller_spec.rb b/admin/spec/controllers/spree/admin/shipping_categories_controller_spec.rbnew file mode 100644index 0000000000..3b38732487--- /dev/null+++ b/admin/spec/controllers/spree/admin/shipping_categories_controller_spec.rb@@ -0,0 +1,80 @@+require 'spec_helper'++RSpec.describe Spree::Admin::ShippingCategoriesController, type: :controller do+ stub_authorization!+ render_views++ describe 'GET #index' do+ let!(:shipping_categories) { create_list(:shipping_category, 3) }++ it 'renders the list of shipping categories' do+ get :index++ expect(response).to be_successful+ expect(response).to render_template(:index)++ expect(assigns(:shipping_categories)).to contain_exactly(*shipping_categories)+ end+ end++ describe 'GET #new' do+ it 'renders the new shipping category form' do+ get :new++ expect(response).to be_successful+ expect(response).to render_template(:new)+ end+ end++ describe 'POST #create' do+ let(:shipping_category_params) do+ {+ name: 'Default Category'+ }+ end++ let(:shipping_category) { Spree::ShippingCategory.last }++ it 'creates a new shipping category' do+ post :create, params: { shipping_category: shipping_category_params }++ expect(response).to redirect_to(spree.edit_admin_shipping_category_path(shipping_category))++ expect(shipping_category).to be_persisted+ expect(shipping_category.name).to eq('Default Category')+ end+ end++ describe 'GET #edit' do+ let!(:shipping_category) { create(:shipping_category) }++ it 'renders the edit shipping category form' do+ get :edit, params: { id: shipping_category.id }++ expect(response).to be_successful+ expect(response).to render_template(:edit)+ end+ end++ describe 'PUT #update' 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' } }++ expect(response).to redirect_to(spree.edit_admin_shipping_category_path(shipping_category))+ expect(shipping_category.reload.name).to eq('Updated Category')+ end+ end++ describe 'DELETE #destroy' do+ let!(:shipping_category) { create(:shipping_category) }++ it 'deletes the shipping category' do+ delete :destroy, params: { id: shipping_category.id }++ expect(response).to redirect_to(spree.admin_shipping_categories_path)+ expect { shipping_category.reload }.to raise_error(ActiveRecord::RecordNotFound)+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rb b/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rbindex a5db99ae12..d4264dcca5 100644--- a/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/shipping_methods_controller_spec.rb@@ -3,7 +3,9 @@ require 'spec_helper'describe Spree::Admin::ShippingMethodsController, type: :controller dostub_authorization!- let(:store) { @default_store }+ render_views++ let(:store) { Spree::Store.default }let!(:shipping_category) { create(:shipping_category) }describe '#index' do@@ -25,10 +27,72 @@ describe Spree::Admin::ShippingMethodsController, type: :controller dodescribe '#create' dolet(:zone) { create(:zone) }- let(:shipping_method_attributes) { attributes_for(:shipping_method, zone_ids: [zone.id], shipping_category_ids: [shipping_category.id], calculator_type: 'Spree::Calculator::Shipping::FlatRate') }+ let(:shipping_method_attributes) { attributes_for(:shipping_method, zone_ids: [zone.id], estimated_transit_business_days_min: 1, estimated_transit_business_days_max: 2, shipping_category_ids: [shipping_category.id], calculator_type: 'Spree::Calculator::Shipping::FlatRate', calculator_attributes: { preferred_amount: 10, preferred_currency: 'EUR' }) }it 'creates a new shipping method' doexpect { post :create, params: { shipping_method: shipping_method_attributes } }.to change(Spree::ShippingMethod, :count).by(1)++ shipping_method = Spree::ShippingMethod.last+ expect(shipping_method.zone_ids).to eq([zone.id])+ expect(shipping_method.shipping_category_ids).to eq([shipping_category.id])+ expect(shipping_method.estimated_transit_business_days_min).to eq(1)+ expect(shipping_method.estimated_transit_business_days_max).to eq(2)+ expect(shipping_method.calculator.preferred_amount).to eq(10)+ expect(shipping_method.calculator.preferred_currency).to eq('EUR')+ end+ end++ describe '#edit' do+ let(:shipping_method) { create(:shipping_method) }++ it 'renders the edit template' do+ get :edit, params: { id: shipping_method.id }+ expect(response.status).to eq(200)+ end+ end++ describe '#update' do+ let(:shipping_method) { create(:shipping_method) }+ let(:zone) { create(:zone) }+ let(:new_attributes) do+ {+ name: 'Updated Method',+ zone_ids: [zone.id],+ estimated_transit_business_days_min: 3,+ estimated_transit_business_days_max: 5,+ shipping_category_ids: [shipping_category.id],+ calculator_type: 'Spree::Calculator::Shipping::FlatRate',+ calculator_attributes: {+ type: 'Spree::Calculator::Shipping::FlatRate',+ preferred_amount: 20,+ preferred_currency: 'USD'+ }+ }+ end++ it 'updates the shipping method' do+ put :update, params: { id: shipping_method.id, shipping_method: new_attributes }++ shipping_method.reload+ expect(shipping_method.name).to eq('Updated Method')+ expect(shipping_method.zone_ids).to eq([zone.id])+ expect(shipping_method.estimated_transit_business_days_min).to eq(3)+ expect(shipping_method.estimated_transit_business_days_max).to eq(5)+ expect(shipping_method.calculator.preferred_amount).to eq(20)+ expect(shipping_method.calculator.preferred_currency).to eq('USD')+ expect(response).to redirect_to(spree.edit_admin_shipping_method_path(shipping_method))+ end+ end++ describe '#destroy' do+ let!(:shipping_method) { create(:shipping_method) }++ it 'deletes the shipping method' do+ expect {+ delete :destroy, params: { id: shipping_method.id }+ }.to change(Spree::ShippingMethod, :count).by(-1)++ expect(response).to redirect_to(spree.admin_shipping_methods_path)endendenddiff --git a/admin/spec/controllers/spree/admin/stock_items_controller_spec.rb b/admin/spec/controllers/spree/admin/stock_items_controller_spec.rbindex 6250d764c3..d333d36783 100644--- a/admin/spec/controllers/spree/admin/stock_items_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/stock_items_controller_spec.rb@@ -2,19 +2,20 @@ require 'spec_helper'RSpec.describe Spree::Admin::StockItemsController, type: :controller dostub_authorization!+ render_views- let!(:stock_location_1) { create(:stock_location, name: 'Stock location 1') }- let!(:stock_location_2) { create(:stock_location, name: 'Stock location 2') }+ describe '#index' do+ let!(:stock_location_1) { create(:stock_location, name: 'Stock location 1') }+ let!(:stock_location_2) { create(:stock_location, name: 'Stock location 2') }- let!(:variant_1) { create(:variant, create_stock: false, sku: 'shirt-1', product: create(:base_product, name: 'Shirt')) }- let!(:variant_1_stock_1) { create(:stock_item, variant: variant_1, stock_location: stock_location_1) }- let!(:variant_1_stock_2) { create(:stock_item, variant: variant_1, stock_location: stock_location_2) }+ let!(:variant_1) { create(:variant, create_stock: false, sku: 'shirt-1', product: create(:base_product, name: 'Shirt')) }+ let!(:variant_1_stock_1) { create(:stock_item, variant: variant_1, stock_location: stock_location_1) }+ let!(:variant_1_stock_2) { create(:stock_item, variant: variant_1, stock_location: stock_location_2) }- let!(:variant_2) { create(:variant, create_stock: false, sku: 'shoes-2', product: create(:base_product, name: 'Shoes')) }- let!(:variant_2_stock_1) { create(:stock_item, variant: variant_2, stock_location: stock_location_1) }- let!(:variant_2_stock_2) { create(:stock_item, variant: variant_2, stock_location: stock_location_2) }+ let!(:variant_2) { create(:variant, create_stock: false, sku: 'shoes-2', product: create(:base_product, name: 'Shoes')) }+ let!(:variant_2_stock_1) { create(:stock_item, variant: variant_2, stock_location: stock_location_1) }+ let!(:variant_2_stock_2) { create(:stock_item, variant: variant_2, stock_location: stock_location_2) }- describe '#index' dosubject(:index) { get :index, params: params }let(:params) { {} }@@ -72,4 +73,18 @@ RSpec.describe Spree::Admin::StockItemsController, type: :controller doendendend++ describe '#update' do+ let!(:stock_item) { create(:stock_item, count_on_hand: 100) }++ subject(:update) { patch :update, params: params, format: :turbo_stream }++ let(:params) { { id: stock_item.id, stock_item: { backorderable: true, count_on_hand: 99 } } }++ it 'updates the stock item' do+ update+ expect(stock_item.reload.backorderable).to be(true)+ expect(stock_item.reload.count_on_hand).to eq(99)+ end+ endenddiff --git a/admin/spec/controllers/spree/admin/stock_locations_controller_spec.rb b/admin/spec/controllers/spree/admin/stock_locations_controller_spec.rbnew file mode 100644index 0000000000..277727c183--- /dev/null+++ b/admin/spec/controllers/spree/admin/stock_locations_controller_spec.rb@@ -0,0 +1,101 @@+require 'spec_helper'++RSpec.describe Spree::Admin::StockLocationsController, type: :controller do+ stub_authorization!+ render_views++ describe 'GET #index' do+ let!(:stock_locations) { create_list(:stock_location, 3) }++ it 'renders the list of stock locations' do+ get :index++ expect(response).to be_successful+ expect(response).to render_template(:index)++ expect(assigns(:collection)).to contain_exactly(*stock_locations)+ end+ end++ describe 'GET #new' do+ it 'renders the new stock location form' do+ get :new++ expect(response).to be_successful+ expect(response).to render_template(:new)+ expect(assigns(:stock_location).country).to eq(controller.current_store.default_country)+ end+ end++ describe 'POST #create' do+ let(:stock_location_params) do+ {+ name: 'Main Warehouse',+ address1: '123 Main St',+ city: 'Portland',+ zipcode: '97210',+ state_id: create(:state).id,+ country_id: create(:country).id+ }+ end++ let(:stock_location) { Spree::StockLocation.last }++ it 'creates a new stock location' do+ post :create, params: { stock_location: stock_location_params }++ expect(response).to redirect_to(spree.edit_admin_stock_location_path(stock_location))++ expect(stock_location).to be_persisted+ expect(stock_location.name).to eq('Main Warehouse')+ expect(stock_location.address1).to eq('123 Main St')+ expect(stock_location.city).to eq('Portland')+ end+ end++ describe 'GET #edit' do+ let!(:stock_location) { create(:stock_location) }++ it 'renders the edit stock location form' do+ get :edit, params: { id: stock_location.id }++ expect(response).to be_successful+ expect(response).to render_template(:edit)+ end+ end++ describe 'PUT #update' 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' } }++ expect(response).to redirect_to(spree.edit_admin_stock_location_path(stock_location))+ expect(stock_location.reload.name).to eq('New Warehouse')+ end+ end++ describe 'PUT #mark_as_default' do+ let!(:stock_location) { create(:stock_location, default: false) }++ it 'marks the stock location as default' do+ expect {+ put :mark_as_default, params: { id: stock_location.id }+ }.to change { stock_location.reload.default }.from(false).to(true)++ expect(response).to redirect_to(spree.admin_stock_locations_path)+ end+ end++ describe 'DELETE #destroy' do+ let!(:stock_location) { create(:stock_location) }++ it 'deletes the stock location' do+ expect {+ delete :destroy, params: { id: stock_location.id }+ }.to change(Spree::StockLocation, :count).by(-1)++ expect(response).to redirect_to(spree.admin_stock_locations_path)+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/store_credit_categories_controller_spec.rb b/admin/spec/controllers/spree/admin/store_credit_categories_controller_spec.rbnew file mode 100644index 0000000000..9dd09bb7e3--- /dev/null+++ b/admin/spec/controllers/spree/admin/store_credit_categories_controller_spec.rb@@ -0,0 +1,80 @@+require 'spec_helper'++RSpec.describe Spree::Admin::StoreCreditCategoriesController, type: :controller do+ stub_authorization!+ render_views++ describe 'GET #index' do+ let!(:store_credit_categories) { create_list(:store_credit_category, 3) }++ it 'renders the list of store credit categories' do+ get :index++ expect(response).to be_successful+ expect(response).to render_template(:index)++ expect(assigns(:store_credit_categories)).to contain_exactly(*store_credit_categories)+ end+ end++ describe 'GET #new' do+ it 'renders the new store credit category form' do+ get :new++ expect(response).to be_successful+ expect(response).to render_template(:new)+ end+ end++ describe 'POST #create' do+ let(:store_credit_category_params) do+ {+ name: 'Gift Card Category'+ }+ end++ let(:store_credit_category) { Spree::StoreCreditCategory.last }++ it 'creates a new store credit category' do+ post :create, params: { store_credit_category: store_credit_category_params }++ expect(response).to redirect_to(spree.edit_admin_store_credit_category_path(store_credit_category))++ expect(store_credit_category).to be_persisted+ expect(store_credit_category.name).to eq('Gift Card Category')+ end+ end++ describe 'GET #edit' do+ 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 }++ expect(response).to be_successful+ expect(response).to render_template(:edit)+ end+ end++ describe 'PUT #update' do+ 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' } }++ 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')+ end+ end++ describe 'DELETE #destroy' do+ let!(:store_credit_category) { create(:store_credit_category) }++ it 'deletes the store credit category' do+ delete :destroy, params: { id: store_credit_category.id }++ expect(response).to redirect_to(spree.admin_store_credit_categories_path)+ expect { store_credit_category.reload }.to raise_error(ActiveRecord::RecordNotFound)+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/tax_categories_controller_spec.rb b/admin/spec/controllers/spree/admin/tax_categories_controller_spec.rbnew file mode 100644index 0000000000..d57eb81cbd--- /dev/null+++ b/admin/spec/controllers/spree/admin/tax_categories_controller_spec.rb@@ -0,0 +1,88 @@+require 'spec_helper'++RSpec.describe Spree::Admin::TaxCategoriesController, type: :controller do+ stub_authorization!+ render_views++ describe 'GET #index' do+ let!(:tax_categories) { create_list(:tax_category, 3) }++ it 'renders the list of tax categories' do+ get :index++ expect(response).to be_successful+ expect(response).to render_template(:index)++ expect(assigns(:tax_categories)).to contain_exactly(*tax_categories)+ end+ end++ describe 'GET #new' do+ it 'renders the new tax category form' do+ get :new++ expect(response).to be_successful+ expect(response).to render_template(:new)+ end+ end++ describe 'POST #create' do+ let(:tax_category_params) do+ {+ name: 'General Category',+ description: 'General tax category',+ tax_code: 'GEN',+ is_default: true+ }+ end++ let(:tax_category) { Spree::TaxCategory.last }++ it 'creates a new tax category' do+ expect {+ post :create, params: { tax_category: tax_category_params }+ }.to change(Spree::TaxCategory, :count).by(1)++ expect(response).to redirect_to(spree.edit_admin_tax_category_path(tax_category))++ expect(tax_category).to be_persisted+ expect(tax_category.name).to eq('General Category')+ expect(tax_category.description).to eq('General tax category')+ expect(tax_category.tax_code).to eq('GEN')+ expect(tax_category.is_default).to be true+ end+ end++ describe 'GET #edit' do+ let!(:tax_category) { create(:tax_category) }++ it 'renders the edit tax category form' do+ get :edit, params: { id: tax_category.id }++ expect(response).to be_successful+ expect(response).to render_template(:edit)+ end+ end++ describe 'PUT #update' 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' } }++ expect(response).to redirect_to(spree.edit_admin_tax_category_path(tax_category))+ expect(tax_category.reload.name).to eq('Updated Category')+ end+ end++ describe 'DELETE #destroy' do+ let!(:tax_category) { create(:tax_category) }++ it 'deletes the tax category' do+ delete :destroy, params: { id: tax_category.id }++ expect(response).to redirect_to(spree.admin_tax_categories_path)+ expect(tax_category.reload).to be_deleted+ end+ end+enddiff --git a/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rb b/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rbindex 432d173b83..5dea33045a 100644--- a/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/taxonomies_controller_spec.rb@@ -4,6 +4,37 @@ describe Spree::Admin::TaxonomiesController dostub_authorization!render_views+ describe '#index' do+ subject { get :index }++ it 'renders index taxonomy view' do+ subject++ expect(response).to have_http_status(:ok)+ expect(response).to render_template(:index)+ end+ end++ describe '#new' do+ subject { get :new }++ it 'renders new taxonomy view' do+ subject++ expect(response).to have_http_status(:ok)+ expect(response).to render_template(:new)+ end+ end++ describe '#create' do+ subject { post :create, params: { taxonomy: { name: 'New Taxonomy' } } }++ it 'creates a new taxonomy' do+ expect { subject }.to change(Spree::Taxonomy, :count).by(1)+ expect(response).to redirect_to spree.admin_taxonomy_path(Spree::Taxonomy.last)+ end+ end+describe '#edit' dolet(:taxonomy) { create(:taxonomy) }@@ -16,4 +47,27 @@ describe Spree::Admin::TaxonomiesController doexpect(response).to render_template(:edit)endend++ describe '#update' do+ subject { put :update, params: { id: taxonomy.id, taxonomy: { name: 'New Name' } } }++ let(:taxonomy) { create(:taxonomy) }++ it 'updates the taxonomy' do+ subject++ expect(response).to redirect_to spree.admin_taxonomy_path(taxonomy)+ end+ end++ describe '#destroy' do+ subject { delete :destroy, params: { id: taxonomy.id } }++ let!(:taxonomy) { create(:taxonomy) }++ it 'destroys the taxonomy' do+ expect { subject }.to change(Spree::Taxonomy, :count).by(-1)+ expect(response).to redirect_to spree.admin_taxonomies_path+ end+ endenddiff --git a/admin/spec/controllers/spree/admin/taxons_controller_spec.rb b/admin/spec/controllers/spree/admin/taxons_controller_spec.rbindex 666e1f9758..23da06a67f 100644--- a/admin/spec/controllers/spree/admin/taxons_controller_spec.rb+++ b/admin/spec/controllers/spree/admin/taxons_controller_spec.rb@@ -22,6 +22,38 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller doendend+ describe 'POST #create' do+ let!(:parent_taxon) { create(:taxon, taxonomy: taxonomy) }++ context 'automatic taxon' do+ it 'returns a successful response' do+ expect {+ post :create, params: {+ taxonomy_id: taxonomy.id,+ taxon: {+ parent_id: parent_taxon.id,+ name: 'Automatic Taxon',+ automatic: true,+ taxon_rules_attributes: [+ { type: 'Spree::TaxonRules::AvailableOn', value: '1', match_policy: 'is_equal_to' }+ ]+ }+ }+ }.to change(Spree::Taxon, :count).by(1).and change(Spree::TaxonRule, :count).by(1)++ taxon = Spree::Taxon.last+ expect(taxon.automatic).to be_truthy+ expect(taxon.taxon_rules.count).to eq(1)+ expect(taxon.taxon_rules.first.type).to eq('Spree::TaxonRules::AvailableOn')+ expect(taxon.taxon_rules.first.value).to eq('1')+ 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))+ end+ end+ end+describe 'GET #show' dolet(:taxon) { create(:taxon, taxonomy: taxonomy) }@@ -41,11 +73,42 @@ RSpec.describe Spree::Admin::TaxonsController, type: :controller doenddescribe 'PUT #update' do- let(:taxon) { create(:taxon, taxonomy: taxonomy) }+ let(:taxon) { create(:taxon, taxonomy: taxonomy, automatic: true) }+ let!(:sale_taxon_rule) { create(:sale_taxon_rule, taxon: taxon) }it 'returns a successful response' do- put :update, params: { taxonomy_id: taxonomy.id, id: taxon.id, taxon: { name: 'New Name' } }+ put :update, params: {+ taxonomy_id: taxonomy.id, id: taxon.id,+ taxon: {+ name: 'New Name',+ description: 'New Description',+ automatic: true,+ rules_match_policy: 'any',+ taxon_rules_attributes: [+ {+ type: 'Spree::TaxonRules::AvailableOn',+ value: '1',+ match_policy: 'is_equal_to'+ },+ {+ id: sale_taxon_rule.id,+ type: 'Spree::TaxonRules::Sale',+ value: '1',+ match_policy: 'is_equal_to',+ _destroy: '1'+ }+ ]+ }+ }expect(response).to redirect_to(spree.edit_admin_taxonomy_taxon_path(taxonomy.id, taxon.id))++ expect(taxon.reload.name).to eq('New Name')+ expect(taxon.description.to_plain_text).to eq('New Description')+ expect(taxon.automatic).to be_truthy+ expect(taxon.rules_match_policy).to eq('any')+ expect(taxon.taxon_rules.count).to eq(1)+ expect(taxon.taxon_rules.first.type).to eq('Spree::TaxonRules::AvailableOn')+ expect(taxon.taxon_rules.first.value).to eq('1')endcontext 'when permalink_part is present' dodiff --git a/admin/spec/controllers/spree/admin/zones_controller_spec.rb b/admin/spec/controllers/spree/admin/zones_controller_spec.rbnew file mode 100644index 0000000000..2aa331b8d6--- /dev/null+++ b/admin/spec/controllers/spree/admin/zones_controller_spec.rb@@ -0,0 +1,114 @@+require 'spec_helper'++RSpec.describe Spree::Admin::ZonesController do+ stub_authorization!+ render_views++ describe 'GET #index' do+ let!(:zone) { create(:zone) }++ it 'renders the index template' do+ get :index+ expect(response).to be_successful+ expect(response).to render_template(:index)+ expect(assigns(:zones)).to include(zone)+ end+ end++ describe 'GET #new' do+ it 'renders the new template' do+ get :new+ expect(response).to be_successful+ expect(response).to render_template(:new)+ expect(assigns(:zone)).to be_a_new(Spree::Zone)+ end+ end++ describe 'POST #create' do+ context 'with country based zone' do+ let(:country) { create(:country) }+ let(:zone_params) do+ {+ name: 'EU Zone',+ description: 'Countries in EU',+ kind: 'country',+ default_tax: true,+ country_ids: [country.id]+ }+ end++ it 'creates a new country-based zone' do+ expect { post :create, params: { zone: zone_params } }.to change(Spree::Zone, :count).by(1)++ zone = Spree::Zone.last+ expect(zone).to be_persisted+ expect(zone.name).to eq('EU Zone')+ expect(zone.kind).to eq('country')+ expect(zone.default_tax).to be true+ expect(zone.zone_members.count).to eq(1)+ expect(zone.zone_members.first.zoneable).to be_a(Spree::Country)+ expect(zone.zone_members.first.zoneable.id).to eq(country.id)+ end+ end++ context 'with state based zone' do+ let!(:country) { create(:country) }+ let!(:state) { create(:state, country: country) }+ let(:zone_params) do+ {+ name: 'California Zone',+ description: 'California tax zone',+ kind: 'state',+ default_tax: true,+ state_country_id: country.id,+ state_ids: [state.id]+ }+ end++ it 'creates a new state-based zone' do+ expect { post :create, params: { zone: zone_params } }.to change(Spree::Zone, :count).by(1)++ zone = Spree::Zone.last+ expect(zone).to be_persisted+ expect(zone.name).to eq('California Zone')+ expect(zone.kind).to eq('state')+ expect(zone.default_tax).to be true+ expect(zone.zone_members.count).to eq(1)+ expect(zone.zone_members.first.zoneable).to be_a(Spree::State)+ expect(zone.zone_members.first.zoneable.id).to eq(state.id)+ end+ end+ end++ describe 'GET #edit' do+ let!(:zone) { create(:zone) }++ it 'renders the edit template' do+ get :edit, params: { id: zone.id }+ expect(response).to be_successful+ expect(response).to render_template(:edit)+ expect(assigns(:zone)).to eq(zone)+ end+ end++ describe 'PUT #update' do+ let!(:zone) { create(:zone, name: 'Old Name') }++ it 'updates the zone' do+ put :update, params: { id: zone.id, zone: { name: 'New Name' } }++ expect(zone.reload.name).to eq('New Name')+ end+ end++ describe 'DELETE #destroy' 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(response).to redirect_to(spree.admin_zones_path)+ expect(Spree::Zone.find_by(id: zone.id)).to be_nil+ end+ end+enddiff --git a/admin/spec/fixtures/files/logo.png b/admin/spec/fixtures/files/logo.pngnew file mode 100644index 0000000000..8d0d83f754Binary files /dev/null and b/admin/spec/fixtures/files/logo.png differdiff --git a/admin/spec/spec_helper.rb b/admin/spec/spec_helper.rbindex a3d229fb94..a85e078c54 100644--- a/admin/spec/spec_helper.rb+++ b/admin/spec/spec_helper.rb@@ -37,6 +37,7 @@ require 'ffaker'require 'spree/testing_support/authorization_helpers'require 'spree/testing_support/factories'+require 'spree/api/testing_support/factories'require 'spree/testing_support/preferences'require 'spree/testing_support/jobs'require 'spree/testing_support/store'diff --git a/core/app/models/spree/store_credit_category.rb b/core/app/models/spree/store_credit_category.rbindex 51e3901f28..b55c890df6 100644--- a/core/app/models/spree/store_credit_category.rb+++ b/core/app/models/spree/store_credit_category.rb@@ -28,6 +28,10 @@ module Spreeendend+ def can_be_deleted?+ !store_credit_category_used?+ end+class << selfdef default_reimbursement_category(_options = {})Spree::StoreCreditCategory.firstdiff --git a/core/lib/spree/core/controller_helpers/strong_parameters.rb b/core/lib/spree/core/controller_helpers/strong_parameters.rbindex cf83ae4167..5e2e2d6be1 100644--- a/core/lib/spree/core/controller_helpers/strong_parameters.rb+++ b/core/lib/spree/core/controller_helpers/strong_parameters.rb@@ -33,8 +33,9 @@ module Spreedef permitted_product_attributespermitted_attributes.product_attributes + [- :store_id,- product_properties_attributes: permitted_product_properties_attributes+ variants_attributes: permitted_variant_attributes + ['id', :_destroy],+ master_attributes: permitted_variant_attributes + ['id'],+ product_properties_attributes: permitted_product_properties_attributes + ['id', :_destroy]]enddiff --git a/core/lib/spree/permitted_attributes.rb b/core/lib/spree/permitted_attributes.rbindex 3374b350a4..544a3eea50 100644--- a/core/lib/spree/permitted_attributes.rb+++ b/core/lib/spree/permitted_attributes.rb@@ -11,31 +11,53 @@ module Spree:customer_return_attributes,:digital_attributes,:digital_link_attributes,+ :export_attributes,:image_attributes,+ :integration_attributes,:inventory_unit_attributes,+ :invitation_attributes,:line_item_attributes,:menu_attributes,:menu_item_attributes,:option_type_attributes,:option_value_attributes,+ :page_attributes,+ :page_link_attributes,+ :page_section_attributes,:payment_attributes,+ :payment_method_attributes,:product_attributes,+ :promotion_attributes,+ :promotion_rule_attributes,+ :promotion_action_attributes,:product_properties_attributes,:property_attributes,+ :refund_attributes,+ :report_attributes,:return_authorization_attributes,+ :return_authorization_reason_attributes,+ :role_attributes,:shipment_attributes,+ :shipping_method_attributes,+ :shipping_category_attributes,:source_attributes,:stock_item_attributes,:stock_location_attributes,:stock_movement_attributes,+ :stock_transfer_attributes,:store_attributes,:store_credit_attributes,+ :store_credit_category_attributes,+ :tax_rate_attributes,+ :tax_category_attributes,:taxon_attributes,:taxonomy_attributes,+ :theme_attributes,:user_attributes,:variant_attributes,:wishlist_attributes,- :wished_item_attributes+ :wished_item_attributes,+ :zone_attributes]mattr_reader(*ATTRIBUTES)@@ -75,24 +97,39 @@ module Spree@@digital_link_attributes = [:access_counter]+ @@export_attributes = [:type, :format, :record_selection, search_params: {}]+@@image_attributes = [:alt, :attachment, :position, :viewable_type, :viewable_id]+ @@integration_attributes = [:type]+@@inventory_unit_attributes = [:shipment, :shipment_id, :variant_id]+ @@invitation_attributes = [:email, :expires_at, :role_id]+@@line_item_attributes = [:id, :variant_id, :quantity]@@menu_attributes = [:name, :locale, :location]- @@menu_item_attributes = [:name, :subtite, :destination, :new_window, :item_type,+ @@menu_item_attributes = [:name, :subtitle, :destination, :new_window, :item_type,:linked_resource_type, :linked_resource_id, :code, :menu_id]- @@option_type_attributes = [:name, :presentation, :option_values_attributes]+ @@option_type_attributes = [:name, :presentation, :position, :filterable,+ option_values_attributes: [:id, :name, :presentation, :position, :_destroy]]++ @@option_value_attributes = [:name, :presentation, :position]- @@option_value_attributes = [:name, :presentation]+ @@page_attributes = [:name, :slug, :meta_title, :meta_description, :meta_keywords]++ @@page_link_attributes = [:linkable_id, :linkable_type, :position, :label, :url]++ @@page_section_attributes = [:type, :name, :position, :asset]@@payment_attributes = [:amount, :payment_method_id, :payment_method]- @@product_properties_attributes = [:property_name, :value, :position]+ @@payment_method_attributes = [:name, :type, :description, :active, :display_on, :auto_capture, :position]++ @@product_properties_attributes = [:property_name, :property_id, :value, :position, :_destroy]@@product_attributes = [:name, :description, :available_on, :make_active_at, :discontinue_on, :permalink, :meta_description,@@ -100,24 +137,56 @@ module Spree:option_values_hash, :weight, :height, :width, :depth,:shipping_category_id, :tax_category_id,:cost_currency, :cost_price, :compare_at_price,- :slug,+ :slug, :track_inventory, :backorderable, :barcode, :status,+ :weight_unit, :dimensions_unit,{tag_list: [],+ label_list: [],option_type_ids: [],- taxon_ids: []+ taxon_ids: [],+ store_ids: [],+ product_option_types_attributes: [:id, :option_type_id, :position, :_destroy]}]- @@property_attributes = [:name, :presentation, :position]+ @@promotion_attributes = [:name, :description, :starts_at, :expires_at, :code, :usage_limit, :path, :match_policy,+ :advertise, :promotion_category_id, :code_prefix, :kind, :number_of_codes, :multi_codes, store_ids: []]++ @@promotion_rule_attributes = [:type, :preferred_match_policy, user_ids_to_add: [], product_ids_to_add: [], taxon_ids_to_add: []]++ @@promotion_action_attributes = [:type, :calculator_type, calculator_attributes: {}, promotion_action_line_items_attributes: [:id, :promotion_action_id, :variant_id, :quantity, :_destroy]]++ @@property_attributes = [:name, :presentation, :position, :kind, :display_on]++ @@refund_attributes = [:amount, :refund_reason_id]++ @@reimbursement_attributes = [return_items_attributes: [:id, :override_reimbursement_type_id, :pre_tax_amount, :exchange_variant_id]]++ @@report_attributes = [:type, :date_from, :date_to, :currency]@@return_authorization_attributes = [:amount, :memo, :stock_location_id, :inventory_units_attributes,- :return_authorization_reason_id]+ :return_authorization_reason_id, {+ return_items_attributes: [:id, :inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount,+ :acceptance_status, :exchange_variant_id, :resellable]+ }]++ @@return_authorization_reason_attributes = [:name, :description]++ @@return_item_attributes = [:inventory_unit_id, :return_authorization_id, :returned, :pre_tax_amount, :acceptance_status, :exchange_variant_id, :resellable]++ @@role_attributes = [:name]@@shipment_attributes = [:order, :special_instructions, :stock_location_id, :id,:tracking, :address, :inventory_units, :selected_shipping_rate_id]+ @@shipping_category_attributes = [:name]++ @@shipping_method_attributes = [:name, :code,:tracking_url, :tax_category_id, :display_on,+ :estimated_transit_business_days_min, :estimated_transit_business_days_max,+ :calculator_type, :preferences, zone_ids: [], shipping_category_ids: [], calculator_attributes: {}]+# month / year may be provided by some sources, or others may elect to use one field@@source_attributes = [:id, :number, :month, :year, :expiry, :verification_value,@@ -125,7 +194,7 @@ module Spree:gateway_payment_profile_id, :last_digits, :name, :encrypted_data]- @@stock_item_attributes = [:variant, :stock_location, :backorderable, :variant_id]+ @@stock_item_attributes = [:variant_id, :stock_location_id, :backorderable, :count_on_hand]@@stock_location_attributes = [:name, :active, :address1, :address2, :city, :zipcode,@@ -137,6 +206,9 @@ module Spree:quantity, :stock_item, :stock_item_id, :originator, :action]+ @@stock_transfer_attributes = [:source_location_id, :destination_location_id, :reference,+ stock_movements_attributes: [:variant_id, :quantity, :originator_id, :stock_item_id]]+@@store_attributes = [:name, :url, :seo_title, :code, :meta_keywords,:meta_description, :default_currency, :mail_from_address,:customer_support_email, :description, :address, :contact_phone,@@ -154,28 +226,48 @@ module Spree@@store_credit_attributes = %i[amount currency category_id memo]+ @@store_credit_category_attributes = [:name]+@@taxonomy_attributes = [:name]+ @@tax_category_attributes = [:name, :tax_code,:description, :is_default]++ @@tax_rate_attributes = [:name, :amount, :zone_id, :tax_category_id, :calculator_type]+@@taxon_attributes = [:name, :parent_id, :position, :icon, :description, :permalink, :hide_from_nav,- :taxonomy_id, :meta_description, :meta_keywords, :meta_title, :child_index+ :taxonomy_id, :meta_description, :meta_keywords, :meta_title, :child_index,+ :automatic, :rules_match_policy, :sort_order,+ :image, :square_image, :description,+ taxon_rules_attributes: [:id, :type, :value, :match_policy, :_destroy],]+ @@theme_attributes = [:name, :type, :default]+@@user_attributes = [:email, :bill_address_id, :ship_address_id, :password, :first_name, :last_name,:password_confirmation, :selected_locale, :avatar, :accepts_email_marketing, :phone,{ public_metadata: {}, private_metadata: {}, tag_list: [] }]@@variant_attributes = [:name, :presentation, :cost_price, :discontinue_on, :lock_version,- :position, :track_inventory,+ :position, :track_inventory, :tax_category_id,:product_id, :product, :option_values_attributes, :price, :compare_at_price,:weight, :height, :width, :depth, :sku, :barcode, :cost_currency,:weight_unit, :dimensions_unit,- { options: [:name, :value], option_value_ids: [] }+ {+ options: [:id, :name, :value, :position, :_destroy],+ stock_items_attributes: [:id, :count_on_hand, :stock_location_id, :backorderable, :_destroy],+ prices_attributes: [:id, :amount, :compare_at_amount, :currency, :_destroy],+ price: {},+ option_value_variants_attributes: [:id, :option_value_id, :_destroy],+ option_value_ids: []+ }]@@wishlist_attributes = [:name, :is_default, :is_private]@@wished_item_attributes = [:variant_id, :quantity]++ @@zone_attributes = [:name, :description, :default_tax, :kind, :states_country_id, country_ids: [], state_ids: []]endenddiff --git a/core/lib/spree/testing_support/factories/promotion_action_factory.rb b/core/lib/spree/testing_support/factories/promotion_action_factory.rbindex 22b6f70700..de49278899 100644--- a/core/lib/spree/testing_support/factories/promotion_action_factory.rb+++ b/core/lib/spree/testing_support/factories/promotion_action_factory.rb@@ -7,4 +7,8 @@ FactoryBot.define doassociation :promotionassociation :calculator, factory: :flat_rate_calculatorend++ factory :promotion_action_create_line_items, class: Spree::Promotion::Actions::CreateLineItems do+ association :promotion+ endend