spree_core 3.2.9 → 3.3.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/concerns/spree/named_type.rb +1 -1
- data/app/models/concerns/spree/number_as_param.rb +9 -0
- data/app/models/concerns/spree/user_address.rb +4 -2
- data/app/models/concerns/spree/user_methods.rb +2 -3
- data/app/models/spree/ability.rb +1 -2
- data/app/models/spree/address.rb +1 -1
- data/app/models/spree/base.rb +2 -0
- data/app/models/spree/calculator.rb +1 -1
- data/app/models/spree/calculator/percent_per_item.rb +4 -3
- data/app/models/spree/calculator/returns/default_refund_amount.rb +16 -14
- data/app/models/spree/country.rb +1 -1
- data/app/models/spree/credit_card.rb +26 -21
- data/app/models/spree/customer_return.rb +2 -2
- data/app/models/spree/exchange.rb +7 -2
- data/app/models/spree/image.rb +1 -1
- data/app/models/spree/inventory_unit.rb +39 -3
- data/app/models/spree/line_item.rb +2 -7
- data/app/models/spree/option_type.rb +1 -1
- data/app/models/spree/option_type_prototype.rb +1 -1
- data/app/models/spree/option_value.rb +1 -1
- data/app/models/spree/option_value_variant.rb +3 -0
- data/app/models/spree/order.rb +82 -81
- data/app/models/spree/order/checkout.rb +23 -33
- data/app/models/spree/order/currency_updater.rb +1 -1
- data/app/models/spree/order/payments.rb +1 -1
- data/app/models/spree/order/store_credit.rb +6 -1
- data/app/models/spree/order_contents.rb +14 -2
- data/app/models/spree/order_inventory.rb +64 -60
- data/app/models/spree/payment.rb +8 -13
- data/app/models/spree/payment/processing.rb +2 -2
- data/app/models/spree/payment_method.rb +4 -2
- data/app/models/spree/preference.rb +1 -1
- data/app/models/spree/preferences/preferable.rb +1 -1
- data/app/models/spree/product.rb +1 -1
- data/app/models/spree/product/scopes.rb +2 -2
- data/app/models/spree/promotion.rb +2 -2
- data/app/models/spree/promotion/rules/option_value.rb +13 -5
- data/app/models/spree/promotion_rule_user.rb +1 -1
- data/app/models/spree/property_prototype.rb +1 -1
- data/app/models/spree/prototype_taxon.rb +1 -1
- data/app/models/spree/refund.rb +2 -2
- data/app/models/spree/reimbursement.rb +2 -1
- data/app/models/spree/reimbursement_type.rb +1 -1
- data/app/models/spree/return_authorization.rb +1 -0
- data/app/models/spree/return_item.rb +35 -9
- data/app/models/spree/role.rb +1 -1
- data/app/models/spree/role_user.rb +1 -1
- data/app/models/spree/shipment.rb +63 -64
- data/app/models/spree/shipment_handler.rb +1 -1
- data/app/models/spree/shipping_category.rb +1 -1
- data/app/models/spree/shipping_method.rb +12 -10
- data/app/models/spree/state_change.rb +1 -1
- data/app/models/spree/stock/adjuster.rb +35 -14
- data/app/models/spree/stock/availability_validator.rb +1 -1
- data/app/models/spree/stock/content_item.rb +9 -8
- data/app/models/spree/stock/coordinator.rb +3 -9
- data/app/models/spree/stock/estimator.rb +1 -1
- data/app/models/spree/stock/inventory_unit_builder.rb +10 -9
- data/app/models/spree/stock/package.rb +6 -6
- data/app/models/spree/stock/packer.rb +8 -15
- data/app/models/spree/stock/prioritizer.rb +13 -10
- data/app/models/spree/stock/splitter/weight.rb +62 -10
- data/app/models/spree/stock_item.rb +42 -29
- data/app/models/spree/stock_location.rb +5 -1
- data/app/models/spree/stock_movement.rb +1 -2
- data/app/models/spree/stock_transfer.rb +2 -3
- data/app/models/spree/store.rb +1 -1
- data/app/models/spree/store_credit.rb +9 -6
- data/app/models/spree/store_credit_category.rb +1 -1
- data/app/models/spree/tax_category.rb +1 -1
- data/app/models/spree/tax_rate.rb +1 -1
- data/app/models/spree/taxon.rb +5 -2
- data/app/models/spree/taxonomy.rb +1 -1
- data/app/models/spree/tracker.rb +1 -1
- data/app/models/spree/variant.rb +4 -3
- data/app/models/spree/zone.rb +19 -21
- data/app/views/spree/reimbursement_mailer/reimbursement_email.html.erb +61 -0
- data/config/locales/en.yml +7 -6
- data/db/migrate/20130807024301_upgrade_adjustments.rb +6 -0
- data/db/migrate/20130807024302_rename_adjustment_fields.rb +6 -0
- data/db/migrate/20161125065505_add_quantity_to_inventory_units.rb +5 -0
- data/db/migrate/20170119122701_add_original_return_item_id_to_spree_inventory_units.rb +29 -0
- data/db/migrate/20170315152755_add_unique_index_on_number_to_spree_orders.rb +16 -0
- data/db/migrate/20170316154338_add_unique_index_on_number_to_spree_stock_transfer.rb +16 -0
- data/db/migrate/20170316205511_add_unique_index_on_number_to_spree_shipment.rb +16 -0
- data/db/migrate/20170320134043_add_unique_index_on_number_to_spree_payments.rb +17 -0
- data/db/migrate/20170320142750_add_unique_index_on_number_to_spree_return_authorizations.rb +16 -0
- data/db/migrate/20170320145040_add_unique_index_on_number_to_spree_customer_returns.rb +16 -0
- data/db/migrate/20170320145518_add_unique_index_on_number_to_spree_reimbursements.rb +16 -0
- data/db/migrate/20170323151450_add_missing_unique_indexes_for_unique_attributes.rb +37 -0
- data/db/migrate/20170329110859_add_index_on_stock_location_to_spree_customer_returns.rb +5 -0
- data/db/migrate/20170329113917_add_index_on_prototype_to_spree_option_type_prototype.rb +19 -0
- data/db/migrate/20170330082155_add_indexes_to_spree_option_value_variant.rb +19 -0
- data/db/migrate/20170330132215_add_index_on_promotion_id_to_order_promotions.rb +5 -0
- data/db/migrate/20170331101758_add_indexes_for_property_prototype.rb +20 -0
- data/db/migrate/20170331103334_add_index_for_prototype_id_to_prototype_taxons.rb +5 -0
- data/db/migrate/20170331110454_add_indexes_to_refunds.rb +6 -0
- data/db/migrate/20170331111757_add_indexes_to_reimbursement_credits.rb +6 -0
- data/db/migrate/20170331115246_add_indexes_to_return_authorizations.rb +6 -0
- data/db/migrate/20170331120125_add_indexes_to_return_items.rb +11 -0
- data/db/migrate/20170331121725_add_index_to_role_users.rb +18 -0
- data/db/migrate/20170331123625_add_index_to_shipping_method_categories.rb +5 -0
- data/db/migrate/20170331123832_add_index_to_shipping_method_zones.rb +20 -0
- data/db/migrate/20170331124251_add_index_to_spree_shipping_rates.rb +6 -0
- data/db/migrate/20170331124513_add_index_to_spree_stock_items.rb +5 -0
- data/db/migrate/20170331124924_add_index_to_spree_stock_movement.rb +5 -0
- data/db/migrate/20170413211707_change_indexes_on_friendly_id_slugs.rb +10 -0
- data/lib/generators/spree/install/install_generator.rb +41 -36
- data/lib/spree/core.rb +0 -1
- data/lib/spree/core/engine.rb +3 -3
- data/lib/spree/core/importer/order.rb +23 -19
- data/lib/spree/core/number_generator.rb +3 -5
- data/lib/spree/core/product_duplicator.rb +7 -3
- data/lib/spree/core/search/base.rb +1 -0
- data/lib/spree/core/validators/email.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/money.rb +1 -15
- data/lib/spree/permitted_attributes.rb +1 -1
- data/lib/spree/testing_support/common_rake.rb +0 -2
- data/lib/spree/testing_support/factories.rb +3 -3
- data/lib/spree/testing_support/factories/address_factory.rb +1 -1
- data/lib/spree/testing_support/factories/adjustment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/calculator_factory.rb +1 -1
- data/lib/spree/testing_support/factories/country_factory.rb +1 -1
- data/lib/spree/testing_support/factories/credit_card_factory.rb +1 -1
- data/lib/spree/testing_support/factories/customer_return_factory.rb +1 -1
- data/lib/spree/testing_support/factories/image_factory.rb +1 -1
- data/lib/spree/testing_support/factories/inventory_unit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/line_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/options_factory.rb +1 -1
- data/lib/spree/testing_support/factories/order_factory.rb +7 -1
- data/lib/spree/testing_support/factories/payment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/payment_method_factory.rb +1 -1
- data/lib/spree/testing_support/factories/price_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_option_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/product_property_factory.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_factory.rb +1 -1
- data/lib/spree/testing_support/factories/promotion_rule_factory.rb +1 -1
- data/lib/spree/testing_support/factories/property_factory.rb +1 -1
- data/lib/spree/testing_support/factories/prototype_factory.rb +1 -1
- data/lib/spree/testing_support/factories/refund_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_factory.rb +1 -1
- data/lib/spree/testing_support/factories/reimbursement_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/return_authorization_factory.rb +1 -1
- data/lib/spree/testing_support/factories/return_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/role_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipment_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipping_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/shipping_method_factory.rb +2 -1
- data/lib/spree/testing_support/factories/state_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_item_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_location_factory.rb +1 -1
- data/lib/spree/testing_support/factories/stock_movement_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_event_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_credit_type_factory.rb +1 -1
- data/lib/spree/testing_support/factories/store_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tag_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tax_category_factory.rb +1 -1
- data/lib/spree/testing_support/factories/tax_rate_factory.rb +1 -1
- data/lib/spree/testing_support/factories/taxon_factory.rb +2 -2
- data/lib/spree/testing_support/factories/taxonomy_factory.rb +2 -2
- data/lib/spree/testing_support/factories/tracker_factory.rb +1 -1
- data/lib/spree/testing_support/factories/user_factory.rb +1 -1
- data/lib/spree/testing_support/factories/variant_factory.rb +1 -1
- data/lib/spree/testing_support/factories/zone_factory.rb +1 -1
- data/lib/spree/testing_support/factories/zone_member_factory.rb +1 -1
- data/lib/spree/testing_support/microdata.rb +3 -0
- data/lib/spree/testing_support/order_walkthrough.rb +9 -9
- data/lib/tasks/exchanges.rake +8 -10
- data/spec/helpers/base_helper_spec.rb +200 -0
- data/spec/helpers/products_helper_spec.rb +289 -0
- data/spec/lib/calculated_adjustments_spec.rb +7 -0
- data/spec/lib/i18n_spec.rb +123 -0
- data/spec/lib/search/base_spec.rb +86 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +103 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +110 -0
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +72 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +22 -0
- data/spec/lib/spree/core/importer/order_spec.rb +607 -0
- data/spec/lib/spree/core/number_generator_spec.rb +139 -0
- data/spec/lib/spree/core/token_generator_spec.rb +24 -0
- data/spec/lib/spree/core/validators/email_spec.rb +54 -0
- data/spec/lib/spree/core_spec.rb +23 -0
- data/spec/lib/spree/localized_number_spec.rb +54 -0
- data/spec/lib/spree/migrations_spec.rb +36 -0
- data/spec/lib/spree/money_spec.rb +122 -0
- data/spec/lib/tasks/exchanges_spec.rb +136 -0
- data/spec/mailers/order_mailer_spec.rb +122 -0
- data/spec/mailers/reimbursement_mailer_spec.rb +52 -0
- data/spec/mailers/shipment_mailer_spec.rb +81 -0
- data/spec/mailers/test_mailer_spec.rb +38 -0
- data/spec/models/spree/ability_spec.rb +251 -0
- data/spec/models/spree/address_spec.rb +402 -0
- data/spec/models/spree/adjustable/adjuster/base_spec.rb +10 -0
- data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +211 -0
- data/spec/models/spree/adjustable/adjuster/tax_spec.rb +86 -0
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +26 -0
- data/spec/models/spree/adjustment_spec.rb +189 -0
- data/spec/models/spree/app_configuration_spec.rb +26 -0
- data/spec/models/spree/asset_spec.rb +28 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +152 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +47 -0
- data/spec/models/spree/calculator/shipping.rb +8 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +29 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +40 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +51 -0
- data/spec/models/spree/calculator_spec.rb +69 -0
- data/spec/models/spree/classification_spec.rb +93 -0
- data/spec/models/spree/concerns/display_money_spec.rb +43 -0
- data/spec/models/spree/concerns/user_methods_spec.rb +82 -0
- data/spec/models/spree/concerns/vat_price_calculation_spec.rb +66 -0
- data/spec/models/spree/country_spec.rb +55 -0
- data/spec/models/spree/credit_card_spec.rb +328 -0
- data/spec/models/spree/customer_return_spec.rb +240 -0
- data/spec/models/spree/exchange_spec.rb +75 -0
- data/spec/models/spree/gateway/bogus_simple.rb +20 -0
- data/spec/models/spree/gateway/bogus_spec.rb +13 -0
- data/spec/models/spree/gateway_spec.rb +61 -0
- data/spec/models/spree/image_spec.rb +8 -0
- data/spec/models/spree/inventory_unit_spec.rb +256 -0
- data/spec/models/spree/line_item_spec.rb +348 -0
- data/spec/models/spree/option_type_prototype_spec.rb +9 -0
- data/spec/models/spree/option_type_spec.rb +14 -0
- data/spec/models/spree/option_value_spec.rb +18 -0
- data/spec/models/spree/order/address_spec.rb +50 -0
- data/spec/models/spree/order/adjustments_spec.rb +29 -0
- data/spec/models/spree/order/callbacks_spec.rb +42 -0
- data/spec/models/spree/order/checkout_spec.rb +770 -0
- data/spec/models/spree/order/currency_updater_spec.rb +32 -0
- data/spec/models/spree/order/finalizing_spec.rb +114 -0
- data/spec/models/spree/order/helpers_spec.rb +5 -0
- data/spec/models/spree/order/payment_spec.rb +214 -0
- data/spec/models/spree/order/risk_assessment_spec.rb +84 -0
- data/spec/models/spree/order/shipments_spec.rb +43 -0
- data/spec/models/spree/order/state_machine_spec.rb +212 -0
- data/spec/models/spree/order/store_credit_spec.rb +457 -0
- data/spec/models/spree/order/tax_spec.rb +84 -0
- data/spec/models/spree/order/totals_spec.rb +24 -0
- data/spec/models/spree/order/updating_spec.rb +18 -0
- data/spec/models/spree/order/validations_spec.rb +15 -0
- data/spec/models/spree/order_contents_spec.rb +332 -0
- data/spec/models/spree/order_inventory_spec.rb +247 -0
- data/spec/models/spree/order_merger_spec.rb +135 -0
- data/spec/models/spree/order_spec.rb +1067 -0
- data/spec/models/spree/order_updater_spec.rb +305 -0
- data/spec/models/spree/payment/gateway_options_spec.rb +127 -0
- data/spec/models/spree/payment/store_credit_spec.rb +60 -0
- data/spec/models/spree/payment_method/store_credit_spec.rb +291 -0
- data/spec/models/spree/payment_method_spec.rb +108 -0
- data/spec/models/spree/payment_spec.rb +922 -0
- data/spec/models/spree/preference_spec.rb +80 -0
- data/spec/models/spree/preferences/configuration_spec.rb +30 -0
- data/spec/models/spree/preferences/preferable_spec.rb +344 -0
- data/spec/models/spree/preferences/scoped_store_spec.rb +58 -0
- data/spec/models/spree/preferences/store_spec.rb +46 -0
- data/spec/models/spree/price_spec.rb +128 -0
- data/spec/models/spree/product/scopes_spec.rb +174 -0
- data/spec/models/spree/product_duplicator_spec.rb +102 -0
- data/spec/models/spree/product_filter_spec.rb +26 -0
- data/spec/models/spree/product_option_type_spec.rb +9 -0
- data/spec/models/spree/product_promotion_rule_spec.rb +9 -0
- data/spec/models/spree/product_property_spec.rb +26 -0
- data/spec/models/spree/product_spec.rb +626 -0
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +113 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +148 -0
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +86 -0
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +36 -0
- data/spec/models/spree/promotion/rules/country_spec.rb +36 -0
- data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
- data/spec/models/spree/promotion/rules/item_total_spec.rb +282 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
- data/spec/models/spree/promotion/rules/option_value_spec.rb +90 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
- data/spec/models/spree/promotion/rules/user_spec.rb +45 -0
- data/spec/models/spree/promotion_action_spec.rb +10 -0
- data/spec/models/spree/promotion_category_spec.rb +17 -0
- data/spec/models/spree/promotion_handler/cart_spec.rb +102 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +323 -0
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +48 -0
- data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
- data/spec/models/spree/promotion_rule_spec.rb +29 -0
- data/spec/models/spree/promotion_rule_taxon_spec.rb +9 -0
- data/spec/models/spree/promotion_rule_user_spec.rb +9 -0
- data/spec/models/spree/promotion_spec.rb +674 -0
- data/spec/models/spree/property_prototype_spec.rb +9 -0
- data/spec/models/spree/property_spec.rb +5 -0
- data/spec/models/spree/prototype_spec.rb +5 -0
- data/spec/models/spree/prototype_taxon_spec.rb +9 -0
- data/spec/models/spree/refund_reason_spec.rb +20 -0
- data/spec/models/spree/refund_spec.rb +195 -0
- data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
- data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
- data/spec/models/spree/reimbursement_spec.rb +188 -0
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +63 -0
- data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +55 -0
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +101 -0
- data/spec/models/spree/return_authorization_reason_spec.rb +7 -0
- data/spec/models/spree/return_authorization_spec.rb +230 -0
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +61 -0
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
- data/spec/models/spree/return_item_spec.rb +734 -0
- data/spec/models/spree/returns_calculator_spec.rb +14 -0
- data/spec/models/spree/role_spec.rb +7 -0
- data/spec/models/spree/shipment_spec.rb +744 -0
- data/spec/models/spree/shipping_calculator_spec.rb +45 -0
- data/spec/models/spree/shipping_category_spec.rb +19 -0
- data/spec/models/spree/shipping_method_spec.rb +125 -0
- data/spec/models/spree/shipping_rate_spec.rb +140 -0
- data/spec/models/spree/state_spec.rb +29 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +42 -0
- data/spec/models/spree/stock/content_item_spec.rb +31 -0
- data/spec/models/spree/stock/coordinator_spec.rb +61 -0
- data/spec/models/spree/stock/differentiator_spec.rb +39 -0
- data/spec/models/spree/stock/estimator_spec.rb +202 -0
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +37 -0
- data/spec/models/spree/stock/package_spec.rb +182 -0
- data/spec/models/spree/stock/packer_spec.rb +70 -0
- data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
- data/spec/models/spree/stock/quantifier_spec.rb +126 -0
- data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
- data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +47 -0
- data/spec/models/spree/stock/splitter/weight_spec.rb +32 -0
- data/spec/models/spree/stock_item_spec.rb +465 -0
- data/spec/models/spree/stock_location_spec.rb +243 -0
- data/spec/models/spree/stock_movement_spec.rb +120 -0
- data/spec/models/spree/stock_transfer_spec.rb +50 -0
- data/spec/models/spree/store_credit_event_spec.rb +101 -0
- data/spec/models/spree/store_credit_spec.rb +798 -0
- data/spec/models/spree/store_spec.rb +78 -0
- data/spec/models/spree/tax_category_spec.rb +32 -0
- data/spec/models/spree/tax_rate_spec.rb +561 -0
- data/spec/models/spree/taxon_spec.rb +93 -0
- data/spec/models/spree/taxonomy_spec.rb +18 -0
- data/spec/models/spree/tracker_spec.rb +21 -0
- data/spec/models/spree/user_spec.rb +203 -0
- data/spec/models/spree/variant_spec.rb +818 -0
- data/spec/models/spree/zone_member_spec.rb +38 -0
- data/spec/models/spree/zone_spec.rb +472 -0
- data/spec/spec_helper.rb +82 -0
- data/spec/support/big_decimal.rb +5 -0
- data/spec/support/concerns/adjustment_source.rb +23 -0
- data/spec/support/concerns/default_price.rb +37 -0
- data/spec/support/rake.rb +13 -0
- data/spec/support/test_gateway.rb +2 -0
- data/spree_core.gemspec +13 -13
- metadata +252 -45
- data/app/models/concerns/spree/user_api_authentication.rb +0 -19
- data/app/models/spree/calculator/free_shipping.rb +0 -23
- data/config/initializers/premailer_rails.rb +0 -3
- data/config/initializers/user_class_extensions.rb +0 -10
- data/spec/fixtures/microdata.html +0 -22
- data/spec/fixtures/microdata_itemref.html +0 -15
- data/spec/fixtures/microdata_no_itemscope.html +0 -20
@@ -0,0 +1,247 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::OrderInventory, type: :model do
|
4
|
+
let(:order) { create :completed_order_with_totals }
|
5
|
+
let(:line_item) { order.line_items.first }
|
6
|
+
|
7
|
+
subject { described_class.new(order, line_item) }
|
8
|
+
|
9
|
+
describe 'delegate' do
|
10
|
+
it { is_expected.to delegate_method(:inventory_units).to(:line_item) }
|
11
|
+
end
|
12
|
+
|
13
|
+
context "when order is missing inventory units" do
|
14
|
+
before { line_item.update_column(:quantity, 2) }
|
15
|
+
|
16
|
+
it 'creates the proper number of inventory units' do
|
17
|
+
subject.verify
|
18
|
+
expect(subject.inventory_units.reload.sum(&:quantity)).to eq 2
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "#add_to_shipment" do
|
23
|
+
let(:shipment) { order.shipments.first }
|
24
|
+
|
25
|
+
context "order is not completed" do
|
26
|
+
before { allow(order).to receive_messages completed?: false }
|
27
|
+
|
28
|
+
it "doesn't unstock items" do
|
29
|
+
expect(shipment.stock_location).not_to receive(:unstock)
|
30
|
+
expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
context "inventory units state" do
|
35
|
+
before { shipment.inventory_units.destroy_all }
|
36
|
+
|
37
|
+
it 'sets inventory_units state as per stock location availability' do
|
38
|
+
expect(shipment.stock_location).to receive(:fill_status).with(subject.variant, 5).and_return([3, 2])
|
39
|
+
|
40
|
+
expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
|
41
|
+
|
42
|
+
units = shipment.inventory_units_for(subject.variant).group_by(&:state)
|
43
|
+
expect(units['backordered'].size).to eq(2)
|
44
|
+
expect(units['on_hand'].size).to eq(3)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "store doesnt track inventory" do
|
49
|
+
let(:variant) { create(:variant) }
|
50
|
+
|
51
|
+
before { Spree::Config.track_inventory_levels = false }
|
52
|
+
|
53
|
+
it "creates only on hand inventory units" do
|
54
|
+
variant.stock_items.destroy_all
|
55
|
+
|
56
|
+
# The before_save callback in LineItem would verify inventory
|
57
|
+
line_item = order.contents.add variant, 1, shipment: shipment
|
58
|
+
|
59
|
+
units = shipment.inventory_units_for(line_item.variant)
|
60
|
+
expect(units.sum(&:quantity)).to eq 1
|
61
|
+
expect(units.first).to be_on_hand
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "variant doesnt track inventory" do
|
66
|
+
let(:variant) { create(:variant) }
|
67
|
+
before { variant.track_inventory = false }
|
68
|
+
|
69
|
+
it "creates only on hand inventory units" do
|
70
|
+
variant.stock_items.destroy_all
|
71
|
+
|
72
|
+
line_item = order.contents.add variant, 1
|
73
|
+
subject.verify(shipment)
|
74
|
+
|
75
|
+
units = shipment.inventory_units_for(line_item.variant)
|
76
|
+
expect(units.sum(&:quantity)).to eq 1
|
77
|
+
expect(units.first).to be_on_hand
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'should create stock_movement' do
|
82
|
+
expect(subject.send(:add_to_shipment, shipment, 5)).to eq(5)
|
83
|
+
|
84
|
+
stock_item = shipment.stock_location.stock_item(subject.variant)
|
85
|
+
movement = stock_item.stock_movements.last
|
86
|
+
# movement.originator.should == shipment
|
87
|
+
expect(movement.quantity).to eq(-5)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "#determine_target_shipment" do
|
92
|
+
let(:stock_location) { create :stock_location }
|
93
|
+
let(:variant) { line_item.variant }
|
94
|
+
|
95
|
+
before do
|
96
|
+
allow(line_item).to receive(:changed?).and_return(:true)
|
97
|
+
subject.verify
|
98
|
+
|
99
|
+
order.shipments.create(stock_location_id: stock_location.id, cost: 5)
|
100
|
+
|
101
|
+
shipped = order.shipments.create(stock_location_id: order.shipments.first.stock_location.id, cost: 10)
|
102
|
+
shipped.update_column(:state, 'shipped')
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'should select first non-shipped shipment that already contains given variant' do
|
106
|
+
shipment = subject.send(:determine_target_shipment)
|
107
|
+
expect(shipment.shipped?).to be false
|
108
|
+
expect(shipment.inventory_units_for(variant)).not_to be_empty
|
109
|
+
|
110
|
+
expect(variant.stock_location_ids.include?(shipment.stock_location_id)).to be true
|
111
|
+
end
|
112
|
+
|
113
|
+
context "when no shipments already contain this varint" do
|
114
|
+
before do
|
115
|
+
subject.line_item.reload
|
116
|
+
subject.inventory_units.destroy_all
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'selects first non-shipped shipment that leaves from same stock_location' do
|
120
|
+
shipment = subject.send(:determine_target_shipment)
|
121
|
+
shipment.reload
|
122
|
+
expect(shipment.shipped?).to be false
|
123
|
+
expect(shipment.inventory_units_for(variant)).to be_empty
|
124
|
+
expect(variant.stock_location_ids.include?(shipment.stock_location_id)).to be true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
context 'when order has too many inventory units' do
|
130
|
+
before do
|
131
|
+
line_item.quantity = 3
|
132
|
+
line_item.save!
|
133
|
+
|
134
|
+
line_item.update_column(:quantity, 2)
|
135
|
+
subject.line_item.reload
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'should be a messed up order' do
|
139
|
+
expect(order.shipments.first.inventory_units_for(line_item.variant).size).to eq(3)
|
140
|
+
expect(line_item.quantity).to eq(2)
|
141
|
+
end
|
142
|
+
|
143
|
+
it 'should decrease the number of inventory units' do
|
144
|
+
subject.verify
|
145
|
+
expect(subject.inventory_units.reload.sum(:quantity)).to eq 2
|
146
|
+
end
|
147
|
+
|
148
|
+
context '#remove_from_shipment' do
|
149
|
+
let(:shipment) { order.shipments.first }
|
150
|
+
let(:variant) { subject.variant }
|
151
|
+
|
152
|
+
context "order is not completed" do
|
153
|
+
before { allow(order).to receive_messages completed?: false }
|
154
|
+
|
155
|
+
it "doesn't restock items" do
|
156
|
+
expect(shipment.stock_location).not_to receive(:restock)
|
157
|
+
expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
it 'should create stock_movement' do
|
162
|
+
expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
|
163
|
+
|
164
|
+
stock_item = shipment.stock_location.stock_item(variant)
|
165
|
+
movement = stock_item.stock_movements.last
|
166
|
+
# movement.originator.should == shipment
|
167
|
+
expect(movement.quantity).to eq(1)
|
168
|
+
end
|
169
|
+
|
170
|
+
it 'should destroy backordered units first' do
|
171
|
+
allow(shipment).to receive_messages(
|
172
|
+
inventory_units_for_item: [
|
173
|
+
mock_model(
|
174
|
+
Spree::InventoryUnit, variant_id: variant.id, quantity: 2, state: 'backordered', shipped?: false
|
175
|
+
),
|
176
|
+
mock_model(
|
177
|
+
Spree::InventoryUnit, variant_id: variant.id, quantity: 1, state: 'on_hand', shipped?: false
|
178
|
+
)
|
179
|
+
]
|
180
|
+
)
|
181
|
+
|
182
|
+
expect(shipment.inventory_units_for_item[0]).to receive(:quantity).and_return(2)
|
183
|
+
expect(shipment.inventory_units_for_item[0]).to receive(:decrement)
|
184
|
+
expect(shipment.inventory_units_for_item[0]).to receive(:quantity).and_return(1)
|
185
|
+
expect(shipment.inventory_units_for_item[0]).to receive(:destroy)
|
186
|
+
expect(shipment.inventory_units_for_item[1]).not_to receive(:decrement)
|
187
|
+
expect(shipment.inventory_units_for_item[1]).not_to receive(:destroy)
|
188
|
+
# expect(shipment.inventory_units_for_item[2]).to receive(:destroy)
|
189
|
+
|
190
|
+
expect(subject.send(:remove_from_shipment, shipment, 2)).to eq(2)
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should destroy unshipped units first' do
|
194
|
+
allow(shipment).to receive_messages(
|
195
|
+
inventory_units_for_item: [
|
196
|
+
mock_model(Spree::InventoryUnit, variant_id: variant.id, quantity: 1, state: 'shipped', shipped?: true),
|
197
|
+
mock_model(Spree::InventoryUnit, variant_id: variant.id, quantity: 1, state: 'on_hand', shipped?: false)
|
198
|
+
]
|
199
|
+
)
|
200
|
+
|
201
|
+
expect(shipment.inventory_units_for_item[0]).not_to receive(:destroy)
|
202
|
+
expect(shipment.inventory_units_for_item[1]).to receive(:destroy)
|
203
|
+
|
204
|
+
expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'only attempts to destroy as many units as are eligible, and return amount destroyed' do
|
208
|
+
allow(shipment).to receive_messages(
|
209
|
+
inventory_units_for_item: [
|
210
|
+
mock_model(Spree::InventoryUnit, variant_id: variant.id, quantity: 1, state: 'shipped', shipped?: true),
|
211
|
+
mock_model(Spree::InventoryUnit, variant_id: variant.id, quantity: 1, state: 'on_hand', shipped?: false)
|
212
|
+
]
|
213
|
+
)
|
214
|
+
|
215
|
+
expect(shipment.inventory_units_for_item[0]).not_to receive(:destroy)
|
216
|
+
expect(shipment.inventory_units_for_item[1]).to receive(:destroy)
|
217
|
+
|
218
|
+
expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should destroy self if not inventory units remain' do
|
222
|
+
allow(shipment).to receive(:inventory_units).and_return(shipment.inventory_units)
|
223
|
+
allow(shipment.inventory_units).to receive_messages(sum: 0)
|
224
|
+
expect(shipment).to receive(:destroy)
|
225
|
+
|
226
|
+
expect(subject.send(:remove_from_shipment, shipment, 1)).to eq(1)
|
227
|
+
end
|
228
|
+
|
229
|
+
context "inventory unit line item and variant points to different products" do
|
230
|
+
let(:different_line_item) { create(:line_item) }
|
231
|
+
|
232
|
+
let!(:different_inventory) do
|
233
|
+
shipment.set_up_inventory("on_hand", variant, order, different_line_item)
|
234
|
+
end
|
235
|
+
|
236
|
+
context "completed order" do
|
237
|
+
before { order.touch :completed_at }
|
238
|
+
|
239
|
+
it "removes only units that match both line item and variant" do
|
240
|
+
subject.send(:remove_from_shipment, shipment, shipment.inventory_units.sum(&:quantity))
|
241
|
+
expect(different_inventory.reload).to be_persisted
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
# Regression tests for #2179
|
4
|
+
module Spree
|
5
|
+
describe OrderMerger, type: :model do
|
6
|
+
let(:variant) { create(:variant) }
|
7
|
+
let(:order_1) { Spree::Order.create }
|
8
|
+
let(:order_2) { Spree::Order.create }
|
9
|
+
let(:user) { stub_model(Spree::LegacyUser, email: "spree@example.com") }
|
10
|
+
let(:subject) { Spree::OrderMerger.new(order_1) }
|
11
|
+
|
12
|
+
it "destroys the other order" do
|
13
|
+
subject.merge!(order_2)
|
14
|
+
expect { order_2.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
15
|
+
end
|
16
|
+
|
17
|
+
it "persist the merge" do
|
18
|
+
expect(subject).to receive(:persist_merge)
|
19
|
+
subject.merge!(order_2)
|
20
|
+
end
|
21
|
+
|
22
|
+
context "user is provided" do
|
23
|
+
it "assigns user to new order" do
|
24
|
+
subject.merge!(order_2, user)
|
25
|
+
expect(order_1.user).to eq user
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "merging together two orders with line items for the same variant" do
|
30
|
+
before do
|
31
|
+
order_1.contents.add(variant, 1)
|
32
|
+
order_2.contents.add(variant, 1)
|
33
|
+
end
|
34
|
+
|
35
|
+
specify do
|
36
|
+
subject.merge!(order_2, user)
|
37
|
+
expect(order_1.line_items.count).to eq(1)
|
38
|
+
|
39
|
+
line_item = order_1.line_items.first
|
40
|
+
expect(line_item.quantity).to eq(2)
|
41
|
+
expect(line_item.variant_id).to eq(variant.id)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "merging using extension-specific line_item_comparison_hooks" do
|
46
|
+
before do
|
47
|
+
Spree::Order.register_line_item_comparison_hook(:foos_match)
|
48
|
+
allow(Spree::Variant).to receive(:price_modifier_amount).and_return(0.00)
|
49
|
+
end
|
50
|
+
|
51
|
+
after do
|
52
|
+
# reset to avoid test pollution
|
53
|
+
Spree::Order.line_item_comparison_hooks = Set.new
|
54
|
+
end
|
55
|
+
|
56
|
+
context "2 equal line items" do
|
57
|
+
before do
|
58
|
+
@line_item_1 = order_1.contents.add(variant, 1, foos: {})
|
59
|
+
@line_item_2 = order_2.contents.add(variant, 1, foos: {})
|
60
|
+
end
|
61
|
+
|
62
|
+
specify do
|
63
|
+
expect(order_1).to receive(:foos_match).with(@line_item_1, kind_of(Hash)).and_return(true)
|
64
|
+
subject.merge!(order_2)
|
65
|
+
expect(order_1.line_items.count).to eq(1)
|
66
|
+
|
67
|
+
line_item = order_1.line_items.first
|
68
|
+
expect(line_item.quantity).to eq(2)
|
69
|
+
expect(line_item.variant_id).to eq(variant.id)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "2 different line items" do
|
74
|
+
before do
|
75
|
+
allow(order_1).to receive(:foos_match).and_return(false)
|
76
|
+
|
77
|
+
order_1.contents.add(variant, 1, foos: {})
|
78
|
+
order_2.contents.add(variant, 1, foos: { bar: :zoo })
|
79
|
+
end
|
80
|
+
|
81
|
+
specify do
|
82
|
+
subject.merge!(order_2)
|
83
|
+
expect(order_1.line_items.count).to eq(2)
|
84
|
+
|
85
|
+
line_item = order_1.line_items.first
|
86
|
+
expect(line_item.quantity).to eq(1)
|
87
|
+
expect(line_item.variant_id).to eq(variant.id)
|
88
|
+
|
89
|
+
line_item = order_1.line_items.last
|
90
|
+
expect(line_item.quantity).to eq(1)
|
91
|
+
expect(line_item.variant_id).to eq(variant.id)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "merging together two orders with different line items" do
|
97
|
+
let(:variant_2) { create(:variant) }
|
98
|
+
|
99
|
+
before do
|
100
|
+
order_1.contents.add(variant, 1)
|
101
|
+
order_2.contents.add(variant_2, 1)
|
102
|
+
end
|
103
|
+
|
104
|
+
specify do
|
105
|
+
subject.merge!(order_2)
|
106
|
+
line_items = order_1.line_items.reload
|
107
|
+
expect(line_items.count).to eq(2)
|
108
|
+
|
109
|
+
expect(order_1.item_count).to eq 2
|
110
|
+
expect(order_1.item_total).to eq line_items.map(&:amount).sum
|
111
|
+
|
112
|
+
# No guarantee on ordering of line items, so we do this:
|
113
|
+
expect(line_items.pluck(:quantity)).to match_array([1, 1])
|
114
|
+
expect(line_items.pluck(:variant_id)).to match_array([variant.id, variant_2.id])
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
context "merging together orders with invalid line items" do
|
119
|
+
let(:variant_2) { create(:variant) }
|
120
|
+
|
121
|
+
before do
|
122
|
+
order_1.contents.add(variant, 1)
|
123
|
+
order_2.contents.add(variant_2, 1)
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should create errors with invalid line items" do
|
127
|
+
# we cannot use .destroy here as it will be halted by
|
128
|
+
# :ensure_no_line_items callback
|
129
|
+
variant_2.really_destroy!
|
130
|
+
subject.merge!(order_2)
|
131
|
+
expect(order_1.errors.full_messages).not_to be_empty
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,1067 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
class FakeCalculator < Spree::Calculator
|
4
|
+
def compute(computable)
|
5
|
+
5
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
describe Spree::Order, type: :model do
|
10
|
+
let(:user) { stub_model(Spree::LegacyUser, email: "spree@example.com") }
|
11
|
+
let(:order) { stub_model(Spree::Order, user: user) }
|
12
|
+
|
13
|
+
before do
|
14
|
+
create(:store)
|
15
|
+
allow(Spree::LegacyUser).to receive_messages(current: mock_model(Spree::LegacyUser, id: 123))
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '.scopes' do
|
19
|
+
let!(:user) { FactoryGirl.create(:user) }
|
20
|
+
let!(:completed_order) { FactoryGirl.create(:order, user: user, completed_at: Time.current) }
|
21
|
+
let!(:incompleted_order) { FactoryGirl.create(:order, user: user, completed_at: nil) }
|
22
|
+
|
23
|
+
describe '.complete' do
|
24
|
+
it { expect(Spree::Order.complete).to include completed_order }
|
25
|
+
it { expect(Spree::Order.complete).not_to include incompleted_order }
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '.incomplete' do
|
29
|
+
it { expect(Spree::Order.incomplete).to include incompleted_order }
|
30
|
+
it { expect(Spree::Order.incomplete).not_to include completed_order }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
describe '#update_with_updater!' do
|
35
|
+
let(:updater) { Spree::OrderUpdater.new(order) }
|
36
|
+
|
37
|
+
before do
|
38
|
+
allow(order).to receive(:updater).and_return(updater)
|
39
|
+
allow(updater).to receive(:update).and_return(true)
|
40
|
+
end
|
41
|
+
|
42
|
+
after { order.update_with_updater! }
|
43
|
+
|
44
|
+
it 'expects to update order with order updater' do
|
45
|
+
expect(updater).to receive(:update).and_return(true)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context "#cancel" do
|
50
|
+
let(:order) { create(:completed_order_with_totals) }
|
51
|
+
let!(:payment) do
|
52
|
+
create(
|
53
|
+
:payment,
|
54
|
+
order: order,
|
55
|
+
amount: order.total,
|
56
|
+
state: "completed"
|
57
|
+
)
|
58
|
+
end
|
59
|
+
let(:payment_method) { double }
|
60
|
+
|
61
|
+
it "should mark the payments as void" do
|
62
|
+
allow_any_instance_of(Spree::Shipment).to receive(:refresh_rates).and_return(true)
|
63
|
+
order.cancel
|
64
|
+
order.reload
|
65
|
+
|
66
|
+
expect(order.payments.first).to be_void
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "#canceled_by" do
|
71
|
+
let(:admin_user) { create :admin_user }
|
72
|
+
let(:order) { create :order }
|
73
|
+
|
74
|
+
before do
|
75
|
+
allow(order).to receive(:cancel!)
|
76
|
+
end
|
77
|
+
|
78
|
+
subject { order.canceled_by(admin_user) }
|
79
|
+
|
80
|
+
it 'should cancel the order' do
|
81
|
+
expect(order).to receive(:cancel!)
|
82
|
+
subject
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should save canceler_id' do
|
86
|
+
subject
|
87
|
+
expect(order.reload.canceler_id).to eq(admin_user.id)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should save canceled_at' do
|
91
|
+
subject
|
92
|
+
expect(order.reload.canceled_at).to_not be_nil
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should have canceler' do
|
96
|
+
subject
|
97
|
+
expect(order.reload.canceler).to eq(admin_user)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context '#create' do
|
102
|
+
let(:order) { Spree::Order.create }
|
103
|
+
|
104
|
+
it 'should assign an order number' do
|
105
|
+
expect(order.number).not_to be_nil
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should create a randomized 35 character token' do
|
109
|
+
expect(order.guest_token.size).to eq(35)
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context "creates shipments cost" do
|
114
|
+
let(:shipment) { double }
|
115
|
+
|
116
|
+
before { allow(order).to receive_messages shipments: [shipment] }
|
117
|
+
|
118
|
+
it "update and persist totals" do
|
119
|
+
expect(shipment).to receive :update_amounts
|
120
|
+
expect(order.updater).to receive :update_shipment_total
|
121
|
+
expect(order.updater).to receive :persist_totals
|
122
|
+
|
123
|
+
order.set_shipments_cost
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
context "#finalize!" do
|
128
|
+
let(:order) { Spree::Order.create(email: 'test@example.com') }
|
129
|
+
|
130
|
+
before do
|
131
|
+
order.update_column :state, 'complete'
|
132
|
+
end
|
133
|
+
|
134
|
+
it "should set completed_at" do
|
135
|
+
expect(order).to receive(:touch).with(:completed_at)
|
136
|
+
order.finalize!
|
137
|
+
end
|
138
|
+
|
139
|
+
it "should sell inventory units" do
|
140
|
+
order.shipments.each do |shipment|
|
141
|
+
expect(shipment).to receive(:update!)
|
142
|
+
expect(shipment).to receive(:finalize!)
|
143
|
+
end
|
144
|
+
order.finalize!
|
145
|
+
end
|
146
|
+
|
147
|
+
it "should decrease the stock for each variant in the shipment" do
|
148
|
+
order.shipments.each do |shipment|
|
149
|
+
expect(shipment.stock_location).to receive(:decrease_stock_for_variant)
|
150
|
+
end
|
151
|
+
order.finalize!
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should change the shipment state to ready if order is paid" do
|
155
|
+
Spree::Shipment.create(order: order, stock_location: create(:stock_location))
|
156
|
+
order.shipments.reload
|
157
|
+
|
158
|
+
allow(order).to receive_messages(paid?: true, complete?: true)
|
159
|
+
order.finalize!
|
160
|
+
order.reload # reload so we're sure the changes are persisted
|
161
|
+
expect(order.shipment_state).to eq('ready')
|
162
|
+
end
|
163
|
+
|
164
|
+
after { Spree::Config.set track_inventory_levels: true }
|
165
|
+
it "should not sell inventory units if track_inventory_levels is false" do
|
166
|
+
Spree::Config.set track_inventory_levels: false
|
167
|
+
expect(Spree::InventoryUnit).not_to receive(:sell_units)
|
168
|
+
order.finalize!
|
169
|
+
end
|
170
|
+
|
171
|
+
it "should send an order confirmation email" do
|
172
|
+
mail_message = double "Mail::Message"
|
173
|
+
expect(Spree::OrderMailer).to receive(:confirm_email).with(order.id).and_return mail_message
|
174
|
+
expect(mail_message).to receive :deliver_later
|
175
|
+
order.finalize!
|
176
|
+
end
|
177
|
+
|
178
|
+
it "sets confirmation delivered when finalizing" do
|
179
|
+
expect(order.confirmation_delivered?).to be false
|
180
|
+
order.finalize!
|
181
|
+
expect(order.confirmation_delivered?).to be true
|
182
|
+
end
|
183
|
+
|
184
|
+
it "should not send duplicate confirmation emails" do
|
185
|
+
allow(order).to receive_messages(confirmation_delivered?: true)
|
186
|
+
expect(Spree::OrderMailer).not_to receive(:confirm_email)
|
187
|
+
order.finalize!
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should freeze all adjustments" do
|
191
|
+
allow(Spree::OrderMailer).to receive_message_chain :confirm_email, :deliver_later
|
192
|
+
adjustments = [double]
|
193
|
+
expect(order).to receive(:all_adjustments).and_return(adjustments)
|
194
|
+
adjustments.each do |adj|
|
195
|
+
expect(adj).to receive(:close)
|
196
|
+
end
|
197
|
+
order.finalize!
|
198
|
+
end
|
199
|
+
|
200
|
+
context "order is considered risky" do
|
201
|
+
before do
|
202
|
+
allow(order).to receive_messages is_risky?: true
|
203
|
+
end
|
204
|
+
|
205
|
+
it "should change state to risky" do
|
206
|
+
expect(order).to receive(:considered_risky!)
|
207
|
+
order.finalize!
|
208
|
+
end
|
209
|
+
|
210
|
+
context "and order is approved" do
|
211
|
+
before do
|
212
|
+
allow(order).to receive_messages approved?: true
|
213
|
+
end
|
214
|
+
|
215
|
+
it "should leave order in complete state" do
|
216
|
+
order.finalize!
|
217
|
+
expect(order.state).to eq 'complete'
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
context "insufficient_stock_lines" do
|
224
|
+
let(:line_item) { mock_model Spree::LineItem, insufficient_stock?: true }
|
225
|
+
|
226
|
+
before { allow(order).to receive_messages(line_items: [line_item]) }
|
227
|
+
|
228
|
+
it "should return line_item that has insufficient stock on hand" do
|
229
|
+
expect(order.insufficient_stock_lines.size).to eq(1)
|
230
|
+
expect(order.insufficient_stock_lines.include?(line_item)).to be true
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
describe "#ensure_line_item_variants_are_not_discontinued" do
|
235
|
+
subject { order.ensure_line_item_variants_are_not_discontinued }
|
236
|
+
|
237
|
+
let(:order) { create :order_with_line_items }
|
238
|
+
|
239
|
+
context 'when variant is destroyed' do
|
240
|
+
before do
|
241
|
+
order.line_items.first.variant.discontinue!
|
242
|
+
end
|
243
|
+
|
244
|
+
it 'should restart checkout flow' do
|
245
|
+
expect(order).to receive(:restart_checkout_flow).once
|
246
|
+
subject
|
247
|
+
end
|
248
|
+
|
249
|
+
it 'should have error message' do
|
250
|
+
subject
|
251
|
+
expect(order.errors[:base]).to include(Spree.t(:discontinued_variants_present))
|
252
|
+
end
|
253
|
+
|
254
|
+
it 'should be false' do
|
255
|
+
expect(subject).to be_falsey
|
256
|
+
end
|
257
|
+
end
|
258
|
+
|
259
|
+
context 'when no variants are destroyed' do
|
260
|
+
it 'should not restart checkout' do
|
261
|
+
expect(order).to receive(:restart_checkout_flow).never
|
262
|
+
subject
|
263
|
+
end
|
264
|
+
|
265
|
+
it 'should be true' do
|
266
|
+
expect(subject).to be_truthy
|
267
|
+
end
|
268
|
+
end
|
269
|
+
end
|
270
|
+
|
271
|
+
describe '#ensure_line_items_are_in_stock' do
|
272
|
+
subject { order.ensure_line_items_are_in_stock }
|
273
|
+
|
274
|
+
let(:line_item) { create(:line_item, order: order) }
|
275
|
+
|
276
|
+
before do
|
277
|
+
allow(order).to receive(:insufficient_stock_lines).and_return([true])
|
278
|
+
end
|
279
|
+
|
280
|
+
it 'should restart checkout flow' do
|
281
|
+
allow(order).to receive(:restart_checkout_flow)
|
282
|
+
expect(order).to receive(:restart_checkout_flow).once
|
283
|
+
subject
|
284
|
+
end
|
285
|
+
|
286
|
+
it 'should have error message' do
|
287
|
+
subject
|
288
|
+
expect(order.errors[:base]).to include(Spree.t(:insufficient_stock_lines_present))
|
289
|
+
end
|
290
|
+
|
291
|
+
it 'should be false' do
|
292
|
+
allow(order).to receive(:restart_checkout_flow)
|
293
|
+
expect(subject).to be_falsey
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
context "empty!" do
|
298
|
+
let(:order) { Spree::Order.create(email: 'test@example.com') }
|
299
|
+
let(:promotion) { create :promotion, code: '10off' }
|
300
|
+
|
301
|
+
before do
|
302
|
+
promotion.orders << order
|
303
|
+
end
|
304
|
+
|
305
|
+
context 'completed order' do
|
306
|
+
before do
|
307
|
+
order.update_columns(state: 'complete', completed_at: Time.current)
|
308
|
+
end
|
309
|
+
|
310
|
+
it "raises an exception" do
|
311
|
+
expect { order.empty! }.to raise_error(RuntimeError, Spree.t(:cannot_empty_completed_order))
|
312
|
+
end
|
313
|
+
end
|
314
|
+
|
315
|
+
context 'incomplete order' do
|
316
|
+
before do
|
317
|
+
order.empty!
|
318
|
+
end
|
319
|
+
|
320
|
+
it "clears out line items, adjustments and update totals" do
|
321
|
+
expect(order.line_items.count).to be_zero
|
322
|
+
expect(order.adjustments.count).to be_zero
|
323
|
+
expect(order.shipments.count).to be_zero
|
324
|
+
expect(order.order_promotions.count).to be_zero
|
325
|
+
expect(order.promo_total).to be_zero
|
326
|
+
expect(order.item_total).to be_zero
|
327
|
+
expect(order.empty!).to eq(order)
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
context "#display_outstanding_balance" do
|
333
|
+
it "returns the value as a spree money" do
|
334
|
+
allow(order).to receive(:outstanding_balance) { 10.55 }
|
335
|
+
expect(order.display_outstanding_balance).to eq(Spree::Money.new(10.55))
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context "#display_item_total" do
|
340
|
+
it "returns the value as a spree money" do
|
341
|
+
allow(order).to receive(:item_total) { 10.55 }
|
342
|
+
expect(order.display_item_total).to eq(Spree::Money.new(10.55))
|
343
|
+
end
|
344
|
+
end
|
345
|
+
|
346
|
+
context "#display_adjustment_total" do
|
347
|
+
it "returns the value as a spree money" do
|
348
|
+
order.adjustment_total = 10.55
|
349
|
+
expect(order.display_adjustment_total).to eq(Spree::Money.new(10.55))
|
350
|
+
end
|
351
|
+
end
|
352
|
+
|
353
|
+
context "#display_promo_total" do
|
354
|
+
it "returns the value as a spree money" do
|
355
|
+
order.promo_total = 10.55
|
356
|
+
expect(order.display_promo_total).to eq(Spree::Money.new(10.55))
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
context "#display_total" do
|
361
|
+
it "returns the value as a spree money" do
|
362
|
+
order.total = 10.55
|
363
|
+
expect(order.display_total).to eq(Spree::Money.new(10.55))
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
context "#currency" do
|
368
|
+
context "when object currency is ABC" do
|
369
|
+
before { order.currency = "ABC" }
|
370
|
+
|
371
|
+
it "returns the currency from the object" do
|
372
|
+
expect(order.currency).to eq("ABC")
|
373
|
+
end
|
374
|
+
end
|
375
|
+
|
376
|
+
context "when object currency is nil" do
|
377
|
+
before { order.currency = nil }
|
378
|
+
|
379
|
+
it "returns the globally configured currency" do
|
380
|
+
expect(order.currency).to eq("USD")
|
381
|
+
end
|
382
|
+
end
|
383
|
+
end
|
384
|
+
|
385
|
+
context "#confirmation_required?" do
|
386
|
+
|
387
|
+
# Regression test for #4117
|
388
|
+
it "is required if the state is currently 'confirm'" do
|
389
|
+
order = Spree::Order.new
|
390
|
+
assert !order.confirmation_required?
|
391
|
+
order.state = 'confirm'
|
392
|
+
assert order.confirmation_required?
|
393
|
+
end
|
394
|
+
|
395
|
+
context 'Spree::Config[:always_include_confirm_step] == true' do
|
396
|
+
|
397
|
+
before do
|
398
|
+
Spree::Config[:always_include_confirm_step] = true
|
399
|
+
end
|
400
|
+
|
401
|
+
it "returns true if payments empty" do
|
402
|
+
order = Spree::Order.new
|
403
|
+
assert order.confirmation_required?
|
404
|
+
end
|
405
|
+
end
|
406
|
+
|
407
|
+
context 'Spree::Config[:always_include_confirm_step] == false' do
|
408
|
+
|
409
|
+
it "returns false if payments empty and Spree::Config[:always_include_confirm_step] == false" do
|
410
|
+
order = Spree::Order.new
|
411
|
+
assert !order.confirmation_required?
|
412
|
+
end
|
413
|
+
|
414
|
+
it "does not bomb out when an order has an unpersisted payment" do
|
415
|
+
order = Spree::Order.new
|
416
|
+
order.payments.build
|
417
|
+
assert !order.confirmation_required?
|
418
|
+
end
|
419
|
+
end
|
420
|
+
end
|
421
|
+
|
422
|
+
|
423
|
+
context "add_update_hook" do
|
424
|
+
before do
|
425
|
+
Spree::Order.class_eval do
|
426
|
+
register_update_hook :add_awesome_sauce
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
after do
|
431
|
+
Spree::Order.update_hooks = Set.new
|
432
|
+
end
|
433
|
+
|
434
|
+
it "calls hook during update" do
|
435
|
+
order = create(:order)
|
436
|
+
expect(order).to receive(:add_awesome_sauce)
|
437
|
+
order.update_with_updater!
|
438
|
+
end
|
439
|
+
|
440
|
+
it "calls hook during finalize" do
|
441
|
+
order = create(:order)
|
442
|
+
expect(order).to receive(:add_awesome_sauce)
|
443
|
+
order.finalize!
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
describe "#tax_address" do
|
448
|
+
before { Spree::Config[:tax_using_ship_address] = tax_using_ship_address }
|
449
|
+
subject { order.tax_address }
|
450
|
+
|
451
|
+
context "when tax_using_ship_address is true" do
|
452
|
+
let(:tax_using_ship_address) { true }
|
453
|
+
|
454
|
+
it 'returns ship_address' do
|
455
|
+
expect(subject).to eq(order.ship_address)
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
context "when tax_using_ship_address is not true" do
|
460
|
+
let(:tax_using_ship_address) { false }
|
461
|
+
|
462
|
+
it "returns bill_address" do
|
463
|
+
expect(subject).to eq(order.bill_address)
|
464
|
+
end
|
465
|
+
end
|
466
|
+
end
|
467
|
+
|
468
|
+
describe "#restart_checkout_flow" do
|
469
|
+
it "updates the state column to the first checkout_steps value" do
|
470
|
+
order = create(:order_with_totals, state: "delivery")
|
471
|
+
expect(order.checkout_steps).to eql ["address", "delivery", "complete"]
|
472
|
+
expect{ order.restart_checkout_flow }.to change{order.state}.from("delivery").to("address")
|
473
|
+
end
|
474
|
+
|
475
|
+
context "without line items" do
|
476
|
+
it "updates the state column to cart" do
|
477
|
+
order = create(:order, state: "delivery")
|
478
|
+
expect{ order.restart_checkout_flow }.to change{order.state}.from("delivery").to("cart")
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
482
|
+
|
483
|
+
# Regression tests for #4072
|
484
|
+
context "#state_changed" do
|
485
|
+
let(:order) { FactoryGirl.create(:order) }
|
486
|
+
|
487
|
+
it "logs state changes" do
|
488
|
+
order.update_column(:payment_state, 'balance_due')
|
489
|
+
order.payment_state = 'paid'
|
490
|
+
expect(order.state_changes).to be_empty
|
491
|
+
order.state_changed('payment')
|
492
|
+
state_change = order.state_changes.find_by(name: 'payment')
|
493
|
+
expect(state_change.previous_state).to eq('balance_due')
|
494
|
+
expect(state_change.next_state).to eq('paid')
|
495
|
+
end
|
496
|
+
|
497
|
+
it "does not do anything if state does not change" do
|
498
|
+
order.update_column(:payment_state, 'balance_due')
|
499
|
+
expect(order.state_changes).to be_empty
|
500
|
+
order.state_changed('payment')
|
501
|
+
expect(order.state_changes).to be_empty
|
502
|
+
end
|
503
|
+
end
|
504
|
+
|
505
|
+
# Regression test for #4199
|
506
|
+
context "#available_payment_methods" do
|
507
|
+
it "includes frontend payment methods" do
|
508
|
+
payment_method = Spree::PaymentMethod.create!({
|
509
|
+
name: "Fake",
|
510
|
+
active: true,
|
511
|
+
display_on: "front_end",
|
512
|
+
})
|
513
|
+
expect(order.available_payment_methods).to include(payment_method)
|
514
|
+
end
|
515
|
+
|
516
|
+
it "includes 'both' payment methods" do
|
517
|
+
payment_method = Spree::PaymentMethod.create!({
|
518
|
+
name: "Fake",
|
519
|
+
active: true,
|
520
|
+
display_on: "both",
|
521
|
+
})
|
522
|
+
expect(order.available_payment_methods).to include(payment_method)
|
523
|
+
end
|
524
|
+
|
525
|
+
it "does not include a payment method twice if display_on is blank" do
|
526
|
+
payment_method = Spree::PaymentMethod.create!({
|
527
|
+
name: "Fake",
|
528
|
+
active: true,
|
529
|
+
display_on: "both",
|
530
|
+
})
|
531
|
+
expect(order.available_payment_methods.count).to eq(1)
|
532
|
+
expect(order.available_payment_methods).to include(payment_method)
|
533
|
+
end
|
534
|
+
|
535
|
+
let(:ok_method) { double :payment_method, available_for_order?: true }
|
536
|
+
let(:no_method) { double :payment_method, available_for_order?: false }
|
537
|
+
let(:methods) { [ok_method, no_method] }
|
538
|
+
|
539
|
+
it "does not include a payment method that is not suitable for this order" do
|
540
|
+
allow(Spree::PaymentMethod).to receive(:available_on_front_end).and_return(methods)
|
541
|
+
expect(order.available_payment_methods).to match_array [ok_method]
|
542
|
+
end
|
543
|
+
end
|
544
|
+
|
545
|
+
context "#apply_free_shipping_promotions" do
|
546
|
+
it "calls out to the FreeShipping promotion handler" do
|
547
|
+
shipment = double('Shipment')
|
548
|
+
allow(order).to receive_messages shipments: [shipment]
|
549
|
+
expect(Spree::PromotionHandler::FreeShipping).to receive(:new).and_return(handler = double)
|
550
|
+
expect(handler).to receive(:activate)
|
551
|
+
|
552
|
+
expect(Spree::Adjustable::AdjustmentsUpdater).to receive(:update).with(shipment)
|
553
|
+
|
554
|
+
expect(order.updater).to receive(:update_shipment_total)
|
555
|
+
expect(order.updater).to receive(:persist_totals)
|
556
|
+
order.apply_free_shipping_promotions
|
557
|
+
end
|
558
|
+
end
|
559
|
+
|
560
|
+
|
561
|
+
context "#products" do
|
562
|
+
before :each do
|
563
|
+
@variant1 = mock_model(Spree::Variant, product: "product1")
|
564
|
+
@variant2 = mock_model(Spree::Variant, product: "product2")
|
565
|
+
@line_items = [mock_model(Spree::LineItem, product: "product1", variant: @variant1, variant_id: @variant1.id, quantity: 1),
|
566
|
+
mock_model(Spree::LineItem, product: "product2", variant: @variant2, variant_id: @variant2.id, quantity: 2)]
|
567
|
+
allow(order).to receive_messages(line_items: @line_items)
|
568
|
+
end
|
569
|
+
|
570
|
+
it "gets the quantity of a given variant" do
|
571
|
+
expect(order.quantity_of(@variant1)).to eq(1)
|
572
|
+
|
573
|
+
@variant3 = mock_model(Spree::Variant, product: "product3")
|
574
|
+
expect(order.quantity_of(@variant3)).to eq(0)
|
575
|
+
end
|
576
|
+
|
577
|
+
it "can find a line item matching a given variant" do
|
578
|
+
expect(order.find_line_item_by_variant(@variant1)).not_to be_nil
|
579
|
+
expect(order.find_line_item_by_variant(mock_model(Spree::Variant))).to be_nil
|
580
|
+
end
|
581
|
+
|
582
|
+
context "match line item with options" do
|
583
|
+
before do
|
584
|
+
Spree::Order.register_line_item_comparison_hook(:foos_match)
|
585
|
+
end
|
586
|
+
|
587
|
+
after do
|
588
|
+
# reset to avoid test pollution
|
589
|
+
Spree::Order.line_item_comparison_hooks = Set.new
|
590
|
+
end
|
591
|
+
|
592
|
+
it "matches line item when options match" do
|
593
|
+
allow(order).to receive(:foos_match).and_return(true)
|
594
|
+
expect(order.line_item_options_match(@line_items.first, {foos: {bar: :zoo}})).to be true
|
595
|
+
end
|
596
|
+
|
597
|
+
it "does not match line item without options" do
|
598
|
+
allow(order).to receive(:foos_match).and_return(false)
|
599
|
+
expect(order.line_item_options_match(@line_items.first, {})).to be false
|
600
|
+
end
|
601
|
+
end
|
602
|
+
end
|
603
|
+
|
604
|
+
describe "#associate_user!" do
|
605
|
+
let(:user) { FactoryGirl.create(:user_with_addreses) }
|
606
|
+
let(:email) { user.email }
|
607
|
+
let(:created_by) { user }
|
608
|
+
let(:bill_address) { user.bill_address }
|
609
|
+
let(:ship_address) { user.ship_address }
|
610
|
+
let(:override_email) { true }
|
611
|
+
|
612
|
+
let(:order) { FactoryGirl.build(:order, order_attributes) }
|
613
|
+
|
614
|
+
let(:order_attributes) do
|
615
|
+
{
|
616
|
+
user: nil,
|
617
|
+
email: nil,
|
618
|
+
created_by: nil,
|
619
|
+
bill_address: nil,
|
620
|
+
ship_address: nil
|
621
|
+
}
|
622
|
+
end
|
623
|
+
|
624
|
+
def assert_expected_order_state
|
625
|
+
expect(order.user).to eql(user)
|
626
|
+
expect(order.user_id).to eql(user.id)
|
627
|
+
|
628
|
+
expect(order.email).to eql(email)
|
629
|
+
|
630
|
+
expect(order.created_by).to eql(created_by)
|
631
|
+
expect(order.created_by_id).to eql(created_by.id)
|
632
|
+
|
633
|
+
expect(order.bill_address).to eql(bill_address)
|
634
|
+
expect(order.bill_address_id).to eql(bill_address.id)
|
635
|
+
|
636
|
+
expect(order.ship_address).to eql(ship_address)
|
637
|
+
expect(order.ship_address_id).to eql(ship_address.id)
|
638
|
+
end
|
639
|
+
|
640
|
+
shared_examples_for "#associate_user!" do |persisted = false|
|
641
|
+
it "associates a user to an order" do
|
642
|
+
order.associate_user!(user, override_email)
|
643
|
+
assert_expected_order_state
|
644
|
+
end
|
645
|
+
|
646
|
+
unless persisted
|
647
|
+
it "does not persist the order" do
|
648
|
+
expect { order.associate_user!(user) }
|
649
|
+
.to_not change(order, :persisted?)
|
650
|
+
.from(false)
|
651
|
+
end
|
652
|
+
end
|
653
|
+
end
|
654
|
+
|
655
|
+
context "when email is set" do
|
656
|
+
let(:order_attributes) { super().merge(email: 'test@example.com') }
|
657
|
+
|
658
|
+
context "when email should be overridden" do
|
659
|
+
it_should_behave_like "#associate_user!"
|
660
|
+
end
|
661
|
+
|
662
|
+
context "when email should not be overridden" do
|
663
|
+
let(:override_email) { false }
|
664
|
+
let(:email) { 'test@example.com' }
|
665
|
+
|
666
|
+
it_should_behave_like "#associate_user!"
|
667
|
+
end
|
668
|
+
end
|
669
|
+
|
670
|
+
context "when created_by is set" do
|
671
|
+
let(:order_attributes) { super().merge(created_by: created_by) }
|
672
|
+
let(:created_by) { create(:user_with_addreses) }
|
673
|
+
|
674
|
+
it_should_behave_like "#associate_user!"
|
675
|
+
end
|
676
|
+
|
677
|
+
context "when bill_address is set" do
|
678
|
+
let(:order_attributes) { super().merge(bill_address: bill_address) }
|
679
|
+
let(:bill_address) { FactoryGirl.build(:address) }
|
680
|
+
|
681
|
+
it_should_behave_like "#associate_user!"
|
682
|
+
end
|
683
|
+
|
684
|
+
context "when ship_address is set" do
|
685
|
+
let(:order_attributes) { super().merge(ship_address: ship_address) }
|
686
|
+
let(:ship_address) { FactoryGirl.build(:address) }
|
687
|
+
|
688
|
+
it_should_behave_like "#associate_user!"
|
689
|
+
end
|
690
|
+
|
691
|
+
context "when the user is not persisted" do
|
692
|
+
let(:user) { FactoryGirl.build(:user_with_addreses) }
|
693
|
+
|
694
|
+
it "does not persist the user" do
|
695
|
+
expect { order.associate_user!(user) }
|
696
|
+
.to_not change(user, :persisted?)
|
697
|
+
.from(false)
|
698
|
+
end
|
699
|
+
|
700
|
+
it_should_behave_like "#associate_user!"
|
701
|
+
end
|
702
|
+
|
703
|
+
context "when the order is persisted" do
|
704
|
+
let(:order) { FactoryGirl.create(:order, order_attributes) }
|
705
|
+
|
706
|
+
it "associates a user to a persisted order" do
|
707
|
+
order.associate_user!(user)
|
708
|
+
order.reload
|
709
|
+
assert_expected_order_state
|
710
|
+
end
|
711
|
+
|
712
|
+
it "does not persist other changes to the order" do
|
713
|
+
order.state = 'complete'
|
714
|
+
order.associate_user!(user)
|
715
|
+
order.reload
|
716
|
+
expect(order.state).to eql('cart')
|
717
|
+
end
|
718
|
+
|
719
|
+
it "does not change any other orders" do
|
720
|
+
other = FactoryGirl.create(:order)
|
721
|
+
order.associate_user!(user)
|
722
|
+
expect(other.reload.user).to_not eql(user)
|
723
|
+
end
|
724
|
+
|
725
|
+
it "is not affected by scoping" do
|
726
|
+
order.class.where.not(id: order).scoping do
|
727
|
+
order.associate_user!(user)
|
728
|
+
end
|
729
|
+
order.reload
|
730
|
+
assert_expected_order_state
|
731
|
+
end
|
732
|
+
|
733
|
+
it_should_behave_like "#associate_user!", true
|
734
|
+
end
|
735
|
+
end
|
736
|
+
|
737
|
+
context "#can_ship?" do
|
738
|
+
let(:order) { Spree::Order.create }
|
739
|
+
|
740
|
+
it "should be true for order in the 'complete' state" do
|
741
|
+
allow(order).to receive_messages(complete?: true)
|
742
|
+
expect(order.can_ship?).to be true
|
743
|
+
end
|
744
|
+
|
745
|
+
it "should be true for order in the 'resumed' state" do
|
746
|
+
allow(order).to receive_messages(resumed?: true)
|
747
|
+
expect(order.can_ship?).to be true
|
748
|
+
end
|
749
|
+
|
750
|
+
it "should be true for an order in the 'awaiting return' state" do
|
751
|
+
allow(order).to receive_messages(awaiting_return?: true)
|
752
|
+
expect(order.can_ship?).to be true
|
753
|
+
end
|
754
|
+
|
755
|
+
it "should be true for an order in the 'returned' state" do
|
756
|
+
allow(order).to receive_messages(returned?: true)
|
757
|
+
expect(order.can_ship?).to be true
|
758
|
+
end
|
759
|
+
|
760
|
+
it "should be false if the order is neither in the 'complete' nor 'resumed' state" do
|
761
|
+
allow(order).to receive_messages(resumed?: false, complete?: false)
|
762
|
+
expect(order.can_ship?).to be false
|
763
|
+
end
|
764
|
+
end
|
765
|
+
|
766
|
+
context "#completed?" do
|
767
|
+
it "should indicate if order is completed" do
|
768
|
+
order.completed_at = nil
|
769
|
+
expect(order.completed?).to be false
|
770
|
+
|
771
|
+
order.completed_at = Time.current
|
772
|
+
expect(order.completed?).to be true
|
773
|
+
end
|
774
|
+
end
|
775
|
+
|
776
|
+
context "#allow_checkout?" do
|
777
|
+
it "should be true if there are line_items in the order" do
|
778
|
+
allow(order).to receive_message_chain(:line_items, count: 1)
|
779
|
+
expect(order.checkout_allowed?).to be true
|
780
|
+
end
|
781
|
+
it "should be false if there are no line_items in the order" do
|
782
|
+
allow(order).to receive_message_chain(:line_items, count: 0)
|
783
|
+
expect(order.checkout_allowed?).to be false
|
784
|
+
end
|
785
|
+
end
|
786
|
+
|
787
|
+
context "#amount" do
|
788
|
+
before do
|
789
|
+
@order = create(:order, user: user)
|
790
|
+
@order.line_items = [create(:line_item, price: 1.0, quantity: 2),
|
791
|
+
create(:line_item, price: 1.0, quantity: 1)]
|
792
|
+
end
|
793
|
+
it "should return the correct lum sum of items" do
|
794
|
+
expect(@order.amount).to eq(3.0)
|
795
|
+
end
|
796
|
+
end
|
797
|
+
|
798
|
+
context "#backordered?" do
|
799
|
+
it 'is backordered if one of the shipments is backordered' do
|
800
|
+
allow(order).to receive_messages(shipments: [mock_model(Spree::Shipment, backordered?: false),
|
801
|
+
mock_model(Spree::Shipment, backordered?: true)])
|
802
|
+
expect(order).to be_backordered
|
803
|
+
end
|
804
|
+
end
|
805
|
+
|
806
|
+
context "#can_cancel?" do
|
807
|
+
it "should be false for completed order in the canceled state" do
|
808
|
+
order.state = 'canceled'
|
809
|
+
order.shipment_state = 'ready'
|
810
|
+
order.completed_at = Time.current
|
811
|
+
expect(order.can_cancel?).to be false
|
812
|
+
end
|
813
|
+
|
814
|
+
it "should be true for completed order with no shipment" do
|
815
|
+
order.state = 'complete'
|
816
|
+
order.shipment_state = nil
|
817
|
+
order.completed_at = Time.current
|
818
|
+
expect(order.can_cancel?).to be true
|
819
|
+
end
|
820
|
+
end
|
821
|
+
|
822
|
+
context "#tax_total" do
|
823
|
+
it "adds included tax and additional tax" do
|
824
|
+
allow(order).to receive_messages(additional_tax_total: 10, included_tax_total: 20)
|
825
|
+
|
826
|
+
expect(order.tax_total).to eq 30
|
827
|
+
end
|
828
|
+
end
|
829
|
+
|
830
|
+
# Regression test for #4923
|
831
|
+
context "locking" do
|
832
|
+
let(:order) { Spree::Order.create } # need a persisted in order to test locking
|
833
|
+
|
834
|
+
it 'can lock' do
|
835
|
+
expect { order.with_lock {} }.to_not raise_error
|
836
|
+
end
|
837
|
+
end
|
838
|
+
|
839
|
+
describe "#pre_tax_item_amount" do
|
840
|
+
it "sums all of the line items' pre tax amounts" do
|
841
|
+
subject.line_items = [
|
842
|
+
Spree::LineItem.new(price: 10, quantity: 2, pre_tax_amount: 5.0),
|
843
|
+
Spree::LineItem.new(price: 30, quantity: 1, pre_tax_amount: 14.0),
|
844
|
+
]
|
845
|
+
|
846
|
+
expect(subject.pre_tax_item_amount).to eq 19.0
|
847
|
+
end
|
848
|
+
end
|
849
|
+
|
850
|
+
describe '#quantity' do
|
851
|
+
# Uses a persisted record, as the quantity is retrieved via a DB count
|
852
|
+
let(:order) { create :order_with_line_items, line_items_count: 3 }
|
853
|
+
|
854
|
+
it 'sums the quantity of all line items' do
|
855
|
+
expect(order.quantity).to eq 3
|
856
|
+
end
|
857
|
+
end
|
858
|
+
|
859
|
+
describe '#has_non_reimbursement_related_refunds?' do
|
860
|
+
subject do
|
861
|
+
order.has_non_reimbursement_related_refunds?
|
862
|
+
end
|
863
|
+
|
864
|
+
context 'no refunds exist' do
|
865
|
+
it { is_expected.to eq false }
|
866
|
+
end
|
867
|
+
|
868
|
+
context 'a non-reimbursement related refund exists' do
|
869
|
+
let(:order) { refund.payment.order }
|
870
|
+
let(:refund) { create(:refund, reimbursement_id: nil, amount: 5) }
|
871
|
+
|
872
|
+
it { is_expected.to eq true }
|
873
|
+
end
|
874
|
+
|
875
|
+
context 'an old-style refund exists' do
|
876
|
+
let(:order) { create(:order_ready_to_ship) }
|
877
|
+
let(:payment) { order.payments.first.tap { |p| allow(p).to receive_messages(profiles_supported: false) } }
|
878
|
+
let!(:refund_payment) {
|
879
|
+
build(:payment, amount: -1, order: order, state: 'completed', source: payment).tap do |p|
|
880
|
+
allow(p).to receive_messages(profiles_supported?: false)
|
881
|
+
p.save!
|
882
|
+
end
|
883
|
+
}
|
884
|
+
|
885
|
+
it { is_expected.to eq true }
|
886
|
+
end
|
887
|
+
|
888
|
+
context 'a reimbursement related refund exists' do
|
889
|
+
let(:order) { refund.payment.order }
|
890
|
+
let(:refund) { create(:refund, reimbursement_id: 123, amount: 5)}
|
891
|
+
|
892
|
+
it { is_expected.to eq false }
|
893
|
+
end
|
894
|
+
end
|
895
|
+
|
896
|
+
describe "#create_proposed_shipments" do
|
897
|
+
context 'has unassociated inventory units' do
|
898
|
+
let!(:inventory_unit) { create(:inventory_unit, order: subject) }
|
899
|
+
|
900
|
+
before(:each) do
|
901
|
+
inventory_unit.update_column(:shipment_id, nil)
|
902
|
+
end
|
903
|
+
|
904
|
+
context 'when shipped' do
|
905
|
+
before(:each) do
|
906
|
+
inventory_unit.update_column(:state, 'shipped')
|
907
|
+
end
|
908
|
+
|
909
|
+
it 'does not delete inventory_unit' do
|
910
|
+
subject.create_proposed_shipments
|
911
|
+
expect(inventory_unit.reload).to eq inventory_unit
|
912
|
+
end
|
913
|
+
end
|
914
|
+
|
915
|
+
context 'when returned' do
|
916
|
+
before(:each) do
|
917
|
+
inventory_unit.update_column(:state, 'returned')
|
918
|
+
end
|
919
|
+
|
920
|
+
it 'does not delete inventory_unit' do
|
921
|
+
subject.create_proposed_shipments
|
922
|
+
expect(inventory_unit.reload).to eq inventory_unit
|
923
|
+
end
|
924
|
+
end
|
925
|
+
|
926
|
+
context 'when on_hand' do
|
927
|
+
before(:each) do
|
928
|
+
inventory_unit.update_column(:state, 'on_hand')
|
929
|
+
end
|
930
|
+
|
931
|
+
it 'deletes inventory_unit' do
|
932
|
+
subject.create_proposed_shipments
|
933
|
+
expect { inventory_unit.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
934
|
+
end
|
935
|
+
end
|
936
|
+
|
937
|
+
context 'when backordered' do
|
938
|
+
before(:each) do
|
939
|
+
inventory_unit.update_column(:state, 'backordered')
|
940
|
+
end
|
941
|
+
|
942
|
+
it 'deletes inventory_unit' do
|
943
|
+
subject.create_proposed_shipments
|
944
|
+
expect { inventory_unit.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
945
|
+
end
|
946
|
+
end
|
947
|
+
end
|
948
|
+
|
949
|
+
it "assigns the coordinator returned shipments to its shipments" do
|
950
|
+
shipment = build(:shipment)
|
951
|
+
allow_any_instance_of(Spree::Stock::Coordinator).to receive(:shipments).and_return([shipment])
|
952
|
+
subject.create_proposed_shipments
|
953
|
+
expect(subject.shipments).to eq [shipment]
|
954
|
+
end
|
955
|
+
end
|
956
|
+
|
957
|
+
describe "#all_inventory_units_returned?" do
|
958
|
+
let(:order) { create(:order_with_line_items, line_items_count: 3) }
|
959
|
+
|
960
|
+
subject { order.all_inventory_units_returned? }
|
961
|
+
|
962
|
+
context "all inventory units are returned" do
|
963
|
+
before { order.inventory_units.update_all(state: 'returned') }
|
964
|
+
|
965
|
+
it "is true" do
|
966
|
+
expect(subject).to eq true
|
967
|
+
end
|
968
|
+
end
|
969
|
+
|
970
|
+
context "some inventory units are returned" do
|
971
|
+
before do
|
972
|
+
order.inventory_units.first.update_attribute(:state, 'returned')
|
973
|
+
end
|
974
|
+
|
975
|
+
it "is false" do
|
976
|
+
expect(subject).to eq false
|
977
|
+
end
|
978
|
+
end
|
979
|
+
|
980
|
+
context "no inventory units are returned" do
|
981
|
+
it "is false" do
|
982
|
+
expect(subject).to eq false
|
983
|
+
end
|
984
|
+
end
|
985
|
+
end
|
986
|
+
|
987
|
+
describe "#fully_discounted?" do
|
988
|
+
let(:line_item) { Spree::LineItem.new(price: 10, quantity: 1) }
|
989
|
+
let(:shipment) { Spree::Shipment.new(cost: 10) }
|
990
|
+
let(:payment) { Spree::Payment.new(amount: 10) }
|
991
|
+
|
992
|
+
before do
|
993
|
+
allow(order).to receive(:line_items) { [line_item] }
|
994
|
+
allow(order).to receive(:shipments) { [shipment] }
|
995
|
+
allow(order).to receive(:payments) { [payment] }
|
996
|
+
end
|
997
|
+
|
998
|
+
context "the order had no inventory-related cost" do
|
999
|
+
before do
|
1000
|
+
# discount the cost of the line items
|
1001
|
+
allow(order).to receive(:adjustment_total) { -5 }
|
1002
|
+
allow(line_item).to receive(:adjustment_total) { -5 }
|
1003
|
+
|
1004
|
+
# but leave some shipment payment amount
|
1005
|
+
allow(shipment).to receive(:adjustment_total) { 0 }
|
1006
|
+
end
|
1007
|
+
|
1008
|
+
it { expect(order.fully_discounted?).to eq true }
|
1009
|
+
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
context "the order had inventory-related cost" do
|
1013
|
+
before do
|
1014
|
+
# partially discount the cost of the line item
|
1015
|
+
allow(order).to receive(:adjustment_total) { 0 }
|
1016
|
+
allow(line_item).to receive(:adjustment_total) { -5 }
|
1017
|
+
|
1018
|
+
# and partially discount the cost of the shipment so the total
|
1019
|
+
# discount matches the item total for test completeness
|
1020
|
+
allow(shipment).to receive(:adjustment_total) { -5 }
|
1021
|
+
end
|
1022
|
+
|
1023
|
+
it { expect(order.fully_discounted?).to eq false }
|
1024
|
+
end
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
describe 'order transit to returned state from resumed state' do
|
1028
|
+
let!(:resumed_order) { create(:order_with_line_items, line_items_count: 3, state: :resumed) }
|
1029
|
+
|
1030
|
+
context 'when all inventory_units returned' do
|
1031
|
+
before do
|
1032
|
+
resumed_order.inventory_units.update_all(state: 'returned')
|
1033
|
+
resumed_order.return
|
1034
|
+
end
|
1035
|
+
it { expect(resumed_order).to be_returned }
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
context 'when some inventory_units returned' do
|
1039
|
+
before do
|
1040
|
+
resumed_order.inventory_units.first.update_attribute(:state, 'returned')
|
1041
|
+
resumed_order.return
|
1042
|
+
end
|
1043
|
+
it { expect(resumed_order).to be_resumed }
|
1044
|
+
end
|
1045
|
+
end
|
1046
|
+
|
1047
|
+
describe 'credit_card_nil_payment' do
|
1048
|
+
let!(:order) { create(:order_with_line_items, line_items_count: 2) }
|
1049
|
+
let!(:credit_card_payment_method) { create(:simple_credit_card_payment_method) }
|
1050
|
+
let!(:store_credits) { create(:store_credit_payment, order: order) }
|
1051
|
+
|
1052
|
+
def attributes(amount = 0)
|
1053
|
+
{ payments_attributes: [{ amount: amount, payment_method_id: credit_card_payment_method.id }] }
|
1054
|
+
end
|
1055
|
+
context 'when zero amount credit-card payment' do
|
1056
|
+
it 'expect not to build a new payment' do
|
1057
|
+
expect { order.assign_attributes(attributes) }.to change { order.payments.size }.by(0)
|
1058
|
+
end
|
1059
|
+
end
|
1060
|
+
|
1061
|
+
context 'when valid-amount(>0) creditcard payment' do
|
1062
|
+
it 'expect not to build a new payment' do
|
1063
|
+
expect { order.assign_attributes(attributes(10)) }.to change { order.payments.size }.by(1)
|
1064
|
+
end
|
1065
|
+
end
|
1066
|
+
end
|
1067
|
+
end
|