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
Remove API v1
Damian Legawiecd8026080705c
diff --git a/api/app/controllers/spree/api/base_controller.rb b/api/app/controllers/spree/api/base_controller.rbdeleted file mode 100644index ee8522c74b..0000000000--- a/api/app/controllers/spree/api/base_controller.rb+++ /dev/null@@ -1,171 +0,0 @@-require_dependency 'spree/api/controller_setup'--module Spree- module Api- class BaseController < ActionController::API- include Spree::Api::ControllerSetup- include Spree::Core::ControllerHelpers::Store- include Spree::Core::ControllerHelpers::StrongParameters- include Spree::Core::ControllerHelpers::Locale- include Spree::Core::ControllerHelpers::Currency-- attr_accessor :current_api_user-- before_action :set_content_type- before_action :load_user- before_action :authorize_for_order, if: proc { order_token.present? }- before_action :authenticate_user- before_action :load_user_roles-- rescue_from ActionController::ParameterMissing, with: :error_during_processing- rescue_from ActiveRecord::RecordInvalid, with: :error_during_processing- rescue_from ActiveRecord::RecordNotFound, with: :not_found- rescue_from CanCan::AccessDenied, with: :unauthorized- rescue_from Spree::Core::GatewayError, with: :gateway_error-- helper Spree::Api::ApiHelpers-- # users should be able to set price when importing orders via api- def permitted_line_item_attributes- if @current_user_roles.include?('admin')- super + [:price, :variant_id, :sku]- else- super- end- end-- def content_type- case params[:format]- when 'json'- 'application/json; charset=utf-8'- when 'xml'- 'text/xml; charset=utf-8'- end- end-- private-- def set_content_type- headers['Content-Type'] = content_type- end-- def load_user- @current_api_user = Spree.user_class.find_by(spree_api_key: api_key.to_s)- end-- def authenticate_user- return if @current_api_user-- if requires_authentication? && api_key.blank? && order_token.blank?- must_specify_api_key and return- elsif order_token.blank? && (requires_authentication? || api_key.present?)- invalid_api_key and return- else- # An anonymous user- @current_api_user = Spree.user_class.new- end- end-- def invalid_api_key- render 'spree/api/errors/invalid_api_key', status: 401- end-- def must_specify_api_key- render 'spree/api/errors/must_specify_api_key', status: 401- end-- def load_user_roles- @current_user_roles = @current_api_user ? @current_api_user.spree_roles.pluck(:name) : []- end-- def unauthorized- render 'spree/api/errors/unauthorized', status: 401 and return- end-- def error_during_processing(exception)- message = if exception.respond_to?(:original_message)- exception.original_message- else- exception.message- end-- Rails.logger.error message- Rails.logger.error exception.backtrace.join("\n")-- unprocessable_entity(message)- end-- def unprocessable_entity(message)- render plain: { exception: message }.to_json, status: 422- end-- def gateway_error(exception)- @order.errors.add(:base, exception.message)- invalid_resource!(@order)- end-- def requires_authentication?- Spree::Api::Config[:requires_authentication]- end-- def not_found- render 'spree/api/errors/not_found', status: 404 and return- end-- def current_ability- Spree::Dependencies.ability_class.constantize.new(current_api_user)- end-- def invalid_resource!(resource)- @resource = resource- render 'spree/api/errors/invalid_resource', status: 422- end-- def api_key- request.headers['X-Spree-Token'] || params[:token]- end- helper_method :api_key-- def order_token- request.headers['X-Spree-Order-Token'] || params[:order_token]- end-- def find_product(id)- @product = product_scope.friendly.distinct(false).find(id.to_s)- rescue ActiveRecord::RecordNotFound- @product = product_scope.find_by(id: id)- not_found unless @product- end-- def product_scope- if @current_user_roles.include?('admin')- scope = Product.with_deleted.accessible_by(current_ability, :show).includes(*product_includes)-- scope = scope.not_deleted unless params[:show_deleted]- scope = scope.not_discontinued unless params[:show_discontinued]- else- scope = Product.accessible_by(current_ability, :show).active.includes(*product_includes)- end-- scope- end-- def variants_associations- [{ option_values: :option_type }, :default_price, :images]- end-- def product_includes- [:option_types, :taxons, product_properties: :property, variants: variants_associations, master: variants_associations]- end-- def order_id- params[:order_id] || params[:checkout_id] || params[:order_number]- end-- def authorize_for_order- @order = Spree::Order.find_by(number: order_id)- authorize! :show, @order, order_token- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/addresses_controller.rb b/api/app/controllers/spree/api/v1/addresses_controller.rbdeleted file mode 100644index 238f4656a9..0000000000--- a/api/app/controllers/spree/api/v1/addresses_controller.rb+++ /dev/null@@ -1,46 +0,0 @@-module Spree- module Api- module V1- class AddressesController < Spree::Api::BaseController- before_action :find_order-- def show- authorize! :show, @order, order_token- @address = find_address- respond_with(@address)- end-- def update- authorize! :update, @order, order_token- @address = find_address-- if @address.update(address_params)- respond_with(@address, default_template: :show)- else- invalid_resource!(@address)- end- end-- private-- def address_params- params.require(:address).permit(permitted_address_attributes)- end-- def find_order- @order = Spree::Order.find_by!(number: order_id)- end-- def find_address- if @order.bill_address_id == params[:id].to_i- @order.bill_address- elsif @order.ship_address_id == params[:id].to_i- @order.ship_address- else- raise CanCan::AccessDenied- end- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/checkouts_controller.rb b/api/app/controllers/spree/api/v1/checkouts_controller.rbdeleted file mode 100644index e01d27c8f4..0000000000--- a/api/app/controllers/spree/api/v1/checkouts_controller.rb+++ /dev/null@@ -1,106 +0,0 @@-module Spree- module Api- module V1- class CheckoutsController < Spree::Api::BaseController- before_action :load_order_with_lock, only: [:next, :advance, :update]-- def next- authorize! :update, @order, order_token- @order.next!- respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)- rescue StateMachines::InvalidTransition- respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)- end-- def advance- authorize! :update, @order, order_token- while @order.next; end- respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)- end-- def update- authorize! :update, @order, order_token-- if @order.update_from_params(params, permitted_checkout_attributes, request.headers.env)- if current_api_user.has_spree_role?('admin') && user_id.present?- @order.associate_user!(Spree.user_class.find(user_id))- end-- log_state_changes if params[:state]-- return if after_update_attributes-- if @order.completed? || @order.next- state_callback(:after)- respond_with(@order, default_template: 'spree/api/v1/orders/show')- else- respond_with(@order, default_template: 'spree/api/v1/orders/could_not_transition', status: 422)- end- else- invalid_resource!(@order)- end- end-- private-- def user_id- params[:order][:user_id] if params[:order]- end-- # Should be overridden if you have areas of your checkout that don't match- # up to a step within checkout_steps, such as a registration step- def skip_state_validation?- false- end-- def load_order(lock = false)- @order = Spree::Order.lock(lock).find_by!(number: params[:id])- raise_insufficient_quantity and return if @order.insufficient_stock_lines.present?- @order.state = params[:state] if params[:state]- state_callback(:before)- end-- def load_order_with_lock- load_order(true)- end-- def raise_insufficient_quantity- respond_with(@order, default_template: 'spree/api/v1/orders/insufficient_quantity', status: 422)- end-- def state_callback(before_or_after = :before)- method_name = :"#{before_or_after}_#{@order.state}"- send(method_name) if respond_to?(method_name, true)- end-- def after_update_attributes- if params[:order] && params[:order][:coupon_code].present?- handler = PromotionHandler::Coupon.new(@order)- handler.apply-- if handler.error.present?- @coupon_message = handler.error- respond_with(@order, default_template: 'spree/api/v1/orders/could_not_apply_coupon', status: 422)- return true- end- end- false- end-- def log_state_changes- if @order.previous_changes[:state]- @order.log_state_changes(- state_name: 'order',- old_state: @order.previous_changes[:state].first,- new_state: @order.previous_changes[:state].last- )- end- end-- def order_id- super || params[:id]- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/classifications_controller.rb b/api/app/controllers/spree/api/v1/classifications_controller.rbdeleted file mode 100644index 5ad7b9a3f7..0000000000--- a/api/app/controllers/spree/api/v1/classifications_controller.rb+++ /dev/null@@ -1,21 +0,0 @@-module Spree- module Api- module V1- class ClassificationsController < Spree::Api::BaseController- def update- authorize! :update, Product- authorize! :update, Taxon- classification = Spree::Classification.find_by(- product_id: params[:product_id],- taxon_id: params[:taxon_id]- )- Spree::Dependencies.classification_reposition_service.constantize.call(- classification: classification,- position: params[:position]- )- head :ok- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/countries_controller.rb b/api/app/controllers/spree/api/v1/countries_controller.rbdeleted file mode 100644index 2b20b40f74..0000000000--- a/api/app/controllers/spree/api/v1/countries_controller.rb+++ /dev/null@@ -1,22 +0,0 @@-module Spree- module Api- module V1- class CountriesController < Spree::Api::BaseController- skip_before_action :authenticate_user-- def index- @countries = Country.accessible_by(current_ability).ransack(params[:q]).result.- order('name ASC').- page(params[:page]).per(params[:per_page])- country = Country.order('updated_at ASC').last- respond_with(@countries) if stale?(country)- end-- def show- @country = Country.accessible_by(current_ability, :show).find(params[:id])- respond_with(@country)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/credit_cards_controller.rb b/api/app/controllers/spree/api/v1/credit_cards_controller.rbdeleted file mode 100644index f1d39f27d5..0000000000--- a/api/app/controllers/spree/api/v1/credit_cards_controller.rb+++ /dev/null@@ -1,26 +0,0 @@-module Spree- module Api- module V1- class CreditCardsController < Spree::Api::BaseController- before_action :user-- def index- @credit_cards = user.- credit_cards.- accessible_by(current_ability).- with_payment_profile.- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@credit_cards)- end-- private-- def user- if params[:user_id].present?- @user ||= Spree.user_class.accessible_by(current_ability, :show).find(params[:user_id])- end- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/customer_returns_controller.rb b/api/app/controllers/spree/api/v1/customer_returns_controller.rbdeleted file mode 100644index 41f11e6fff..0000000000--- a/api/app/controllers/spree/api/v1/customer_returns_controller.rb+++ /dev/null@@ -1,25 +0,0 @@-module Spree- module Api- module V1- class CustomerReturnsController < Spree::Api::BaseController- def index- collection(Spree::CustomerReturn)- respond_with(@collection)- end-- private-- def collection(resource)- return @collection if @collection.present?-- params[:q] ||= {}-- @collection = resource.all- # @search needs to be defined as this is passed to search_form_for- @search = @collection.ransack(params[:q])- @collection = @search.result.order(created_at: :desc).page(params[:page]).per(params[:per_page])- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/images_controller.rb b/api/app/controllers/spree/api/v1/images_controller.rbdeleted file mode 100644index 1207b9e5ed..0000000000--- a/api/app/controllers/spree/api/v1/images_controller.rb+++ /dev/null@@ -1,58 +0,0 @@-module Spree- module Api- module V1- class ImagesController < Spree::Api::BaseController- def index- @images = scope.images.accessible_by(current_ability)- respond_with(@images)- end-- def show- @image = Image.accessible_by(current_ability, :show).find(params[:id])- respond_with(@image)- end-- def new; end-- def create- authorize! :create, Image- @image = scope.images.new(image_params)- if @image.save- respond_with(@image, status: 201, default_template: :show)- else- invalid_resource!(@image)- end- end-- def update- @image = scope.images.accessible_by(current_ability, :update).find(params[:id])- if @image.update(image_params)- respond_with(@image, default_template: :show)- else- invalid_resource!(@image)- end- end-- def destroy- @image = scope.images.accessible_by(current_ability, :destroy).find(params[:id])- @image.destroy- respond_with(@image, status: 204)- end-- private-- def image_params- params.require(:image).permit(permitted_image_attributes)- end-- def scope- if params[:product_id]- Spree::Product.friendly.find(params[:product_id])- elsif params[:variant_id]- Spree::Variant.find(params[:variant_id])- end- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/inventory_units_controller.rb b/api/app/controllers/spree/api/v1/inventory_units_controller.rbdeleted file mode 100644index 96c969e301..0000000000--- a/api/app/controllers/spree/api/v1/inventory_units_controller.rb+++ /dev/null@@ -1,54 +0,0 @@-module Spree- module Api- module V1- class InventoryUnitsController < Spree::Api::BaseController- before_action :prepare_event, only: :update-- def show- @inventory_unit = inventory_unit- respond_with(@inventory_unit)- end-- def update- authorize! :update, inventory_unit.order-- inventory_unit.transaction do- if inventory_unit.update(inventory_unit_params)- fire- render :show, status: 200- else- invalid_resource!(inventory_unit)- end- end- end-- private-- def inventory_unit- @inventory_unit ||= InventoryUnit.accessible_by(current_ability, :show).find(params[:id])- end-- def prepare_event- return unless @event = params[:fire]-- can_event = "can_#{@event}?"-- unless inventory_unit.respond_to?(can_event) &&- inventory_unit.send(can_event)- render plain: { exception: "cannot transition to #{@event}" }.to_json,- status: 200- false- end- end-- def fire- inventory_unit.send("#{@event}!") if @event- end-- def inventory_unit_params- params.require(:inventory_unit).permit(permitted_inventory_unit_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/line_items_controller.rb b/api/app/controllers/spree/api/v1/line_items_controller.rbdeleted file mode 100644index c2941d8f02..0000000000--- a/api/app/controllers/spree/api/v1/line_items_controller.rb+++ /dev/null@@ -1,70 +0,0 @@-module Spree- module Api- module V1- class LineItemsController < Spree::Api::BaseController- class_attribute :line_item_options-- self.line_item_options = []-- def new; end-- def create- variant = Spree::Variant.find(params[:line_item][:variant_id])-- @line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: order,- variant: variant,- quantity: params[:line_item][:quantity],- options: line_item_params[:options]).value- if @line_item.errors.empty?- respond_with(@line_item, status: 201, default_template: :show)- else- invalid_resource!(@line_item)- end- end-- def update- @line_item = find_line_item-- if Spree::Dependencies.cart_update_service.constantize.call(order: @order, params: line_items_attributes).success?- @line_item.reload- respond_with(@line_item, default_template: :show)- else- invalid_resource!(@line_item)- end- end-- def destroy- @line_item = find_line_item- Spree::Dependencies.cart_remove_line_item_service.constantize.call(order: @order, line_item: @line_item)-- respond_with(@line_item, status: 204)- end-- private-- def order- @order ||= Spree::Order.includes(:line_items).find_by!(number: order_id)- authorize! :update, @order, order_token- end-- def find_line_item- id = params[:id].to_i- order.line_items.detect { |line_item| line_item.id == id } or- raise ActiveRecord::RecordNotFound- end-- def line_items_attributes- { line_items_attributes: {- id: params[:id],- quantity: params[:line_item][:quantity],- options: line_item_params[:options] || {}- } }- end-- def line_item_params- params.require(:line_item).permit(:quantity, :variant_id, options: line_item_options)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/option_types_controller.rb b/api/app/controllers/spree/api/v1/option_types_controller.rbdeleted file mode 100644index 96559a6005..0000000000--- a/api/app/controllers/spree/api/v1/option_types_controller.rb+++ /dev/null@@ -1,60 +0,0 @@-module Spree- module Api- module V1- class OptionTypesController < Spree::Api::BaseController- def index- @option_types = if params[:ids]- Spree::OptionType.- includes(:option_values).- accessible_by(current_ability).- where(id: params[:ids].split(','))- else- Spree::OptionType.- includes(:option_values).- accessible_by(current_ability).- load.ransack(params[:q]).result- end- respond_with(@option_types)- end-- def show- @option_type = Spree::OptionType.accessible_by(current_ability, :show).find(params[:id])- respond_with(@option_type)- end-- def new; end-- def create- authorize! :create, Spree::OptionType- @option_type = Spree::OptionType.new(option_type_params)- if @option_type.save- render :show, status: 201- else- invalid_resource!(@option_type)- end- end-- def update- @option_type = Spree::OptionType.accessible_by(current_ability, :update).find(params[:id])- if @option_type.update(option_type_params)- render :show- else- invalid_resource!(@option_type)- end- end-- def destroy- @option_type = Spree::OptionType.accessible_by(current_ability, :destroy).find(params[:id])- @option_type.destroy- render plain: nil, status: 204- end-- private-- def option_type_params- params.require(:option_type).permit(permitted_option_type_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/option_values_controller.rb b/api/app/controllers/spree/api/v1/option_values_controller.rbdeleted file mode 100644index 5a34753295..0000000000--- a/api/app/controllers/spree/api/v1/option_values_controller.rb+++ /dev/null@@ -1,62 +0,0 @@-module Spree- module Api- module V1- class OptionValuesController < Spree::Api::BaseController- def index- @option_values = if params[:ids]- scope.where(id: params[:ids])- else- scope.ransack(params[:q]).result.distinct- end- respond_with(@option_values)- end-- def show- @option_value = scope.find(params[:id])- respond_with(@option_value)- end-- def new; end-- def create- authorize! :create, Spree::OptionValue- @option_value = scope.new(option_value_params)- if @option_value.save- render :show, status: 201- else- invalid_resource!(@option_value)- end- end-- def update- @option_value = scope.accessible_by(current_ability, :update).find(params[:id])- if @option_value.update(option_value_params)- render :show- else- invalid_resource!(@option_value)- end- end-- def destroy- @option_value = scope.accessible_by(current_ability, :destroy).find(params[:id])- @option_value.destroy- render plain: nil, status: 204- end-- private-- def scope- @scope ||= if params[:option_type_id]- Spree::OptionType.find(params[:option_type_id]).option_values.accessible_by(current_ability, :show)- else- Spree::OptionValue.accessible_by(current_ability, :show).load- end- end-- def option_value_params- params.require(:option_value).permit(permitted_option_value_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/orders_controller.rb b/api/app/controllers/spree/api/v1/orders_controller.rbdeleted file mode 100644index d9b0dcff81..0000000000--- a/api/app/controllers/spree/api/v1/orders_controller.rb+++ /dev/null@@ -1,160 +0,0 @@-module Spree- module Api- module V1- class OrdersController < Spree::Api::BaseController- skip_before_action :authenticate_user, only: :apply_coupon_code-- before_action :find_order, except: [:create, :mine, :current, :index, :update, :remove_coupon_code]-- # Dynamically defines our stores checkout steps to ensure we check authorization on each step.- Order.checkout_steps.keys.each do |step|- define_method step do- find_order- authorize! :update, @order, params[:token]- end- end-- def cancel- authorize! :update, @order, params[:token]- @order.canceled_by(current_api_user)- respond_with(@order, default_template: :show)- end-- def approve- authorize! :approve, @order, params[:token]- @order.approved_by(current_api_user)- respond_with(@order, default_template: :show)- end-- def create- authorize! :create, Spree::Order- if can?(:admin, Spree::Order)- order_user = if @current_user_roles.include?('admin') && order_params[:user_id]- Spree.user_class.find(order_params[:user_id])- else- current_api_user- end-- import_params = if @current_user_roles.include?('admin')- params[:order].present? ? params[:order].permit! : {}- else- order_params- end-- @order = Spree::Core::Importer::Order.import(order_user, import_params)-- respond_with(@order, default_template: :show, status: 201)- else- @order = Spree::Order.create!(user: current_api_user, store: current_store)- if Cart::Update.call(order: @order, params: order_params).success?- respond_with(@order, default_template: :show, status: 201)- else- invalid_resource!(@order)- end- end- end-- def empty- authorize! :update, @order, order_token- cart_empty_service.call(order: @order)- render plain: nil, status: 204- end-- def index- authorize! :index, Order- @orders = Order.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@orders)- end-- def show- authorize! :show, @order, order_token- respond_with(@order)- end-- def update- find_order(true)- authorize! :update, @order, order_token-- if Cart::Update.call(order: @order, params: order_params).success?- user_id = params[:order][:user_id]- if current_api_user.has_spree_role?('admin') && user_id- @order.associate_user!(Spree.user_class.find(user_id))- end- respond_with(@order, default_template: :show)- else- invalid_resource!(@order)- end- end-- def current- @order = find_current_order- if @order- respond_with(@order, default_template: :show, locals: { root_object: @order })- else- head :no_content- end- end-- def mine- if current_api_user.persisted?- @orders = current_api_user.orders.reverse_chronological.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- else- render 'spree/api/errors/unauthorized', status: :unauthorized- end- end-- def apply_coupon_code- find_order- authorize! :update, @order, order_token- @order.coupon_code = params[:coupon_code]- @handler = PromotionHandler::Coupon.new(@order).apply- status = @handler.successful? ? 200 : 422- render 'spree/api/v1/promotions/handler', status: status- end-- def remove_coupon_code- find_order(true)- authorize! :update, @order, order_token- @handler = Spree::PromotionHandler::Coupon.new(@order).remove(params[:coupon_code])- status = @handler.successful? ? 200 : 404- render 'spree/api/v1/promotions/handler', status: status- end-- private-- def order_params- if params[:order]- normalize_params- params.require(:order).permit(permitted_order_attributes)- else- {}- end- end-- def normalize_params- params[:order][:payments_attributes] = params[:order].delete(:payments) if params[:order][:payments]- params[:order][:shipments_attributes] = params[:order].delete(:shipments) if params[:order][:shipments]- params[:order][:line_items_attributes] = params[:order].delete(:line_items) if params[:order][:line_items]- params[:order][:ship_address_attributes] = params[:order].delete(:ship_address) if params[:order][:ship_address]- params[:order][:bill_address_attributes] = params[:order].delete(:bill_address) if params[:order][:bill_address]- end-- def find_order(lock = false)- @order = Spree::Order.lock(lock).find_by!(number: params[:id])- end-- def find_current_order- current_api_user ? current_api_user.orders.incomplete.order(:created_at).last : nil- end-- def order_id- super || params[:id]- end-- def cart_empty_service- Spree::Dependencies.cart_empty_service.constantize- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/payments_controller.rb b/api/app/controllers/spree/api/v1/payments_controller.rbdeleted file mode 100644index c49b2e21c3..0000000000--- a/api/app/controllers/spree/api/v1/payments_controller.rb+++ /dev/null@@ -1,82 +0,0 @@-module Spree- module Api- module V1- class PaymentsController < Spree::Api::BaseController- before_action :find_order- before_action :find_payment, only: [:update, :show, :authorize, :purchase, :capture, :void]-- def index- @payments = @order.payments.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@payments)- end-- def new- @payment_methods = Spree::PaymentMethod.available- respond_with(@payment_methods)- end-- def create- @order.validate_payments_attributes([payment_params])- @payment = @order.payments.build(payment_params)- if @payment.save- respond_with(@payment, status: 201, default_template: :show)- else- invalid_resource!(@payment)- end- end-- def update- authorize! params[:action], @payment- if [email protected]?- render 'update_forbidden', status: 403- elsif @payment.update(payment_params)- respond_with(@payment, default_template: :show)- else- invalid_resource!(@payment)- end- end-- def show- respond_with(@payment)- end-- def authorize- perform_payment_action(:authorize)- end-- def capture- perform_payment_action(:capture)- end-- def purchase- perform_payment_action(:purchase)- end-- def void- perform_payment_action(:void_transaction)- end-- private-- def find_order- @order = Spree::Order.find_by!(number: order_id)- authorize! :show, @order, order_token- end-- def find_payment- @payment = @order.payments.find_by!(number: params[:id])- end-- def perform_payment_action(action, *args)- authorize! action, Payment- @payment.send("#{action}!", *args)- respond_with(@payment, default_template: :show)- end-- def payment_params- params.require(:payment).permit(permitted_payment_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/product_properties_controller.rb b/api/app/controllers/spree/api/v1/product_properties_controller.rbdeleted file mode 100644index a43e46b961..0000000000--- a/api/app/controllers/spree/api/v1/product_properties_controller.rb+++ /dev/null@@ -1,73 +0,0 @@-module Spree- module Api- module V1- class ProductPropertiesController < Spree::Api::BaseController- before_action :find_product, :authorize_product!- before_action :product_property, only: [:show, :update, :destroy]-- def index- @product_properties = @product.product_properties.accessible_by(current_ability).- ransack(params[:q]).result.- page(params[:page]).per(params[:per_page])- respond_with(@product_properties)- end-- def show- respond_with(@product_property)- end-- def new; end-- def create- authorize! :create, ProductProperty- @product_property = @product.product_properties.new(product_property_params)- if @product_property.save- respond_with(@product_property, status: 201, default_template: :show)- else- invalid_resource!(@product_property)- end- end-- def update- authorize! :update, @product_property-- if @product_property.update(product_property_params)- respond_with(@product_property, status: 200, default_template: :show)- else- invalid_resource!(@product_property)- end- end-- def destroy- authorize! :destroy, @product_property- @product_property.destroy- respond_with(@product_property, status: 204)- end-- private-- def find_product- super(params[:product_id])- end-- def authorize_product!- authorize! :show, @product- end-- def product_property- if @product- @product_property ||= @product.product_properties.find_by(id: params[:id])- @product_property ||= @product.product_properties.includes(:property).where(spree_properties: { name: params[:id] }).first- raise ActiveRecord::RecordNotFound unless @product_property-- authorize! :show, @product_property- end- end-- def product_property_params- params.require(:product_property).permit(permitted_product_properties_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/products_controller.rb b/api/app/controllers/spree/api/v1/products_controller.rbdeleted file mode 100644index d34e3a45c0..0000000000--- a/api/app/controllers/spree/api/v1/products_controller.rb+++ /dev/null@@ -1,131 +0,0 @@-module Spree- module Api- module V1- class ProductsController < Spree::Api::BaseController- before_action :find_product, only: [:update, :show, :destroy]-- def index- @products = if params[:ids]- product_scope.where(id: params[:ids].split(',').flatten)- else- product_scope.ransack(params[:q]).result- end-- @products = @products.distinct.page(params[:page]).per(params[:per_page])- expires_in 15.minutes, public: true- headers['Surrogate-Control'] = "max-age=#{15.minutes}"- respond_with(@products)- end-- def show- expires_in 15.minutes, public: true- headers['Surrogate-Control'] = "max-age=#{15.minutes}"- headers['Surrogate-Key'] = 'product_id=1'- respond_with(@product)- end-- # Takes besides the products attributes either an array of variants or- # an array of option types.- #- # By submitting an array of variants the option types will be created- # using the *name* key in options hash. e.g- #- # product: {- # ...- # variants: {- # price: 19.99,- # sku: "hey_you",- # options: [- # { name: "size", value: "small" },- # { name: "color", value: "black" }- # ]- # }- # }- #- # Or just pass in the option types hash:- #- # product: {- # ...- # option_types: ['size', 'color']- # }- #- # By passing the shipping category name you can fetch or create that- # shipping category on the fly. e.g.- #- # product: {- # ...- # shipping_category: "Free Shipping Items"- # }- #- def new; end-- def create- authorize! :create, Product- params[:product][:available_on] ||= Time.current- set_up_shipping_category-- options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }- @product = Core::Importer::Product.new(nil, product_params, options).create-- if @product.persisted?- respond_with(@product, status: 201, default_template: :show)- else- invalid_resource!(@product)- end- end-- def update- authorize! :update, @product-- options = { store: current_store, variants_attrs: variants_params, options_attrs: option_types_params }- @product = Core::Importer::Product.new(@product, product_params, options).update-- if @product.errors.empty?- respond_with(@product.reload, status: 200, default_template: :show)- else- invalid_resource!(@product)- end- end-- def destroy- authorize! :destroy, @product- @product.destroy- respond_with(@product, status: 204)- end-- private-- def product_params- params.require(:product).permit(permitted_product_attributes)- end-- def variants_params- variants_key = if params[:product].key? :variants- :variants- else- :variants_attributes- end-- params.require(:product).permit(- variants_key => [permitted_variant_attributes, :id]- ).delete(variants_key) || []- end-- def option_types_params- params[:product].fetch(:option_types, [])- end-- def find_product- super(params[:id])- end-- def set_up_shipping_category- if shipping_category = params[:product].delete(:shipping_category)- id = ShippingCategory.find_or_create_by(name: shipping_category).id- params[:product][:shipping_category_id] = id- end- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/promotions_controller.rb b/api/app/controllers/spree/api/v1/promotions_controller.rbdeleted file mode 100644index 92eea86979..0000000000--- a/api/app/controllers/spree/api/v1/promotions_controller.rb+++ /dev/null@@ -1,30 +0,0 @@-module Spree- module Api- module V1- class PromotionsController < Spree::Api::BaseController- before_action :requires_admin- before_action :load_promotion-- def show- if @promotion- respond_with(@promotion, default_template: :show)- else- raise ActiveRecord::RecordNotFound- end- end-- private-- def requires_admin- return if @current_user_roles.include?('admin')-- unauthorized and return- end-- def load_promotion- @promotion = Spree::Promotion.find_by(id: params[:id]) || Spree::Promotion.with_coupon_code(params[:id])- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/properties_controller.rb b/api/app/controllers/spree/api/v1/properties_controller.rbdeleted file mode 100644index 64a2e7907c..0000000000--- a/api/app/controllers/spree/api/v1/properties_controller.rb+++ /dev/null@@ -1,70 +0,0 @@-module Spree- module Api- module V1- class PropertiesController < Spree::Api::BaseController- before_action :find_property, only: [:show, :update, :destroy]-- def index- @properties = Spree::Property.accessible_by(current_ability)-- @properties = if params[:ids]- @properties.where(id: params[:ids].split(',').flatten)- else- @properties.ransack(params[:q]).result- end-- @properties = @properties.page(params[:page]).per(params[:per_page])- respond_with(@properties)- end-- def show- respond_with(@property)- end-- def new; end-- def create- authorize! :create, Property- @property = Spree::Property.new(property_params)- if @property.save- respond_with(@property, status: 201, default_template: :show)- else- invalid_resource!(@property)- end- end-- def update- if @property- authorize! :update, @property- @property.update(property_params)- respond_with(@property, status: 200, default_template: :show)- else- invalid_resource!(@property)- end- end-- def destroy- if @property- authorize! :destroy, @property- @property.destroy- respond_with(@property, status: 204)- else- invalid_resource!(@property)- end- end-- private-- def find_property- @property = Spree::Property.accessible_by(current_ability, :show).find(params[:id])- rescue ActiveRecord::RecordNotFound- @property = Spree::Property.accessible_by(current_ability, :show).find_by!(name: params[:id])- end-- def property_params- params.require(:property).permit(permitted_property_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/reimbursements_controller.rb b/api/app/controllers/spree/api/v1/reimbursements_controller.rbdeleted file mode 100644index 09685edd18..0000000000--- a/api/app/controllers/spree/api/v1/reimbursements_controller.rb+++ /dev/null@@ -1,25 +0,0 @@-module Spree- module Api- module V1- class ReimbursementsController < Spree::Api::BaseController- def index- collection(Spree::Reimbursement)- respond_with(@collection)- end-- private-- def collection(resource)- return @collection if @collection.present?-- params[:q] ||= {}-- @collection = resource.all- # @search needs to be defined as this is passed to search_form_for- @search = @collection.ransack(params[:q])- @collection = @search.result.order(created_at: :desc).page(params[:page]).per(params[:per_page])- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb b/api/app/controllers/spree/api/v1/return_authorizations_controller.rbdeleted file mode 100644index 5ea2ec9810..0000000000--- a/api/app/controllers/spree/api/v1/return_authorizations_controller.rb+++ /dev/null@@ -1,70 +0,0 @@-module Spree- module Api- module V1- class ReturnAuthorizationsController < Spree::Api::BaseController- def create- authorize! :create, ReturnAuthorization- @return_authorization = order.return_authorizations.build(return_authorization_params)- if @return_authorization.save- respond_with(@return_authorization, status: 201, default_template: :show)- else- invalid_resource!(@return_authorization)- end- end-- def destroy- @return_authorization = order.return_authorizations.accessible_by(current_ability, :destroy).find(params[:id])- @return_authorization.destroy- respond_with(@return_authorization, status: 204)- end-- def index- authorize! :admin, ReturnAuthorization- @return_authorizations = order.return_authorizations.accessible_by(current_ability).- ransack(params[:q]).result.- page(params[:page]).per(params[:per_page])- respond_with(@return_authorizations)- end-- def new- authorize! :admin, ReturnAuthorization- end-- def show- authorize! :admin, ReturnAuthorization- @return_authorization = order.return_authorizations.accessible_by(current_ability, :show).find(params[:id])- respond_with(@return_authorization)- end-- def update- @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])- if @return_authorization.update(return_authorization_params)- respond_with(@return_authorization, default_template: :show)- else- invalid_resource!(@return_authorization)- end- end-- def cancel- @return_authorization = order.return_authorizations.accessible_by(current_ability, :update).find(params[:id])- if @return_authorization.cancel- respond_with @return_authorization, default_template: :show- else- invalid_resource!(@return_authorization)- end- end-- private-- def order- @order ||= Spree::Order.find_by!(number: order_id)- authorize! :show, @order- end-- def return_authorization_params- params.require(:return_authorization).permit(permitted_return_authorization_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/shipments_controller.rb b/api/app/controllers/spree/api/v1/shipments_controller.rbdeleted file mode 100644index aafbc4035f..0000000000--- a/api/app/controllers/spree/api/v1/shipments_controller.rb+++ /dev/null@@ -1,196 +0,0 @@-module Spree- module Api- module V1- class ShipmentsController < Spree::Api::BaseController- before_action :find_and_update_shipment, only: [:ship, :ready, :add, :remove]- before_action :load_transfer_params, only: [:transfer_to_location, :transfer_to_shipment]-- def mine- if current_api_user.persisted?- @shipments = Spree::Shipment.- reverse_chronological.- joins(:order).- where(spree_orders: { user_id: current_api_user.id }).- includes(mine_includes).- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- else- render 'spree/api/errors/unauthorized', status: :unauthorized- end- end-- def create- @order = Spree::Order.find_by!(number: params.fetch(:shipment).fetch(:order_id))- authorize! :show, @order- authorize! :create, Shipment- quantity = params[:quantity].to_i- @shipment = @order.shipments.create(stock_location_id: params.fetch(:stock_location_id))-- @line_item = Spree::Dependencies.cart_add_item_service.constantize.call(order: @order,- variant: variant,- quantity: quantity,- options: { shipment: @shipment }).value-- respond_with(@shipment.reload, default_template: :show)- end-- def update- @shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])- @shipment.update_attributes_and_order(shipment_params)-- respond_with(@shipment.reload, default_template: :show)- end-- def ready- unless @shipment.ready?- if @shipment.can_ready?- @shipment.ready!- else- render 'spree/api/v1/shipments/cannot_ready_shipment', status: 422 and return- end- end- respond_with(@shipment, default_template: :show)- end-- def ship- @shipment.ship! unless @shipment.shipped?- respond_with(@shipment, default_template: :show)- end-- def add- quantity = params[:quantity].to_i-- Spree::Dependencies.cart_add_item_service.constantize.call(order: @shipment.order,- variant: variant,- quantity: quantity,- options: { shipment: @shipment })-- respond_with(@shipment, default_template: :show)- end-- def remove- quantity = if params.key?(:quantity)- params[:quantity].to_i- else- @shipment.inventory_units_for(variant).sum(:quantity)- end-- Spree::Dependencies.cart_remove_item_service.constantize.call(order: @shipment.order,- variant: variant,- quantity: quantity,- options: { shipment: @shipment })-- if @shipment.inventory_units.any?- @shipment.reload- else- @shipment.destroy!- end-- respond_with(@shipment, default_template: :show)- end-- def transfer_to_location- @stock_location = Spree::StockLocation.find(params[:stock_location_id])-- unless @quantity > 0- unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n #{Spree.t(:negative_quantity, scope: 'api')}")- return- end-- transfer = @original_shipment.transfer_to_location(@variant, @quantity, @stock_location)- if transfer.valid?- transfer.run!- render json: { message: Spree.t(:shipment_transfer_success) }, status: 201- else- render json: { message: transfer.errors.full_messages.to_sentence }, status: 422- end- end-- def transfer_to_shipment- @target_shipment = Spree::Shipment.find_by!(number: params[:target_shipment_number])-- error =- if @quantity < 0 && @target_shipment == @original_shipment- "#{Spree.t(:negative_quantity, scope: 'api')}, \n#{Spree.t('wrong_shipment_target', scope: 'api')}"- elsif @target_shipment == @original_shipment- Spree.t(:wrong_shipment_target, scope: 'api')- elsif @quantity < 0- Spree.t(:negative_quantity, scope: 'api')- end-- if error- unprocessable_entity("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n#{error}")- else- transfer = @original_shipment.transfer_to_shipment(@variant, @quantity, @target_shipment)- if transfer.valid?- transfer.run!- render json: { message: Spree.t(:shipment_transfer_success) }, status: 201- else- render json: { message: transfer.errors.full_messages }, status: 422- end- end- end-- private-- def load_transfer_params- @original_shipment = Spree::Shipment.find_by!(number: params[:original_shipment_number])- @variant = Spree::Variant.find(params[:variant_id])- @quantity = params[:quantity].to_i- authorize! :show, @original_shipment- authorize! :create, Shipment- end-- def find_and_update_shipment- @shipment = Spree::Shipment.accessible_by(current_ability, :update).readonly(false).find_by!(number: params[:id])- @shipment.update(shipment_params)- @shipment.reload- end-- def shipment_params- if params[:shipment] && !params[:shipment].empty?- params.require(:shipment).permit(permitted_shipment_attributes)- else- {}- end- end-- def variant- @variant ||= Spree::Variant.unscoped.find(params.fetch(:variant_id))- end-- def mine_includes- {- order: {- bill_address: {- state: {},- country: {}- },- ship_address: {- state: {},- country: {}- },- adjustments: {},- payments: {- order: {},- payment_method: {}- }- },- inventory_units: {- line_item: {- product: {},- variant: {}- },- variant: {- product: {},- default_price: {},- option_values: {- option_type: {}- }- }- }- }- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/states_controller.rb b/api/app/controllers/spree/api/v1/states_controller.rbdeleted file mode 100644index 382f8d3abd..0000000000--- a/api/app/controllers/spree/api/v1/states_controller.rb+++ /dev/null@@ -1,36 +0,0 @@-module Spree- module Api- module V1- class StatesController < Spree::Api::BaseController- skip_before_action :authenticate_user-- def index- @states = scope.ransack(params[:q]).result.includes(:country)-- if params[:page] || params[:per_page]- @states = @states.page(params[:page]).per(params[:per_page])- end-- state = @states.last- respond_with(@states) if stale?(state)- end-- def show- @state = scope.find(params[:id])- respond_with(@state)- end-- private-- def scope- if params[:country_id]- @country = Country.accessible_by(current_ability, :show).find(params[:country_id])- @country.states.accessible_by(current_ability).order('name ASC')- else- State.accessible_by(current_ability).order('name ASC')- end- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/stock_items_controller.rb b/api/app/controllers/spree/api/v1/stock_items_controller.rbdeleted file mode 100644index 18ab46009a..0000000000--- a/api/app/controllers/spree/api/v1/stock_items_controller.rb+++ /dev/null@@ -1,82 +0,0 @@-module Spree- module Api- module V1- class StockItemsController < Spree::Api::BaseController- before_action :stock_location, except: [:update, :destroy]-- def index- @stock_items = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@stock_items)- end-- def show- @stock_item = scope.find(params[:id])- respond_with(@stock_item)- end-- def create- authorize! :create, StockItem-- count_on_hand = 0- if params[:stock_item].key?(:count_on_hand)- count_on_hand = params[:stock_item][:count_on_hand].to_i- end-- @stock_item = scope.new(stock_item_params)- if @stock_item.save- @stock_item.adjust_count_on_hand(count_on_hand)- respond_with(@stock_item, status: 201, default_template: :show)- else- invalid_resource!(@stock_item)- end- end-- def update- @stock_item = StockItem.accessible_by(current_ability, :update).find(params[:id])-- if params[:stock_item].key?(:backorderable)- @stock_item.backorderable = params[:stock_item][:backorderable]- @stock_item.save- end-- count_on_hand = 0- if params[:stock_item].key?(:count_on_hand)- count_on_hand = params[:stock_item][:count_on_hand].to_i- params[:stock_item].delete(:count_on_hand)- end-- updated = params[:stock_item][:force] ? @stock_item.set_count_on_hand(count_on_hand)- : @stock_item.adjust_count_on_hand(count_on_hand)-- if updated- respond_with(@stock_item, status: 200, default_template: :show)- else- invalid_resource!(@stock_item)- end- end-- def destroy- @stock_item = StockItem.accessible_by(current_ability, :destroy).find(params[:id])- @stock_item.destroy- respond_with(@stock_item, status: 204)- end-- private-- def stock_location- render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]- @stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id])- end-- def scope- includes = { variant: [{ option_values: :option_type }, :product] }- @stock_location.stock_items.accessible_by(current_ability, :show).includes(includes)- end-- def stock_item_params- params.require(:stock_item).permit(permitted_stock_item_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/stock_locations_controller.rb b/api/app/controllers/spree/api/v1/stock_locations_controller.rbdeleted file mode 100644index 1eacab8dfa..0000000000--- a/api/app/controllers/spree/api/v1/stock_locations_controller.rb+++ /dev/null@@ -1,53 +0,0 @@-module Spree- module Api- module V1- class StockLocationsController < Spree::Api::BaseController- def index- authorize! :index, StockLocation- @stock_locations = StockLocation.accessible_by(current_ability).order('name ASC').- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@stock_locations)- end-- def show- respond_with(stock_location)- end-- def create- authorize! :create, StockLocation- @stock_location = StockLocation.new(stock_location_params)- if @stock_location.save- respond_with(@stock_location, status: 201, default_template: :show)- else- invalid_resource!(@stock_location)- end- end-- def update- authorize! :update, stock_location- if stock_location.update(stock_location_params)- respond_with(stock_location, status: 200, default_template: :show)- else- invalid_resource!(stock_location)- end- end-- def destroy- authorize! :destroy, stock_location- stock_location.destroy- respond_with(stock_location, status: 204)- end-- private-- def stock_location- @stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:id])- end-- def stock_location_params- params.require(:stock_location).permit(permitted_stock_location_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/stock_movements_controller.rb b/api/app/controllers/spree/api/v1/stock_movements_controller.rbdeleted file mode 100644index a1515b5f56..0000000000--- a/api/app/controllers/spree/api/v1/stock_movements_controller.rb+++ /dev/null@@ -1,45 +0,0 @@-module Spree- module Api- module V1- class StockMovementsController < Spree::Api::BaseController- before_action :stock_location, except: [:update, :destroy]-- def index- authorize! :index, StockMovement- @stock_movements = scope.ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@stock_movements)- end-- def show- @stock_movement = scope.find(params[:id])- respond_with(@stock_movement)- end-- def create- authorize! :create, StockMovement- @stock_movement = scope.new(stock_movement_params)- if @stock_movement.save- respond_with(@stock_movement, status: 201, default_template: :show)- else- invalid_resource!(@stock_movement)- end- end-- private-- def stock_location- render 'spree/api/v1/shared/stock_location_required', status: 422 and return unless params[:stock_location_id]- @stock_location ||= StockLocation.accessible_by(current_ability, :show).find(params[:stock_location_id])- end-- def scope- @stock_location.stock_movements.accessible_by(current_ability, :show)- end-- def stock_movement_params- params.require(:stock_movement).permit(permitted_stock_movement_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/stores_controller.rb b/api/app/controllers/spree/api/v1/stores_controller.rbdeleted file mode 100644index 33be6ed611..0000000000--- a/api/app/controllers/spree/api/v1/stores_controller.rb+++ /dev/null@@ -1,56 +0,0 @@-module Spree- module Api- module V1- class StoresController < Spree::Api::BaseController- before_action :get_store, except: [:index, :create]-- def index- authorize! :index, Store- @stores = Store.accessible_by(current_ability).all- respond_with(@stores)- end-- def create- authorize! :create, Store- @store = Store.new(store_params)- @store.code = params[:store][:code]- if @store.save- respond_with(@store, status: 201, default_template: :show)- else- invalid_resource!(@store)- end- end-- def update- authorize! :update, @store- if @store.update(store_params)- respond_with(@store, status: 200, default_template: :show)- else- invalid_resource!(@store)- end- end-- def show- authorize! :show, @store- respond_with(@store)- end-- def destroy- authorize! :destroy, @store- @store.destroy- respond_with(@store, status: 204)- end-- private-- def get_store- @store = Store.find(params[:id])- end-- def store_params- params.require(:store).permit(permitted_store_attributes)- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/taxonomies_controller.rb b/api/app/controllers/spree/api/v1/taxonomies_controller.rbdeleted file mode 100644index 770bf9055b..0000000000--- a/api/app/controllers/spree/api/v1/taxonomies_controller.rb+++ /dev/null@@ -1,67 +0,0 @@-module Spree- module Api- module V1- class TaxonomiesController < Spree::Api::BaseController- def index- respond_with(taxonomies)- end-- def show- respond_with(taxonomy)- end-- # Because JSTree wants parameters in a *slightly* different format- def jstree- show- end-- def new; end-- def create- authorize! :create, Taxonomy- @taxonomy = current_store.taxonomies.new(taxonomy_params)- if @taxonomy.save- respond_with(@taxonomy, status: 201, default_template: :show)- else- invalid_resource!(@taxonomy)- end- end-- def update- authorize! :update, taxonomy- if taxonomy.update(taxonomy_params)- respond_with(taxonomy, status: 200, default_template: :show)- else- invalid_resource!(taxonomy)- end- end-- def destroy- authorize! :destroy, taxonomy- taxonomy.destroy- respond_with(taxonomy, status: 204)- end-- private-- def taxonomies- @taxonomies = Taxonomy.accessible_by(current_ability).order('name').includes(root: :children).- ransack(params[:q]).result.- page(params[:page]).per(params[:per_page])- end-- def taxonomy- @taxonomy ||= Taxonomy.accessible_by(current_ability, :show).find(params[:id])- end-- def taxonomy_params- if params[:taxonomy] && !params[:taxonomy].empty?- params.require(:taxonomy).permit(permitted_taxonomy_attributes)- else- {}- end- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/taxons_controller.rb b/api/app/controllers/spree/api/v1/taxons_controller.rbdeleted file mode 100644index e93b1866a7..0000000000--- a/api/app/controllers/spree/api/v1/taxons_controller.rb+++ /dev/null@@ -1,100 +0,0 @@-module Spree- module Api- module V1- class TaxonsController < Spree::Api::BaseController- def index- @taxons = if taxonomy- taxonomy.root.children- elsif params[:ids]- Spree::Taxon.includes(:children).accessible_by(current_ability).where(id: params[:ids].split(','))- else- Spree::Taxon.includes(:children).accessible_by(current_ability).order(:taxonomy_id, :lft)- end- @taxons = @taxons.ransack(params[:q]).result- @taxons = @taxons.page(params[:page]).per(params[:per_page])- respond_with(@taxons)- end-- def show- @taxon = taxon- respond_with(@taxon)- end-- def jstree- show- end-- def new; end-- def create- authorize! :create, Taxon- @taxon = Spree::Taxon.new(taxon_params)- @taxon.taxonomy_id = params[:taxonomy_id]- taxonomy = Spree::Taxonomy.find_by(id: params[:taxonomy_id])-- if taxonomy.nil?- @taxon.errors.add(:taxonomy_id, I18n.t('spree.api.invalid_taxonomy_id'))- invalid_resource!(@taxon) and return- end-- @taxon.parent_id = taxonomy.root_id unless params[:taxon][:parent_id]-- if @taxon.save- respond_with(@taxon, status: 201, default_template: :show)- else- invalid_resource!(@taxon)- end- end-- def update- authorize! :update, taxon- if taxon.update(taxon_params)- respond_with(taxon, status: 200, default_template: :show)- else- invalid_resource!(taxon)- end- end-- def destroy- authorize! :destroy, taxon- taxon.destroy- respond_with(taxon, status: 204)- end-- def products- # Returns the products sorted by their position with the classification- # Products#index does not do the sorting.- taxon = Spree::Taxon.find(params[:id])- @products = taxon.products.ransack(params[:q]).result- @products = @products.page(params[:page]).per(params[:per_page] || 500)- render 'spree/api/v1/products/index'- end-- private-- def taxonomy- if params[:taxonomy_id].present?- @taxonomy ||=- if defined?(SpreeGlobalize)- Spree::Taxonomy.includes(:translations, taxons: [:translations]).accessible_by(current_ability, :show).find(params[:taxonomy_id])- else- Spree::Taxonomy.accessible_by(current_ability, :show).find(params[:taxonomy_id])- end- end- end-- def taxon- @taxon ||= taxonomy.taxons.accessible_by(current_ability, :show).find(params[:id])- end-- def taxon_params- if params[:taxon] && !params[:taxon].empty?- params.require(:taxon).permit(permitted_taxon_attributes)- else- {}- end- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/users_controller.rb b/api/app/controllers/spree/api/v1/users_controller.rbdeleted file mode 100644index e6b9054786..0000000000--- a/api/app/controllers/spree/api/v1/users_controller.rb+++ /dev/null@@ -1,97 +0,0 @@-module Spree- module Api- module V1- class UsersController < Spree::Api::BaseController- rescue_from Spree::Core::DestroyWithOrdersError, with: :error_during_processing-- def index- users-- if params[:ids]- load_users_by_ids- elsif params.dig(:q, :ship_address_firstname_start)- load_users_by_address- elsif params.dig(:q, :email_start)- load_users_by_email- end-- prepare_index_response- respond_with(@users)- end-- def users- @users ||= Spree.user_class.accessible_by(current_ability, :show)- end-- def load_users_by_ids- @users = @users.where(id: params[:ids])- end-- def load_users_by_address- address_params = params[:q][:ship_address_firstname_start] ||- params[:q][:ship_address_lastname_start] ||- params[:q][:bill_address_firstname_start] ||- params[:q][:bill_address_lastname_start]- @users = @users.with_email_or_address(params[:q][:email_start], address_params)- end-- def load_users_by_email- @users = @users.with_email(params[:q][:email_start])- end-- def paginate_users- @users = @users.page(params[:page]).per(params[:per_page])- end-- def prepare_index_response- paginate_users- expires_in 15.minutes, public: true- headers['Surrogate-Control'] = "max-age=#{15.minutes}"- end-- def show- respond_with(user)- end-- def new; end-- def create- authorize! :create, Spree.user_class- @user = Spree.user_class.new(user_params)- if @user.save- respond_with(@user, status: 201, default_template: :show)- else- invalid_resource!(@user)- end- end-- def update- authorize! :update, user- if user.update(user_params)- respond_with(user, status: 200, default_template: :show)- else- invalid_resource!(user)- end- end-- def destroy- authorize! :destroy, user- user.destroy- respond_with(user, status: 204)- end-- private-- def user- @user ||= Spree.user_class.accessible_by(current_ability, :show).find(params[:id])- end-- def user_params- params.require(:user).permit(permitted_user_attributes |- [bill_address_attributes: permitted_address_attributes,- ship_address_attributes: permitted_address_attributes])- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/variants_controller.rb b/api/app/controllers/spree/api/v1/variants_controller.rbdeleted file mode 100644index 0e63ec93ca..0000000000--- a/api/app/controllers/spree/api/v1/variants_controller.rb+++ /dev/null@@ -1,81 +0,0 @@-module Spree- module Api- module V1- class VariantsController < Spree::Api::BaseController- before_action :product-- def create- authorize! :create, Variant- @variant = scope.new(variant_params)- if @variant.save- respond_with(@variant, status: 201, default_template: :show)- else- invalid_resource!(@variant)- end- end-- def destroy- @variant = scope.accessible_by(current_ability, :destroy).find(params[:id])- @variant.destroy- respond_with(@variant, status: 204)- end-- # The lazyloaded associations here are pretty much attached to which nodes- # we render on the view so we better update it any time a node is included- # or removed from the views.- def index- @variants = scope.includes(*variant_includes).for_currency_and_available_price_amount.- ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@variants)- end-- def new; end-- def show- @variant = scope.includes(*variant_includes).find(params[:id])- respond_with(@variant)- end-- def update- @variant = scope.accessible_by(current_ability, :update).find(params[:id])- if @variant.update(variant_params)- respond_with(@variant, status: 200, default_template: :show)- else- invalid_resource!(@product)- end- end-- private-- def product- if params[:product_id]- @product ||= Spree::Product.accessible_by(current_ability, :show).- friendly.find(params[:product_id])- end- end-- def scope- variants = if @product- @product.variants_including_master- else- Variant- end-- if current_ability.can?(:manage, Variant) && params[:show_deleted]- variants = variants.with_deleted- end-- variants.eligible.accessible_by(current_ability)- end-- def variant_params- params.require(:variant).permit(permitted_variant_attributes)- end-- def variant_includes- [{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }]- end- end- end- end-enddiff --git a/api/app/controllers/spree/api/v1/zones_controller.rb b/api/app/controllers/spree/api/v1/zones_controller.rbdeleted file mode 100644index 769572bdf0..0000000000--- a/api/app/controllers/spree/api/v1/zones_controller.rb+++ /dev/null@@ -1,55 +0,0 @@-module Spree- module Api- module V1- class ZonesController < Spree::Api::BaseController- def create- authorize! :create, Zone- @zone = Spree::Zone.new(zone_params)- if @zone.save- respond_with(@zone, status: 201, default_template: :show)- else- invalid_resource!(@zone)- end- end-- def destroy- authorize! :destroy, zone- zone.destroy- respond_with(zone, status: 204)- end-- def index- @zones = Zone.accessible_by(current_ability).order('name ASC').ransack(params[:q]).result.page(params[:page]).per(params[:per_page])- respond_with(@zones)- end-- def show- respond_with(zone)- end-- def update- authorize! :update, zone- if zone.update(zone_params)- respond_with(zone, status: 200, default_template: :show)- else- invalid_resource!(zone)- end- end-- private-- def zone_params- attrs = params.require(:zone).permit!- if attrs[:zone_members]- attrs[:zone_members_attributes] = attrs.delete(:zone_members)- end- attrs- end-- def zone- @zone ||= Spree::Zone.accessible_by(current_ability, :show).find(params[:id])- end- end- end- end-enddiff --git a/api/app/helpers/spree/api/api_helpers.rb b/api/app/helpers/spree/api/api_helpers.rbdeleted file mode 100644index c3d384ca62..0000000000--- a/api/app/helpers/spree/api/api_helpers.rb+++ /dev/null@@ -1,190 +0,0 @@-module Spree- module Api- module ApiHelpers- ATTRIBUTES = [- :product_attributes,- :product_property_attributes,- :variant_attributes,- :image_attributes,- :option_value_attributes,- :order_attributes,- :line_item_attributes,- :option_type_attributes,- :payment_attributes,- :payment_method_attributes,- :shipment_attributes,- :taxonomy_attributes,- :taxon_attributes,- :address_attributes,- :country_attributes,- :state_attributes,- :adjustment_attributes,- :inventory_unit_attributes,- :return_authorization_attributes,- :creditcard_attributes,- :payment_source_attributes,- :user_attributes,- :property_attributes,- :stock_location_attributes,- :stock_movement_attributes,- :stock_item_attributes,- :promotion_attributes,- :store_attributes,- :tag_attributes,- :customer_return_attributes,- :reimbursement_attributes- ]-- mattr_reader *ATTRIBUTES-- def required_fields_for(model)- required_fields = model._validators.select do |_field, validations|- validations.any? { |v| v.is_a?(ActiveModel::Validations::PresenceValidator) }- end.map(&:first) # get fields that are invalid- # Permalinks presence is validated, but are really automatically generated- # Therefore we shouldn't tell API clients that they MUST send one through- required_fields.map!(&:to_s).delete('permalink')- # Do not require slugs, either- required_fields.delete('slug')- required_fields- end-- @@product_attributes = [- :id, :name, :description, :price, :display_price, :available_on,- :slug, :meta_description, :meta_keywords, :shipping_category_id,- :taxon_ids, :total_on_hand- ]-- @@product_property_attributes = [- :id, :product_id, :property_id, :value, :property_name- ]-- @@variant_attributes = [- :id, :name, :sku, :price, :weight, :height, :width, :depth, :is_master,- :slug, :description, :track_inventory- ]-- @@image_attributes = [- :id, :position, :attachment_content_type, :attachment_file_name, :type,- :attachment_updated_at, :attachment_width, :attachment_height, :alt- ]-- @@option_value_attributes = [- :id, :name, :presentation, :option_type_name, :option_type_id,- :option_type_presentation- ]-- @@order_attributes = [- :id, :number, :item_total, :total, :ship_total, :state, :adjustment_total,- :user_id, :created_at, :updated_at, :completed_at, :payment_total,- :shipment_state, :payment_state, :email, :special_instructions, :channel,- :included_tax_total, :additional_tax_total, :display_included_tax_total,- :display_additional_tax_total, :tax_total, :currency, :considered_risky,- :canceler_id- ]-- @@line_item_attributes = [:id, :quantity, :price, :variant_id]-- @@option_type_attributes = [:id, :name, :presentation, :position]-- @@payment_attributes = [- :id, :source_type, :source_id, :amount, :display_amount,- :payment_method_id, :state, :avs_response, :created_at,- :updated_at, :number- ]-- @@payment_method_attributes = [:id, :name, :description]-- @@shipment_attributes = [:id, :tracking, :number, :cost, :shipped_at, :state]-- @@taxonomy_attributes = [:id, :name]-- @@taxon_attributes = [- :id, :name, :pretty_name, :permalink, :parent_id,- :taxonomy_id, :meta_title, :meta_description- ]-- @@inventory_unit_attributes = [- :id, :lock_version, :state, :variant_id, :shipment_id,- :return_authorization_id- ]-- @@return_authorization_attributes = [- :id, :number, :state, :order_id, :memo, :created_at, :updated_at- ]-- @@address_attributes = [- :id, :firstname, :lastname, :full_name, :address1, :address2, :city,- :zipcode, :phone, :company, :alternative_phone, :country_id, :state_id,- :label, :state_name, :state_text- ]-- @@country_attributes = [:id, :iso_name, :iso, :iso3, :name, :numcode]-- @@state_attributes = [:id, :name, :abbr, :country_id]-- @@adjustment_attributes = [- :id, :source_type, :source_id, :adjustable_type, :adjustable_id,- :originator_type, :originator_id, :amount, :label, :mandatory,- :locked, :eligible, :created_at, :updated_at- ]-- @@creditcard_attributes = [- :id, :month, :year, :cc_type, :last_digits, :name,- :gateway_customer_profile_id, :gateway_payment_profile_id- ]-- @@payment_source_attributes = [- :id, :month, :year, :cc_type, :last_digits, :name- ]-- @@user_attributes = [:id, :email, :created_at, :updated_at]-- @@property_attributes = [:id, :name, :presentation]-- @@stock_location_attributes = [- :id, :name, :address1, :address2, :city, :state_id, :state_name,- :country_id, :zipcode, :phone, :active- ]-- @@stock_movement_attributes = [:id, :quantity, :stock_item_id]-- @@stock_item_attributes = [- :id, :count_on_hand, :backorderable, :lock_version, :stock_location_id,- :variant_id- ]-- @@promotion_attributes = [- :id, :name, :description, :expires_at, :starts_at, :type, :usage_limit,- :match_policy, :code, :advertise, :path- ]-- @@store_attributes = [- :id, :name, :url, :meta_description, :meta_keywords, :seo_title,- :mail_from_address, :customer_support_email, :default_currency,- :code, :default, :facebook, :twitter, :instagram,- :supported_currencies, :default_locale, :supported_locales- ]-- @@tag_attributes = [:id, :name]-- @@customer_return_attributes = [- :id, :number, :order_id, :fully_reimbursed?, :pre_tax_total,- :created_at, :updated_at- ]-- @@reimbursement_attributes = [- :id, :reimbursement_status, :customer_return_id, :order_id,- :number, :total, :created_at, :updated_at- ]-- def variant_attributes- if @current_user_roles&.include?('admin')- @@variant_attributes + [:cost_price]- else- @@variant_attributes- end- end- end- end-enddiff --git a/api/app/views/spree/api/errors/gateway_error.rabl b/api/app/views/spree/api/errors/gateway_error.rabldeleted file mode 100644index 4df2620dee..0000000000--- a/api/app/views/spree/api/errors/gateway_error.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:gateway_error, scope: 'spree.api', text: @error) }diff --git a/api/app/views/spree/api/errors/invalid_api_key.rabl b/api/app/views/spree/api/errors/invalid_api_key.rabldeleted file mode 100644index 2c22e71fb3..0000000000--- a/api/app/views/spree/api/errors/invalid_api_key.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:invalid_api_key, key: api_key, scope: 'spree.api') }diff --git a/api/app/views/spree/api/errors/invalid_resource.rabl b/api/app/views/spree/api/errors/invalid_resource.rabldeleted file mode 100644index 5ce6418009..0000000000--- a/api/app/views/spree/api/errors/invalid_resource.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:error) { I18n.t(:invalid_resource, scope: 'spree.api') }-node(:errors) { @resource.errors.to_hash }diff --git a/api/app/views/spree/api/errors/must_specify_api_key.rabl b/api/app/views/spree/api/errors/must_specify_api_key.rabldeleted file mode 100644index 5c34ad9dda..0000000000--- a/api/app/views/spree/api/errors/must_specify_api_key.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:must_specify_api_key, scope: 'spree.api') }diff --git a/api/app/views/spree/api/errors/not_found.rabl b/api/app/views/spree/api/errors/not_found.rabldeleted file mode 100644index 1fba5b7298..0000000000--- a/api/app/views/spree/api/errors/not_found.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:resource_not_found, scope: 'spree.api') }diff --git a/api/app/views/spree/api/errors/unauthorized.rabl b/api/app/views/spree/api/errors/unauthorized.rabldeleted file mode 100644index 4073205773..0000000000--- a/api/app/views/spree/api/errors/unauthorized.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:unauthorized, scope: 'spree.api') }diff --git a/api/app/views/spree/api/v1/addresses/show.rabl b/api/app/views/spree/api/v1/addresses/show.rabldeleted file mode 100644index 2d771704bf..0000000000--- a/api/app/views/spree/api/v1/addresses/show.rabl+++ /dev/null@@ -1,10 +0,0 @@-object @address-cache [I18n.locale, root_object]-attributes *address_attributes--child(:country) do |_address|- attributes *country_attributes-end-child(:state) do |_address|- attributes *state_attributes-enddiff --git a/api/app/views/spree/api/v1/adjustments/show.rabl b/api/app/views/spree/api/v1/adjustments/show.rabldeleted file mode 100644index e88c3d801d..0000000000--- a/api/app/views/spree/api/v1/adjustments/show.rabl+++ /dev/null@@ -1,4 +0,0 @@-object @adjustment-cache [I18n.locale, root_object]-attributes *adjustment_attributes-node(:display_amount) { |a| a.display_amount.to_s }diff --git a/api/app/views/spree/api/v1/countries/index.rabl b/api/app/views/spree/api/v1/countries/index.rabldeleted file mode 100644index d153ae1ed0..0000000000--- a/api/app/views/spree/api/v1/countries/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@countries => :countries) do- attributes *country_attributes-end-node(:count) { @countries.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @countries.total_pages }diff --git a/api/app/views/spree/api/v1/countries/show.rabl b/api/app/views/spree/api/v1/countries/show.rabldeleted file mode 100644index b485c3c11f..0000000000--- a/api/app/views/spree/api/v1/countries/show.rabl+++ /dev/null@@ -1,5 +0,0 @@-object @country-attributes *country_attributes-child states: :states do- attributes :id, :name, :abbr, :country_id-enddiff --git a/api/app/views/spree/api/v1/credit_cards/index.rabl b/api/app/views/spree/api/v1/credit_cards/index.rabldeleted file mode 100644index 1eb0e53cf2..0000000000--- a/api/app/views/spree/api/v1/credit_cards/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@credit_cards => :credit_cards) do- extends 'spree/api/v1/credit_cards/show'-end-node(:count) { @credit_cards.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @credit_cards.total_pages }diff --git a/api/app/views/spree/api/v1/credit_cards/show.rabl b/api/app/views/spree/api/v1/credit_cards/show.rabldeleted file mode 100644index 57d734d6ab..0000000000--- a/api/app/views/spree/api/v1/credit_cards/show.rabl+++ /dev/null@@ -1,3 +0,0 @@-object @credit_card-cache [I18n.locale, root_object]-attributes *creditcard_attributesdiff --git a/api/app/views/spree/api/v1/customer_returns/index.rabl b/api/app/views/spree/api/v1/customer_returns/index.rabldeleted file mode 100644index d9b0985371..0000000000--- a/api/app/views/spree/api/v1/customer_returns/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@collection => :customer_returns) do- attributes *customer_return_attributes-end-node(:count) { @collection.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @collection.total_pages }diff --git a/api/app/views/spree/api/v1/images/index.rabl b/api/app/views/spree/api/v1/images/index.rabldeleted file mode 100644index 60bec60528..0000000000--- a/api/app/views/spree/api/v1/images/index.rabl+++ /dev/null@@ -1,4 +0,0 @@-object false-child(@images => :images) do- extends 'spree/api/v1/images/show'-enddiff --git a/api/app/views/spree/api/v1/images/new.rabl b/api/app/views/spree/api/v1/images/new.rabldeleted file mode 100644index 102585c15a..0000000000--- a/api/app/views/spree/api/v1/images/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*image_attributes] }-node(:required_attributes) { required_fields_for(Spree::Image) }diff --git a/api/app/views/spree/api/v1/images/show.rabl b/api/app/views/spree/api/v1/images/show.rabldeleted file mode 100644index d8eb5e3e90..0000000000--- a/api/app/views/spree/api/v1/images/show.rabl+++ /dev/null@@ -1,6 +0,0 @@-object @image-attributes *image_attributes-attributes :viewable_type, :viewable_id-Spree::Image.styles.each do |k, _v|- node("#{k}_url") { |i| main_app.url_for(i.url(k)) }-enddiff --git a/api/app/views/spree/api/v1/inventory_units/show.rabl b/api/app/views/spree/api/v1/inventory_units/show.rabldeleted file mode 100644index d9e7960b50..0000000000--- a/api/app/views/spree/api/v1/inventory_units/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @inventory_unit-attributes *inventory_unit_attributesdiff --git a/api/app/views/spree/api/v1/line_items/new.rabl b/api/app/views/spree/api/v1/line_items/new.rabldeleted file mode 100644index 6269ff819e..0000000000--- a/api/app/views/spree/api/v1/line_items/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*line_item_attributes] - [:id] }-node(:required_attributes) { [:variant_id, :quantity] }diff --git a/api/app/views/spree/api/v1/line_items/show.rabl b/api/app/views/spree/api/v1/line_items/show.rabldeleted file mode 100644index 1de39cb4b0..0000000000--- a/api/app/views/spree/api/v1/line_items/show.rabl+++ /dev/null@@ -1,14 +0,0 @@-object @line_item-cache [I18n.locale, root_object]-attributes *line_item_attributes-node(:single_display_amount) { |li| li.single_display_amount.to_s }-node(:display_amount) { |li| li.display_amount.to_s }-node(:total, &:total)-child :variant do- extends 'spree/api/v1/variants/small'- attributes :product_id-end--child adjustments: :adjustments do- extends 'spree/api/v1/adjustments/show'-enddiff --git a/api/app/views/spree/api/v1/option_types/index.rabl b/api/app/views/spree/api/v1/option_types/index.rabldeleted file mode 100644index 3f1f70659b..0000000000--- a/api/app/views/spree/api/v1/option_types/index.rabl+++ /dev/null@@ -1,3 +0,0 @@-collection @option_types--extends 'spree/api/v1/option_types/show'diff --git a/api/app/views/spree/api/v1/option_types/new.rabl b/api/app/views/spree/api/v1/option_types/new.rabldeleted file mode 100644index 74a74b7dfb..0000000000--- a/api/app/views/spree/api/v1/option_types/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*option_type_attributes] }-node(:required_attributes) { required_fields_for(Spree::OptionType) }diff --git a/api/app/views/spree/api/v1/option_types/show.rabl b/api/app/views/spree/api/v1/option_types/show.rabldeleted file mode 100644index 8e8d0b3366..0000000000--- a/api/app/views/spree/api/v1/option_types/show.rabl+++ /dev/null@@ -1,5 +0,0 @@-object @option_type-attributes *option_type_attributes-child option_values: :option_values do- attributes *option_value_attributes-enddiff --git a/api/app/views/spree/api/v1/option_values/index.rabl b/api/app/views/spree/api/v1/option_values/index.rabldeleted file mode 100644index d3592c98cd..0000000000--- a/api/app/views/spree/api/v1/option_values/index.rabl+++ /dev/null@@ -1,3 +0,0 @@-collection @option_values--extends 'spree/api/v1/option_values/show'diff --git a/api/app/views/spree/api/v1/option_values/new.rabl b/api/app/views/spree/api/v1/option_values/new.rabldeleted file mode 100644index 662f9de448..0000000000--- a/api/app/views/spree/api/v1/option_values/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*option_value_attributes] }-node(:required_attributes) { required_fields_for(Spree::OptionValue) }diff --git a/api/app/views/spree/api/v1/option_values/show.rabl b/api/app/views/spree/api/v1/option_values/show.rabldeleted file mode 100644index a3f6680d2e..0000000000--- a/api/app/views/spree/api/v1/option_values/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @option_value-attributes *option_value_attributesdiff --git a/api/app/views/spree/api/v1/orders/address.rabl b/api/app/views/spree/api/v1/orders/address.rabldeleted file mode 100644index e69de29bb2..0000000000diff --git a/api/app/views/spree/api/v1/orders/canceled.rabl b/api/app/views/spree/api/v1/orders/canceled.rabldeleted file mode 100644index e69de29bb2..0000000000diff --git a/api/app/views/spree/api/v1/orders/cart.rabl b/api/app/views/spree/api/v1/orders/cart.rabldeleted file mode 100644index e69de29bb2..0000000000diff --git a/api/app/views/spree/api/v1/orders/complete.rabl b/api/app/views/spree/api/v1/orders/complete.rabldeleted file mode 100644index e69de29bb2..0000000000diff --git a/api/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl b/api/app/views/spree/api/v1/orders/could_not_apply_coupon.rabldeleted file mode 100644index 0a45713063..0000000000--- a/api/app/views/spree/api/v1/orders/could_not_apply_coupon.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { @coupon_message }diff --git a/api/app/views/spree/api/v1/orders/could_not_transition.rabl b/api/app/views/spree/api/v1/orders/could_not_transition.rabldeleted file mode 100644index c2bfb5c84a..0000000000--- a/api/app/views/spree/api/v1/orders/could_not_transition.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:error) { I18n.t(:could_not_transition, scope: 'spree.api.order') }-node(:errors) { @order.errors.to_hash }diff --git a/api/app/views/spree/api/v1/orders/index.rabl b/api/app/views/spree/api/v1/orders/index.rabldeleted file mode 100644index 27acb95f30..0000000000--- a/api/app/views/spree/api/v1/orders/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@orders => :orders) do- extends 'spree/api/v1/orders/order'-end-node(:count) { @orders.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @orders.total_pages }diff --git a/api/app/views/spree/api/v1/orders/insufficient_quantity.rabl b/api/app/views/spree/api/v1/orders/insufficient_quantity.rabldeleted file mode 100644index 2cd37ffdf0..0000000000--- a/api/app/views/spree/api/v1/orders/insufficient_quantity.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { Spree.t(:insufficient_quantity, scope: [:api, :order]) }diff --git a/api/app/views/spree/api/v1/orders/invalid_shipping_method.rabl b/api/app/views/spree/api/v1/orders/invalid_shipping_method.rabldeleted file mode 100644index 9876194d71..0000000000--- a/api/app/views/spree/api/v1/orders/invalid_shipping_method.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:errors) { [I18n.t(:invalid_shipping_method, scope: 'spree.api.order')] }diff --git a/api/app/views/spree/api/v1/orders/mine.rabl b/api/app/views/spree/api/v1/orders/mine.rabldeleted file mode 100644index ce5284216b..0000000000--- a/api/app/views/spree/api/v1/orders/mine.rabl+++ /dev/null@@ -1,9 +0,0 @@-object false--child(@orders => :orders) do- extends 'spree/api/v1/orders/show'-end--node(:count) { @orders.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @orders.total_pages }diff --git a/api/app/views/spree/api/v1/orders/order.rabl b/api/app/views/spree/api/v1/orders/order.rabldeleted file mode 100644index fda367071c..0000000000--- a/api/app/views/spree/api/v1/orders/order.rabl+++ /dev/null@@ -1,10 +0,0 @@-cache [I18n.locale, root_object]-attributes *order_attributes-node(:display_item_total) { |o| o.display_item_total.to_s }-node(:total_quantity) { |o| o.line_items.sum(:quantity) }-node(:display_total) { |o| o.display_total.to_s }-node(:display_ship_total, &:display_ship_total)-node(:display_tax_total, &:display_tax_total)-node(:display_adjustment_total, &:display_adjustment_total)-node(:token, &:token)-node(:checkout_steps, &:checkout_steps)diff --git a/api/app/views/spree/api/v1/orders/payment.rabl b/api/app/views/spree/api/v1/orders/payment.rabldeleted file mode 100644index 0533ca838a..0000000000--- a/api/app/views/spree/api/v1/orders/payment.rabl+++ /dev/null@@ -1,3 +0,0 @@-child available_payment_methods: :payment_methods do- attributes :id, :name, :method_type-enddiff --git a/api/app/views/spree/api/v1/orders/show.rabl b/api/app/views/spree/api/v1/orders/show.rabldeleted file mode 100644index 6ae5a97b3b..0000000000--- a/api/app/views/spree/api/v1/orders/show.rabl+++ /dev/null@@ -1,51 +0,0 @@-object @order-extends 'spree/api/v1/orders/order'--if lookup_context.find_all("spree/api/v1/orders/#{root_object.state}").present?- extends "spree/api/v1/orders/#{root_object.state}"-end--child billing_address: :bill_address do- extends 'spree/api/v1/addresses/show'-end--child shipping_address: :ship_address do- extends 'spree/api/v1/addresses/show'-end--child line_items: :line_items do- extends 'spree/api/v1/line_items/show'-end--child payments: :payments do- attributes *payment_attributes-- child payment_method: :payment_method do- attributes :id, :name- end-- child source: :source do- if @current_user_roles.include?('admin')- attributes *payment_source_attributes + [:gateway_customer_profile_id, :gateway_payment_profile_id]- else- attributes *payment_source_attributes- end- end-end--child shipments: :shipments do- extends 'spree/api/v1/shipments/small'-end--child adjustments: :adjustments do- extends 'spree/api/v1/adjustments/show'-end--# Necessary for backend's order interface-node :permissions do- { can_update: current_ability.can?(:update, root_object) }-end--child valid_credit_cards: :credit_cards do- extends 'spree/api/v1/credit_cards/show'-enddiff --git a/api/app/views/spree/api/v1/payments/credit_over_limit.rabl b/api/app/views/spree/api/v1/payments/credit_over_limit.rabldeleted file mode 100644index e6ca9336fa..0000000000--- a/api/app/views/spree/api/v1/payments/credit_over_limit.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:credit_over_limit, limit: @payment.credit_allowed, scope: 'spree.api.payment') }diff --git a/api/app/views/spree/api/v1/payments/index.rabl b/api/app/views/spree/api/v1/payments/index.rabldeleted file mode 100644index b816d9e47f..0000000000--- a/api/app/views/spree/api/v1/payments/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@payments => :payments) do- attributes *payment_attributes-end-node(:count) { @payments.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @payments.total_pages }diff --git a/api/app/views/spree/api/v1/payments/new.rabl b/api/app/views/spree/api/v1/payments/new.rabldeleted file mode 100644index 05d227cf83..0000000000--- a/api/app/views/spree/api/v1/payments/new.rabl+++ /dev/null@@ -1,5 +0,0 @@-object false-node(:attributes) { [*payment_attributes] }-child @payment_methods => :payment_methods do- attributes *payment_method_attributes-enddiff --git a/api/app/views/spree/api/v1/payments/show.rabl b/api/app/views/spree/api/v1/payments/show.rabldeleted file mode 100644index e2f48cb940..0000000000--- a/api/app/views/spree/api/v1/payments/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @payment-attributes *payment_attributesdiff --git a/api/app/views/spree/api/v1/payments/update_forbidden.rabl b/api/app/views/spree/api/v1/payments/update_forbidden.rabldeleted file mode 100644index 9ce6b061fc..0000000000--- a/api/app/views/spree/api/v1/payments/update_forbidden.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:update_forbidden, state: @payment.state, scope: 'spree.api.payment') }diff --git a/api/app/views/spree/api/v1/product_properties/index.rabl b/api/app/views/spree/api/v1/product_properties/index.rabldeleted file mode 100644index 2a04d57282..0000000000--- a/api/app/views/spree/api/v1/product_properties/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@product_properties => :product_properties) do- attributes *product_property_attributes-end-node(:count) { @product_properties.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @product_properties.total_pages }diff --git a/api/app/views/spree/api/v1/product_properties/new.rabl b/api/app/views/spree/api/v1/product_properties/new.rabldeleted file mode 100644index 3706711981..0000000000--- a/api/app/views/spree/api/v1/product_properties/new.rabl+++ /dev/null@@ -1,2 +0,0 @@-node(:attributes) { [*product_property_attributes] }-node(:required_attributes) { [] }diff --git a/api/app/views/spree/api/v1/product_properties/show.rabl b/api/app/views/spree/api/v1/product_properties/show.rabldeleted file mode 100644index 12e24137b5..0000000000--- a/api/app/views/spree/api/v1/product_properties/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @product_property-attributes *product_property_attributesdiff --git a/api/app/views/spree/api/v1/products/index.rabl b/api/app/views/spree/api/v1/products/index.rabldeleted file mode 100644index faca145d23..0000000000--- a/api/app/views/spree/api/v1/products/index.rabl+++ /dev/null@@ -1,9 +0,0 @@-object false-node(:count) { @products.count }-node(:total_count) { @products.total_count }-node(:current_page) { params[:page] ? params[:page].to_i : 1 }-node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }-node(:pages) { @products.total_pages }-child(@products => :products) do- extends 'spree/api/v1/products/show'-enddiff --git a/api/app/views/spree/api/v1/products/new.rabl b/api/app/views/spree/api/v1/products/new.rabldeleted file mode 100644index 71861f9183..0000000000--- a/api/app/views/spree/api/v1/products/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*product_attributes] }-node(:required_attributes) { required_fields_for(Spree::Product) }diff --git a/api/app/views/spree/api/v1/products/product.rabl b/api/app/views/spree/api/v1/products/product.rabldeleted file mode 100644index ba18e3f709..0000000000--- a/api/app/views/spree/api/v1/products/product.rabl+++ /dev/null@@ -1 +0,0 @@-attributes *product_attributesdiff --git a/api/app/views/spree/api/v1/products/show.rabl b/api/app/views/spree/api/v1/products/show.rabldeleted file mode 100644index fcb67c388b..0000000000--- a/api/app/views/spree/api/v1/products/show.rabl+++ /dev/null@@ -1,36 +0,0 @@-object @product-cache [I18n.locale, @current_user_roles.include?('admin'), current_currency, root_object]--attributes *product_attributes--node(:display_price) { |p| p.display_price.to_s }-node(:has_variants, &:has_variants?)-node(:taxon_ids, &:taxon_ids)-node(:display_current_currency_price) do |product|- price = product.price_in(current_currency)- Spree::Money.new(price.amount, currency: current_currency).to_s-end--child master: :master do- extends 'spree/api/v1/variants/small'-end--child variants: :variants do- extends 'spree/api/v1/variants/small'-end--child option_types: :option_types do- attributes *option_type_attributes-end--child product_properties: :product_properties do- attributes *product_property_attributes-end--child classifications: :classifications do- attributes :taxon_id, :position-- child(:taxon) do- extends 'spree/api/v1/taxons/show'- end-enddiff --git a/api/app/views/spree/api/v1/promotions/handler.rabl b/api/app/views/spree/api/v1/promotions/handler.rabldeleted file mode 100644index e08a89b08e..0000000000--- a/api/app/views/spree/api/v1/promotions/handler.rabl+++ /dev/null@@ -1,5 +0,0 @@-object false-node(:success) { @handler.success }-node(:error) { @handler.error }-node(:successful) { @handler.successful? }-node(:status_code) { @handler.status_code }diff --git a/api/app/views/spree/api/v1/promotions/show.rabl b/api/app/views/spree/api/v1/promotions/show.rabldeleted file mode 100644index 90a577d22a..0000000000--- a/api/app/views/spree/api/v1/promotions/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @promotion-attributes *promotion_attributesdiff --git a/api/app/views/spree/api/v1/properties/index.rabl b/api/app/views/spree/api/v1/properties/index.rabldeleted file mode 100644index 7a8ca7223c..0000000000--- a/api/app/views/spree/api/v1/properties/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@properties => :properties) do- attributes *property_attributes-end-node(:count) { @properties.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @properties.total_pages }diff --git a/api/app/views/spree/api/v1/properties/new.rabl b/api/app/views/spree/api/v1/properties/new.rabldeleted file mode 100644index 76f03444e8..0000000000--- a/api/app/views/spree/api/v1/properties/new.rabl+++ /dev/null@@ -1,2 +0,0 @@-node(:attributes) { [*property_attributes] }-node(:required_attributes) { [] }diff --git a/api/app/views/spree/api/v1/properties/show.rabl b/api/app/views/spree/api/v1/properties/show.rabldeleted file mode 100644index 08cfbe5e9b..0000000000--- a/api/app/views/spree/api/v1/properties/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @property-attributes *property_attributesdiff --git a/api/app/views/spree/api/v1/reimbursements/index.rabl b/api/app/views/spree/api/v1/reimbursements/index.rabldeleted file mode 100644index b3d47cf050..0000000000--- a/api/app/views/spree/api/v1/reimbursements/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@collection => :reimbursements) do- attributes *reimbursement_attributes-end-node(:count) { @collection.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @collection.total_pages }diff --git a/api/app/views/spree/api/v1/return_authorizations/index.rabl b/api/app/views/spree/api/v1/return_authorizations/index.rabldeleted file mode 100644index 1410d4de9d..0000000000--- a/api/app/views/spree/api/v1/return_authorizations/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@return_authorizations => :return_authorizations) do- attributes *return_authorization_attributes-end-node(:count) { @return_authorizations.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @return_authorizations.total_pages }diff --git a/api/app/views/spree/api/v1/return_authorizations/new.rabl b/api/app/views/spree/api/v1/return_authorizations/new.rabldeleted file mode 100644index 362fa8ac9d..0000000000--- a/api/app/views/spree/api/v1/return_authorizations/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*return_authorization_attributes] }-node(:required_attributes) { required_fields_for(Spree::ReturnAuthorization) }diff --git a/api/app/views/spree/api/v1/return_authorizations/show.rabl b/api/app/views/spree/api/v1/return_authorizations/show.rabldeleted file mode 100644index 72bfb85911..0000000000--- a/api/app/views/spree/api/v1/return_authorizations/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @return_authorization-attributes *return_authorization_attributesdiff --git a/api/app/views/spree/api/v1/shared/stock_location_required.rabl b/api/app/views/spree/api/v1/shared/stock_location_required.rabldeleted file mode 100644index 330bee5df9..0000000000--- a/api/app/views/spree/api/v1/shared/stock_location_required.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:stock_location_required, scope: 'spree.api') }diff --git a/api/app/views/spree/api/v1/shipments/big.rabl b/api/app/views/spree/api/v1/shipments/big.rabldeleted file mode 100644index 7776810a7c..0000000000--- a/api/app/views/spree/api/v1/shipments/big.rabl+++ /dev/null@@ -1,48 +0,0 @@-object @shipment-cache @shipment-attributes *shipment_attributes--child selected_shipping_rate: :selected_shipping_rate do- extends 'spree/api/v1/shipping_rates/show'-end--child inventory_units: :inventory_units do- object @inventory_unit- attributes *inventory_unit_attributes-- child :variant do- extends 'spree/api/v1/variants/small'- attributes :product_id- child(images: :images) { extends 'spree/api/v1/images/show' }- end-- child :line_item do- attributes *line_item_attributes- node(:single_display_amount) { |li| li.single_display_amount.to_s }- node(:display_amount) { |li| li.display_amount.to_s }- node(:total, &:total)- end-end--child order: :order do- extends 'spree/api/v1/orders/order'-- child billing_address: :bill_address do- extends 'spree/api/v1/addresses/show'- end-- child shipping_address: :ship_address do- extends 'spree/api/v1/addresses/show'- end-- child adjustments: :adjustments do- extends 'spree/api/v1/adjustments/show'- end-- child payments: :payments do- attributes :id, :amount, :display_amount, :state- child payment_method: :payment_method do- attributes :id, :name- end- end-enddiff --git a/api/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl b/api/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabldeleted file mode 100644index 8481b710c8..0000000000--- a/api/app/views/spree/api/v1/shipments/cannot_ready_shipment.rabl+++ /dev/null@@ -1,2 +0,0 @@-object false-node(:error) { I18n.t(:cannot_ready, scope: 'spree.api.shipment') }diff --git a/api/app/views/spree/api/v1/shipments/mine.rabl b/api/app/views/spree/api/v1/shipments/mine.rabldeleted file mode 100644index 8a4b5e83b7..0000000000--- a/api/app/views/spree/api/v1/shipments/mine.rabl+++ /dev/null@@ -1,9 +0,0 @@-object false--node(:count) { @shipments.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @shipments.total_pages }--child(@shipments => :shipments) do- extends 'spree/api/v1/shipments/big'-enddiff --git a/api/app/views/spree/api/v1/shipments/show.rabl b/api/app/views/spree/api/v1/shipments/show.rabldeleted file mode 100644index f9b069fc88..0000000000--- a/api/app/views/spree/api/v1/shipments/show.rabl+++ /dev/null@@ -1,32 +0,0 @@-object @shipment-cache [I18n.locale, root_object]-attributes *shipment_attributes-node(:order_id) { |shipment| shipment.order.number }-node(:stock_location_name) { |shipment| shipment.stock_location.name }--child shipping_rates: :shipping_rates do- extends 'spree/api/v1/shipping_rates/show'-end--child selected_shipping_rate: :selected_shipping_rate do- extends 'spree/api/v1/shipping_rates/show'-end--child shipping_methods: :shipping_methods do- attributes :id, :name, :tracking_url- child zones: :zones do- attributes :id, :name, :description- end-- child shipping_categories: :shipping_categories do- attributes :id, :name- end-end--child manifest: :manifest do- child variant: :variant do- extends 'spree/api/v1/variants/small'- end- node(:quantity, &:quantity)- node(:states, &:states)-enddiff --git a/api/app/views/spree/api/v1/shipments/small.rabl b/api/app/views/spree/api/v1/shipments/small.rabldeleted file mode 100644index f826dd6de9..0000000000--- a/api/app/views/spree/api/v1/shipments/small.rabl+++ /dev/null@@ -1,37 +0,0 @@-object @shipment-cache [I18n.locale, 'small_shipment', root_object]--attributes *shipment_attributes-node(:order_id) { |shipment| shipment.order.number }-node(:stock_location_name) { |shipment| shipment.stock_location.name }--child shipping_rates: :shipping_rates do- extends 'spree/api/v1/shipping_rates/show'-end--child selected_shipping_rate: :selected_shipping_rate do- extends 'spree/api/v1/shipping_rates/show'-end--child shipping_methods: :shipping_methods do- attributes :id, :code, :name- child zones: :zones do- attributes :id, :name, :description- end-- child shipping_categories: :shipping_categories do- attributes :id, :name- end-end--child manifest: :manifest do- glue(:variant) do- attribute id: :variant_id- end- node(:quantity, &:quantity)- node(:states, &:states)-end--child adjustments: :adjustments do- extends 'spree/api/v1/adjustments/show'-enddiff --git a/api/app/views/spree/api/v1/shipping_rates/show.rabl b/api/app/views/spree/api/v1/shipping_rates/show.rabldeleted file mode 100644index 6b06d3102d..0000000000--- a/api/app/views/spree/api/v1/shipping_rates/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-attributes :id, :name, :cost, :selected, :shipping_method_id, :shipping_method_code-node(:display_cost) { |sr| sr.display_cost.to_s }diff --git a/api/app/views/spree/api/v1/states/index.rabl b/api/app/views/spree/api/v1/states/index.rabldeleted file mode 100644index 5ffad7024d..0000000000--- a/api/app/views/spree/api/v1/states/index.rabl+++ /dev/null@@ -1,12 +0,0 @@-object false-node(:states_required) { @country.states_required } if @country--child(@states => :states) do- attributes *state_attributes-end--if @states.respond_to?(:total_pages)- node(:count) { @states.count }- node(:current_page) { params[:page].try(:to_i) || 1 }- node(:pages) { @states.total_pages }-enddiff --git a/api/app/views/spree/api/v1/states/show.rabl b/api/app/views/spree/api/v1/states/show.rabldeleted file mode 100644index 3b7533d511..0000000000--- a/api/app/views/spree/api/v1/states/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @state-attributes *state_attributesdiff --git a/api/app/views/spree/api/v1/stock_items/index.rabl b/api/app/views/spree/api/v1/stock_items/index.rabldeleted file mode 100644index 350cb1e609..0000000000--- a/api/app/views/spree/api/v1/stock_items/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@stock_items => :stock_items) do- extends 'spree/api/v1/stock_items/show'-end-node(:count) { @stock_items.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @stock_items.total_pages }diff --git a/api/app/views/spree/api/v1/stock_items/show.rabl b/api/app/views/spree/api/v1/stock_items/show.rabldeleted file mode 100644index 1047974e9c..0000000000--- a/api/app/views/spree/api/v1/stock_items/show.rabl+++ /dev/null@@ -1,5 +0,0 @@-object @stock_item-attributes *stock_item_attributes-child(:variant) do- extends 'spree/api/v1/variants/small'-enddiff --git a/api/app/views/spree/api/v1/stock_locations/index.rabl b/api/app/views/spree/api/v1/stock_locations/index.rabldeleted file mode 100644index bbd6cd0461..0000000000--- a/api/app/views/spree/api/v1/stock_locations/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@stock_locations => :stock_locations) do- extends 'spree/api/v1/stock_locations/show'-end-node(:count) { @stock_locations.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @stock_locations.total_pages }diff --git a/api/app/views/spree/api/v1/stock_locations/show.rabl b/api/app/views/spree/api/v1/stock_locations/show.rabldeleted file mode 100644index f5c74e3b96..0000000000--- a/api/app/views/spree/api/v1/stock_locations/show.rabl+++ /dev/null@@ -1,8 +0,0 @@-object @stock_location-attributes *stock_location_attributes-child(:country) do |_address|- attributes *country_attributes-end-child(:state) do |_address|- attributes *state_attributes-enddiff --git a/api/app/views/spree/api/v1/stock_movements/index.rabl b/api/app/views/spree/api/v1/stock_movements/index.rabldeleted file mode 100644index 6e098424c4..0000000000--- a/api/app/views/spree/api/v1/stock_movements/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@stock_movements => :stock_movements) do- extends 'spree/api/v1/stock_movements/show'-end-node(:count) { @stock_movements.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @stock_movements.total_pages }diff --git a/api/app/views/spree/api/v1/stock_movements/show.rabl b/api/app/views/spree/api/v1/stock_movements/show.rabldeleted file mode 100644index 8c24b4bae2..0000000000--- a/api/app/views/spree/api/v1/stock_movements/show.rabl+++ /dev/null@@ -1,5 +0,0 @@-object @stock_movement-attributes *stock_movement_attributes-child :stock_item do- extends 'spree/api/v1/stock_items/show'-enddiff --git a/api/app/views/spree/api/v1/stores/index.rabl b/api/app/views/spree/api/v1/stores/index.rabldeleted file mode 100644index ae547356bb..0000000000--- a/api/app/views/spree/api/v1/stores/index.rabl+++ /dev/null@@ -1,4 +0,0 @@-object false-child(@stores => :stores) do- attributes *store_attributes-enddiff --git a/api/app/views/spree/api/v1/stores/show.rabl b/api/app/views/spree/api/v1/stores/show.rabldeleted file mode 100644index a0e1941b72..0000000000--- a/api/app/views/spree/api/v1/stores/show.rabl+++ /dev/null@@ -1,2 +0,0 @@-object @store-attributes *store_attributesdiff --git a/api/app/views/spree/api/v1/tags/index.rabl b/api/app/views/spree/api/v1/tags/index.rabldeleted file mode 100644index 339df7ea38..0000000000--- a/api/app/views/spree/api/v1/tags/index.rabl+++ /dev/null@@ -1,9 +0,0 @@-object false-node(:count) { @tags.count }-node(:total_count) { @tags.total_count }-node(:current_page) { params[:page] ? params[:page].to_i : 1 }-node(:per_page) { params[:per_page] || Kaminari.config.default_per_page }-node(:pages) { @tags.total_pages }-child(@tags => :tags) do- attributes :name, :id-enddiff --git a/api/app/views/spree/api/v1/taxonomies/index.rabl b/api/app/views/spree/api/v1/taxonomies/index.rabldeleted file mode 100644index 0febb17df5..0000000000--- a/api/app/views/spree/api/v1/taxonomies/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@taxonomies => :taxonomies) do- extends 'spree/api/v1/taxonomies/show'-end-node(:count) { @taxonomies.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @taxonomies.total_pages }diff --git a/api/app/views/spree/api/v1/taxonomies/jstree.rabl b/api/app/views/spree/api/v1/taxonomies/jstree.rabldeleted file mode 100644index 727debf2dc..0000000000--- a/api/app/views/spree/api/v1/taxonomies/jstree.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-node(:data) { @taxonomy.root.name }-node(:attr) do- { id: @taxonomy.root.id,- name: @taxonomy.root.name }-end-node(:state) { 'closed' }diff --git a/api/app/views/spree/api/v1/taxonomies/nested.rabl b/api/app/views/spree/api/v1/taxonomies/nested.rabldeleted file mode 100644index 1314df5974..0000000000--- a/api/app/views/spree/api/v1/taxonomies/nested.rabl+++ /dev/null@@ -1,11 +0,0 @@-attributes *taxonomy_attributes--child root: :root do- attributes *taxon_attributes-- child children: :taxons do- attributes *taxon_attributes-- extends 'spree/api/v1/taxons/taxons'- end-enddiff --git a/api/app/views/spree/api/v1/taxonomies/new.rabl b/api/app/views/spree/api/v1/taxonomies/new.rabldeleted file mode 100644index a3dd32d4ef..0000000000--- a/api/app/views/spree/api/v1/taxonomies/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*taxonomy_attributes] }-node(:required_attributes) { required_fields_for(Spree::Taxonomy) }diff --git a/api/app/views/spree/api/v1/taxonomies/show.rabl b/api/app/views/spree/api/v1/taxonomies/show.rabldeleted file mode 100644index a99bddcfdd..0000000000--- a/api/app/views/spree/api/v1/taxonomies/show.rabl+++ /dev/null@@ -1,15 +0,0 @@-object @taxonomy--if params[:set] == 'nested'- extends 'spree/api/v1/taxonomies/nested'-else- attributes *taxonomy_attributes-- child root: :root do- attributes *taxon_attributes-- child children: :taxons do- attributes *taxon_attributes- end- end-enddiff --git a/api/app/views/spree/api/v1/taxons/index.rabl b/api/app/views/spree/api/v1/taxons/index.rabldeleted file mode 100644index 6256e952b1..0000000000--- a/api/app/views/spree/api/v1/taxons/index.rabl+++ /dev/null@@ -1,10 +0,0 @@-object false-node(:count) { @taxons.count }-node(:total_count) { @taxons.total_count }-node(:current_page) { params[:page] ? params[:page].to_i : 1 }-node(:per_page) { params[:per_page].try(:to_i) || Kaminari.config.default_per_page }-node(:pages) { @taxons.total_pages }-child @taxons => :taxons do- attributes *taxon_attributes- extends 'spree/api/v1/taxons/taxons' unless params[:without_children]-enddiff --git a/api/app/views/spree/api/v1/taxons/jstree.rabl b/api/app/views/spree/api/v1/taxons/jstree.rabldeleted file mode 100644index fdfdaae5f5..0000000000--- a/api/app/views/spree/api/v1/taxons/jstree.rabl+++ /dev/null@@ -1,7 +0,0 @@-collection @taxon.children, object_root: false-node(:data, &:name)-node(:attr) do |taxon|- { id: taxon.id,- name: taxon.name }-end-node(:state) { 'closed' }diff --git a/api/app/views/spree/api/v1/taxons/new.rabl b/api/app/views/spree/api/v1/taxons/new.rabldeleted file mode 100644index f85dbece9e..0000000000--- a/api/app/views/spree/api/v1/taxons/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*taxon_attributes] }-node(:required_attributes) { required_fields_for(Spree::Taxon) }diff --git a/api/app/views/spree/api/v1/taxons/show.rabl b/api/app/views/spree/api/v1/taxons/show.rabldeleted file mode 100644index 95f485715f..0000000000--- a/api/app/views/spree/api/v1/taxons/show.rabl+++ /dev/null@@ -1,6 +0,0 @@-object @taxon-attributes *taxon_attributes--child children: :taxons do- attributes *taxon_attributes-enddiff --git a/api/app/views/spree/api/v1/taxons/taxons.rabl b/api/app/views/spree/api/v1/taxons/taxons.rabldeleted file mode 100644index 3470decfc1..0000000000--- a/api/app/views/spree/api/v1/taxons/taxons.rabl+++ /dev/null@@ -1,5 +0,0 @@-attributes *taxon_attributes--node :taxons do |t|- t.children.map { |c| partial('spree/api/v1/taxons/taxons', object: c) }-enddiff --git a/api/app/views/spree/api/v1/users/index.rabl b/api/app/views/spree/api/v1/users/index.rabldeleted file mode 100644index f481400797..0000000000--- a/api/app/views/spree/api/v1/users/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@users => :users) do- extends 'spree/api/v1/users/show'-end-node(:count) { @users.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @users.total_pages }diff --git a/api/app/views/spree/api/v1/users/new.rabl b/api/app/views/spree/api/v1/users/new.rabldeleted file mode 100644index f3e36dd7d3..0000000000--- a/api/app/views/spree/api/v1/users/new.rabl+++ /dev/null@@ -1,3 +0,0 @@-object false-node(:attributes) { [*user_attributes] }-node(:required_attributes) { required_fields_for(Spree.user_class) }diff --git a/api/app/views/spree/api/v1/users/show.rabl b/api/app/views/spree/api/v1/users/show.rabldeleted file mode 100644index b5f680a93a..0000000000--- a/api/app/views/spree/api/v1/users/show.rabl+++ /dev/null@@ -1,11 +0,0 @@-object @user-cache [I18n.locale, root_object]--attributes *user_attributes-child(bill_address: :bill_address) do- extends 'spree/api/v1/addresses/show'-end--child(ship_address: :ship_address) do- extends 'spree/api/v1/addresses/show'-enddiff --git a/api/app/views/spree/api/v1/variants/big.rabl b/api/app/views/spree/api/v1/variants/big.rabldeleted file mode 100644index 718422228c..0000000000--- a/api/app/views/spree/api/v1/variants/big.rabl+++ /dev/null@@ -1,14 +0,0 @@-object @variant--cache [I18n.locale, @current_user_roles.include?('admin'), 'big_variant', root_object]--extends 'spree/api/v1/variants/small'--child(stock_items: :stock_items) do- attributes :id, :count_on_hand, :stock_location_id, :backorderable- attribute available?: :available-- glue(:stock_location) do- attribute name: :stock_location_name- end-enddiff --git a/api/app/views/spree/api/v1/variants/index.rabl b/api/app/views/spree/api/v1/variants/index.rabldeleted file mode 100644index 3b941ebb29..0000000000--- a/api/app/views/spree/api/v1/variants/index.rabl+++ /dev/null@@ -1,9 +0,0 @@-object false-node(:count) { @variants.count }-node(:total_count) { @variants.total_count }-node(:current_page) { params[:page] ? params[:page].to_i : 1 }-node(:pages) { @variants.total_pages }--child(@variants => :variants) do- extends 'spree/api/v1/variants/big'-enddiff --git a/api/app/views/spree/api/v1/variants/new.rabl b/api/app/views/spree/api/v1/variants/new.rabldeleted file mode 100644index 26cf41db3b..0000000000--- a/api/app/views/spree/api/v1/variants/new.rabl+++ /dev/null@@ -1,2 +0,0 @@-node(:attributes) { [*variant_attributes] }-node(:required_attributes) { [] }diff --git a/api/app/views/spree/api/v1/variants/show.rabl b/api/app/views/spree/api/v1/variants/show.rabldeleted file mode 100644index 0d4d594217..0000000000--- a/api/app/views/spree/api/v1/variants/show.rabl+++ /dev/null@@ -1,3 +0,0 @@-object @variant-cache [I18n.locale, @current_user_roles.include?('admin'), 'show', root_object]-extends 'spree/api/v1/variants/big'diff --git a/api/app/views/spree/api/v1/variants/small.rabl b/api/app/views/spree/api/v1/variants/small.rabldeleted file mode 100644index ab80fc636f..0000000000--- a/api/app/views/spree/api/v1/variants/small.rabl+++ /dev/null@@ -1,18 +0,0 @@-cache [I18n.locale, @current_user_roles.include?('admin'), 'small_variant', root_object]--attributes *variant_attributes--node(:display_price) { |p| p.display_price.to_s }-node(:options_text, &:options_text)-node(:track_inventory, &:should_track_inventory?)-node(:in_stock, &:in_stock?)-node(:is_backorderable, &:is_backorderable?)-node(:is_orderable) { |v| v.is_backorderable? || v.in_stock? }-node(:total_on_hand, &:total_on_hand)-node(:is_destroyed, &:destroyed?)--child option_values: :option_values do- attributes *option_value_attributes-end--child(images: :images) { extends 'spree/api/v1/images/show' }diff --git a/api/app/views/spree/api/v1/zones/index.rabl b/api/app/views/spree/api/v1/zones/index.rabldeleted file mode 100644index 633f918137..0000000000--- a/api/app/views/spree/api/v1/zones/index.rabl+++ /dev/null@@ -1,7 +0,0 @@-object false-child(@zones => :zones) do- extends 'spree/api/v1/zones/show'-end-node(:count) { @zones.count }-node(:current_page) { params[:page].try(:to_i) || 1 }-node(:pages) { @zones.total_pages }diff --git a/api/app/views/spree/api/v1/zones/show.rabl b/api/app/views/spree/api/v1/zones/show.rabldeleted file mode 100644index eb66574ed4..0000000000--- a/api/app/views/spree/api/v1/zones/show.rabl+++ /dev/null@@ -1,6 +0,0 @@-object @zone-attributes :id, :name, :description--child zone_members: :zone_members do- attributes :id, :name, :zoneable_type, :zoneable_id-enddiff --git a/api/config/initializers/rabl.rb b/api/config/initializers/rabl.rbdeleted file mode 100644index 080dd4ffea..0000000000--- a/api/config/initializers/rabl.rb+++ /dev/null@@ -1,9 +0,0 @@-Rabl.configure do |config|- config.include_json_root = false- config.include_child_root = false-- # Motivation here it make it call as_json when rendering timestamps- # and therefore display milliseconds. Otherwise it would fall to- # JSON.dump which doesn't display the milliseconds- config.json_engine = ActiveSupport::JSON-enddiff --git a/api/config/routes.rb b/api/config/routes.rbindex 235c9a801b..d8f03e1bce 100644--- a/api/config/routes.rb+++ b/api/config/routes.rb@@ -6,126 +6,6 @@ endSpree::Core::Engine.add_routes donamespace :api, defaults: { format: 'json' } do- namespace :v1 do- resources :promotions, only: [:show]-- resources :customer_returns, only: [:index]- resources :reimbursements, only: [:index]-- resources :products do- resources :images- resources :variants- resources :product_properties- end-- concern :order_routes do- member do- put :approve- put :cancel- put :empty- put :apply_coupon_code- end-- resources :line_items- resources :payments do- member do- put :authorize- put :capture- put :purchase- put :void- put :credit- end- end-- resources :addresses, only: [:show, :update]-- resources :return_authorizations do- member do- put :add- put :cancel- put :receive- end- end- end-- resources :checkouts, only: [:update], concerns: :order_routes do- member do- put :next- put :advance- end- end-- resources :variants do- resources :images- end-- resources :option_types do- resources :option_values- end- resources :option_values-- resources :option_values, only: :index-- get '/orders/mine', to: 'orders#mine', as: 'my_orders'- get '/orders/current', to: 'orders#current', as: 'current_order'-- resources :orders, concerns: :order_routes do- put :remove_coupon_code, on: :member- end-- resources :zones- resources :countries, only: [:index, :show] do- resources :states, only: [:index, :show]- end-- resources :shipments, only: [:create, :update] do- collection do- post 'transfer_to_location'- post 'transfer_to_shipment'- get :mine- end-- member do- put :ready- put :ship- put :add- put :remove- end- end- resources :states, only: [:index, :show]-- resources :taxonomies do- member do- get :jstree- end- resources :taxons do- member do- get :jstree- end- end- end-- resources :taxons, only: [:index]-- resources :inventory_units, only: [:show, :update]-- resources :users do- resources :credit_cards, only: [:index]- end-- resources :properties- resources :stock_locations do- resources :stock_movements- resources :stock_items- end-- resources :stock_items, only: [:index, :update, :destroy]- resources :stores-- put '/classifications', to: 'classifications#update', as: :classifications- get '/taxons/products', to: 'taxons#products', as: :taxon_products- end-namespace :v2 donamespace :storefront doresource :cart, controller: :cart, only: %i[show create destroy] dodiff --git a/api/lib/spree/api.rb b/api/lib/spree/api.rbindex 889152191d..d91f4cfbe0 100644--- a/api/lib/spree/api.rb+++ b/api/lib/spree/api.rb@@ -1,8 +1,5 @@require 'spree/core'-require 'rabl'-require 'responders'-module Spreemodule Apienddiff --git a/api/lib/spree/api/configuration.rb b/api/lib/spree/api/configuration.rbindex 54d04ef215..75ae7f4626 100644--- a/api/lib/spree/api/configuration.rb+++ b/api/lib/spree/api/configuration.rb@@ -1,7 +1,6 @@module Spreemodule Apiclass Configuration < Preferences::Configuration- preference :requires_authentication, :boolean, default: truepreference :api_v2_serializers_cache_ttl, :integer, default: 3600 # 1 hour in secondspreference :api_v2_collection_cache_ttl, :integer, default: 3600 # 1 hour in secondspreference :api_v2_collection_cache_namespace, :string, default: 'api_v2_collection_cache'diff --git a/api/lib/spree/api/controller_setup.rb b/api/lib/spree/api/controller_setup.rbdeleted file mode 100644index a295b3bb62..0000000000--- a/api/lib/spree/api/controller_setup.rb+++ /dev/null@@ -1,19 +0,0 @@-require 'spree/api/responders'--module Spree- module Api- module ControllerSetup- def self.included(klass)- klass.class_eval do- include CanCan::ControllerAdditions-- prepend_view_path Rails.root + 'app/views'- append_view_path File.expand_path('../../../app/views', File.dirname(__FILE__))-- self.responder = Spree::Api::Responders::AppResponder- respond_to :json- end- end- end- end-enddiff --git a/api/lib/spree/api/responders.rb b/api/lib/spree/api/responders.rbdeleted file mode 100644index deb18094d1..0000000000--- a/api/lib/spree/api/responders.rb+++ /dev/null@@ -1,11 +0,0 @@-require 'spree/api/responders/rabl_template'--module Spree- module Api- module Responders- class AppResponder < ActionController::Responder- include RablTemplate- end- end- end-enddiff --git a/api/lib/spree/api/responders/rabl_template.rb b/api/lib/spree/api/responders/rabl_template.rbdeleted file mode 100644index dc853772e7..0000000000--- a/api/lib/spree/api/responders/rabl_template.rb+++ /dev/null@@ -1,28 +0,0 @@-module Spree- module Api- module Responders- module RablTemplate- def to_format- if template- render template, status: options[:status] || 200- else- super- end- rescue ActionView::MissingTemplate => e- api_behavior- end-- def template- options[:default_template]- end-- def api_behavior- if controller.params[:action] == 'destroy'- # Render a blank template- super- end- end- end- end- end-enddiff --git a/api/lib/spree/api/testing_support/helpers.rb b/api/lib/spree/api/testing_support/helpers.rbdeleted file mode 100644index 9c78e81fde..0000000000--- a/api/lib/spree/api/testing_support/helpers.rb+++ /dev/null@@ -1,44 +0,0 @@-module Spree- module Api- module TestingSupport- module Helpers- def json_response- case body = JSON.parse(response.body)- when Hash- body.with_indifferent_access- when Array- body- end- end-- def assert_not_found!- expect(json_response).to eq('error' => 'The resource you were looking for could not be found.')- expect(response.status).to eq 404- end-- def assert_unauthorized!- expect(json_response).to eq('error' => 'You are not authorized to perform that action.')- expect(response.status).to eq 401- end-- def stub_authentication!- allow(Spree.user_class).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }- end-- # This method can be overridden (with a let block) inside a context- # For instance, if you wanted to have an admin user instead.- def current_api_user- @current_api_user ||= stub_model(Spree.user_class, email: '[email protected]')- end-- def image(filename)- File.open(Spree::Api::Engine.root + 'spec/fixtures' + filename)- end-- def upload_image(filename)- fixture_file_upload(image(filename).path, 'image/jpg')- end- end- end- end-enddiff --git a/api/lib/spree/api/testing_support/setup.rb b/api/lib/spree/api/testing_support/setup.rbdeleted file mode 100644index 2210cba271..0000000000--- a/api/lib/spree/api/testing_support/setup.rb+++ /dev/null@@ -1,16 +0,0 @@-module Spree- module Api- module TestingSupport- module Setup- def sign_in_as_admin!- let!(:current_api_user) do- user = stub_model(Spree.user_class)- allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(['admin'])- allow(user).to receive(:has_spree_role?).with('admin').and_return(true)- user- end- end- end- end- end-enddiff --git a/api/lib/spree_api.rb b/api/lib/spree_api.rbindex da7f570833..8628301711 100644--- a/api/lib/spree_api.rb+++ b/api/lib/spree_api.rb@@ -1,4 +1,3 @@require 'spree/api'-require 'spree/api/responders'require 'jsonapi/serializer'require 'doorkeeper'diff --git a/api/spec/controllers/spree/api/base_controller_spec.rb b/api/spec/controllers/spree/api/base_controller_spec.rbdeleted file mode 100644index e4f47ee009..0000000000--- a/api/spec/controllers/spree/api/base_controller_spec.rb+++ /dev/null@@ -1,87 +0,0 @@-require 'spec_helper'--class FakesController < Spree::Api::BaseController-end--describe Spree::Api::BaseController, type: :controller do- render_views-- let(:store) { Spree::Store.default }-- controller(Spree::Api::BaseController) do- def index- render plain: { 'products' => [] }.to_json- end- end-- before do- @routes = ActionDispatch::Routing::RouteSet.new.tap do |r|- r.draw { get 'index', to: 'spree/api/base#index' }- end- end-- context 'when validating based on an order token' do- let!(:order) { create :order }-- context 'with a correct order token' do- it 'succeeds' do- api_get :index, order_token: order.token, order_id: order.number- expect(response.status).to eq(200)- end-- it 'succeeds with an order_number parameter' do- api_get :index, order_token: order.token, order_number: order.number- expect(response.status).to eq(200)- end- end-- context 'with an incorrect order token' do- it 'returns unauthorized' do- api_get :index, order_token: 'NOT_A_TOKEN', order_id: order.number- expect(response.status).to eq(401)- end- end- end-- context 'cannot make a request to the API' do- it 'without an API key' do- api_get :index- expect(json_response).to eq('error' => 'You must specify an API key.')- expect(response.status).to eq(401)- end-- it 'with an invalid API key' do- request.headers['X-Spree-Token'] = 'fake_key'- get :index- expect(json_response).to eq('error' => 'Invalid API key (fake_key) specified.')- expect(response.status).to eq(401)- end-- it 'using an invalid token param' do- get :index, params: { token: 'fake_key' }- expect(json_response).to eq('error' => 'Invalid API key (fake_key) specified.')- end- end-- it 'handles parameter missing exceptions' do- expect(subject).to receive(:authenticate_user).and_return(true)- expect(subject).to receive(:load_user_roles).and_return(true)- expect(subject).to receive(:index).and_raise(ActionController::ParameterMissing.new('foo'))- get :index, params: { token: 'exception-message' }- expect(json_response).to eql('exception' => 'param is missing or the value is empty: foo')- end-- it 'handles record invalid exceptions' do- expect(subject).to receive(:authenticate_user).and_return(true)- expect(subject).to receive(:load_user_roles).and_return(true)- resource = Spree::Product.new(stores: [store])- resource.valid? # get some errors- expect(subject).to receive(:index).and_raise(ActiveRecord::RecordInvalid.new(resource))- get :index, params: { token: 'exception-message' }- expect(json_response).to eql('exception' => "Validation failed: Name can't be blank, Shipping Category can't be blank, Price can't be blank")- end-- it 'lets a subclass override the product associations that are eager-loaded' do- expect(controller.respond_to?(:product_includes, true)).to be true- end-enddiff --git a/api/spec/controllers/spree/api/v1/addresses_controller_spec.rb b/api/spec/controllers/spree/api/v1/addresses_controller_spec.rbdeleted file mode 100644index a1e4718648..0000000000--- a/api/spec/controllers/spree/api/v1/addresses_controller_spec.rb+++ /dev/null@@ -1,56 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::AddressesController, type: :controller do- render_views-- before do- stub_authentication!- @address = create(:address)- @order = create(:order, bill_address: @address)- end-- context 'with their own address' do- before do- allow_any_instance_of(Order).to receive_messages user: current_api_user- end-- it 'gets an address' do- api_get :show, id: @address.id, order_id: @order.number- expect(json_response['address1']).to eq @address.address1- end-- it 'updates an address' do- api_put :update, id: @address.id, order_id: @order.number,- address: { address1: '123 Test Lane' }- expect(json_response['address1']).to eq '123 Test Lane'- end-- it 'receives the errors object if address is invalid' do- api_put :update, id: @address.id, order_id: @order.number,- address: { address1: '' }-- expect(json_response['error']).not_to be_nil- expect(json_response['errors']).not_to be_nil- expect(json_response['errors']['address1'].first).to eq "can't be blank"- end- end-- context 'on an address that does not belong to this order' do- before do- @order.bill_address_id = nil- @order.ship_address = nil- end-- it 'cannot retrieve address information' do- api_get :show, id: @address.id, order_id: @order.number- assert_unauthorized!- end-- it 'cannot update address information' do- api_get :update, id: @address.id, order_id: @order.number- assert_unauthorized!- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/checkouts_controller_spec.rb b/api/spec/controllers/spree/api/v1/checkouts_controller_spec.rbdeleted file mode 100644index 085f5323d5..0000000000--- a/api/spec/controllers/spree/api/v1/checkouts_controller_spec.rb+++ /dev/null@@ -1,379 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::CheckoutsController, type: :controller do- render_views-- let(:store) { Spree::Store.default }-- shared_examples_for 'action which loads order using load_order_with_lock' do- before do- allow(controller).to receive(:load_order).with(true).and_return(true)- end-- it 'invokes load_order_with_lock' do- expect(controller).to receive(:load_order_with_lock).once- end-- it 'invokes load_order' do- expect(controller).to receive(:load_order).with(true).once.and_return(true)- end-- context 'ensure no double_render_error' do- before do- def controller.load_order(*)- respond_with(@order, default_template: 'spree/api/v1/orders/show', status: 200)- end- end-- it 'does not generate double_render_error' do- expect(response).to be_successful- end- end-- after do- send_request- end- end-- before do- stub_authentication!- Spree::Config[:track_inventory_levels] = false- country_zone = create(:zone, name: 'CountryZone')- @state = create(:state)- @country = @state.country- country_zone.members.create(zoneable: @country)- create(:stock_location)-- @shipping_method = create(:shipping_method, zones: [country_zone])- @payment_method = create(:credit_card_payment_method, stores: [store], display_on: 'both')- end-- after do- Spree::Config[:track_inventory_levels] = true- end-- context "PUT 'update'" do- let(:order) do- order = create(:order_with_line_items, store: store)- # Order should be in a pristine state- # Without doing this, the order may transition from 'cart' straight to 'delivery'- Spree::ShippingRate.where(shipment_id: order.shipment_ids).delete_all- order.shipments.delete_all- order- end-- before do- allow_any_instance_of(Order).to receive_messages(confirmation_required?: true)- allow_any_instance_of(Order).to receive_messages(payment_required?: true)- end-- it 'transitions a recently created order from cart to address' do- expect(order.state).to eq 'cart'- expect(order.email).not_to be_nil- api_put :update, id: order.to_param, order_token: order.token- expect(order.reload.state).to eq 'address'- end-- it 'transitions a recently created order from cart to address with order token in header' do- expect(order.state).to eq 'cart'- expect(order.email).not_to be_nil- request.headers['X-Spree-Order-Token'] = order.token- api_put :update, id: order.to_param- expect(order.reload.state).to eq 'address'- end-- it 'can take line_items_attributes as a parameter' do- line_item = order.line_items.first- api_put :update, id: order.to_param, order_token: order.token,- order: { line_items_attributes: { 0 => { id: line_item.id, quantity: 1 } } }- expect(response.status).to eq(200)- expect(order.reload.state).to eq 'address'- end-- it 'can take line_items as a parameter' do- line_item = order.line_items.first- api_put :update, id: order.to_param, order_token: order.token,- order: { line_items: { 0 => { id: line_item.id, quantity: 1 } } }- expect(response.status).to eq(200)- expect(order.reload.state).to eq 'address'- end-- it 'will return an error if the order cannot transition' do- skip 'not sure if this test is valid'- order.bill_address = nil- order.save- order.update_column(:state, 'address')- api_put :update, id: order.to_param, order_token: order.token- # Order has not transitioned- expect(response.status).to eq(422)- end-- context 'transitioning to delivery' do- before do- order.update_column(:state, 'address')- end-- let(:address) do- {- firstname: 'John',- lastname: 'Doe',- address1: '7735 Old Georgetown Road',- city: 'Bethesda',- phone: '3014445002',- zipcode: '20814',- state_id: @state.id,- country_id: @country.id- }- end-- it 'can update addresses and transition from address to delivery' do- api_put :update,- id: order.to_param, order_token: order.token,- order: {- bill_address_attributes: address,- ship_address_attributes: address- }- expect(json_response['state']).to eq('delivery')- expect(json_response['bill_address']['firstname']).to eq('John')- expect(json_response['ship_address']['firstname']).to eq('John')- expect(response.status).to eq(200)- end-- # Regression Spec for #5389 & #5880- it 'can update addresses but not transition to delivery w/o shipping setup' do- Spree::ShippingMethod.destroy_all- api_put :update,- id: order.to_param, order_token: order.token,- order: {- bill_address_attributes: address,- ship_address_attributes: address- }- expect(json_response['error']).to eq(I18n.t(:could_not_transition, scope: 'spree.api.order'))- expect(response.status).to eq(422)- end-- # Regression test for #4498- it 'does not contain duplicate variant data in delivery return' do- api_put :update,- id: order.to_param, order_token: order.token,- order: {- bill_address_attributes: address,- ship_address_attributes: address- }- # Shipments manifests should not return the ENTIRE variant- # This information is already present within the order's line items- expect(json_response['shipments'].first['manifest'].first['variant']).to be_nil- expect(json_response['shipments'].first['manifest'].first['variant_id']).not_to be_nil- end- end-- it 'can update shipping method and transition from delivery to payment' do- order.update_column(:state, 'delivery')- shipment = create(:shipment, order: order)- shipment.refresh_rates- shipping_rate = shipment.shipping_rates.where(selected: false).first- api_put :update, id: order.to_param, order_token: order.token,- order: { shipments_attributes: { '0' => { selected_shipping_rate_id: shipping_rate.id, id: shipment.id } } }- expect(response.status).to eq(200)- # Find the correct shipment...- json_shipment = json_response['shipments'].detect { |s| s['id'] == shipment.id }- # Find the correct shipping rate for that shipment...- json_shipping_rate = json_shipment['shipping_rates'].detect { |sr| sr['id'] == shipping_rate.id }- # ... And finally ensure that it's selected- expect(json_shipping_rate['selected']).to be true- # Order should automatically transfer to payment because all criteria are met- expect(json_response['state']).to eq('payment')- end-- it 'can update payment method and transition from payment to confirm' do- allow_any_instance_of(Spree::PaymentMethod).to receive(:source_required?).and_return(false)- order.update_column(:state, 'payment')- api_put :update, id: order.to_param, order_token: order.token,- order: { payments_attributes: [{ payment_method_id: @payment_method.id }] }- expect(json_response['state']).to eq('confirm')- expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)- expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)- expect(response.status).to eq(200)- end-- it 'can update payment method with source and transition from payment to confirm' do- order.update_column(:state, 'payment')- source_attributes = {- number: '4111111111111111',- month: 1.month.from_now.month,- year: 1.month.from_now.year,- verification_value: '123',- name: 'Spree Commerce'- }-- api_put :update, id: order.to_param, order_token: order.token,- order: { payments_attributes: [{ payment_method_id: @payment_method.id.to_s, source_attributes: source_attributes }] }- expect(json_response['payments'][0]['payment_method']['name']).to eq(@payment_method.name)- expect(json_response['payments'][0]['amount']).to eq(order.total.to_s)- expect(response.status).to eq(200)- end-- it 'returns errors when source is missing attributes' do- order.update_column(:state, 'payment')- api_put :update, id: order.to_param, order_token: order.token,- order: {- payments_attributes: [{ payment_method_id: @payment_method.id }]- },- payment_source: {- @payment_method.id.to_s => { name: 'Spree' }- }-- expect(response.status).to eq(422)- cc_errors = json_response['errors']['payments.Credit Card']- expect(cc_errors).to include("Number can't be blank")- expect(cc_errors).to include('Month is not a number')- expect(cc_errors).to include('Year is not a number')- expect(cc_errors).to include("Verification Value can't be blank")- end-- it 'allow users to reuse a credit card' do- order.update_column(:state, 'payment')- credit_card = create(:credit_card, user_id: order.user_id, payment_method_id: @payment_method.id)-- api_put :update, id: order.to_param, order_token: order.token,- order: { existing_card: credit_card.id }-- expect(response.status).to eq 200- expect(order.credit_cards).to match_array [credit_card]- end-- it 'can transition from confirm to complete' do- order.update_columns(state: 'confirm')- allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)- api_put :update, id: order.to_param, order_token: order.token- expect(json_response['state']).to eq('complete')- expect(response.status).to eq(200)- end-- it 'can transition from confirm to delivery with logging state changes' do- order.update_columns(state: 'confirm')- allow_any_instance_of(Spree::Order).to receive_messages(payment_required?: false)- api_put :update, state: 'delivery', id: order.to_param, order_token: order.token- expect(response.status).to eq(200)- expect(order.state_changes.count).to eq 3- end-- it 'prevent normal user from updating completed order' do- order.update_columns(completed_at: Time.current, state: 'complete')- api_put :update, id: order.to_param, order_token: order.token- assert_unauthorized!- end-- # Regression test for #3784- it 'can update the special instructions for an order' do- instructions = "Don't drop it. (Please)"- api_put :update, id: order.to_param, order_token: order.token,- order: { special_instructions: instructions }- expect(json_response['special_instructions']).to eql(instructions)- end-- context 'as an admin' do- sign_in_as_admin!- it 'can assign a user to the order' do- user = create(:user)- # Need to pass email as well so that validations succeed- api_put :update, id: order.to_param, order_token: order.token,- order: { user_id: user.id, email: '[email protected]' }- expect(response.status).to eq(200)- expect(json_response['user_id']).to eq(user.id)- end- end-- it 'can assign an email to the order' do- api_put :update, id: order.to_param, order_token: order.token,- order: { email: '[email protected]' }- expect(json_response['email']).to eq('[email protected]')- expect(response.status).to eq(200)- end-- it 'can apply a coupon code to an order' do- order.update_column(:state, 'payment')- expect(PromotionHandler::Coupon).to receive(:new).with(order).and_call_original- expect_any_instance_of(PromotionHandler::Coupon).to receive(:apply).and_return(coupon_applied?: true)- api_put :update, id: order.to_param, order_token: order.token, order: { coupon_code: 'foobar' }- end-- def send_request- api_put :update, id: order.to_param, order_token: order.token- end-- it_behaves_like 'action which loads order using load_order_with_lock'- end-- context "PUT 'next'" do- let!(:order) { create(:order_with_line_items, store: store) }-- it 'cannot transition to address without a line item' do- order.line_items.delete_all- order.update_column(:email, '[email protected]')- api_put :next, id: order.to_param, order_token: order.token- expect(response.status).to eq(422)- expect(json_response['errors']['base']).to include(Spree.t(:there_are_no_items_for_this_order))- end-- it 'can transition an order to the next state' do- order.update_column(:email, '[email protected]')-- api_put :next, id: order.to_param, order_token: order.token- expect(response.status).to eq(200)- expect(json_response['state']).to eq('address')- end-- it 'cannot transition if order email is blank' do- order.update_columns(- state: 'address',- email: nil- )-- api_put :next, id: order.to_param, order_token: order.token- expect(response.status).to eq(422)- expect(json_response['error']).to match(/could not be transitioned/)- end-- it 'cannot transition if any line_item becomes unavailable' do- allow_any_instance_of(Order).to receive(:insufficient_stock_lines).and_return(order.line_items)- api_put :next, id: order.to_param, order_token: order.token- expect(response.status).to eq(422)- expect(json_response['error']).to match(Spree.t(:insufficient_quantity, scope: [:api, :order]))- end-- it 'doesnt advance payment state if order has no payment' do- order.update_column(:state, 'payment')- api_put :next, id: order.to_param, order_token: order.token, order: {}- expect(json_response['errors']['base']).to include(Spree.t(:no_payment_found))- end-- def send_request- api_put :next, id: order.to_param, order_token: order.token- end-- it_behaves_like 'action which loads order using load_order_with_lock'- end-- context "PUT 'advance'" do- let!(:order) { create(:order_with_line_items, store: store) }-- it 'continues to advance advances an order while it can move forward' do- expect_any_instance_of(Spree::Order).to receive(:next).exactly(3).times.and_return(true, true, false)- api_put :advance, id: order.to_param, order_token: order.token- end-- it 'returns the order' do- api_put :advance, id: order.to_param, order_token: order.token- expect(json_response['id']).to eq(order.id)- end-- def send_request- api_put :advance, id: order.to_param, order_token: order.token- end-- it_behaves_like 'action which loads order using load_order_with_lock'- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/classifications_controller_spec.rb b/api/spec/controllers/spree/api/v1/classifications_controller_spec.rbdeleted file mode 100644index e198857622..0000000000--- a/api/spec/controllers/spree/api/v1/classifications_controller_spec.rb+++ /dev/null@@ -1,48 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::ClassificationsController, type: :controller do- let(:taxon) do- taxon = create(:taxon)-- 3.times do- product = create(:product, stores: Spree::Store.all)- product.taxons << taxon- end- taxon- end-- before do- stub_authentication!- end-- context 'as a user' do- it 'cannot change the order of a product' do- api_put :update, taxon_id: taxon, product_id: taxon.products.first, position: 1- expect(response.status).to eq(401)- end- end-- context 'as an admin' do- sign_in_as_admin!-- let(:last_product) { taxon.products.last }-- it 'can change the order a product' do- classification = taxon.classifications.find_by(product_id: last_product.id)- expect(classification.position).to eq(3)- api_put :update, taxon_id: taxon.id, product_id: last_product.id, position: 0- expect(response.status).to eq(200)- expect(classification.reload.position).to eq(1)- end-- it 'touches the taxon' do- taxon.update(updated_at: Time.current - 10.seconds)- taxon_last_updated_at = taxon.updated_at- api_put :update, taxon_id: taxon.id, product_id: last_product.id, position: 0- taxon.reload- expect(taxon_last_updated_at.to_i).not_to eq(taxon.updated_at.to_i)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/countries_controller_spec.rb b/api/spec/controllers/spree/api/v1/countries_controller_spec.rbdeleted file mode 100644index d39ac38043..0000000000--- a/api/spec/controllers/spree/api/v1/countries_controller_spec.rb+++ /dev/null@@ -1,48 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::CountriesController, type: :controller do- render_views-- before do- stub_authentication!- @state = create(:state)- @country = @state.country- end-- it 'gets all countries' do- api_get :index- expect(json_response['countries'].first['iso3']).to eq @country.iso3- end-- context 'with two countries' do- before { @zambia = create(:country, name: 'Zambia') }-- it 'can view all countries' do- api_get :index- expect(json_response['count']).to eq(2)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- end-- it 'can query the results through a parameter' do- api_get :index, q: { name_cont: 'zam' }- expect(json_response['count']).to eq(1)- expect(json_response['countries'].first['name']).to eq @zambia.name- end-- it 'can control the page size through a parameter' do- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end- end-- it 'includes states' do- api_get :show, id: @country.id- states = json_response['states']- expect(states.first['name']).to eq @state.name- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb b/api/spec/controllers/spree/api/v1/credit_cards_controller_spec.rbdeleted file mode 100644index e9f0f71f0c..0000000000--- a/api/spec/controllers/spree/api/v1/credit_cards_controller_spec.rb+++ /dev/null@@ -1,80 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::CreditCardsController, type: :controller do- render_views-- let!(:admin_user) do- user = Spree.user_class.new(email: '[email protected]', id: 1)- user.generate_spree_api_key!- allow(user).to receive(:has_spree_role?).with('admin').and_return(true)- user- end-- let!(:normal_user) do- user = Spree.user_class.new(email: '[email protected]', id: 2)- user.generate_spree_api_key!- user- end-- let!(:card) { create(:credit_card, user_id: admin_user.id, gateway_customer_profile_id: 'random') }-- before do- stub_authentication!- end-- it "the user id doesn't exist" do- api_get :index, user_id: 1000- expect(response.status).to eq(404)- end-- context 'calling user is in admin role' do- let(:current_api_user) do- user = admin_user- user- end-- it 'no credit cards exist for user' do- api_get :index, user_id: normal_user.id-- expect(response.status).to eq(200)- expect(json_response['pages']).to eq(0)- end-- it 'can view all credit cards for user' do- api_get :index, user_id: current_api_user.id-- expect(response.status).to eq(200)- expect(json_response['pages']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['credit_cards'].length).to eq(1)- expect(json_response['credit_cards'].first['id']).to eq(card.id)- end- end-- context 'calling user is not in admin role' do- let(:current_api_user) do- user = normal_user- user- end-- let!(:card) { create(:credit_card, user_id: normal_user.id, gateway_customer_profile_id: 'random') }-- it 'can not view user' do- api_get :index, user_id: admin_user.id-- expect(response.status).to eq(404)- end-- it 'can view own credit cards' do- api_get :index, user_id: normal_user.id-- expect(response.status).to eq(200)- expect(json_response['pages']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['credit_cards'].length).to eq(1)- expect(json_response['credit_cards'].first['id']).to eq(card.id)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/customer_returns_controller_spec.rb b/api/spec/controllers/spree/api/v1/customer_returns_controller_spec.rbdeleted file mode 100644index 78c7d50a2e..0000000000--- a/api/spec/controllers/spree/api/v1/customer_returns_controller_spec.rb+++ /dev/null@@ -1,26 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::CustomerReturnsController, type: :controller do- render_views-- before do- stub_authentication!- @customer_return = create(:customer_return)- end-- describe '#index' do- let(:order) { customer_return.order }- let(:customer_return) { create(:customer_return) }-- before do- api_get :index- end-- it 'loads customer returns' do- expect(response.status).to eq(200)- expect(json_response['count']).to eq(1)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/images_controller_spec.rb b/api/spec/controllers/spree/api/v1/images_controller_spec.rbdeleted file mode 100644index 94e34445ed..0000000000--- a/api/spec/controllers/spree/api/v1/images_controller_spec.rb+++ /dev/null@@ -1,115 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::ImagesController, type: :controller do- render_views-- let!(:product) { create(:product, stores: Spree::Store.all) }- let!(:attributes) do- [:id, :position, :attachment_content_type,- :attachment_file_name, :type, :attachment_updated_at, :attachment_width,- :attachment_height, :alt]- end-- before do- stub_authentication!- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can learn how to create a new image' do- api_get :new, product_id: product.id- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- expect(json_response['required_attributes']).to be_empty- end-- it 'can upload a new image for a variant' do- expect do- api_post :create,- image: { attachment: upload_image('thinking-cat.jpg'),- viewable_type: 'Spree::Variant',- viewable_id: product.master.to_param },- product_id: product.id- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- end.to change(Image, :count).by(1)- end-- it "can't upload a new image for a variant without attachment" do- api_post :create,- image: { viewable_type: 'Spree::Variant',- viewable_id: product.master.to_param },- product_id: product.id- expect(response.status).to eq(422)- end-- context 'working with an existing image' do- let!(:product_image) { create_image(product.master, image('thinking-cat.jpg')) }-- it 'can get a single product image' do- api_get :show, id: product_image.id, product_id: product.id- expect(response.status).to eq(200)- expect(json_response).to have_attributes(attributes)- end-- it 'can get a single variant image' do- api_get :show, id: product_image.id, variant_id: product.master.id- expect(response.status).to eq(200)- expect(json_response).to have_attributes(attributes)- end-- it 'can get a list of product images' do- api_get :index, product_id: product.id- expect(response.status).to eq(200)- expect(json_response).to have_key('images')- expect(json_response['images'].first).to have_attributes(attributes)- end-- it 'can get a list of variant images' do- api_get :index, variant_id: product.master.id- expect(response.status).to eq(200)- expect(json_response).to have_key('images')- expect(json_response['images'].first).to have_attributes(attributes)- end-- it 'can update image data' do- expect(product_image.position).to eq(1)- api_post :update, image: { position: 2 }, id: product_image.id, product_id: product.id- expect(response.status).to eq(200)- expect(json_response).to have_attributes(attributes)- expect(product_image.reload.position).to eq(2)- end-- it "can't update an image without attachment" do- api_post :update,- id: product_image.id, product_id: product.id- expect(response.status).to eq(422)- end-- it 'can delete an image' do- api_delete :destroy, id: product_image.id, product_id: product.id- expect(response.status).to eq(204)- expect { product_image.reload }.to raise_error(ActiveRecord::RecordNotFound)- end- end- end-- context 'as a non-admin' do- it 'cannot create an image' do- api_post :create, product_id: product.id- assert_unauthorized!- end-- it 'cannot update an image' do- api_put :update, id: 1, product_id: product.id- assert_not_found!- end-- it 'cannot delete an image' do- api_delete :destroy, id: 1, product_id: product.id- assert_not_found!- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb b/api/spec/controllers/spree/api/v1/inventory_units_controller_spec.rbdeleted file mode 100644index 096dd8fe00..0000000000--- a/api/spec/controllers/spree/api/v1/inventory_units_controller_spec.rb+++ /dev/null@@ -1,48 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::InventoryUnitsController, type: :controller do- render_views-- before do- stub_authentication!- @inventory_unit = create(:inventory_unit)- end-- context 'as an admin' do- sign_in_as_admin!-- it 'gets an inventory unit' do- api_get :show, id: @inventory_unit.id- expect(json_response['state']).to eq @inventory_unit.state- end-- it 'updates an inventory unit' do- api_put :update, id: @inventory_unit.id,- inventory_unit: { shipment_id: nil }- expect(json_response['shipment_id']).to be_nil- end-- context 'fires state event' do- it 'if supplied with :fire param' do- api_put :update, id: @inventory_unit.id,- fire: 'ship',- inventory_unit: { shipment: { tracking: 'foobar' } }- expect(json_response['state']).to eq 'shipped'- end-- it 'and returns exception if cannot fire' do- api_put :update, id: @inventory_unit.id,- fire: 'return'- expect(json_response['exception']).to match(/cannot transition to return/)- end-- it 'and returns exception bad state' do- api_put :update, id: @inventory_unit.id,- fire: 'bad'- expect(json_response['exception']).to match(/cannot transition to bad/)- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb b/api/spec/controllers/spree/api/v1/line_items_controller_spec.rbdeleted file mode 100644index f9f22cdb61..0000000000--- a/api/spec/controllers/spree/api/v1/line_items_controller_spec.rb+++ /dev/null@@ -1,206 +0,0 @@-require 'spec_helper'--module Spree- PermittedAttributes.module_eval do- mattr_writer :line_item_attributes- end-- unless PermittedAttributes.line_item_attributes.include?(:some_option)- PermittedAttributes.line_item_attributes += [:some_option]- end-- # This should go in an initializer- Spree::Api::V1::LineItemsController.line_item_options += [:some_option]-- describe Api::V1::LineItemsController, type: :controller do- render_views-- let!(:order) { create(:order_with_line_items, line_items_count: 1) }-- let(:product) { create(:product, stores: Spree::Store.all) }- let(:attributes) { [:id, :quantity, :price, :variant, :total, :display_amount, :single_display_amount] }- let(:resource_scoping) { { order_id: order.to_param } }- let(:admin_role) { create(:admin_role) }-- before do- stub_authentication!- end-- it 'can learn how to create a new line item' do- api_get :new- expect(json_response['attributes']).to eq(['quantity', 'price', 'variant_id'])- required_attributes = json_response['required_attributes']- expect(required_attributes).to include('quantity', 'variant_id')- end-- context 'authenticating with a token' do- it 'can add a new line item to an existing order' do- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }, order_token: order.token- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- expect(json_response['variant']['name']).not_to be_blank- end-- it 'can add a new line item to an existing order with token in header' do- request.headers['X-Spree-Order-Token'] = order.token- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- expect(json_response['variant']['name']).not_to be_blank- end- end-- context 'as the order owner' do- before do- allow_any_instance_of(Order).to receive_messages user: current_api_user- end-- it 'can add a new line item to an existing order' do- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- expect(json_response['variant']['name']).not_to be_blank- end-- it 'can add a new line item to an existing order with options' do- expect_any_instance_of(LineItem).to receive(:some_option=).with('foo')- api_post :create,- line_item: {- variant_id: product.master.to_param,- quantity: 1,- options: { some_option: 'foo' }- }- expect(response.status).to eq(201)- end-- it 'default quantity to 1 if none is given' do- api_post :create, line_item: { variant_id: product.master.to_param }- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- expect(json_response[:quantity]).to eq 1- end-- it "increases a line item's quantity if it exists already" do- order.line_items.create(variant_id: product.master.id, quantity: 10)- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }- expect(response.status).to eq(201)- order.reload- expect(order.line_items.count).to eq(2) # 1 original due to factory, + 1 in this test- expect(json_response).to have_attributes(attributes)- expect(json_response['quantity']).to eq(11)- end-- it 'can update a line item on the order' do- line_item = order.line_items.first- api_put :update, id: line_item.id, line_item: { quantity: 101 }- expect(response.status).to eq(200)- order.reload- expect(order.total).to eq(1010) # 10 original due to factory, + 1000 in this test- expect(json_response).to have_attributes(attributes)- expect(json_response['quantity']).to eq(101)- end-- it "can update a line item's options on the order" do- expect_any_instance_of(LineItem).to receive(:some_option=).with('foo')- line_item = order.line_items.first- api_put :update,- id: line_item.id,- line_item: { quantity: 1, options: { some_option: 'foo' } }- expect(response.status).to eq(200)- end-- it 'can delete a line item on the order' do- line_item = order.line_items.first- api_delete :destroy, id: line_item.id- expect(response.status).to eq(204)- order.reload- expect(order.line_items.count).to eq(0) # 1 original due to factory, - 1 in this test- expect { line_item.reload }.to raise_error(ActiveRecord::RecordNotFound)- end-- context 'order contents changed after shipments were created' do- let!(:order) { create(:order) }- let!(:line_item) { Spree::Cart::AddItem.call(order: order, variant: product.master).value }-- before { order.create_proposed_shipments }-- it 'clear out shipments on create' do- expect(order.reload.shipments).not_to be_empty- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }- expect(order.reload.shipments).to be_empty- end-- it 'clear out shipments on update' do- expect(order.reload.shipments).not_to be_empty- api_put :update, id: line_item.id, line_item: { quantity: 1000 }- expect(order.reload.shipments).to be_empty- end-- it 'clear out shipments on delete' do- expect(order.reload.shipments).not_to be_empty- api_delete :destroy, id: line_item.id- expect(order.reload.shipments).to be_empty- end-- context 'order is completed' do- before do- current_api_user.spree_roles << admin_role- order.reload- allow(order).to receive_messages completed?: true- allow(Order).to receive_message_chain :includes, find_by!: order- end-- it "doesn't destroy shipments or restart checkout flow" do- expect(order.reload.shipments).not_to be_empty- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }- expect(order.reload.shipments).not_to be_empty- end-- context 'deleting line items' do- let!(:shipments) { order.shipments.load }-- it 'restocks product after line item removal' do- line_item = order.line_items.first- variant = line_item.variant- expect do- api_delete :destroy, id: line_item.id- end.to change { variant.total_on_hand }.by(line_item.quantity)-- expect(response.status).to eq(204)- order.reload- expect(order.line_items.count).to eq(0)- end-- it 'calls `restock` on proper stock location' do- expect(shipments.first.stock_location).to receive(:restock)- api_delete :destroy, id: line_item.id- end- end- end- end- end-- context 'as just another user' do- before { create(:user) }-- it 'cannot add a new line item to the order' do- api_post :create, line_item: { variant_id: product.master.to_param, quantity: 1 }- assert_unauthorized!- end-- it 'cannot update a line item on the order' do- line_item = order.line_items.first- api_put :update, id: line_item.id, line_item: { quantity: 1000 }- assert_unauthorized!- expect(line_item.reload.quantity).not_to eq(1000)- end-- it 'cannot delete a line item on the order' do- line_item = order.line_items.first- api_delete :destroy, id: line_item.id- assert_unauthorized!- expect { line_item.reload }.not_to raise_error- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/option_types_controller_spec.rb b/api/spec/controllers/spree/api/v1/option_types_controller_spec.rbdeleted file mode 100644index 0a2e520957..0000000000--- a/api/spec/controllers/spree/api/v1/option_types_controller_spec.rb+++ /dev/null@@ -1,116 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::OptionTypesController, type: :controller do- render_views-- let(:attributes) { [:id, :name, :presentation, :position] }- let!(:option_value) { create(:option_value) }- let!(:option_type) { option_value.option_type }-- before do- stub_authentication!- end-- def check_option_values(option_values)- expect(option_values.count).to eq(1)- expect(option_values.first).to have_attributes([:id, :name, :presentation,- :option_type_id, :option_type_name])- end-- it 'can list all option types' do- api_get :index- expect(json_response.count).to eq(1)- expect(json_response.first).to have_attributes(attributes)-- check_option_values(json_response.first['option_values'])- end-- it 'can search for an option type' do- create(:option_type, name: 'buzz')- api_get :index, q: { name_cont: option_type.name }- expect(json_response.count).to eq(1)- expect(json_response.first).to have_attributes(attributes)- end-- it 'can retrieve a list of specific option types' do- option_type_1 = create(:option_type)- create(:option_type) # option_type_2-- api_get :index, ids: "#{option_type.id},#{option_type_1.id}"- expect(json_response.count).to eq(2)-- check_option_values(json_response.first['option_values'])- end-- it 'can list a single option type' do- api_get :show, id: option_type.id- expect(json_response).to have_attributes(attributes)- check_option_values(json_response['option_values'])- end-- it 'can learn how to create a new option type' do- api_get :new- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- expect(json_response['required_attributes']).not_to be_empty- end-- it 'cannot create a new option type' do- api_post :create, option_type: {- name: 'Option Type',- presentation: 'Option Type'- }- assert_unauthorized!- end-- it 'cannot alter an option type' do- original_name = option_type.name- api_put :update, id: option_type.id,- option_type: {- name: 'Option Type'- }- assert_not_found!- expect(option_type.reload.name).to eq(original_name)- end-- it 'cannot delete an option type' do- api_delete :destroy, id: option_type.id- assert_not_found!- expect { option_type.reload }.not_to raise_error- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can create an option type' do- api_post :create, option_type: {- name: 'Option Type',- presentation: 'Option Type'- }- expect(json_response).to have_attributes(attributes)- expect(response.status).to eq(201)- end-- it 'cannot create an option type with invalid attributes' do- api_post :create, option_type: {}- expect(response.status).to eq(422)- end-- it 'can update an option type' do- api_put :update, id: option_type.id, option_type: { name: 'Option Type' }- expect(response.status).to eq(200)- expect(option_type.reload.name).to eq('Option Type')- end-- it 'cannot update an option type with invalid attributes' do- api_put :update, id: option_type.id, option_type: { name: '' }- expect(response.status).to eq(422)- end-- it 'can delete an option type' do- api_delete :destroy, id: option_type.id- expect(response.status).to eq(204)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/option_values_controller_spec.rb b/api/spec/controllers/spree/api/v1/option_values_controller_spec.rbdeleted file mode 100644index 83bcf0819b..0000000000--- a/api/spec/controllers/spree/api/v1/option_values_controller_spec.rb+++ /dev/null@@ -1,132 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::OptionValuesController, type: :controller do- render_views-- let(:attributes) { [:id, :name, :presentation, :option_type_name, :option_type_id, :option_type_presentation] }- let!(:option_value) { create(:option_value) }- let!(:option_type) { option_value.option_type }-- before do- stub_authentication!- end-- def check_option_values(option_values)- expect(option_values.count).to eq(1)- expect(option_values.first).to have_attributes([:id, :name, :presentation,- :option_type_name, :option_type_id])- end-- context 'without any option type scoping' do- before do- # Create another option value with a brand new option type- create(:option_value, option_type: create(:option_type))- end-- it 'can retrieve a list of all option values' do- api_get :index- expect(json_response.count).to eq(2)- expect(json_response.first).to have_attributes(attributes)- end- end-- context 'for a particular option type' do- let(:resource_scoping) { { option_type_id: option_type.id } }-- it 'can list all option values' do- api_get :index- expect(json_response.count).to eq(1)- expect(json_response.first).to have_attributes(attributes)- end-- it 'can search for an option type' do- create(:option_value, name: 'buzz')- api_get :index, q: { name_cont: option_value.name }- expect(json_response.count).to eq(1)- expect(json_response.first).to have_attributes(attributes)- end-- it 'can retrieve a list of option types' do- option_value_1 = create(:option_value, option_type: option_type)- create(:option_value, option_type: option_type) # option_value_2- api_get :index, ids: [option_value.id, option_value_1.id]- expect(json_response.count).to eq(2)- end-- it 'can list a single option value' do- api_get :show, id: option_value.id- expect(json_response).to have_attributes(attributes)- end-- it 'cannot create a new option value' do- api_post :create, option_value: {- name: 'Option Value',- presentation: 'Option Value'- }- assert_unauthorized!- end-- it 'cannot alter an option value' do- original_name = option_type.name- api_put :update, id: option_type.id,- option_value: {- name: 'Option Value'- }- assert_not_found!- expect(option_type.reload.name).to eq(original_name)- end-- it 'cannot delete an option value' do- api_delete :destroy, id: option_type.id- assert_not_found!- expect { option_type.reload }.not_to raise_error- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can learn how to create a new option value' do- api_get :new- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- expect(json_response['required_attributes']).not_to be_empty- end-- it 'can create an option value' do- api_post :create, option_value: {- name: 'Option Value',- presentation: 'Option Value'- }- expect(json_response).to have_attributes(attributes)- expect(response.status).to eq(201)- end-- it 'cannot create an option type with invalid attributes' do- api_post :create, option_value: {}- expect(response.status).to eq(422)- end-- it 'can update an option value' do- api_put :update, id: option_value.id, option_value: { name: 'Option Value' }- expect(response.status).to eq(200)- expect(option_value.reload.name).to eq('Option Value')- end-- it 'permits the correct attributes' do- expect(controller).to receive(:permitted_option_value_attributes)- api_put :update, id: option_value.id, option_value: { name: '' }- end-- it 'cannot update an option value with invalid attributes' do- api_put :update, id: option_value.id, option_value: { name: '' }- expect(response.status).to eq(422)- end-- it 'can delete an option value' do- api_delete :destroy, id: option_value.id- expect(response.status).to eq(204)- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb b/api/spec/controllers/spree/api/v1/orders_controller_spec.rbdeleted file mode 100755index 5b7b2890e2..0000000000--- a/api/spec/controllers/spree/api/v1/orders_controller_spec.rb+++ /dev/null@@ -1,856 +0,0 @@-require 'spec_helper'-require 'spree/testing_support/bar_ability'--module Spree- describe Api::V1::OrdersController, type: :controller do- render_views-- let!(:order) { create(:order) }- let(:variant) { create(:variant) }- let(:line_item) { create(:line_item) }-- let(:attributes) do- [:number, :item_total, :display_total, :total, :state, :adjustment_total, :user_id,- :created_at, :updated_at, :completed_at, :payment_total, :shipment_state, :payment_state,- :email, :special_instructions, :total_quantity, :display_item_total, :currency, :considered_risky]- end-- let(:address_params) { { country_id: Country.first.id, state_id: State.first.id } }-- let(:current_api_user) do- user = Spree.user_class.new(email: '[email protected]')- user.generate_spree_api_key!- user- end-- before do- stub_authentication!- end-- it 'cannot view all orders' do- api_get :index- assert_unauthorized!- end-- context 'the current api user is not persisted' do- let(:current_api_user) { Spree.user_class.new }-- it 'returns a 401' do- api_get :mine- expect(response.status).to eq(401)- end- end-- context 'the current api user is authenticated' do- let(:current_api_user) { order.user }- let(:order) { create(:order, line_items: [line_item]) }-- it 'can view all of their own orders' do- api_get :mine-- expect(response.status).to eq(200)- expect(json_response['pages']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['orders'].length).to eq(1)- expect(json_response['orders'].first['number']).to eq(order.number)- expect(json_response['orders'].first['line_items'].length).to eq(1)- expect(json_response['orders'].first['line_items'].first['id']).to eq(line_item.id)- end-- it 'can filter the returned results' do- api_get :mine, q: { completed_at_not_null: 1 }-- expect(response.status).to eq(200)- expect(json_response['orders'].length).to eq(0)- end-- it 'returns orders in reverse chronological order by completed_at' do- Timecop.scale(3600) do- order.update_columns completed_at: Time.current-- order2 = Order.create user: order.user, completed_at: Time.current - 1.day- expect(order2.created_at).to be > order.created_at- order3 = Order.create user: order.user, completed_at: nil- expect(order3.created_at).to be > order2.created_at- order4 = Order.create user: order.user, completed_at: nil- expect(order4.created_at).to be > order3.created_at-- api_get :mine- expect(response.status).to eq(200)- expect(json_response['pages']).to eq(1)- expect(json_response['orders'].length).to eq(4)- expect(json_response['orders'][0]['number']).to eq(order.number)- expect(json_response['orders'][1]['number']).to eq(order2.number)- expect(json_response['orders'][2]['number']).to eq(order4.number)- expect(json_response['orders'][3]['number']).to eq(order3.number)- end- end- end-- describe 'current' do- subject do- api_get :current, format: 'json'- end-- let(:current_api_user) { order.user }- let!(:order) { create(:order, line_items: [line_item]) }-- context 'an incomplete order exists' do- it 'returns that order' do- expect(JSON.parse(subject.body)['id']).to eq order.id- expect(subject).to be_successful- end- end-- context 'multiple incomplete orders exist' do- it 'returns the latest incomplete order' do- Timecop.scale(3600) do- new_order = Spree::Order.create! user: order.user- expect(new_order.created_at).to be > order.created_at- expect(JSON.parse(subject.body)['id']).to eq new_order.id- end- end- end-- context 'an incomplete order does not exist' do- before do- order.update_attribute(:state, order_state)- order.update_attribute(:completed_at, 5.minutes.ago)- end-- ['complete', 'returned', 'awaiting_return'].each do |order_state|- context "order is in the #{order_state} state" do- let(:order_state) { order_state }-- it 'returns no content' do- expect(subject.status).to eq 204- expect(subject.body).to be_blank- end- end- end- end- end-- it 'can view their own order' do- allow_any_instance_of(Order).to receive_messages user: current_api_user- api_get :show, id: order.to_param- expect(response.status).to eq(200)- expect(json_response).to have_attributes(attributes)- expect(json_response['adjustments']).to be_empty- end-- describe 'GET #show' do- subject { api_get :show, id: order.to_param }-- let(:order) { create :order_with_line_items }- let(:adjustment) { FactoryBot.create(:adjustment, order: order) }-- before do- allow_any_instance_of(Order).to receive_messages user: current_api_user- end-- context 'when inventory information is present' do- it 'contains stock information on variant' do- subject- variant = json_response['line_items'][0]['variant']- expect(variant).not_to be_nil- expect(variant['in_stock']).to eq(false)- expect(variant['total_on_hand']).to eq(0)- expect(variant['is_backorderable']).to eq(true)- expect(variant['is_destroyed']).to eq(false)- end- end-- context 'when shipment adjustments are present' do- before do- order.shipments.first.adjustments << adjustment- end-- it 'contains adjustments on shipment' do- subject-- # Test to insure shipment has adjustments- shipment = json_response['shipments'][0]- expect(shipment).not_to be_nil- expect(shipment['adjustments'][0]).not_to be_empty- expect(shipment['adjustments'][0]['label']).to eq(adjustment.label)- end- end- end-- it 'order contains the basic checkout steps' do- allow_any_instance_of(Order).to receive_messages user: current_api_user- api_get :show, id: order.to_param- expect(response.status).to eq(200)- expect(json_response['checkout_steps']).to eq(['address', 'delivery', 'complete'])- end-- # Regression test for #1992- it 'can view an order not in a standard state' do- allow_any_instance_of(Order).to receive_messages user: current_api_user- order.update_column(:state, 'shipped')- api_get :show, id: order.to_param- end-- it "can not view someone else's order" do- allow_any_instance_of(Order).to receive_messages user: stub_model(Spree::LegacyUser)- api_get :show, id: order.to_param- assert_unauthorized!- end-- it 'can view an order if the token is known' do- api_get :show, id: order.to_param, order_token: order.token- expect(response.status).to eq(200)- end-- it 'can view an order if the token is passed in header' do- request.headers['X-Spree-Order-Token'] = order.token- api_get :show, id: order.to_param- expect(response.status).to eq(200)- end-- context 'with BarAbility registered' do- before { Spree::Ability.register_ability(::BarAbility) }-- after { Spree::Ability.remove_ability(::BarAbility) }-- it 'can view an order' do- user = mock_model(Spree::LegacyUser)- allow(user).to receive_message_chain(:spree_roles, :pluck).and_return(['bar'])- allow(user).to receive(:has_spree_role?).with('bar').and_return(true)- allow(user).to receive(:has_spree_role?).with('admin').and_return(false)- allow(Spree.user_class).to receive_messages find_by: user- api_get :show, id: order.to_param- expect(response.status).to eq(200)- end- end-- it "cannot cancel an order that doesn't belong to them" do- order.update_attribute(:completed_at, Time.current)- order.update_attribute(:shipment_state, 'ready')- api_put :cancel, id: order.to_param- assert_unauthorized!- end-- it 'can create an order' do- api_post :create, order: { line_items: { '0' => { variant_id: variant.to_param, quantity: 5 } } }- expect(response.status).to eq(201)-- order = Order.last- expect(order.line_items.count).to eq(1)- expect(order.line_items.first.variant).to eq(variant)- expect(order.line_items.first.quantity).to eq(5)-- expect(json_response['number']).to be_present- expect(json_response['token']).not_to be_blank- expect(json_response['state']).to eq('cart')- expect(order.user).to eq(current_api_user)- expect(order.email).to eq(current_api_user.email)- expect(json_response['user_id']).to eq(current_api_user.id)- end-- it 'assigns email when creating a new order' do- api_post :create, order: { email: '[email protected]' }- expect(json_response['email']).not_to eq controller.current_api_user- expect(json_response['email']).to eq '[email protected]'- end-- it 'cannot arbitrarily set the line items price' do- api_post :create, order: {- line_items: { '0' => { price: 33.0, variant_id: variant.to_param, quantity: 5 } }- }-- expect(response.status).to eq 201- expect(Order.last.line_items.first.price.to_f).to eq(variant.price)- end-- context 'admin user imports order' do- before do- allow(current_api_user).to receive_messages has_spree_role?: true- allow(current_api_user).to receive_message_chain :spree_roles, pluck: ['admin']- end-- it 'is able to set any default unpermitted attribute' do- api_post :create, order: { number: 'WOW' }- expect(response.status).to eq 201- expect(json_response['number']).to eq 'WOW'- end- end-- it 'can create an order without any parameters' do- expect { api_post :create }.not_to raise_error- expect(response.status).to eq(201)- expect(json_response['state']).to eq('cart')- end-- context 'working with an order' do- let(:variant) { create(:variant) }- let!(:line_item) { Spree::Cart::AddItem.call(order: order, variant: variant).value }- let(:address_params) { { country_id: country.id } }- let(:billing_address) do- {- firstname: 'Tiago', lastname: 'Motta', address1: 'Av Paulista',- city: 'Sao Paulo', zipcode: '01310-300', phone: '12345678',- country_id: country.id- }- end- let(:shipping_address) do- {- firstname: 'Tiago', lastname: 'Motta', address1: 'Av Paulista',- city: 'Sao Paulo', zipcode: '01310-300', phone: '12345678',- country_id: country.id- }- end- let(:country) { create(:country, name: 'Brazil', iso_name: 'BRAZIL', iso: 'BR', iso3: 'BRA', numcode: 76) }-- before do- allow_any_instance_of(Order).to receive_messages user: current_api_user- order.next # Switch from cart to address- order.bill_address = nil- order.ship_address = nil- order.save- expect(order.state).to eq('address')- end-- def clean_address(address)- address.delete(:state)- address.delete(:country)- address- end-- context 'line_items hash not present in request' do- it 'responds successfully' do- api_put :update, id: order.to_param, order: {- email: '[email protected]'- }-- expect(response).to be_successful- end- end-- it 'updates quantities of existing line items' do- api_put :update, id: order.to_param, order: {- line_items: {- '0' => { id: line_item.id, quantity: 10 }- }- }-- expect(response.status).to eq(200)- expect(json_response['line_items'].count).to eq(1)- expect(json_response['line_items'].first['quantity']).to eq(10)- end-- it 'adds an extra line item' do- variant2 = create(:variant)- api_put :update, id: order.to_param, order: {- line_items: {- '0' => { id: line_item.id, quantity: 10 },- '1' => { variant_id: variant2.id, quantity: 1 }- }- }-- expect(response.status).to eq(200)- expect(json_response['line_items'].count).to eq(2)- expect(json_response['line_items'][0]['quantity']).to eq(10)- expect(json_response['line_items'][1]['variant_id']).to eq(variant2.id)- expect(json_response['line_items'][1]['quantity']).to eq(1)- end-- it 'cannot change the price of an existing line item' do- api_put :update, id: order.to_param, order: {- line_items: {- 0 => { id: line_item.id, price: 0 }- }- }-- expect(response.status).to eq(200)- expect(json_response['line_items'].count).to eq(1)- expect(json_response['line_items'].first['price'].to_f).not_to eq(0)- expect(json_response['line_items'].first['price'].to_f).to eq(line_item.variant.price)- end-- it 'can add billing address' do- api_put :update, id: order.to_param, order: { bill_address_attributes: billing_address }-- expect(order.reload.bill_address).not_to be_nil- end-- it 'receives error message if trying to add billing address with errors' do- billing_address[:firstname] = ''-- api_put :update, id: order.to_param, order: { bill_address_attributes: billing_address }-- expect(json_response['error']).not_to be_nil- expect(json_response['errors']).not_to be_nil- expect(json_response['errors']['bill_address.firstname'].first).to eq "can't be blank"- end-- it 'can add shipping address' do- expect(order.ship_address).to be_nil-- api_put :update, id: order.to_param, order: { ship_address_attributes: shipping_address }-- expect(order.reload.ship_address).not_to be_nil- end-- it 'receives error message if trying to add shipping address with errors' do- expect(order.ship_address).to be_nil- shipping_address[:firstname] = ''-- api_put :update, id: order.to_param, order: { ship_address_attributes: shipping_address }-- expect(json_response['error']).not_to be_nil- expect(json_response['errors']).not_to be_nil- expect(json_response['errors']['ship_address.firstname'].first).to eq "can't be blank"- end-- it 'can set the user_id for the order' do- user = Spree.user_class.create- api_post :update, id: order.to_param, order: { user_id: user.id }- expect(response.status).to eq 200- expect(json_response['user_id']).to eq(user.id)- end-- context 'order has shipments' do- before { order.create_proposed_shipments }-- it 'clears out all existing shipments on line item udpate' do- api_put :update, id: order.to_param, order: {- line_items: {- 0 => { id: line_item.id, quantity: 10 }- }- }- expect(order.reload.shipments).to be_empty- end- end-- context 'with a line item' do- let(:order_with_line_items) do- order = create(:order_with_line_items)- create(:adjustment, order: order, adjustable: order)- order- end-- it 'can empty an order' do- expect(order_with_line_items.adjustments.count).to eq(1)- api_put :empty, id: order_with_line_items.to_param- expect(response.status).to eq(204)- order_with_line_items.reload- expect(order_with_line_items.line_items).to be_empty- expect(order_with_line_items.adjustments).to be_empty- end-- it 'can list its line items with images' do- create_image(order.line_items.first.variant, image('thinking-cat.jpg'))-- api_get :show, id: order.to_param-- expect(json_response['line_items'].first['variant']).to have_attributes([:images])- end-- it 'lists variants product id' do- api_get :show, id: order.to_param-- expect(json_response['line_items'].first['variant']).to have_attributes([:product_id])- end-- it 'includes the tax_total in the response' do- api_get :show, id: order.to_param-- expect(json_response['included_tax_total']).to eq('0.0')- expect(json_response['additional_tax_total']).to eq('0.0')- expect(json_response['display_included_tax_total']).to eq('$0.00')- expect(json_response['display_additional_tax_total']).to eq('$0.00')- end-- it 'lists line item adjustments' do- adjustment = create(:adjustment,- label: '10% off!',- order: order,- adjustable: order.line_items.first)- adjustment.update_column(:amount, 5)- api_get :show, id: order.to_param-- adjustment = json_response['line_items'].first['adjustments'].first- expect(adjustment['label']).to eq('10% off!')- expect(adjustment['amount']).to eq('5.0')- end-- it 'lists payments source without gateway info' do- order.payments.push payment = create(:payment)- api_get :show, id: order.to_param-- source = json_response[:payments].first[:source]- expect(source[:name]).to eq payment.source.name- expect(source[:cc_type]).to eq payment.source.cc_type- expect(source[:last_digits]).to eq payment.source.last_digits- expect(source[:month].to_i).to eq payment.source.month- expect(source[:year].to_i).to eq payment.source.year- expect(source.key?(:gateway_customer_profile_id)).to be false- expect(source.key?(:gateway_payment_profile_id)).to be false- end-- context 'when in delivery' do- let!(:shipping_method) do- FactoryBot.create(:shipping_method).tap do |shipping_method|- shipping_method.calculator.preferred_amount = 10- shipping_method.calculator.save- end- end-- before do- order.bill_address = FactoryBot.create(:address)- order.ship_address = FactoryBot.create(:address)- order.next!- order.save- end-- it 'includes the ship_total in the response' do- api_get :show, id: order.to_param-- expect(json_response['ship_total']).to eq '10.0'- expect(json_response['display_ship_total']).to eq '$10.00'- end-- it 'returns available shipments for an order' do- api_get :show, id: order.to_param- expect(response.status).to eq(200)- expect(json_response['shipments']).not_to be_empty- shipment = json_response['shipments'][0]- # Test for correct shipping method attributes- # Regression test for #3206- expect(shipment['shipping_methods']).not_to be_nil- json_shipping_method = shipment['shipping_methods'][0]- expect(json_shipping_method['id']).to eq(shipping_method.id)- expect(json_shipping_method['name']).to eq(shipping_method.name)- expect(json_shipping_method['code']).to eq(shipping_method.code)- expect(json_shipping_method['zones']).not_to be_empty- expect(json_shipping_method['shipping_categories']).not_to be_empty-- # Test for correct shipping rates attributes- # Regression test for #3206- expect(shipment['shipping_rates']).not_to be_nil- shipping_rate = shipment['shipping_rates'][0]- expect(shipping_rate['name']).to eq(json_shipping_method['name'])- expect(shipping_rate['cost']).to eq('10.0')- expect(shipping_rate['selected']).to be true- expect(shipping_rate['display_cost']).to eq('$10.00')- expect(shipping_rate['shipping_method_code']).to eq(json_shipping_method['code'])-- expect(shipment['stock_location_name']).not_to be_blank- manifest_item = shipment['manifest'][0]- expect(manifest_item['quantity']).to eq(1)- expect(manifest_item['variant_id']).to eq(order.line_items.first.variant_id)- end- end- end- end-- context 'as an admin' do- sign_in_as_admin!-- context 'with no orders' do- before { Spree::Order.delete_all }-- it 'still returns a root :orders key' do- api_get :index- expect(json_response['orders']).to eq([])- end- end-- it 'responds with orders updated_at with milliseconds precision' do- if ApplicationRecord.connection.adapter_name == 'Mysql2'- skip 'MySQL does not support millisecond timestamps.'- else- skip 'Probable need to make it call as_json. See https://github.com/rails/rails/commit/0f33d70e89991711ff8b3dde134a61f4a5a0ec06'- end-- api_get :index- millisecond = order.updated_at.strftime('%L')- updated_at = json_response['orders'].first['updated_at']- expect(updated_at.split('T').last).to have_content(millisecond)- end-- context 'caching enabled' do- before do- ActionController::Base.perform_caching = true- create_list(:order, 3)- end-- after { ActionController::Base.perform_caching = false }-- it 'returns unique orders' do- api_get :index-- orders = json_response[:orders]- expect(orders.count).to be >= 3- expect(orders.map { |o| o[:id] }).to match_array Order.pluck(:id)- end- end-- it 'lists payments source with gateway info' do- order.payments.push payment = create(:payment)- api_get :show, id: order.to_param-- source = json_response[:payments].first[:source]- expect(source[:name]).to eq payment.source.name- expect(source[:cc_type]).to eq payment.source.cc_type- expect(source[:last_digits]).to eq payment.source.last_digits- expect(source[:month].to_i).to eq payment.source.month- expect(source[:year].to_i).to eq payment.source.year- expect(source[:gateway_customer_profile_id]).to eq payment.source.gateway_customer_profile_id- expect(source[:gateway_payment_profile_id]).to eq payment.source.gateway_payment_profile_id- end-- context 'with two orders' do- before { create(:order) }-- it 'can view all orders' do- api_get :index- expect(json_response['orders'].first).to have_attributes(attributes)- expect(json_response['count']).to eq(2)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- end-- # Test for #1763- it 'can control the page size through a parameter' do- api_get :index, per_page: 1- expect(json_response['orders'].count).to eq(1)- expect(json_response['orders'].first).to have_attributes(attributes)- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end- end-- context 'search' do- before do- create(:order)- Spree::Order.last.update_attribute(:email, '[email protected]')- end-- let(:expected_result) { Spree::Order.last }-- it 'can query the results through a parameter' do- api_get :index, q: { email_cont: 'spree' }- expect(json_response['orders'].count).to eq(1)- expect(json_response['orders'].first).to have_attributes(attributes)- expect(json_response['orders'].first['email']).to eq(expected_result.email)- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- end- end-- context 'creation' do- it 'can create an order without any parameters' do- expect { api_post :create }.not_to raise_error- expect(response.status).to eq(201)- expect(json_response['state']).to eq('cart')- end-- it 'can arbitrarily set the line items price' do- api_post :create, order: {- line_items: [{ price: 33.0, variant_id: variant.to_param, quantity: 5 }]- }- expect(response.status).to eq 201- expect(Order.last.line_items.first.price.to_f).to eq(33.0)- end-- it 'can set the user_id for the order' do- user = Spree.user_class.create- api_post :create, order: { user_id: user.id }- expect(response.status).to eq 201- expect(json_response['user_id']).to eq(user.id)- end- end-- context 'updating' do- it 'can set the user_id for the order' do- user = Spree.user_class.create- api_post :update, id: order.number, order: { user_id: user.id }- expect(response.status).to eq 200- expect(json_response['user_id']).to eq(user.id)- end- end-- context 'can cancel an order' do- before do- order.completed_at = Time.current- order.state = 'complete'- order.shipment_state = 'ready'- order.save!- end-- specify do- api_put :cancel, id: order.to_param- expect(json_response['state']).to eq('canceled')- expect(json_response['canceler_id']).to eq(current_api_user.id)- end- end-- context 'can approve an order' do- before do- order.completed_at = Time.current- order.state = 'complete'- order.shipment_state = 'ready'- order.considered_risky = true- order.save!- end-- specify do- api_put :approve, id: order.to_param- order.reload- expect(order.approver_id).to eq(current_api_user.id)- expect(order.considered_risky).to eq(false)- end- end- end-- describe '#apply_coupon_code' do- subject(:apply_coupon_code) do- api_put :apply_coupon_code, id: order.number,- order_token: order.token,- coupon_code: coupon_code- end-- let(:order) { create(:order_with_line_items, user: current_api_user) }- let(:coupon_code) { 'coupon_code' }-- context 'when coupon is not found' do- it 'returns coupon not found response' do- apply_coupon_code-- expect(response.status).to eq 422- expect(json_response[:successful]).to eq false- expect(json_response[:status_code]).to eq 'coupon_code_not_found'- expect(json_response[:error]).to eq "The coupon code you entered doesn't exist. Please try again."- expect(json_response[:success]).to be_nil- end-- it 'does not apply any promotion to order' do- apply_coupon_code-- expect(order.promotions).to be_empty- end- end-- context 'when coupon is found' do- let!(:promotion) { create(:promotion_with_one_use_per_user_rule, code: coupon_code) }-- context 'when coupon is applied' do- it 'returns coupon applied response' do- apply_coupon_code-- expect(response.status).to eq 200- expect(json_response[:successful]).to eq true- expect(json_response[:status_code]).to eq 'coupon_code_applied'- expect(json_response[:success]).to eq 'The coupon code was successfully applied to your order.'- expect(json_response[:error]).to be_nil- end-- it 'applies specified promotion to order' do- expect(order.promotions).to be_empty-- apply_coupon_code-- expect(order.promotions.count).to eq 1- expect(order.promotions.first.code).to eq coupon_code- end- end-- context 'when coupon can not be applied' do- let!(:order_with_line_item_promotion) do- create(:order_with_line_items, coupon_code: coupon_code, user: current_api_user).tap do |order|- Spree::PromotionHandler::Coupon.new(order).apply- order.update_column(:completed_at, Time.current)- order.update_column(:state, 'complete')- end- end-- context 'when coupon was used by user already' do- it 'returns coupon was used already' do- apply_coupon_code-- expect(response.status).to eq 422- expect(json_response[:successful]).to eq false- expect(json_response[:status_code]).to be_nil- expect(json_response[:error]).to eq 'This coupon code can only be used once per user.'- expect(json_response[:success]).to be_nil- end- end- end- end- end-- context 'PUT remove_coupon_code' do- let(:order) { create(:order_with_line_items) }-- it 'returns 404 status if promotion does not exist' do- api_put :remove_coupon_code, id: order.number,- order_token: order.token,- coupon_code: 'example'-- expect(response.status).to eq 404- end-- context 'order with discount promotion' do- let!(:discount_promo_code) { 'discount' }- let!(:discount_promotion) { create(:promotion_with_order_adjustment, code: discount_promo_code) }- let(:order_with_discount_promotion) do- create(:order_with_line_items, coupon_code: discount_promo_code).tap do |order|- Spree::PromotionHandler::Coupon.new(order).apply- end- end-- it 'removes all order adjustments from order and return status 200' do- expect(order_with_discount_promotion.reload.total.to_f).to eq 100.0-- api_put :remove_coupon_code, id: order_with_discount_promotion.number,- order_token: order_with_discount_promotion.token,- coupon_code: order_with_discount_promotion.coupon_code-- expect(response.status).to eq 200- expect(json_response['success']).to eq Spree.t('adjustments_deleted')- expect(order_with_discount_promotion.reload.total.to_f).to eq 110.0- end- end-- context 'order with line item discount promotion' do- let!(:line_item_promo_code) { 'line_item_discount' }- let!(:line_item_promotion) { create(:promotion_with_item_adjustment, code: line_item_promo_code) }- let(:order_with_line_item_promotion) do- create(:order_with_line_items, coupon_code: line_item_promo_code).tap do |order|- Spree::PromotionHandler::Coupon.new(order).apply- end- end-- it 'removes line item adjustments from order and return status 200' do- expect(order_with_line_item_promotion.reload.total.to_f).to eq 100.0-- api_put :remove_coupon_code, id: order_with_line_item_promotion.number,- order_token: order_with_line_item_promotion.token,- coupon_code: order_with_line_item_promotion.coupon_code-- expect(response.status).to eq 200- expect(json_response['success']).to eq Spree.t('adjustments_deleted')- expect(order_with_line_item_promotion.reload.total.to_f).to eq 110.0- end-- it 'removes line item adjustments only for promotable line item' do- order_with_line_item_promotion.line_items << create(:line_item, price: 100)- order_with_line_item_promotion.update_with_updater!-- expect(order_with_line_item_promotion.reload.total.to_f).to eq 200.0-- api_put :remove_coupon_code, id: order_with_line_item_promotion.number,- order_token: order_with_line_item_promotion.token,- coupon_code: order_with_line_item_promotion.coupon_code-- expect(order_with_line_item_promotion.reload.total.to_f).to eq 210.0- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb b/api/spec/controllers/spree/api/v1/payments_controller_spec.rbdeleted file mode 100644index 4e9d576326..0000000000--- a/api/spec/controllers/spree/api/v1/payments_controller_spec.rb+++ /dev/null@@ -1,237 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::PaymentsController, type: :controller do- render_views- let(:store) { Spree::Store.default }- let!(:order) { create(:order, store: store) }- let!(:payment) { create(:payment, order: order) }- let!(:attributes) do- [:id, :source_type, :source_id, :amount, :display_amount,- :payment_method_id, :state, :avs_response,- :created_at, :updated_at, :number]- end-- let(:resource_scoping) { { order_id: order.to_param } }-- before do- stub_authentication!- end-- context 'as a user' do- context 'when the order belongs to the user' do- before do- allow_any_instance_of(Order).to receive_messages user: current_api_user- end-- it 'can view the payments for their order' do- api_get :index- expect(json_response['payments'].first).to have_attributes(attributes)- end-- it 'can learn how to create a new payment' do- api_get :new- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- expect(json_response['payment_methods']).not_to be_empty- expect(json_response['payment_methods'].first).to have_attributes([:id, :name, :description])- end-- it 'can create a new payment' do- allow_any_instance_of(Spree::PaymentMethod).to receive(:source_required?).and_return(false)- api_post :create, payment: { payment_method_id: PaymentMethod.first.id, amount: 50 }- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- end-- it "can view a pre-existing payment's details" do- api_get :show, id: payment.to_param- expect(json_response).to have_attributes(attributes)- end-- it 'cannot update a payment' do- api_put :update, id: payment.to_param, payment: { amount: 2.01 }- assert_unauthorized!- end-- it 'cannot authorize a payment' do- api_put :authorize, id: payment.to_param- assert_unauthorized!- end- end-- context 'when the order does not belong to the user' do- before do- allow_any_instance_of(Order).to receive_messages user: stub_model(LegacyUser)- end-- it "cannot view payments for somebody else's order" do- api_get :index, order_id: order.to_param- assert_unauthorized!- end-- it 'can view the payments for an order given the order token' do- api_get :index, order_id: order.to_param, order_token: order.token- expect(json_response['payments'].first).to have_attributes(attributes)- end- end- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can view the payments on any order' do- api_get :index- expect(response.status).to eq(200)- expect(json_response['payments'].first).to have_attributes(attributes)- end-- context 'multiple payments' do- before { @payment = create(:payment, order: order) }-- it 'can view all payments on an order' do- api_get :index- expect(json_response['count']).to eq(2)- end-- it 'can control the page size through a parameter' do- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end- end-- context 'for a given payment' do- context 'updating' do- context 'when the state is checkout' do- it 'can update' do- payment.update(state: 'checkout')- api_put(:update, id: payment.to_param, payment: { amount: 2.01 })- expect(response.status).to eq(200)- expect(payment.reload.amount).to eq(2.01)- end- end-- context 'when the state is pending' do- it 'can update' do- payment.update(state: 'pending')- api_put(:update, id: payment.to_param, payment: { amount: 2.01 })- expect(response.status).to be(200)- expect(payment.reload.amount).to eq(2.01)- end- end-- context 'update fails' do- it 'returns a 422 status when the amount is invalid' do- payment.update(state: 'pending')- api_put(:update, id: payment.to_param, payment: { amount: 'invalid' })- expect(response.status).to be(422)- expect(json_response['error']).to eql('Invalid resource. Please fix errors and try again.')- end-- it 'returns a 403 status when the payment is not pending' do- payment.update(state: 'completed')- api_put(:update, id: payment.to_param, payment: { amount: 2.01 })- expect(response.status).to be(403)- expect(json_response['error']).to eql('This payment cannot be updated because it is completed.')- end- end- end-- context 'authorizing' do- it 'can authorize' do- api_put :authorize, id: payment.to_param- expect(response.status).to eq(200)- expect(payment.reload.state).to eq('pending')- end-- context 'authorization fails' do- before do- fake_response = double(success?: false, to_s: 'Could not authorize card')- expect_any_instance_of(Spree::Gateway::Bogus).to receive(:authorize).and_return(fake_response)- api_put :authorize, id: payment.to_param- end-- it 'returns a 422 status' do- expect(response.status).to eq(422)- expect(json_response['error']).to eq 'Invalid resource. Please fix errors and try again.'- expect(json_response['errors']['base'][0]).to eq 'Could not authorize card'- end-- it 'does not raise a stack level error' do- skip "Investigate why a payment.reload after the request raises 'stack level too deep'"- expect(payment.reload.state).to eq('failed')- end- end- end-- context 'capturing' do- it 'can capture' do- api_put :capture, id: payment.to_param- expect(response.status).to eq(200)- expect(payment.reload.state).to eq('completed')- end-- context 'capturing fails' do- before do- fake_response = double(success?: false, to_s: 'Insufficient funds')- expect_any_instance_of(Spree::Gateway::Bogus).to receive(:capture).and_return(fake_response)- end-- it 'returns a 422 status' do- api_put :capture, id: payment.to_param- expect(response.status).to eq(422)- expect(json_response['error']).to eq 'Invalid resource. Please fix errors and try again.'- expect(json_response['errors']['base'][0]).to eq 'Insufficient funds'- end- end- end-- context 'purchasing' do- it 'can purchase' do- api_put :purchase, id: payment.to_param- expect(response.status).to eq(200)- expect(payment.reload.state).to eq('completed')- end-- context 'purchasing fails' do- before do- fake_response = double(success?: false, to_s: 'Insufficient funds')- expect_any_instance_of(Spree::Gateway::Bogus).to receive(:purchase).and_return(fake_response)- end-- it 'returns a 422 status' do- api_put :purchase, id: payment.to_param- expect(response.status).to eq(422)- expect(json_response['error']).to eq 'Invalid resource. Please fix errors and try again.'- expect(json_response['errors']['base'][0]).to eq 'Insufficient funds'- end- end- end-- context 'voiding' do- it 'can void' do- api_put :void, id: payment.to_param- expect(response.status).to eq 200- expect(payment.reload.state).to eq 'void'- end-- context 'voiding fails' do- before do- fake_response = double(success?: false, to_s: 'NO REFUNDS')- expect_any_instance_of(Spree::Gateway::Bogus).to receive(:void).and_return(fake_response)- end-- it 'returns a 422 status' do- api_put :void, id: payment.to_param- expect(response.status).to eq 422- expect(json_response['error']).to eq 'Invalid resource. Please fix errors and try again.'- expect(json_response['errors']['base'][0]).to eq 'NO REFUNDS'- expect(payment.reload.state).to eq 'checkout'- end- end- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rbdeleted file mode 100644index 355daf79d1..0000000000--- a/api/spec/controllers/spree/api/v1/product_properties_controller_spec.rb+++ /dev/null@@ -1,156 +0,0 @@-require 'spec_helper'-require 'shared_examples/protect_product_actions'--module Spree- describe Api::V1::ProductPropertiesController, type: :controller do- render_views-- let!(:product) { create(:product, stores: Spree::Store.all) }- let!(:property_1) { product.product_properties.create(property_name: 'My Property 1', value: 'my value 1', position: 0) }-- let(:attributes) { [:id, :product_id, :property_id, :value, :property_name] }- let(:resource_scoping) { { product_id: product.to_param } }-- before do- product.product_properties.create(property_name: 'My Property 2', value: 'my value 2', position: 1) # property_2- stub_authentication!- end-- context 'if product is deleted' do- before do- product.update_column(:deleted_at, 1.day.ago)- end-- it 'can not see a list of product properties' do- api_get :index- expect(response.status).to eq(404)- end- end-- it 'can see a list of all product properties' do- api_get :index- expect(json_response['product_properties'].count).to eq 2- expect(json_response['product_properties'].first).to have_attributes(attributes)- end-- it 'can control the page size through a parameter' do- api_get :index, per_page: 1- expect(json_response['product_properties'].count).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- Spree::ProductProperty.last.update_attribute(:value, 'loose')- property = Spree::ProductProperty.last- api_get :index, q: { value_cont: 'loose' }- expect(json_response['count']).to eq(1)- expect(json_response['product_properties'].first['value']).to eq property.value- end-- it 'can search for product properties' do- product.product_properties.create(property_name: 'Shirt Size')- product.product_properties.create(property_name: 'Shirt Weight')- api_get :index, q: { property_name_cont: 'size' }- expect(json_response['product_properties'].first['property_name']).to eq('Shirt Size')- expect(json_response['product_properties'].first).to have_attributes(attributes)- expect(json_response['count']).to eq(1)- end-- it 'can see a single product_property' do- api_get :show, id: property_1.property_name- expect(json_response).to have_attributes(attributes)- end-- it 'can learn how to create a new product property' do- api_get :new- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- expect(json_response['required_attributes']).to be_empty- end-- it 'cannot create a new product property if not an admin' do- api_post :create, product_property: { property_name: 'My Property 3' }- assert_unauthorized!- end-- it 'cannot update a product property' do- api_put :update, id: property_1.property_name, product_property: { value: 'my value 456' }- assert_unauthorized!- end-- it 'cannot delete a product property' do- api_delete :destroy, id: property_1.to_param, property_name: property_1.property_name- assert_unauthorized!- expect { property_1.reload }.not_to raise_error- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can create a new product property' do- expect do- api_post :create, product_property: { property_name: 'My Property 3', value: 'my value 3' }- end.to change(product.product_properties, :count).by(1)- expect(json_response).to have_attributes(attributes)- expect(response.status).to eq(201)- end-- context 'when product property does not exist' do- it 'cannot update product property and responds 404' do- api_put :update, id: 'does not exist', product_property: { value: 'new value' }- expect(response.status).to eq(404)- end- end-- context 'when product property exists' do- context 'when product property is valid' do- it 'responds 200' do- api_put :update, id: property_1.property_name, product_property: { value: 'my value 456' }- expect(response.status).to eq(200)- end- end-- context 'when product property is invalid' do- before do- expect_any_instance_of(Spree::ProductProperty).to receive(:update).and_return false- end-- it 'responds 422' do- api_put :update, id: property_1.property_name, product_property: { value: 'hello' }- expect(response.status).to eq(422)- end- end- end-- context 'when product property does not exist' do- it 'cannot delete product property and responds 404' do- api_delete :destroy, id: 'does not exist'- expect(response.status).to eq(404)- end- end-- context 'when product property exists' do- it 'can delete a product property' do- api_delete :destroy, id: property_1.property_name- expect(response.status).to eq(204)- expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)- end- end- end-- context 'with product identified by id' do- let(:resource_scoping) { { product_id: product.id } }-- it 'can see a list of all product properties' do- api_get :index- expect(json_response['product_properties'].count).to eq 2- expect(json_response['product_properties'].first).to have_attributes(attributes)- end-- it 'can see a single product_property by id' do- api_get :show, id: property_1.id- expect(json_response).to have_attributes(attributes)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/products_controller_spec.rb b/api/spec/controllers/spree/api/v1/products_controller_spec.rbdeleted file mode 100644index a55bdc9271..0000000000--- a/api/spec/controllers/spree/api/v1/products_controller_spec.rb+++ /dev/null@@ -1,507 +0,0 @@-require 'spec_helper'-require 'shared_examples/protect_product_actions'--module Spree- describe Api::V1::ProductsController, type: :controller do- render_views-- let(:store) { Spree::Store.default }-- let!(:product) { create(:product, stores: [store]) }- let!(:inactive_product) { create(:product, available_on: Time.current.tomorrow, name: 'inactive', stores: [store]) }- let(:base_attributes) { Api::ApiHelpers.product_attributes }- let(:show_attributes) { base_attributes.dup.push(:has_variants) }- let(:new_attributes) { base_attributes }-- let(:product_data) do- { name: 'The Other Product',- price: 19.99,- shipping_category_id: create(:shipping_category).id }- end- let(:attributes_for_variant) do- h = attributes_for(:variant).except(:option_values, :product)- h.merge(options: [- { name: 'size', value: 'small' },- { name: 'color', value: 'black' }- ])- end-- before do- stub_authentication!- end-- context 'as a normal user' do- context 'with caching enabled' do- before do- create(:product, stores: [store]) # product_2- ActionController::Base.perform_caching = true- end-- after do- ActionController::Base.perform_caching = false- end-- it 'returns unique products' do- api_get :index- product_ids = json_response['products'].map { |p| p['id'] }- expect(product_ids.uniq.count).to eq(product_ids.count)- end- end-- it 'retrieves a list of products' do- api_get :index- expect(json_response['products'].first).to have_attributes(show_attributes)- expect(json_response['total_count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- expect(json_response['per_page']).to eq(Kaminari.config.default_per_page)- end-- it 'retrieves a list of products by id' do- api_get :index, ids: [product.id]- expect(json_response['products'].first).to have_attributes(show_attributes)- expect(json_response['total_count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- expect(json_response['per_page']).to eq(Kaminari.config.default_per_page)- end-- context 'product has more than one price' do- before { product.master.prices.create currency: 'EUR', amount: 22 }-- it 'returns distinct products only' do- api_get :index- expect(assigns(:products).map(&:id).uniq).to eq assigns(:products).map(&:id)- end- end-- it 'retrieves a list of products by ids string' do- second_product = create(:product, stores: [store])- api_get :index, ids: [product.id, second_product.id].join(',')- expect(json_response['products'].first).to have_attributes(show_attributes)- expect(json_response['products'][1]).to have_attributes(show_attributes)- expect(json_response['total_count']).to eq(2)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- expect(json_response['per_page']).to eq(Kaminari.config.default_per_page)- end-- it 'does not return inactive products when queried by ids' do- api_get :index, ids: [inactive_product.id]- expect(json_response['count']).to eq(0)- end-- it 'does not list unavailable products' do- api_get :index- expect(json_response['products'].first['name']).not_to eq('inactive')- end-- context 'pagination' do- before { create(:product, stores: [store]) }-- it 'can select the next page of products' do- api_get :index, page: 2, per_page: 1- expect(json_response['products'].first).to have_attributes(show_attributes)- expect(json_response['total_count']).to eq(2)- expect(json_response['current_page']).to eq(2)- expect(json_response['pages']).to eq(2)- end-- it 'can control the page size through a parameter' do- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['total_count']).to eq(2)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end- end-- it 'can search for products' do- create(:product, name: 'The best product in the world', stores: [store])- api_get :index, q: { name_cont: 'best' }- expect(json_response['products'].first).to have_attributes(show_attributes)- expect(json_response['count']).to eq(1)- end-- # regression test for https://github.com/spree/spree/issues/8207- it 'can sort products by date' do- first_product = create(:product, created_at: Time.current - 1.month, stores: [store])- create(:product, created_at: Time.current, stores: [store]) # second_product- api_get :index, q: { s: 'created_at asc' }- expect(json_response['products'].first['id']).to eq(first_product.id)- end-- it 'gets a single product' do- create_image(product.master, image('thinking-cat.jpg'))- create(:variant, product: product)- create_image(product.variants.first, image('thinking-cat.jpg'))- product.set_property('spree', 'rocks')- product.taxons << create(:taxon)-- api_get :show, id: product.to_param-- expect(json_response).to have_attributes(show_attributes)- expect(json_response['variants'].first).to have_attributes([:name,- :is_master,- :price,- :images,- :in_stock])-- expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,- :attachment_width,- :attachment_height,- :attachment_content_type,- :mini_url,- :small_url,- :product_url,- :large_url])-- expect(json_response['product_properties'].first).to have_attributes([:value,- :product_id,- :property_name])-- expect(json_response['classifications'].first).to have_attributes([:taxon_id, :position, :taxon])- expect(json_response['classifications'].first['taxon']).to have_attributes([:id, :name, :pretty_name, :permalink, :taxonomy_id, :parent_id])- end-- context 'tracking is disabled' do- before { Config.track_inventory_levels = false }-- after { Config.track_inventory_levels = true }-- it 'still displays valid json with total_on_hand Float::INFINITY' do- api_get :show, id: product.to_param- expect(response).to be_ok- expect(json_response[:total_on_hand]).to eq nil- end- end-- context 'finds a product by slug first then by id' do- let!(:other_product) { create(:product, slug: 'these-are-not-the-droids-you-are-looking-for', stores:[store]) }-- before do- product.update_column(:slug, "#{other_product.id}-and-1-ways")- end-- specify do- api_get :show, id: product.to_param- expect(json_response['slug']).to match(/and-1-ways/)- product.destroy-- api_get :show, id: other_product.id- expect(json_response['slug']).to match(/droids/)- end- end-- it 'cannot see inactive products' do- api_get :show, id: inactive_product.to_param- assert_not_found!- end-- it 'returns a 404 error when it cannot find a product' do- api_get :show, id: 'non-existant'- assert_not_found!- end-- it 'can learn how to create a new product' do- api_get :new- expect(json_response['attributes']).to eq(new_attributes.map(&:to_s))- required_attributes = json_response['required_attributes']- expect(required_attributes).to include('name')- expect(required_attributes).to include('price')- expect(required_attributes).to include('shipping_category')- end-- it_behaves_like 'modifying product actions are restricted'- end-- context 'as an admin' do- let(:taxon_1) { create(:taxon) }- let(:taxon_2) { create(:taxon) }-- sign_in_as_admin!-- it 'can see all products' do- api_get :index- expect(json_response['products'].count).to eq(2)- expect(json_response['count']).to eq(2)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- end-- # Regression test for #1626- context 'deleted products' do- before do- create(:product, deleted_at: 1.day.ago, stores: [store])- end-- it 'does not include deleted products' do- api_get :index- expect(json_response['products'].count).to eq(2)- end-- it 'can include deleted products' do- api_get :index, show_deleted: 1- expect(json_response['products'].count).to eq(3)- end- end-- describe 'creating a product' do- it 'can create a new product' do- api_post :create, product: { name: 'The Other Product',- price: 19.99,- shipping_category_id: create(:shipping_category).id }- expect(json_response).to have_attributes(base_attributes)- expect(response.status).to eq(201)- end-- it 'creates with embedded variants' do- product_data[:variants] = [attributes_for_variant, attributes_for_variant]-- api_post :create, product: product_data- expect(response.status).to eq 201-- variants = json_response['variants']- expect(variants.count).to eq(2)- expect(variants.last['option_values'][0]['name']).to eq('small')- expect(variants.last['option_values'][0]['option_type_name']).to eq('size')-- expect(json_response['option_types'].count).to eq(2) # size, color- end-- it 'can create a new product with embedded product_properties' do- product_data[:product_properties_attributes] = [{- property_name: 'fabric',- value: 'cotton'- }]-- api_post :create, product: product_data-- expect(json_response['product_properties'][0]['property_name']).to eq('fabric')- expect(json_response['product_properties'][0]['value']).to eq('cotton')- end-- it 'can create a new product with option_types' do- product_data[:option_types] = ['size', 'color']-- api_post :create, product: product_data- expect(json_response['option_types'].count).to eq(2)- end-- it 'creates product with option_types ids' do- option_type = create(:option_type)- product_data[:option_type_ids] = [option_type.id]- api_post :create, product: product_data- expect(json_response['option_types'].first['id']).to eq option_type.id- end-- it 'creates with shipping categories' do- hash = { name: 'The Other Product',- price: 19.99,- shipping_category: 'Free Ships' }-- api_post :create, product: hash- expect(response.status).to eq 201-- shipping_id = ShippingCategory.find_by(name: 'Free Ships').id- expect(json_response['shipping_category_id']).to eq shipping_id- end-- it 'puts the created product in the given taxons' do- product_data[:taxon_ids] = [taxon_1.id, taxon_2.id]- api_post :create, product: product_data- expect(json_response['taxon_ids']).to eq([taxon_1.id, taxon_2.id])- end-- # Regression test for #2140- context 'with authentication_required set to false' do- before do- Spree::Api::Config.requires_authentication = false- end-- after do- Spree::Api::Config.requires_authentication = true- end-- it 'can still create a product' do- api_post :create, product: product_data, token: 'fake'- expect(json_response).to have_attributes(show_attributes)- expect(response.status).to eq(201)- end- end-- it 'cannot create a new product with invalid attributes' do- api_post :create, product: { foo: :bar }- expect(response.status).to eq(422)- expect(json_response['error']).to eq('Invalid resource. Please fix errors and try again.')- errors = json_response['errors']- errors.delete('slug') # Don't care about this one.- expect(errors.keys).to match_array(['name', 'price', 'shipping_category'])- end- end-- context 'updating a product' do- it 'can update a product' do- api_put :update, id: product.to_param, product: { name: 'New and Improved Product!' }- expect(response.status).to eq(200)- end-- it 'can create new option types on a product' do- api_put :update, id: product.to_param, product: { option_types: ['shape', 'color'] }- expect(json_response['option_types'].count).to eq(2)- end-- it 'can create new variants on a product' do- api_put :update, id: product.to_param, product: { variants: [attributes_for_variant, attributes_for_variant.merge(sku: "ABC-#{Kernel.rand(9999)}")] }- expect(response.status).to eq 200- expect(json_response['variants'].count).to eq(2) # 2 variants-- variants = json_response['variants'].reject { |v| v['is_master'] }- expect(variants.last['option_values'][0]['name']).to eq('small')- expect(variants.last['option_values'][0]['option_type_name']).to eq('size')-- expect(json_response['option_types'].count).to eq(2) # size, color- end-- it 'can update an existing variant on a product' do- variant_hash = {- sku: '123', price: 19.99, options: [{ name: 'size', value: 'small' }]- }- variant_id = product.variants.create!({ product: product }.merge(variant_hash)).id-- api_put :update, id: product.to_param, product: {- variants: [- variant_hash.merge(- id: variant_id.to_s,- sku: '456',- options: [{ name: 'size', value: 'large' }]- )- ]- }-- expect(json_response['variants'].count).to eq(1)- variants = json_response['variants'].reject { |v| v['is_master'] }- expect(variants.last['option_values'][0]['name']).to eq('large')- expect(variants.last['sku']).to eq('456')- expect(variants.count).to eq(1)- end-- it 'cannot update a product with an invalid attribute' do- api_put :update, id: product.to_param, product: { name: '' }- expect(response.status).to eq(422)- expect(json_response['error']).to eq('Invalid resource. Please fix errors and try again.')- expect(json_response['errors']['name']).to eq(["can't be blank"])- end-- it 'puts the updated product in the given taxons' do- api_put :update, id: product.to_param, product: { taxon_ids: [taxon_1.id, taxon_2.id] }- expect(json_response['taxon_ids'].to_set).to eql([taxon_1.id, taxon_2.id].to_set)- end- end-- it 'can delete a product' do- expect(product.deleted_at).to be_nil- api_delete :destroy, id: product.to_param- expect(response.status).to eq(204)- expect(product.reload.deleted_at).not_to be_nil- end- end-- describe '#find_product' do- let(:products) { Spree::Product.all }-- def send_request- api_get :show, id: product.id- end-- before { allow(controller).to receive(:product_scope).and_return(products) }-- context 'product found using friendly_id' do- before do- allow(products).to receive(:friendly).and_return(products)- allow(products).to receive(:find).with(product.id.to_s).and_return(product)- end-- describe 'expects to receive' do- after { send_request }-- it { expect(controller).to receive(:product_scope).and_return(products) }- it { expect(products).to receive(:friendly).and_return(products) }- it { expect(products).to receive(:find).with(product.id.to_s).and_return(product) }- end-- describe 'assigns' do- before { send_request }-- it { expect(assigns(:product)).to eq(product) }- end-- describe 'response' do- before { send_request }-- it { expect(response).to have_http_status(:ok) }- it { expect(json_response[:id]).to eq(product.id) }- it { expect(json_response[:name]).to eq(product.name) }- end- end-- context 'product not found using friendly_id, but found in normal scope using id' do- before do- allow(products).to receive(:friendly).and_return(products)- allow(products).to receive(:find).with(product.id.to_s).and_raise(ActiveRecord::RecordNotFound)- allow(products).to receive(:find_by).with(id: product.id.to_s).and_return(product)- end-- describe 'expects to receive' do- after { send_request }-- it { expect(controller).to receive(:product_scope).and_return(products) }- it { expect(products).to receive(:friendly).and_return(products) }- it { expect(products).to receive(:find_by).with(id: product.id.to_s).and_return(product) }- end-- describe 'assigns' do- before { send_request }-- it { expect(assigns(:product)).to eq(product) }- end-- describe 'response' do- before { send_request }-- it { expect(response).to have_http_status(:ok) }- it { expect(json_response[:id]).to eq(product.id) }- it { expect(json_response[:name]).to eq(product.name) }- end- end-- context 'product not found' do- before do- allow(products).to receive(:friendly).and_return(products)- allow(products).to receive(:find).with(product.id.to_s).and_raise(ActiveRecord::RecordNotFound)- allow(products).to receive(:find_by).with(id: product.id.to_s).and_return(nil)- end-- describe 'expects to receive' do- after { send_request }-- it { expect(controller).to receive(:product_scope).and_return(products) }- it { expect(products).to receive(:friendly).and_return(products) }- it { expect(products).to receive(:find_by).with(id: product.id.to_s).and_return(nil) }- end-- describe 'assigns' do- before { send_request }-- it { expect(assigns(:product)).to eq(nil) }- end-- describe 'response' do- before { send_request }-- it { assert_not_found! }- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/promotion_application_spec.rb b/api/spec/controllers/spree/api/v1/promotion_application_spec.rbdeleted file mode 100644index 9ee0681897..0000000000--- a/api/spec/controllers/spree/api/v1/promotion_application_spec.rb+++ /dev/null@@ -1,50 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::OrdersController, type: :controller do- render_views-- before do- stub_authentication!- end-- context 'with an available promotion' do- let!(:order) { create(:order_with_line_items, line_items_count: 1) }- let!(:promotion) do- promotion = create(:promotion, name: '10% off', code: '10off')- calculator = Spree::Calculator::FlatPercentItemTotal.create(preferred_flat_percent: '10')- action = Spree::Promotion::Actions::CreateItemAdjustments.create(calculator: calculator)- promotion.actions << action- promotion- end-- it 'can apply a coupon code to the order' do- expect(order.total).to eq(110.00)- api_put :apply_coupon_code, id: order.to_param, coupon_code: '10off', order_token: order.token- expect(response.status).to eq(200)- expect(order.reload.total).to eq(109.00)- expect(json_response['success']).to eq('The coupon code was successfully applied to your order.')- expect(json_response['error']).to be_blank- expect(json_response['successful']).to be true- expect(json_response['status_code']).to eq('coupon_code_applied')- end-- context 'with an expired promotion' do- before do- promotion.starts_at = 2.weeks.ago- promotion.expires_at = 1.week.ago- promotion.save- end-- it 'fails to apply' do- api_put :apply_coupon_code, id: order.to_param, coupon_code: '10off', order_token: order.token- expect(response.status).to eq(422)- expect(json_response['success']).to be_blank- expect(json_response['error']).to eq('The coupon code is expired')- expect(json_response['successful']).to be false- expect(json_response['status_code']).to eq('coupon_code_expired')- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/promotions_controller_spec.rb b/api/spec/controllers/spree/api/v1/promotions_controller_spec.rbdeleted file mode 100644index 40200951c8..0000000000--- a/api/spec/controllers/spree/api/v1/promotions_controller_spec.rb+++ /dev/null@@ -1,64 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::PromotionsController, type: :controller do- render_views-- shared_examples 'a JSON response' do- it 'is ok' do- expect(subject).to be_ok- end-- it 'returns JSON' do- payload = HashWithIndifferentAccess.new(JSON.parse(subject.body))- expect(payload).not_to be_nil- Spree::Api::ApiHelpers.promotion_attributes.each do |attribute|- expect(payload.key?(attribute)).to be true- end- end- end-- before do- stub_authentication!- end-- let(:promotion) { create :promotion, :with_order_adjustment, code: '10off' }-- describe 'GET #show' do- subject { api_get :show, id: id }-- context 'when admin' do- sign_in_as_admin!-- context 'when finding by id' do- let(:id) { promotion.id }-- it_behaves_like 'a JSON response'- end-- context 'when finding by code' do- let(:id) { promotion.code }-- it_behaves_like 'a JSON response'- end-- context 'when id does not exist' do- let(:id) { 'argh' }-- it 'is 404' do- expect(subject.status).to eq(404)- end- end- end-- context 'when non admin' do- let(:id) { promotion.id }-- it 'is unauthorized' do- subject- assert_unauthorized!- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/properties_controller_spec.rb b/api/spec/controllers/spree/api/v1/properties_controller_spec.rbdeleted file mode 100644index e1fe88d3e5..0000000000--- a/api/spec/controllers/spree/api/v1/properties_controller_spec.rb+++ /dev/null@@ -1,102 +0,0 @@-require 'spec_helper'-module Spree- describe Api::V1::PropertiesController, type: :controller do- render_views-- let!(:property_1) { Property.create!(name: 'foo', presentation: 'Foo') }- let!(:property_2) { Property.create!(name: 'bar', presentation: 'Bar') }-- let(:attributes) { [:id, :name, :presentation] }-- before do- stub_authentication!- end-- it 'can see a list of all properties' do- api_get :index- expect(json_response['properties'].count).to eq(2)- expect(json_response['properties'].first).to have_attributes(attributes)- end-- it 'can control the page size through a parameter' do- api_get :index, per_page: 1- expect(json_response['properties'].count).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- api_get :index, q: { name_cont: 'ba' }- expect(json_response['count']).to eq(1)- expect(json_response['properties'].first['presentation']).to eq property_2.presentation- end-- it 'retrieves a list of properties by id' do- api_get :index, ids: [property_1.id]- expect(json_response['properties'].first).to have_attributes(attributes)- expect(json_response['count']).to eq(1)- end-- it 'retrieves a list of properties by ids string' do- api_get :index, ids: [property_1.id, property_2.id].join(',')- expect(json_response['properties'].first).to have_attributes(attributes)- expect(json_response['properties'][1]).to have_attributes(attributes)- expect(json_response['count']).to eq(2)- end-- it 'can see a single property' do- api_get :show, id: property_1.id- expect(json_response).to have_attributes(attributes)- end-- it 'can see a property by name' do- api_get :show, id: property_1.name- expect(json_response).to have_attributes(attributes)- end-- it 'can learn how to create a new property' do- api_get :new- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- expect(json_response['required_attributes']).to be_empty- end-- it 'cannot create a new property if not an admin' do- api_post :create, property: { name: 'My Property 3' }- assert_unauthorized!- end-- it 'cannot update a property' do- api_put :update, id: property_1.name, property: { presentation: 'my value 456' }- assert_unauthorized!- end-- it 'cannot delete a property' do- api_delete :destroy, id: property_1.id- assert_unauthorized!- expect { property_1.reload }.not_to raise_error- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can create a new property' do- expect(Spree::Property.count).to eq(2)- api_post :create, property: { name: 'My Property 3', presentation: 'my value 3' }- expect(json_response).to have_attributes(attributes)- expect(response.status).to eq(201)- expect(Spree::Property.count).to eq(3)- end-- it 'can update a property' do- api_put :update, id: property_1.name, property: { presentation: 'my value 456' }- expect(response.status).to eq(200)- end-- it 'can delete a property' do- api_delete :destroy, id: property_1.name- expect(response.status).to eq(204)- expect { property_1.reload }.to raise_error(ActiveRecord::RecordNotFound)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/reimbursements_controller_spec.rb b/api/spec/controllers/spree/api/v1/reimbursements_controller_spec.rbdeleted file mode 100644index bfe733364e..0000000000--- a/api/spec/controllers/spree/api/v1/reimbursements_controller_spec.rb+++ /dev/null@@ -1,23 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::ReimbursementsController, type: :controller do- render_views-- before do- stub_authentication!- end-- describe '#index' do- before do- create(:reimbursement)- api_get :index- end-- it 'loads reimbursements' do- expect(response.status).to eq(200)- expect(json_response['count']).to eq(1)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb b/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rbdeleted file mode 100644index e7ac814c31..0000000000--- a/api/spec/controllers/spree/api/v1/return_authorizations_controller_spec.rb+++ /dev/null@@ -1,161 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::ReturnAuthorizationsController, type: :controller do- render_views-- let!(:order) { create(:shipped_order) }-- let(:product) { create(:product, stores: Spree::Store.all) }- let(:attributes) { [:id, :memo, :state] }- let(:resource_scoping) { { order_id: order.to_param } }-- before do- stub_authentication!- end-- context 'as the order owner' do- before do- allow_any_instance_of(Order).to receive_messages user: current_api_user- end-- it 'cannot see any return authorizations' do- api_get :index- assert_unauthorized!- end-- it 'cannot see a single return authorization' do- api_get :show, id: 1- assert_unauthorized!- end-- it 'cannot learn how to create a new return authorization' do- api_get :new- assert_unauthorized!- end-- it 'cannot create a new return authorization' do- api_post :create- assert_unauthorized!- end-- it 'cannot update a return authorization' do- api_put :update, id: 1- assert_not_found!- end-- it 'cannot delete a return authorization' do- api_delete :destroy, id: 1- assert_not_found!- end- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can show return authorization' do- FactoryBot.create(:return_authorization, order: order)- return_authorization = order.return_authorizations.first- api_get :show, order_id: order.number, id: return_authorization.id- expect(response.status).to eq(200)- expect(json_response).to have_attributes(attributes)- expect(json_response['state']).not_to be_blank- end-- it 'can get a list of return authorizations' do- FactoryBot.create(:return_authorization, order: order)- FactoryBot.create(:return_authorization, order: order)- api_get :index, order_id: order.number- expect(response.status).to eq(200)- return_authorizations = json_response['return_authorizations']- expect(return_authorizations.first).to have_attributes(attributes)- expect(return_authorizations.first).not_to eq(return_authorizations.last)- end-- it 'can control the page size through a parameter' do- FactoryBot.create(:return_authorization, order: order)- FactoryBot.create(:return_authorization, order: order)- api_get :index, order_id: order.number, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- FactoryBot.create(:return_authorization, order: order)- expected_result = create(:return_authorization, memo: 'damaged')- order.return_authorizations << expected_result- api_get :index, q: { memo_cont: 'damaged' }- expect(json_response['count']).to eq(1)- expect(json_response['return_authorizations'].first['memo']).to eq expected_result.memo- end-- it 'can learn how to create a new return authorization' do- api_get :new- expect(json_response['attributes']).to eq(['id', 'number', 'state', 'order_id', 'memo', 'created_at', 'updated_at'])- required_attributes = json_response['required_attributes']- expect(required_attributes).to include('order')- end-- it 'can update a return authorization on the order' do- FactoryBot.create(:return_authorization, order: order)- return_authorization = order.return_authorizations.first- api_put :update, id: return_authorization.id, return_authorization: { memo: 'ABC' }- expect(response.status).to eq(200)- expect(json_response).to have_attributes(attributes)- end-- it 'can cancel a return authorization on the order' do- FactoryBot.create(:new_return_authorization, order: order)- return_authorization = order.return_authorizations.first- expect(return_authorization.state).to eq('authorized')- api_delete :cancel, id: return_authorization.id- expect(response.status).to eq(200)- expect(return_authorization.reload.state).to eq('canceled')- end-- it 'can delete a return authorization on the order' do- FactoryBot.create(:return_authorization, order: order)- return_authorization = order.return_authorizations.first- api_delete :destroy, id: return_authorization.id- expect(response.status).to eq(204)- expect { return_authorization.reload }.to raise_error(ActiveRecord::RecordNotFound)- end-- it 'can add a new return authorization to an existing order' do- stock_location = FactoryBot.create(:stock_location)- reason = FactoryBot.create(:return_authorization_reason)- rma_params = { stock_location_id: stock_location.id,- return_authorization_reason_id: reason.id,- memo: 'Defective' }- api_post :create, order_id: order.number, return_authorization: rma_params- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- expect(json_response['state']).not_to be_blank- end- end-- context 'as just another user' do- it 'cannot add a return authorization to the order' do- api_post :create, return_autorization: { order_id: order.number, memo: 'Defective' }- assert_unauthorized!- end-- it 'cannot update a return authorization on the order' do- FactoryBot.create(:return_authorization, order: order)- return_authorization = order.return_authorizations.first- api_put :update, id: return_authorization.id, return_authorization: { memo: 'ABC' }- assert_unauthorized!- expect(return_authorization.reload.memo).not_to eq('ABC')- end-- it 'cannot delete a return authorization on the order' do- FactoryBot.create(:return_authorization, order: order)- return_authorization = order.return_authorizations.first- api_delete :destroy, id: return_authorization.id- assert_unauthorized!- expect { return_authorization.reload }.not_to raise_error- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb b/api/spec/controllers/spree/api/v1/shipments_controller_spec.rbdeleted file mode 100644index 5d291c4636..0000000000--- a/api/spec/controllers/spree/api/v1/shipments_controller_spec.rb+++ /dev/null@@ -1,229 +0,0 @@-require 'spec_helper'--describe Spree::Api::V1::ShipmentsController, type: :controller do- render_views- let!(:shipment) { create(:shipment) }- let!(:shipment2) { create(:shipment) }- let!(:attributes) { [:id, :tracking, :number, :cost, :shipped_at, :stock_location_name, :order_id, :shipping_rates, :shipping_methods] }- let(:resource_scoping) { { id: shipment.to_param, shipment: { order_id: shipment.order.to_param } } }-- before do- stub_authentication!- end-- context 'as a non-admin' do- it 'cannot make a shipment ready' do- api_put :ready- assert_not_found!- end-- it 'cannot make a shipment shipped' do- api_put :ship- assert_not_found!- end- end-- context 'as an admin' do- let!(:order) { shipment.order }- let!(:stock_location) { create(:stock_location_with_items) }- let!(:variant) { create(:variant) }-- sign_in_as_admin!-- # Start writing this spec a bit differently than before....- describe 'POST #create' do- subject do- api_post :create, params- end-- let(:params) do- {- variant_id: stock_location.stock_items.first.variant.to_param,- shipment: { order_id: order.number },- stock_location_id: stock_location.to_param- }- end-- [:variant_id, :stock_location_id].each do |field|- context "when #{field} is missing" do- before do- params.delete(field)- end-- it 'returns proper error' do- subject- expect(response.status).to eq(422)- expect(json_response['exception']).to eq("param is missing or the value is empty: #{field}")- end- end- end-- it 'creates a new shipment' do- expect(subject).to be_ok- expect(json_response).to have_attributes(attributes)- end- end-- describe 'POST #transfer_to_shipment' do- let(:shared_params) do- {- original_shipment_number: shipment.number,- variant_id: stock_location.stock_items.first.variant.to_param,- shipment: { order_id: order.number },- stock_location_id: stock_location.to_param- }- end-- context 'wrong quantity and shipment target' do- let!(:params) do- shared_params.merge(target_shipment_number: shipment.number, quantity: '-200')- end-- it 'displays wrong target and negative quantity errors' do- api_post :transfer_to_shipment, params- expect(json_response['exception']).to eq("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n#{Spree.t(:negative_quantity, scope: 'api')}, \n#{Spree.t(:wrong_shipment_target, scope: 'api')}")- end- end-- context 'wrong quantity' do- let!(:params) do- shared_params.merge(target_shipment_number: shipment2.number, quantity: '-200')- end-- it 'displays negative quantity error' do- api_post :transfer_to_shipment, params- expect(json_response['exception']).to eq("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n#{Spree.t(:negative_quantity, scope: 'api')}")- end- end-- context 'wrong shipment target' do- let!(:params) do- shared_params.merge(target_shipment_number: shipment.number, quantity: '200')- end-- it 'displays wrong target error' do- api_post :transfer_to_shipment, params- expect(json_response['exception']).to eq("#{Spree.t(:shipment_transfer_errors_occurred, scope: 'api')} \n#{Spree.t(:wrong_shipment_target, scope: 'api')}")- end- end- end-- context 'should update a shipment' do- let(:resource_scoping) { { id: shipment.to_param, shipment: { order_id: shipment.order.to_param, stock_location_id: stock_location.to_param } } }-- it 'can update a shipment' do- api_put :update- expect(response.status).to eq(200)- expect(json_response['stock_location_name']).to eq(stock_location.name)- end- end-- it 'can make a shipment ready' do- allow_any_instance_of(Spree::Order).to receive_messages(paid?: true, complete?: true)- api_put :ready- expect(json_response).to have_attributes(attributes)- expect(json_response['state']).to eq('ready')- expect(shipment.reload.state).to eq('ready')- end-- it 'cannot make a shipment ready if the order is unpaid' do- allow_any_instance_of(Spree::Order).to receive_messages(paid?: false)- api_put :ready- expect(json_response['error']).to eq('Cannot ready shipment.')- expect(response.status).to eq(422)- end-- context 'for completed shipments' do- let(:order) { create :completed_order_with_totals }- let(:resource_scoping) { { id: order.shipments.first.to_param, shipment: { order_id: order.to_param } } }-- it 'adds a variant to a shipment' do- api_put :add, variant_id: variant.to_param, quantity: 2- expect(response.status).to eq(200)- expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }['quantity']).to eq(2)- end-- it 'removes a variant from a shipment' do- Spree::Cart::AddItem.call(order: order, variant: variant, quantity: 2)-- api_put :remove, variant_id: variant.to_param, quantity: 1- expect(response.status).to eq(200)- expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }['quantity']).to eq(1)- end-- it 'removes a destroyed variant from a shipment' do- Spree::Cart::AddItem.call(order: order, variant: variant, quantity: 2)- variant.destroy-- api_put :remove, variant_id: variant.to_param, quantity: 1- expect(response.status).to eq(200)- expect(json_response['manifest'].detect { |h| h['variant']['id'] == variant.id }['quantity']).to eq(1)- end- end-- context 'can transition a shipment from ready to ship' do- before do- allow_any_instance_of(Spree::Order).to receive_messages(paid?: true, complete?: true)- shipment.update!(shipment.order)- expect(shipment.state).to eq('ready')- allow_any_instance_of(Spree::ShippingRate).to receive_messages(cost: 5)- end-- it 'can transition a shipment from ready to ship' do- shipment.reload- api_put :ship, id: shipment.to_param, shipment: { tracking: '123123', order_id: shipment.order.to_param }- expect(json_response).to have_attributes(attributes)- expect(json_response['state']).to eq('shipped')- end- end-- describe '#mine' do- subject do- api_get :mine, format: 'json', params: params- end-- let(:params) { {} }-- before { subject }-- context 'the current api user is authenticated and has orders' do- let(:current_api_user) { shipped_order.user }- let(:shipped_order) { create(:shipped_order) }-- it 'succeeds' do- expect(response.status).to eq 200- end-- describe 'json output' do- render_views-- let(:rendered_shipment_ids) { json_response['shipments'].map { |s| s['id'] } }-- it 'contains the shipments' do- expect(rendered_shipment_ids).to match_array current_api_user.orders.flat_map(&:shipments).map(&:id)- end- end-- context 'with filtering' do- let(:params) { { q: { order_completed_at_not_null: 1 } } }-- before do- create(:order, user: current_api_user) # incomplete_order- end-- it 'filters' do- expect(assigns(:shipments).map(&:id)).to match_array current_api_user.orders.complete.flat_map(&:shipments).map(&:id)- end- end- end-- context 'the current api user is not persisted' do- let(:current_api_user) { Spree.user_class.new }-- it 'returns a 401' do- expect(response.status).to eq(401)- end- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/states_controller_spec.rb b/api/spec/controllers/spree/api/v1/states_controller_spec.rbdeleted file mode 100644index df327752c2..0000000000--- a/api/spec/controllers/spree/api/v1/states_controller_spec.rb+++ /dev/null@@ -1,85 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::StatesController, type: :controller do- render_views-- let!(:state) { create(:state, name: 'Victoria') }- let(:attributes) { [:id, :name, :abbr, :country_id] }-- before do- stub_authentication!- end-- it 'gets all states' do- api_get :index- expect(json_response['states'].first).to have_attributes(attributes)- expect(json_response['states'].first['name']).to eq(state.name)- end-- it 'gets all the states for a particular country' do- api_get :index, country_id: state.country.id- expect(json_response['states'].first).to have_attributes(attributes)- expect(json_response['states'].first['name']).to eq(state.name)- end-- context 'pagination' do- let(:scope) { double('scope') }-- before do- expect(scope).to receive_messages(last: state)- expect(State).to receive_messages(accessible_by: scope)- expect(scope).to receive_messages(order: scope)- allow(scope).to receive_message_chain(:ransack, :result, :includes).and_return(scope)- end-- it 'does not paginate states results when asked not to do so' do- expect(scope).not_to receive(:page)- expect(scope).not_to receive(:per)- api_get :index- end-- it 'paginates when page parameter is passed through' do- expect(scope).to receive(:page).with('1').and_return(scope)- expect(scope).to receive(:per).with(nil).and_return(scope)- api_get :index, page: 1- end-- it 'paginates when per_page parameter is passed through' do- expect(scope).to receive(:page).with(nil).and_return(scope)- expect(scope).to receive(:per).with('25').and_return(scope)- api_get :index, per_page: 25- end- end-- context 'with two states' do- before { create(:state, name: 'New South Wales') }-- it 'gets all states for a country' do- country = create(:country, states_required: true)- state.country = country- state.save-- api_get :index, country_id: country.id- expect(json_response['states'].first).to have_attributes(attributes)- expect(json_response['states'].count).to eq(1)- json_response['states_required'] = true- end-- it 'can view all states' do- api_get :index- expect(json_response['states'].first).to have_attributes(attributes)- end-- it 'can query the results through a parameter' do- api_get :index, q: { name_cont: 'Vic' }- expect(json_response['states'].first['name']).to eq('Victoria')- end- end-- it 'can view a state' do- api_get :show, id: state.id- expect(json_response).to have_attributes(attributes)- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/stock_items_controller_spec.rb b/api/spec/controllers/spree/api/v1/stock_items_controller_spec.rbdeleted file mode 100644index 53e689e56e..0000000000--- a/api/spec/controllers/spree/api/v1/stock_items_controller_spec.rb+++ /dev/null@@ -1,164 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::StockItemsController, type: :controller do- render_views-- let!(:stock_location) { create(:stock_location_with_items) }- let!(:stock_item) { stock_location.stock_items.order(:id).first }- let!(:attributes) { [:id, :count_on_hand, :backorderable, :stock_location_id, :variant_id] }-- before do- stub_authentication!- stock_item.update(backorderable: true)- end-- context 'as a normal user' do- it 'cannot list stock items for a stock location' do- api_get :index, stock_location_id: stock_location.to_param- expect(response.status).to eq(404)- end-- it 'cannot see a stock item' do- api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param- expect(response.status).to eq(404)- end-- it 'cannot create a stock item' do- variant = create(:variant)- params = {- stock_location_id: stock_location.to_param,- stock_item: {- variant_id: variant.id,- count_on_hand: '20'- }- }-- api_post :create, params- expect(response.status).to eq(404)- end-- it 'cannot update a stock item' do- api_put :update, stock_location_id: stock_location.to_param,- id: stock_item.to_param- expect(response.status).to eq(404)- end-- it 'cannot destroy a stock item' do- api_delete :destroy, stock_location_id: stock_location.to_param,- id: stock_item.to_param- expect(response.status).to eq(404)- end- end-- context 'as an admin' do- sign_in_as_admin!-- it 'cannot list of stock items' do- api_get :index, stock_location_id: stock_location.to_param- expect(json_response['stock_items'].first).to have_attributes(attributes)- expect(json_response['stock_items'].first['variant']['sku']).to include 'SKU'- end-- it 'requires a stock_location_id to be passed as a parameter' do- api_get :index- expect(json_response['error']).to match(/stock_location_id parameter must be provided/)- expect(response.status).to eq(422)- end-- it 'can control the page size through a parameter' do- api_get :index, stock_location_id: stock_location.to_param, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- end-- it 'can query the results through a parameter (count_on_hand)' do- stock_item.update_column(:count_on_hand, 30)- api_get :index, stock_location_id: stock_location.to_param, q: { count_on_hand_eq: '30' }- expect(json_response['count']).to eq(1)- expect(json_response['stock_items'].first['count_on_hand']).to eq 30- end-- it 'can query the results through a parameter (variant_id)' do- api_get :index, stock_location_id: stock_location.to_param, q: { variant_id_eq: 999_999 }- expect(json_response['count']).to eq(0)- api_get :index, stock_location_id: stock_location.to_param, q: { variant_id_eq: stock_item.variant_id }- expect(json_response['count']).to eq(1)- expect(json_response['stock_items'].first['variant_id']).to eq stock_item.variant_id- end-- it 'gets a stock item' do- api_get :show, stock_location_id: stock_location.to_param, id: stock_item.to_param- expect(json_response).to have_attributes(attributes)- expect(json_response['count_on_hand']).to eq stock_item.count_on_hand- end-- it 'can create a new stock item' do- variant = create(:variant)- # Creating a variant also creates stock items.- # We don't want any to exist (as they would conflict with what we're about to create)- StockItem.delete_all- params = {- stock_location_id: stock_location.to_param,- stock_item: {- variant_id: variant.id,- count_on_hand: '20'- }- }-- api_post :create, params- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- end-- it 'can update a stock item to add new inventory' do- expect(stock_item.count_on_hand).to eq(10)- params = {- id: stock_item.to_param,- stock_item: {- count_on_hand: 40- }- }-- api_put :update, params- expect(response.status).to eq(200)- expect(json_response['count_on_hand']).to eq 50- end-- it 'can update a stock item to modify its backorderable field' do- params = {- id: stock_item.to_param,- stock_item: {- backorderable: false- }- }-- api_put :update, params- expect(response.status).to eq(200)- expect(json_response[:backorderable]).to eq(false)- end-- it 'can set a stock item to modify the current inventory' do- expect(stock_item.count_on_hand).to eq(10)-- params = {- id: stock_item.to_param,- stock_item: {- count_on_hand: 40,- force: true- }- }-- api_put :update, params- expect(response.status).to eq(200)- expect(json_response['count_on_hand']).to eq 40- end-- it 'can delete a stock item' do- api_delete :destroy, id: stock_item.to_param- expect(response.status).to eq(204)- expect { Spree::StockItem.find(stock_item.id) }.to raise_error(ActiveRecord::RecordNotFound)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb b/api/spec/controllers/spree/api/v1/stock_locations_controller_spec.rbdeleted file mode 100644index 59b9428711..0000000000--- a/api/spec/controllers/spree/api/v1/stock_locations_controller_spec.rb+++ /dev/null@@ -1,112 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::StockLocationsController, type: :controller do- render_views-- let!(:stock_location) { create(:stock_location) }- let!(:attributes) { [:id, :name, :address1, :address2, :city, :state_id, :state_name, :country_id, :zipcode, :phone, :active] }-- before do- stub_authentication!- end-- context 'as a user' do- it 'cannot see stock locations' do- api_get :index- expect(response.status).to eq(401)- end-- it 'cannot see a single stock location' do- api_get :show, id: stock_location.id- expect(response.status).to eq(404)- end-- it 'cannot create a new stock location' do- params = {- stock_location: {- name: 'North Pole',- active: true- }- }-- api_post :create, params- expect(response.status).to eq(401)- end-- it 'cannot update a stock location' do- api_put :update, stock_location: { name: 'South Pole' }, id: stock_location.to_param- expect(response.status).to eq(404)- end-- it 'cannot delete a stock location' do- api_put :destroy, id: stock_location.to_param- expect(response.status).to eq(404)- end- end-- context 'as an admin' do- sign_in_as_admin!-- it 'gets list of stock locations' do- api_get :index- expect(json_response['stock_locations'].first).to have_attributes(attributes)- expect(json_response['stock_locations'].first['country']).not_to be_nil- expect(json_response['stock_locations'].first['state']).not_to be_nil- end-- it 'can control the page size through a parameter' do- create(:stock_location)- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- expected_result = create(:stock_location, name: 'South America')- api_get :index, q: { name_cont: 'south' }- expect(json_response['count']).to eq(1)- expect(json_response['stock_locations'].first['name']).to eq expected_result.name- end-- it 'gets a stock location' do- api_get :show, id: stock_location.to_param- expect(json_response).to have_attributes(attributes)- expect(json_response['name']).to eq stock_location.name- end-- it 'can create a new stock location' do- params = {- stock_location: {- name: 'North Pole',- active: true- }- }-- api_post :create, params- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- end-- it 'can update a stock location' do- params = {- id: stock_location.to_param,- stock_location: {- name: 'South Pole'- }- }-- api_put :update, params- expect(response.status).to eq(200)- expect(json_response['name']).to eq 'South Pole'- end-- it 'can delete a stock location' do- api_delete :destroy, id: stock_location.to_param- expect(response.status).to eq(204)- expect { stock_location.reload }.to raise_error(ActiveRecord::RecordNotFound)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb b/api/spec/controllers/spree/api/v1/stock_movements_controller_spec.rbdeleted file mode 100644index c7651c0fe3..0000000000--- a/api/spec/controllers/spree/api/v1/stock_movements_controller_spec.rb+++ /dev/null@@ -1,83 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::StockMovementsController, type: :controller do- render_views-- let!(:stock_location) { create(:stock_location_with_items) }- let!(:stock_item) { stock_location.stock_items.order(:id).first }- let!(:stock_movement) { create(:stock_movement, stock_item: stock_item) }- let!(:attributes) { [:id, :quantity, :stock_item_id] }-- before do- stub_authentication!- end-- context 'as a user' do- it 'cannot see a list of stock movements' do- api_get :index, stock_location_id: stock_location.to_param- expect(response.status).to eq(404)- end-- it 'cannot see a stock movement' do- api_get :show, stock_location_id: stock_location.to_param, id: stock_movement.id- expect(response.status).to eq(404)- end-- it 'cannot create a stock movement' do- params = {- stock_location_id: stock_location.to_param,- stock_movement: {- stock_item_id: stock_item.to_param- }- }-- api_post :create, params- expect(response.status).to eq(404)- end- end-- context 'as an admin' do- sign_in_as_admin!-- it 'gets list of stock movements' do- api_get :index, stock_location_id: stock_location.to_param- expect(json_response['stock_movements'].first).to have_attributes(attributes)- expect(json_response['stock_movements'].first['stock_item']['count_on_hand']).to eq 11- end-- it 'can control the page size through a parameter' do- create(:stock_movement, stock_item: stock_item)- api_get :index, stock_location_id: stock_location.to_param, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- create(:stock_movement, :received, quantity: 10, stock_item: stock_item)- api_get :index, stock_location_id: stock_location.to_param, q: { quantity_eq: '10' }- expect(json_response['count']).to eq(1)- end-- it 'gets a stock movement' do- api_get :show, stock_location_id: stock_location.to_param, id: stock_movement.to_param- expect(json_response).to have_attributes(attributes)- expect(json_response['stock_item_id']).to eq stock_movement.stock_item_id- end-- it 'can create a new stock movement' do- params = {- stock_location_id: stock_location.to_param,- stock_movement: {- stock_item_id: stock_item.to_param- }- }-- api_post :create, params- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/stores_controller_spec.rb b/api/spec/controllers/spree/api/v1/stores_controller_spec.rbdeleted file mode 100644index e2b0e86bf3..0000000000--- a/api/spec/controllers/spree/api/v1/stores_controller_spec.rb+++ /dev/null@@ -1,159 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::StoresController, type: :controller do- render_views-- let!(:store) do- Spree::Store.default.update!(name: 'My Spree Store', url: 'spreestore.example.com')- Spree::Store.default- end-- before do- stub_authentication!- end-- context 'as an admin' do- sign_in_as_admin!-- let!(:non_default_store) do- create(:store,- name: 'Extra Store',- url: 'spreestore-5.example.com',- default: false)- end-- it 'I can list the available stores' do- api_get :index- expect(json_response['stores']).to eq(- [- {- 'id' => store.id,- 'name' => 'My Spree Store',- 'url' => 'spreestore.example.com',- 'meta_description' => nil,- 'meta_keywords' => nil,- 'seo_title' => nil,- 'mail_from_address' => '[email protected]',- 'customer_support_email' => '[email protected]',- 'default_currency' => 'USD',- 'supported_currencies' => 'USD,EUR,GBP',- 'default_locale' => 'en',- 'supported_locales' => 'en',- 'code' => store.code,- 'default' => true,- 'facebook' => 'spreecommerce',- 'twitter' => 'spreecommerce',- 'instagram' => 'spreecommerce'- },- {- 'id' => non_default_store.id,- 'name' => 'Extra Store',- 'url' => 'spreestore-5.example.com',- 'meta_description' => nil,- 'meta_keywords' => nil,- 'seo_title' => nil,- 'mail_from_address' => '[email protected]',- 'customer_support_email' => '[email protected]',- 'default_currency' => 'USD',- 'supported_currencies' => 'USD,EUR,GBP',- 'default_locale' => 'en',- 'supported_locales' => 'en',- 'code' => non_default_store.code,- 'default' => false,- 'facebook' => 'spreecommerce',- 'twitter' => 'spreecommerce',- 'instagram' => 'spreecommerce'- }- ]- )- end-- it 'I can get the store details' do- api_get :show, id: store.id- expect(json_response).to eq(- 'id' => store.id,- 'name' => 'My Spree Store',- 'url' => 'spreestore.example.com',- 'meta_description' => nil,- 'meta_keywords' => nil,- 'seo_title' => nil,- 'mail_from_address' => '[email protected]',- 'customer_support_email' => '[email protected]',- 'default_currency' => 'USD',- 'default_locale' => 'en',- 'supported_currencies' => 'USD,EUR,GBP',- 'supported_locales' => 'en',- 'code' => store.code,- 'default' => true,- 'facebook' => 'spreecommerce',- 'twitter' => 'spreecommerce',- 'instagram' => 'spreecommerce'- )- end-- it 'I can create a new store' do- store_hash = {- code: 'spree123',- name: 'Hack0rz',- url: 'spree123.example.com',- mail_from_address: '[email protected]',- default_currency: 'USD',- supported_currencies: 'USD'- }- api_post :create, store: store_hash- expect(response.status).to eq(201)- end-- it 'I can update an existing store' do- store_hash = {- url: 'spree123.example.com',- mail_from_address: '[email protected]',- customer_support_email: '[email protected]',- }- api_put :update, id: store.id, store: store_hash- expect(response.status).to eq(200)- expect(store.reload.url).to eql 'spree123.example.com'- expect(store.reload.mail_from_address).to eql '[email protected]'- expect(store.reload.customer_support_email).to eql '[email protected]'- end-- xcontext 'deleting a store' do- it "will fail if it's the default Store" do- api_delete :destroy, id: store.id- expect(response.status).to eq(422)- expect(json_response['errors']['base']).to eql(- ['Cannot destroy the default Store.']- )- end-- it 'will destroy the store' do- api_delete :destroy, id: non_default_store.id- expect(response.status).to eq(204)- end- end- end-- context 'as an user' do- it 'I can list all the stores' do- api_get :index- expect(response.status).to eq(200)- end-- it 'I can get the store details' do- api_get :show, id: store.id- expect(response.status).to eq(200)- end-- it 'I cannot create a new store' do- api_post :create, store: {}- expect(response.status).to eq(401)- end-- it 'I cannot update an existing store' do- api_put :update, id: store.id, store: {}- expect(response.status).to eq(401)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb b/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rbdeleted file mode 100644index b78bc71903..0000000000--- a/api/spec/controllers/spree/api/v1/taxonomies_controller_spec.rb+++ /dev/null@@ -1,113 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::TaxonomiesController, type: :controller do- render_views-- let(:taxonomy) { create(:taxonomy) }- let(:taxon) { create(:taxon, name: 'Ruby', taxonomy: taxonomy) }- let(:taxon2) { create(:taxon, name: 'Rails', taxonomy: taxonomy) }- let(:attributes) { [:id, :name] }-- before do- stub_authentication!- taxon2.children << create(:taxon, name: '3.2.2', taxonomy: taxonomy)- taxon.children << taxon2- taxonomy.root.children << taxon- end-- context 'as a normal user' do- it 'gets all taxonomies' do- api_get :index-- expect(json_response['taxonomies'].first['name']).to eq taxonomy.name- expect(json_response['taxonomies'].first['root']['taxons'].count).to eq 1- end-- it 'can control the page size through a parameter' do- create(:taxonomy)- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- expected_result = create(:taxonomy, name: 'Style')- api_get :index, q: { name_cont: 'style' }- expect(json_response['count']).to eq(1)- expect(json_response['taxonomies'].first['name']).to eq expected_result.name- end-- it 'gets a single taxonomy' do- api_get :show, id: taxonomy.id-- expect(json_response['name']).to eq taxonomy.name-- children = json_response['root']['taxons']- expect(children.count).to eq 1- expect(children.first['name']).to eq taxon.name- expect(children.first.key?('taxons')).to be false- end-- it 'gets a single taxonomy with set=nested' do- api_get :show, id: taxonomy.id, set: 'nested'-- expect(json_response['name']).to eq taxonomy.name-- children = json_response['root']['taxons']- expect(children.first.key?('taxons')).to be true- end-- it 'gets the jstree-friendly version of a taxonomy' do- api_get :jstree, id: taxonomy.id- expect(json_response['data']).to eq(taxonomy.root.name)- expect(json_response['attr']).to eq('id' => taxonomy.root.id, 'name' => taxonomy.root.name)- expect(json_response['state']).to eq('closed')- end-- it 'can learn how to create a new taxonomy' do- api_get :new- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- required_attributes = json_response['required_attributes']- expect(required_attributes).to include('name')- end-- it 'cannot create a new taxonomy if not an admin' do- api_post :create, taxonomy: { name: 'Location' }- assert_unauthorized!- end-- it 'cannot update a taxonomy' do- api_put :update, id: taxonomy.id, taxonomy: { name: 'I hacked your store!' }- assert_unauthorized!- end-- it 'cannot delete a taxonomy' do- api_delete :destroy, id: taxonomy.id- assert_unauthorized!- end- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can create' do- api_post :create, taxonomy: { name: 'Colors' }- expect(json_response).to have_attributes(attributes)- expect(response.status).to eq(201)- end-- it 'cannot create a new taxonomy with invalid attributes' do- api_post :create, taxonomy: {}- expect(response.status).to eq(422)- expect(json_response['error']).to eq('Invalid resource. Please fix errors and try again.')- end-- it 'can destroy' do- api_delete :destroy, id: taxonomy.id- expect(response.status).to eq(204)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb b/api/spec/controllers/spree/api/v1/taxons_controller_spec.rbdeleted file mode 100644index ca2605fc25..0000000000--- a/api/spec/controllers/spree/api/v1/taxons_controller_spec.rb+++ /dev/null@@ -1,197 +0,0 @@-require 'spec_helper'--def expect_single_taxon_result(taxon_name)- expect(json_response['taxons'].count).to eq(1)- expect(json_response['taxons'].first['name']).to eq(taxon_name)-end--module Spree- describe Api::V1::TaxonsController, type: :controller do- render_views-- let!(:taxonomy) { create(:taxonomy) }- let!(:taxon) { create(:taxon, name: 'Ruby', taxonomy: taxonomy, parent_id: taxonomy.root.id) }- let!(:rust_taxon) { create(:taxon, name: 'Rust', taxonomy: taxonomy, parent_id: taxonomy.root.id) }- let!(:taxon2) { create(:taxon, name: 'Rails', taxonomy: taxonomy, parent_id: taxon.id) }- let(:attributes) { ['id', 'name', 'pretty_name', 'permalink', 'parent_id', 'taxonomy_id', 'meta_title', 'meta_description'] }-- before do- create(:taxon, name: 'React', taxonomy: taxonomy, parent_id: taxon2.id) # taxon3- stub_authentication!- end-- context 'as a normal user' do- it 'gets all taxons for a taxonomy' do- api_get :index, taxonomy_id: taxonomy.id- expect(json_response['taxons'].first['name']).to eq taxon.name- children = json_response['taxons'].first['taxons']- expect(children.count).to eq 1- expect(children.first['name']).to eq taxon2.name- expect(children.first['taxons'].count).to eq 1- end-- # Regression test for #4112- it 'does not include children when asked not to' do- api_get :index, taxonomy_id: taxonomy.id, without_children: 1-- expect(json_response['taxons'].first['name']).to eq(taxon.name)- expect(json_response['taxons'].first['taxons']).to be_nil- end-- it 'paginates through taxons' do- new_taxon = create(:taxon, name: 'Go', taxonomy: taxonomy, parent_id: taxonomy.root.id)- taxonomy.root.children << new_taxon- expect(taxonomy.root.children.count).to eq(3)- api_get :index, taxonomy_id: taxonomy.id, page: 1, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['total_count']).to eq(3)- expect(json_response['current_page']).to eq(1)- expect(json_response['per_page']).to eq(1)- expect(json_response['pages']).to eq(3)- end-- describe 'searching' do- context 'within a taxonomy' do- before do- api_get :index, taxonomy_id: taxonomy.id, q: { name_cont: name }- end-- context 'searching for top level taxon' do- let(:name) { 'Ruby' }-- it 'returns the matching taxons' do- expect_single_taxon_result 'Ruby'- end- end- end-- context 'with a name' do- before do- api_get :index, q: { name_cont: name }- end-- context 'with one result' do- let(:name) { 'Ruby' }-- it 'returns an array including the matching taxon' do- expect_single_taxon_result 'Ruby'- end- end-- context 'with no results' do- let(:name) { 'Imaginary' }-- it 'returns an empty array of taxons' do- expect(json_response.keys).to include('taxons')- expect(json_response['taxons'].count).to eq(0)- end- end- end-- context 'with no filters' do- it 'gets all taxons' do- api_get :index-- expect(json_response['taxons'].first['name']).to eq taxonomy.root.name- children = json_response['taxons'].first['taxons']- expect(children.count).to eq 2- expect(children.first['name']).to eq taxon.name- expect(children.first['taxons'].count).to eq 1- expect(children.second['name']).to eq rust_taxon.name- expect(children.second['taxons'].count).to eq 0- end- end- end-- it 'gets a single taxon' do- api_get :show, id: taxon.id, taxonomy_id: taxonomy.id-- expect(json_response['name']).to eq taxon.name- expect(json_response['taxons'].count).to eq 1- end-- it 'gets all taxons in JSTree form' do- api_get :jstree, taxonomy_id: taxonomy.id, id: taxon.id- response = json_response.first- expect(response['data']).to eq(taxon2.name)- expect(response['attr']).to eq('name' => taxon2.name, 'id' => taxon2.id)- expect(response['state']).to eq('closed')- end-- it 'can learn how to create a new taxon' do- api_get :new, taxonomy_id: taxonomy.id- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- required_attributes = json_response['required_attributes']- expect(required_attributes).to include('name')- end-- it 'cannot create a new taxon if not an admin' do- api_post :create, taxonomy_id: taxonomy.id, taxon: { name: 'Location' }- assert_unauthorized!- end-- it 'cannot update a taxon' do- api_put :update, taxonomy_id: taxonomy.id, id: taxon.id, taxon: { name: 'I hacked your store!' }- assert_unauthorized!- end-- it 'cannot delete a taxon' do- api_delete :destroy, taxonomy_id: taxonomy.id, id: taxon.id- assert_unauthorized!- end- end-- context 'as an admin' do- sign_in_as_admin!-- it 'can create' do- api_post :create, taxonomy_id: taxonomy.id, taxon: { name: 'Colors' }- expect(json_response).to have_attributes(attributes)- expect(response.status).to eq(201)-- expect(taxonomy.reload.root.children.count).to eq 3- taxon = Spree::Taxon.where(name: 'Colors').first-- expect(taxon.parent_id).to eq taxonomy.root.id- expect(taxon.taxonomy_id).to eq taxonomy.id- end-- it 'can update the position in the list' do- taxonomy.root.children << taxon2- api_put :update, taxonomy_id: taxonomy.id, id: taxon.id, taxon: { parent_id: taxon.parent_id, child_index: 2 }- expect(response.status).to eq(200)- expect(taxonomy.reload.root.children[0]).to eql rust_taxon- expect(taxonomy.reload.root.children[1]).to eql taxon2- end-- it 'cannot create a new taxon with invalid attributes' do- api_post :create, taxonomy_id: taxonomy.id, taxon: { foo: :bar }- expect(response.status).to eq(422)- expect(json_response['error']).to eq('Invalid resource. Please fix errors and try again.')- expect(taxonomy.reload.root.children.count).to eq 2- end-- it 'cannot create another root taxon' do- api_post :create, taxonomy_id: taxonomy.id, taxon: { name: 'foo', parent_id: nil }- expect(json_response[:errors][:root_conflict].first).to eq 'this taxonomy already has a root taxon'- end-- it 'cannot create a new taxon with invalid taxonomy_id' do- api_post :create, taxonomy_id: 1000, taxon: { name: 'Colors' }- expect(response.status).to eq(422)- expect(json_response['error']).to eq('Invalid resource. Please fix errors and try again.')-- errors = json_response['errors']- expect(errors['taxonomy_id']).not_to be_nil- expect(errors['taxonomy_id'].first).to eq 'Invalid taxonomy id.'-- expect(taxonomy.reload.root.children.count).to eq 2- end-- it 'can destroy' do- api_delete :destroy, taxonomy_id: taxonomy.id, id: taxon.id- expect(response.status).to eq(204)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb b/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rbdeleted file mode 100644index 1b673ca713..0000000000--- a/api/spec/controllers/spree/api/v1/unauthenticated_products_controller_spec.rb+++ /dev/null@@ -1,25 +0,0 @@-require 'shared_examples/protect_product_actions'-require 'spec_helper'--module Spree- describe Api::V1::ProductsController, type: :controller do- render_views-- let!(:product) { create(:product, stores: Spree::Store.all) }- let(:attributes) { [:id, :name, :description, :price, :available_on, :slug, :meta_description, :meta_keywords, :taxon_ids] }-- context 'without authentication' do- before { Spree::Api::Config[:requires_authentication] = false }-- it 'retrieves a list of products' do- api_get :index- expect(json_response['products'].first).to have_attributes(attributes)- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- end-- it_behaves_like 'modifying product actions are restricted'- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/users_controller_spec.rb b/api/spec/controllers/spree/api/v1/users_controller_spec.rbdeleted file mode 100644index cc8af5ccf3..0000000000--- a/api/spec/controllers/spree/api/v1/users_controller_spec.rb+++ /dev/null@@ -1,231 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::UsersController, type: :controller do- render_views-- let(:user) { create(:user, spree_api_key: rand.to_s) }- let(:stranger) { create(:user, email: '[email protected]') }- let(:attributes) { [:id, :email, :created_at, :updated_at] }-- context 'as a normal user' do- it 'can get own details' do- api_get :show, id: user.id, token: user.spree_api_key-- expect(json_response['email']).to eq user.email- end-- it 'cannot get other users details' do- api_get :show, id: stranger.id, token: user.spree_api_key-- assert_not_found!- end-- it 'can learn how to create a new user' do- api_get :new, token: user.spree_api_key- expect(json_response['attributes']).to eq(attributes.map(&:to_s))- end-- it 'can create a new user' do- user_params = {- email: '[email protected]', password: 'spree123', password_confirmation: 'spree123'- }-- api_post :create, user: user_params, token: user.spree_api_key- expect(json_response['email']).to eq '[email protected]'- end-- # there's no validations on LegacyUser?- xit 'cannot create a new user with invalid attributes' do- api_post :create, user: {}, token: user.spree_api_key- expect(response.status).to eq(422)- expect(json_response['error']).to eq('Invalid resource. Please fix errors and try again.')- end-- it 'can update own details' do- country = create(:country)- api_put :update, id: user.id, token: user.spree_api_key, user: {- email: '[email protected]',- bill_address_attributes: {- first_name: 'First',- last_name: 'Last',- address1: '1 Test Rd',- city: 'City',- country_id: country.id,- state_id: 1,- zipcode: '55555',- phone: '5555555555'- },- ship_address_attributes: {- first_name: 'First',- last_name: 'Last',- address1: '1 Test Rd',- city: 'City',- country_id: country.id,- state_id: 1,- zipcode: '55555',- phone: '5555555555'- }- }- expect(json_response['email']).to eq '[email protected]'- expect(json_response['bill_address']).not_to be_nil- expect(json_response['ship_address']).not_to be_nil- end-- it 'cannot update other users details' do- api_put :update, id: stranger.id, token: user.spree_api_key, user: { email: '[email protected]' }- assert_not_found!- end-- it 'can delete itself' do- api_delete :destroy, id: user.id, token: user.spree_api_key- expect(response.status).to eq(204)- end-- it 'cannot delete other user' do- api_delete :destroy, id: stranger.id, token: user.spree_api_key- assert_not_found!- end-- it 'only gets own details on index' do- create_list(:user, 2)- api_get :index, token: user.spree_api_key-- expect(Spree.user_class.count).to eq 3- expect(json_response['count']).to eq 1- expect(json_response['users'].size).to eq 1- end- end-- context 'as an admin' do- before { stub_authentication! }-- sign_in_as_admin!-- it 'gets all users' do- allow(Spree::LegacyUser).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }-- create_list(:user, 2)-- api_get :index- expect(Spree.user_class.count).to eq 2- expect(json_response['count']).to eq 2- expect(json_response['users'].size).to eq 2- end-- context 'can query the results through' do- let(:first_bill_address) { create(:bill_address, firstname: 'John', lastname: 'Snow') }- let(:second_bill_address) { create(:bill_address, firstname: 'Michael', lastname: 'Michael') }-- let!(:first_user) { create(:user, bill_address: first_bill_address, email: '[email protected]') }- let!(:second_user) { create(:user, bill_address: second_bill_address, email: '[email protected]') }-- before do- first_user.addresses << first_bill_address- second_user.addresses << second_bill_address- allow(Spree::LegacyUser).to receive(:find_by).with(hash_including(:spree_api_key)) { current_api_user }- end-- it 'existing bill_address firstname parameter' do- api_get :index, q: {- email_start: 'John',- bill_address_firstname_start: 'John',- bill_address_lastname_start: 'John',- ship_address_firstname_start: 'John',- ship_address_lastname_start: 'John'- }-- expect(Spree.user_class.count).to eq 2- expect(json_response['count']).to eq 1- expect(json_response['users'].size).to eq 1- expect(json_response['users'].first['email']).to eq first_user.email- end-- it 'existing bill_address lastname parameter' do- api_get :index, q: {- email_start: 'Snow',- bill_address_firstname_start: 'Snow',- bill_address_lastname_start: 'Snow',- ship_address_firstname_start: 'Snow',- ship_address_lastname_start: 'Snow'- }-- expect(Spree.user_class.count).to eq 2- expect(json_response['count']).to eq 1- expect(json_response['users'].size).to eq 1- expect(json_response['users'].first['email']).to eq first_user.email- end-- it 'existing bill_address firstname and lastname parameter' do- api_get :index, q: {- email_start: 'Michael',- bill_address_firstname_start: 'Michael',- bill_address_lastname_start: 'Michael',- ship_address_firstname_start: 'Michael',- ship_address_lastname_start: 'Michael'- }-- expect(Spree.user_class.count).to eq 2- expect(json_response['count']).to eq 1- expect(json_response['users'].size).to eq 1- expect(json_response['users'].first['email']).to eq second_user.email- end-- it 'non-existenting ship_address firstname parameter' do- api_get :index, q: {- email_start: 'Result',- bill_address_firstname_start: 'Result',- bill_address_lastname_start: 'Result',- ship_address_firstname_start: 'Result',- ship_address_lastname_start: 'Result'- }-- expect(Spree.user_class.count).to eq 2- expect(json_response['count']).to eq 0- expect(json_response['users'].size).to eq 0- end-- it 'existing email parameter' do- api_get :index, q: {- email_start: 'actor',- bill_address_firstname_start: 'actor',- bill_address_lastname_start: 'actor',- ship_address_firstname_start: 'actor',- ship_address_lastname_start: 'actor'- }-- expect(Spree.user_class.count).to eq 2- expect(json_response['count']).to eq(1)- expect(json_response['users'].first['email']).to eq first_user.email- end- end-- it 'can control the page size through a parameter' do- create_list(:user, 2)- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can create' do- api_post :create, user: { email: '[email protected]', password: 'spree123', password_confirmation: 'spree123' }- expect(json_response).to have_attributes(attributes)- expect(response.status).to eq(201)- end-- it 'can destroy user without orders' do- user.orders.destroy_all- api_delete :destroy, id: user.id- expect(response.status).to eq(204)- end-- it 'cannot destroy user with orders' do- create(:completed_order_with_totals, user: user)- api_delete :destroy, id: user.id- expect(json_response['exception']).to eq 'Spree::Core::DestroyWithOrdersError'- expect(response.status).to eq(422)- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb b/api/spec/controllers/spree/api/v1/variants_controller_spec.rbdeleted file mode 100644index d72388e133..0000000000--- a/api/spec/controllers/spree/api/v1/variants_controller_spec.rb+++ /dev/null@@ -1,221 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::VariantsController, type: :controller do- render_views-- let(:option_value) { create(:option_value) }- let!(:product) { create(:product, stores: Spree::Store.all) }- let!(:variant) do- variant = product.master- variant.option_values << option_value- variant- end-- let!(:base_attributes) { Api::ApiHelpers.variant_attributes }- let!(:show_attributes) { base_attributes.dup.push(:in_stock, :display_price) }- let!(:new_attributes) { base_attributes }-- before do- stub_authentication!- end-- describe '#variant_includes' do- let(:variants_includes_list) do- [{ option_values: :option_type }, :product, :default_price, :images, { stock_items: :stock_location }]- end-- after { api_get :index }-- it { expect(controller).to receive(:variant_includes).and_return(variants_includes_list) }- end-- it 'adds for_currency_and_available_price_amount scope to variants list' do- expect(Spree::Variant).to receive(:for_currency_and_available_price_amount).- and_return(Spree::Variant.for_currency_and_available_price_amount)- api_get :index- end-- it 'can see a paginated list of variants' do- api_get :index- first_variant = json_response['variants'].first- expect(first_variant).to have_attributes(show_attributes)- expect(first_variant['stock_items']).to be_present- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(1)- end-- it 'can control the page size through a parameter' do- create(:variant)- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- expected_result = create(:variant, sku: 'FOOBAR')- api_get :index, q: { sku_cont: 'FOO' }- expect(json_response['count']).to eq(1)- expect(json_response['variants'].first['sku']).to eq expected_result.sku- end-- it 'variants returned contain option values data' do- api_get :index- option_values = json_response['variants'].last['option_values']- expect(option_values.first).to have_attributes([:name,- :presentation,- :option_type_name,- :option_type_id])- end-- it 'variants returned contain images data' do- create_image(variant, image('thinking-cat.jpg'))-- api_get :index-- expect(json_response['variants'].last).to have_attributes([:images])- expect(json_response['variants'].first['images'].first).to have_attributes([:attachment_file_name,- :attachment_width,- :attachment_height,- :attachment_content_type,- :mini_url,- :small_url,- :product_url,- :large_url])- end-- it 'variants returned do not contain cost price data' do- api_get :index- expect(json_response['variants'].first.key?(:cost_price)).to eq false- end-- # Regression test for #2141- context 'a deleted variant' do- before do- variant.update_column(:deleted_at, Time.current)- end-- it 'is not returned in the results' do- api_get :index- expect(json_response['variants'].count).to eq(0)- end-- it 'is not returned even when show_deleted is passed' do- api_get :index, show_deleted: true- expect(json_response['variants'].count).to eq(0)- end- end-- context 'pagination' do- before { create(:variant) }-- it 'can select the next page of variants' do- api_get :index, page: 2, per_page: 1- expect(json_response['variants'].first).to have_attributes(show_attributes)- expect(json_response['total_count']).to eq(2)- expect(json_response['current_page']).to eq(2)- expect(json_response['pages']).to eq(2)- end- end-- it 'can see a single variant' do- api_get :show, id: variant.to_param- expect(json_response).to have_attributes(show_attributes)- expect(json_response['stock_items']).to be_present- option_values = json_response['option_values']- expect(option_values.first).to have_attributes([:name,- :presentation,- :option_type_name,- :option_type_id])- end-- it 'can see a single variant with images' do- create_image(variant, image('thinking-cat.jpg'))-- api_get :show, id: variant.to_param-- expect(json_response).to have_attributes(show_attributes + [:images])- option_values = json_response['option_values']- expect(option_values.first).to have_attributes([:name,- :presentation,- :option_type_name,- :option_type_id])- end-- it 'can learn how to create a new variant' do- api_get :new- expect(json_response['attributes']).to eq(new_attributes.map(&:to_s))- expect(json_response['required_attributes']).to be_empty- end-- it 'cannot create a new variant if not an admin' do- api_post :create, variant: { sku: '12345' }- assert_unauthorized!- end-- it 'cannot update a variant' do- api_put :update, id: variant.to_param, variant: { sku: '12345' }- assert_not_found!- end-- it 'cannot delete a variant' do- api_delete :destroy, id: variant.to_param- assert_not_found!- expect { variant.reload }.not_to raise_error- end-- context 'as an admin' do- sign_in_as_admin!- let(:resource_scoping) { { product_id: variant.product.to_param } }-- # Test for #2141- context 'deleted variants' do- before do- variant.update_columns(deleted_at: Time.current, discontinue_on: Time.current + 1)- end-- it 'are visible by admin' do- api_get :index, show_deleted: 1- expect(json_response['variants'].count).to eq(1)- end- end-- it 'can create a new variant' do- other_value = create(:option_value)- api_post :create, variant: {- sku: '12345',- price: '20',- option_value_ids: [option_value.id, other_value.id]- }-- expect(json_response).to have_attributes(new_attributes)- expect(response.status).to eq(201)- expect(json_response['sku']).to eq('12345')- expect(json_response['price']).to match '20'-- option_value_ids = json_response['option_values'].map { |o| o['id'] }- expect(option_value_ids).to match_array [option_value.id, other_value.id]-- expect(variant.product.variants.count).to eq(1)- end-- it 'can update a variant' do- api_put :update, id: variant.to_param, variant: { sku: '12345' }- expect(response.status).to eq(200)- end-- it 'can delete a variant' do- api_delete :destroy, id: variant.to_param- expect(response.status).to eq(204)- expect { Spree::Variant.find(variant.id) }.to raise_error(ActiveRecord::RecordNotFound)- end-- it 'variants returned contain cost price data' do- api_get :index- expect(json_response['variants'].first.key?(:cost_price)).to eq true- end- end- end-enddiff --git a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb b/api/spec/controllers/spree/api/v1/zones_controller_spec.rbdeleted file mode 100644index 6325a0150f..0000000000--- a/api/spec/controllers/spree/api/v1/zones_controller_spec.rb+++ /dev/null@@ -1,90 +0,0 @@-require 'spec_helper'--module Spree- describe Api::V1::ZonesController, type: :controller do- render_views-- let!(:attributes) { [:id, :name, :zone_members] }-- before do- stub_authentication!- @zone = create(:zone, name: 'Europe')- end-- it 'gets list of zones' do- api_get :index- expect(json_response['zones'].first).to have_attributes(attributes)- end-- it 'can control the page size through a parameter' do- create(:zone)- api_get :index, per_page: 1- expect(json_response['count']).to eq(1)- expect(json_response['current_page']).to eq(1)- expect(json_response['pages']).to eq(2)- end-- it 'can query the results through a parameter' do- expected_result = create(:zone, name: 'South America')- api_get :index, q: { name_cont: 'south' }- expect(json_response['count']).to eq(1)- expect(json_response['zones'].first['name']).to eq expected_result.name- end-- it 'gets a zone' do- api_get :show, id: @zone.id- expect(json_response).to have_attributes(attributes)- expect(json_response['name']).to eq @zone.name- expect(json_response['zone_members'].size).to eq @zone.zone_members.count- end-- context 'as an admin' do- sign_in_as_admin!-- let!(:country) { create(:country) }-- it 'can create a new zone' do- params = {- zone: {- name: 'North Pole',- zone_members: [- {- zoneable_type: 'Spree::Country',- zoneable_id: country.id- }- ]- }- }-- api_post :create, params- expect(response.status).to eq(201)- expect(json_response).to have_attributes(attributes)- expect(json_response['zone_members']).not_to be_empty- end-- it 'updates a zone' do- params = { id: @zone.id,- zone: {- name: 'North Pole',- zone_members: [- {- zoneable_type: 'Spree::Country',- zoneable_id: country.id- }- ]- } }-- api_put :update, params- expect(response.status).to eq(200)- expect(json_response['name']).to eq 'North Pole'- expect(json_response['zone_members']).not_to be_blank- end-- it 'can delete a zone' do- api_delete :destroy, id: @zone.id- expect(response.status).to eq(204)- expect { @zone.reload }.to raise_error(ActiveRecord::RecordNotFound)- end- end- end-enddiff --git a/api/spec/requests/rabl_cache_spec.rb b/api/spec/requests/rabl_cache_spec.rbdeleted file mode 100644index db240158a4..0000000000--- a/api/spec/requests/rabl_cache_spec.rb+++ /dev/null@@ -1,32 +0,0 @@-require 'spec_helper'--describe 'Rabl Cache', type: :request, caching: true do- let!(:user) { create(:admin_user) }-- before do- create(:variant)- user.generate_spree_api_key!- expect(Spree::Product.count).to eq(1)- end-- it "doesn't create a cache key collision for models with different rabl templates" do- get '/api/v1/variants', params: { token: user.spree_api_key }- expect(response.status).to eq(200)-- # Make sure we get a non master variant- variant_a = JSON.parse(response.body)['variants'].reject do |v|- v['is_master']- end.first-- expect(variant_a['is_master']).to be false- expect(variant_a['stock_items']).not_to be_nil-- get "/api/v1/products/#{Spree::Product.first.id}", params: { token: user.spree_api_key }- expect(response.status).to eq(200)- variant_b = JSON.parse(response.body)['variants'].last- expect(variant_b['is_master']).to be false-- expect(variant_a['id']).to eq(variant_b['id'])- expect(variant_b['stock_items']).to be_nil- end-enddiff --git a/api/spec/requests/ransackable_attributes_spec.rb b/api/spec/requests/ransackable_attributes_spec.rbdeleted file mode 100644index 84a692fc0a..0000000000--- a/api/spec/requests/ransackable_attributes_spec.rb+++ /dev/null@@ -1,79 +0,0 @@-require 'spec_helper'--describe 'Ransackable Attributes' do- let(:store) { Spree::Store.default }- let(:user) { create(:user).tap(&:generate_spree_api_key!) }- let(:order) { create(:order_with_line_items, user: user) }-- context 'filtering by attributes one association away' do- it 'does not allow the filtering of variants by order attributes' do- create_list(:variant, 2)-- get "/api/v1/variants?q[orders_email_start]=#{order.email}", params: { token: user.spree_api_key }-- variants_response = JSON.parse(response.body)- expect(variants_response['total_count']).to eq(Spree::Variant.eligible.count)- end- end-- context 'filtering by attributes two associations away' do- it 'does not allow the filtering of variants by user attributes' do- create_list(:variant, 2)-- get "/api/v1/variants?q[orders_user_email_start]=#{order.user.email}", params: { token: user.spree_api_key }-- variants_response = JSON.parse(response.body)- expect(variants_response['total_count']).to eq(Spree::Variant.eligible.count)- end- end-- context 'it maintains desired association behavior' do- it 'allows filtering of variants product name' do- product = create(:product, name: 'Fritos', stores: [store])- variant = create(:variant, product: product)- other_variant = create(:variant)-- get '/api/v1/variants?q[product_name_or_sku_cont]=fritos', params: { token: user.spree_api_key }-- skus = JSON.parse(response.body)['variants'].map { |var| var['sku'] }- expect(skus).to include variant.sku- expect(skus).not_to include other_variant.sku- end- end-- context 'filtering by attributes' do- it 'most attributes are not filterable by default' do- create(:product, meta_title: 'special product', stores: [store])- create(:product, stores: [store])-- get '/api/v1/products?q[meta_title_cont]=special', params: { token: user.spree_api_key }-- products_response = JSON.parse(response.body)- expect(products_response['total_count']).to eq(Spree::Product.count)- end-- it 'id is filterable by default' do- product = create(:product, stores: [store])- other_product = create(:product, stores: [store])-- get "/api/v1/products?q[id_eq]=#{product.id}", params: { token: user.spree_api_key }-- product_names = JSON.parse(response.body)['products'].map { |prod| prod['name'] }- expect(product_names).to include product.name- expect(product_names).not_to include other_product.name- end- end-- context 'filtering by whitelisted attributes' do- it 'filtering is supported for whitelisted attributes' do- product = create(:product, name: 'Fritos', stores: [store])- other_product = create(:product, stores: [store])-- get '/api/v1/products?q[name_cont]=fritos', params: { token: user.spree_api_key }-- product_names = JSON.parse(response.body)['products'].map { |prod| prod['name'] }- expect(product_names).to include product.name- expect(product_names).not_to include other_product.name- end- end-enddiff --git a/api/spec/requests/version_spec.rb b/api/spec/requests/version_spec.rbdeleted file mode 100644index 7f6d03b154..0000000000--- a/api/spec/requests/version_spec.rb+++ /dev/null@@ -1,12 +0,0 @@-require 'spec_helper'--describe 'Version', type: :request do- before { create_list(:country, 2) }-- describe '/api/v1' do- it 'be successful' do- get '/api/v1/countries'- expect(response).to have_http_status 200- end- end-enddiff --git a/api/spec/spec_helper.rb b/api/spec/spec_helper.rbindex dcf116c322..dd232593d8 100644--- a/api/spec/spec_helper.rb+++ b/api/spec/spec_helper.rb@@ -42,9 +42,7 @@ require 'spree/testing_support/rspec_retry_config'require 'spree/api/testing_support/caching'require 'spree/api/testing_support/jobs'-require 'spree/api/testing_support/helpers'require 'spree/api/testing_support/serializers'-require 'spree/api/testing_support/setup'require 'spree/api/testing_support/spree_webhooks'require 'spree/api/testing_support/matchers/webhooks'require 'spree/api/testing_support/v2/base'@@ -53,6 +51,15 @@ require 'spree/api/testing_support/v2/platform_contexts'require 'spree/api/testing_support/v2/serializers_params'require 'spree/api/testing_support/factories'+def json_response+ case body = JSON.parse(response.body)+ when Hash+ body.with_indifferent_access+ when Array+ body+ end+end+RSpec.configure do |config|config.backtrace_exclusion_patterns = [/gems\/activesupport/, /gems\/actionpack/, /gems\/rspec/]config.color = true@@ -64,9 +71,6 @@ RSpec.configure do |config|config.include JSONAPI::RSpecconfig.include FactoryBot::Syntax::Methods- config.include Spree::Api::TestingSupport::Helpers, type: :controller- config.include Spree::Api::TestingSupport::Helpers, type: :request- config.extend Spree::Api::TestingSupport::Setup, type: :controllerconfig.include Spree::TestingSupport::Preferencesconfig.include Spree::TestingSupport::ImageHelpers@@ -76,8 +80,6 @@ RSpec.configure do |config|Rails.cache.clearreset_spree_preferences- Spree::Api::Config[:requires_authentication] = true-country = create(:country, name: 'United States of America', iso_name: 'UNITED STATES', iso: 'US', iso3: 'USA', states_required: true)create(:store, default: true, default_country: country, default_currency: 'USD')enddiff --git a/api/spree_api.gemspec b/api/spree_api.gemspecindex a0f12d4646..c110fadd70 100644--- a/api/spree_api.gemspec+++ b/api/spree_api.gemspec@@ -31,7 +31,5 @@ Gem::Specification.new do |s|s.add_dependency 'bcrypt', '~> 3.1's.add_dependency 'doorkeeper', '~> 5.3's.add_dependency 'jsonapi-serializer', '~> 2.1'- s.add_dependency 'rabl', '~> 0.14', '>= 0.14.2'- s.add_dependency 'responders's.add_dependency 'spree_core', s.versionend