solidus_core 1.1.4 → 1.2.0.beta1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of solidus_core might be problematic. Click here for more details.

Files changed (296) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/images/logo/solidus_logo.png +0 -0
  3. data/app/helpers/spree/base_helper.rb +2 -3
  4. data/app/models/concerns/spree/adjustment_source.rb +1 -1
  5. data/app/models/concerns/spree/default_price.rb +3 -1
  6. data/app/models/concerns/spree/named_type.rb +1 -1
  7. data/app/models/concerns/spree/user_methods.rb +10 -0
  8. data/app/models/spree/adjustment.rb +1 -1
  9. data/app/models/spree/adjustment_reason.rb +2 -4
  10. data/app/models/spree/app_configuration.rb +36 -0
  11. data/app/models/spree/base.rb +10 -1
  12. data/app/models/spree/calculator/tiered_percent.rb +2 -1
  13. data/app/models/spree/classification.rb +1 -1
  14. data/app/models/spree/country.rb +3 -3
  15. data/app/models/spree/credit_card.rb +2 -2
  16. data/app/models/spree/customer_return.rb +3 -4
  17. data/app/models/spree/inventory_unit.rb +13 -24
  18. data/app/models/spree/item_adjustments.rb +5 -5
  19. data/app/models/spree/line_item.rb +6 -15
  20. data/app/models/spree/log_entry.rb +1 -1
  21. data/app/models/spree/option_type.rb +4 -2
  22. data/app/models/spree/option_type_prototype.rb +6 -0
  23. data/app/models/spree/option_value.rb +1 -1
  24. data/app/models/spree/order.rb +18 -63
  25. data/app/models/spree/order/checkout.rb +4 -2
  26. data/app/models/spree/order_cancellations.rb +52 -1
  27. data/app/models/spree/order_contents.rb +1 -1
  28. data/app/models/spree/order_merger.rb +143 -0
  29. data/app/models/spree/order_shipping.rb +3 -3
  30. data/app/models/spree/order_update_attributes.rb +42 -0
  31. data/app/models/spree/order_updater.rb +1 -1
  32. data/app/models/spree/payment.rb +16 -10
  33. data/app/models/spree/payment_create.rb +68 -0
  34. data/app/models/spree/payment_method.rb +0 -1
  35. data/app/models/spree/preference.rb +1 -1
  36. data/app/models/spree/price.rb +1 -8
  37. data/app/models/spree/product.rb +9 -44
  38. data/app/models/spree/product/scopes.rb +9 -7
  39. data/app/models/spree/promotion/rules/nth_order.rb +1 -1
  40. data/app/models/spree/promotion/rules/taxon.rb +2 -1
  41. data/app/models/spree/promotion_chooser.rb +1 -0
  42. data/app/models/spree/promotion_code.rb +1 -1
  43. data/app/models/spree/promotion_rule_taxon.rb +6 -0
  44. data/app/models/spree/property.rb +2 -1
  45. data/app/models/spree/property_prototype.rb +6 -0
  46. data/app/models/spree/prototype.rb +6 -2
  47. data/app/models/spree/reimbursement.rb +10 -0
  48. data/app/models/spree/return_item/eligibility_validator/time_since_purchase.rb +1 -1
  49. data/app/models/spree/return_reason.rb +1 -7
  50. data/app/models/spree/role_user.rb +3 -5
  51. data/app/models/spree/shipment.rb +6 -11
  52. data/app/models/spree/shipping_method.rb +1 -7
  53. data/app/models/spree/shipping_rate.rb +3 -14
  54. data/app/models/spree/stock/coordinator.rb +48 -4
  55. data/app/models/spree/stock/estimator.rb +3 -6
  56. data/app/models/spree/stock/packer.rb +18 -2
  57. data/app/models/spree/stock/shipping_rate_selector.rb +16 -0
  58. data/app/models/spree/stock/shipping_rate_sorter.rb +16 -0
  59. data/app/models/spree/stock_item.rb +19 -15
  60. data/app/models/spree/stock_location.rb +2 -12
  61. data/app/models/spree/stock_transfer.rb +3 -3
  62. data/app/models/spree/store_credit.rb +2 -2
  63. data/app/models/spree/tax_category.rb +3 -2
  64. data/app/models/spree/tax_rate.rb +7 -14
  65. data/app/models/spree/taxon.rb +4 -1
  66. data/app/models/spree/taxonomy.rb +1 -1
  67. data/app/models/spree/transfer_item.rb +2 -2
  68. data/app/models/spree/unit_cancel.rb +2 -0
  69. data/app/models/spree/variant.rb +9 -14
  70. data/app/models/spree/zone.rb +6 -0
  71. data/app/models/spree/zone_member.rb +1 -4
  72. data/app/views/spree/order_mailer/cancel_email.text.erb +0 -0
  73. data/config/locales/en.yml +7 -5
  74. data/db/default/spree/countries.rb +1 -1
  75. data/db/default/spree/zones.rb +5 -11
  76. data/db/migrate/20130213191427_create_default_stock.rb +1 -1
  77. data/db/migrate/20130306181701_add_address_fields_to_stock_location.rb +1 -1
  78. data/db/migrate/20140309033438_create_store_from_preferences.rb +5 -2
  79. data/db/migrate/20141009204607_add_store_id_to_orders.rb +6 -2
  80. data/db/migrate/20141215235502_remove_extra_products_slug_index.rb +5 -0
  81. data/db/migrate/20141217215630_update_product_slug_index.rb +6 -0
  82. data/db/migrate/20150225205344_move_promotion_code_to_promotion_code_value.rb +2 -2
  83. data/db/migrate/20150609093816_increase_scale_on_pre_tax_amounts.rb +10 -0
  84. data/db/migrate/20151117063249_convert_habtm_to_hmt_for_properties_prototypes.rb +17 -0
  85. data/db/migrate/20151124062500_convert_habtm_to_hmt_for_option_type_prototypes.rb +17 -0
  86. data/db/migrate/20151126063028_convert_habtm_to_hmt_for_taxons_promotion_rules.rb +15 -0
  87. data/db/migrate/20151219020209_add_stock_item_unique_index.rb +9 -0
  88. data/lib/generators/spree/dummy/dummy_generator.rb +1 -1
  89. data/lib/generators/spree/dummy/templates/rails/database.yml +1 -1
  90. data/lib/generators/spree/install/templates/config/initializers/spree.rb +25 -1
  91. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/backend/all.js +3 -0
  92. data/lib/generators/spree/install/templates/vendor/assets/javascripts/spree/frontend/all.js +3 -0
  93. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/backend/all.css +3 -0
  94. data/lib/generators/spree/install/templates/vendor/assets/stylesheets/spree/frontend/all.css +3 -0
  95. data/lib/spree/core/controller_helpers/common.rb +1 -1
  96. data/lib/spree/core/controller_helpers/order.rb +1 -1
  97. data/lib/spree/core/controller_helpers/payment_parameters.rb +104 -5
  98. data/lib/spree/core/engine.rb +3 -2
  99. data/lib/spree/core/stock_configuration.rb +11 -0
  100. data/lib/spree/core/unreturned_item_charger.rb +4 -4
  101. data/lib/spree/core/version.rb +9 -1
  102. data/lib/spree/permission_sets/restricted_stock_transfer_management.rb +15 -24
  103. data/lib/spree/permitted_attributes.rb +3 -1
  104. data/lib/spree/testing_support/capybara_ext.rb +14 -40
  105. data/lib/spree/testing_support/factories.rb +0 -15
  106. data/lib/spree/testing_support/factories/address_factory.rb +3 -0
  107. data/lib/spree/testing_support/factories/adjustment_factory.rb +9 -1
  108. data/lib/spree/testing_support/factories/carton_factory.rb +4 -1
  109. data/lib/spree/testing_support/factories/customer_return_factory.rb +4 -0
  110. data/lib/spree/testing_support/factories/inventory_unit_factory.rb +5 -0
  111. data/lib/spree/testing_support/factories/line_item_factory.rb +3 -0
  112. data/lib/spree/testing_support/factories/option_type_factory.rb +6 -0
  113. data/lib/spree/testing_support/factories/{options_factory.rb → option_value_factory.rb} +0 -5
  114. data/lib/spree/testing_support/factories/order_factory.rb +13 -3
  115. data/lib/spree/testing_support/factories/order_promotion_factory.rb +3 -0
  116. data/lib/spree/testing_support/factories/payment_factory.rb +13 -5
  117. data/lib/spree/testing_support/factories/price_factory.rb +2 -0
  118. data/lib/spree/testing_support/factories/product_factory.rb +7 -1
  119. data/lib/spree/testing_support/factories/product_option_type_factory.rb +3 -0
  120. data/lib/spree/testing_support/factories/product_property_factory.rb +3 -0
  121. data/lib/spree/testing_support/factories/promotion_code_factory.rb +3 -0
  122. data/lib/spree/testing_support/factories/promotion_factory.rb +3 -0
  123. data/lib/spree/testing_support/factories/prototype_factory.rb +2 -0
  124. data/lib/spree/testing_support/factories/refund_factory.rb +10 -5
  125. data/lib/spree/testing_support/factories/refund_reason_factory.rb +5 -0
  126. data/lib/spree/testing_support/factories/reimbursement_factory.rb +2 -0
  127. data/lib/spree/testing_support/factories/return_authorization_factory.rb +4 -4
  128. data/lib/spree/testing_support/factories/return_item_factory.rb +4 -0
  129. data/lib/spree/testing_support/factories/return_reason_factory.rb +5 -0
  130. data/lib/spree/testing_support/factories/shipment_factory.rb +6 -1
  131. data/lib/spree/testing_support/factories/shipping_method_factory.rb +22 -10
  132. data/lib/spree/testing_support/factories/shipping_rate_factory.rb +9 -0
  133. data/lib/spree/testing_support/factories/state_factory.rb +2 -0
  134. data/lib/spree/testing_support/factories/stock_item_factory.rb +4 -1
  135. data/lib/spree/testing_support/factories/stock_location_factory.rb +8 -0
  136. data/lib/spree/testing_support/factories/stock_movement_factory.rb +2 -0
  137. data/lib/spree/testing_support/factories/{stock_factory.rb → stock_package_factory.rb} +5 -10
  138. data/lib/spree/testing_support/factories/stock_packer_factory.rb +13 -0
  139. data/lib/spree/testing_support/factories/stock_transfer_factory.rb +2 -2
  140. data/lib/spree/testing_support/factories/store_credit_event_factory.rb +4 -1
  141. data/lib/spree/testing_support/factories/store_credit_factory.rb +10 -6
  142. data/lib/spree/testing_support/factories/tax_category_factory.rb +2 -0
  143. data/lib/spree/testing_support/factories/tax_rate_factory.rb +4 -0
  144. data/lib/spree/testing_support/factories/taxon_factory.rb +2 -0
  145. data/lib/spree/testing_support/factories/user_factory.rb +6 -2
  146. data/lib/spree/testing_support/factories/variant_factory.rb +5 -0
  147. data/lib/spree/testing_support/factories/variant_property_rule_condition_factory.rb +3 -0
  148. data/lib/spree/testing_support/factories/variant_property_rule_factory.rb +4 -0
  149. data/lib/spree/testing_support/factories/variant_property_rule_value_factory.rb +3 -0
  150. data/lib/spree/testing_support/factories/zone_factory.rb +6 -0
  151. data/lib/spree/testing_support/sequences.rb +9 -0
  152. data/lib/tasks/exchanges.rake +4 -3
  153. data/lib/tasks/migrations/copy_shipped_shipments_to_cartons.rake +2 -2
  154. data/solidus_core.gemspec +4 -5
  155. data/spec/helpers/base_helper_spec.rb +6 -6
  156. data/spec/helpers/order_helper_spec.rb +1 -1
  157. data/spec/helpers/products_helper_spec.rb +2 -2
  158. data/spec/helpers/taxons_helper_spec.rb +1 -1
  159. data/spec/lib/spree/core/controller_helpers/payment_parameters_spec.rb +107 -7
  160. data/spec/lib/spree/core/importer/order_spec.rb +1 -1
  161. data/spec/lib/spree/core/stock_configuration_spec.rb +16 -0
  162. data/spec/lib/spree/core/testing_support/factories/address_factory_spec.rb +24 -0
  163. data/spec/lib/spree/core/testing_support/factories/adjustment_factory_spec.rb +18 -0
  164. data/spec/lib/spree/core/testing_support/factories/adjustment_reason_factory_spec.rb +12 -0
  165. data/spec/lib/spree/core/testing_support/factories/calculator_factory_spec.rb +42 -0
  166. data/spec/lib/spree/core/testing_support/factories/carton_factory_spec.rb +12 -0
  167. data/spec/lib/spree/core/testing_support/factories/country_factory_spec.rb +12 -0
  168. data/spec/lib/spree/core/testing_support/factories/credit_card_factory_spec.rb +12 -0
  169. data/spec/lib/spree/core/testing_support/factories/customer_return_factory_spec.rb +28 -0
  170. data/spec/lib/spree/core/testing_support/factories/image_factory_spec.rb +12 -0
  171. data/spec/lib/spree/core/testing_support/factories/inventory_unit_factory_spec.rb +12 -0
  172. data/spec/lib/spree/core/testing_support/factories/line_item_factory_spec.rb +12 -0
  173. data/spec/lib/spree/core/testing_support/factories/option_type_factory_spec.rb +12 -0
  174. data/spec/lib/spree/core/testing_support/factories/option_value_factory_spec.rb +12 -0
  175. data/spec/lib/spree/core/testing_support/factories/order_factory_spec.rb +49 -0
  176. data/spec/lib/spree/core/testing_support/factories/order_promotion_factory_spec.rb +12 -0
  177. data/spec/lib/spree/core/testing_support/factories/payment_factory_spec.rb +24 -0
  178. data/spec/lib/spree/core/testing_support/factories/payment_method_factory_spec.rb +30 -0
  179. data/spec/lib/spree/core/testing_support/factories/price_factory_spec.rb +12 -0
  180. data/spec/lib/spree/core/testing_support/factories/product_factory_spec.rb +30 -0
  181. data/spec/lib/spree/core/testing_support/factories/product_option_type_factory_spec.rb +12 -0
  182. data/spec/lib/spree/core/testing_support/factories/product_property_factory_spec.rb +12 -0
  183. data/spec/lib/spree/core/testing_support/factories/promotion_category_factory_spec.rb +12 -0
  184. data/spec/lib/spree/core/testing_support/factories/promotion_code_factory_spec.rb +12 -0
  185. data/spec/lib/spree/core/testing_support/factories/promotion_factory_spec.rb +30 -0
  186. data/spec/lib/spree/core/testing_support/factories/property_factory_spec.rb +12 -0
  187. data/spec/lib/spree/core/testing_support/factories/prototype_factory_spec.rb +12 -0
  188. data/spec/lib/spree/core/testing_support/factories/refund_factory_spec.rb +12 -0
  189. data/spec/lib/spree/core/testing_support/factories/refund_reason_factory_spec.rb +12 -0
  190. data/spec/lib/spree/core/testing_support/factories/reimbursement_factory_spec.rb +12 -0
  191. data/spec/lib/spree/core/testing_support/factories/reimbursement_type_factory_spec.rb +12 -0
  192. data/spec/lib/spree/core/testing_support/factories/return_authorization_factory_spec.rb +12 -0
  193. data/spec/lib/spree/core/testing_support/factories/return_item_factory_spec.rb +18 -0
  194. data/spec/lib/spree/core/testing_support/factories/return_reason_factory_spec.rb +12 -0
  195. data/spec/lib/spree/core/testing_support/factories/role_factory_spec.rb +18 -0
  196. data/spec/lib/spree/core/testing_support/factories/shipment_factory_spec.rb +12 -0
  197. data/spec/lib/spree/core/testing_support/factories/shipping_category_factory_spec.rb +12 -0
  198. data/spec/lib/spree/core/testing_support/factories/shipping_method_factory_spec.rb +28 -0
  199. data/spec/lib/spree/core/testing_support/factories/shipping_rate_factory_spec.rb +12 -0
  200. data/spec/lib/spree/core/testing_support/factories/state_factory_spec.rb +12 -0
  201. data/spec/lib/spree/core/testing_support/factories/stock_item_factory_spec.rb +12 -0
  202. data/spec/lib/spree/core/testing_support/factories/stock_location_factory_spec.rb +24 -0
  203. data/spec/lib/spree/core/testing_support/factories/stock_movement_factory_spec.rb +12 -0
  204. data/spec/lib/spree/core/testing_support/factories/stock_package_factory_spec.rb +26 -0
  205. data/spec/lib/spree/core/testing_support/factories/stock_packer_factory_spec.rb +16 -0
  206. data/spec/lib/spree/core/testing_support/factories/stock_transfer_factory_spec.rb +12 -0
  207. data/spec/lib/spree/core/testing_support/factories/store_credit_category_factory_spec.rb +12 -0
  208. data/spec/lib/spree/core/testing_support/factories/store_credit_event_factory_spec.rb +42 -0
  209. data/spec/lib/spree/core/testing_support/factories/store_credit_factory_spec.rb +12 -0
  210. data/spec/lib/spree/core/testing_support/factories/store_credit_type_factory_spec.rb +18 -0
  211. data/spec/lib/spree/core/testing_support/factories/store_credit_update_reason_factory_spec.rb +12 -0
  212. data/spec/lib/spree/core/testing_support/factories/store_factory_spec.rb +12 -0
  213. data/spec/lib/spree/core/testing_support/factories/tax_category_factory_spec.rb +12 -0
  214. data/spec/lib/spree/core/testing_support/factories/tax_rate_factory_spec.rb +12 -0
  215. data/spec/lib/spree/core/testing_support/factories/taxon_factory_spec.rb +12 -0
  216. data/spec/lib/spree/core/testing_support/factories/taxonomy_factory_spec.rb +12 -0
  217. data/spec/lib/spree/core/testing_support/factories/tracker_factory_spec.rb +12 -0
  218. data/spec/lib/spree/core/testing_support/factories/user_factory_spec.rb +22 -0
  219. data/spec/lib/spree/core/testing_support/factories/variant_factory_spec.rb +36 -0
  220. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_condition_factory_spec.rb +12 -0
  221. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_factory_spec.rb +12 -0
  222. data/spec/lib/spree/core/testing_support/factories/variant_property_rule_value_factory_spec.rb +12 -0
  223. data/spec/lib/spree/core/testing_support/factories/zone_factory_spec.rb +18 -0
  224. data/spec/lib/spree/core/unreturned_item_charger_spec.rb +1 -1
  225. data/spec/lib/spree/core/version_spec.rb +17 -0
  226. data/spec/lib/spree/money_spec.rb +1 -1
  227. data/spec/mailers/carton_mailer_spec.rb +1 -1
  228. data/spec/mailers/order_mailer_spec.rb +1 -1
  229. data/spec/mailers/reimbursement_mailer_spec.rb +1 -3
  230. data/spec/mailers/test_mailer_spec.rb +1 -3
  231. data/spec/models/spree/address_spec.rb +4 -4
  232. data/spec/models/spree/adjustment_reason_spec.rb +1 -3
  233. data/spec/models/spree/app_configuration_spec.rb +4 -0
  234. data/spec/models/spree/calculator/price_sack_spec.rb +3 -3
  235. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +3 -3
  236. data/spec/models/spree/calculator/tiered_percent_spec.rb +86 -10
  237. data/spec/models/spree/carton_spec.rb +3 -1
  238. data/spec/models/spree/classification_spec.rb +3 -3
  239. data/spec/models/spree/credit_card_spec.rb +16 -16
  240. data/spec/models/spree/customer_return_spec.rb +1 -1
  241. data/spec/models/spree/gateway/bogus_simple.rb +1 -1
  242. data/spec/models/spree/inventory_unit_spec.rb +3 -3
  243. data/spec/models/spree/item_adjustments_spec.rb +1 -1
  244. data/spec/models/spree/line_item_spec.rb +2 -2
  245. data/spec/models/spree/option_type_spec.rb +2 -2
  246. data/spec/models/spree/option_value_spec.rb +2 -2
  247. data/spec/models/spree/order/callbacks_spec.rb +1 -1
  248. data/spec/models/spree/order/checkout_spec.rb +16 -11
  249. data/spec/models/spree/order/payment_spec.rb +24 -22
  250. data/spec/models/spree/order/state_machine_spec.rb +1 -1
  251. data/spec/models/spree/order/validations_spec.rb +1 -1
  252. data/spec/models/spree/order_cancellations_spec.rb +63 -0
  253. data/spec/models/spree/order_contents_spec.rb +1 -1
  254. data/spec/models/spree/order_merger_spec.rb +133 -0
  255. data/spec/models/spree/order_spec.rb +39 -159
  256. data/spec/models/spree/order_update_attributes_spec.rb +82 -0
  257. data/spec/models/spree/order_updater_spec.rb +6 -4
  258. data/spec/models/spree/payment_create_spec.rb +131 -0
  259. data/spec/models/spree/payment_spec.rb +130 -48
  260. data/spec/models/spree/permission_sets/restricted_stock_transfer_management_spec.rb +91 -33
  261. data/spec/models/spree/product_filter_spec.rb +3 -3
  262. data/spec/models/spree/product_spec.rb +80 -26
  263. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +1 -1
  264. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +2 -2
  265. data/spec/models/spree/promotion/rules/nth_order_spec.rb +1 -1
  266. data/spec/models/spree/promotion/rules/user_spec.rb +2 -2
  267. data/spec/models/spree/promotion_handler/coupon_spec.rb +2 -2
  268. data/spec/models/spree/promotion_spec.rb +18 -18
  269. data/spec/models/spree/reimbursement_spec.rb +22 -0
  270. data/spec/models/spree/return_item_spec.rb +2 -2
  271. data/spec/models/spree/shipment_spec.rb +28 -12
  272. data/spec/models/spree/shipping_method_spec.rb +2 -2
  273. data/spec/models/spree/shipping_rate_spec.rb +3 -3
  274. data/spec/models/spree/stock/coordinator_spec.rb +5 -0
  275. data/spec/models/spree/stock/estimator_spec.rb +35 -1
  276. data/spec/models/spree/stock/package_spec.rb +1 -1
  277. data/spec/models/spree/stock/packer_spec.rb +2 -3
  278. data/spec/models/spree/stock/shipping_rate_selector_spec.rb +16 -0
  279. data/spec/models/spree/stock/shipping_rate_sorter_spec.rb +16 -0
  280. data/spec/models/spree/stock_item_spec.rb +5 -7
  281. data/spec/models/spree/stock_location_spec.rb +5 -9
  282. data/spec/models/spree/stock_transfer_spec.rb +33 -13
  283. data/spec/models/spree/store_credit_event_spec.rb +1 -1
  284. data/spec/models/spree/store_credit_spec.rb +1 -1
  285. data/spec/models/spree/tax_rate_spec.rb +381 -120
  286. data/spec/models/spree/taxon_spec.rb +3 -3
  287. data/spec/models/spree/transfer_item_spec.rb +4 -4
  288. data/spec/models/spree/unit_cancel_spec.rb +1 -1
  289. data/spec/models/spree/variant_spec.rb +3 -3
  290. data/spec/models/spree/zone_spec.rb +35 -1
  291. data/spec/support/concerns/working_factories.rb +9 -0
  292. data/vendor/assets/javascripts/jquery-migrate-1.0.0.js +498 -0
  293. data/vendor/assets/javascripts/jquery.payment.js +231 -80
  294. metadata +103 -27
  295. data/app/models/spree/order/currency_updater.rb +0 -40
  296. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
