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,78 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Store, :type => :model do
4
-
5
- describe ".by_url" do
6
- let!(:store) { create(:store, url: "website1.com\nwww.subdomain.com") }
7
- let!(:store_2) { create(:store, url: 'freethewhales.com') }
8
-
9
- it "should find stores by url" do
10
- by_domain = Spree::Store.by_url('www.subdomain.com')
11
-
12
- expect(by_domain).to include(store)
13
- expect(by_domain).not_to include(store_2)
14
- end
15
- end
16
-
17
- describe '.current' do
18
- # there is a default store created with the test_app rake task.
19
- let!(:store_1) { Spree::Store.first || create(:store) }
20
-
21
- let!(:store_2) { create(:store, default: false, url: 'www.subdomain.com') }
22
-
23
- it 'should return default when no domain' do
24
- expect(subject.class.current).to eql(store_1)
25
- end
26
-
27
- it 'should return store for domain' do
28
- expect(subject.class.current('spreecommerce.com')).to eql(store_1)
29
- expect(subject.class.current('www.subdomain.com')).to eql(store_2)
30
- end
31
- end
32
-
33
- describe '.default' do
34
- context 'when a default store is already present' do
35
- let!(:store) { create(:store) }
36
- let!(:store_2) { create(:store, default: true) }
37
-
38
- it 'should return the already existing default store' do
39
- expect(Spree::Store.default).to eq(store_2)
40
- end
41
-
42
- it "should ensure there is a default if one doesn't exist yet" do
43
- expect(store_2.default).to be true
44
- end
45
-
46
- it 'should ensure there is only one default' do
47
- [store, store_2].each(&:reload)
48
-
49
- expect(Spree::Store.where(default: true).count).to eq(1)
50
- expect(store_2.default).to be true
51
- expect(store.default).not_to be true
52
- end
53
-
54
- context 'when store is not saved' do
55
- before do
56
- store.default = true
57
- store.code = nil
58
- store.save
59
- end
60
-
61
- it 'ensure old default location still default' do
62
- [store, store_2].each(&:reload)
63
- expect(store.default).to be false
64
- expect(store_2.default).to be true
65
- end
66
- end
67
- end
68
-
69
- context 'when a default store is not present' do
70
- it 'should build a new default store' do
71
- expect(Spree::Store.default.class).to eq(Spree::Store)
72
- expect(Spree::Store.default.persisted?).to eq(false)
73
- expect(Spree::Store.default.default).to be(true)
74
- end
75
- end
76
- end
77
-
78
- end
@@ -1,32 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::TaxCategory, type: :model do
4
- describe 'Validations' do
5
- it { is_expected.to validate_presence_of(:name) }
6
- it { is_expected.to validate_uniqueness_of(:name).scoped_to(:deleted_at).case_insensitive.allow_blank }
7
- end
8
-
9
- context 'default tax category' do
10
- let(:tax_category) { create(:tax_category) }
11
- let(:new_tax_category) { create(:tax_category) }
12
-
13
- before do
14
- tax_category.update_column(:is_default, true)
15
- end
16
-
17
- it "should undefault the previous default tax category" do
18
- new_tax_category.update_attributes({:is_default => true})
19
- expect(new_tax_category.is_default).to be true
20
-
21
- tax_category.reload
22
- expect(tax_category.is_default).to be false
23
- end
24
-
25
- it "should undefault the previous default tax category except when updating the existing default tax category" do
26
- tax_category.update_column(:description, "Updated description")
27
-
28
- tax_category.reload
29
- expect(tax_category.is_default).to be true
30
- end
31
- end
32
- end
@@ -1,542 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::TaxRate, :type => :model do
4
- context "match" do
5
- let(:order) { create(:order) }
6
- let(:country) { create(:country) }
7
- let(:tax_category) { create(:tax_category) }
8
- let(:calculator) { Spree::Calculator::FlatRate.new }
9
-
10
- it "should return an empty array when tax_zone is nil" do
11
- allow(order).to receive_messages :tax_zone => nil
12
- expect(Spree::TaxRate.match(order.tax_zone)).to eq([])
13
- end
14
-
15
- context "when no rate zones match the tax zone" do
16
- before do
17
- Spree::TaxRate.create(:amount => 1, :zone => create(:zone))
18
- end
19
-
20
- context "when there is no default tax zone" do
21
- before do
22
- @zone = create(:zone, :name => "Country Zone", :default_tax => false, :zone_members => [])
23
- @zone.zone_members.create(:zoneable => country)
24
- end
25
-
26
- it "should return an empty array" do
27
- allow(order).to receive_messages :tax_zone => @zone
28
- expect(Spree::TaxRate.match(order.tax_zone)).to eq([])
29
- end
30
-
31
- it "should return the rate that matches the rate zone" do
32
- rate = Spree::TaxRate.create(
33
- :amount => 1,
34
- :zone => @zone,
35
- :tax_category => tax_category,
36
- :calculator => calculator
37
- )
38
-
39
- allow(order).to receive_messages :tax_zone => @zone
40
- expect(Spree::TaxRate.match(order.tax_zone)).to eq([rate])
41
- end
42
-
43
- it "should return all rates that match the rate zone" do
44
- rate1 = Spree::TaxRate.create(
45
- :amount => 1,
46
- :zone => @zone,
47
- :tax_category => tax_category,
48
- :calculator => calculator
49
- )
50
-
51
- rate2 = Spree::TaxRate.create(
52
- :amount => 2,
53
- :zone => @zone,
54
- :tax_category => tax_category,
55
- :calculator => Spree::Calculator::FlatRate.new
56
- )
57
-
58
- allow(order).to receive_messages :tax_zone => @zone
59
- expect(Spree::TaxRate.match(order.tax_zone)).to match_array([rate1, rate2])
60
- end
61
-
62
- context "when the tax_zone is contained within a rate zone" do
63
- before do
64
- sub_zone = create(:zone, :name => "State Zone", :zone_members => [])
65
- sub_zone.zone_members.create(:zoneable => create(:state, :country => country))
66
- allow(order).to receive_messages :tax_zone => sub_zone
67
- @rate = Spree::TaxRate.create(
68
- :amount => 1,
69
- :zone => @zone,
70
- :tax_category => tax_category,
71
- :calculator => calculator
72
- )
73
- end
74
-
75
- it "should return the rate zone" do
76
- expect(Spree::TaxRate.match(order.tax_zone)).to eq([@rate])
77
- end
78
- end
79
- end
80
-
81
- context "when there is a default tax zone" do
82
- before do
83
- @zone = create(:zone, :name => "Country Zone", :default_tax => true, :zone_members => [])
84
- @zone.zone_members.create(:zoneable => country)
85
- end
86
-
87
- let(:included_in_price) { false }
88
- let!(:rate) do
89
- Spree::TaxRate.create(:amount => 1,
90
- :zone => @zone,
91
- :tax_category => tax_category,
92
- :calculator => calculator,
93
- :included_in_price => included_in_price)
94
- end
95
-
96
- subject { Spree::TaxRate.match(order.tax_zone) }
97
-
98
- context "when the order has the same tax zone" do
99
- before do
100
- allow(order).to receive_messages :tax_zone => @zone
101
- end
102
-
103
- context "when the tax is not a VAT" do
104
- it { is_expected.to eq([rate]) }
105
- end
106
-
107
- context "when the tax is a VAT" do
108
- let(:included_in_price) { true }
109
- it { is_expected.to eq([rate]) }
110
- end
111
- end
112
-
113
- context "when the order has a different tax zone" do
114
- before do
115
- allow(order).to receive_messages :tax_zone => create(:zone, :name => "Other Zone")
116
- end
117
-
118
- context "when the tax is a VAT" do
119
- let(:included_in_price) { true }
120
- # The rate should NOT match in this instance because:
121
- # The order has a different tax zone, and the price is
122
- # henceforth a net price and will not change.
123
- it 'return no tax rate' do
124
- expect(subject).to be_empty
125
- end
126
- end
127
-
128
- context "when the tax is not VAT" do
129
- it "returns no tax rate" do
130
- expect(subject).to be_empty
131
- end
132
- end
133
- end
134
- end
135
- end
136
- end
137
-
138
- describe ".adjust" do
139
- let(:order) { stub_model(Spree::Order) }
140
- let(:tax_category_1) { stub_model(Spree::TaxCategory) }
141
- let(:tax_category_2) { stub_model(Spree::TaxCategory) }
142
- let(:rate_1) { stub_model(Spree::TaxRate, :tax_category => tax_category_1) }
143
- let(:rate_2) { stub_model(Spree::TaxRate, :tax_category => tax_category_2) }
144
-
145
- context "with line items" do
146
- let(:line_item) do
147
- stub_model(Spree::LineItem,
148
- :price => 10.0,
149
- :quantity => 1,
150
- :tax_category => tax_category_1,
151
- :variant => stub_model(Spree::Variant)
152
- )
153
- end
154
-
155
- let(:line_items) { [line_item] }
156
-
157
- before do
158
- allow(Spree::TaxRate).to receive_messages :match => [rate_1, rate_2]
159
- end
160
-
161
- it "should apply adjustments for two tax rates to the order" do
162
- expect(rate_1).to receive(:adjust)
163
- expect(rate_2).not_to receive(:adjust)
164
- Spree::TaxRate.adjust(order, line_items)
165
- end
166
- end
167
-
168
- context "with shipments" do
169
- let(:shipments) { [stub_model(Spree::Shipment, :cost => 10.0, :tax_category => tax_category_1)] }
170
-
171
- before do
172
- allow(Spree::TaxRate).to receive_messages :match => [rate_1, rate_2]
173
- end
174
-
175
- it "should apply adjustments for two tax rates to the order" do
176
- expect(rate_1).to receive(:adjust)
177
- expect(rate_2).not_to receive(:adjust)
178
- Spree::TaxRate.adjust(order, shipments)
179
- end
180
- end
181
-
182
- context "for MOSS taxation in Europe" do
183
- let(:germany) { create :country, name: "Germany" }
184
- let(:india) { create :country, name: "India" }
185
- let(:france) { create :country, name: "France" }
186
- let(:france_zone) { create :zone_with_country, name: "France Zone" }
187
- let(:germany_zone) { create :zone_with_country, name: "Germany Zone", default_tax: true }
188
- let(:india_zone) { create :zone_with_country, name: "India" }
189
- let(:moss_category) { Spree::TaxCategory.create(name: "Digital Goods") }
190
- let(:normal_category) { Spree::TaxCategory.create(name: "Analogue Goods") }
191
- let(:eu_zone) { create(:zone, name: "EU") }
192
-
193
- let!(:german_vat) do
194
- Spree::TaxRate.create(
195
- name: "German VAT",
196
- amount: 0.19,
197
- calculator: Spree::Calculator::DefaultTax.create,
198
- tax_category: moss_category,
199
- zone: germany_zone,
200
- included_in_price: true
201
- )
202
- end
203
- let!(:french_vat) do
204
- Spree::TaxRate.create(
205
- name: "French VAT",
206
- amount: 0.25,
207
- calculator: Spree::Calculator::DefaultTax.create,
208
- tax_category: moss_category,
209
- zone: france_zone,
210
- included_in_price: true
211
- )
212
- end
213
- let!(:eu_vat) do
214
- Spree::TaxRate.create(
215
- name: "EU_VAT",
216
- amount: 0.19,
217
- calculator: Spree::Calculator::DefaultTax.create,
218
- tax_category: normal_category,
219
- zone: eu_zone,
220
- included_in_price: true
221
- )
222
- end
223
-
224
- let(:download) { create(:product, tax_category: moss_category, price: 100) }
225
- let(:tshirt) { create(:product, tax_category: normal_category, price: 100) }
226
- let(:order) { Spree::Order.create }
227
-
228
- before do
229
- germany_zone.zone_members.create(zoneable: germany)
230
- france_zone.zone_members.create(zoneable: france)
231
- india_zone.zone_members.create(zoneable: india)
232
- eu_zone.zone_members.create(zoneable: germany)
233
- eu_zone.zone_members.create(zoneable: france)
234
- end
235
-
236
- context "a download" do
237
- before do
238
- order.contents.add(download.master, 1)
239
- end
240
-
241
- it "without an adress costs 100 euros including tax" do
242
- Spree::TaxRate.adjust(order, order.line_items)
243
- order.update_with_updater!
244
- expect(order.display_total).to eq(Spree::Money.new(100))
245
- expect(order.included_tax_total).to eq(15.97)
246
- end
247
-
248
- it "to germany costs 100 euros including tax" do
249
- allow(order).to receive(:tax_zone).and_return(germany_zone)
250
- Spree::TaxRate.adjust(order, order.line_items)
251
- order.update_with_updater!
252
- expect(order.display_total).to eq(Spree::Money.new(100))
253
- expect(order.included_tax_total).to eq(15.97)
254
- end
255
-
256
- it "to france costs more including tax" do
257
- allow(order).to receive(:tax_zone).and_return(france_zone)
258
- order.update_line_item_prices!
259
- Spree::TaxRate.adjust(order, order.line_items)
260
- order.update_with_updater!
261
- expect(order.display_total).to eq(Spree::Money.new(105.04))
262
- expect(order.included_tax_total).to eq(21.01)
263
- expect(order.additional_tax_total).to eq(0)
264
- end
265
-
266
- it "to somewhere else costs the net amount" do
267
- allow(order).to receive(:tax_zone).and_return(india_zone)
268
- order.update_line_item_prices!
269
- Spree::TaxRate.adjust(order, order.line_items)
270
- order.update_with_updater!
271
- expect(order.included_tax_total).to eq(0)
272
- expect(order.included_tax_total).to eq(0)
273
- expect(order.display_total).to eq(Spree::Money.new(84.03))
274
- end
275
- end
276
-
277
- context "a t-shirt" do
278
- before do
279
- order.contents.add(tshirt.master, 1)
280
- end
281
-
282
- it "to germany costs 100 euros including tax" do
283
- allow(order).to receive(:tax_zone).and_return(germany_zone)
284
- Spree::TaxRate.adjust(order, order.line_items)
285
- order.update_with_updater!
286
- expect(order.display_total).to eq(Spree::Money.new(100))
287
- expect(order.included_tax_total).to eq(15.97)
288
- end
289
-
290
- it "to france costs 100 euros including tax" do
291
- allow(order).to receive(:tax_zone).and_return(france_zone)
292
- order.update_line_item_prices!
293
- Spree::TaxRate.adjust(order, order.line_items)
294
- order.update_with_updater!
295
- expect(order.display_total).to eq(Spree::Money.new(100.00))
296
- expect(order.included_tax_total).to eq(15.97)
297
- expect(order.additional_tax_total).to eq(0)
298
- end
299
-
300
- it "to somewhere else costs the net amount" do
301
- allow(order).to receive(:tax_zone).and_return(india_zone)
302
- order.update_line_item_prices!
303
- Spree::TaxRate.adjust(order, order.line_items)
304
- order.update_with_updater!
305
- expect(order.included_tax_total).to eq(0)
306
- expect(order.display_total).to eq(Spree::Money.new(84.03))
307
- end
308
- end
309
- end
310
- end
311
-
312
- describe ".included_tax_amount_for" do
313
- let!(:order) { create :order_with_line_items }
314
- let!(:included_tax_rate) do
315
- create :tax_rate,
316
- included_in_price: true,
317
- tax_category: order.line_items.first.tax_category,
318
- zone: order.tax_zone,
319
- amount: 0.4
320
- end
321
-
322
- let!(:other_included_tax_rate) do
323
- create :tax_rate,
324
- included_in_price: true,
325
- tax_category: order.line_items.first.tax_category,
326
- zone: order.tax_zone,
327
- amount: 0.05
328
- end
329
-
330
- let!(:additional_tax_rate) do
331
- create :tax_rate,
332
- included_in_price: false,
333
- tax_category: order.line_items.first.tax_category,
334
- zone: order.tax_zone,
335
- amount: 0.2
336
- end
337
-
338
- let!(:included_tax_rate_from_somewhere_else) do
339
- create :tax_rate,
340
- included_in_price: true,
341
- tax_category: order.line_items.first.tax_category,
342
- zone: create(:zone_with_country),
343
- amount: 0.1
344
- end
345
- let(:price_options) do
346
- {
347
- tax_zone: order.tax_zone,
348
- tax_category: line_item.tax_category
349
- }
350
- end
351
-
352
-
353
- let(:line_item) { order.line_items.first }
354
- subject(:included_tax_amount) { Spree::TaxRate.included_tax_amount_for(price_options) }
355
-
356
- it 'will only get me tax amounts from tax_rates that match' do
357
- expect(subject).to eq(included_tax_rate.amount + other_included_tax_rate.amount)
358
- end
359
- end
360
-
361
- describe "#adjust" do
362
- before do
363
- @country = create(:country)
364
- @zone = create(:zone, :name => "Country Zone", :default_tax => true, :zone_members => [])
365
- @zone.zone_members.create(:zoneable => @country)
366
- @category = Spree::TaxCategory.create :name => "Taxable Foo"
367
- @category2 = Spree::TaxCategory.create(:name => "Non Taxable")
368
- @rate1 = Spree::TaxRate.create(
369
- :amount => 0.10,
370
- :calculator => Spree::Calculator::DefaultTax.create,
371
- :tax_category => @category,
372
- :zone => @zone
373
- )
374
- @rate2 = Spree::TaxRate.create(
375
- :amount => 0.05,
376
- :calculator => Spree::Calculator::DefaultTax.create,
377
- :tax_category => @category,
378
- :zone => @zone
379
- )
380
- @order = Spree::Order.create!
381
- @taxable = create(:product, :tax_category => @category)
382
- @nontaxable = create(:product, :tax_category => @category2)
383
- end
384
-
385
- context "not taxable line item " do
386
- let!(:line_item) { @order.contents.add(@nontaxable.master, 1) }
387
-
388
- it "should not create a tax adjustment" do
389
- Spree::TaxRate.adjust(@order, @order.line_items)
390
- expect(line_item.adjustments.tax.charge.count).to eq(0)
391
- end
392
-
393
- it "should not create a refund" do
394
- Spree::TaxRate.adjust(@order, @order.line_items)
395
- expect(line_item.adjustments.credit.count).to eq(0)
396
- end
397
- end
398
-
399
- context "taxable line item" do
400
- let!(:line_item) { @order.contents.add(@taxable.master, 1) }
401
-
402
- context "when price includes tax" do
403
- before do
404
- @rate1.update_column(:included_in_price, true)
405
- @rate2.update_column(:included_in_price, true)
406
- Spree::TaxRate.store_pre_tax_amount(line_item, [@rate1, @rate2])
407
- end
408
-
409
- context "when zone is contained by default tax zone" do
410
- it "should create two adjustments, one for each tax rate" do
411
- Spree::TaxRate.adjust(@order, @order.line_items)
412
- expect(line_item.adjustments.count).to eq(2)
413
- end
414
-
415
- it "should not create a tax refund" do
416
- Spree::TaxRate.adjust(@order, @order.line_items)
417
- expect(line_item.adjustments.credit.count).to eq(0)
418
- end
419
- end
420
-
421
- context "when order's zone is neither the default zone, or included in the default zone, but matches the rate's zone" do
422
- before do
423
- new_rate = Spree::TaxRate.create(
424
- amount: 0.2,
425
- included_in_price: true,
426
- calculator: Spree::Calculator::DefaultTax.create,
427
- tax_category: @category,
428
- zone: create(:zone_with_country)
429
- )
430
- allow(@order).to receive(:tax_zone).and_return(new_rate.zone)
431
- end
432
-
433
- it "should create an adjustment" do
434
- Spree::TaxRate.adjust(@order, @order.line_items)
435
- expect(line_item.adjustments.charge.count).to eq(1)
436
- end
437
-
438
- it "should not create a tax refund for each tax rate" do
439
- Spree::TaxRate.adjust(@order, @order.line_items)
440
- expect(line_item.adjustments.credit.count).to eq(0)
441
- end
442
- end
443
-
444
- context "when order's zone does not match default zone, is not included in the default zone, AND does not match the rate's zone" do
445
- before do
446
- @new_zone = create(:zone, :name => "New Zone", :default_tax => false)
447
- @new_country = create(:country, :name => "New Country")
448
- @new_zone.zone_members.create(:zoneable => @new_country)
449
- @order.ship_address = create(:address, :country => @new_country)
450
- @order.save
451
- @order.reload
452
- end
453
-
454
- it "should not create positive adjustments" do
455
- Spree::TaxRate.adjust(@order, @order.line_items)
456
- expect(line_item.adjustments.charge.count).to eq(0)
457
- end
458
-
459
- it "should not create a tax refund for each tax rate" do
460
- Spree::TaxRate.adjust(@order, @order.line_items)
461
- expect(line_item.adjustments.credit.count).to eq(0)
462
- end
463
- end
464
-
465
- context "when price does not include tax" do
466
- before do
467
- allow(@order).to receive_messages :tax_zone => @zone
468
- [@rate1, @rate2].each do |rate|
469
- rate.included_in_price = false
470
- rate.zone = @zone
471
- rate.save
472
- end
473
- Spree::TaxRate.adjust(@order, @order.line_items)
474
- end
475
-
476
- it "should delete adjustments for open order when taxrate is deleted" do
477
- @rate1.destroy!
478
- @rate2.destroy!
479
- expect(line_item.adjustments.count).to eq(0)
480
- end
481
-
482
- it "should not delete adjustments for complete order when taxrate is deleted" do
483
- @order.update_column :completed_at, Time.current
484
- @rate1.destroy!
485
- @rate2.destroy!
486
- expect(line_item.adjustments.count).to eq(2)
487
- end
488
-
489
- it "should create an adjustment" do
490
- expect(line_item.adjustments.count).to eq(2)
491
- end
492
-
493
- it "should not create a tax refund" do
494
- expect(line_item.adjustments.credit.count).to eq(0)
495
- end
496
-
497
- describe 'tax adjustments' do
498
- before { Spree::TaxRate.adjust(@order, @order.line_items) }
499
-
500
- it "should apply adjustments when a tax zone is present" do
501
- expect(line_item.adjustments.count).to eq(2)
502
- line_item.adjustments.each do |adjustment|
503
- expect(adjustment.label).to eq("#{adjustment.source.tax_category.name} #{adjustment.source.amount * 100}%")
504
- end
505
- end
506
-
507
- describe 'when the tax zone is removed' do
508
- before { allow(@order).to receive_messages :tax_zone => nil }
509
-
510
- it 'does not apply any adjustments' do
511
- Spree::TaxRate.adjust(@order, @order.line_items)
512
- expect(line_item.adjustments.count).to eq(0)
513
- end
514
- end
515
- end
516
- end
517
-
518
- context "when two rates apply" do
519
- before do
520
- @price_before_taxes = line_item.price / (1 + @rate1.amount + @rate2.amount)
521
- # Use the same rounding method as in DefaultTax calculator
522
- @price_before_taxes = BigDecimal.new(@price_before_taxes).round(2, BigDecimal::ROUND_HALF_UP)
523
- line_item.update_column(:pre_tax_amount, @price_before_taxes)
524
- # Clear out any previously automatically-applied adjustments
525
- @order.all_adjustments.delete_all
526
- @rate1.adjust(@order, line_item)
527
- @rate2.adjust(@order, line_item)
528
- end
529
-
530
- it "should create two price adjustments" do
531
- expect(@order.line_item_adjustments.count).to eq(2)
532
- end
533
-
534
- it "price adjustments should be accurate" do
535
- included_tax = @order.line_item_adjustments.sum(:amount)
536
- expect(@price_before_taxes + included_tax).to eq(line_item.total)
537
- end
538
- end
539
- end
540
- end
541
- end
542
- end