spree_core 3.1.5 → 3.1.6

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 (215) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/concerns/spree/ransackable_attributes.rb +6 -1
  3. data/app/models/concerns/spree/user_methods.rb +10 -0
  4. data/app/models/spree/legacy_user.rb +0 -8
  5. data/app/models/spree/order.rb +1 -1
  6. data/app/models/spree/product.rb +8 -0
  7. data/app/models/spree/product/scopes.rb +7 -3
  8. data/app/models/spree/stock_transfer.rb +1 -1
  9. data/config/locales/en.yml +2 -0
  10. data/lib/spree/core/version.rb +1 -1
  11. data/spree_core.gemspec +2 -2
  12. metadata +11 -208
  13. data/spec/fixtures/microdata.html +0 -22
  14. data/spec/fixtures/microdata_itemref.html +0 -15
  15. data/spec/fixtures/microdata_no_itemscope.html +0 -20
  16. data/spec/fixtures/thinking-cat.jpg +0 -0
  17. data/spec/helpers/base_helper_spec.rb +0 -200
  18. data/spec/helpers/products_helper_spec.rb +0 -296
  19. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  20. data/spec/lib/i18n_spec.rb +0 -123
  21. data/spec/lib/search/base_spec.rb +0 -86
  22. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  23. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  24. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  25. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  26. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  27. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  28. data/spec/lib/spree/core/importer/order_spec.rb +0 -605
  29. data/spec/lib/spree/core/number_generator_spec.rb +0 -175
  30. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  31. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  32. data/spec/lib/spree/core_spec.rb +0 -23
  33. data/spec/lib/spree/localized_number_spec.rb +0 -48
  34. data/spec/lib/spree/migrations_spec.rb +0 -36
  35. data/spec/lib/spree/money_spec.rb +0 -122
  36. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  37. data/spec/mailers/order_mailer_spec.rb +0 -122
  38. data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
  39. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  40. data/spec/mailers/test_mailer_spec.rb +0 -38
  41. data/spec/models/option_type_prototype_spec.rb +0 -9
  42. data/spec/models/spree/ability_spec.rb +0 -251
  43. data/spec/models/spree/address_spec.rb +0 -291
  44. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  45. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  46. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  47. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  48. data/spec/models/spree/adjustment_spec.rb +0 -189
  49. data/spec/models/spree/app_configuration_spec.rb +0 -26
  50. data/spec/models/spree/asset_spec.rb +0 -28
  51. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  52. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  53. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  54. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  55. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  56. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  57. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -51
  58. data/spec/models/spree/calculator/shipping.rb +0 -8
  59. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  60. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  61. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  62. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  63. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  64. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  65. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  66. data/spec/models/spree/calculator_spec.rb +0 -69
  67. data/spec/models/spree/classification_spec.rb +0 -93
  68. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  69. data/spec/models/spree/concerns/user_methods_spec.rb +0 -55
  70. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  71. data/spec/models/spree/country_spec.rb +0 -55
  72. data/spec/models/spree/credit_card_spec.rb +0 -328
  73. data/spec/models/spree/customer_return_spec.rb +0 -240
  74. data/spec/models/spree/exchange_spec.rb +0 -75
  75. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  76. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  77. data/spec/models/spree/gateway_spec.rb +0 -61
  78. data/spec/models/spree/image_spec.rb +0 -8
  79. data/spec/models/spree/inventory_unit_spec.rb +0 -225
  80. data/spec/models/spree/line_item_spec.rb +0 -327
  81. data/spec/models/spree/option_type_spec.rb +0 -14
  82. data/spec/models/spree/option_value_spec.rb +0 -18
  83. data/spec/models/spree/order/address_spec.rb +0 -50
  84. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  85. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  86. data/spec/models/spree/order/checkout_spec.rb +0 -782
  87. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  88. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  89. data/spec/models/spree/order/helpers_spec.rb +0 -5
  90. data/spec/models/spree/order/payment_spec.rb +0 -214
  91. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  92. data/spec/models/spree/order/shipments_spec.rb +0 -43
  93. data/spec/models/spree/order/state_machine_spec.rb +0 -211
  94. data/spec/models/spree/order/store_credit_spec.rb +0 -426
  95. data/spec/models/spree/order/tax_spec.rb +0 -84
  96. data/spec/models/spree/order/totals_spec.rb +0 -24
  97. data/spec/models/spree/order/updating_spec.rb +0 -18
  98. data/spec/models/spree/order/validations_spec.rb +0 -15
  99. data/spec/models/spree/order_contents_spec.rb +0 -297
  100. data/spec/models/spree/order_inventory_spec.rb +0 -238
  101. data/spec/models/spree/order_merger_spec.rb +0 -135
  102. data/spec/models/spree/order_spec.rb +0 -967
  103. data/spec/models/spree/order_updater_spec.rb +0 -305
  104. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  105. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  106. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  107. data/spec/models/spree/payment_method_spec.rb +0 -103
  108. data/spec/models/spree/payment_spec.rb +0 -919
  109. data/spec/models/spree/preference_spec.rb +0 -80
  110. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  111. data/spec/models/spree/preferences/preferable_spec.rb +0 -348
  112. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  113. data/spec/models/spree/preferences/store_spec.rb +0 -46
  114. data/spec/models/spree/price_spec.rb +0 -128
  115. data/spec/models/spree/product/scopes_spec.rb +0 -183
  116. data/spec/models/spree/product_duplicator_spec.rb +0 -103
  117. data/spec/models/spree/product_filter_spec.rb +0 -26
  118. data/spec/models/spree/product_option_type_spec.rb +0 -9
  119. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  120. data/spec/models/spree/product_property_spec.rb +0 -22
  121. data/spec/models/spree/product_spec.rb +0 -540
  122. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -50
  123. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  124. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  125. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  126. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  127. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  128. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  129. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  130. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  131. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  132. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  133. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  134. data/spec/models/spree/promotion_action_spec.rb +0 -10
  135. data/spec/models/spree/promotion_category_spec.rb +0 -17
  136. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  137. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  138. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  139. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  140. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  141. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  142. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  143. data/spec/models/spree/promotion_spec.rb +0 -644
  144. data/spec/models/spree/property_prototype_spec.rb +0 -9
  145. data/spec/models/spree/property_spec.rb +0 -5
  146. data/spec/models/spree/prototype_spec.rb +0 -5
  147. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  148. data/spec/models/spree/refund_reason_spec.rb +0 -7
  149. data/spec/models/spree/refund_spec.rb +0 -195
  150. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  151. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  152. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  153. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  154. data/spec/models/spree/reimbursement_spec.rb +0 -188
  155. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  156. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  157. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  158. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  159. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  160. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  161. data/spec/models/spree/return_authorization_spec.rb +0 -230
  162. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  163. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  164. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  165. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  166. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  167. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  168. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  169. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  170. data/spec/models/spree/return_item_spec.rb +0 -731
  171. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  172. data/spec/models/spree/role_spec.rb +0 -7
  173. data/spec/models/spree/shipment_spec.rb +0 -740
  174. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  175. data/spec/models/spree/shipping_category_spec.rb +0 -19
  176. data/spec/models/spree/shipping_method_spec.rb +0 -95
  177. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  178. data/spec/models/spree/state_spec.rb +0 -29
  179. data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
  180. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  181. data/spec/models/spree/stock/coordinator_spec.rb +0 -51
  182. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  183. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  184. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
  185. data/spec/models/spree/stock/package_spec.rb +0 -194
  186. data/spec/models/spree/stock/packer_spec.rb +0 -70
  187. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  188. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  189. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  190. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  191. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  192. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  193. data/spec/models/spree/stock_item_spec.rb +0 -428
  194. data/spec/models/spree/stock_location_spec.rb +0 -243
  195. data/spec/models/spree/stock_movement_spec.rb +0 -56
  196. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  197. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  198. data/spec/models/spree/store_credit_spec.rb +0 -786
  199. data/spec/models/spree/store_spec.rb +0 -78
  200. data/spec/models/spree/tax_category_spec.rb +0 -32
  201. data/spec/models/spree/tax_rate_spec.rb +0 -542
  202. data/spec/models/spree/taxon_spec.rb +0 -74
  203. data/spec/models/spree/taxonomy_spec.rb +0 -18
  204. data/spec/models/spree/tracker_spec.rb +0 -21
  205. data/spec/models/spree/user_spec.rb +0 -203
  206. data/spec/models/spree/variant_spec.rb +0 -795
  207. data/spec/models/spree/zone_member_spec.rb +0 -38
  208. data/spec/models/spree/zone_spec.rb +0 -470
  209. data/spec/spec_helper.rb +0 -77
  210. data/spec/support/big_decimal.rb +0 -5
  211. data/spec/support/concerns/adjustment_source.rb +0 -23
  212. data/spec/support/concerns/default_price.rb +0 -37
  213. data/spec/support/rake.rb +0 -13
  214. data/spec/support/test_gateway.rb +0 -2
  215. data/spec/validators/db_maximum_length_validator_spec.rb +0 -22
