spree_core 3.3.0.rc1 → 3.3.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/app/helpers/spree/base_helper.rb +1 -1
  3. data/app/mailers/spree/base_mailer.rb +5 -0
  4. data/app/models/spree/ability.rb +4 -1
  5. data/app/models/spree/image.rb +6 -2
  6. data/app/models/spree/order.rb +10 -9
  7. data/app/models/spree/order/payments.rb +1 -1
  8. data/app/models/spree/payment_method/store_credit.rb +4 -0
  9. data/app/models/spree/shipment.rb +2 -0
  10. data/app/views/spree/shared/_base_mailer_header.html.erb +5 -1
  11. data/app/views/spree/shared/_mailer_line_item.html.erb +5 -1
  12. data/config/routes.rb +0 -3
  13. data/lib/spree/core/components.rb +17 -0
  14. data/lib/spree/core/controller_helpers/auth.rb +3 -1
  15. data/lib/spree/core/engine.rb +1 -0
  16. data/lib/spree/core/validators/email.rb +1 -5
  17. data/lib/spree/core/version.rb +1 -1
  18. data/spree_core.gemspec +1 -1
  19. metadata +4 -204
  20. data/lib/spree/testing_support/shoulda_matcher_configuration.rb +0 -6
  21. data/spec/fixtures/thinking-cat.jpg +0 -0
  22. data/spec/helpers/base_helper_spec.rb +0 -200
  23. data/spec/helpers/products_helper_spec.rb +0 -289
  24. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  25. data/spec/lib/i18n_spec.rb +0 -123
  26. data/spec/lib/search/base_spec.rb +0 -86
  27. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  28. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  29. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  30. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  31. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  32. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  33. data/spec/lib/spree/core/importer/order_spec.rb +0 -607
  34. data/spec/lib/spree/core/number_generator_spec.rb +0 -139
  35. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  36. data/spec/lib/spree/core/validators/email_spec.rb +0 -54
  37. data/spec/lib/spree/core_spec.rb +0 -23
  38. data/spec/lib/spree/localized_number_spec.rb +0 -54
  39. data/spec/lib/spree/migrations_spec.rb +0 -36
  40. data/spec/lib/spree/money_spec.rb +0 -122
  41. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  42. data/spec/mailers/order_mailer_spec.rb +0 -122
  43. data/spec/mailers/reimbursement_mailer_spec.rb +0 -52
  44. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  45. data/spec/mailers/test_mailer_spec.rb +0 -38
  46. data/spec/models/spree/ability_spec.rb +0 -251
  47. data/spec/models/spree/address_spec.rb +0 -402
  48. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  49. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  50. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  51. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  52. data/spec/models/spree/adjustment_spec.rb +0 -189
  53. data/spec/models/spree/app_configuration_spec.rb +0 -26
  54. data/spec/models/spree/asset_spec.rb +0 -28
  55. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  56. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  57. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  58. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  59. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  60. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  61. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
  62. data/spec/models/spree/calculator/shipping.rb +0 -8
  63. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  64. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  65. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  66. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  67. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  68. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  69. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  70. data/spec/models/spree/calculator_spec.rb +0 -69
  71. data/spec/models/spree/classification_spec.rb +0 -93
  72. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  73. data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
  74. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  75. data/spec/models/spree/country_spec.rb +0 -55
  76. data/spec/models/spree/credit_card_spec.rb +0 -328
  77. data/spec/models/spree/customer_return_spec.rb +0 -240
  78. data/spec/models/spree/exchange_spec.rb +0 -75
  79. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  80. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  81. data/spec/models/spree/gateway_spec.rb +0 -61
  82. data/spec/models/spree/image_spec.rb +0 -8
  83. data/spec/models/spree/inventory_unit_spec.rb +0 -256
  84. data/spec/models/spree/line_item_spec.rb +0 -348
  85. data/spec/models/spree/option_type_prototype_spec.rb +0 -9
  86. data/spec/models/spree/option_type_spec.rb +0 -14
  87. data/spec/models/spree/option_value_spec.rb +0 -18
  88. data/spec/models/spree/order/address_spec.rb +0 -50
  89. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  90. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  91. data/spec/models/spree/order/checkout_spec.rb +0 -770
  92. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  93. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  94. data/spec/models/spree/order/helpers_spec.rb +0 -5
  95. data/spec/models/spree/order/payment_spec.rb +0 -214
  96. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  97. data/spec/models/spree/order/shipments_spec.rb +0 -43
  98. data/spec/models/spree/order/state_machine_spec.rb +0 -212
  99. data/spec/models/spree/order/store_credit_spec.rb +0 -457
  100. data/spec/models/spree/order/tax_spec.rb +0 -84
  101. data/spec/models/spree/order/totals_spec.rb +0 -24
  102. data/spec/models/spree/order/updating_spec.rb +0 -18
  103. data/spec/models/spree/order/validations_spec.rb +0 -15
  104. data/spec/models/spree/order_contents_spec.rb +0 -332
  105. data/spec/models/spree/order_inventory_spec.rb +0 -247
  106. data/spec/models/spree/order_merger_spec.rb +0 -135
  107. data/spec/models/spree/order_spec.rb +0 -1067
  108. data/spec/models/spree/order_updater_spec.rb +0 -305
  109. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  110. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  111. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  112. data/spec/models/spree/payment_method_spec.rb +0 -108
  113. data/spec/models/spree/payment_spec.rb +0 -922
  114. data/spec/models/spree/preference_spec.rb +0 -80
  115. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  116. data/spec/models/spree/preferences/preferable_spec.rb +0 -344
  117. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  118. data/spec/models/spree/preferences/store_spec.rb +0 -46
  119. data/spec/models/spree/price_spec.rb +0 -128
  120. data/spec/models/spree/product/scopes_spec.rb +0 -174
  121. data/spec/models/spree/product_duplicator_spec.rb +0 -102
  122. data/spec/models/spree/product_filter_spec.rb +0 -26
  123. data/spec/models/spree/product_option_type_spec.rb +0 -9
  124. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  125. data/spec/models/spree/product_property_spec.rb +0 -26
  126. data/spec/models/spree/product_spec.rb +0 -626
  127. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
  128. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  129. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  130. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  131. data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
  132. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  133. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  134. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  135. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  136. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  137. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  138. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  139. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  140. data/spec/models/spree/promotion_action_spec.rb +0 -10
  141. data/spec/models/spree/promotion_category_spec.rb +0 -17
  142. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  143. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  144. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  145. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  146. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  147. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  148. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  149. data/spec/models/spree/promotion_spec.rb +0 -674
  150. data/spec/models/spree/property_prototype_spec.rb +0 -9
  151. data/spec/models/spree/property_spec.rb +0 -5
  152. data/spec/models/spree/prototype_spec.rb +0 -5
  153. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  154. data/spec/models/spree/refund_reason_spec.rb +0 -20
  155. data/spec/models/spree/refund_spec.rb +0 -195
  156. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  157. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  158. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  159. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  160. data/spec/models/spree/reimbursement_spec.rb +0 -188
  161. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  162. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  163. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  164. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  165. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  166. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  167. data/spec/models/spree/return_authorization_spec.rb +0 -230
  168. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  169. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  170. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  171. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  172. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  173. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  174. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  175. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  176. data/spec/models/spree/return_item_spec.rb +0 -734
  177. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  178. data/spec/models/spree/role_spec.rb +0 -7
  179. data/spec/models/spree/shipment_spec.rb +0 -744
  180. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  181. data/spec/models/spree/shipping_category_spec.rb +0 -19
  182. data/spec/models/spree/shipping_method_spec.rb +0 -125
  183. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  184. data/spec/models/spree/state_spec.rb +0 -29
  185. data/spec/models/spree/stock/availability_validator_spec.rb +0 -42
  186. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  187. data/spec/models/spree/stock/coordinator_spec.rb +0 -61
  188. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  189. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  190. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -37
  191. data/spec/models/spree/stock/package_spec.rb +0 -182
  192. data/spec/models/spree/stock/packer_spec.rb +0 -70
  193. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  194. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  195. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  196. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  197. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  198. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  199. data/spec/models/spree/stock_item_spec.rb +0 -465
  200. data/spec/models/spree/stock_location_spec.rb +0 -243
  201. data/spec/models/spree/stock_movement_spec.rb +0 -120
  202. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  203. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  204. data/spec/models/spree/store_credit_spec.rb +0 -798
  205. data/spec/models/spree/store_spec.rb +0 -78
  206. data/spec/models/spree/tax_category_spec.rb +0 -32
  207. data/spec/models/spree/tax_rate_spec.rb +0 -561
  208. data/spec/models/spree/taxon_spec.rb +0 -93
  209. data/spec/models/spree/taxonomy_spec.rb +0 -18
  210. data/spec/models/spree/tracker_spec.rb +0 -21
  211. data/spec/models/spree/user_spec.rb +0 -203
  212. data/spec/models/spree/variant_spec.rb +0 -818
  213. data/spec/models/spree/zone_member_spec.rb +0 -38
  214. data/spec/models/spree/zone_spec.rb +0 -472
  215. data/spec/spec_helper.rb +0 -82
  216. data/spec/support/big_decimal.rb +0 -5
  217. data/spec/support/concerns/adjustment_source.rb +0 -23
  218. data/spec/support/concerns/default_price.rb +0 -37
  219. data/spec/support/rake.rb +0 -13
  220. data/spec/support/test_gateway.rb +0 -2
