spree_core 3.3.0.rc1 → 3.3.0.rc2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +1 -1
  3. data/app/mailers/spree/base_mailer.rb +5 -0
  4. data/app/models/spree/ability.rb +4 -1
  5. data/app/models/spree/image.rb +6 -2
  6. data/app/models/spree/order.rb +10 -9
  7. data/app/models/spree/order/payments.rb +1 -1
  8. data/app/models/spree/payment_method/store_credit.rb +4 -0
  9. data/app/models/spree/shipment.rb +2 -0
  10. data/app/views/spree/shared/_base_mailer_header.html.erb +5 -1
  11. data/app/views/spree/shared/_mailer_line_item.html.erb +5 -1
  12. data/config/routes.rb +0 -3
  13. data/lib/spree/core/components.rb +17 -0
  14. data/lib/spree/core/controller_helpers/auth.rb +3 -1
  15. data/lib/spree/core/engine.rb +1 -0
  16. data/lib/spree/core/validators/email.rb +1 -5
  17. data/lib/spree/core/version.rb +1 -1
  18. data/spree_core.gemspec +1 -1
  19. metadata +4 -204
  20. data/lib/spree/testing_support/shoulda_matcher_configuration.rb +0 -6
  21. data/spec/fixtures/thinking-cat.jpg +0 -0
  22. data/spec/helpers/base_helper_spec.rb +0 -200
  23. data/spec/helpers/products_helper_spec.rb +0 -289
  24. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  25. data/spec/lib/i18n_spec.rb +0 -123
  26. data/spec/lib/search/base_spec.rb +0 -86
  27. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  28. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  29. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  30. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  31. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  32. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  33. data/spec/lib/spree/core/importer/order_spec.rb +0 -607
  34. data/spec/lib/spree/core/number_generator_spec.rb +0 -139
  35. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  36. data/spec/lib/spree/core/validators/email_spec.rb +0 -54
  37. data/spec/lib/spree/core_spec.rb +0 -23
  38. data/spec/lib/spree/localized_number_spec.rb +0 -54
  39. data/spec/lib/spree/migrations_spec.rb +0 -36
  40. data/spec/lib/spree/money_spec.rb +0 -122
  41. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  42. data/spec/mailers/order_mailer_spec.rb +0 -122
  43. data/spec/mailers/reimbursement_mailer_spec.rb +0 -52
  44. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  45. data/spec/mailers/test_mailer_spec.rb +0 -38
  46. data/spec/models/spree/ability_spec.rb +0 -251
  47. data/spec/models/spree/address_spec.rb +0 -402
  48. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  49. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  50. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  51. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  52. data/spec/models/spree/adjustment_spec.rb +0 -189
  53. data/spec/models/spree/app_configuration_spec.rb +0 -26
  54. data/spec/models/spree/asset_spec.rb +0 -28
  55. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  56. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  57. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  58. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  59. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  60. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  61. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
  62. data/spec/models/spree/calculator/shipping.rb +0 -8
  63. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  64. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  65. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  66. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  67. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  68. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  69. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  70. data/spec/models/spree/calculator_spec.rb +0 -69
  71. data/spec/models/spree/classification_spec.rb +0 -93
  72. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  73. data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
  74. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  75. data/spec/models/spree/country_spec.rb +0 -55
  76. data/spec/models/spree/credit_card_spec.rb +0 -328
  77. data/spec/models/spree/customer_return_spec.rb +0 -240
  78. data/spec/models/spree/exchange_spec.rb +0 -75
  79. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  80. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  81. data/spec/models/spree/gateway_spec.rb +0 -61
  82. data/spec/models/spree/image_spec.rb +0 -8
  83. data/spec/models/spree/inventory_unit_spec.rb +0 -256
  84. data/spec/models/spree/line_item_spec.rb +0 -348
  85. data/spec/models/spree/option_type_prototype_spec.rb +0 -9
  86. data/spec/models/spree/option_type_spec.rb +0 -14
  87. data/spec/models/spree/option_value_spec.rb +0 -18
  88. data/spec/models/spree/order/address_spec.rb +0 -50
  89. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  90. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  91. data/spec/models/spree/order/checkout_spec.rb +0 -770
  92. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  93. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  94. data/spec/models/spree/order/helpers_spec.rb +0 -5
  95. data/spec/models/spree/order/payment_spec.rb +0 -214
  96. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  97. data/spec/models/spree/order/shipments_spec.rb +0 -43
  98. data/spec/models/spree/order/state_machine_spec.rb +0 -212
  99. data/spec/models/spree/order/store_credit_spec.rb +0 -457
  100. data/spec/models/spree/order/tax_spec.rb +0 -84
  101. data/spec/models/spree/order/totals_spec.rb +0 -24
  102. data/spec/models/spree/order/updating_spec.rb +0 -18
  103. data/spec/models/spree/order/validations_spec.rb +0 -15
  104. data/spec/models/spree/order_contents_spec.rb +0 -332
  105. data/spec/models/spree/order_inventory_spec.rb +0 -247
  106. data/spec/models/spree/order_merger_spec.rb +0 -135
  107. data/spec/models/spree/order_spec.rb +0 -1067
  108. data/spec/models/spree/order_updater_spec.rb +0 -305
  109. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  110. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  111. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  112. data/spec/models/spree/payment_method_spec.rb +0 -108
  113. data/spec/models/spree/payment_spec.rb +0 -922
  114. data/spec/models/spree/preference_spec.rb +0 -80
  115. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  116. data/spec/models/spree/preferences/preferable_spec.rb +0 -344
  117. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  118. data/spec/models/spree/preferences/store_spec.rb +0 -46
  119. data/spec/models/spree/price_spec.rb +0 -128
  120. data/spec/models/spree/product/scopes_spec.rb +0 -174
  121. data/spec/models/spree/product_duplicator_spec.rb +0 -102
  122. data/spec/models/spree/product_filter_spec.rb +0 -26
  123. data/spec/models/spree/product_option_type_spec.rb +0 -9
  124. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  125. data/spec/models/spree/product_property_spec.rb +0 -26
  126. data/spec/models/spree/product_spec.rb +0 -626
  127. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
  128. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  129. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  130. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  131. data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
  132. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  133. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  134. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  135. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  136. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  137. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  138. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  139. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  140. data/spec/models/spree/promotion_action_spec.rb +0 -10
  141. data/spec/models/spree/promotion_category_spec.rb +0 -17
  142. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  143. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  144. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  145. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  146. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  147. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  148. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  149. data/spec/models/spree/promotion_spec.rb +0 -674
  150. data/spec/models/spree/property_prototype_spec.rb +0 -9
  151. data/spec/models/spree/property_spec.rb +0 -5
  152. data/spec/models/spree/prototype_spec.rb +0 -5
  153. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  154. data/spec/models/spree/refund_reason_spec.rb +0 -20
  155. data/spec/models/spree/refund_spec.rb +0 -195
  156. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  157. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  158. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  159. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  160. data/spec/models/spree/reimbursement_spec.rb +0 -188
  161. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  162. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  163. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  164. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  165. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  166. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  167. data/spec/models/spree/return_authorization_spec.rb +0 -230
  168. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  169. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  170. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  171. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  172. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  173. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  174. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  175. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  176. data/spec/models/spree/return_item_spec.rb +0 -734
  177. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  178. data/spec/models/spree/role_spec.rb +0 -7
  179. data/spec/models/spree/shipment_spec.rb +0 -744
  180. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  181. data/spec/models/spree/shipping_category_spec.rb +0 -19
  182. data/spec/models/spree/shipping_method_spec.rb +0 -125
  183. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  184. data/spec/models/spree/state_spec.rb +0 -29
  185. data/spec/models/spree/stock/availability_validator_spec.rb +0 -42
  186. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  187. data/spec/models/spree/stock/coordinator_spec.rb +0 -61
  188. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  189. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  190. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -37
  191. data/spec/models/spree/stock/package_spec.rb +0 -182
  192. data/spec/models/spree/stock/packer_spec.rb +0 -70
  193. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  194. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  195. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  196. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  197. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  198. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  199. data/spec/models/spree/stock_item_spec.rb +0 -465
  200. data/spec/models/spree/stock_location_spec.rb +0 -243
  201. data/spec/models/spree/stock_movement_spec.rb +0 -120
  202. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  203. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  204. data/spec/models/spree/store_credit_spec.rb +0 -798
  205. data/spec/models/spree/store_spec.rb +0 -78
  206. data/spec/models/spree/tax_category_spec.rb +0 -32
  207. data/spec/models/spree/tax_rate_spec.rb +0 -561
  208. data/spec/models/spree/taxon_spec.rb +0 -93
  209. data/spec/models/spree/taxonomy_spec.rb +0 -18
  210. data/spec/models/spree/tracker_spec.rb +0 -21
  211. data/spec/models/spree/user_spec.rb +0 -203
  212. data/spec/models/spree/variant_spec.rb +0 -818
  213. data/spec/models/spree/zone_member_spec.rb +0 -38
  214. data/spec/models/spree/zone_spec.rb +0 -472
  215. data/spec/spec_helper.rb +0 -82
  216. data/spec/support/big_decimal.rb +0 -5
  217. data/spec/support/concerns/adjustment_source.rb +0 -23
  218. data/spec/support/concerns/default_price.rb +0 -37
  219. data/spec/support/rake.rb +0 -13
  220. data/spec/support/test_gateway.rb +0 -2