@@ -28,7 +28,7 @@ describe Spree::StoreCreditEvent do
28
28
  end
29
29
 
30
30
  it "excludes invalidated store credit events" do
31
- invalidated_store_credit = create(:store_credit, invalidated_at: Time.now)
31
+ invalidated_store_credit = create(:store_credit, invalidated_at: Time.current)
32
32
  event = create(:store_credit_event, action: Spree::StoreCredit::VOID_ACTION, store_credit: invalidated_store_credit)
33
33
  expect(described_class.exposed_events).not_to include event
34
34
  end
@@ -837,7 +837,7 @@ describe Spree::StoreCredit do
837
837
  subject { store_credit.invalidate(invalidation_reason, invalidation_user) }
838
838
 
839
839
  it "sets the invalidated_at field to the current time" do
840
- invalidated_at = Time.now
840
+ invalidated_at = Time.current
841
841
  Timecop.freeze(invalidated_at) do
842
842
  subject
843
843
  expect(store_credit.invalidated_at).to eq invalidated_at
@@ -181,7 +181,7 @@ describe Spree::TaxRate, :type => :model do
181
181
  allow(Spree::TaxRate).to receive_messages :match => [rate_1, rate_2]
182
182
  end
183
183
 
184
- it "should apply adjustments for two tax rates to the order" do
184
+ it "should only apply adjustments for matching rates" do
185
185
  expect(rate_1).to receive(:adjust)
