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,30 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::ReimbursementPerformer, type: :model do
4
- let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
5
- let(:return_item) { reimbursement.return_items.first }
6
- let(:reimbursement_type) { double("ReimbursementType") }
7
- let(:reimbursement_type_hash) { { reimbursement_type => [return_item]} }
8
-
9
- before do
10
- expect(Spree::ReimbursementPerformer).to receive(:calculate_reimbursement_types).and_return(reimbursement_type_hash)
11
- end
12
-
13
- describe ".simulate" do
14
- subject { Spree::ReimbursementPerformer.simulate(reimbursement) }
15
-
16
- it "reimburses each calculated reimbursement types with the correct return items as a simulation" do
17
- expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], true)
18
- subject
19
- end
20
- end
21
-
22
- describe '.perform' do
23
- subject { Spree::ReimbursementPerformer.perform(reimbursement) }
24
-
25
- it "reimburses each calculated reimbursement types with the correct return items as a simulation" do
26
- expect(reimbursement_type).to receive(:reimburse).with(reimbursement, [return_item], false)
27
- subject
28
- end
29
- end
30
- end
@@ -1,188 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Reimbursement, type: :model do
4
-
5
- describe "#display_total" do
6
- let(:total) { 100.50 }
7
- let(:currency) { "USD" }
8
- let(:order) { Spree::Order.new(currency: currency) }
9
- let(:reimbursement) { Spree::Reimbursement.new(total: total, order: order) }
10
-
11
- subject { reimbursement.display_total }
12
-
13
- it "returns the value as a Spree::Money instance" do
14
- expect(subject).to eq Spree::Money.new(total)
15
- end
16
-
17
- it "uses the order's currency" do
18
- expect(subject.money.currency.to_s).to eq currency
19
- end
20
- end
21
-
22
- describe "#perform!" do
23
- let!(:adjustments) { [] } # placeholder to ensure it gets run prior the "before" at this level
24
-
25
- let!(:tax_rate) { nil }
26
- let!(:tax_zone) { create(:zone_with_country, default_tax: true) }
27
-
28
- let(:order) { create(:order_with_line_items, state: 'payment', line_items_count: 1, line_items_price: line_items_price, shipment_cost: 0) }
29
- let(:line_items_price) { BigDecimal.new(10) }
30
- let(:line_item) { order.line_items.first }
31
- let(:inventory_unit) { line_item.inventory_units.first }
32
- let(:payment) { build(:payment, amount: payment_amount, order: order, state: 'completed') }
33
- let(:payment_amount) { order.total }
34
- let(:customer_return) { build(:customer_return, return_items: [return_item]) }
35
- let(:return_item) { build(:return_item, inventory_unit: inventory_unit) }
36
-
37
- let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
38
-
39
- let(:reimbursement) { create(:reimbursement, customer_return: customer_return, order: order, return_items: [return_item]) }
40
-
41
- subject { reimbursement.perform! }
42
-
43
- before do
44
- order.shipments.each do |shipment|
45
- shipment.inventory_units.update_all state: 'shipped'
46
- shipment.update_column('state', 'shipped')
47
- end
48
- order.reload
49
- order.update_with_updater!
50
- if payment
51
- payment.save!
52
- order.next! # confirm
53
- end
54
- order.next! # completed
55
- customer_return.save!
56
- return_item.accept!
57
- end
58
-
59
- it "refunds the total amount" do
60
- subject
61
- expect(reimbursement.unpaid_amount).to eq 0
62
- end
63
-
64
- it "creates a refund" do
65
- expect {
66
- subject
67
- }.to change{ Spree::Refund.count }.by(1)
68
- expect(Spree::Refund.last.amount).to eq order.total
69
- end
70
-
71
- context 'with additional tax' do
72
- let!(:tax_rate) { create(:tax_rate, name: "Sales Tax", amount: 0.10, included_in_price: false, zone: tax_zone) }
73
-
74
- it 'saves the additional tax and refunds the total' do
75
- expect {
76
- subject
77
- }.to change { Spree::Refund.count }.by(1)
78
- return_item.reload
79
- expect(return_item.additional_tax_total).to be > 0
80
- expect(return_item.additional_tax_total).to eq line_item.additional_tax_total
81
- expect(reimbursement.total).to eq line_item.pre_tax_amount + line_item.additional_tax_total
82
- expect(Spree::Refund.last.amount).to eq line_item.pre_tax_amount + line_item.additional_tax_total
83
- end
84
- end
85
-
86
- context 'with included tax' do
87
- let!(:tax_rate) { create(:tax_rate, name: "VAT Tax", amount: 0.1, included_in_price: true, zone: tax_zone) }
88
-
89
- it 'saves the included tax and refunds the total' do
90
- expect {
91
- subject
92
- }.to change { Spree::Refund.count }.by(1)
93
- return_item.reload
94
- expect(return_item.included_tax_total).to be > 0
95
- expect(return_item.included_tax_total).to eq line_item.included_tax_total
96
- expect(reimbursement.total).to eq (line_item.pre_tax_amount + line_item.included_tax_total).round(2)
97
- expect(Spree::Refund.last.amount).to eq (line_item.pre_tax_amount + line_item.included_tax_total).round(2)
98
- end
99
- end
100
-
101
- context 'when reimbursement cannot be fully performed' do
102
- let!(:non_return_refund) { create(:refund, amount: 1, payment: payment) }
103
-
104
- it 'raises IncompleteReimbursement error' do
105
- expect { subject }.to raise_error(Spree::Reimbursement::IncompleteReimbursementError)
106
- end
107
- end
108
-
109
- context "when exchange is required" do
110
- let(:exchange_variant) { build(:variant) }
111
- before { return_item.exchange_variant = exchange_variant }
112
- it "generates an exchange shipment for the order for the exchange items" do
113
- expect { subject }.to change { order.reload.shipments.count }.by 1
114
- expect(order.shipments.last.inventory_units.first.variant).to eq exchange_variant
115
- end
116
- end
117
-
118
- it "triggers the reimbursement mailer to be sent" do
119
- expect(Spree::ReimbursementMailer).to receive(:reimbursement_email).with(reimbursement.id) { double(deliver_later: true) }
120
- subject
121
- end
122
- end
123
-
124
- describe "#return_items_requiring_exchange" do
125
- it "returns only the return items that require an exchange" do
126
- return_items = [double(exchange_required?: true), double(exchange_required?: true),double(exchange_required?: false)]
127
- allow(subject).to receive(:return_items) { return_items }
128
- expect(subject.return_items_requiring_exchange).to eq return_items.take(2)
129
- end
130
- end
131
-
132
- describe "#calculated_total" do
133
- context 'with return item amounts that would round up if added' do
134
- let(:reimbursement) { Spree::Reimbursement.new }
135
-
136
- subject { reimbursement.calculated_total }
137
-
138
- before do
139
- reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 10.003)
140
- reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 10.003)
141
- end
142
-
143
- it 'rounds down' do
144
- expect(subject).to eq 20
145
- end
146
- end
147
-
148
- context 'with a return item amount that should round up' do
149
- let(:reimbursement) { Spree::Reimbursement.new }
150
-
151
- subject { reimbursement.calculated_total }
152
-
153
- before do
154
- reimbursement.return_items << Spree::ReturnItem.new(pre_tax_amount: 19.998)
155
- end
156
-
157
- it 'rounds up' do
158
- expect(subject).to eq 20
159
- end
160
- end
161
- end
162
-
163
- describe '.build_from_customer_return' do
164
- let(:customer_return) { create(:customer_return, line_items_count: 5) }
165
-
166
- let!(:pending_return_item) { customer_return.return_items.first.tap { |ri| ri.update!(acceptance_status: 'pending') } }
167
- let!(:accepted_return_item) { customer_return.return_items.second.tap(&:accept!) }
168
- let!(:rejected_return_item) { customer_return.return_items.third.tap(&:reject!) }
169
- let!(:manual_intervention_return_item) { customer_return.return_items.fourth.tap(&:require_manual_intervention!) }
170
- let!(:already_reimbursed_return_item) { customer_return.return_items.fifth }
171
-
172
- let!(:previous_reimbursement) { create(:reimbursement, order: customer_return.order, return_items: [already_reimbursed_return_item]) }
173
-
174
- subject { Spree::Reimbursement.build_from_customer_return(customer_return) }
175
-
176
- it 'connects to the accepted return items' do
177
- expect(subject.return_items.to_a).to eq [accepted_return_item]
178
- end
179
-
180
- it 'connects to the order' do
181
- expect(subject.order).to eq customer_return.order
182
- end
183
-
184
- it 'connects to the customer_return' do
185
- expect(subject.customer_return).to eq customer_return
186
- end
187
- end
188
- end
@@ -1,63 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::ReimbursementTaxCalculator, type: :model do
4
-
5
- let!(:tax_rate) { nil }
6
-
7
- let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
8
- let(:return_item) { reimbursement.return_items.first }
9
- let(:line_item) { return_item.inventory_unit.line_item }
10
-
11
- subject do
12
- Spree::ReimbursementTaxCalculator.call(reimbursement)
13
- end
14
-
15
- context 'without taxes' do
16
- let!(:tax_rate) { nil }
17
-
18
- it 'leaves the return items additional_tax_total and included_tax_total at zero' do
19
- subject
20
-
21
- expect(return_item.additional_tax_total).to eq 0
22
- expect(return_item.included_tax_total).to eq 0
23
- end
24
- end
25
-
26
- context 'with additional tax' do
27
- let!(:tax_rate) do
28
- create :tax_rate,
29
- name: "Sales Tax",
30
- amount: 0.10,
31
- included_in_price: false,
32
- tax_category: create(:tax_category),
33
- zone: create(:zone_with_country, default_tax: true)
34
- end
35
-
36
- it 'sets additional_tax_total on the return items' do
37
- subject
38
- return_item.reload
39
-
40
- expect(return_item.additional_tax_total).to be > 0
41
- expect(return_item.additional_tax_total).to eq line_item.additional_tax_total
42
- end
43
- end
44
-
45
- context 'with included tax' do
46
- let!(:tax_rate) do
47
- create :tax_rate,
48
- name: "VAT Tax",
49
- amount: 0.10,
50
- included_in_price: true,
51
- tax_category: create(:tax_category),
52
- zone: create(:zone_with_country, default_tax: true)
53
- end
54
-
55
- it 'sets included_tax_total on the return items' do
56
- subject
57
- return_item.reload
58
-
59
- expect(return_item.included_tax_total).to be > 0
60
- expect(return_item.included_tax_total).to eq line_item.included_tax_total
61
- end
62
- end
63
- end
@@ -1,53 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe ReimbursementType::Credit, type: :model do
5
- let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
6
- let(:return_item) { reimbursement.return_items.first }
7
- let(:payment) { reimbursement.order.payments.first }
8
- let(:simulate) { false }
9
- let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
10
- let(:creditable) { DummyCreditable.new(amount: 99.99) }
11
-
12
- class DummyCreditable < Spree::Base
13
- attr_accessor :amount
14
- self.table_name = 'spree_payments' # Your creditable class should not use this table
15
- end
16
-
17
- subject { Spree::ReimbursementType::Credit.reimburse(reimbursement, [return_item], simulate)}
18
-
19
- before do
20
- reimbursement.update!(total: reimbursement.calculated_total)
21
- allow(Spree::ReimbursementType::Credit).to receive(:create_creditable).and_return(creditable)
22
- end
23
-
24
- describe '.reimburse' do
25
- context 'simulate is true' do
26
- let(:simulate) { true }
27
-
28
- it 'creates one readonly lump credit for all outstanding balance payable to the customer' do
29
- expect(subject.map(&:class)).to eq [Spree::Reimbursement::Credit]
30
- expect(subject.map(&:readonly?)).to eq [true]
31
- expect(subject.sum(&:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
32
- end
33
-
34
- it 'does not save to the database' do
35
- expect { subject }.to_not change { Spree::Reimbursement::Credit.count }
36
- end
37
- end
38
-
39
- context 'simulate is false' do
40
- let(:simulate) { false }
41
-
42
- before do
43
- expect(creditable).to receive(:save).and_return(true)
44
- end
45
-
46
- it 'creates one lump credit for all outstanding balance payable to the customer' do
47
- expect { subject }.to change { Spree::Reimbursement::Credit.count }.by(1)
48
- expect(subject.sum(&:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
49
- end
50
- end
51
- end
52
- end
53
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe ReimbursementType::Exchange, type: :model do
5
- describe '.reimburse' do
6
- let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
7
- let(:return_items) { reimbursement.return_items }
8
- let(:new_exchange) { double("Exchange") }
9
- let(:simulate) { true }
10
-
11
- subject { Spree::ReimbursementType::Exchange.reimburse(reimbursement, return_items, simulate)}
12
-
13
- context 'return items are supplied' do
14
- before do
15
- expect(Spree::Exchange).to receive(:new).with(reimbursement.order, return_items).and_return(new_exchange)
16
- end
17
-
18
- context "simulate is true" do
19
-
20
- it 'does not perform an exchange and returns the exchange object' do
21
- expect(new_exchange).not_to receive(:perform!)
22
- expect(subject).to eq [new_exchange]
23
- end
24
- end
25
-
26
- context "simulate is false" do
27
- let(:simulate) { false }
28
-
29
- it 'performs an exchange and returns the exchange object' do
30
- expect(new_exchange).to receive(:perform!)
31
- expect(subject).to eq [new_exchange]
32
- end
33
- end
34
- end
35
-
36
- context "no return items are supplied" do
37
- let(:return_items) { [] }
38
-
39
- it 'does not perform an exchange and returns an empty array' do
40
- expect(new_exchange).not_to receive(:perform!)
41
- expect(subject).to eq []
42
- end
43
- end
44
- end
45
- end
46
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe ReimbursementType::OriginalPayment, type: :model do
5
- let(:reimbursement) { create(:reimbursement, return_items_count: 1) }
6
- let(:return_item) { reimbursement.return_items.first }
7
- let(:payment) { reimbursement.order.payments.first }
8
- let(:simulate) { false }
9
- let!(:default_refund_reason) { Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON, mutable: false) }
10
-
11
- subject { Spree::ReimbursementType::OriginalPayment.reimburse(reimbursement, [return_item], simulate)}
12
-
13
- before { reimbursement.update!(total: reimbursement.calculated_total) }
14
-
15
- describe ".reimburse" do
16
- context "simulate is true" do
17
- let(:simulate) { true }
18
-
19
- it "returns an array of readonly refunds" do
20
- expect(subject.map(&:class)).to eq [Spree::Refund]
21
- expect(subject.map(&:readonly?)).to eq [true]
22
- end
23
- end
24
-
25
- context "simulate is false" do
26
- it 'performs the refund' do
27
- expect {
28
- subject
29
- }.to change { payment.refunds.count }.by(1)
30
- expect(payment.refunds.sum(:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
31
- end
32
- end
33
-
34
- context 'when no credit is allowed on the payment' do
35
- before do
36
- expect_any_instance_of(Spree::Payment).to receive(:credit_allowed).and_return 0
37
- end
38
-
39
- it 'returns an empty array' do
40
- expect(subject).to eq []
41
- end
42
- end
43
-
44
- context 'when a payment is negative' do
45
- before do
46
- expect_any_instance_of(Spree::Payment).to receive(:amount).and_return -100
47
- end
48
-
49
- it 'returns an empty array' do
50
- expect(subject).to eq []
51
- end
52
- end
53
- end
54
- end
55
- end
@@ -1,101 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe ReimbursementType::StoreCredit do
5
- let(:reimbursement) { create(:reimbursement, return_items_count: 2) }
6
- let(:return_item) { reimbursement.return_items.first }
7
- let(:return_item2) { reimbursement.return_items.last }
8
- let(:payment) { reimbursement.order.payments.first }
9
- let(:simulate) { false }
10
- let!(:default_refund_reason) do
11
- Spree::RefundReason.find_or_create_by!(name: Spree::RefundReason::RETURN_PROCESSING_REASON,
12
- mutable: false)
13
- end
14
-
15
- let!(:primary_credit_type) { create(:primary_credit_type) }
16
- let!(:created_by_user) { create(:user, email: Spree::StoreCredit::DEFAULT_CREATED_BY_EMAIL) }
17
- let!(:default_reimbursement_category) { create(:store_credit_category) }
18
-
19
- subject do
20
- Spree::ReimbursementType::StoreCredit.reimburse(reimbursement, [return_item, return_item2],
21
- simulate)
22
- end
23
-
24
- before { reimbursement.update!(total: reimbursement.calculated_total) }
25
-
26
- describe '.reimburse' do
27
- context 'simulate is true' do
28
- let(:simulate) { true }
29
-
30
- context 'for store credits that the customer used' do
31
- before do
32
- allow(Spree::ReimbursementType::StoreCredit).to receive(:store_credit_payments).and_return([payment])
33
- end
34
-
35
- it 'creates readonly refunds for all store credit payments' do
36
- expect(subject.map(&:class)).to eq [Spree::Refund]
37
- expect(subject.map(&:readonly?)).to eq [true]
38
- end
39
-
40
- it 'does not save to the database' do
41
- expect { subject }.to_not change { payment.refunds.count }
42
- end
43
- end
44
-
45
- context 'for return items that were not paid for with store credit' do
46
- before do
47
- allow(Spree::ReimbursementType::StoreCredit).to receive(:store_credit_payments).and_return([])
48
- end
49
-
50
- context 'creates one readonly lump credit for all outstanding balance payable to the customer' do
51
- it 'creates a credit that is read only' do
52
- expect(subject.map(&:class)).to eq [Spree::Reimbursement::Credit]
53
- expect(subject.map(&:readonly?)).to eq [true]
54
- end
55
-
56
- it 'creates a credit which amounts to the sum of the return items rounded down' do
57
- allow(return_item).to receive(:total).and_return(10.0076)
58
- allow(return_item2).to receive(:total).and_return(10.0023)
59
- expect(subject.sum(&:amount)).to eq 20.0
60
- end
61
- end
62
-
63
- it 'does not save to the database' do
64
- expect { subject }.to_not change { Spree::Reimbursement::Credit.count }
65
- end
66
- end
67
- end
68
-
69
- context 'simulate is false' do
70
- let(:simulate) { false }
71
-
72
- context 'for store credits that the customer used' do
73
- before do
74
- allow(Spree::ReimbursementType::StoreCredit).to receive(:store_credit_payments).and_return([payment])
75
- end
76
-
77
- it 'performs refunds for all store credit payments' do
78
- expect { subject }.to change { payment.refunds.count }.by(1)
79
- expect(payment.refunds.sum(:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
80
- end
81
- end
82
-
83
- context 'for return items that were not paid for with store credit' do
84
- before do
85
- allow(Spree::ReimbursementType::StoreCredit).to receive(:store_credit_payments).and_return([])
86
- end
87
-
88
- it 'creates one lump credit for all outstanding balance payable to the customer' do
89
- expect { subject }.to change { Spree::Reimbursement::Credit.count }.by(1)
90
- expect(subject.sum(&:amount)).to eq reimbursement.return_items.to_a.sum(&:total)
91
- end
92
-
93
- it "creates a store credit with the same currency as the reimbursement's order" do
94
- expect { subject }.to change { Spree::StoreCredit.count }.by(1)
95
- expect(Spree::StoreCredit.last.currency).to eq reimbursement.order.currency
96
- end
97
- end
98
- end
99
- end
100
- end
101
- end