spree_core 3.1.5 → 3.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (215) hide show
  1. checksums.yaml +4 -4
  2. data/app/models/concerns/spree/ransackable_attributes.rb +6 -1
  3. data/app/models/concerns/spree/user_methods.rb +10 -0
  4. data/app/models/spree/legacy_user.rb +0 -8
  5. data/app/models/spree/order.rb +1 -1
  6. data/app/models/spree/product.rb +8 -0
  7. data/app/models/spree/product/scopes.rb +7 -3
  8. data/app/models/spree/stock_transfer.rb +1 -1
  9. data/config/locales/en.yml +2 -0
  10. data/lib/spree/core/version.rb +1 -1
  11. data/spree_core.gemspec +2 -2
  12. metadata +11 -208
  13. data/spec/fixtures/microdata.html +0 -22
  14. data/spec/fixtures/microdata_itemref.html +0 -15
  15. data/spec/fixtures/microdata_no_itemscope.html +0 -20
  16. data/spec/fixtures/thinking-cat.jpg +0 -0
  17. data/spec/helpers/base_helper_spec.rb +0 -200
  18. data/spec/helpers/products_helper_spec.rb +0 -296
  19. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  20. data/spec/lib/i18n_spec.rb +0 -123
  21. data/spec/lib/search/base_spec.rb +0 -86
  22. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  23. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  24. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  25. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  26. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  27. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  28. data/spec/lib/spree/core/importer/order_spec.rb +0 -605
  29. data/spec/lib/spree/core/number_generator_spec.rb +0 -175
  30. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  31. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  32. data/spec/lib/spree/core_spec.rb +0 -23
  33. data/spec/lib/spree/localized_number_spec.rb +0 -48
  34. data/spec/lib/spree/migrations_spec.rb +0 -36
  35. data/spec/lib/spree/money_spec.rb +0 -122
  36. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  37. data/spec/mailers/order_mailer_spec.rb +0 -122
  38. data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
  39. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  40. data/spec/mailers/test_mailer_spec.rb +0 -38
  41. data/spec/models/option_type_prototype_spec.rb +0 -9
  42. data/spec/models/spree/ability_spec.rb +0 -251
  43. data/spec/models/spree/address_spec.rb +0 -291
  44. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  45. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  46. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  47. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  48. data/spec/models/spree/adjustment_spec.rb +0 -189
  49. data/spec/models/spree/app_configuration_spec.rb +0 -26
  50. data/spec/models/spree/asset_spec.rb +0 -28
  51. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  52. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  53. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  54. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  55. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  56. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  57. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -51
  58. data/spec/models/spree/calculator/shipping.rb +0 -8
  59. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  60. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  61. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  62. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  63. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  64. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  65. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  66. data/spec/models/spree/calculator_spec.rb +0 -69
  67. data/spec/models/spree/classification_spec.rb +0 -93
  68. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  69. data/spec/models/spree/concerns/user_methods_spec.rb +0 -55
  70. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  71. data/spec/models/spree/country_spec.rb +0 -55
  72. data/spec/models/spree/credit_card_spec.rb +0 -328
  73. data/spec/models/spree/customer_return_spec.rb +0 -240
  74. data/spec/models/spree/exchange_spec.rb +0 -75
  75. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  76. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  77. data/spec/models/spree/gateway_spec.rb +0 -61
  78. data/spec/models/spree/image_spec.rb +0 -8
  79. data/spec/models/spree/inventory_unit_spec.rb +0 -225
  80. data/spec/models/spree/line_item_spec.rb +0 -327
  81. data/spec/models/spree/option_type_spec.rb +0 -14
  82. data/spec/models/spree/option_value_spec.rb +0 -18
  83. data/spec/models/spree/order/address_spec.rb +0 -50
  84. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  85. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  86. data/spec/models/spree/order/checkout_spec.rb +0 -782
  87. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  88. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  89. data/spec/models/spree/order/helpers_spec.rb +0 -5
  90. data/spec/models/spree/order/payment_spec.rb +0 -214
  91. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  92. data/spec/models/spree/order/shipments_spec.rb +0 -43
  93. data/spec/models/spree/order/state_machine_spec.rb +0 -211
  94. data/spec/models/spree/order/store_credit_spec.rb +0 -426
  95. data/spec/models/spree/order/tax_spec.rb +0 -84
  96. data/spec/models/spree/order/totals_spec.rb +0 -24
  97. data/spec/models/spree/order/updating_spec.rb +0 -18
  98. data/spec/models/spree/order/validations_spec.rb +0 -15
  99. data/spec/models/spree/order_contents_spec.rb +0 -297
  100. data/spec/models/spree/order_inventory_spec.rb +0 -238
  101. data/spec/models/spree/order_merger_spec.rb +0 -135
  102. data/spec/models/spree/order_spec.rb +0 -967
  103. data/spec/models/spree/order_updater_spec.rb +0 -305
  104. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  105. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  106. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  107. data/spec/models/spree/payment_method_spec.rb +0 -103
  108. data/spec/models/spree/payment_spec.rb +0 -919
  109. data/spec/models/spree/preference_spec.rb +0 -80
  110. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  111. data/spec/models/spree/preferences/preferable_spec.rb +0 -348
  112. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  113. data/spec/models/spree/preferences/store_spec.rb +0 -46
  114. data/spec/models/spree/price_spec.rb +0 -128
  115. data/spec/models/spree/product/scopes_spec.rb +0 -183
  116. data/spec/models/spree/product_duplicator_spec.rb +0 -103
  117. data/spec/models/spree/product_filter_spec.rb +0 -26
  118. data/spec/models/spree/product_option_type_spec.rb +0 -9
  119. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  120. data/spec/models/spree/product_property_spec.rb +0 -22
  121. data/spec/models/spree/product_spec.rb +0 -540
  122. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -50
  123. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  124. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  125. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  126. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  127. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  128. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  129. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  130. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  131. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  132. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  133. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  134. data/spec/models/spree/promotion_action_spec.rb +0 -10
  135. data/spec/models/spree/promotion_category_spec.rb +0 -17
  136. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  137. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  138. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  139. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  140. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  141. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  142. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  143. data/spec/models/spree/promotion_spec.rb +0 -644
  144. data/spec/models/spree/property_prototype_spec.rb +0 -9
  145. data/spec/models/spree/property_spec.rb +0 -5
  146. data/spec/models/spree/prototype_spec.rb +0 -5
  147. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  148. data/spec/models/spree/refund_reason_spec.rb +0 -7
  149. data/spec/models/spree/refund_spec.rb +0 -195
  150. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  151. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  152. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  153. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  154. data/spec/models/spree/reimbursement_spec.rb +0 -188
  155. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  156. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  157. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  158. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  159. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  160. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  161. data/spec/models/spree/return_authorization_spec.rb +0 -230
  162. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  163. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  164. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  165. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  166. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  167. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  168. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  169. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  170. data/spec/models/spree/return_item_spec.rb +0 -731
  171. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  172. data/spec/models/spree/role_spec.rb +0 -7
  173. data/spec/models/spree/shipment_spec.rb +0 -740
  174. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  175. data/spec/models/spree/shipping_category_spec.rb +0 -19
  176. data/spec/models/spree/shipping_method_spec.rb +0 -95
  177. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  178. data/spec/models/spree/state_spec.rb +0 -29
  179. data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
  180. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  181. data/spec/models/spree/stock/coordinator_spec.rb +0 -51
  182. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  183. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  184. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
  185. data/spec/models/spree/stock/package_spec.rb +0 -194
  186. data/spec/models/spree/stock/packer_spec.rb +0 -70
  187. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  188. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  189. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  190. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  191. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  192. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  193. data/spec/models/spree/stock_item_spec.rb +0 -428
  194. data/spec/models/spree/stock_location_spec.rb +0 -243
  195. data/spec/models/spree/stock_movement_spec.rb +0 -56
  196. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  197. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  198. data/spec/models/spree/store_credit_spec.rb +0 -786
  199. data/spec/models/spree/store_spec.rb +0 -78
  200. data/spec/models/spree/tax_category_spec.rb +0 -32
  201. data/spec/models/spree/tax_rate_spec.rb +0 -542
  202. data/spec/models/spree/taxon_spec.rb +0 -74
  203. data/spec/models/spree/taxonomy_spec.rb +0 -18
  204. data/spec/models/spree/tracker_spec.rb +0 -21
  205. data/spec/models/spree/user_spec.rb +0 -203
  206. data/spec/models/spree/variant_spec.rb +0 -795
  207. data/spec/models/spree/zone_member_spec.rb +0 -38
  208. data/spec/models/spree/zone_spec.rb +0 -470
  209. data/spec/spec_helper.rb +0 -77
  210. data/spec/support/big_decimal.rb +0 -5
  211. data/spec/support/concerns/adjustment_source.rb +0 -23
  212. data/spec/support/concerns/default_price.rb +0 -37
  213. data/spec/support/rake.rb +0 -13
  214. data/spec/support/test_gateway.rb +0 -2
  215. data/spec/validators/db_maximum_length_validator_spec.rb +0 -22