186
186
  expect(rate_2).not_to receive(:adjust)
187
187
  Spree::TaxRate.adjust(order.tax_zone, line_items)
@@ -195,7 +195,7 @@ describe Spree::TaxRate, :type => :model do
195
195
  allow(Spree::TaxRate).to receive_messages :match => [rate_1, rate_2]
196
196
  end
197
197
 
198
- it "should apply adjustments for two tax rates to the order" do
198
+ it "should apply adjustments for matching rates" do
199
199
  expect(rate_1).to receive(:adjust)
200
200
  expect(rate_2).not_to receive(:adjust)
201
201
  Spree::TaxRate.adjust(order.tax_zone, shipments)
@@ -203,173 +203,434 @@ describe Spree::TaxRate, :type => :model do
203
203
  end
204
204
  end
205
205
 
206
- context "#adjust" do
207
- before do
208
- @country = create(:country)
209
- @zone = create(:zone, :name => "Country Zone", :default_tax => true, :zone_members => [])
210
- @zone.zone_members.create(:zoneable => @country)
211
- @category = Spree::TaxCategory.create :name => "Taxable Foo"
212
- @category2 = Spree::TaxCategory.create(:name => "Non Taxable")
213
- @rate1 = Spree::TaxRate.create(
214
- :amount => 0.10,
215
- :calculator => Spree::Calculator::DefaultTax.create,
216
- :tax_category => @category,
217
- :zone => @zone
218
- )
219
- @rate2 = Spree::TaxRate.create(
220
- :amount => 0.05,
221
- :calculator => Spree::Calculator::DefaultTax.create,
222
- :tax_category => @category,
223
- :zone => @zone
224
- )
225
- @order = Spree::Order.create!
226
- @taxable = create(:product, :tax_category => @category)
227
- @nontaxable = create(:product, :tax_category => @category2)
228
- end
229
-
230
- context "not taxable line item " do
231
- let!(:line_item) { @order.contents.add(@nontaxable.master, 1) }
206
+ # While the above test is nice and fast - let me tell you a story or two here.
207
+ context ".adjust" do
208
+ let(:order) { create :order }
209
+ let(:book_product) { create :product, price: 20, name: "Book", tax_category: books_category }
210
+ let(:download_product) { create :product, price: 10, name: "Download", tax_category: digital_category }
211
+ let(:sweater_product) { create :product, price: 30, name: "Download", tax_category: normal_category }
212
+ let(:book) { book_product.master }
213
+ let(:download) { download_product.master }
214
+ let(:sweater) { sweater_product.master }
215
+ let(:books_category) { create :tax_category, name: "Books" }
216
+ let(:normal_category) { create :tax_category, name: "Normal" }
217
+ let(:digital_category) { create :tax_category, name: "Digital Goods" }
218
+
219
+ context 'selling from germany' do
220
+ let(:germany) { create :country, iso: "DE" }
221
+ # The weird default_tax boolean is what makes this context one with default included taxes
222
+ let!(:germany_zone) { create :zone, countries: [germany], default_tax: true }
223
+ let(:romania) { create(:country, iso: "RO") }
224
+ let(:romania_zone) { create(:zone, countries: [romania] ) }
225
+ let(:eu_zone) { create(:zone, countries: [romania, germany]) }
226
+ let(:world_zone) { create(:zone, :with_country) }
227
+
228
+ let!(:german_book_vat) do
229
+ create(
230
+ :tax_rate,
231
+ included_in_price: true,
232
+ amount: 0.07,
233
+ tax_category: books_category,
234
+ zone: eu_zone
235
+ )
236
+ end
237
+ let!(:german_normal_vat) do
238
+ create(
239
+ :tax_rate,
240
+ included_in_price: true,
241
+ amount: 0.19,
242
+ tax_category: normal_category,
243
+ zone: eu_zone
244
+ )
245
+ end
246
+ let!(:german_digital_vat) do
247
+ create(
248
+ :tax_rate,
249
+ included_in_price: true,
250
+ amount: 0.19,
251
+ tax_category: digital_category,
252
+ zone: germany_zone
253
+ )
254
+ end
255
+ let!(:romanian_digital_vat) do
256
+ create(
257
+ :tax_rate,
258
+ included_in_price: true,
259
+ amount: 0.24,
260
+ tax_category: digital_category,
261
+ zone: romania_zone
262
+ )
263
+ end
232
264
 
