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,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Promotion::Rules::Taxon, type: :model do
4
- let(:rule){ subject }
5
-
6
- context '#elegible?(order)' do
7
- let(:taxon){ create :taxon, name: 'first' }
8
- let(:taxon2){ create :taxon, name: 'second'}
9
- let(:order){ create :order_with_line_items }
10
-
11
- before do
12
- rule.save
13
- end
14
-
15
- context 'with any match policy' do
16
- before do
17
- rule.preferred_match_policy = 'any'
18
- end
19
-
20
- it 'is eligible if order does has any prefered taxon' do
21
- order.products.first.taxons << taxon
22
- rule.taxons << taxon
23
- expect(rule).to be_eligible(order)
24
- end
25
-
26
- context 'when order contains items from different taxons' do
27
- before do
28
- order.products.first.taxons << taxon
29
- rule.taxons << taxon
30
- end
31
-
32
- it 'should act on a product within the eligible taxon' do
33
- expect(rule).to be_actionable(order.line_items.last)
34
- end
35
-
36
- it 'should not act on a product in another taxon' do
37
- order.line_items << create(:line_item, product: create(:product, taxons: [taxon2]))
38
- expect(rule).not_to be_actionable(order.line_items.last)
39
- end
40
- end
41
-
42
- context "when order does not have any prefered taxon" do
43
- before { rule.taxons << taxon2 }
44
- it { expect(rule).not_to be_eligible(order) }
45
- it "sets an error message" do
46
- rule.eligible?(order)
47
- expect(rule.eligibility_errors.full_messages.first).
48
- to eq "You need to add a product from an applicable category before applying this coupon code."
49
- end
50
- end
51
-
52
- context 'when a product has a taxon child of a taxon rule' do
53
- before do
54
- taxon.children << taxon2
55
- order.products.first.taxons << taxon2
56
- rule.taxons << taxon2
57
- end
58
-
59
- it{ expect(rule).to be_eligible(order) }
60
- end
61
- end
62
-
63
- context 'with all match policy' do
64
- before do
65
- rule.preferred_match_policy = 'all'
66
- end
67
-
68
- it 'is eligible order has all prefered taxons' do
69
- order.products.first.taxons << taxon2
70
- order.products.last.taxons << taxon
71
-
72
- rule.taxons = [taxon, taxon2]
73
-
74
- expect(rule).to be_eligible(order)
75
- end
76
-
77
- context "when order does not have all prefered taxons" do
78
- before { rule.taxons << taxon }
79
- it { expect(rule).not_to be_eligible(order) }
80
- it "sets an error message" do
81
- rule.eligible?(order)
82
- expect(rule.eligibility_errors.full_messages.first).
83
- to eq "You need to add a product from all applicable categories before applying this coupon code."
84
- end
85
- end
86
-
87
- context 'when a product has a taxon child of a taxon rule' do
88
- let(:taxon3){ create :taxon }
89
-
90
- before do
91
- taxon.children << taxon2
92
- order.products.first.taxons << taxon2
93
- order.products.last.taxons << taxon3
94
- rule.taxons << taxon2
95
- rule.taxons << taxon3
96
- end
97
-
98
- it{ expect(rule).to be_eligible(order) }
99
- end
100
- end
101
- end
102
- end
@@ -1,27 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Promotion::Rules::UserLoggedIn, type: :model do
4
- let(:rule) { Spree::Promotion::Rules::UserLoggedIn.new }
5
-
6
- context "#eligible?(order)" do
7
- let(:order) { Spree::Order.new }
8
-
9
- it "should be eligible if order has an associated user" do
10
- user = double('User')
11
- allow(order).to receive_messages(user: user)
12
-
13
- expect(rule).to be_eligible(order)
14
- end
15
-
16
- context "when user is not logged in" do
17
- before { allow(order).to receive_messages(user: nil) } # better to be explicit here
18
- it { expect(rule).not_to be_eligible(order) }
19
- it "sets an error message" do
20
- rule.eligible?(order)
21
- expect(rule.eligibility_errors.full_messages.first).
22
- to eq "You need to login before applying this coupon code."
23
- end
24
- end
25
- end
26
- end
27
-
@@ -1,45 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Promotion::Rules::User, type: :model do
4
- let(:rule) { Spree::Promotion::Rules::User.new }
5
- let(:test_user) { create :user }
6
-
7
- describe 'Associations' do
8
- it 'should have many promotion_rule_users' do
9
- is_expected.to have_many(:promotion_rule_users).with_foreign_key(:promotion_rule_id).
10
- class_name('Spree::PromotionRuleUser').dependent(:destroy)
11
- end
12
- end
13
-
14
- context "#eligible?(order)" do
15
- let(:order) { Spree::Order.new }
16
-
17
- it "should not be eligible if users are not provided" do
18
- expect(rule).not_to be_eligible(order)
19
- end
20
-
21
- it "should be eligible if users include user placing the order" do
22
- user = mock_model(Spree::LegacyUser)
23
- users = [user, mock_model(Spree::LegacyUser)]
24
- allow(rule).to receive_messages(users: users)
25
- allow(order).to receive_messages(user: user)
26
-
27
- expect(rule).to be_eligible(order)
28
- end
29
-
30
- it "should not be eligible if user placing the order is not listed" do
31
- allow(order).to receive_messages(user: mock_model(Spree::LegacyUser))
32
- users = [mock_model(Spree::LegacyUser), mock_model(Spree::LegacyUser)]
33
- allow(rule).to receive_messages(users: users)
34
-
35
- expect(rule).not_to be_eligible(order)
36
- end
37
-
38
- # Regression test for #3885
39
- it "can assign to user_ids" do
40
- user1 = Spree::LegacyUser.create!(email: "test1@example.com")
41
- user2 = Spree::LegacyUser.create!(email: "test2@example.com")
42
- expect { rule.user_ids = "#{user1.id}, #{user2.id}" }.not_to raise_error
43
- end
44
- end
45
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::PromotionAction, type: :model do
4
-
5
- it "should force developer to implement 'perform' method" do
6
- expect { MyAction.new.perform }.to raise_error(NameError)
7
- end
8
-
9
- end
10
-
@@ -1,17 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::PromotionCategory, type: :model do
4
- describe 'validation' do
5
- let(:name) { 'Nom' }
6
- subject { Spree::PromotionCategory.new name: name }
7
-
8
- context 'when all required attributes are specified' do
9
- it { is_expected.to be_valid }
10
- end
11
-
12
- context 'when name is missing' do
13
- let(:name) { nil }
14
- it { is_expected.not_to be_valid }
15
- end
16
- end
17
- end
@@ -1,102 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module PromotionHandler
5
- describe Cart, type: :model do
6
- let(:line_item) { create(:line_item) }
7
- let(:order) { line_item.order }
8
-
9
- let(:promotion) { Promotion.create(name: "At line items") }
10
- let(:calculator) { Calculator::FlatPercentItemTotal.new(preferred_flat_percent: 10) }
11
-
12
- subject { Cart.new(order, line_item) }
13
-
14
- context "activates in LineItem level" do
15
- let!(:action) { Promotion::Actions::CreateItemAdjustments.create(promotion: promotion, calculator: calculator) }
16
- let(:adjustable) { line_item }
17
-
18
- shared_context "creates the adjustment" do
19
- it "creates the adjustment" do
20
- expect {
21
- subject.activate
22
- }.to change { adjustable.adjustments.count }.by(1)
23
- end
24
- end
25
-
26
- context "promotion with no rules" do
27
- include_context "creates the adjustment"
28
- end
29
-
30
- context "promotion includes item involved" do
31
- let!(:rule) { Promotion::Rules::Product.create(products: [line_item.product], promotion: promotion) }
32
-
33
- include_context "creates the adjustment"
34
- end
35
-
36
- context "promotion has item total rule" do
37
- let(:shirt) { create(:product) }
38
- let!(:rule) { Promotion::Rules::ItemTotal.create(preferred_operator_min: 'gt', preferred_amount_min: 50, preferred_operator_max: 'lt', preferred_amount_max: 150, promotion: promotion) }
39
-
40
- before do
41
- # Makes the order eligible for this promotion
42
- order.item_total = 100
43
- order.save
44
- end
45
-
46
- include_context "creates the adjustment"
47
- end
48
- end
49
-
50
- context "activates in Order level" do
51
- let!(:action) { Promotion::Actions::CreateAdjustment.create(promotion: promotion, calculator: calculator) }
52
- let(:adjustable) { order }
53
-
54
- shared_context "creates the adjustment" do
55
- it "creates the adjustment" do
56
- expect {
57
- subject.activate
58
- }.to change { adjustable.adjustments.count }.by(1)
59
- end
60
- end
61
-
62
- context "promotion with no rules" do
63
- before do
64
- # Gives the calculator something to discount
65
- order.item_total = 10
66
- order.save
67
- end
68
-
69
- include_context "creates the adjustment"
70
- end
71
-
72
- context "promotion has item total rule" do
73
- let(:shirt) { create(:product) }
74
- let!(:rule) { Promotion::Rules::ItemTotal.create(preferred_operator_min: 'gt', preferred_amount_min: 50, preferred_operator_max: 'lt', preferred_amount_max: 150, promotion: promotion) }
75
-
76
- before do
77
- # Makes the order eligible for this promotion
78
- order.item_total = 100
79
- order.save
80
- end
81
-
82
- include_context "creates the adjustment"
83
- end
84
- end
85
-
86
- context "activates promotions associated with the order" do
87
- let(:promo) { create :promotion_with_item_adjustment, adjustment_rate: 5, code: 'promo' }
88
- let(:adjustable) { line_item }
89
-
90
- before do
91
- order.promotions << promo
92
- end
93
-
94
- it "creates the adjustment" do
95
- expect {
96
- subject.activate
97
- }.to change { adjustable.adjustments.count }.by(1)
98
- end
99
- end
100
- end
101
- end
102
- end
@@ -1,323 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Spree
4
- module PromotionHandler
5
- describe Coupon, type: :model do
6
- let(:order) { double("Order", coupon_code: "10off").as_null_object }
7
-
8
- subject { Coupon.new(order) }
9
-
10
- it "returns self in apply" do
11
- expect(subject.apply).to be_a Coupon
12
- end
13
-
14
- context 'status messages' do
15
- let(:coupon) { Coupon.new(order) }
16
-
17
- describe "#set_success_code" do
18
- let(:status) { :coupon_code_applied }
19
- subject { coupon.set_success_code status }
20
-
21
- it 'should have status_code' do
22
- subject
23
- expect(coupon.status_code).to eq(status)
24
- end
25
-
26
- it 'should have success message' do
27
- subject
28
- expect(coupon.success).to eq(Spree.t(status))
29
- end
30
- end
31
-
32
- describe "#set_error_code" do
33
- let(:status) { :coupon_code_not_found }
34
-
35
- subject { coupon.set_error_code status }
36
-
37
- it 'should have status_code' do
38
- subject
39
- expect(coupon.status_code).to eq(status)
40
- end
41
-
42
- it 'should have error message' do
43
- subject
44
- expect(coupon.error).to eq(Spree.t(status))
45
- end
46
- end
47
- end
48
-
49
- context "coupon code promotion doesnt exist" do
50
- before { Promotion.create name: "promo", code: nil }
51
-
52
- it "doesnt fetch any promotion" do
53
- expect(subject.promotion).to be_blank
54
- end
55
-
56
- context "with no actions defined" do
57
- before { Promotion.create name: "promo", code: "10off" }
58
-
59
- it "populates error message" do
60
- subject.apply
61
- expect(subject.error).to eq Spree.t(:coupon_code_not_found)
62
- end
63
- end
64
- end
65
-
66
- context "existing coupon code promotion" do
67
- let!(:promotion) { Promotion.create name: "promo", code: "10off" }
68
- let!(:action) { Promotion::Actions::CreateItemAdjustments.create(promotion: promotion, calculator: calculator) }
69
- let(:calculator) { Calculator::FlatRate.new(preferred_amount: 10) }
70
-
71
- it "fetches with given code" do
72
- expect(subject.promotion).to eq promotion
73
- end
74
-
75
- context "with a per-item adjustment action" do
76
- let(:order) { create(:order_with_line_items, line_items_count: 3) }
77
-
78
- context "right coupon given" do
79
- context "with correct coupon code casing" do
80
- before { allow(order).to receive_messages coupon_code: "10off" }
81
-
82
- it "successfully activates promo" do
83
- expect(order.total).to eq(130)
84
- subject.apply
85
- expect(subject.success).to be_present
86
- order.line_items.each do |line_item|
87
- expect(line_item.adjustments.count).to eq(1)
88
- end
89
- # Ensure that applying the adjustment actually affects the order's total!
90
- expect(order.reload.total).to eq(100)
91
- end
92
-
93
- it "coupon already applied to the order" do
94
- subject.apply
95
- expect(subject.success).to be_present
96
- subject.apply
97
- expect(subject.error).to eq Spree.t(:coupon_code_already_applied)
98
- end
99
- end
100
-
101
- # Regression test for #4211
102
- context "with incorrect coupon code casing" do
103
- before { allow(order).to receive_messages coupon_code: "10OFF" }
104
- it "successfully activates promo" do
105
- expect(order.total).to eq(130)
106
- subject.apply
107
- expect(subject.success).to be_present
108
- order.line_items.each do |line_item|
109
- expect(line_item.adjustments.count).to eq(1)
110
- end
111
- # Ensure that applying the adjustment actually affects the order's total!
112
- expect(order.reload.total).to eq(100)
113
- end
114
- end
115
- end
116
-
117
- context "coexists with a non coupon code promo" do
118
- let!(:order) { Order.create }
119
-
120
- before do
121
- allow(order).to receive_messages coupon_code: "10off"
122
- calculator = Calculator::FlatRate.new(preferred_amount: 10)
123
- general_promo = Promotion.create name: "General Promo"
124
- general_action = Promotion::Actions::CreateItemAdjustments.create(promotion: general_promo, calculator: calculator)
125
-
126
- order.contents.add create(:variant)
127
- end
128
-
129
- # regression spec for #4515
130
- it "successfully activates promo" do
131
- subject.apply
132
- expect(subject).to be_successful
133
- end
134
- end
135
- end
136
-
137
- context "with a free-shipping adjustment action" do
138
- let!(:action) { Promotion::Actions::FreeShipping.create(promotion: promotion) }
139
- context "right coupon code given" do
140
- let(:order) { create(:order_with_line_items, line_items_count: 3) }
141
-
142
- before { allow(order).to receive_messages coupon_code: "10off" }
143
-
144
- it "successfully activates promo" do
145
- expect(order.total).to eq(130)
146
- subject.apply
147
- expect(subject.success).to be_present
148
-
149
- expect(order.shipment_adjustments.count).to eq(1)
150
- end
151
-
152
- it "coupon already applied to the order" do
153
- subject.apply
154
- expect(subject.success).to be_present
155
- subject.apply
156
- expect(subject.error).to eq Spree.t(:coupon_code_already_applied)
157
- end
158
- end
159
- end
160
-
161
- context "with a whole-order adjustment action" do
162
- let!(:action) { Promotion::Actions::CreateAdjustment.create(promotion: promotion, calculator: calculator) }
163
- context "right coupon given" do
164
- let(:order) { create(:order) }
165
- let(:calculator) { Calculator::FlatRate.new(preferred_amount: 10) }
166
-
167
- before do
168
- allow(order).to receive_messages({
169
- coupon_code: "10off",
170
- # These need to be here so that promotion adjustment "wins"
171
- item_total: 50,
172
- ship_total: 10
173
- })
174
- end
175
-
176
- it "successfully activates promo" do
177
- subject.apply
178
- expect(subject.success).to be_present
179
- expect(order.adjustments.count).to eq(1)
180
- end
181
-
182
- it "coupon already applied to the order" do
183
- subject.apply
184
- expect(subject.success).to be_present
185
- subject.apply
186
- expect(subject.error).to eq Spree.t(:coupon_code_already_applied)
187
- end
188
-
189
- it "coupon fails to activate" do
190
- allow_any_instance_of(Spree::Promotion).to receive(:activate).and_return false
191
- subject.apply
192
- expect(subject.error).to eq Spree.t(:coupon_code_unknown_error)
193
- end
194
-
195
-
196
- it "coupon code hit max usage" do
197
- promotion.update_column(:usage_limit, 1)
198
- coupon = Coupon.new(order)
199
- coupon.apply
200
- expect(coupon.successful?).to be true
201
-
202
- order_2 = create(:order)
203
- allow(order_2).to receive_messages coupon_code: "10off"
204
- coupon = Coupon.new(order_2)
205
- coupon.apply
206
- expect(coupon.successful?).to be false
207
- expect(coupon.error).to eq Spree.t(:coupon_code_max_usage)
208
- end
209
-
210
- context "when the a new coupon is less good" do
211
- let!(:action_5) { Promotion::Actions::CreateAdjustment.create(promotion: promotion_5, calculator: calculator_5) }
212
- let(:calculator_5) { Calculator::FlatRate.new(preferred_amount: 5) }
213
- let!(:promotion_5) { Promotion.create name: "promo", code: "5off" }
214
-
215
- it 'notifies of better deal' do
216
- subject.apply
217
- allow(order).to receive_messages( { coupon_code: '5off' } )
218
- coupon = Coupon.new(order).apply
219
- expect(coupon.error).to eq Spree.t(:coupon_code_better_exists)
220
- end
221
- end
222
- end
223
- end
224
-
225
- context "for an order with taxable line items" do
226
- before(:each) do
227
- @country = create(:country)
228
- @zone = create(:zone, name: "Country Zone", default_tax: true, zone_members: [])
229
- @zone.zone_members.create(zoneable: @country)
230
- @category = Spree::TaxCategory.create name: "Taxable Foo"
231
- @rate1 = Spree::TaxRate.create(
232
- amount: 0.10,
233
- calculator: Spree::Calculator::DefaultTax.create,
234
- tax_category: @category,
235
- zone: @zone
236
- )
237
-
238
- @order = Spree::Order.create!
239
- allow(@order).to receive_messages coupon_code: "10off"
240
- end
241
- context "and the product price is less than promo discount" do
242
- before(:each) do
243
- 3.times do |i|
244
- taxable = create(:product, tax_category: @category, price: 9.0)
245
- @order.contents.add(taxable.master, 1)
246
- end
247
- end
248
- it "successfully applies the promo" do
249
- # 3 * (9 + 0.9)
250
- expect(@order.total).to eq(29.7)
251
- coupon = Coupon.new(@order)
252
- coupon.apply
253
- expect(coupon.success).to be_present
254
- # 3 * ((9 - [9,10].min) + 0)
255
- expect(@order.reload.total).to eq(0)
256
- expect(@order.additional_tax_total).to eq(0)
257
- end
258
- end
259
- context "and the product price is greater than promo discount" do
260
- before(:each) do
261
- 3.times do |i|
262
- taxable = create(:product, tax_category: @category, price: 11.0)
263
- @order.contents.add(taxable.master, 2)
264
- end
265
- end
266
- it "successfully applies the promo" do
267
- # 3 * (22 + 2.2)
268
- expect(@order.total.to_f).to eq(72.6)
269
- coupon = Coupon.new(@order)
270
- coupon.apply
271
- expect(coupon.success).to be_present
272
- # 3 * ( (22 - 10) + 1.2)
273
- expect(@order.reload.total).to eq(39.6)
274
- expect(@order.additional_tax_total).to eq(3.6)
275
- end
276
- end
277
- context "and multiple quantity per line item" do
278
- before(:each) do
279
- twnty_off = Promotion.create name: "promo", code: "20off"
280
- twnty_off_calc = Calculator::FlatRate.new(preferred_amount: 20)
281
- Promotion::Actions::CreateItemAdjustments.create(promotion: twnty_off,
282
- calculator: twnty_off_calc)
283
-
284
- allow(@order).to receive(:coupon_code).and_call_original
285
- allow(@order).to receive_messages coupon_code: "20off"
286
- 3.times do |i|
287
- taxable = create(:product, tax_category: @category, price: 10.0)
288
- @order.contents.add(taxable.master, 2)
289
- end
290
- end
291
- it "successfully applies the promo" do
292
- # 3 * ((2 * 10) + 2.0)
293
- expect(@order.total.to_f).to eq(66)
294
- coupon = Coupon.new(@order)
295
- coupon.apply
296
- expect(coupon.success).to be_present
297
- # 0
298
- expect(@order.reload.total).to eq(0)
299
- expect(@order.additional_tax_total).to eq(0)
300
- end
301
- end
302
- end
303
-
304
- context "with a CreateLineItems action" do
305
- let!(:variant) { create(:variant) }
306
- let!(:action) { Promotion::Actions::CreateLineItems.create(promotion: promotion, promotion_action_line_items_attributes: { :'0' => { variant_id: variant.id }}) }
307
- let(:order) { create(:order) }
308
-
309
- before do
310
- allow(order).to receive_messages(coupon_code: "10off")
311
- end
312
-
313
- it "successfully activates promo" do
314
- subject.apply
315
- expect(subject.success).to be_present
316
- expect(order.line_items.pluck(:variant_id)).to include(variant.id)
317
- end
318
- end
319
-
320
- end
321
- end
322
- end
323
- end