@@ -1,25 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator::FlatPercentItemTotal, type: :model do
4
- let(:calculator) { Spree::Calculator::FlatPercentItemTotal.new }
5
- let(:line_item) { mock_model Spree::LineItem }
6
-
7
- before { allow(calculator).to receive_messages preferred_flat_percent: 10 }
8
-
9
- context "compute" do
10
- it "should round result correctly" do
11
- allow(line_item).to receive_messages amount: 31.08
12
- expect(calculator.compute(line_item)).to eq 3.11
13
-
14
- allow(line_item).to receive_messages amount: 31.00
15
- expect(calculator.compute(line_item)).to eq 3.10
16
- end
17
-
18
- it 'returns object.amount if computed amount is greater' do
19
- allow(calculator).to receive_messages preferred_flat_percent: 110
20
- allow(line_item).to receive_messages amount: 30.00
21
-
22
- expect(calculator.compute(line_item)).to eq 30.0
23
- end
24
- end
25
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator::FlatRate, type: :model do
4
- let(:calculator) { Spree::Calculator::FlatRate.new }
5
-
6
- let(:order) do
7
- mock_model(
8
- Spree::Order, quantity: 10, currency: "USD"
9
- )
10
- end
11
-
12
- context "compute" do
13
- it "should compute the amount as the rate when currency matches the order's currency" do
14
- calculator.preferred_amount = 25.0
15
- calculator.preferred_currency = "GBP"
16
- allow(order).to receive_messages currency: "GBP"
17
- expect(calculator.compute(order).round(2)).to eq(25.0)
18
- end
19
-
20
- it "should compute the amount as 0 when currency does not match the order's currency" do
21
- calculator.preferred_amount = 100.0
22
- calculator.preferred_currency = "GBP"
23
- allow(order).to receive_messages currency: "USD"
24
- expect(calculator.compute(order).round(2)).to eq(0.0)
25
- end
26
-
27
- it "should compute the amount as 0 when currency is blank" do
28
- calculator.preferred_amount = 100.0
29
- calculator.preferred_currency = ""
30
- allow(order).to receive_messages currency: "GBP"
31
- expect(calculator.compute(order).round(2)).to eq(0.0)
32
- end
33
-
34
- it "should compute the amount as the rate when the currencies use different casing" do
35
- calculator.preferred_amount = 100.0
36
- calculator.preferred_currency = "gBp"
37
- allow(order).to receive_messages currency: "GBP"
38
- expect(calculator.compute(order).round(2)).to eq(100.0)
39
- end
40
-
41
- it "should compute the amount as 0 when there is no object" do
42
- calculator.preferred_amount = 100.0
43
- calculator.preferred_currency = "GBP"
44
- expect(calculator.compute.round(2)).to eq(0.0)
45
- end
46
- end
47
- end
@@ -1,41 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator::FlexiRate, type: :model do
4
- let(:calculator) { Spree::Calculator::FlexiRate.new }
5
-
6
- let(:order) do
7
- mock_model(
8
- Spree::Order, quantity: 10
9
- )
10
- end
11
-
12
- context "compute" do
13
- it "should compute amount correctly when all fees are 0" do
14
- expect(calculator.compute(order).round(2)).to eq(0.0)
15
- end
16
-
17
- it "should compute amount correctly when first_item has a value" do
18
- allow(calculator).to receive_messages preferred_first_item: 1.0
19
- expect(calculator.compute(order).round(2)).to eq(1.0)
20
- end
21
-
22
- it "should compute amount correctly when additional_items has a value" do
23
- allow(calculator).to receive_messages preferred_additional_item: 1.0
24
- expect(calculator.compute(order).round(2)).to eq(9.0)
25
- end
26
-
27
- it "should compute amount correctly when additional_items and first_item have values" do
28
- allow(calculator).to receive_messages preferred_first_item: 5.0, preferred_additional_item: 1.0
29
- expect(calculator.compute(order).round(2)).to eq(14.0)
30
- end
31
-
32
- it "should compute amount correctly when additional_items and first_item have values AND max items has value" do
33
- allow(calculator).to receive_messages preferred_first_item: 5.0, preferred_additional_item: 1.0, preferred_max_items: 3
34
- expect(calculator.compute(order).round(2)).to eq(7.0)
35
- end
36
-
37
- it "should allow creation of new object with all the attributes" do
38
- Spree::Calculator::FlexiRate.new(preferred_first_item: 1, preferred_additional_item: 1, preferred_max_items: 1)
39
- end
40
- end
41
- end
@@ -1,15 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- class Calculator
5
- describe PercentOnLineItem, type: :model do
6
- let(:line_item) { double("LineItem", amount: 100) }
7
-
8
- before { subject.preferred_percent = 15 }
9
-
10
- it "computes based on item price and quantity" do
11
- expect(subject.compute(line_item)).to eq 15
12
- end
13
- end
14
- end
15
- end
@@ -1,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator::PriceSack, type: :model do
4
- let(:calculator) do
5
- calculator = Spree::Calculator::PriceSack.new
6
- calculator.preferred_minimal_amount = 5
7
- calculator.preferred_normal_amount = 10
8
- calculator.preferred_discount_amount = 1
9
- calculator
10
- end
11
-
12
- let(:order) { stub_model(Spree::Order) }
13
- let(:shipment) { stub_model(Spree::Shipment, amount: 10) }
14
-
15
- # Regression test for #714 and #739
16
- it "computes with an order object" do
17
- calculator.compute(order)
18
- end
19
-
20
- # Regression test for #1156
21
- it "computes with a shipment object" do
22
- calculator.compute(shipment)
23
- end
24
-
25
- # Regression test for #2055
26
- it "computes the correct amount" do
27
- expect(calculator.compute(2)).to eq(calculator.preferred_normal_amount)
28
- expect(calculator.compute(6)).to eq(calculator.preferred_discount_amount)
29
- end
30
- end
@@ -1,47 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator::Returns::DefaultRefundAmount, type: :model do
4
- let(:order) { create(:order) }
5
- let(:line_item_quantity) { 2 }
6
- let(:item_price) { 100.0 }
7
- let(:pre_tax_amount) { line_item_quantity * item_price }
8
- let(:line_item) { create(:line_item, price: item_price, quantity: line_item_quantity) }
9
- let(:inventory_unit) { build(:inventory_unit, order: order, line_item: line_item, quantity: 1) }
10
- let(:return_item) { build(:return_item, inventory_unit: inventory_unit) }
11
- let(:calculator) { Spree::Calculator::Returns::DefaultRefundAmount.new }
12
-
13
- before { order.line_items << line_item }
14
-
15
- subject { calculator.compute(return_item) }
16
-
17
- context "not an exchange" do
18
- context "no promotions or taxes" do
19
- it { is_expected.to eq pre_tax_amount / line_item_quantity }
20
- end
21
-
22
- context "order adjustments" do
23
- let(:adjustment_amount) { -10.0 }
24
-
25
- before do
26
- order.adjustments << create(:adjustment, order: order, amount: adjustment_amount, eligible: true, label: 'Adjustment', source_type: 'Spree::Order')
27
- order.adjustments.first.update_attributes(amount: adjustment_amount)
28
- end
29
-
30
- it { is_expected.to eq (pre_tax_amount - adjustment_amount.abs) / line_item_quantity }
31
- end
32
-
33
- context "shipping adjustments" do
34
- let(:adjustment_total) { -50.0 }
35
-
36
- before { order.shipments << Spree::Shipment.new(adjustment_total: adjustment_total) }
37
-
38
- it { is_expected.to eq pre_tax_amount / line_item_quantity }
39
- end
40
- end
41
-
42
- context "an exchange" do
43
- let(:return_item) { build(:exchange_return_item) }
44
-
45
- it { is_expected.to eq 0.0 }
46
- end
47
- end
@@ -1,8 +0,0 @@
1
- require_dependency 'spree/calculator'
2
-
3
- module Spree
4
- class Calculator::Shipping < Calculator
5
- def compute(content_items)
6
- end
7
- end
8
- end
@@ -1,23 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Calculator::Shipping
5
- describe FlatPercentItemTotal, type: :model do
6
- let(:variant1) { build(:variant, price: 10.11) }
7
- let(:variant2) { build(:variant, price: 20.2222) }
8
-
9
- let(:line_item1) { build(:line_item, variant: variant1) }
10
- let(:line_item2) { build(:line_item, variant: variant2) }
11
-
12
- let(:package) do
13
- build(:stock_package, variants_contents: { variant1 => 2, variant2 => 1 })
14
- end
15
-
16
- subject { FlatPercentItemTotal.new(preferred_flat_percent: 10) }
17
-
18
- it "should round result correctly" do
19
- expect(subject.compute(package)).to eq(4.04)
20
- end
21
- end
22
- end
23
- end
@@ -1,13 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Calculator::Shipping
5
- describe FlatRate, type: :model do
6
- subject { Calculator::Shipping::FlatRate.new(preferred_amount: 4.00) }
7
-
8
- it 'always returns the same rate' do
9
- expect(subject.compute(build(:stock_package_fulfilled))).to eql 4.00
10
- end
11
- end
12
- end
13
- end
@@ -1,52 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Calculator::Shipping
5
- describe FlexiRate, type: :model do
6
- let(:variant1) { build(:variant, price: 10) }
7
- let(:variant2) { build(:variant, price: 20) }
8
-
9
- let(:package) do
10
- build(:stock_package, variants_contents: { variant1 => 4, variant2 => 6 })
11
- end
12
-
13
- let(:subject) { FlexiRate.new }
14
-
15
- context "compute" do
16
- it "should compute amount correctly when all fees are 0" do
17
- expect(subject.compute(package).round(2)).to eq(0.0)
18
- end
19
-
20
- it "should compute amount correctly when first_item has a value" do
21
- subject.preferred_first_item = 1.0
22
- expect(subject.compute(package).round(2)).to eq(1.0)
23
- end
24
-
25
- it "should compute amount correctly when additional_items has a value" do
26
- subject.preferred_additional_item = 1.0
27
- expect(subject.compute(package).round(2)).to eq(9.0)
28
- end
29
-
30
- it "should compute amount correctly when additional_items and first_item have values" do
31
- subject.preferred_first_item = 5.0
32
- subject.preferred_additional_item = 1.0
33
- expect(subject.compute(package).round(2)).to eq(14.0)
34
- end
35
-
36
- it "should compute amount correctly when additional_items and first_item have values AND max items has value" do
37
- subject.preferred_first_item = 5.0
38
- subject.preferred_additional_item = 1.0
39
- subject.preferred_max_items = 3
40
- expect(subject.compute(package).round(2)).to eq(26.0)
41
- end
42
-
43
- it "should allow creation of new object with all the attributes" do
44
- FlexiRate.new(preferred_first_item: 1,
45
- preferred_additional_item: 1,
46
- preferred_max_items: 1)
47
- end
48
- end
49
- end
50
- end
51
- end
52
-
@@ -1,20 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Calculator::Shipping
5
- describe PerItem, type: :model do
6
- let(:variant1) { build(:variant) }
7
- let(:variant2) { build(:variant) }
8
-
9
- let(:package) do
10
- build(:stock_package, variants_contents: { variant1 => 5, variant2 => 3 })
11
- end
12
-
13
- subject { PerItem.new(preferred_amount: 10) }
14
-
15
- it "correctly calculates per item shipping" do
16
- expect(subject.compute(package).to_f).to eq(80) # 5 x 10 + 3 x 10
17
- end
18
- end
19
- end
20
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Calculator::Shipping
5
- describe PriceSack do
6
- let(:variant) { build(:variant, price: 2) }
7
- subject(:calculator) do
8
- calculator = PriceSack.new
9
- calculator.preferred_minimal_amount = 5
10
- calculator.preferred_normal_amount = 10
11
- calculator.preferred_discount_amount = 1
12
- calculator
13
- end
14
-
15
- let(:normal_package) do
16
- build(:stock_package, variants_contents: { variant => 2 })
17
- end
18
-
19
- let(:discount_package) do
20
- build(:stock_package, variants_contents: { variant => 4 })
21
- end
22
-
23
- it 'computes the correct amount' do
24
- expect(calculator.compute(normal_package)).to eq(calculator.preferred_normal_amount)
25
- expect(calculator.compute(discount_package)).to eq(calculator.preferred_discount_amount)
26
- end
27
- end
28
- end
29
- end
@@ -1,40 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator::TieredFlatRate, type: :model do
4
- let(:calculator) { Spree::Calculator::TieredFlatRate.new }
5
-
6
- describe "#valid?" do
7
- subject { calculator.valid? }
8
- context "when tiers is not a hash" do
9
- before { calculator.preferred_tiers = ["nope", 0] }
10
- it { is_expected.to be false }
11
- end
12
- context "when tiers is a hash" do
13
- context "and one of the keys is not a positive number" do
14
- before { calculator.preferred_tiers = { "nope" => 20 } }
15
- it { is_expected.to be false }
16
- end
17
- end
18
- end
19
-
20
- describe "#compute" do
21
- let(:line_item) { mock_model Spree::LineItem, amount: amount }
22
- before do
23
- calculator.preferred_base_amount = 10
24
- calculator.preferred_tiers = {
25
- 100 => 15,
26
- 200 => 20
27
- }
28
- end
29
- subject { calculator.compute(line_item) }
30
- context "when amount falls within the first tier" do
31
- let(:amount) { 50 }
32
- it { is_expected.to eq 10 }
33
- end
34
- context "when amount falls within the second tier" do
35
- let(:amount) { 150 }
36
- it { is_expected.to eq 15 }
37
- end
38
- end
39
- end
40
-
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator::TieredPercent, type: :model do
4
- let(:calculator) { Spree::Calculator::TieredPercent.new }
5
-
6
- describe "#valid?" do
7
- subject { calculator.valid? }
8
- context "when base percent is less than zero" do
9
- before { calculator.preferred_base_percent = -1 }
10
- it { is_expected.to be false }
11
- end
12
- context "when base percent is greater than 100" do
13
- before { calculator.preferred_base_percent = 110 }
14
- it { is_expected.to be false }
15
- end
16
- context "when tiers is not a hash" do
17
- before { calculator.preferred_tiers = ["nope", 0] }
18
- it { is_expected.to be false }
19
- end
20
- context "when tiers is a hash" do
21
- context "and one of the keys is not a positive number" do
22
- before { calculator.preferred_tiers = { "nope" => 20 } }
23
- it { is_expected.to be false }
24
- end
25
- context "and one of the values is not a percent" do
26
- before { calculator.preferred_tiers = { 10 => 110 } }
27
- it { is_expected.to be false }
28
- end
29
- end
30
- end
31
-
32
- describe "#compute" do
33
- let(:line_item) { mock_model Spree::LineItem, amount: amount }
34
- before do
35
- calculator.preferred_base_percent = 10
36
- calculator.preferred_tiers = {
37
- 100 => 15,
38
- 200 => 20
39
- }
40
- end
41
- subject { calculator.compute(line_item) }
42
- context "when amount falls within the first tier" do
43
- let(:amount) { 50 }
44
- it { is_expected.to eq 5 }
45
- end
46
- context "when amount falls within the second tier" do
47
- let(:amount) { 150 }
48
- it { is_expected.to eq 22 }
49
- end
50
- end
51
- end