233
- it "should not create a tax adjustment" do
234
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
235
- expect(line_item.adjustments.tax.charge.count).to eq(0)
265
+ before do
266
+ allow(order).to receive(:tax_zone) { tax_zone }
267
+ order.contents.add(variant)
268
+ Spree::TaxRate.adjust(order.tax_zone, order.line_items)
236
269
  end
237
270
 
238
- it "should not create a refund" do
239
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
240
- expect(line_item.adjustments.credit.count).to eq(0)
271
+ let(:line_item) { order.line_items.first }
272
+
273
+ context 'to germany' do
274
+ let(:tax_zone) { germany_zone }
275
+
276
+ context 'an order with a book' do
277
+ let(:variant) { book }
278
+
279
+ it 'still has the original price' do
280
+ expect(line_item.price).to eq(20)
281
+ end
282
+
283
+ it 'has one tax adjustment' do
284
+ expect(line_item.adjustments.tax.count).to eq(1)
285
+ end
286
+
287
+ it 'has 1.13 cents of included tax' do
288
+ expect(line_item.included_tax_total).to eq(1.31)
289
+ end
290
+ end
291
+
292
+ context 'an order with a sweater' do
293
+ let(:variant) { sweater }
294
+
295
+ it 'still has the original price' do
296
+ expect(line_item.price).to eq(30)
297
+ end
298
+
299
+ it 'has one tax adjustment' do
300
+ expect(line_item.adjustments.tax.count).to eq(1)
301
+ end
302
+
303
+ it 'has 4,78 of included tax' do
304
+ expect(line_item.included_tax_total).to eq(4.79)
305
+ end
306
+ end
307
+
308
+ context 'an order with a download' do
309
+ let(:variant) { download }
310
+
311
+ it 'still has the original price' do
312
+ expect(line_item.price).to eq(10)
313
+ end
314
+
315
+ it 'has one tax adjustment' do
316
+ expect(line_item.adjustments.tax.count).to eq(1)
317
+ end
318
+
319
+ it 'has 1.60 of included tax' do
320
+ expect(line_item.included_tax_total).to eq(1.60)
321
+ end
322
+ end
241
323
  end
