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,69 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Calculator, type: :model do
4
-
5
- let(:order) { create(:order) }
6
- let!(:line_item) { create(:line_item, order: order) }
7
- let(:shipment) { create(:shipment, order: order, stock_location: create(:stock_location_with_items)) }
8
-
9
- context "with computable" do
10
- context "and compute methods stubbed out" do
11
- context "with a Spree::LineItem" do
12
- it "calls compute_line_item" do
13
- expect(subject).to receive(:compute_line_item).with(line_item)
14
- subject.compute(line_item)
15
- end
16
- end
17
-
18
- context "with a Spree::Order" do
19
- it "calls compute_order" do
20
- expect(subject).to receive(:compute_order).with(order)
21
- subject.compute(order)
22
- end
23
- end
24
-
25
- context "with a Spree::Shipment" do
26
- it "calls compute_shipment" do
27
- expect(subject).to receive(:compute_shipment).with(shipment)
28
- subject.compute(shipment)
29
- end
30
- end
31
-
32
- context "with a arbitray object" do
33
- it "calls the correct compute" do
34
- s = "Calculator can all"
35
- expect(subject).to receive(:compute_string).with(s)
36
- subject.compute(s)
37
- end
38
- end
39
- end
40
-
41
- context "with no stubbing" do
42
- context "with a Spree::LineItem" do
43
- it "raises NotImplementedError" do
44
- expect{subject.compute(line_item)}.to raise_error NotImplementedError, /Please implement \'compute_line_item\(line_item\)\' in your calculator/
45
- end
46
- end
47
-
48
- context "with a Spree::Order" do
49
- it "raises NotImplementedError" do
50
- expect{subject.compute(order)}.to raise_error NotImplementedError, /Please implement \'compute_order\(order\)\' in your calculator/
51
- end
52
- end
53
-
54
- context "with a Spree::Shipment" do
55
- it "raises NotImplementedError" do
56
- expect{subject.compute(shipment)}.to raise_error NotImplementedError, /Please implement \'compute_shipment\(shipment\)\' in your calculator/
57
- end
58
- end
59
-
60
- context "with a arbitray object" do
61
- it "raises NotImplementedError" do
62
- s = "Calculator can all"
63
- expect{subject.compute(s)}.to raise_error NotImplementedError, /Please implement \'compute_string\(string\)\' in your calculator/
64
- end
65
- end
66
- end
67
- end
68
-
69
- end
@@ -1,93 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- describe Classification, type: :model do
5
- # Regression test for #3494
6
- it "cannot link the same taxon to the same product more than once" do
7
- product = create(:product)
8
- taxon = create(:taxon)
9
- add_taxon = lambda { product.taxons << taxon }
10
- expect(add_taxon).not_to raise_error
11
- expect(add_taxon).to raise_error(ActiveRecord::RecordInvalid)
12
- end
13
-
14
- let(:taxon_with_5_products) do
15
- products = []
16
- 5.times do
17
- products << create(:base_product)
18
- end
19
-
20
- create(:taxon, products: products)
21
- end
22
-
23
- def positions_to_be_valid(taxon)
24
- positions = taxon.reload.classifications.map(&:position)
25
- expect(positions).to eq((1..taxon.classifications.count).to_a)
26
- end
27
-
28
- it "has a valid fixtures" do
29
- expect positions_to_be_valid(taxon_with_5_products)
30
- expect(Spree::Classification.count).to eq 5
31
- end
32
-
33
- context "removing product from taxon" do
34
- before :each do
35
- p = taxon_with_5_products.products[1]
36
- expect(p.classifications.first.position).to eq(2)
37
- taxon_with_5_products.products.destroy(p)
38
- end
39
-
40
- it "resets positions" do
41
- expect positions_to_be_valid(taxon_with_5_products)
42
- end
43
- end
44
-
45
- context "replacing taxon's products" do
46
- before :each do
47
- products = taxon_with_5_products.products.to_a
48
- products.pop(1)
49
- taxon_with_5_products.products = products
50
- taxon_with_5_products.save!
51
- end
52
-
53
- it "resets positions" do
54
- expect positions_to_be_valid(taxon_with_5_products)
55
- end
56
- end
57
-
58
- context "removing taxon from product" do
59
- before :each do
60
- p = taxon_with_5_products.products[1]
61
- p.taxons.destroy(taxon_with_5_products)
62
- p.save!
63
- end
64
-
65
- it "resets positions" do
66
- expect positions_to_be_valid(taxon_with_5_products)
67
- end
68
- end
69
-
70
- context "replacing product's taxons" do
71
- before :each do
72
- p = taxon_with_5_products.products[1]
73
- p.taxons = []
74
- p.save!
75
- end
76
-
77
- it "resets positions" do
78
- expect positions_to_be_valid(taxon_with_5_products)
79
- end
80
- end
81
-
82
- context "destroying classification" do
83
- before :each do
84
- classification = taxon_with_5_products.classifications[1]
85
- classification.destroy
86
- end
87
-
88
- it "resets positions" do
89
- expect positions_to_be_valid(taxon_with_5_products)
90
- end
91
- end
92
- end
93
- end
@@ -1,43 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
-
5
- describe DisplayMoney do
6
- let(:test_class) do
7
- Class.new do
8
- extend DisplayMoney
9
- def total; 10.0; end
10
- end
11
- end
12
-
13
- describe ".money_methods" do
14
- before { test_class.money_methods :total }
15
-
16
- context "currency is not defined" do
17
- it "generates a display_method that builds a Spree::Money without options" do
18
- expect(test_class.new.display_total).to eq Spree::Money.new(10.0)
19
- end
20
- end
21
-
22
- context "currency is defined" do
23
- before { test_class.class_eval { def currency; "USD"; end } }
24
-
25
- it "generates a display_* method that builds a Spree::Money with currency" do
26
- expect(test_class.new.display_total).to eq Spree::Money.new(10.0, currency: "USD")
27
- end
28
- end
29
-
30
- context "with multiple + options" do
31
- before do
32
- test_class.class_eval { def amount; 20.0; end }
33
- test_class.money_methods :total, amount: { no_cents: true }
34
- end
35
-
36
- it "generates a display_* method that builds a Spree::Money with the specified options" do
37
- expect(test_class.new.display_total).to eq Spree::Money.new(10.0)
38
- expect(test_class.new.display_amount).to eq Spree::Money.new(20.0, no_cents: true)
39
- end
40
- end
41
- end
42
- end
43
- end
@@ -1,82 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::UserMethods do
4
- let(:test_user) { create :user }
5
-
6
- describe 'Associations' do
7
- subject { test_user }
8
-
9
- it 'should have many promotion_rule_users' do
10
- is_expected.to have_many(:promotion_rule_users).with_foreign_key(:user_id).
11
- class_name('Spree::PromotionRuleUser').dependent(:destroy)
12
- end
13
-
14
- it 'should have many role_users' do
15
- is_expected.to have_many(:role_users).class_name('Spree::RoleUser').
16
- with_foreign_key(:user_id).dependent(:destroy)
17
- end
18
- end
19
-
20
- describe '#has_spree_role?' do
21
- subject { test_user.has_spree_role? name }
22
-
23
- let(:role) { Spree::Role.create(name: name) }
24
- let(:name) { 'test' }
25
-
26
- context 'with a role' do
27
- before { test_user.spree_roles << role }
28
- it { is_expected.to be_truthy }
29
- end
30
-
31
- context 'without a role' do
32
- it { is_expected.to be_falsy }
33
- end
34
- end
35
-
36
- describe '#last_incomplete_spree_order' do
37
- subject { test_user.last_incomplete_spree_order }
38
-
39
- context 'with an incomplete order' do
40
- let(:last_incomplete_order) { create :order, user: test_user }
41
-
42
- before do
43
- create(:order, user: test_user, created_at: 1.day.ago)
44
- create(:order, user: create(:user))
45
- last_incomplete_order
46
- end
47
-
48
- it { is_expected.to eq last_incomplete_order }
49
- end
50
-
51
- context 'without an incomplete order' do
52
- it { is_expected.to be_nil }
53
- end
54
- end
55
-
56
- context '#check_completed_orders' do
57
- let(:possible_promotion) { create(:promotion, advertise: true, starts_at: 1.day.ago) }
58
- context 'rstrict t delete dependent destroyed' do
59
- before do
60
- test_user.promotion_rules.create!(promotion: possible_promotion)
61
- create(:order, user: test_user, completed_at: Time.current)
62
- end
63
-
64
- it 'should not destroy dependent destroy items' do
65
- expect { test_user.destroy }.to raise_error(Spree::Core::DestroyWithOrdersError)
66
- expect(test_user.promotion_rule_users.any?).to be(true)
67
- end
68
- end
69
-
70
- context 'allow to destroy dependent destroy' do
71
- before do
72
- test_user.promotion_rules.create!(promotion: possible_promotion)
73
- create(:order, user: test_user, created_at: 1.day.ago)
74
- test_user.destroy
75
- end
76
-
77
- it 'should not destroy dependent destroy items' do
78
- expect(test_user.promotion_rule_users.any?).to be(false)
79
- end
80
- end
81
- end
82
- end
@@ -1,66 +0,0 @@
1
- require "spec_helper"
2
-
3
- module Spree
4
- describe VatPriceCalculation do
5
- let(:test_class) do
6
- Class.new do
7
- include VatPriceCalculation
8
- def total; 10.0; end
9
- end
10
- end
11
-
12
- describe "#gross_amount" do
13
- let(:zone) { Zone.new }
14
- let(:tax_category) { TaxCategory.new }
15
- let(:price_options) do
16
- {
17
- tax_zone: zone,
18
- tax_category: tax_category
19
- }
20
- end
21
- let(:amount) { 100 }
22
-
23
- subject(:gross_amount) { test_class.new.gross_amount(amount, price_options) }
24
-
25
- context "with no default zone set" do
26
- it "does not call TaxRate.included_tax_amount_for" do
27
- expect(TaxRate).not_to receive(:included_tax_amount_for)
28
- gross_amount
29
- end
30
- end
31
-
32
- context "with no zone given" do
33
- let(:zone) { nil }
34
- it "does not call TaxRate.included_tax_amount_for" do
35
- expect(TaxRate).not_to receive(:included_tax_amount_for)
36
- gross_amount
37
- end
38
- end
39
-
40
- context "with a default zone set" do
41
- let(:default_zone) { Spree::Zone.new }
42
- before do
43
- allow(Spree::Zone).to receive(:default_tax).and_return(default_zone)
44
- end
45
-
46
- context "and zone equal to the default zone" do
47
- let(:zone) { default_zone }
48
-
49
- it "does not call 'TaxRate.included_tax_amount_for'" do
50
- expect(TaxRate).not_to receive(:included_tax_amount_for)
51
- gross_amount
52
- end
53
- end
54
-
55
- context "and zone not equal to default zone" do
56
- let(:zone) { Spree::Zone.new }
57
-
58
- it "calls TaxRate.included_tax_amount_for two times" do
59
- expect(TaxRate).to receive(:included_tax_amount_for).twice
60
- gross_amount
61
- end
62
- end
63
- end
64
- end
65
- end
66
- end
@@ -1,55 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Country, type: :model do
4
- let(:america) { create :country }
5
- let(:canada) { create :country, name: 'Canada', iso_name: 'CANADA', numcode: '124' }
6
-
7
- describe 'Callbacks' do
8
- it { is_expected.to callback(:ensure_not_default).before(:destroy) }
9
- end
10
-
11
- describe 'Associations' do
12
- it { is_expected.to have_many(:addresses).dependent(:restrict_with_error) }
13
- end
14
-
15
- describe 'Validations' do
16
- it { is_expected.to validate_presence_of(:name) }
17
- it { is_expected.to validate_presence_of(:iso_name) }
18
- it { is_expected.to validate_uniqueness_of(:iso_name).case_insensitive }
19
- it { is_expected.to validate_uniqueness_of(:name).case_insensitive }
20
- end
21
-
22
- describe '.default' do
23
- context 'when default_country_id config is set' do
24
- before { Spree::Config[:default_country_id] = canada.id }
25
- it 'will return the country from the config' do
26
- expect(described_class.default.id).to eql canada.id
27
- end
28
- end
29
-
30
- context 'config is not set though record for america exists' do
31
- before { america.touch }
32
- it 'will return the US' do
33
- expect(described_class.default.id).to eql america.id
34
- end
35
- end
36
- end
37
-
38
- describe 'ensure default country in not deleted' do
39
- before { Spree::Config[:default_country_id] = america.id }
40
-
41
- context 'will not destroy country if it is default' do
42
- subject { america.destroy }
43
- it { is_expected.to be_falsy }
44
-
45
- context 'error should be default country cannot be deleted' do
46
- before { subject }
47
- it { expect(america.errors[:base]).to include(Spree.t(:default_country_cannot_be_deleted)) }
48
- end
49
- end
50
-
51
- context 'will destroy if it is not a default' do
52
- it { expect(canada.destroy).to be_truthy }
53
- end
54
- end
55
- end
@@ -1,328 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::CreditCard, type: :model do
4
- let(:valid_credit_card_attributes) do
5
- {
6
- number: '4111111111111111',
7
- verification_value: '123',
8
- expiry: "12 / #{(Time.current.year + 1).to_s.last(2)}",
9
- name: 'Spree Commerce'
10
- }
11
- end
12
-
13
- def self.payment_states
14
- Spree::Payment.state_machine.states.keys
15
- end
16
-
17
- let(:credit_card) { Spree::CreditCard.new }
18
-
19
- before(:each) do
20
-
21
- @order = create(:order)
22
- @payment = Spree::Payment.create(amount: 100, order: @order)
23
-
24
- @success_response = double('gateway_response', success?: true, authorization: '123', avs_result: { 'code' => 'avs-code' })
25
- @fail_response = double('gateway_response', success?: false)
26
-
27
- @payment_gateway = mock_model(Spree::PaymentMethod,
28
- payment_profiles_supported?: true,
29
- authorize: @success_response,
30
- purchase: @success_response,
31
- capture: @success_response,
32
- void: @success_response,
33
- credit: @success_response,
34
- )
35
-
36
- allow(@payment).to receive_messages payment_method: @payment_gateway
37
- end
38
-
39
- it 'should respond to track_data' do
40
- expect(credit_card.respond_to?(:track_data)).to be true
41
- end
42
-
43
- context "#can_capture?" do
44
- it "should be true if payment is pending" do
45
- payment = mock_model(Spree::Payment, pending?: true, created_at: Time.current)
46
- expect(credit_card.can_capture?(payment)).to be true
47
- end
48
-
49
- it "should be true if payment is checkout" do
50
- payment = mock_model(Spree::Payment, pending?: false, checkout?: true, created_at: Time.current)
51
- expect(credit_card.can_capture?(payment)).to be true
52
- end
53
- end
54
-
55
- context "#can_void?" do
56
- it "should be true if payment is not void" do
57
- payment = mock_model(Spree::Payment, failed?: false, void?: false)
58
- expect(credit_card.can_void?(payment)).to be true
59
- end
60
- end
61
-
62
- context "#can_credit?" do
63
- it "should be false if payment is not completed" do
64
- payment = mock_model(Spree::Payment, completed?: false)
65
- expect(credit_card.can_credit?(payment)).to be false
66
- end
67
-
68
- it "should be false when credit_allowed is zero" do
69
- payment = mock_model(Spree::Payment, completed?: true, credit_allowed: 0, order: mock_model(Spree::Order, payment_state: 'credit_owed'))
70
- expect(credit_card.can_credit?(payment)).to be false
71
- end
72
- end
73
-
74
- context "#valid?" do
75
- it "should validate presence of number" do
76
- credit_card.attributes = valid_credit_card_attributes.except(:number)
77
- expect(credit_card).not_to be_valid
78
- expect(credit_card.errors[:number]).to eq(["can't be blank"])
79
- end
80
-
81
- it "should validate presence of security code" do
82
- credit_card.attributes = valid_credit_card_attributes.except(:verification_value)
83
- expect(credit_card).not_to be_valid
84
- expect(credit_card.errors[:verification_value]).to eq(["can't be blank"])
85
- end
86
-
87
- it "validates name presence" do
88
- credit_card.valid?
89
- expect(credit_card.error_on(:name).size).to eq(1)
90
- end
91
-
92
- it "should only validate on create" do
93
- credit_card.attributes = valid_credit_card_attributes
94
- credit_card.save
95
- expect(credit_card).to be_valid
96
- end
97
-
98
- context "encrypted data is present" do
99
- it "does not validate presence of number or cvv" do
100
- credit_card.encrypted_data = "$fdgsfgdgfgfdg&gfdgfdgsf-"
101
- credit_card.valid?
102
- expect(credit_card.errors[:number]).to be_empty
103
- expect(credit_card.errors[:verification_value]).to be_empty
104
- end
105
- end
106
-
107
- context "imported is true" do
108
- it "does not validate presence of number or cvv" do
109
- credit_card.imported = true
110
- credit_card.valid?
111
- expect(credit_card.errors[:number]).to be_empty
112
- expect(credit_card.errors[:verification_value]).to be_empty
113
- end
114
- end
115
- end
116
-
117
- context "#save" do
118
- before do
119
- credit_card.attributes = valid_credit_card_attributes
120
- credit_card.save!
121
- end
122
-
123
- let!(:persisted_card) { Spree::CreditCard.find(credit_card.id) }
124
-
125
- it "should not actually store the number" do
126
- expect(persisted_card.number).to be_blank
127
- end
128
-
129
- it "should not actually store the security code" do
130
- expect(persisted_card.verification_value).to be_blank
131
- end
132
- end
133
-
134
- context "#number=" do
135
- it "should strip non-numeric characters from card input" do
136
- credit_card.number = "6011000990139424"
137
- expect(credit_card.number).to eq("6011000990139424")
138
-
139
- credit_card.number = " 6011-0009-9013-9424 "
140
- expect(credit_card.number).to eq("6011000990139424")
141
- end
142
-
143
- it "should not raise an exception on non-string input" do
144
- credit_card.number = Hash.new
145
- expect(credit_card.number).to be_nil
146
- end
147
- end
148
-
149
- # Regression test for #3847 & #3896
150
- context "#expiry=" do
151
- it "can set with a 2-digit month and year" do
152
- credit_card.expiry = '04 / 14'
153
- expect(credit_card.month).to eq(4)
154
- expect(credit_card.year).to eq(2014)
155
- end
156
-
157
- it "can set with a 2-digit month and 4-digit year" do
158
- credit_card.expiry = '04 / 2014'
159
- expect(credit_card.month).to eq(4)
160
- expect(credit_card.year).to eq(2014)
161
- end
162
-
163
- it "can set with a 2-digit month and 4-digit year without whitespace" do
164
- credit_card.expiry = '04/14'
165
- expect(credit_card.month).to eq(4)
166
- expect(credit_card.year).to eq(2014)
167
- end
168
-
169
- it "can set with a 2-digit month and 4-digit year without whitespace" do
170
- credit_card.expiry = '04/2014'
171
- expect(credit_card.month).to eq(4)
172
- expect(credit_card.year).to eq(2014)
173
- end
174
-
175
- it "can set with a 2-digit month and 4-digit year without whitespace and slash" do
176
- credit_card.expiry = '042014'
177
- expect(credit_card.month).to eq(4)
178
- expect(credit_card.year).to eq(2014)
179
- end
180
-
181
- it "can set with a 2-digit month and 2-digit year without whitespace and slash" do
182
- credit_card.expiry = '0414'
183
- expect(credit_card.month).to eq(4)
184
- expect(credit_card.year).to eq(2014)
185
- end
186
-
187
- it "does not blow up when passed an empty string" do
188
- expect { credit_card.expiry = '' }.not_to raise_error
189
- end
190
-
191
- # Regression test for #4725
192
- it "does not blow up when passed one number" do
193
- expect { credit_card.expiry = '12' }.not_to raise_error
194
- end
195
-
196
- end
197
-
198
- context "#cc_type=" do
199
- it "converts between the different types" do
200
- credit_card.cc_type = 'mastercard'
201
- expect(credit_card.cc_type).to eq('master')
202
-
203
- credit_card.cc_type = 'maestro'
204
- expect(credit_card.cc_type).to eq('master')
205
-
206
- credit_card.cc_type = 'amex'
207
- expect(credit_card.cc_type).to eq('american_express')
208
-
209
- credit_card.cc_type = 'dinersclub'
210
- expect(credit_card.cc_type).to eq('diners_club')
211
-
212
- credit_card.cc_type = 'some_outlandish_cc_type'
213
- expect(credit_card.cc_type).to eq('some_outlandish_cc_type')
214
- end
215
-
216
- it "assigns the type based on card number in the event of js failure" do
217
- credit_card.number = '4242424242424242'
218
- credit_card.cc_type = ''
219
- expect(credit_card.cc_type).to eq('visa')
220
-
221
- credit_card.number = '5555555555554444'
222
- credit_card.cc_type = ''
223
- expect(credit_card.cc_type).to eq('master')
224
-
225
- credit_card.number = '2223000010309703'
226
- credit_card.cc_type = ''
227
- expect(credit_card.cc_type).to eq('master')
228
-
229
- credit_card.number = '378282246310005'
230
- credit_card.cc_type = ''
231
- expect(credit_card.cc_type).to eq('american_express')
232
-
233
- credit_card.number = '30569309025904'
234
- credit_card.cc_type = ''
235
- expect(credit_card.cc_type).to eq('diners_club')
236
-
237
- credit_card.number = '3530111333300000'
238
- credit_card.cc_type = ''
239
- expect(credit_card.cc_type).to eq('jcb')
240
-
241
- credit_card.number = ''
242
- credit_card.cc_type = ''
243
- expect(credit_card.cc_type).to eq('')
244
-
245
- credit_card.number = nil
246
- credit_card.cc_type = ''
247
- expect(credit_card.cc_type).to eq('')
248
- end
249
- end
250
-
251
- context "#associations" do
252
- it "should be able to access its payments" do
253
- expect { credit_card.payments.to_a }.not_to raise_error
254
- end
255
- end
256
-
257
- context "#first_name" do
258
- before do
259
- credit_card.name = "Ludwig van Beethoven"
260
- end
261
-
262
- it "extracts the first name" do
263
- expect(credit_card.first_name).to eq "Ludwig"
264
- end
265
- end
266
-
267
- context "#last_name" do
268
- before do
269
- credit_card.name = "Ludwig van Beethoven"
270
- end
271
-
272
- it "extracts the last name" do
273
- expect(credit_card.last_name).to eq "van Beethoven"
274
- end
275
- end
276
-
277
- context "#to_active_merchant" do
278
- before do
279
- credit_card.number = "4111111111111111"
280
- credit_card.year = Time.current.year
281
- credit_card.month = Time.current.month
282
- credit_card.name = "Ludwig van Beethoven"
283
- credit_card.verification_value = 123
284
- end
285
-
286
- it "converts to an ActiveMerchant::Billing::CreditCard object" do
287
- am_card = credit_card.to_active_merchant
288
- expect(am_card.number).to eq("4111111111111111")
289
- expect(am_card.year).to eq(Time.current.year)
290
- expect(am_card.month).to eq(Time.current.month)
291
- expect(am_card.first_name).to eq("Ludwig")
292
- expect(am_card.last_name).to eq("van Beethoven")
293
- expect(am_card.verification_value).to eq(123)
294
- end
295
- end
296
-
297
- it 'ensures only one credit card per user is default at a time' do
298
- user = FactoryGirl.create(:user)
299
- first = FactoryGirl.create(:credit_card, user: user, default: true)
300
- second = FactoryGirl.create(:credit_card, user: user, default: true)
301
-
302
- expect(first.reload.default).to eq false
303
- expect(second.reload.default).to eq true
304
-
305
- first.default = true
306
- first.save!
307
-
308
- expect(first.reload.default).to eq true
309
- expect(second.reload.default).to eq false
310
- end
311
-
312
- it 'allows default credit cards for different users' do
313
- first = FactoryGirl.create(:credit_card, user: FactoryGirl.create(:user), default: true)
314
- second = FactoryGirl.create(:credit_card, user: FactoryGirl.create(:user), default: true)
315
-
316
- expect(first.reload.default).to eq true
317
- expect(second.reload.default).to eq true
318
- end
319
-
320
- it 'allows this card to save even if the previously default card has expired' do
321
- user = FactoryGirl.create(:user)
322
- first = FactoryGirl.create(:credit_card, user: user, default: true)
323
- second = FactoryGirl.create(:credit_card, user: user, default: false)
324
- first.update_columns(year: DateTime.current.year, month: 1.month.ago.month)
325
-
326
- expect { second.update_attributes!(default: true) }.not_to raise_error
327
- end
328
- end