@@ -1,58 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Preferences::ScopedStore, type: :model do
4
- let(:scoped_store){ described_class.new(prefix, suffix) }
5
- subject{ scoped_store }
6
- let(:prefix){ nil }
7
- let(:suffix){ nil }
8
-
9
- describe '#store' do
10
- subject{ scoped_store.store }
11
- it{ is_expected.to be Spree::Preferences::Store.instance }
12
- end
13
-
14
- context 'stubbed store' do
15
- let(:store){ double(:store) }
16
- before do
17
- allow(scoped_store).to receive(:store).and_return(store)
18
- end
19
-
20
- context "with a prefix" do
21
- let(:prefix){ 'my_class' }
22
-
23
- it "can fetch" do
24
- expect(store).to receive(:fetch).with('my_class/attr')
25
- scoped_store.fetch('attr'){ 'default' }
26
- end
27
-
28
- it "can assign" do
29
- expect(store).to receive(:[]=).with('my_class/attr', 'val')
30
- scoped_store['attr'] = 'val'
31
- end
32
-
33
- it "can delete" do
34
- expect(store).to receive(:delete).with('my_class/attr')
35
- scoped_store.delete('attr')
36
- end
37
-
38
- context "and suffix" do
39
- let(:suffix){ 123 }
40
-
41
- it "can fetch" do
42
- expect(store).to receive(:fetch).with('my_class/attr/123')
43
- scoped_store.fetch('attr'){ 'default' }
44
- end
45
-
46
- it "can assign" do
47
- expect(store).to receive(:[]=).with('my_class/attr/123', 'val')
48
- scoped_store['attr'] = 'val'
49
- end
50
-
51
- it "can delete" do
52
- expect(store).to receive(:delete).with('my_class/attr/123')
53
- scoped_store.delete('attr')
54
- end
55
- end
56
- end
57
- end
58
- end
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Preferences::Store, type: :model do
4
- before :each do
5
- @store = Spree::Preferences::StoreInstance.new
6
- end
7
-
8
- it "sets and gets a key" do
9
- @store.set :test, 1
10
- expect(@store.exist?(:test)).to be true
11
- expect(@store.get(:test)).to eq 1
12
- end
13
-
14
- it "can set and get false values when cache return nil" do
15
- @store.set :test, false
16
- expect(@store.get(:test)).to be false
17
- end
18
-
19
- it "will return db value when cache is emtpy and cache the db value" do
20
- preference = Spree::Preference.where(key: 'test').first_or_initialize
21
- preference.value = '123'
22
- preference.save
23
-
24
- Rails.cache.clear
25
- expect(@store.get(:test)).to eq '123'
26
- expect(Rails.cache.read(:test)).to eq '123'
27
- end
28
-
29
- it "should return and cache fallback value when supplied" do
30
- Rails.cache.clear
31
- expect(@store.get(:test){ false }).to be false
32
- expect(Rails.cache.read(:test)).to be false
33
- end
34
-
35
- it "should return but not cache fallback value when persistence is disabled" do
36
- Rails.cache.clear
37
- allow(@store).to receive_messages(should_persist?: false)
38
- expect(@store.get(:test){ true }).to be true
39
- expect(Rails.cache.exist?(:test)).to be false
40
- end
41
-
42
- it "should return nil when key can't be found and fallback value is not supplied" do
43
- expect(@store.get(:random_key){ nil }).to be_nil
44
- end
45
-
46
- end
@@ -1,128 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Price, type: :model do
4
- describe '#amount=' do
5
- let(:price) { Spree::Price.new }
6
- let(:amount) { '3,0A0' }
7
-
8
- before do
9
- price.amount = amount
10
- end
11
-
12
- it 'is expected to equal to localized number' do
13
- expect(price.amount).to eq(Spree::LocalizedNumber.parse(amount))
14
- end
15
- end
16
-
17
- describe '#price' do
18
- let(:price) { Spree::Price.new }
19
- let(:amount) { 3000.00 }
20
-
21
- context 'when amount is changed' do
22
- before do
23
- price.amount = amount
24
- end
25
-
26
- it 'is expected to equal to price' do
27
- expect(price.amount).to eq(price.price)
28
- end
29
- end
30
- end
31
-
32
- describe 'validations' do
33
- let(:variant) { stub_model Spree::Variant }
34
- subject { Spree::Price.new variant: variant, amount: amount }
35
-
36
- context 'when the amount is nil' do
37
- let(:amount) { nil }
38
- it { is_expected.to be_valid }
39
- end
40
-
41
- context 'when the amount is less than 0' do
42
- let(:amount) { -1 }
43
-
44
- it 'has 1 error_on' do
45
- expect(subject.error_on(:amount).size).to eq(1)
46
- end
47
- it 'populates errors' do
48
- subject.valid?
49
- expect(subject.errors.messages[:amount].first).to eq 'must be greater than or equal to 0'
50
- end
51
- end
52
-
53
- context 'when the amount is greater than maximum amount' do
54
- let(:amount) { Spree::Price::MAXIMUM_AMOUNT + 1 }
55
-
56
- it 'has 1 error_on' do
57
- expect(subject.error_on(:amount).size).to eq(1)
58
- end
59
- it 'populates errors' do
60
- subject.valid?
61
- expect(subject.errors.messages[:amount].first).to eq "must be less than or equal to #{Spree::Price::MAXIMUM_AMOUNT}"
62
- end
63
- end
64
-
65
- context 'when the amount is between 0 and the maximum amount' do
66
- let(:amount) { Spree::Price::MAXIMUM_AMOUNT }
67
- it { is_expected.to be_valid }
68
- end
69
- end
70
-
71
- describe '#price_including_vat_for(zone)' do
72
- let(:variant) { stub_model Spree::Variant }
73
- let(:default_zone) { Spree::Zone.new }
74
- let(:zone) { Spree::Zone.new }
75
- let(:amount) { 10 }
76
- let(:tax_category) { Spree::TaxCategory.new }
77
- let(:price) { Spree::Price.new variant: variant, amount: amount }
78
- let(:price_options) { { tax_zone: zone } }
79
-
80
- subject(:price_with_vat) { price.price_including_vat_for(price_options) }
81
-
82
- context 'when called with a non-default zone' do
83
- before do
84
- allow(variant).to receive(:tax_category).and_return(tax_category)
85
- expect(price).to receive(:default_zone).at_least(:once).and_return(default_zone)
86
- allow(price).to receive(:apply_foreign_vat?).and_return(true)
87
- allow(price).to receive(:included_tax_amount).with(tax_zone: default_zone, tax_category: tax_category) { 0.19 }
88
- allow(price).to receive(:included_tax_amount).with(tax_zone: zone, tax_category: tax_category) { 0.25 }
89
- end
90
-
91
- it "returns the correct price including another VAT to two digits" do
92
- expect(price_with_vat).to eq(10.50)
93
- end
94
- end
95
-
96
- context 'when called from the default zone' do
97
- before do
98
- allow(variant).to receive(:tax_category).and_return(tax_category)
99
- expect(price).to receive(:default_zone).at_least(:once).and_return(zone)
100
- end
101
-
102
- it "returns the correct price" do
103
- expect(price).to receive(:price).and_call_original
104
- expect(price_with_vat).to eq(10.00)
105
- end
106
- end
107
-
108
- context 'when no default zone is set' do
109
- before do
110
- allow(variant).to receive(:tax_category).and_return(tax_category)
111
- expect(price).to receive(:default_zone).at_least(:once).and_return(nil)
112
- end
113
-
114
- it "returns the correct price" do
115
- expect(price).to receive(:price).and_call_original
116
- expect(price.price_including_vat_for(tax_zone: zone)).to eq(10.00)
117
- end
118
- end
119
- end
120
-
121
- describe '#display_price_including_vat_for(zone)' do
122
- subject { Spree::Price.new amount: 10 }
123
- it 'calls #price_including_vat_for' do
124
- expect(subject).to receive(:price_including_vat_for)
125
- subject.display_price_including_vat_for(nil)
126
- end
127
- end
128
- end
@@ -1,174 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe "Product scopes", type: :model do
4
- let!(:product) { create(:product) }
5
-
6
- describe '#available' do
7
- context 'when discontinued' do
8
- let!(:discontinued_product) { create(:product, discontinue_on: Time.current - 1.day) }
9
-
10
- it { expect(Spree::Product.available).not_to include(discontinued_product) }
11
- end
12
-
13
- context 'when not discontinued' do
14
- let!(:product_2) { create(:product, discontinue_on: Time.current + 1.day) }
15
-
16
- it { expect(Spree::Product.available).to include(product_2) }
17
- end
18
-
19
- context 'when available' do
20
- let!(:product_2) { create(:product, available_on: Time.current - 1.day) }
21
-
22
- it { expect(Spree::Product.available).to include(product_2) }
23
- end
24
-
25
- context 'when not available' do
26
- let!(:unavailable_product) { create(:product, available_on: Time.current + 1.day) }
27
-
28
- it { expect(Spree::Product.available).not_to include(unavailable_product) }
29
- end
30
- end
31
-
32
- context "A product assigned to parent and child taxons" do
33
- before do
34
- @taxonomy = create(:taxonomy)
35
- @root_taxon = @taxonomy.root
36
-
37
- @parent_taxon = create(:taxon, name: 'Parent', taxonomy_id: @taxonomy.id, parent: @root_taxon)
38
- @child_taxon = create(:taxon, name:'Child 1', taxonomy_id: @taxonomy.id, parent: @parent_taxon)
39
- @parent_taxon.reload # Need to reload for descendents to show up
40
-
41
- product.taxons << @parent_taxon
42
- product.taxons << @child_taxon
43
- end
44
-
45
- it "calling Product.in_taxon returns products in child taxons" do
46
- product.taxons -= [@child_taxon]
47
- expect(product.taxons.count).to eq(1)
48
-
49
- expect(Spree::Product.in_taxon(@parent_taxon)).to include(product)
50
- end
51
-
52
- it "calling Product.in_taxon should not return duplicate records" do
53
- expect(Spree::Product.in_taxon(@parent_taxon).to_a.count).to eq(1)
54
- end
55
-
56
- context 'orders products based on their ordering within the classifications' do
57
- let(:other_taxon) { create(:taxon, products: [product]) }
58
- let!(:product_2) { create(:product, taxons: [@child_taxon, other_taxon]) }
59
-
60
- it 'by initial ordering' do
61
- expect(Spree::Product.in_taxon(@child_taxon)).to eq([product, product_2])
62
- expect(Spree::Product.in_taxon(other_taxon)).to eq([product, product_2])
63
- end
64
-
65
- it 'after ordering changed' do
66
- [@child_taxon, other_taxon].each do |taxon|
67
- Spree::Classification.find_by(taxon: taxon, product: product).insert_at(2)
68
- expect(Spree::Product.in_taxon(taxon)).to eq([product_2, product])
69
- end
70
- end
71
- end
72
- end
73
-
74
- context "property scopes" do
75
- let(:name) { "A proper tee" }
76
- let(:value) { "A proper value"}
77
- let!(:property) { create(:property, name: name)}
78
-
79
- before do
80
- product.properties << property
81
- product.product_properties.find_by(property: property).update_column(:value, value)
82
- end
83
-
84
- context "with_property" do
85
- let(:with_property) { Spree::Product.method(:with_property) }
86
- it "finds by a property's name" do
87
- expect(with_property.(name).count).to eq(1)
88
- end
89
-
90
- it "doesn't find any properties with an unknown name" do
91
- expect(with_property.("fake").count).to eq(0)
92
- end
93
-
94
- it "finds by a property" do
95
- expect(with_property.(property).count).to eq(1)
96
- end
97
-
98
- it "finds by an id" do
99
- expect(with_property.(property.id).count).to eq(1)
100
- end
101
-
102
- it "cannot find a property with an unknown id" do
103
- expect(with_property.(0).count).to eq(0)
104
- end
105
- end
106
-
107
- context "with_property_value" do
108
- let(:with_property_value) { Spree::Product.method(:with_property_value) }
109
- it "finds by a property's name" do
110
- expect(with_property_value.(name, value).count).to eq(1)
111
- end
112
-
113
- it "cannot find by an unknown property's name" do
114
- expect(with_property_value.("fake", value).count).to eq(0)
115
- end
116
-
117
- it "cannot find with a name by an incorrect value" do
118
- expect(with_property_value.(name, "fake").count).to eq(0)
119
- end
120
-
121
- it "finds by a property" do
122
- expect(with_property_value.(property, value).count).to eq(1)
123
- end
124
-
125
- it "cannot find with a property by an incorrect value" do
126
- expect(with_property_value.(property, "fake").count).to eq(0)
127
- end
128
-
129
- it "finds by an id with a value" do
130
- expect(with_property_value.(property.id, value).count).to eq(1)
131
- end
132
-
133
- it "cannot find with an invalid id" do
134
- expect(with_property_value.(0, value).count).to eq(0)
135
- end
136
-
137
- it "cannot find with an invalid value" do
138
- expect(with_property_value.(property.id, "fake").count).to eq(0)
139
- end
140
- end
141
- end
142
-
143
- context '#add_simple_scopes' do
144
- let(:simple_scopes) { [:ascend_by_updated_at, :descend_by_name] }
145
-
146
- before do
147
- Spree::Product.add_simple_scopes(simple_scopes)
148
- end
149
-
150
- context 'define scope' do
151
- context 'ascend_by_updated_at' do
152
- context 'on class' do
153
- it { expect(Spree::Product.ascend_by_updated_at.to_sql).to eq Spree::Product.order("#{Spree::Product.quoted_table_name}.updated_at ASC").to_sql }
154
- end
155
-
156
- context 'on ActiveRecord::Relation' do
157
- it { expect(Spree::Product.limit(2).ascend_by_updated_at.to_sql).to eq Spree::Product.limit(2).order("#{Spree::Product.quoted_table_name}.updated_at ASC").to_sql }
158
- it { expect(Spree::Product.limit(2).ascend_by_updated_at.to_sql).to eq Spree::Product.ascend_by_updated_at.limit(2).to_sql }
159
- end
160
- end
161
-
162
- context 'descend_by_name' do
163
- context 'on class' do
164
- it { expect(Spree::Product.descend_by_name.to_sql).to eq Spree::Product.order("#{Spree::Product.quoted_table_name}.name DESC").to_sql }
165
- end
166
-
167
- context 'on ActiveRecord::Relation' do
168
- it { expect(Spree::Product.limit(2).descend_by_name.to_sql).to eq Spree::Product.limit(2).order("#{Spree::Product.quoted_table_name}.name DESC").to_sql }
169
- it { expect(Spree::Product.limit(2).descend_by_name.to_sql).to eq Spree::Product.descend_by_name.limit(2).to_sql }
170
- end
171
- end
172
- end
173
- end
174
- end
@@ -1,102 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Spree
4
- describe Spree::ProductDuplicator, type: :model do
5
- let(:product) { create(:product, properties: [create(:property, name: "MyProperty")]) }
6
- let!(:duplicator) { Spree::ProductDuplicator.new(product) }
7
-
8
- let(:image) { File.open(File.expand_path("../../../fixtures/thinking-cat.jpg", __FILE__)) }
9
- let(:params) do
10
- {
11
- viewable_id: product.master.id,
12
- viewable_type: "Spree::Variant",
13
- attachment: image,
14
- alt: "position 1",
15
- position: 1,
16
- }
17
- end
18
-
19
- before do
20
- Spree::Image.create(params)
21
- end
22
-
23
- it "will duplicate the product" do
24
- expect { duplicator.duplicate }.to change { Spree::Product.count }.by(1)
25
- end
26
-
27
- it "will duplicate already duplicated product" do
28
- expect { 3.times { duplicator.duplicate } }.to change { Spree::Product.count }.by(3)
29
- end
30
-
31
- context "when image duplication enabled" do
32
- it "will duplicate the product images" do
33
- expect { duplicator.duplicate }.to change { Spree::Image.count }.by(1)
34
- end
35
- end
36
-
37
- context "when image duplication disabled" do
38
- let!(:duplicator) { Spree::ProductDuplicator.new(product, false) }
39
-
40
- it "will not duplicate the product images" do
41
- expect { duplicator.duplicate }.to change { Spree::Image.count }.by(0)
42
- end
43
- end
44
-
45
- context "image duplication default" do
46
- context "when default is set to true" do
47
- it "clones images if no flag passed to initializer" do
48
- expect { duplicator.duplicate }.to change { Spree::Image.count }.by(1)
49
- end
50
- end
51
-
52
- context "when default is set to false" do
53
- before do
54
- ProductDuplicator.clone_images_default = false
55
- end
56
-
57
- after do
58
- ProductDuplicator.clone_images_default = true
59
- end
60
-
61
- it "does not clone images if no flag passed to initializer" do
62
- expect { ProductDuplicator.new(product).duplicate }.to change { Spree::Image.count }.by(0)
63
- end
64
- end
65
- end
66
-
67
- context "product attributes" do
68
- let!(:new_product) { duplicator.duplicate }
69
-
70
- it "will set an unique name" do
71
- expect(new_product.name).to eql "COPY OF #{product.name}"
72
- end
73
-
74
- it "will set an unique sku" do
75
- expect(new_product.sku).to include "COPY OF SKU"
76
- end
77
-
78
- it "copied the properties" do
79
- expect(new_product.product_properties.count).to be 1
80
- expect(new_product.product_properties.first.property.name).to eql "MyProperty"
81
- end
82
- end
83
-
84
- context "with variants" do
85
- let(:option_type) { create(:option_type, name: "MyOptionType") }
86
- let(:option_value1) { create(:option_value, name: "OptionValue1", option_type: option_type) }
87
- let(:option_value2) { create(:option_value, name: "OptionValue2", option_type: option_type) }
88
-
89
- let!(:variant1) { create(:variant, product: product, option_values: [option_value1]) }
90
- let!(:variant2) { create(:variant, product: product, option_values: [option_value2]) }
91
-
92
- it "will duplciate the variants" do
93
- # will change the count by 3, since there will be a master variant as well
94
- expect { duplicator.duplicate }.to change { Spree::Variant.count }.by(3)
95
- end
96
-
97
- it "will not duplicate the option values" do
98
- expect { duplicator.duplicate }.to change { Spree::OptionValue.count }.by(0)
99
- end
100
- end
101
- end
102
- end