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,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,183 +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
-
31
- context 'when multiple prices present' do
32
- let!(:price_1) { create(:price, currency: 'EUR', variant: product.master) }
33
- let!(:price_2) { create(:price, currency: 'EUR', variant: product.master) }
34
-
35
- it 'should not duplicate product' do
36
- expect(Spree::Product.available).to eq([product])
37
- end
38
- end
39
- end
40
-
41
- context "A product assigned to parent and child taxons" do
42
- before do
43
- @taxonomy = create(:taxonomy)
44
- @root_taxon = @taxonomy.root
45
-
46
- @parent_taxon = create(:taxon, name: 'Parent', taxonomy_id: @taxonomy.id, parent: @root_taxon)
47
- @child_taxon = create(:taxon, name:'Child 1', taxonomy_id: @taxonomy.id, parent: @parent_taxon)
48
- @parent_taxon.reload # Need to reload for descendents to show up
49
-
50
- product.taxons << @parent_taxon
51
- product.taxons << @child_taxon
52
- end
53
-
54
- it "calling Product.in_taxon returns products in child taxons" do
55
- product.taxons -= [@child_taxon]
56
- expect(product.taxons.count).to eq(1)
57
-
58
- expect(Spree::Product.in_taxon(@parent_taxon)).to include(product)
59
- end
60
-
61
- it "calling Product.in_taxon should not return duplicate records" do
62
- expect(Spree::Product.in_taxon(@parent_taxon).to_a.count).to eq(1)
63
- end
64
-
65
- context 'orders products based on their ordering within the classifications' do
66
- let(:other_taxon) { create(:taxon, products: [product]) }
67
- let!(:product_2) { create(:product, taxons: [@child_taxon, other_taxon]) }
68
-
69
- it 'by initial ordering' do
70
- expect(Spree::Product.in_taxon(@child_taxon)).to eq([product, product_2])
71
- expect(Spree::Product.in_taxon(other_taxon)).to eq([product, product_2])
72
- end
73
-
74
- it 'after ordering changed' do
75
- [@child_taxon, other_taxon].each do |taxon|
76
- Spree::Classification.find_by(taxon: taxon, product: product).insert_at(2)
77
- expect(Spree::Product.in_taxon(taxon)).to eq([product_2, product])
78
- end
79
- end
80
- end
81
- end
82
-
83
- context "property scopes" do
84
- let(:name) { "A proper tee" }
85
- let(:value) { "A proper value"}
86
- let!(:property) { create(:property, name: name)}
87
-
88
- before do
89
- product.properties << property
90
- product.product_properties.find_by(property: property).update_column(:value, value)
91
- end
92
-
93
- context "with_property" do
94
- let(:with_property) { Spree::Product.method(:with_property) }
95
- it "finds by a property's name" do
96
- expect(with_property.(name).count).to eq(1)
97
- end
98
-
99
- it "doesn't find any properties with an unknown name" do
100
- expect(with_property.("fake").count).to eq(0)
101
- end
102
-
103
- it "finds by a property" do
104
- expect(with_property.(property).count).to eq(1)
105
- end
106
-
107
- it "finds by an id" do
108
- expect(with_property.(property.id).count).to eq(1)
109
- end
110
-
111
- it "cannot find a property with an unknown id" do
112
- expect(with_property.(0).count).to eq(0)
113
- end
114
- end
115
-
116
- context "with_property_value" do
117
- let(:with_property_value) { Spree::Product.method(:with_property_value) }
118
- it "finds by a property's name" do
119
- expect(with_property_value.(name, value).count).to eq(1)
120
- end
121
-
122
- it "cannot find by an unknown property's name" do
123
- expect(with_property_value.("fake", value).count).to eq(0)
124
- end
125
-
126
- it "cannot find with a name by an incorrect value" do
127
- expect(with_property_value.(name, "fake").count).to eq(0)
128
- end
129
-
130
- it "finds by a property" do
131
- expect(with_property_value.(property, value).count).to eq(1)
132
- end
133
-
134
- it "cannot find with a property by an incorrect value" do
135
- expect(with_property_value.(property, "fake").count).to eq(0)
136
- end
137
-
138
- it "finds by an id with a value" do
139
- expect(with_property_value.(property.id, value).count).to eq(1)
140
- end
141
-
142
- it "cannot find with an invalid id" do
143
- expect(with_property_value.(0, value).count).to eq(0)
144
- end
145
-
146
- it "cannot find with an invalid value" do
147
- expect(with_property_value.(property.id, "fake").count).to eq(0)
148
- end
149
- end
150
- end
151
-
152
- context '#add_simple_scopes' do
153
- let(:simple_scopes) { [:ascend_by_updated_at, :descend_by_name] }
154
-
155
- before do
156
- Spree::Product.add_simple_scopes(simple_scopes)
157
- end
158
-
159
- context 'define scope' do
160
- context 'ascend_by_updated_at' do
161
- context 'on class' do
162
- 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 }
163
- end
164
-
165
- context 'on ActiveRecord::Relation' do
166
- 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 }
167
- it { expect(Spree::Product.limit(2).ascend_by_updated_at.to_sql).to eq Spree::Product.ascend_by_updated_at.limit(2).to_sql }
168
- end
169
- end
170
-
171
- context 'descend_by_name' do
172
- context 'on class' do
173
- it { expect(Spree::Product.descend_by_name.to_sql).to eq Spree::Product.order("#{Spree::Product.quoted_table_name}.name DESC").to_sql }
174
- end
175
-
176
- context 'on ActiveRecord::Relation' do
177
- 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 }
178
- it { expect(Spree::Product.limit(2).descend_by_name.to_sql).to eq Spree::Product.descend_by_name.limit(2).to_sql }
179
- end
180
- end
181
- end
182
- end
183
- end
@@ -1,103 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
-
5
- describe Spree::ProductDuplicator, type: :model do
6
-
7
- let(:product) { create(:product, properties: [create(:property, name: "MyProperty")])}
8
- let!(:duplicator) { Spree::ProductDuplicator.new(product)}
9
-
10
- let(:image) { File.open(File.expand_path('../../../fixtures/thinking-cat.jpg', __FILE__)) }
11
- let(:params) { {viewable_id: product.master.id, viewable_type: 'Spree::Variant', attachment: image, alt: "position 1", position: 1} }
12
-
13
- before do
14
- Spree::Image.create(params)
15
- end
16
-
17
- it "will duplicate the product" do
18
- expect{duplicator.duplicate}.to change{Spree::Product.count}.by(1)
19
- end
20
-
21
- context 'when image duplication enabled' do
22
-
23
- it "will duplicate the product images" do
24
- expect{duplicator.duplicate}.to change{Spree::Image.count}.by(1)
25
- end
26
-
27
- end
28
-
29
- context 'when image duplication disabled' do
30
-
31
- let!(:duplicator) { Spree::ProductDuplicator.new(product, false) }
32
-
33
- it "will not duplicate the product images" do
34
- expect{duplicator.duplicate}.to change{Spree::Image.count}.by(0)
35
- end
36
-
37
- end
38
-
39
- context 'image duplication default' do
40
-
41
- context 'when default is set to true' do
42
-
43
- it 'clones images if no flag passed to initializer' do
44
- expect{duplicator.duplicate}.to change{Spree::Image.count}.by(1)
45
- end
46
-
47
- end
48
-
49
- context 'when default is set to false' do
50
-
51
- before do
52
- ProductDuplicator.clone_images_default = false
53
- end
54
-
55
- after do
56
- ProductDuplicator.clone_images_default = true
57
- end
58
-
59
- it 'does not clone images if no flag passed to initializer' do
60
- expect{ProductDuplicator.new(product).duplicate}.to change{Spree::Image.count}.by(0)
61
- end
62
-
63
- end
64
-
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
-
101
- end
102
- end
103
- end