242
- end
243
324
 
244
- context "taxable line item" do
245
- let!(:line_item) { @order.contents.add(@taxable.master, 1) }
325
+ context 'to romania' do
326
+ let(:tax_zone) { romania_zone }
246
327
 
247
- context "when price includes tax" do
248
- before do
249
- @rate1.update_column(:included_in_price, true)
250
- @rate2.update_column(:included_in_price, true)
251
- Spree::TaxRate.store_pre_tax_amount(line_item, [@rate1, @rate2])
328
+ context 'an order with a book' do
329
+ let(:variant) { book }
330
+
331
+ it 'still has the original price' do
332
+ expect(line_item.price).to eq(20)
333
+ end
334
+
335
+ it 'is adjusted to the original price' do
336
+ expect(line_item.total).to eq(20)
337
+ end
338
+
339
+ it 'has one tax adjustment' do
340
+ expect(line_item.adjustments.tax.count).to eq(1)
341
+ end
342
+
343
+ it 'has 1.13 cents of included tax' do
344
+ expect(line_item.included_tax_total).to eq(1.31)
345
+ end
346
+
347
+ it 'has a constant amount pre tax' do
348
+ expect(line_item.pre_tax_amount).to eq(18.69)
349
+ end
252
350
  end
253
351
 
254
- context "when zone is contained by default tax zone" do
255
- it "should create two adjustments, one for each tax rate" do
256
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
257
- expect(line_item.adjustments.count).to eq(1)
352
+ context 'an order with a sweater' do
353
+ let(:variant) { sweater }
354
+
355
+ it 'still has the original price' do
356
+ expect(line_item.price).to eq(30)
357
+ end
358
+
359
+ it 'has one tax adjustment' do
360
+ expect(line_item.adjustments.tax.count).to eq(1)
361
+ end
362
+
363
+ # This test fails intermittently - it's a matter of luck
364
+ xit 'has 4.79 of included tax' do
365
+ expect(line_item.included_tax_total).to eq(4.79)
258
366
  end
