spree_core 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
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,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe ShippingCalculator, :type => :model do
5
- let(:variant1) { build(:variant, :price => 10) }
6
- let(:variant2) { build(:variant, :price => 20) }
7
-
8
- let(:package) do
9
- build(:stock_package, variants_contents: { variant1 => 2, variant2 => 1 })
10
- end
11
-
12
- subject { ShippingCalculator.new }
13
-
14
- it 'computes with a shipment' do
15
- shipment = mock_model(Spree::Shipment)
16
- expect(subject).to receive(:compute_shipment).with(shipment)
17
- subject.compute(shipment)
18
- end
19
-
20
- it 'computes with a package' do
21
- expect(subject).to receive(:compute_package).with(package)
22
- subject.compute(package)
23
- end
24
-
25
- it 'compute_shipment must be overridden' do
26
- expect {
27
- subject.compute_shipment(shipment)
28
- }.to raise_error(NameError)
29
- end
30
-
31
- it 'compute_package must be overridden' do
32
- expect {
33
- subject.compute_package(package)
34
- }.to raise_error(NotImplementedError)
35
- end
36
-
37
- it 'checks availability for a package' do
38
- expect(subject.available?(package)).to be true
39
- end
40
-
41
- it 'calculates totals for content_items' do
42
- expect(subject.send(:total, package.contents)).to eq 40.00
43
- end
44
- end
45
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::ShippingCategory, :type => :model do
4
-
5
- describe '#validations' do
6
- it 'should have a valid factory' do
7
- expect(FactoryGirl.build(:shipping_category)).to be_valid
8
- end
9
-
10
- it 'should require name' do
11
- expect(FactoryGirl.build(:shipping_category, name: '')).not_to be_valid
12
- end
13
-
14
- it 'should validate uniqueness' do
15
- FactoryGirl.create(:shipping_category, name: 'Test')
16
- expect(FactoryGirl.build(:shipping_category, name: 'Test')).not_to be_valid
17
- end
18
- end
19
- end
@@ -1,95 +0,0 @@
1
- require 'spec_helper'
2
-
3
- class DummyShippingCalculator < Spree::ShippingCalculator
4
- end
5
-
6
- describe Spree::ShippingMethod, :type => :model do
7
- let(:shipping_method){ create(:shipping_method) }
8
-
9
- context 'calculators' do
10
- it "Should reject calculators that don't inherit from Spree::ShippingCalculator" do
11
- allow(Spree::ShippingMethod).to receive_message_chain(:spree_calculators, :shipping_methods).and_return([
12
- Spree::Calculator::Shipping::FlatPercentItemTotal,
13
- Spree::Calculator::Shipping::PriceSack,
14
- Spree::Calculator::DefaultTax,
15
- DummyShippingCalculator # included as regression test for https://github.com/spree/spree/issues/3109
16
- ])
17
-
18
- expect(Spree::ShippingMethod.calculators).to eq([Spree::Calculator::Shipping::FlatPercentItemTotal, Spree::Calculator::Shipping::PriceSack, DummyShippingCalculator ])
19
- expect(Spree::ShippingMethod.calculators).not_to eq([Spree::Calculator::DefaultTax])
20
- end
21
- end
22
-
23
- # Regression test for #4492
24
- context "#shipments" do
25
- let!(:shipping_method) { create(:shipping_method) }
26
- let!(:shipment) do
27
- shipment = create(:shipment)
28
- shipment.shipping_rates.create!(:shipping_method => shipping_method)
29
- shipment
30
- end
31
-
32
- it "can gather all the related shipments" do
33
- expect(shipping_method.shipments).to include(shipment)
34
- end
35
- end
36
-
37
- context "validations" do
38
- before { subject.valid? }
39
-
40
- it "validates presence of name" do
41
- expect(subject.error_on(:name).size).to eq(1)
42
- end
43
-
44
- context "shipping category" do
45
- context "is required" do
46
- it { expect(subject.error_on(:base).size).to eq(1) }
47
- it 'adds error to base' do
48
- expect(subject.error_on(:base)).to include(I18n.t(:required_shipping_category,
49
- scope: [
50
- :activerecord, :errors, :models,
51
- 'spree/shipping_method', :attributes, :base
52
- ]))
53
- end
54
- end
55
-
56
- context "one associated" do
57
- before { subject.shipping_categories.push create(:shipping_category) }
58
- it { expect(subject.error_on(:base).size).to eq(0) }
59
- end
60
- end
61
- end
62
-
63
- context 'factory' do
64
- it "should set calculable correctly" do
65
- expect(shipping_method.calculator.calculable).to eq(shipping_method)
66
- end
67
- end
68
-
69
- context "generating tracking URLs" do
70
- context "shipping method has a tracking URL mask on file" do
71
- let(:tracking_url) { "https://track-o-matic.com/:tracking" }
72
- before { allow(subject).to receive(:tracking_url) { tracking_url } }
73
-
74
- context 'tracking number has spaces' do
75
- let(:tracking_numbers) { ["1234 5678 9012 3456", "a bcdef"] }
76
- let(:expectations) { %w[https://track-o-matic.com/1234%205678%209012%203456 https://track-o-matic.com/a%20bcdef] }
77
-
78
- it "should return a single URL with '%20' in lieu of spaces" do
79
- tracking_numbers.each_with_index do |num, i|
80
- expect(subject.build_tracking_url(num)).to eq(expectations[i])
81
- end
82
- end
83
- end
84
- end
85
- end
86
-
87
- # Regression test for #4320
88
- context "soft deletion" do
89
- let(:shipping_method) { create(:shipping_method) }
90
- it "soft-deletes when destroy is called" do
91
- shipping_method.destroy
92
- expect(shipping_method.deleted_at).not_to be_blank
93
- end
94
- end
95
- end
@@ -1,140 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'spec_helper'
4
-
5
- describe Spree::ShippingRate, type: :model do
6
- let(:shipment) { create(:shipment) }
7
- let(:shipping_method) { create(:shipping_method) }
8
- let(:shipping_rate) do
9
- Spree::ShippingRate.new shipment: shipment,
10
- shipping_method: shipping_method,
11
- cost: 10
12
- end
13
-
14
- context "#display_price" do
15
- context "when tax included in price" do
16
- let!(:default_zone) { create(:zone, default_tax: true) }
17
- let(:default_tax_rate) do
18
- create :tax_rate,
19
- name: "VAT",
20
- amount: 0.1,
21
- included_in_price: true,
22
- zone: default_zone
23
- end
24
- context "when the tax rate is from the default zone" do
25
-
26
- before { shipping_rate.tax_rate = default_tax_rate }
27
-
28
- it "shows correct tax amount" do
29
- expect(shipping_rate.display_price.to_s).
30
- to eq("$10.00 (incl. $0.91 #{default_tax_rate.name})")
31
- end
32
-
33
- context "when cost is zero" do
34
- before do
35
- shipping_rate.cost = 0
36
- end
37
-
38
- it "shows no tax amount" do
39
- expect(shipping_rate.display_price.to_s).to eq("$0.00")
40
- end
41
- end
42
- end
43
-
44
- context "when the tax rate is from another zone" do
45
- let!(:non_default_zone) { create(:zone, default_tax: false) }
46
-
47
- let(:non_default_tax_rate) do
48
- create :tax_rate,
49
- name: "VAT",
50
- amount: 0.2,
51
- included_in_price: true,
52
- zone: non_default_zone
53
- end
54
- before { shipping_rate.tax_rate = non_default_tax_rate }
55
-
56
- it "deducts the other zone's VAT from the calculated shipping rate" do
57
- expect(shipping_rate.display_price.to_s).
58
- to eq("$10.00 (incl. $1.67 #{non_default_tax_rate.name})")
59
- end
60
-
61
- context "when cost is zero" do
62
- before do
63
- shipping_rate.cost = 0
64
- end
65
-
66
- it "shows no tax amount" do
67
- expect(shipping_rate.display_price.to_s).to eq("$0.00")
68
- end
69
- end
70
- end
71
- end
72
-
73
- context "when tax is additional to price" do
74
- let(:tax_rate) { create(:tax_rate, name: "Sales Tax", amount: 0.1) }
75
- before { shipping_rate.tax_rate = tax_rate }
76
-
77
- it "shows correct tax amount" do
78
- expect(shipping_rate.display_price.to_s).
79
- to eq("$10.00 (+ $1.00 #{tax_rate.name})")
80
- end
81
-
82
- context "when cost is zero" do
83
- before do
84
- shipping_rate.cost = 0
85
- end
86
-
87
- it "shows no tax amount" do
88
- expect(shipping_rate.display_price.to_s).to eq("$0.00")
89
- end
90
- end
91
- end
92
-
93
- context "when the currency is JPY" do
94
- let(:shipping_rate) { Spree::ShippingRate.new(cost: 205) }
95
-
96
- before { allow(shipping_rate).to receive_messages(currency: "JPY") }
97
-
98
- it "displays the price in yen" do
99
- expect(shipping_rate.display_price.to_s).to eq("¥205")
100
- end
101
- end
102
- end
103
-
104
- # Regression test for #3829
105
- context "#shipping_method" do
106
- it "can be retrieved" do
107
- expect(shipping_rate.shipping_method.reload).to eq(shipping_method)
108
- end
109
-
110
- it "can be retrieved even when deleted" do
111
- shipping_method.update_column(:deleted_at, Time.current)
112
- shipping_rate.save
113
- shipping_rate.reload
114
- expect(shipping_rate.shipping_method).to eq(shipping_method)
115
- end
116
- end
117
-
118
- context "#tax_rate" do
119
- let!(:tax_rate) { create(:tax_rate) }
120
-
121
- before do
122
- shipping_rate.tax_rate = tax_rate
123
- end
124
-
125
- it "can be retrieved" do
126
- expect(shipping_rate.tax_rate.reload).to eq(tax_rate)
127
- end
128
-
129
- it "can be retrieved even when deleted" do
130
- tax_rate.update_column(:deleted_at, Time.current)
131
- shipping_rate.save
132
- shipping_rate.reload
133
- expect(shipping_rate.tax_rate).to eq(tax_rate)
134
- end
135
- end
136
-
137
- describe 'delegate' do
138
- it { is_expected.to delegate_method(:code).to(:shipping_method).with_prefix(true) }
139
- end
140
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::State, type: :model do
4
- describe 'Associations' do
5
- it { is_expected.to have_many(:addresses).dependent(:restrict_with_error) }
6
- end
7
-
8
- describe 'validations' do
9
- it { is_expected.to validate_presence_of(:name) }
10
- it { is_expected.to validate_presence_of(:country) }
11
- it { is_expected.to validate_uniqueness_of(:name).scoped_to(:country_id).case_insensitive }
12
- it { is_expected.to validate_uniqueness_of(:abbr).scoped_to(:country_id).case_insensitive }
13
- end
14
-
15
- it "can find a state by name or abbr" do
16
- state = create(:state, :name => "California", :abbr => "CA")
17
- expect(Spree::State.find_all_by_name_or_abbr("California")).to include(state)
18
- expect(Spree::State.find_all_by_name_or_abbr("CA")).to include(state)
19
- end
20
-
21
- it "can find all states group by country id" do
22
- state = create(:state)
23
- expect(Spree::State.states_group_by_country_id).to eq({ state.country_id.to_s => [[state.id, state.name]] })
24
- end
25
-
26
- describe 'whitelisted_ransackable_attributes' do
27
- it { expect(Spree::State.whitelisted_ransackable_attributes).to eq(%w(abbr)) }
28
- end
29
- end
@@ -1,36 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- describe AvailabilityValidator, :type => :model do
6
- let!(:line_item) { double(quantity: 5, variant_id: 1, variant: double.as_null_object, errors: double('errors'), inventory_units: []) }
7
-
8
- subject { described_class.new }
9
-
10
- it 'should be valid when supply is sufficient' do
11
- allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: true)
12
- expect(line_item).not_to receive(:errors)
13
- subject.validate(line_item)
14
- end
15
-
16
- it 'should be invalid when supply is insufficent' do
17
- allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: false)
18
- expect(line_item.errors).to receive(:[]).with(:quantity).and_return []
19
- subject.validate(line_item)
20
- end
21
-
22
- it 'should consider existing inventory_units sufficient' do
23
- allow_any_instance_of(Stock::Quantifier).to receive_messages(can_supply?: false)
24
- expect(line_item).not_to receive(:errors)
25
- allow(line_item).to receive_messages(inventory_units: [double] * 5)
26
- subject.validate(line_item)
27
- end
28
-
29
- it 'should be valid when the quantity is zero' do
30
- expect(line_item).to receive(:quantity).and_return(0)
31
- expect(line_item.errors).to_not receive(:[]).with(:quantity)
32
- subject.validate(line_item)
33
- end
34
- end
35
- end
36
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- describe ContentItem, type: :model do
6
- let(:variant) { build(:variant, weight: 25.0) }
7
- subject { ContentItem.new(build(:inventory_unit, variant: variant)) }
8
-
9
- describe 'Delegations' do
10
- it { is_expected.to delegate_method(:line_item).to(:inventory_unit) }
11
- it { is_expected.to delegate_method(:variant).to(:inventory_unit) }
12
- it { is_expected.to delegate_method(:dimension).to(:variant).with_prefix }
13
- it { is_expected.to delegate_method(:price).to(:variant) }
14
- it { is_expected.to delegate_method(:volume).to(:variant).with_prefix }
15
- it { is_expected.to delegate_method(:weight).to(:variant).with_prefix }
16
- end
17
-
18
- context "#volume" do
19
- it "calculate the total volume of the variant" do
20
- expect(subject.volume).to eq variant.volume * subject.quantity
21
- end
22
- end
23
-
24
- context "#dimension" do
25
- it "calculate the total dimension of the variant" do
26
- expect(subject.dimension).to eq variant.dimension * subject.quantity
27
- end
28
- end
29
- end
30
- end
31
- end
@@ -1,51 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module Stock
5
- describe Coordinator, :type => :model do
6
- let!(:order) { create(:order_with_line_items) }
7
-
8
- subject { Coordinator.new(order) }
9
-
10
- context "packages" do
11
- it "builds, prioritizes and estimates" do
12
- expect(subject).to receive(:build_packages).ordered
13
- expect(subject).to receive(:prioritize_packages).ordered
14
- expect(subject).to receive(:estimate_packages).ordered
15
- subject.packages
16
- end
17
- end
18
-
19
- describe "#shipments" do
20
- let(:packages) { [build(:stock_package_fulfilled), build(:stock_package_fulfilled)] }
21
-
22
- before { allow(subject).to receive(:packages).and_return(packages) }
23
-
24
- it "turns packages into shipments" do
25
- shipments = subject.shipments
26
- expect(shipments.count).to eq packages.count
27
- shipments.each { |shipment| expect(shipment).to be_a Shipment }
28
- end
29
-
30
- it "puts the order's ship address on the shipments" do
31
- shipments = subject.shipments
32
- shipments.each { |shipment| expect(shipment.address).to eq order.ship_address }
33
- end
34
- end
35
-
36
- context "build packages" do
37
- it "builds a package for every stock location" do
38
- subject.packages.count == StockLocation.count
39
- end
40
-
41
- context "missing stock items in stock location" do
42
- let!(:another_location) { create(:stock_location, propagate_all_variants: false) }
43
-
44
- it "builds packages only for valid stock locations" do
45
- expect(subject.build_packages.count).to eq(StockLocation.count - 1)
46
- end
47
- end
48
- end
49
- end
50
- end
51
- end