spree_core 3.0.5 → 3.0.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +4 -0
  3. data/Gemfile +3 -0
  4. data/Rakefile +30 -0
  5. data/app/assets/javascripts/spree.js.coffee.erb +1 -1
  6. data/app/models/spree/ability.rb +1 -1
  7. data/app/models/spree/base.rb +3 -1
  8. data/app/models/spree/order_updater.rb +2 -1
  9. data/app/models/spree/price.rb +7 -12
  10. data/app/models/spree/product.rb +3 -2
  11. data/app/models/spree/reimbursement.rb +1 -1
  12. data/app/models/spree/state.rb +2 -0
  13. data/app/models/spree/zone.rb +1 -1
  14. data/lib/spree/core/version.rb +1 -1
  15. data/lib/spree/testing_support/shoulda_matcher_configuration.rb +6 -0
  16. data/script/rails +9 -0
  17. data/spec/fixtures/thinking-cat.jpg +0 -0
  18. data/spec/helpers/base_helper_spec.rb +137 -0
  19. data/spec/helpers/products_helper_spec.rb +224 -0
  20. data/spec/lib/calculated_adjustments_spec.rb +7 -0
  21. data/spec/lib/i18n_spec.rb +123 -0
  22. data/spec/lib/search/base_spec.rb +86 -0
  23. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +101 -0
  24. data/spec/lib/spree/core/controller_helpers/order_spec.rb +95 -0
  25. data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
  26. data/spec/lib/spree/core/controller_helpers/store_spec.rb +16 -0
  27. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
  28. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +22 -0
  29. data/spec/lib/spree/core/importer/order_spec.rb +502 -0
  30. data/spec/lib/spree/core/validators/email_spec.rb +53 -0
  31. data/spec/lib/spree/localized_number_spec.rb +38 -0
  32. data/spec/lib/spree/migrations_spec.rb +34 -0
  33. data/spec/lib/spree/money_spec.rb +122 -0
  34. data/spec/lib/tasks/exchanges_spec.rb +136 -0
  35. data/spec/mailers/order_mailer_spec.rb +124 -0
  36. data/spec/mailers/reimbursement_mailer_spec.rb +47 -0
  37. data/spec/mailers/shipment_mailer_spec.rb +63 -0
  38. data/spec/mailers/test_mailer_spec.rb +24 -0
  39. data/spec/models/spree/ability_spec.rb +246 -0
  40. data/spec/models/spree/address_spec.rb +291 -0
  41. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +286 -0
  42. data/spec/models/spree/adjustment_spec.rb +163 -0
  43. data/spec/models/spree/app_configuration_spec.rb +23 -0
  44. data/spec/models/spree/asset_spec.rb +25 -0
  45. data/spec/models/spree/calculator/default_tax_spec.rb +127 -0
  46. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
  47. data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
  48. data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
  49. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
  50. data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
  51. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +51 -0
  52. data/spec/models/spree/calculator/shipping.rb +8 -0
  53. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
  54. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
  55. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
  56. data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
  57. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +29 -0
  58. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +40 -0
  59. data/spec/models/spree/calculator/tiered_percent_spec.rb +51 -0
  60. data/spec/models/spree/calculator_spec.rb +69 -0
  61. data/spec/models/spree/classification_spec.rb +93 -0
  62. data/spec/models/spree/concerns/display_money_spec.rb +43 -0
  63. data/spec/models/spree/country_spec.rb +18 -0
  64. data/spec/models/spree/credit_card_spec.rb +324 -0
  65. data/spec/models/spree/customer_return_spec.rb +262 -0
  66. data/spec/models/spree/exchange_spec.rb +75 -0
  67. data/spec/models/spree/gateway/bogus_simple.rb +20 -0
  68. data/spec/models/spree/gateway/bogus_spec.rb +13 -0
  69. data/spec/models/spree/gateway_spec.rb +54 -0
  70. data/spec/models/spree/image_spec.rb +5 -0
  71. data/spec/models/spree/inventory_unit_spec.rb +242 -0
  72. data/spec/models/spree/line_item_spec.rb +267 -0
  73. data/spec/models/spree/option_type_spec.rb +14 -0
  74. data/spec/models/spree/option_value_spec.rb +13 -0
  75. data/spec/models/spree/order/address_spec.rb +50 -0
  76. data/spec/models/spree/order/adjustments_spec.rb +29 -0
  77. data/spec/models/spree/order/callbacks_spec.rb +42 -0
  78. data/spec/models/spree/order/checkout_spec.rb +764 -0
  79. data/spec/models/spree/order/currency_updater_spec.rb +32 -0
  80. data/spec/models/spree/order/finalizing_spec.rb +117 -0
  81. data/spec/models/spree/order/helpers_spec.rb +5 -0
  82. data/spec/models/spree/order/payment_spec.rb +214 -0
  83. data/spec/models/spree/order/risk_assessment_spec.rb +84 -0
  84. data/spec/models/spree/order/shipments_spec.rb +43 -0
  85. data/spec/models/spree/order/state_machine_spec.rb +216 -0
  86. data/spec/models/spree/order/tax_spec.rb +84 -0
  87. data/spec/models/spree/order/totals_spec.rb +24 -0
  88. data/spec/models/spree/order/updating_spec.rb +18 -0
  89. data/spec/models/spree/order/validations_spec.rb +15 -0
  90. data/spec/models/spree/order_contents_spec.rb +256 -0
  91. data/spec/models/spree/order_inventory_spec.rb +228 -0
  92. data/spec/models/spree/order_merger_spec.rb +133 -0
  93. data/spec/models/spree/order_spec.rb +954 -0
  94. data/spec/models/spree/order_updater_spec.rb +283 -0
  95. data/spec/models/spree/payment/gateway_options_spec.rb +119 -0
  96. data/spec/models/spree/payment_method_spec.rb +95 -0
  97. data/spec/models/spree/payment_spec.rb +926 -0
  98. data/spec/models/spree/preference_spec.rb +80 -0
  99. data/spec/models/spree/preferences/configuration_spec.rb +30 -0
  100. data/spec/models/spree/preferences/preferable_spec.rb +348 -0
  101. data/spec/models/spree/preferences/scoped_store_spec.rb +58 -0
  102. data/spec/models/spree/preferences/store_spec.rb +46 -0
  103. data/spec/models/spree/price_spec.rb +42 -0
  104. data/spec/models/spree/product/scopes_spec.rb +148 -0
  105. data/spec/models/spree/product_duplicator_spec.rb +103 -0
  106. data/spec/models/spree/product_filter_spec.rb +26 -0
  107. data/spec/models/spree/product_option_type_spec.rb +5 -0
  108. data/spec/models/spree/product_property_spec.rb +11 -0
  109. data/spec/models/spree/product_spec.rb +474 -0
  110. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +50 -0
  111. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +148 -0
  112. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +86 -0
  113. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +36 -0
  114. data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
  115. data/spec/models/spree/promotion/rules/item_total_spec.rb +282 -0
  116. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
  117. data/spec/models/spree/promotion/rules/option_value_spec.rb +90 -0
  118. data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
  119. data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
  120. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
  121. data/spec/models/spree/promotion/rules/user_spec.rb +37 -0
  122. data/spec/models/spree/promotion_action_spec.rb +10 -0
  123. data/spec/models/spree/promotion_category_spec.rb +17 -0
  124. data/spec/models/spree/promotion_handler/cart_spec.rb +102 -0
  125. data/spec/models/spree/promotion_handler/coupon_spec.rb +323 -0
  126. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +48 -0
  127. data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
  128. data/spec/models/spree/promotion_rule_spec.rb +29 -0
  129. data/spec/models/spree/promotion_spec.rb +603 -0
  130. data/spec/models/spree/property_spec.rb +5 -0
  131. data/spec/models/spree/prototype_spec.rb +5 -0
  132. data/spec/models/spree/refund_spec.rb +195 -0
  133. data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
  134. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
  135. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
  136. data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
  137. data/spec/models/spree/reimbursement_spec.rb +215 -0
  138. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +51 -0
  139. data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
  140. data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
  141. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +55 -0
  142. data/spec/models/spree/return_authorization_spec.rb +250 -0
  143. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
  144. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
  145. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +61 -0
  146. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
  147. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
  148. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
  149. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
  150. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
  151. data/spec/models/spree/return_item_spec.rb +682 -0
  152. data/spec/models/spree/returns_calculator_spec.rb +14 -0
  153. data/spec/models/spree/shipment_spec.rb +740 -0
  154. data/spec/models/spree/shipping_calculator_spec.rb +45 -0
  155. data/spec/models/spree/shipping_category_spec.rb +5 -0
  156. data/spec/models/spree/shipping_method_spec.rb +88 -0
  157. data/spec/models/spree/shipping_rate_spec.rb +141 -0
  158. data/spec/models/spree/state_spec.rb +18 -0
  159. data/spec/models/spree/stock/availability_validator_spec.rb +36 -0
  160. data/spec/models/spree/stock/content_item_spec.rb +22 -0
  161. data/spec/models/spree/stock/coordinator_spec.rb +51 -0
  162. data/spec/models/spree/stock/differentiator_spec.rb +39 -0
  163. data/spec/models/spree/stock/estimator_spec.rb +154 -0
  164. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +38 -0
  165. data/spec/models/spree/stock/package_spec.rb +194 -0
  166. data/spec/models/spree/stock/packer_spec.rb +70 -0
  167. data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
  168. data/spec/models/spree/stock/quantifier_spec.rb +97 -0
  169. data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
  170. data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
  171. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +47 -0
  172. data/spec/models/spree/stock/splitter/weight_spec.rb +32 -0
  173. data/spec/models/spree/stock_item_spec.rb +410 -0
  174. data/spec/models/spree/stock_location_spec.rb +243 -0
  175. data/spec/models/spree/stock_movement_spec.rb +56 -0
  176. data/spec/models/spree/stock_transfer_spec.rb +50 -0
  177. data/spec/models/spree/store_spec.rb +50 -0
  178. data/spec/models/spree/tax_category_spec.rb +27 -0
  179. data/spec/models/spree/tax_rate_spec.rb +382 -0
  180. data/spec/models/spree/taxon_spec.rb +74 -0
  181. data/spec/models/spree/taxonomy_spec.rb +18 -0
  182. data/spec/models/spree/tracker_spec.rb +21 -0
  183. data/spec/models/spree/user_spec.rb +130 -0
  184. data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +24 -0
  185. data/spec/models/spree/variant_spec.rb +523 -0
  186. data/spec/models/spree/zone_spec.rb +444 -0
  187. data/spec/spec_helper.rb +74 -0
  188. data/spec/support/big_decimal.rb +5 -0
  189. data/spec/support/concerns/adjustment_source_spec.rb +23 -0
  190. data/spec/support/concerns/default_price_spec.rb +28 -0
  191. data/spec/support/rake.rb +13 -0
  192. data/spec/support/test_gateway.rb +2 -0
  193. data/spree_core.gemspec +48 -0
  194. metadata +185 -4