259
367
 
260
- it "should not create a tax refund" do
261
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
262
- expect(line_item.adjustments.credit.count).to eq(0)
368
+ it 'has a constant amount pre tax' do
369
+ expect(line_item.pre_tax_amount).to eq(25.21)
263
370
  end
264
371
  end
265
372
 
266
- context "when order's zone is neither the default zone, or included in the default zone, but matches the rate's zone" do
267
- before do
268
- # With no zone members, this zone will not contain anything
269
- # Previously:
270
- # Zone.stub_chain :default_tax, :contains? => false
271
- @zone.zone_members.delete_all
373
+ context 'an order with a download' do
374
+ let(:variant) { download }
375
+
376
+ it 'still has an adjusted price for romania' do
377
+ pending "waiting for the MOSS refactoring"
378
+ expect(line_item.price).to eq(10.42)
272
379
  end
273
- it "should create an adjustment" do
274
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
275
- expect(line_item.adjustments.charge.count).to eq(1)
380
+
381
+ it 'has one tax adjustment' do
382
+ expect(line_item.adjustments.tax.count).to eq(1)
383
+ end
384
+
385
+ # Fails intermittently - xit'ed for the time being
386
+ xit 'has 2.02 of included tax' do
387
+ expect(line_item.included_tax_total).to eq(2.02)
276
388
  end
