spree_core 3.2.1 → 3.2.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spree/core/version.rb +1 -1
  3. data/spree_core.gemspec +1 -1
  4. metadata +3 -206
  5. data/spec/fixtures/microdata.html +0 -22
  6. data/spec/fixtures/microdata_itemref.html +0 -15
  7. data/spec/fixtures/microdata_no_itemscope.html +0 -20
  8. data/spec/fixtures/thinking-cat.jpg +0 -0
  9. data/spec/helpers/base_helper_spec.rb +0 -200
  10. data/spec/helpers/products_helper_spec.rb +0 -289
  11. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  12. data/spec/lib/i18n_spec.rb +0 -123
  13. data/spec/lib/search/base_spec.rb +0 -86
  14. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  15. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  16. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  17. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  18. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  19. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  20. data/spec/lib/spree/core/importer/order_spec.rb +0 -605
  21. data/spec/lib/spree/core/number_generator_spec.rb +0 -175
  22. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  23. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  24. data/spec/lib/spree/core_spec.rb +0 -23
  25. data/spec/lib/spree/localized_number_spec.rb +0 -48
  26. data/spec/lib/spree/migrations_spec.rb +0 -36
  27. data/spec/lib/spree/money_spec.rb +0 -122
  28. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  29. data/spec/mailers/order_mailer_spec.rb +0 -122
  30. data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
  31. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  32. data/spec/mailers/test_mailer_spec.rb +0 -38
  33. data/spec/models/option_type_prototype_spec.rb +0 -9
  34. data/spec/models/spree/ability_spec.rb +0 -251
  35. data/spec/models/spree/address_spec.rb +0 -402
  36. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  37. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  38. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  39. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  40. data/spec/models/spree/adjustment_spec.rb +0 -189
  41. data/spec/models/spree/app_configuration_spec.rb +0 -26
  42. data/spec/models/spree/asset_spec.rb +0 -28
  43. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  44. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  45. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  46. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  47. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  48. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  49. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
  50. data/spec/models/spree/calculator/shipping.rb +0 -8
  51. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  52. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  53. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  54. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  55. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  56. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  57. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  58. data/spec/models/spree/calculator_spec.rb +0 -69
  59. data/spec/models/spree/classification_spec.rb +0 -93
  60. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  61. data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
  62. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  63. data/spec/models/spree/country_spec.rb +0 -55
  64. data/spec/models/spree/credit_card_spec.rb +0 -328
  65. data/spec/models/spree/customer_return_spec.rb +0 -240
  66. data/spec/models/spree/exchange_spec.rb +0 -75
  67. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  68. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  69. data/spec/models/spree/gateway_spec.rb +0 -61
  70. data/spec/models/spree/image_spec.rb +0 -8
  71. data/spec/models/spree/inventory_unit_spec.rb +0 -256
  72. data/spec/models/spree/line_item_spec.rb +0 -346
  73. data/spec/models/spree/option_type_spec.rb +0 -14
  74. data/spec/models/spree/option_value_spec.rb +0 -18
  75. data/spec/models/spree/order/address_spec.rb +0 -50
  76. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  77. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  78. data/spec/models/spree/order/checkout_spec.rb +0 -770
  79. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  80. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  81. data/spec/models/spree/order/helpers_spec.rb +0 -5
  82. data/spec/models/spree/order/payment_spec.rb +0 -214
  83. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  84. data/spec/models/spree/order/shipments_spec.rb +0 -43
  85. data/spec/models/spree/order/state_machine_spec.rb +0 -212
  86. data/spec/models/spree/order/store_credit_spec.rb +0 -426
  87. data/spec/models/spree/order/tax_spec.rb +0 -84
  88. data/spec/models/spree/order/totals_spec.rb +0 -24
  89. data/spec/models/spree/order/updating_spec.rb +0 -18
  90. data/spec/models/spree/order/validations_spec.rb +0 -15
  91. data/spec/models/spree/order_contents_spec.rb +0 -297
  92. data/spec/models/spree/order_inventory_spec.rb +0 -239
  93. data/spec/models/spree/order_merger_spec.rb +0 -135
  94. data/spec/models/spree/order_spec.rb +0 -1046
  95. data/spec/models/spree/order_updater_spec.rb +0 -305
  96. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  97. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  98. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  99. data/spec/models/spree/payment_method_spec.rb +0 -103
  100. data/spec/models/spree/payment_spec.rb +0 -919
  101. data/spec/models/spree/preference_spec.rb +0 -80
  102. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  103. data/spec/models/spree/preferences/preferable_spec.rb +0 -344
  104. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  105. data/spec/models/spree/preferences/store_spec.rb +0 -46
  106. data/spec/models/spree/price_spec.rb +0 -128
  107. data/spec/models/spree/product/scopes_spec.rb +0 -183
  108. data/spec/models/spree/product_duplicator_spec.rb +0 -103
  109. data/spec/models/spree/product_filter_spec.rb +0 -26
  110. data/spec/models/spree/product_option_type_spec.rb +0 -9
  111. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  112. data/spec/models/spree/product_property_spec.rb +0 -26
  113. data/spec/models/spree/product_spec.rb +0 -629
  114. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
  115. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  116. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  117. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  118. data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
  119. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  120. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  121. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  122. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  123. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  124. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  125. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  126. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  127. data/spec/models/spree/promotion_action_spec.rb +0 -10
  128. data/spec/models/spree/promotion_category_spec.rb +0 -17
  129. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  130. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  131. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  132. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  133. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  134. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  135. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  136. data/spec/models/spree/promotion_spec.rb +0 -679
  137. data/spec/models/spree/property_prototype_spec.rb +0 -9
  138. data/spec/models/spree/property_spec.rb +0 -5
  139. data/spec/models/spree/prototype_spec.rb +0 -5
  140. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  141. data/spec/models/spree/refund_reason_spec.rb +0 -20
  142. data/spec/models/spree/refund_spec.rb +0 -195
  143. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  144. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  145. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  146. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  147. data/spec/models/spree/reimbursement_spec.rb +0 -188
  148. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  149. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  150. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  151. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  152. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  153. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  154. data/spec/models/spree/return_authorization_spec.rb +0 -230
  155. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  156. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  157. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  158. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  159. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  160. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  161. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  162. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  163. data/spec/models/spree/return_item_spec.rb +0 -731
  164. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  165. data/spec/models/spree/role_spec.rb +0 -7
  166. data/spec/models/spree/shipment_spec.rb +0 -742
  167. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  168. data/spec/models/spree/shipping_category_spec.rb +0 -19
  169. data/spec/models/spree/shipping_method_spec.rb +0 -95
  170. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  171. data/spec/models/spree/state_spec.rb +0 -29
  172. data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
  173. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  174. data/spec/models/spree/stock/coordinator_spec.rb +0 -61
  175. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  176. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  177. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
  178. data/spec/models/spree/stock/package_spec.rb +0 -182
  179. data/spec/models/spree/stock/packer_spec.rb +0 -70
  180. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  181. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  182. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  183. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  184. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  185. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  186. data/spec/models/spree/stock_item_spec.rb +0 -432
  187. data/spec/models/spree/stock_location_spec.rb +0 -243
  188. data/spec/models/spree/stock_movement_spec.rb +0 -120
  189. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  190. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  191. data/spec/models/spree/store_credit_spec.rb +0 -786
  192. data/spec/models/spree/store_spec.rb +0 -78
  193. data/spec/models/spree/tax_category_spec.rb +0 -32
  194. data/spec/models/spree/tax_rate_spec.rb +0 -561
  195. data/spec/models/spree/taxon_spec.rb +0 -85
  196. data/spec/models/spree/taxonomy_spec.rb +0 -18
  197. data/spec/models/spree/tracker_spec.rb +0 -21
  198. data/spec/models/spree/user_spec.rb +0 -203
  199. data/spec/models/spree/variant_spec.rb +0 -818
  200. data/spec/models/spree/zone_member_spec.rb +0 -38
  201. data/spec/models/spree/zone_spec.rb +0 -472
  202. data/spec/spec_helper.rb +0 -79
  203. data/spec/support/big_decimal.rb +0 -5
  204. data/spec/support/concerns/adjustment_source.rb +0 -23
  205. data/spec/support/concerns/default_price.rb +0 -37
  206. data/spec/support/rake.rb +0 -13
  207. 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) }
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