@@ -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,51 +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(:pre_tax_amount) { 100.0 }
7
- let(:line_item) { create(:line_item, price: 100.0, quantity: line_item_quantity, pre_tax_amount: pre_tax_amount) }
8
- let(:inventory_unit) { build(:inventory_unit, order: order, line_item: line_item) }
9
- let(:return_item) { build(:return_item, inventory_unit: inventory_unit ) }
10
- let(:calculator) { Spree::Calculator::Returns::DefaultRefundAmount.new }
11
-
12
- before { order.line_items << line_item }
13
-
14
- subject { calculator.compute(return_item) }
15
-
16
- context "not an exchange" do
17
- context "no promotions or taxes" do
18
- it { is_expected.to eq pre_tax_amount / line_item_quantity }
19
- end
20
-
21
- context "order adjustments" do
22
- let(:adjustment_amount) { -10.0 }
23
-
24
- before do
25
- order.adjustments << create(:adjustment, order: order, amount: adjustment_amount, eligible: true, label: 'Adjustment', source_type: 'Spree::Order')
26
- order.adjustments.first.update_attributes(amount: adjustment_amount)
27
- end
28
-
29
- it { is_expected.to eq (pre_tax_amount - adjustment_amount.abs) / line_item_quantity }
30
- end
31
-
32
- context "shipping adjustments" do
33
- let(:adjustment_total) { -50.0 }
34
-
35
- before { order.shipments << Spree::Shipment.new(adjustment_total: adjustment_total) }
36
-
37
- it { is_expected.to eq pre_tax_amount / line_item_quantity }
38
- end
39
- end
40
-
41
- context "an exchange" do
42
- let(:return_item) { build(:exchange_return_item) }
43
-
44
- it { is_expected.to eq 0.0 }
45
- end
46
-
47
- context "pre_tax_amount is zero" do
48
- let(:pre_tax_amount) { 0.0 }
49
- it { should eq 0.0 }
50
- end
51
- 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