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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -0
- data/Rakefile +30 -0
- data/app/assets/javascripts/spree.js.coffee.erb +1 -1
- data/app/models/spree/ability.rb +1 -1
- data/app/models/spree/base.rb +3 -1
- data/app/models/spree/order_updater.rb +2 -1
- data/app/models/spree/price.rb +7 -12
- data/app/models/spree/product.rb +3 -2
- data/app/models/spree/reimbursement.rb +1 -1
- data/app/models/spree/state.rb +2 -0
- data/app/models/spree/zone.rb +1 -1
- data/lib/spree/core/version.rb +1 -1
- data/lib/spree/testing_support/shoulda_matcher_configuration.rb +6 -0
- data/script/rails +9 -0
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +137 -0
- data/spec/helpers/products_helper_spec.rb +224 -0
- data/spec/lib/calculated_adjustments_spec.rb +7 -0
- data/spec/lib/i18n_spec.rb +123 -0
- data/spec/lib/search/base_spec.rb +86 -0
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +101 -0
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +95 -0
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +17 -0
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +16 -0
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +39 -0
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +22 -0
- data/spec/lib/spree/core/importer/order_spec.rb +502 -0
- data/spec/lib/spree/core/validators/email_spec.rb +53 -0
- data/spec/lib/spree/localized_number_spec.rb +38 -0
- data/spec/lib/spree/migrations_spec.rb +34 -0
- data/spec/lib/spree/money_spec.rb +122 -0
- data/spec/lib/tasks/exchanges_spec.rb +136 -0
- data/spec/mailers/order_mailer_spec.rb +124 -0
- data/spec/mailers/reimbursement_mailer_spec.rb +47 -0
- data/spec/mailers/shipment_mailer_spec.rb +63 -0
- data/spec/mailers/test_mailer_spec.rb +24 -0
- data/spec/models/spree/ability_spec.rb +246 -0
- data/spec/models/spree/address_spec.rb +291 -0
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +286 -0
- data/spec/models/spree/adjustment_spec.rb +163 -0
- data/spec/models/spree/app_configuration_spec.rb +23 -0
- data/spec/models/spree/asset_spec.rb +25 -0
- data/spec/models/spree/calculator/default_tax_spec.rb +127 -0
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +25 -0
- data/spec/models/spree/calculator/flat_rate_spec.rb +47 -0
- data/spec/models/spree/calculator/flexi_rate_spec.rb +41 -0
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +15 -0
- data/spec/models/spree/calculator/price_sack_spec.rb +30 -0
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +51 -0
- data/spec/models/spree/calculator/shipping.rb +8 -0
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +23 -0
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +13 -0
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +52 -0
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +20 -0
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +29 -0
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +40 -0
- data/spec/models/spree/calculator/tiered_percent_spec.rb +51 -0
- data/spec/models/spree/calculator_spec.rb +69 -0
- data/spec/models/spree/classification_spec.rb +93 -0
- data/spec/models/spree/concerns/display_money_spec.rb +43 -0
- data/spec/models/spree/country_spec.rb +18 -0
- data/spec/models/spree/credit_card_spec.rb +324 -0
- data/spec/models/spree/customer_return_spec.rb +262 -0
- data/spec/models/spree/exchange_spec.rb +75 -0
- data/spec/models/spree/gateway/bogus_simple.rb +20 -0
- data/spec/models/spree/gateway/bogus_spec.rb +13 -0
- data/spec/models/spree/gateway_spec.rb +54 -0
- data/spec/models/spree/image_spec.rb +5 -0
- data/spec/models/spree/inventory_unit_spec.rb +242 -0
- data/spec/models/spree/line_item_spec.rb +267 -0
- data/spec/models/spree/option_type_spec.rb +14 -0
- data/spec/models/spree/option_value_spec.rb +13 -0
- data/spec/models/spree/order/address_spec.rb +50 -0
- data/spec/models/spree/order/adjustments_spec.rb +29 -0
- data/spec/models/spree/order/callbacks_spec.rb +42 -0
- data/spec/models/spree/order/checkout_spec.rb +764 -0
- data/spec/models/spree/order/currency_updater_spec.rb +32 -0
- data/spec/models/spree/order/finalizing_spec.rb +117 -0
- data/spec/models/spree/order/helpers_spec.rb +5 -0
- data/spec/models/spree/order/payment_spec.rb +214 -0
- data/spec/models/spree/order/risk_assessment_spec.rb +84 -0
- data/spec/models/spree/order/shipments_spec.rb +43 -0
- data/spec/models/spree/order/state_machine_spec.rb +216 -0
- data/spec/models/spree/order/tax_spec.rb +84 -0
- data/spec/models/spree/order/totals_spec.rb +24 -0
- data/spec/models/spree/order/updating_spec.rb +18 -0
- data/spec/models/spree/order/validations_spec.rb +15 -0
- data/spec/models/spree/order_contents_spec.rb +256 -0
- data/spec/models/spree/order_inventory_spec.rb +228 -0
- data/spec/models/spree/order_merger_spec.rb +133 -0
- data/spec/models/spree/order_spec.rb +954 -0
- data/spec/models/spree/order_updater_spec.rb +283 -0
- data/spec/models/spree/payment/gateway_options_spec.rb +119 -0
- data/spec/models/spree/payment_method_spec.rb +95 -0
- data/spec/models/spree/payment_spec.rb +926 -0
- data/spec/models/spree/preference_spec.rb +80 -0
- data/spec/models/spree/preferences/configuration_spec.rb +30 -0
- data/spec/models/spree/preferences/preferable_spec.rb +348 -0
- data/spec/models/spree/preferences/scoped_store_spec.rb +58 -0
- data/spec/models/spree/preferences/store_spec.rb +46 -0
- data/spec/models/spree/price_spec.rb +42 -0
- data/spec/models/spree/product/scopes_spec.rb +148 -0
- data/spec/models/spree/product_duplicator_spec.rb +103 -0
- data/spec/models/spree/product_filter_spec.rb +26 -0
- data/spec/models/spree/product_option_type_spec.rb +5 -0
- data/spec/models/spree/product_property_spec.rb +11 -0
- data/spec/models/spree/product_spec.rb +474 -0
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +50 -0
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +148 -0
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +86 -0
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +36 -0
- data/spec/models/spree/promotion/rules/first_order_spec.rb +75 -0
- data/spec/models/spree/promotion/rules/item_total_spec.rb +282 -0
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +42 -0
- data/spec/models/spree/promotion/rules/option_value_spec.rb +90 -0
- data/spec/models/spree/promotion/rules/product_spec.rb +143 -0
- data/spec/models/spree/promotion/rules/taxon_spec.rb +102 -0
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +27 -0
- data/spec/models/spree/promotion/rules/user_spec.rb +37 -0
- data/spec/models/spree/promotion_action_spec.rb +10 -0
- data/spec/models/spree/promotion_category_spec.rb +17 -0
- data/spec/models/spree/promotion_handler/cart_spec.rb +102 -0
- data/spec/models/spree/promotion_handler/coupon_spec.rb +323 -0
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +48 -0
- data/spec/models/spree/promotion_handler/page_spec.rb +44 -0
- data/spec/models/spree/promotion_rule_spec.rb +29 -0
- data/spec/models/spree/promotion_spec.rb +603 -0
- data/spec/models/spree/property_spec.rb +5 -0
- data/spec/models/spree/prototype_spec.rb +5 -0
- data/spec/models/spree/refund_spec.rb +195 -0
- data/spec/models/spree/reimbursement/credit_spec.rb +36 -0
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +140 -0
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +83 -0
- data/spec/models/spree/reimbursement_performer_spec.rb +30 -0
- data/spec/models/spree/reimbursement_spec.rb +215 -0
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +51 -0
- data/spec/models/spree/reimbursement_type/credit_spec.rb +53 -0
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +46 -0
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +55 -0
- data/spec/models/spree/return_authorization_spec.rb +250 -0
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +77 -0
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +58 -0
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +61 -0
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +32 -0
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +29 -0
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +35 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +65 -0
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +43 -0
- data/spec/models/spree/return_item_spec.rb +682 -0
- data/spec/models/spree/returns_calculator_spec.rb +14 -0
- data/spec/models/spree/shipment_spec.rb +740 -0
- data/spec/models/spree/shipping_calculator_spec.rb +45 -0
- data/spec/models/spree/shipping_category_spec.rb +5 -0
- data/spec/models/spree/shipping_method_spec.rb +88 -0
- data/spec/models/spree/shipping_rate_spec.rb +141 -0
- data/spec/models/spree/state_spec.rb +18 -0
- data/spec/models/spree/stock/availability_validator_spec.rb +36 -0
- data/spec/models/spree/stock/content_item_spec.rb +22 -0
- data/spec/models/spree/stock/coordinator_spec.rb +51 -0
- data/spec/models/spree/stock/differentiator_spec.rb +39 -0
- data/spec/models/spree/stock/estimator_spec.rb +154 -0
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +38 -0
- data/spec/models/spree/stock/package_spec.rb +194 -0
- data/spec/models/spree/stock/packer_spec.rb +70 -0
- data/spec/models/spree/stock/prioritizer_spec.rb +125 -0
- data/spec/models/spree/stock/quantifier_spec.rb +97 -0
- data/spec/models/spree/stock/splitter/backordered_spec.rb +29 -0
- data/spec/models/spree/stock/splitter/base_spec.rb +21 -0
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +47 -0
- data/spec/models/spree/stock/splitter/weight_spec.rb +32 -0
- data/spec/models/spree/stock_item_spec.rb +410 -0
- data/spec/models/spree/stock_location_spec.rb +243 -0
- data/spec/models/spree/stock_movement_spec.rb +56 -0
- data/spec/models/spree/stock_transfer_spec.rb +50 -0
- data/spec/models/spree/store_spec.rb +50 -0
- data/spec/models/spree/tax_category_spec.rb +27 -0
- data/spec/models/spree/tax_rate_spec.rb +382 -0
- data/spec/models/spree/taxon_spec.rb +74 -0
- data/spec/models/spree/taxonomy_spec.rb +18 -0
- data/spec/models/spree/tracker_spec.rb +21 -0
- data/spec/models/spree/user_spec.rb +130 -0
- data/spec/models/spree/validations/db_maximum_length_validator_spec.rb +24 -0
- data/spec/models/spree/variant_spec.rb +523 -0
- data/spec/models/spree/zone_spec.rb +444 -0
- data/spec/spec_helper.rb +74 -0
- data/spec/support/big_decimal.rb +5 -0
- data/spec/support/concerns/adjustment_source_spec.rb +23 -0
- data/spec/support/concerns/default_price_spec.rb +28 -0
- data/spec/support/rake.rb +13 -0
- data/spec/support/test_gateway.rb +2 -0
- data/spree_core.gemspec +48 -0
- 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
|
data/spec/spec_helper.rb
ADDED
@@ -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
|