@@ -0,0 +1,444 @@
1
+ require 'spec_helper'
2
+
3
+ describe Spree::Zone, :type => :model do
4
+ context "#match" do
5
+ let(:country_zone) { create(:zone, kind: 'country') }
6
+
7
+ let(:country) do
8
+ create(:country)
9
+ end
10
+
11
+ let(:state) do
12
+ create(:state, country: country)
13
+ end
14
+
15
+ before { country_zone.members.create(zoneable: country) }
16
+
17
+ context "when there is only one qualifying zone" do
18
+ let(:address) { create(:address, country: country, state: state) }
19
+
20
+ it "should return the qualifying zone" do
21
+ expect(Spree::Zone.match(address)).to eq(country_zone)
22
+ end
23
+ end
24
+
25
+ context "when there are two qualified zones with same member type" do
26
+ let(:address) { create(:address, country: country, state: state) }
27
+ let(:second_zone) { create(:zone, name: 'SecondZone') }
28
+
29
+ before { second_zone.members.create(zoneable: country) }
30
+
31
+ context "when both zones have the same number of members" do
32
+ it "should return the zone that was created first" do
33
+ expect(Spree::Zone.match(address)).to eq(country_zone)
34
+ end
35
+ end
36
+
37
+ context "when one of the zones has fewer members" do
38
+ let(:country2) { create(:country) }
39
+
40
+ before { country_zone.members.create(zoneable: country2) }
41
+
42
+ it "should return the zone with fewer members" do
43
+ expect(Spree::Zone.match(address)).to eq(second_zone)
44
+ end
45
+ end
46
+ end
47
+
48
+ context "when there are two qualified zones with different member types" do
49
+ let(:state_zone) { create(:zone, kind: 'state') }
50
+ let(:address) { create(:address, country: country, state: state) }
51
+
52
+ before { state_zone.members.create!(zoneable: state) }
53
+
54
+ it "should return the zone with the more specific member type" do
55
+ expect(Spree::Zone.match(address)).to eq(state_zone)
56
+ end
57
+ end
58
+
59
+ context "when there are no qualifying zones" do
60
+ it "should return nil" do
61
+ expect(Spree::Zone.match(Spree::Address.new)).to be_nil
62
+ end
63
+ end
64
+ end
65
+
66
+ context "#country_list" do
67
+ let(:state) { create(:state) }
68
+ let(:country) { state.country }
69
+
70
+ context "when zone consists of countries" do
71
+ let(:country_zone) { create(:zone, kind: 'country') }
72
+
73
+ before { country_zone.members.create(zoneable: country) }
74
+
75
+ it 'should return a list of countries' do
76
+ expect(country_zone.country_list).to eq([country])
77
+ end
78
+ end
79
+
80
+ context "when zone consists of states" do
81
+ let(:state_zone) { create(:zone, kind: 'state') }
82
+
83
+ before { state_zone.members.create(zoneable: state) }
84
+
85
+ it 'should return a list of countries' do
86
+ expect(state_zone.country_list).to eq([state.country])
87
+ end
88
+ end
89
+ end
90
+
91
+ context "#include?" do
92
+ let(:state) { create(:state) }
93
+ let(:country) { state.country }
94
+ let(:address) { create(:address, state: state) }
95
+
96
+ context "when zone is country type" do
97
+ let(:country_zone) { create(:zone, kind: 'country') }
98
+ before { country_zone.members.create(zoneable: country) }
99
+
100
+ it "should be true" do
101
+ expect(country_zone.include?(address)).to be true
102
+ end
103
+ end
104
+
105
+ context "when zone is state type" do
106
+ let(:state_zone) { create(:zone, kind: 'state') }
107
+ before { state_zone.members.create(zoneable: state) }
108
+
109
+ it "should be true" do
110
+ expect(state_zone.include?(address)).to be true
111
+ end
112
+ end
113
+ end
114
+
115
+ context ".default_tax" do
116
+ context "when there is a default tax zone specified" do
117
+ before { @foo_zone = create(:zone, name: 'whatever', default_tax: true) }
118
+
119
+ it "should be the correct zone" do
120
+ foo_zone = create(:zone, name: 'foo')
121
+ expect(Spree::Zone.default_tax).to eq(@foo_zone)
122
+ end
123
+ end
124
+
125
+ context "when there is no default tax zone specified" do
126
+ it "should be nil" do
127
+ expect(Spree::Zone.default_tax).to be_nil
128
+ end
129
+ end
130
+ end
131
+
132
+ context "#contains?" do
133
+ let(:country1) { create(:country) }
134
+ let(:country2) { create(:country) }
135
+ let(:country3) { create(:country) }
136
+
137
+ let(:state1) { create(:state) }
138
+ let(:state2) { create(:state) }
139
+ let(:state3) { create(:state) }
140
+
141
+ before do
142
+ @source = create(:zone, name: 'source', zone_members: [])
143
+ @target = create(:zone, name: 'target', zone_members: [])
144
+ end
145
+
146
+ context "when the target has no members" do
147
+ before { @source.members.create(zoneable: country1) }
148
+
149
+ it "should be false" do
150
+ expect(@source.contains?(@target)).to be false
151
+ end
152
+ end
153
+
154
+ context "when the source has no members" do
155
+ before { @target.members.create(zoneable: country1) }
156
+
157
+ it "should be false" do
158
+ expect(@source.contains?(@target)).to be false
159
+ end
160
+ end
161
+
162
+ context "when both zones are the same zone" do
163
+ before do
164
+ @source.members.create(zoneable: country1)
165
+ @target = @source
166
+ end
167
+
168
+ it "should be true" do
169
+ expect(@source.contains?(@target)).to be true
170
+ end
171
+ end
172
+
173
+ context "when checking countries against countries" do
174
+ before do
175
+ @source.members.create(zoneable: country1)
176
+ @source.members.create(zoneable: country2)
177
+ end
178
+
179
+ context "when all members are included in the zone we check against" do
180
+ before do
181
+ @target.members.create(zoneable: country1)
182
+ @target.members.create(zoneable: country2)
183
+ end
184
+
185
+ it "should be true" do
186
+ expect(@source.contains?(@target)).to be true
187
+ end
188
+ end
189
+
190
+ context "when some members are included in the zone we check against" do
191
+ before do
192
+ @target.members.create(zoneable: country1)
193
+ @target.members.create(zoneable: country2)
194
+ @target.members.create(zoneable: create(:country))
195
+ end
196
+
197
+ it "should be false" do
198
+ expect(@source.contains?(@target)).to be false
199
+ end
200
+ end
201
+
202
+ context "when none of the members are included in the zone we check against" do
203
+ before do
204
+ @target.members.create(zoneable: create(:country))
205
+ @target.members.create(zoneable: create(:country))
206
+ end
207
+
208
+ it "should be false" do
209
+ expect(@source.contains?(@target)).to be false
210
+ end
211
+ end
212
+ end
213
+
214
+
215
+ context "when checking states against states" do
216
+ before do
217
+ @source.members.create(zoneable: state1)
218
+ @source.members.create(zoneable: state2)
219
+ end
220
+
221
+ context "when all members are included in the zone we check against" do
222
+ before do
223
+ @target.members.create(zoneable: state1)
224
+ @target.members.create(zoneable: state2)
225
+ end
226
+
227
+ it "should be true" do
228
+ expect(@source.contains?(@target)).to be true
229
+ end
230
+ end
231
+
232
+ context "when some members are included in the zone we check against" do
233
+ before do
234
+ @target.members.create(zoneable: state1)
235
+ @target.members.create(zoneable: state2)
236
+ @target.members.create(zoneable: create(:state))
237
+ end
238
+
239
+ it "should be false" do
240
+ expect(@source.contains?(@target)).to be false
241
+ end
242
+ end
243
+
244
+ context "when none of the members are included in the zone we check against" do
245
+ before do
246
+ @target.members.create(zoneable: create(:state))
247
+ @target.members.create(zoneable: create(:state))
248
+ end
249
+
250
+ it "should be false" do
251
+ expect(@source.contains?(@target)).to be false
252
+ end
253
+ end
254
+ end
255
+
256
+ context "when checking country against state" do
257
+ before do
258
+ @source.members.create(zoneable: create(:state))
259
+ @target.members.create(zoneable: country1)
260
+ end
261
+
262
+ it "should be false" do
263
+ expect(@source.contains?(@target)).to be false
264
+ end
265
+ end
266
+
267
+ context "when checking state against country" do
268
+ before { @source.members.create(zoneable: country1) }
269
+
270
+ context "when all states contained in one of the countries we check against" do
271
+
272
+ before do
273
+ state1 = create(:state, country: country1)
274
+ @target.members.create(zoneable: state1)
275
+ end
276
+
277
+ it "should be true" do
278
+ expect(@source.contains?(@target)).to be true
279
+ end
280
+ end
281
+
282
+ context "when some states contained in one of the countries we check against" do
283
+ before do
284
+ state1 = create(:state, country: country1)
285
+ @target.members.create(zoneable: state1)
286
+ @target.members.create(zoneable: create(:state, country: country2))
287
+ end
288
+
289
+ it "should be false" do
290
+ expect(@source.contains?(@target)).to be false
291
+ end
292
+ end
293
+
294
+ context "when none of the states contained in any of the countries we check against" do
295
+ before do
296
+ @target.members.create(zoneable: create(:state, country: country2))
297
+ @target.members.create(zoneable: create(:state, country: country2))
298
+ end
299
+
300
+ it "should be false" do
301
+ expect(@source.contains?(@target)).to be false
302
+ end
303
+ end
304
+ end
305
+ end
306
+
307
+ context "#save" do
308
+ context "when default_tax is true" do
309
+ it "should clear previous default tax zone" do
310
+ zone1 = create(:zone, name: 'foo', default_tax: true)
311
+ zone = create(:zone, name: 'bar', default_tax: true)
312
+ expect(zone1.reload.default_tax).to be false
313
+ end
314
+ end
315
+
316
+ context "when a zone member country is added to an existing zone consisting of state members" do
317
+ it "should remove existing state members" do
318
+ zone = create(:zone, name: 'foo', zone_members: [])
319
+ state = create(:state)
320
+ country = create(:country)
321
+ zone.members.create(zoneable: state)
322
+ country_member = zone.members.create(zoneable: country)
323
+ zone.save
324
+ expect(zone.reload.members).to eq([country_member])
325
+ end
326
+ end
327
+ end
328
+
329
+ context "#kind" do
330
+ it "returns whatever value you set" do
331
+ zone = Spree::Zone.new kind: 'city'
332
+ expect(zone.kind).to eq 'city'
333
+ end
334
+
335
+ context "when the zone consists of country zone members" do
336
+ before do
337
+ @zone = create(:zone, name: 'country', zone_members: [])
338
+ @zone.members.create(zoneable: create(:country))
339
+ end
340
+
341
+ it "should return the kind of zone member" do
342
+ expect(@zone.kind).to eq("country")
343
+ end
344
+ end
345
+ end
346
+
347
+ context "#potential_matching_zones" do
348
+ let!(:country) { create(:country) }
349
+ let!(:country2) { create(:country, name: 'OtherCountry') }
350
+ let!(:country3) { create(:country, name: 'TaxCountry') }
351
+ let!(:default_tax_zone) do
352
+ create(:zone, default_tax: true).tap { |z| z.members.create(zoneable: country3) }
353
+ end
354
+
355
+ context "finding potential matches for a country zone" do
356
+ let!(:zone) do
357
+ create(:zone).tap do |z|
358
+ z.members.create(zoneable: country)
359
+ z.members.create(zoneable: country2)
360
+ z.save!
361
+ end
362
+ end
363
+ let!(:zone2) do
364
+ create(:zone).tap { |z| z.members.create(zoneable: country) && z.save! }
365
+ end
366
+
367
+ before { @result = Spree::Zone.potential_matching_zones(zone) }
368
+
369
+ it "will find all zones with countries covered by the passed in zone" do
370
+ expect(@result).to include(zone, zone2)
371
+ end
372
+
373
+ it "only returns each zone once" do
374
+ expect(@result.select { |z| z == zone }.size).to be 1
375
+ end
376
+
377
+ it "will include the default_tax zone" do
378
+ expect(@result).to include(default_tax_zone)
379
+ end
380
+ end
381
+
382
+ context "finding potential matches for a state zone" do
383
+ let!(:state) { create(:state, country: country) }
384
+ let!(:state2) { create(:state, country: country2, name: 'OtherState') }
385
+ let!(:state3) { create(:state, country: country2, name: 'State') }
386
+ let!(:zone) do
387
+ create(:zone).tap do |z|
388
+ z.members.create(zoneable: state)
389
+ z.members.create(zoneable: state2)
390
+ z.save!
391
+ end
392
+ end
393
+ let!(:zone2) do
394
+ create(:zone).tap { |z| z.members.create(zoneable: state) && z.save! }
395
+ end
396
+ let!(:zone3) do
397
+ create(:zone).tap { |z| z.members.create(zoneable: state2) && z.save! }
398
+ end
399
+
400
+ before { @result = Spree::Zone.potential_matching_zones(zone) }
401
+
402
+ it "will find all zones which share states covered by passed in zone" do
403
+ expect(@result).to include(zone, zone2)
404
+ end
405
+
406
+ it "will find zones that share countries with any states of the passed in zone" do
407
+ expect(@result).to include(zone3)
408
+ end
409
+
410
+ it "only returns each zone once" do
411
+ expect(@result.select { |z| z == zone }.size).to be 1
412
+ end
413
+
414
+ it "will include the default tax zone" do
415
+ expect(@result).to include(default_tax_zone)
416
+ end
417
+ end
418
+ end
419
+
420
+ context "state and country associations" do
421
+ let!(:country) { create(:country) }
422
+
423
+ context "has countries associated" do
424
+ let!(:zone) do
425
+ create(:zone, countries: [country])
426
+ end
427
+
428
+ it "can access associated countries" do
429
+ expect(zone.countries).to include(country)
430
+ end
431
+ end
432
+
433
+ context "has states associated" do
434
+ let!(:state) { create(:state, country: country) }
435
+ let!(:zone) do
436
+ create(:zone, states: [state])
437
+ end
438
+
439
+ it "can access associated states" do
440
+ expect(zone.states).to include(state)
441
+ end
442
+ end
443
+ end
444
+ end
@@ -0,0 +1,74 @@
1
+ if ENV["COVERAGE"]
2
+ # Run Coverage report
3
+ require 'simplecov'
4
+ SimpleCov.start do
5
+ add_group 'Controllers', 'app/controllers'
6
+ add_group 'Helpers', 'app/helpers'
7
+ add_group 'Mailers', 'app/mailers'
8
+ add_group 'Models', 'app/models'
9
+ add_group 'Views', 'app/views'
10
+ add_group 'Jobs', 'app/jobs'
11
+ add_group 'Libraries', 'lib'
12
+ end
13
+ end
14
+
15
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
16
+ # from the project root directory.
17
+ ENV["RAILS_ENV"] ||= 'test'
18
+
19
+ begin
20
+ require File.expand_path("../dummy/config/environment", __FILE__)
21
+ rescue LoadError
22
+ puts "Could not load dummy application. Please ensure you have run `bundle exec rake test_app`"
23
+ end
24
+
25
+ require 'rspec/rails'
26
+ require 'database_cleaner'
27
+ require 'ffaker'
28
+
29
+ Dir["./spec/support/**/*.rb"].sort.each { |f| require f }
30
+
31
+ if ENV["CHECK_TRANSLATIONS"]
32
+ require "spree/testing_support/i18n"
33
+ end
34
+
35
+ require 'spree/testing_support/factories'
36
+ require 'spree/testing_support/preferences'
37
+ require 'spree/testing_support/shoulda_matcher_configuration'
38
+
39
+ RSpec.configure do |config|
40
+ config.color = true
41
+ config.fail_fast = ENV['FAIL_FAST'] || false
42
+ config.fixture_path = File.join(File.expand_path(File.dirname(__FILE__)), "fixtures")
43
+ config.infer_spec_type_from_file_location!
44
+ config.mock_with :rspec
45
+ config.raise_errors_for_deprecations!
46
+
47
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
48
+ # examples within a transaction, comment the following line or assign false
49
+ # instead of true.
50
+ config.use_transactional_fixtures = true
51
+
52
+ config.before :each do
53
+ Rails.cache.clear
54
+ reset_spree_preferences
55
+ end
56
+
57
+ config.include FactoryGirl::Syntax::Methods
58
+ config.include Spree::TestingSupport::Preferences
59
+
60
+ # Clean out the database state before the tests run
61
+ config.before(:suite) do
62
+ DatabaseCleaner.clean_with(:truncation)
63
+ DatabaseCleaner.strategy = :transaction
64
+ end
65
+
66
+ # Wrap all db isolated tests in a transaction
67
+ config.around(db: :isolate) do |example|
68
+ DatabaseCleaner.cleaning(&example)
69
+ end
70
+
71
+ config.around do |example|
72
+ Timeout.timeout(30, &example)
73
+ end
74
+ end