277
389
 
278
- it "should not create a tax refund for each tax rate" do
279
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
280
- expect(line_item.adjustments.credit.count).to eq(0)
390
+ it 'has a constant amount pre tax' do
391
+ pending 'but it changes to 8.06, because Spree thinks both VATs apply'
392
+ expect(line_item.pre_tax_amount).to eq(8.40)
281
393
  end
282
394
  end
395
+ end
283
396
 
284
- context "when order's zone does not match default zone, is not included in the default zone, AND does not match the rate's zone" do
285
- before do
286
- @new_zone = create(:zone, :name => "New Zone", :default_tax => false)
287
- @new_country = create(:country, :name => "New Country")
288
- @new_zone.zone_members.create(:zoneable => @new_country)
289
- @order.ship_address = create(:address, :country => @new_country)
290
- @order.save
397
+ # International delivery, no tax applies whatsoever
398
+ context 'to anywhere else in the world' do
399
+ let(:tax_zone) { world_zone }
400
+
401
+ context 'an order with a book' do
402
+ let(:variant) { book }
403
+
404
+ it 'should sell at the net price' do
405
+ pending "Prices have to be adjusted"
406
+ expect(line_item.price).to eq(18.69)
291
407
  end
292
408
 
293
- it "should not create positive adjustments" do
294
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
295
- expect(line_item.adjustments.charge.count).to eq(0)
409
+ it 'is adjusted to the net price' do
410
+ expect(line_item.total).to eq(18.69)
296
411
  end
297
412
 
298
- it "should create a tax refund for each tax rate" do
299
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
300
- expect(line_item.adjustments.credit.count).to eq(1)
413
+ it 'has no tax adjustments' do
414
+ pending "Right now it gets a refund"
415
+ expect(line_item.adjustments.tax.count).to eq(0)
416
+ end
417
+
418
+ it 'has no included tax' do
419
+ expect(line_item.included_tax_total).to eq(0)
420
+ end
421
+
422
+ it 'has no additional tax' do
423
+ pending 'but there is a refund, still'
424
+ expect(line_item.additional_tax_total).to eq(0)
425
+ end
426
+
427
+ it 'has a constant amount pre tax' do
428
+ expect(line_item.pre_tax_amount).to eq(18.69)
301
429
  end
302
430
  end
303
431
 
304
- context "when price does not include tax" do
305
- before do
306
- allow(@order).to receive_messages :tax_zone => @zone
307
- [@rate1, @rate2].each do |rate|
308
- rate.included_in_price = false
309
- rate.zone = @zone
310
- rate.save
311
- end
312
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
432
+ context 'an order with a sweater' do
433
+ let(:variant) { sweater }
434
+
435
+ it 'should sell at the net price' do
436
+ pending 'but prices are not adjusted according to the zone yet'
437
+ expect(line_item.price).to eq(25.21)
438
+ end
439
+
440
+ it 'has no tax adjustments' do
441
+ pending 'but it has a refund'
442
+ expect(line_item.adjustments.tax.count).to eq(0)
443
+ end
444
+
445
+ it 'has no included tax' do
446
+ expect(line_item.included_tax_total).to eq(0)
447
+ end
448
+
449
+ it 'has no additional tax' do
450
+ pending 'but it has a refund for included taxes wtf'
451
+ expect(line_item.additional_tax_total).to eq(0)
452
+ end
453
+
454
+ it 'has a constant amount pre tax' do
455
+ expect(line_item.pre_tax_amount).to eq(25.21)
456
+ end
457
+ end
458
+
459
+ context 'an order with a download' do
460
+ let(:variant) { download }
461
+
462
+ it 'should sell at the net price' do
463
+ pending 'but prices are not adjusted yet'
464
+ expect(line_item.price).to eq(8.40)
465
+ end
466
+
467
+ it 'has no tax adjustments' do
468
+ pending 'but a refund is created'
469
+ expect(line_item.adjustments.tax.count).to eq(0)
470
+ end
471
+
472
+ it 'has no included tax' do
473
+ expect(line_item.included_tax_total).to eq(0)
474
+ end
475
+
476
+ it 'has no additional tax' do
477
+ pending 'but an tax refund that disguises as additional tax is created'
478
+ expect(line_item.additional_tax_total).to eq(0)
479
+ end
480
+
481
+ it 'has a constant amount pre tax' do
482
+ expect(line_item.pre_tax_amount).to eq(8.40)
483
+ end
484
+ end
485
+ end
486
+ end
487
+
488
+ # Choosing New York here because in the US, states matter
489
+ context 'selling from new york' do
490
+ let(:new_york) { create(:state) }
491
+ let(:united_states) { create(:country, states: [new_york]) }
492
+ let(:new_york_zone) { create(:zone, states: [new_york]) }
493
+ let(:unites_states_zone) { create(:zone, countries: [united_states])}
494
+ # Creating two rates for books here to
495
+ # mimick the existing specs
496
+ let!(:new_york_books_tax) do
497
+ create(
498
+ :tax_rate,
499
+ tax_category: books_category,
500
+ zone: new_york_zone,
501
+ included_in_price: false,
502
+ amount: 0.05
503
+ )
504
+ end
505
+
506
+ let!(:federal_books_tax) do
507
+ create(
508
+ :tax_rate,
509
+ tax_category: books_category,
510
+ zone: unites_states_zone,
511
+ included_in_price: false,
512
+ amount: 0.10
513
+ )
514
+ end
515
+
516
+ let!(:federal_digital_tax) do
517
+ create(
518
+ :tax_rate,
519
+ tax_category: digital_category,
520
+ zone: unites_states_zone,
521
+ included_in_price: false,
522
+ amount: 0.20
523
+ )
524
+ end
525
+
526
+ before do
527
+ allow(order).to receive(:tax_zone) { tax_zone }
528
+ order.contents.add(variant)
529
+ Spree::TaxRate.adjust(order.tax_zone, order.line_items)
530
+ end
531
+
532
+ let(:line_item) { order.line_items.first }
533
+
534
+ context 'to new york' do
535
+ let(:tax_zone) { new_york_zone }
536
+
537
+ # A fictional case for an item with two applicable rates
538
+ context 'an order with a book' do
539
+ let(:variant) { book }
540
+
541
+ it 'still has the original price' do
542
+ expect(line_item.price).to eq(20)
543
+ end
544
+
545
+ it 'sells for the line items amount plus additional tax' do
546
+ expect(line_item.total).to eq(23)
547
+ end
548
+
549
+ it 'has two tax adjustments' do
550
+ expect(line_item.adjustments.tax.count).to eq(2)
551
+ end
552
+
553
+ it 'has no included tax' do
554
+ expect(line_item.included_tax_total).to eq(0)
555
+ end
556
+
557
+ it 'has 15% additional tax' do
558
+ expect(line_item.additional_tax_total).to eq(3)
313
559
  end