@@ -1,291 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Address, :type => :model do
4
-
5
- subject { Spree::Address }
6
-
7
- describe "clone" do
8
- it "creates a copy of the address with the exception of the id, updated_at and created_at attributes" do
9
- state = create(:state)
10
- original = create(:address,
11
- :address1 => 'address1',
12
- :address2 => 'address2',
13
- :alternative_phone => 'alternative_phone',
14
- :city => 'city',
15
- :country => Spree::Country.first,
16
- :firstname => 'firstname',
17
- :lastname => 'lastname',
18
- :company => 'company',
19
- :phone => 'phone',
20
- :state_id => state.id,
21
- :state_name => state.name,
22
- :zipcode => '10001')
23
-
24
- cloned = original.clone
25
-
26
- expect(cloned.address1).to eq(original.address1)
27
- expect(cloned.address2).to eq(original.address2)
28
- expect(cloned.alternative_phone).to eq(original.alternative_phone)
29
- expect(cloned.city).to eq(original.city)
30
- expect(cloned.country_id).to eq(original.country_id)
31
- expect(cloned.firstname).to eq(original.firstname)
32
- expect(cloned.lastname).to eq(original.lastname)
33
- expect(cloned.company).to eq(original.company)
34
- expect(cloned.phone).to eq(original.phone)
35
- expect(cloned.state_id).to eq(original.state_id)
36
- expect(cloned.state_name).to eq(original.state_name)
37
- expect(cloned.zipcode).to eq(original.zipcode)
38
-
39
- expect(cloned.id).not_to eq(original.id)
40
- expect(cloned.created_at).not_to eq(original.created_at)
41
- expect(cloned.updated_at).not_to eq(original.updated_at)
42
- end
43
- end
44
-
45
- context "aliased attributes" do
46
- let(:address) { Spree::Address.new }
47
-
48
- it "first_name" do
49
- address.firstname = "Ryan"
50
- expect(address.first_name).to eq("Ryan")
51
- end
52
-
53
- it "last_name" do
54
- address.lastname = "Bigg"
55
- expect(address.last_name).to eq("Bigg")
56
- end
57
- end
58
-
59
- context "validation" do
60
- before do
61
- configure_spree_preferences do |config|
62
- config.address_requires_state = true
63
- end
64
- end
65
-
66
- let(:country) { mock_model(Spree::Country, :states => [state], :states_required => true) }
67
- let(:state) { stub_model(Spree::State, :name => 'maryland', :abbr => 'md') }
68
- let(:address) { build(:address, :country => country) }
69
-
70
- before do
71
- allow(country.states).to receive_messages :find_all_by_name_or_abbr => [state]
72
- end
73
-
74
- it "state_name is not nil and country does not have any states" do
75
- address.state = nil
76
- address.state_name = 'alabama'
77
- expect(address).to be_valid
78
- end
79
-
80
- it "errors when state_name is nil" do
81
- address.state_name = nil
82
- address.state = nil
83
- expect(address).not_to be_valid
84
- end
85
-
86
- it "full state name is in state_name and country does contain that state" do
87
- address.state_name = 'alabama'
88
- # called by state_validate to set up state_id.
89
- # Perhaps this should be a before_validation instead?
90
- expect(address).to be_valid
91
- expect(address.state).not_to be_nil
92
- expect(address.state_name).to be_nil
93
- end
94
-
95
- it "state abbr is in state_name and country does contain that state" do
96
- address.state_name = state.abbr
97
- expect(address).to be_valid
98
- expect(address.state_id).not_to be_nil
99
- expect(address.state_name).to be_nil
100
- end
101
-
102
- it "state is entered but country does not contain that state" do
103
- address.state = state
104
- address.country = stub_model(Spree::Country, :states_required => true)
105
- address.valid?
106
- expect(address.errors["state"]).to eq(['is invalid'])
107
- end
108
-
109
- it "both state and state_name are entered but country does not contain the state" do
110
- address.state = state
111
- address.state_name = 'maryland'
112
- address.country = stub_model(Spree::Country, :states_required => true)
113
- expect(address).to be_valid
114
- expect(address.state_id).to be_nil
115
- end
116
-
117
- it "both state and state_name are entered and country does contain the state" do
118
- address.state = state
119
- address.state_name = 'maryland'
120
- expect(address).to be_valid
121
- expect(address.state_name).to be_nil
122
- end
123
-
124
- it "address_requires_state preference is false" do
125
- Spree::Config.set :address_requires_state => false
126
- address.state = nil
127
- address.state_name = nil
128
- expect(address).to be_valid
129
- end
130
-
131
- it "requires phone" do
132
- address.phone = ""
133
- address.valid?
134
- expect(address.errors["phone"]).to eq(["can't be blank"])
135
- end
136
-
137
- it "requires zipcode" do
138
- address.zipcode = ""
139
- address.valid?
140
- expect(address.errors['zipcode']).to include("can't be blank")
141
- end
142
-
143
- context "zipcode validation" do
144
- it "validates the zipcode" do
145
- allow(address.country).to receive(:iso).and_return('US')
146
- address.zipcode = 'abc'
147
- address.valid?
148
- expect(address.errors['zipcode']).to include('is invalid')
149
- end
150
-
151
- it "accepts a zip code with surrounding white space" do
152
- allow(address.country).to receive(:iso).and_return('US')
153
- address.zipcode = ' 12345 '
154
- address.valid?
155
- expect(address.errors['zipcode']).not_to include('is invalid')
156
- end
157
-
158
- context 'does not validate' do
159
- it 'does not have a country' do
160
- address.country = nil
161
- address.valid?
162
- expect(address.errors['zipcode']).not_to include('is invalid')
163
- end
164
-
165
- it 'does not have an iso' do
166
- allow(address.country).to receive(:iso).and_return(nil)
167
- address.valid?
168
- expect(address.errors['zipcode']).not_to include('is invalid')
169
- end
170
-
171
- it 'does not have a zipcode' do
172
- address.zipcode = ""
173
- address.valid?
174
- expect(address.errors['zipcode']).not_to include('is invalid')
175
- end
176
-
177
- it 'does not have a supported country iso' do
178
- allow(address.country).to receive(:iso).and_return('BO')
179
- address.valid?
180
- expect(address.errors['zipcode']).not_to include('is invalid')
181
- end
182
- end
183
- end
184
-
185
- context "phone not required" do
186
- before { allow(address).to receive_messages require_phone?: false }
187
-
188
- it "shows no errors when phone is blank" do
189
- address.phone = ""
190
- address.valid?
191
- expect(address.errors[:phone].size).to eq 0
192
- end
193
- end
194
-
195
- context "zipcode not required" do
196
- before { allow(address).to receive_messages require_zipcode?: false }
197
-
198
- it "shows no errors when phone is blank" do
199
- address.zipcode = ""
200
- address.valid?
201
- expect(address.errors[:zipcode].size).to eq 0
202
- end
203
- end
204
- end
205
-
206
- context ".default" do
207
- context "no user given" do
208
- before do
209
- @default_country_id = Spree::Config[:default_country_id]
210
- new_country = create(:country)
211
- Spree::Config[:default_country_id] = new_country.id
212
- end
213
-
214
- after do
215
- Spree::Config[:default_country_id] = @default_country_id
216
- end
217
-
218
- it "sets up a new record with Spree::Config[:default_country_id]" do
219
- expect(Spree::Address.default.country).to eq(Spree::Country.find(Spree::Config[:default_country_id]))
220
- end
221
-
222
- # Regression test for #1142
223
- it "uses the first available country if :default_country_id is set to an invalid value" do
224
- Spree::Config[:default_country_id] = "0"
225
- expect(Spree::Address.default.country).to eq(Spree::Country.first)
226
- end
227
- end
228
-
229
- context "user given" do
230
- let(:bill_address) { Spree::Address.new(phone: Time.current.to_i) }
231
- let(:ship_address) { double("ShipAddress") }
232
- let(:user) { double("User", bill_address: bill_address, ship_address: ship_address) }
233
-
234
- it "returns a copy of that user bill address" do
235
- expect(subject.default(user).phone).to eq bill_address.phone
236
- end
237
-
238
- it "falls back to build default when user has no address" do
239
- allow(user).to receive_messages(bill_address: nil)
240
- expect(subject.default(user)).to eq subject.build_default
241
- end
242
- end
243
- end
244
-
245
- context '#full_name' do
246
- context 'both first and last names are present' do
247
- let(:address) { stub_model(Spree::Address, :firstname => 'Michael', :lastname => 'Jackson') }
248
- specify { expect(address.full_name).to eq('Michael Jackson') }
249
- end
250
-
251
- context 'first name is blank' do
252
- let(:address) { stub_model(Spree::Address, :firstname => nil, :lastname => 'Jackson') }
253
- specify { expect(address.full_name).to eq('Jackson') }
254
- end
255
-
256
- context 'last name is blank' do
257
- let(:address) { stub_model(Spree::Address, :firstname => 'Michael', :lastname => nil) }
258
- specify { expect(address.full_name).to eq('Michael') }
259
- end
260
-
261
- context 'both first and last names are blank' do
262
- let(:address) { stub_model(Spree::Address, :firstname => nil, :lastname => nil) }
263
- specify { expect(address.full_name).to eq('') }
264
- end
265
-
266
- end
267
-
268
- context '#state_text' do
269
- context 'state is blank' do
270
- let(:address) { stub_model(Spree::Address, :state => nil, :state_name => 'virginia') }
271
- specify { expect(address.state_text).to eq('virginia') }
272
- end
273
-
274
- context 'both name and abbr is present' do
275
- let(:state) { stub_model(Spree::State, :name => 'virginia', :abbr => 'va') }
276
- let(:address) { stub_model(Spree::Address, :state => state) }
277
- specify { expect(address.state_text).to eq('va') }
278
- end
279
-
280
- context 'only name is present' do
281
- let(:state) { stub_model(Spree::State, :name => 'virginia', :abbr => nil) }
282
- let(:address) { stub_model(Spree::Address, :state => state) }
283
- specify { expect(address.state_text).to eq('virginia') }
284
- end
285
- end
286
-
287
- context "defines require_phone? helper method" do
288
- let(:address) { stub_model(Spree::Address) }
289
- specify { expect(address.instance_eval{ require_phone? }).to be true}
290
- end
291
- end
@@ -1,10 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Adjustable::Adjuster::Base, type: :model do
4
- let(:line_item) { create(:line_item) }
5
- let(:subject) { Spree::Adjustable::Adjuster::Base }
6
-
7
- it "raises missing update method" do
8
- expect { subject.adjust(line_item, {}) }.to raise_error(NotImplementedError)
9
- end
10
- end
@@ -1,211 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Spree::Adjustable::Adjuster::Promotion, type: :model do
4
- let(:order) { create :order_with_line_items, line_items_count: 1 }
5
- let(:line_item) { order.line_items.first }
6
- let(:subject) { Spree::Adjustable::AdjustmentsUpdater.new(line_item) }
7
- let(:order_subject) { Spree::Adjustable::AdjustmentsUpdater.new(order) }
8
-
9
- context "best promotion is always applied" do
10
- let(:calculator) { Spree::Calculator::FlatRate.new(preferred_amount: 10) }
11
- let(:source) { Spree::Promotion::Actions::CreateItemAdjustments.create calculator: calculator }
12
-
13
- def create_adjustment(label, amount)
14
- create(:adjustment,
15
- order: order,
16
- adjustable: line_item,
17
- source: source,
18
- amount: amount,
19
- state: "closed",
20
- label: label,
21
- mandatory: false)
22
- end
23
-
24
- describe "competing promos" do
25
- before { Spree::Adjustment.competing_promos_source_types = ['Spree::PromotionAction', 'Custom'] }
26
-
27
- it "do not update promo_total" do
28
- create(:adjustment,
29
- order: order,
30
- adjustable: line_item,
31
- source_type: 'Custom',
32
- source_id: nil,
33
- amount: -3.50,
34
- label: "Other",
35
- mandatory: false)
36
- create_adjustment("Promotion A", -2.50)
37
-
38
- subject.update
39
- expect(line_item.promo_total).to eql 0.0
40
- end
41
- end
42
-
43
- it "should use only the most valuable promotion" do
44
- create_adjustment("Promotion A", -100)
45
- create_adjustment("Promotion B", -200)
46
- create_adjustment("Promotion C", -300)
47
- create(:adjustment,
48
- order: order,
49
- adjustable: line_item,
50
- source: nil,
51
- amount: -500,
52
- state: "closed",
53
- label: "Some other credit")
54
- line_item.adjustments.each { |a| a.update_column(:eligible, true) }
55
-
56
- subject.update
57
-
58
- expect(line_item.adjustments.promotion.eligible.count).to eq(1)
59
- expect(line_item.adjustments.promotion.eligible.first.label).to eq('Promotion C')
60
- end
61
-
62
- it "should choose the most recent promotion adjustment when amounts are equal" do
63
- # Using Timecop is a regression test
64
- Timecop.freeze do
65
- create_adjustment("Promotion A", -200)
66
- create_adjustment("Promotion B", -200)
67
- end
68
- line_item.adjustments.each { |a| a.update_column(:eligible, true) }
69
-
70
- subject.update
71
-
72
- expect(line_item.adjustments.promotion.eligible.count).to eq(1)
73
- expect(line_item.adjustments.promotion.eligible.first.label).to eq('Promotion B')
74
- end
75
-
76
- context "when previously ineligible promotions become available" do
77
- let(:order_promo1) do
78
- create(:promotion,
79
- :with_order_adjustment,
80
- :with_item_total_rule,
81
- weighted_order_adjustment_amount: 5,
82
- item_total_threshold_amount: 10)
83
- end
84
-
85
- let(:order_promo2) do
86
- create(:promotion,
87
- :with_order_adjustment,
88
- :with_item_total_rule,
89
- weighted_order_adjustment_amount: 10,
90
- item_total_threshold_amount: 20)
91
- end
92
-
93
- let(:order_promos) { [order_promo1, order_promo2] }
94
-
95
- let(:line_item_promo1) do
96
- create(:promotion,
97
- :with_line_item_adjustment,
98
- :with_item_total_rule,
99
- adjustment_rate: 2.5,
100
- item_total_threshold_amount: 10)
101
- end
102
-
103
- let(:line_item_promo2) do
104
- create(:promotion,
105
- :with_line_item_adjustment,
106
- :with_item_total_rule,
107
- adjustment_rate: 5,
108
- item_total_threshold_amount: 20)
109
- end
110
-
111
- let(:line_item_promos) { [line_item_promo1, line_item_promo2] }
112
- let(:order) { create(:order_with_line_items, line_items_count: 1) }
113
-
114
- # Apply promotions in different sequences. Results should be the same.
115
- promo_sequences = [[0, 1], [1, 0]]
116
-
117
- promo_sequences.each do |promo_sequence|
118
- it "should pick the best order-level promo according to current eligibility" do
119
- # apply both promos to the order, even though only promo1 is eligible
120
- order_promos[promo_sequence[0]].activate order: order
121
- order_promos[promo_sequence[1]].activate order: order
122
-
123
- order.reload
124
- msg = "Expected two adjustments (using sequence #{promo_sequence})"
125
- expect(order.all_adjustments.count).to eq(2), msg
126
-
127
- msg = "Expected one elegible adjustment (using sequence #{promo_sequence})"
128
- expect(order.all_adjustments.eligible.count).to eq(1), msg
129
-
130
- msg = "Expected promo1 to be used (using sequence #{promo_sequence})"
131
- expect(order.all_adjustments.eligible.first.source.promotion).to eq(order_promo1), msg
132
-
133
- order.contents.add create(:variant, price: 10), 1
134
- order.save
135
-
136
- order.reload
137
- msg = "Expected two adjustments (using sequence #{promo_sequence})"
138
- expect(order.all_adjustments.count).to eq(2), msg
139
-
140
- msg = "Expected one elegible adjustment (using sequence #{promo_sequence})"
141
- expect(order.all_adjustments.eligible.count).to eq(1), msg
142
-
143
- msg = "Expected promo2 to be used (using sequence #{promo_sequence})"
144
- expect(order.all_adjustments.eligible.first.source.promotion).to eq(order_promo2), msg
145
- end
146
- end
147
-
148
- promo_sequences.each do |promo_sequence|
149
- it "should pick the best line-item-level promo according to current eligibility" do
150
- # apply both promos to the order, even though only promo1 is eligible
151
- line_item_promos[promo_sequence[0]].activate order: order
152
- line_item_promos[promo_sequence[1]].activate order: order
153
-
154
- order.reload
155
- msg = "Expected one adjustment (using sequence #{promo_sequence})"
156
- expect(order.all_adjustments.count).to eq(1), msg
157
-
158
- msg = "Expected one elegible adjustment (using sequence #{promo_sequence})"
159
- expect(order.all_adjustments.eligible.count).to eq(1), msg
160
-
161
- # line_item_promo1 is the only one that has thus far met the order total threshold,
162
- # it is the only promo which should be applied.
163
- msg = "Expected line_item_promo1 to be used (using sequence #{promo_sequence})"
164
- expect(order.all_adjustments.first.source.promotion).to eq(line_item_promo1), msg
165
-
166
- order.contents.add create(:variant, price: 10), 1
167
- order.save
168
-
169
- order.reload
170
- msg = "Expected four adjustments (using sequence #{promo_sequence})"
171
- expect(order.all_adjustments.count).to eq(4), msg
172
-
173
- msg = "Expected two elegible adjustments (using sequence #{promo_sequence})"
174
- expect(order.all_adjustments.eligible.count).to eq(2), msg
175
-
176
- order.all_adjustments.eligible.each do |adjustment|
177
- msg = "Expected line_item_promo2 to be used (using sequence #{promo_sequence})"
178
- expect(adjustment.source.promotion).to eq(line_item_promo2), msg
179
- end
180
- end
181
- end
182
- end
183
-
184
- context "multiple adjustments and the best one is not eligible" do
185
- let!(:promo_a) { create_adjustment("Promotion A", -100) }
186
- let!(:promo_c) { create_adjustment("Promotion C", -300) }
187
-
188
- before do
189
- promo_a.update_column(:eligible, true)
190
- promo_c.update_column(:eligible, false)
191
- end
192
-
193
- # regression for #3274
194
- it "still makes the previous best eligible adjustment valid" do
195
- subject.update
196
- expect(line_item.adjustments.promotion.eligible.first.label).to eq('Promotion A')
197
- end
198
- end
199
-
200
- it "should only leave one adjustment even if 2 have the same amount" do
201
- create_adjustment("Promotion A", -100)
202
- create_adjustment("Promotion B", -200)
203
- create_adjustment("Promotion C", -200)
204
-
205
- subject.update
206
-
207
- expect(line_item.adjustments.promotion.eligible.count).to eq(1)
208
- expect(line_item.adjustments.promotion.eligible.first.amount.to_i).to eq(-200)
209
- end
210
- end
211
- end