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,69 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Calculator, type: :model do
|
4
|
+
|
5
|
+
let(:order) { create(:order) }
|
6
|
+
let!(:line_item) { create(:line_item, order: order) }
|
7
|
+
let(:shipment) { create(:shipment, order: order, stock_location: create(:stock_location_with_items)) }
|
8
|
+
|
9
|
+
context "with computable" do
|
10
|
+
context "and compute methods stubbed out" do
|
11
|
+
context "with a Spree::LineItem" do
|
12
|
+
it "calls compute_line_item" do
|
13
|
+
expect(subject).to receive(:compute_line_item).with(line_item)
|
14
|
+
subject.compute(line_item)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context "with a Spree::Order" do
|
19
|
+
it "calls compute_order" do
|
20
|
+
expect(subject).to receive(:compute_order).with(order)
|
21
|
+
subject.compute(order)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "with a Spree::Shipment" do
|
26
|
+
it "calls compute_shipment" do
|
27
|
+
expect(subject).to receive(:compute_shipment).with(shipment)
|
28
|
+
subject.compute(shipment)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with a arbitray object" do
|
33
|
+
it "calls the correct compute" do
|
34
|
+
s = "Calculator can all"
|
35
|
+
expect(subject).to receive(:compute_string).with(s)
|
36
|
+
subject.compute(s)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "with no stubbing" do
|
42
|
+
context "with a Spree::LineItem" do
|
43
|
+
it "raises NotImplementedError" do
|
44
|
+
expect{subject.compute(line_item)}.to raise_error NotImplementedError, /Please implement \'compute_line_item\(line_item\)\' in your calculator/
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "with a Spree::Order" do
|
49
|
+
it "raises NotImplementedError" do
|
50
|
+
expect{subject.compute(order)}.to raise_error NotImplementedError, /Please implement \'compute_order\(order\)\' in your calculator/
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "with a Spree::Shipment" do
|
55
|
+
it "raises NotImplementedError" do
|
56
|
+
expect{subject.compute(shipment)}.to raise_error NotImplementedError, /Please implement \'compute_shipment\(shipment\)\' in your calculator/
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
context "with a arbitray object" do
|
61
|
+
it "raises NotImplementedError" do
|
62
|
+
s = "Calculator can all"
|
63
|
+
expect{subject.compute(s)}.to raise_error NotImplementedError, /Please implement \'compute_string\(string\)\' in your calculator/
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe Classification, type: :model do
|
5
|
+
# Regression test for #3494
|
6
|
+
it "cannot link the same taxon to the same product more than once" do
|
7
|
+
product = create(:product)
|
8
|
+
taxon = create(:taxon)
|
9
|
+
add_taxon = lambda { product.taxons << taxon }
|
10
|
+
expect(add_taxon).not_to raise_error
|
11
|
+
expect(add_taxon).to raise_error(ActiveRecord::RecordInvalid)
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:taxon_with_5_products) do
|
15
|
+
products = []
|
16
|
+
5.times do
|
17
|
+
products << create(:base_product)
|
18
|
+
end
|
19
|
+
|
20
|
+
create(:taxon, products: products)
|
21
|
+
end
|
22
|
+
|
23
|
+
def positions_to_be_valid(taxon)
|
24
|
+
positions = taxon.reload.classifications.map(&:position)
|
25
|
+
expect(positions).to eq((1..taxon.classifications.count).to_a)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "has a valid fixtures" do
|
29
|
+
expect positions_to_be_valid(taxon_with_5_products)
|
30
|
+
expect(Spree::Classification.count).to eq 5
|
31
|
+
end
|
32
|
+
|
33
|
+
context "removing product from taxon" do
|
34
|
+
before :each do
|
35
|
+
p = taxon_with_5_products.products[1]
|
36
|
+
expect(p.classifications.first.position).to eq(2)
|
37
|
+
taxon_with_5_products.products.destroy(p)
|
38
|
+
end
|
39
|
+
|
40
|
+
it "resets positions" do
|
41
|
+
expect positions_to_be_valid(taxon_with_5_products)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "replacing taxon's products" do
|
46
|
+
before :each do
|
47
|
+
products = taxon_with_5_products.products.to_a
|
48
|
+
products.pop(1)
|
49
|
+
taxon_with_5_products.products = products
|
50
|
+
taxon_with_5_products.save!
|
51
|
+
end
|
52
|
+
|
53
|
+
it "resets positions" do
|
54
|
+
expect positions_to_be_valid(taxon_with_5_products)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
context "removing taxon from product" do
|
59
|
+
before :each do
|
60
|
+
p = taxon_with_5_products.products[1]
|
61
|
+
p.taxons.destroy(taxon_with_5_products)
|
62
|
+
p.save!
|
63
|
+
end
|
64
|
+
|
65
|
+
it "resets positions" do
|
66
|
+
expect positions_to_be_valid(taxon_with_5_products)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "replacing product's taxons" do
|
71
|
+
before :each do
|
72
|
+
p = taxon_with_5_products.products[1]
|
73
|
+
p.taxons = []
|
74
|
+
p.save!
|
75
|
+
end
|
76
|
+
|
77
|
+
it "resets positions" do
|
78
|
+
expect positions_to_be_valid(taxon_with_5_products)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "destroying classification" do
|
83
|
+
before :each do
|
84
|
+
classification = taxon_with_5_products.classifications[1]
|
85
|
+
classification.destroy
|
86
|
+
end
|
87
|
+
|
88
|
+
it "resets positions" do
|
89
|
+
expect positions_to_be_valid(taxon_with_5_products)
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
|
5
|
+
describe DisplayMoney do
|
6
|
+
let(:test_class) do
|
7
|
+
Class.new do
|
8
|
+
extend DisplayMoney
|
9
|
+
def total; 10.0; end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
describe ".money_methods" do
|
14
|
+
before { test_class.money_methods :total }
|
15
|
+
|
16
|
+
context "currency is not defined" do
|
17
|
+
it "generates a display_method that builds a Spree::Money without options" do
|
18
|
+
expect(test_class.new.display_total).to eq Spree::Money.new(10.0)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
context "currency is defined" do
|
23
|
+
before { test_class.class_eval { def currency; "USD"; end } }
|
24
|
+
|
25
|
+
it "generates a display_* method that builds a Spree::Money with currency" do
|
26
|
+
expect(test_class.new.display_total).to eq Spree::Money.new(10.0, currency: "USD")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with multiple + options" do
|
31
|
+
before do
|
32
|
+
test_class.class_eval { def amount; 20.0; end }
|
33
|
+
test_class.money_methods :total, amount: { no_cents: true }
|
34
|
+
end
|
35
|
+
|
36
|
+
it "generates a display_* method that builds a Spree::Money with the specified options" do
|
37
|
+
expect(test_class.new.display_total).to eq Spree::Money.new(10.0)
|
38
|
+
expect(test_class.new.display_amount).to eq Spree::Money.new(20.0, no_cents: true)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::UserMethods do
|
4
|
+
let(:test_user) { create :user }
|
5
|
+
|
6
|
+
describe 'Associations' do
|
7
|
+
subject { test_user }
|
8
|
+
|
9
|
+
it 'should have many promotion_rule_users' do
|
10
|
+
is_expected.to have_many(:promotion_rule_users).with_foreign_key(:user_id).
|
11
|
+
class_name('Spree::PromotionRuleUser').dependent(:destroy)
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'should have many role_users' do
|
15
|
+
is_expected.to have_many(:role_users).class_name('Spree::RoleUser').
|
16
|
+
with_foreign_key(:user_id).dependent(:destroy)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#has_spree_role?' do
|
21
|
+
subject { test_user.has_spree_role? name }
|
22
|
+
|
23
|
+
let(:role) { Spree::Role.create(name: name) }
|
24
|
+
let(:name) { 'test' }
|
25
|
+
|
26
|
+
context 'with a role' do
|
27
|
+
before { test_user.spree_roles << role }
|
28
|
+
it { is_expected.to be_truthy }
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'without a role' do
|
32
|
+
it { is_expected.to be_falsy }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#last_incomplete_spree_order' do
|
37
|
+
subject { test_user.last_incomplete_spree_order }
|
38
|
+
|
39
|
+
context 'with an incomplete order' do
|
40
|
+
let(:last_incomplete_order) { create :order, user: test_user }
|
41
|
+
|
42
|
+
before do
|
43
|
+
create(:order, user: test_user, created_at: 1.day.ago)
|
44
|
+
create(:order, user: create(:user))
|
45
|
+
last_incomplete_order
|
46
|
+
end
|
47
|
+
|
48
|
+
it { is_expected.to eq last_incomplete_order }
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'without an incomplete order' do
|
52
|
+
it { is_expected.to be_nil }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context '#check_completed_orders' do
|
57
|
+
let(:possible_promotion) { create(:promotion, advertise: true, starts_at: 1.day.ago) }
|
58
|
+
context 'rstrict t delete dependent destroyed' do
|
59
|
+
before do
|
60
|
+
test_user.promotion_rules.create!(promotion: possible_promotion)
|
61
|
+
create(:order, user: test_user, completed_at: Time.current)
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'should not destroy dependent destroy items' do
|
65
|
+
expect { test_user.destroy }.to raise_error(Spree::Core::DestroyWithOrdersError)
|
66
|
+
expect(test_user.promotion_rule_users.any?).to be(true)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'allow to destroy dependent destroy' do
|
71
|
+
before do
|
72
|
+
test_user.promotion_rules.create!(promotion: possible_promotion)
|
73
|
+
create(:order, user: test_user, created_at: 1.day.ago)
|
74
|
+
test_user.destroy
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'should not destroy dependent destroy items' do
|
78
|
+
expect(test_user.promotion_rule_users.any?).to be(false)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Spree
|
4
|
+
describe VatPriceCalculation do
|
5
|
+
let(:test_class) do
|
6
|
+
Class.new do
|
7
|
+
include VatPriceCalculation
|
8
|
+
def total; 10.0; end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#gross_amount" do
|
13
|
+
let(:zone) { Zone.new }
|
14
|
+
let(:tax_category) { TaxCategory.new }
|
15
|
+
let(:price_options) do
|
16
|
+
{
|
17
|
+
tax_zone: zone,
|
18
|
+
tax_category: tax_category
|
19
|
+
}
|
20
|
+
end
|
21
|
+
let(:amount) { 100 }
|
22
|
+
|
23
|
+
subject(:gross_amount) { test_class.new.gross_amount(amount, price_options) }
|
24
|
+
|
25
|
+
context "with no default zone set" do
|
26
|
+
it "does not call TaxRate.included_tax_amount_for" do
|
27
|
+
expect(TaxRate).not_to receive(:included_tax_amount_for)
|
28
|
+
gross_amount
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context "with no zone given" do
|
33
|
+
let(:zone) { nil }
|
34
|
+
it "does not call TaxRate.included_tax_amount_for" do
|
35
|
+
expect(TaxRate).not_to receive(:included_tax_amount_for)
|
36
|
+
gross_amount
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with a default zone set" do
|
41
|
+
let(:default_zone) { Spree::Zone.new }
|
42
|
+
before do
|
43
|
+
allow(Spree::Zone).to receive(:default_tax).and_return(default_zone)
|
44
|
+
end
|
45
|
+
|
46
|
+
context "and zone equal to the default zone" do
|
47
|
+
let(:zone) { default_zone }
|
48
|
+
|
49
|
+
it "does not call 'TaxRate.included_tax_amount_for'" do
|
50
|
+
expect(TaxRate).not_to receive(:included_tax_amount_for)
|
51
|
+
gross_amount
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "and zone not equal to default zone" do
|
56
|
+
let(:zone) { Spree::Zone.new }
|
57
|
+
|
58
|
+
it "calls TaxRate.included_tax_amount_for two times" do
|
59
|
+
expect(TaxRate).to receive(:included_tax_amount_for).twice
|
60
|
+
gross_amount
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::Country, type: :model do
|
4
|
+
let(:america) { create :country }
|
5
|
+
let(:canada) { create :country, name: 'Canada', iso_name: 'CANADA', numcode: '124' }
|
6
|
+
|
7
|
+
describe 'Callbacks' do
|
8
|
+
it { is_expected.to callback(:ensure_not_default).before(:destroy) }
|
9
|
+
end
|
10
|
+
|
11
|
+
describe 'Associations' do
|
12
|
+
it { is_expected.to have_many(:addresses).dependent(:restrict_with_error) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe 'Validations' do
|
16
|
+
it { is_expected.to validate_presence_of(:name) }
|
17
|
+
it { is_expected.to validate_presence_of(:iso_name) }
|
18
|
+
it { is_expected.to validate_uniqueness_of(:iso_name).case_insensitive }
|
19
|
+
it { is_expected.to validate_uniqueness_of(:name).case_insensitive }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.default' do
|
23
|
+
context 'when default_country_id config is set' do
|
24
|
+
before { Spree::Config[:default_country_id] = canada.id }
|
25
|
+
it 'will return the country from the config' do
|
26
|
+
expect(described_class.default.id).to eql canada.id
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
context 'config is not set though record for america exists' do
|
31
|
+
before { america.touch }
|
32
|
+
it 'will return the US' do
|
33
|
+
expect(described_class.default.id).to eql america.id
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'ensure default country in not deleted' do
|
39
|
+
before { Spree::Config[:default_country_id] = america.id }
|
40
|
+
|
41
|
+
context 'will not destroy country if it is default' do
|
42
|
+
subject { america.destroy }
|
43
|
+
it { is_expected.to be_falsy }
|
44
|
+
|
45
|
+
context 'error should be default country cannot be deleted' do
|
46
|
+
before { subject }
|
47
|
+
it { expect(america.errors[:base]).to include(Spree.t(:default_country_cannot_be_deleted)) }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'will destroy if it is not a default' do
|
52
|
+
it { expect(canada.destroy).to be_truthy }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,328 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::CreditCard, type: :model do
|
4
|
+
let(:valid_credit_card_attributes) do
|
5
|
+
{
|
6
|
+
number: '4111111111111111',
|
7
|
+
verification_value: '123',
|
8
|
+
expiry: "12 / #{(Time.current.year + 1).to_s.last(2)}",
|
9
|
+
name: 'Spree Commerce'
|
10
|
+
}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.payment_states
|
14
|
+
Spree::Payment.state_machine.states.keys
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:credit_card) { Spree::CreditCard.new }
|
18
|
+
|
19
|
+
before(:each) do
|
20
|
+
|
21
|
+
@order = create(:order)
|
22
|
+
@payment = Spree::Payment.create(amount: 100, order: @order)
|
23
|
+
|
24
|
+
@success_response = double('gateway_response', success?: true, authorization: '123', avs_result: { 'code' => 'avs-code' })
|
25
|
+
@fail_response = double('gateway_response', success?: false)
|
26
|
+
|
27
|
+
@payment_gateway = mock_model(Spree::PaymentMethod,
|
28
|
+
payment_profiles_supported?: true,
|
29
|
+
authorize: @success_response,
|
30
|
+
purchase: @success_response,
|
31
|
+
capture: @success_response,
|
32
|
+
void: @success_response,
|
33
|
+
credit: @success_response,
|
34
|
+
)
|
35
|
+
|
36
|
+
allow(@payment).to receive_messages payment_method: @payment_gateway
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should respond to track_data' do
|
40
|
+
expect(credit_card.respond_to?(:track_data)).to be true
|
41
|
+
end
|
42
|
+
|
43
|
+
context "#can_capture?" do
|
44
|
+
it "should be true if payment is pending" do
|
45
|
+
payment = mock_model(Spree::Payment, pending?: true, created_at: Time.current)
|
46
|
+
expect(credit_card.can_capture?(payment)).to be true
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should be true if payment is checkout" do
|
50
|
+
payment = mock_model(Spree::Payment, pending?: false, checkout?: true, created_at: Time.current)
|
51
|
+
expect(credit_card.can_capture?(payment)).to be true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context "#can_void?" do
|
56
|
+
it "should be true if payment is not void" do
|
57
|
+
payment = mock_model(Spree::Payment, failed?: false, void?: false)
|
58
|
+
expect(credit_card.can_void?(payment)).to be true
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context "#can_credit?" do
|
63
|
+
it "should be false if payment is not completed" do
|
64
|
+
payment = mock_model(Spree::Payment, completed?: false)
|
65
|
+
expect(credit_card.can_credit?(payment)).to be false
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should be false when credit_allowed is zero" do
|
69
|
+
payment = mock_model(Spree::Payment, completed?: true, credit_allowed: 0, order: mock_model(Spree::Order, payment_state: 'credit_owed'))
|
70
|
+
expect(credit_card.can_credit?(payment)).to be false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "#valid?" do
|
75
|
+
it "should validate presence of number" do
|
76
|
+
credit_card.attributes = valid_credit_card_attributes.except(:number)
|
77
|
+
expect(credit_card).not_to be_valid
|
78
|
+
expect(credit_card.errors[:number]).to eq(["can't be blank"])
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should validate presence of security code" do
|
82
|
+
credit_card.attributes = valid_credit_card_attributes.except(:verification_value)
|
83
|
+
expect(credit_card).not_to be_valid
|
84
|
+
expect(credit_card.errors[:verification_value]).to eq(["can't be blank"])
|
85
|
+
end
|
86
|
+
|
87
|
+
it "validates name presence" do
|
88
|
+
credit_card.valid?
|
89
|
+
expect(credit_card.error_on(:name).size).to eq(1)
|
90
|
+
end
|
91
|
+
|
92
|
+
it "should only validate on create" do
|
93
|
+
credit_card.attributes = valid_credit_card_attributes
|
94
|
+
credit_card.save
|
95
|
+
expect(credit_card).to be_valid
|
96
|
+
end
|
97
|
+
|
98
|
+
context "encrypted data is present" do
|
99
|
+
it "does not validate presence of number or cvv" do
|
100
|
+
credit_card.encrypted_data = "$fdgsfgdgfgfdg&gfdgfdgsf-"
|
101
|
+
credit_card.valid?
|
102
|
+
expect(credit_card.errors[:number]).to be_empty
|
103
|
+
expect(credit_card.errors[:verification_value]).to be_empty
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
context "imported is true" do
|
108
|
+
it "does not validate presence of number or cvv" do
|
109
|
+
credit_card.imported = true
|
110
|
+
credit_card.valid?
|
111
|
+
expect(credit_card.errors[:number]).to be_empty
|
112
|
+
expect(credit_card.errors[:verification_value]).to be_empty
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context "#save" do
|
118
|
+
before do
|
119
|
+
credit_card.attributes = valid_credit_card_attributes
|
120
|
+
credit_card.save!
|
121
|
+
end
|
122
|
+
|
123
|
+
let!(:persisted_card) { Spree::CreditCard.find(credit_card.id) }
|
124
|
+
|
125
|
+
it "should not actually store the number" do
|
126
|
+
expect(persisted_card.number).to be_blank
|
127
|
+
end
|
128
|
+
|
129
|
+
it "should not actually store the security code" do
|
130
|
+
expect(persisted_card.verification_value).to be_blank
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context "#number=" do
|
135
|
+
it "should strip non-numeric characters from card input" do
|
136
|
+
credit_card.number = "6011000990139424"
|
137
|
+
expect(credit_card.number).to eq("6011000990139424")
|
138
|
+
|
139
|
+
credit_card.number = " 6011-0009-9013-9424 "
|
140
|
+
expect(credit_card.number).to eq("6011000990139424")
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should not raise an exception on non-string input" do
|
144
|
+
credit_card.number = Hash.new
|
145
|
+
expect(credit_card.number).to be_nil
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Regression test for #3847 & #3896
|
150
|
+
context "#expiry=" do
|
151
|
+
it "can set with a 2-digit month and year" do
|
152
|
+
credit_card.expiry = '04 / 14'
|
153
|
+
expect(credit_card.month).to eq(4)
|
154
|
+
expect(credit_card.year).to eq(2014)
|
155
|
+
end
|
156
|
+
|
157
|
+
it "can set with a 2-digit month and 4-digit year" do
|
158
|
+
credit_card.expiry = '04 / 2014'
|
159
|
+
expect(credit_card.month).to eq(4)
|
160
|
+
expect(credit_card.year).to eq(2014)
|
161
|
+
end
|
162
|
+
|
163
|
+
it "can set with a 2-digit month and 4-digit year without whitespace" do
|
164
|
+
credit_card.expiry = '04/14'
|
165
|
+
expect(credit_card.month).to eq(4)
|
166
|
+
expect(credit_card.year).to eq(2014)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "can set with a 2-digit month and 4-digit year without whitespace" do
|
170
|
+
credit_card.expiry = '04/2014'
|
171
|
+
expect(credit_card.month).to eq(4)
|
172
|
+
expect(credit_card.year).to eq(2014)
|
173
|
+
end
|
174
|
+
|
175
|
+
it "can set with a 2-digit month and 4-digit year without whitespace and slash" do
|
176
|
+
credit_card.expiry = '042014'
|
177
|
+
expect(credit_card.month).to eq(4)
|
178
|
+
expect(credit_card.year).to eq(2014)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "can set with a 2-digit month and 2-digit year without whitespace and slash" do
|
182
|
+
credit_card.expiry = '0414'
|
183
|
+
expect(credit_card.month).to eq(4)
|
184
|
+
expect(credit_card.year).to eq(2014)
|
185
|
+
end
|
186
|
+
|
187
|
+
it "does not blow up when passed an empty string" do
|
188
|
+
expect { credit_card.expiry = '' }.not_to raise_error
|
189
|
+
end
|
190
|
+
|
191
|
+
# Regression test for #4725
|
192
|
+
it "does not blow up when passed one number" do
|
193
|
+
expect { credit_card.expiry = '12' }.not_to raise_error
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
|
198
|
+
context "#cc_type=" do
|
199
|
+
it "converts between the different types" do
|
200
|
+
credit_card.cc_type = 'mastercard'
|
201
|
+
expect(credit_card.cc_type).to eq('master')
|
202
|
+
|
203
|
+
credit_card.cc_type = 'maestro'
|
204
|
+
expect(credit_card.cc_type).to eq('master')
|
205
|
+
|
206
|
+
credit_card.cc_type = 'amex'
|
207
|
+
expect(credit_card.cc_type).to eq('american_express')
|
208
|
+
|
209
|
+
credit_card.cc_type = 'dinersclub'
|
210
|
+
expect(credit_card.cc_type).to eq('diners_club')
|
211
|
+
|
212
|
+
credit_card.cc_type = 'some_outlandish_cc_type'
|
213
|
+
expect(credit_card.cc_type).to eq('some_outlandish_cc_type')
|
214
|
+
end
|
215
|
+
|
216
|
+
it "assigns the type based on card number in the event of js failure" do
|
217
|
+
credit_card.number = '4242424242424242'
|
218
|
+
credit_card.cc_type = ''
|
219
|
+
expect(credit_card.cc_type).to eq('visa')
|
220
|
+
|
221
|
+
credit_card.number = '5555555555554444'
|
222
|
+
credit_card.cc_type = ''
|
223
|
+
expect(credit_card.cc_type).to eq('master')
|
224
|
+
|
225
|
+
credit_card.number = '2223000010309703'
|
226
|
+
credit_card.cc_type = ''
|
227
|
+
expect(credit_card.cc_type).to eq('master')
|
228
|
+
|
229
|
+
credit_card.number = '378282246310005'
|
230
|
+
credit_card.cc_type = ''
|
231
|
+
expect(credit_card.cc_type).to eq('american_express')
|
232
|
+
|
233
|
+
credit_card.number = '30569309025904'
|
234
|
+
credit_card.cc_type = ''
|
235
|
+
expect(credit_card.cc_type).to eq('diners_club')
|
236
|
+
|
237
|
+
credit_card.number = '3530111333300000'
|
238
|
+
credit_card.cc_type = ''
|
239
|
+
expect(credit_card.cc_type).to eq('jcb')
|
240
|
+
|
241
|
+
credit_card.number = ''
|
242
|
+
credit_card.cc_type = ''
|
243
|
+
expect(credit_card.cc_type).to eq('')
|
244
|
+
|
245
|
+
credit_card.number = nil
|
246
|
+
credit_card.cc_type = ''
|
247
|
+
expect(credit_card.cc_type).to eq('')
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context "#associations" do
|
252
|
+
it "should be able to access its payments" do
|
253
|
+
expect { credit_card.payments.to_a }.not_to raise_error
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
context "#first_name" do
|
258
|
+
before do
|
259
|
+
credit_card.name = "Ludwig van Beethoven"
|
260
|
+
end
|
261
|
+
|
262
|
+
it "extracts the first name" do
|
263
|
+
expect(credit_card.first_name).to eq "Ludwig"
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
context "#last_name" do
|
268
|
+
before do
|
269
|
+
credit_card.name = "Ludwig van Beethoven"
|
270
|
+
end
|
271
|
+
|
272
|
+
it "extracts the last name" do
|
273
|
+
expect(credit_card.last_name).to eq "van Beethoven"
|
274
|
+
end
|
275
|
+
end
|
276
|
+
|
277
|
+
context "#to_active_merchant" do
|
278
|
+
before do
|
279
|
+
credit_card.number = "4111111111111111"
|
280
|
+
credit_card.year = Time.current.year
|
281
|
+
credit_card.month = Time.current.month
|
282
|
+
credit_card.name = "Ludwig van Beethoven"
|
283
|
+
credit_card.verification_value = 123
|
284
|
+
end
|
285
|
+
|
286
|
+
it "converts to an ActiveMerchant::Billing::CreditCard object" do
|
287
|
+
am_card = credit_card.to_active_merchant
|
288
|
+
expect(am_card.number).to eq("4111111111111111")
|
289
|
+
expect(am_card.year).to eq(Time.current.year)
|
290
|
+
expect(am_card.month).to eq(Time.current.month)
|
291
|
+
expect(am_card.first_name).to eq("Ludwig")
|
292
|
+
expect(am_card.last_name).to eq("van Beethoven")
|
293
|
+
expect(am_card.verification_value).to eq(123)
|
294
|
+
end
|
295
|
+
end
|
296
|
+
|
297
|
+
it 'ensures only one credit card per user is default at a time' do
|
298
|
+
user = FactoryGirl.create(:user)
|
299
|
+
first = FactoryGirl.create(:credit_card, user: user, default: true)
|
300
|
+
second = FactoryGirl.create(:credit_card, user: user, default: true)
|
301
|
+
|
302
|
+
expect(first.reload.default).to eq false
|
303
|
+
expect(second.reload.default).to eq true
|
304
|
+
|
305
|
+
first.default = true
|
306
|
+
first.save!
|
307
|
+
|
308
|
+
expect(first.reload.default).to eq true
|
309
|
+
expect(second.reload.default).to eq false
|
310
|
+
end
|
311
|
+
|
312
|
+
it 'allows default credit cards for different users' do
|
313
|
+
first = FactoryGirl.create(:credit_card, user: FactoryGirl.create(:user), default: true)
|
314
|
+
second = FactoryGirl.create(:credit_card, user: FactoryGirl.create(:user), default: true)
|
315
|
+
|
316
|
+
expect(first.reload.default).to eq true
|
317
|
+
expect(second.reload.default).to eq true
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'allows this card to save even if the previously default card has expired' do
|
321
|
+
user = FactoryGirl.create(:user)
|
322
|
+
first = FactoryGirl.create(:credit_card, user: user, default: true)
|
323
|
+
second = FactoryGirl.create(:credit_card, user: user, default: false)
|
324
|
+
first.update_columns(year: DateTime.current.year, month: 1.month.ago.month)
|
325
|
+
|
326
|
+
expect { second.update_attributes!(default: true) }.not_to raise_error
|
327
|
+
end
|
328
|
+
end
|