314
560
 
315
561
  it "should delete adjustments for open order when taxrate is deleted" do
316
- @rate1.destroy!
317
- @rate2.destroy!
562
+ new_york_books_tax.destroy!
563
+ federal_books_tax.destroy!
318
564
  expect(line_item.adjustments.count).to eq(0)
319
565
  end
320
566
 
321
567
  it "should not delete adjustments for complete order when taxrate is deleted" do
322
- @order.update_column :completed_at, Time.now
323
- @rate1.destroy!
324
- @rate2.destroy!
568
+ order.update_column :completed_at, Time.now
569
+ new_york_books_tax.destroy!
570
+ federal_books_tax.destroy!
325
571
  expect(line_item.adjustments.count).to eq(2)
326
572
  end
573
+ end
327
574
 
328
- it "should create an adjustment" do
329
- expect(line_item.adjustments.count).to eq(2)
330
- end
575
+ # This is a fictional case for when no taxes apply at all.
576
+ context 'an order with a sweater' do
577
+ let(:variant) { sweater }
331
578
 
332
- it "should not create a tax refund" do
333
- expect(line_item.adjustments.credit.count).to eq(0)
579
+ it 'still has the original price' do
580
+ expect(line_item.price).to eq(30)
334
581
  end
335
582
 
336
- describe 'tax adjustments' do
337
- before { Spree::TaxRate.adjust(@order.tax_zone, @order.line_items) }
583
+ it 'sells for the line items amount plus additional tax' do
584
+ expect(line_item.total).to eq(30)
585
+ end
338
586
 
339
- it "should apply adjustments when a tax zone is present" do
340
- expect(line_item.adjustments.count).to eq(2)
341
- end
587
+ it 'has no tax adjustments' do
588
+ expect(line_item.adjustments.tax.count).to eq(0)
589
+ end
342
590
 
343
- describe 'when the tax zone is removed' do
344
- before { allow(@order).to receive_messages :tax_zone => nil }
591
+ it 'has no included tax' do
592
+ expect(line_item.included_tax_total).to eq(0)
593
+ end
345
594
 
346
- it 'does not apply any adjustments' do
347
- Spree::TaxRate.adjust(@order.tax_zone, @order.line_items)
348
- expect(line_item.adjustments.count).to eq(0)
349
- end
350
- end
595
+ it 'has no additional tax' do
596
+ expect(line_item.additional_tax_total).to eq(0)
351
597
  end
352
598
  end
353
599
 
354
- context "when two rates apply" do
355
- before do
356
- @price_before_taxes = line_item.price / (1 + @rate1.amount + @rate2.amount)
357
- # Use the same rounding method as in DefaultTax calculator
358
- @price_before_taxes = BigDecimal.new(@price_before_taxes).round(2, BigDecimal::ROUND_HALF_UP)
359
- line_item.update_column(:pre_tax_amount, @price_before_taxes)
360
- # Clear out any previously automatically-applied adjustments
361
- @order.all_adjustments.delete_all
362
- @rate1.adjust(@order.tax_zone, line_item)
363
- @rate2.adjust(@order.tax_zone, line_item)
600
+ # A fictional case with one applicable rate
601
+ context 'an order with a download' do
602
+ let(:variant) { download }
603
+
604
+ it 'still has the original price' do
605
+ expect(line_item.price).to eq(10)
606
+ end
607
+
608
+ it 'sells for the line items amount plus additional tax' do
609
+ expect(line_item.total).to eq(12)
364
610
  end
365
611
 
366
- it "should create two price adjustments" do
367
- expect(@order.line_item_adjustments.count).to eq(2)
612
+ it 'has one tax adjustments' do
613
+ expect(line_item.adjustments.tax.count).to eq(1)
368
614
  end
369
615
 
370
- it "price adjustments should be accurate" do
371
- included_tax = @order.line_item_adjustments.sum(:amount)
372
- expect(@price_before_taxes + included_tax).to eq(line_item.price)
616
+ it 'has no included tax' do
617
+ expect(line_item.included_tax_total).to eq(0)
618
+ end
619
+
620
+ it 'has 15% additional tax' do
621
+ expect(line_item.additional_tax_total).to eq(2)
622
+ end
623
+ end
624
+ end
625
+
626
+ context 'when no tax zone is given' do
627
+ let(:tax_zone) { nil }
628
+
629
+ context 'and we buy a book' do
630
+ let(:variant) { book }
631
+
632
+ it 'does not create adjustments' do
633
+ expect(line_item.adjustments.count).to eq(0)
373
634
  end
374
635
  end
375
636
  end