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.
- checksums.yaml +4 -4
- data/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +1 -1
- metadata +3 -206
- data/spec/fixtures/microdata.html +0 -22
- data/spec/fixtures/microdata_itemref.html +0 -15
- data/spec/fixtures/microdata_no_itemscope.html +0 -20
- data/spec/fixtures/thinking-cat.jpg +0 -0
- data/spec/helpers/base_helper_spec.rb +0 -200
- data/spec/helpers/products_helper_spec.rb +0 -289
- data/spec/lib/calculated_adjustments_spec.rb +0 -7
- data/spec/lib/i18n_spec.rb +0 -123
- data/spec/lib/search/base_spec.rb +0 -86
- data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
- data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
- data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
- data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
- data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
- data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
- data/spec/lib/spree/core/importer/order_spec.rb +0 -605
- data/spec/lib/spree/core/number_generator_spec.rb +0 -175
- data/spec/lib/spree/core/token_generator_spec.rb +0 -24
- data/spec/lib/spree/core/validators/email_spec.rb +0 -53
- data/spec/lib/spree/core_spec.rb +0 -23
- data/spec/lib/spree/localized_number_spec.rb +0 -48
- data/spec/lib/spree/migrations_spec.rb +0 -36
- data/spec/lib/spree/money_spec.rb +0 -122
- data/spec/lib/tasks/exchanges_spec.rb +0 -136
- data/spec/mailers/order_mailer_spec.rb +0 -122
- data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
- data/spec/mailers/shipment_mailer_spec.rb +0 -81
- data/spec/mailers/test_mailer_spec.rb +0 -38
- data/spec/models/option_type_prototype_spec.rb +0 -9
- data/spec/models/spree/ability_spec.rb +0 -251
- data/spec/models/spree/address_spec.rb +0 -402
- data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
- data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
- data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
- data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
- data/spec/models/spree/adjustment_spec.rb +0 -189
- data/spec/models/spree/app_configuration_spec.rb +0 -26
- data/spec/models/spree/asset_spec.rb +0 -28
- data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
- data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
- data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
- data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
- data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
- data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
- data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
- data/spec/models/spree/calculator/shipping.rb +0 -8
- data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
- data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
- data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
- data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
- data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
- data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
- data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
- data/spec/models/spree/calculator_spec.rb +0 -69
- data/spec/models/spree/classification_spec.rb +0 -93
- data/spec/models/spree/concerns/display_money_spec.rb +0 -43
- data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
- data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
- data/spec/models/spree/country_spec.rb +0 -55
- data/spec/models/spree/credit_card_spec.rb +0 -328
- data/spec/models/spree/customer_return_spec.rb +0 -240
- data/spec/models/spree/exchange_spec.rb +0 -75
- data/spec/models/spree/gateway/bogus_simple.rb +0 -20
- data/spec/models/spree/gateway/bogus_spec.rb +0 -13
- data/spec/models/spree/gateway_spec.rb +0 -61
- data/spec/models/spree/image_spec.rb +0 -8
- data/spec/models/spree/inventory_unit_spec.rb +0 -256
- data/spec/models/spree/line_item_spec.rb +0 -346
- data/spec/models/spree/option_type_spec.rb +0 -14
- data/spec/models/spree/option_value_spec.rb +0 -18
- data/spec/models/spree/order/address_spec.rb +0 -50
- data/spec/models/spree/order/adjustments_spec.rb +0 -29
- data/spec/models/spree/order/callbacks_spec.rb +0 -42
- data/spec/models/spree/order/checkout_spec.rb +0 -770
- data/spec/models/spree/order/currency_updater_spec.rb +0 -32
- data/spec/models/spree/order/finalizing_spec.rb +0 -114
- data/spec/models/spree/order/helpers_spec.rb +0 -5
- data/spec/models/spree/order/payment_spec.rb +0 -214
- data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
- data/spec/models/spree/order/shipments_spec.rb +0 -43
- data/spec/models/spree/order/state_machine_spec.rb +0 -212
- data/spec/models/spree/order/store_credit_spec.rb +0 -426
- data/spec/models/spree/order/tax_spec.rb +0 -84
- data/spec/models/spree/order/totals_spec.rb +0 -24
- data/spec/models/spree/order/updating_spec.rb +0 -18
- data/spec/models/spree/order/validations_spec.rb +0 -15
- data/spec/models/spree/order_contents_spec.rb +0 -297
- data/spec/models/spree/order_inventory_spec.rb +0 -239
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -1046
- data/spec/models/spree/order_updater_spec.rb +0 -305
- data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
- data/spec/models/spree/payment/store_credit_spec.rb +0 -60
- data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
- data/spec/models/spree/payment_method_spec.rb +0 -103
- data/spec/models/spree/payment_spec.rb +0 -919
- data/spec/models/spree/preference_spec.rb +0 -80
- data/spec/models/spree/preferences/configuration_spec.rb +0 -30
- data/spec/models/spree/preferences/preferable_spec.rb +0 -344
- data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
- data/spec/models/spree/preferences/store_spec.rb +0 -46
- data/spec/models/spree/price_spec.rb +0 -128
- data/spec/models/spree/product/scopes_spec.rb +0 -183
- data/spec/models/spree/product_duplicator_spec.rb +0 -103
- data/spec/models/spree/product_filter_spec.rb +0 -26
- data/spec/models/spree/product_option_type_spec.rb +0 -9
- data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
- data/spec/models/spree/product_property_spec.rb +0 -26
- data/spec/models/spree/product_spec.rb +0 -629
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
- data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
- data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
- data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
- data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
- data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
- data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
- data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
- data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
- data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
- data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
- data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
- data/spec/models/spree/promotion_action_spec.rb +0 -10
- data/spec/models/spree/promotion_category_spec.rb +0 -17
- data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
- data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
- data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
- data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
- data/spec/models/spree/promotion_rule_spec.rb +0 -29
- data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
- data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
- data/spec/models/spree/promotion_spec.rb +0 -679
- data/spec/models/spree/property_prototype_spec.rb +0 -9
- data/spec/models/spree/property_spec.rb +0 -5
- data/spec/models/spree/prototype_spec.rb +0 -5
- data/spec/models/spree/prototype_taxon_spec.rb +0 -9
- data/spec/models/spree/refund_reason_spec.rb +0 -20
- data/spec/models/spree/refund_spec.rb +0 -195
- data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
- data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
- data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
- data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
- data/spec/models/spree/reimbursement_spec.rb +0 -188
- data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
- data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
- data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
- data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
- data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
- data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
- data/spec/models/spree/return_authorization_spec.rb +0 -230
- data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
- data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
- data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
- data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
- data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
- data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
- data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
- data/spec/models/spree/return_item_spec.rb +0 -731
- data/spec/models/spree/returns_calculator_spec.rb +0 -14
- data/spec/models/spree/role_spec.rb +0 -7
- data/spec/models/spree/shipment_spec.rb +0 -742
- data/spec/models/spree/shipping_calculator_spec.rb +0 -45
- data/spec/models/spree/shipping_category_spec.rb +0 -19
- data/spec/models/spree/shipping_method_spec.rb +0 -95
- data/spec/models/spree/shipping_rate_spec.rb +0 -140
- data/spec/models/spree/state_spec.rb +0 -29
- data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
- data/spec/models/spree/stock/content_item_spec.rb +0 -31
- data/spec/models/spree/stock/coordinator_spec.rb +0 -61
- data/spec/models/spree/stock/differentiator_spec.rb +0 -39
- data/spec/models/spree/stock/estimator_spec.rb +0 -202
- data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
- data/spec/models/spree/stock/package_spec.rb +0 -182
- data/spec/models/spree/stock/packer_spec.rb +0 -70
- data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
- data/spec/models/spree/stock/quantifier_spec.rb +0 -126
- data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
- data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
- data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
- data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
- data/spec/models/spree/stock_item_spec.rb +0 -432
- data/spec/models/spree/stock_location_spec.rb +0 -243
- data/spec/models/spree/stock_movement_spec.rb +0 -120
- data/spec/models/spree/stock_transfer_spec.rb +0 -50
- data/spec/models/spree/store_credit_event_spec.rb +0 -101
- data/spec/models/spree/store_credit_spec.rb +0 -786
- data/spec/models/spree/store_spec.rb +0 -78
- data/spec/models/spree/tax_category_spec.rb +0 -32
- data/spec/models/spree/tax_rate_spec.rb +0 -561
- data/spec/models/spree/taxon_spec.rb +0 -85
- data/spec/models/spree/taxonomy_spec.rb +0 -18
- data/spec/models/spree/tracker_spec.rb +0 -21
- data/spec/models/spree/user_spec.rb +0 -203
- data/spec/models/spree/variant_spec.rb +0 -818
- data/spec/models/spree/zone_member_spec.rb +0 -38
- data/spec/models/spree/zone_spec.rb +0 -472
- data/spec/spec_helper.rb +0 -79
- data/spec/support/big_decimal.rb +0 -5
- data/spec/support/concerns/adjustment_source.rb +0 -23
- data/spec/support/concerns/default_price.rb +0 -37
- data/spec/support/rake.rb +0 -13
- data/spec/support/test_gateway.rb +0 -2
@@ -1,38 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Spree::ZoneMember, type: :model do
|
4
|
-
let(:country) { create(:country) }
|
5
|
-
let(:state) { create(:state) }
|
6
|
-
let(:zone) { create(:zone, kind: 'country') }
|
7
|
-
let(:zone_member) { create(:zone_member, zone: zone, zoneable: country) }
|
8
|
-
|
9
|
-
describe 'associations' do
|
10
|
-
it { is_expected.to belong_to(:zoneable) }
|
11
|
-
it { is_expected.to belong_to(:zone).counter_cache(true).inverse_of(:zone_members) }
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'validations' do
|
15
|
-
it { is_expected.to validate_presence_of(:zone) }
|
16
|
-
it { is_expected.to validate_presence_of(:zoneable) }
|
17
|
-
end
|
18
|
-
|
19
|
-
describe 'scopes' do
|
20
|
-
describe '.defunct_without_kind' do
|
21
|
-
let(:defunct_without_kind) { Spree::ZoneMember.defunct_without_kind('country') }
|
22
|
-
|
23
|
-
context 'zoneable is present and is of defunct kind' do
|
24
|
-
it { expect(defunct_without_kind).to_not include(zone_member) }
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'zoneable is not of defunct kind' do
|
28
|
-
before { zone_member.update(zoneable: state) }
|
29
|
-
it { expect(defunct_without_kind).to include(zone_member) }
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'zoneable is absent' do
|
33
|
-
before { zone_member.update_column(:zoneable_id, nil) }
|
34
|
-
it { expect(defunct_without_kind).to include(zone_member) }
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
@@ -1,472 +0,0 @@
|
|
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
|
-
it { is_expected.to have_many(:shipping_methods).through(:shipping_method_zones).class_name('Spree::ShippingMethod') }
|
16
|
-
|
17
|
-
before { country_zone.members.create(zoneable: country) }
|
18
|
-
|
19
|
-
describe 'scopes' do
|
20
|
-
describe '.remove_previous_default' do
|
21
|
-
let(:zone_with_default_tax) { create(:zone, kind: 'country', default_tax: true) }
|
22
|
-
let(:zone_not_with_default_tax) { create(:zone, kind: 'country', default_tax: false) }
|
23
|
-
|
24
|
-
subject { Spree::Zone.with_default_tax }
|
25
|
-
|
26
|
-
it 'is expected to include zone with default tax' do
|
27
|
-
is_expected.to include(zone_with_default_tax)
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'is expected to not include zone with default tax' do
|
31
|
-
is_expected.to_not include(zone_not_with_default_tax)
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe 'callbacks' do
|
37
|
-
it { is_expected.to callback(:remove_previous_default).after(:save).if(:default_tax?).if(:default_tax_changed?) }
|
38
|
-
|
39
|
-
describe '#remove_previous_default' do
|
40
|
-
let!(:zone_with_default_tax) { create(:zone, kind: 'country', default_tax: true) }
|
41
|
-
let!(:zone_not_with_default_tax) { create(:zone, kind: 'country', default_tax: false) }
|
42
|
-
|
43
|
-
it 'is expected to make previous default tax zones to non default tax zones' do
|
44
|
-
expect(zone_with_default_tax).to be_default_tax
|
45
|
-
zone_not_with_default_tax.update(default_tax: true)
|
46
|
-
expect(zone_with_default_tax.reload).to_not be_default_tax
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
context "when there is only one qualifying zone" do
|
52
|
-
let(:address) { create(:address, country: country, state: state) }
|
53
|
-
|
54
|
-
it "should return the qualifying zone" do
|
55
|
-
expect(Spree::Zone.match(address)).to eq(country_zone)
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
context "when there are two qualified zones with same member type" do
|
60
|
-
let(:address) { create(:address, country: country, state: state) }
|
61
|
-
let(:second_zone) { create(:zone, name: 'SecondZone') }
|
62
|
-
|
63
|
-
before { second_zone.members.create(zoneable: country) }
|
64
|
-
|
65
|
-
context "when both zones have the same number of members" do
|
66
|
-
it "should return the zone that was created first" do
|
67
|
-
Timecop.scale(100) do
|
68
|
-
expect(Spree::Zone.match(address)).to eq(country_zone)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
context "when one of the zones has fewer members" do
|
74
|
-
let(:country2) { create(:country) }
|
75
|
-
|
76
|
-
before { country_zone.members.create(zoneable: country2) }
|
77
|
-
|
78
|
-
it "should return the zone with fewer members" do
|
79
|
-
expect(Spree::Zone.match(address)).to eq(second_zone)
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
context "when there are two qualified zones with different member types" do
|
85
|
-
let(:state_zone) { create(:zone, kind: 'state') }
|
86
|
-
let(:address) { create(:address, country: country, state: state) }
|
87
|
-
|
88
|
-
before { state_zone.members.create!(zoneable: state) }
|
89
|
-
|
90
|
-
it "should return the zone with the more specific member type" do
|
91
|
-
expect(Spree::Zone.match(address)).to eq(state_zone)
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
context "when there are no qualifying zones" do
|
96
|
-
it "should return nil" do
|
97
|
-
expect(Spree::Zone.match(Spree::Address.new)).to be_nil
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
|
102
|
-
context "#country_list" do
|
103
|
-
let(:state) { create(:state) }
|
104
|
-
let(:country) { state.country }
|
105
|
-
|
106
|
-
context "when zone consists of countries" do
|
107
|
-
let(:country_zone) { create(:zone, kind: 'country') }
|
108
|
-
|
109
|
-
before { country_zone.members.create(zoneable: country) }
|
110
|
-
|
111
|
-
it 'should return a list of countries' do
|
112
|
-
expect(country_zone.country_list).to eq([country])
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
context "when zone consists of states" do
|
117
|
-
let(:state_zone) { create(:zone, kind: 'state') }
|
118
|
-
|
119
|
-
before { state_zone.members.create(zoneable: state) }
|
120
|
-
|
121
|
-
it 'should return a list of countries' do
|
122
|
-
expect(state_zone.country_list).to eq([state.country])
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
context "#include?" do
|
128
|
-
let(:state) { create(:state) }
|
129
|
-
let(:country) { state.country }
|
130
|
-
let(:address) { create(:address, state: state) }
|
131
|
-
|
132
|
-
context "when zone is country type" do
|
133
|
-
let(:country_zone) { create(:zone, kind: 'country') }
|
134
|
-
before { country_zone.members.create(zoneable: country) }
|
135
|
-
|
136
|
-
it "should be true" do
|
137
|
-
expect(country_zone.include?(address)).to be true
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
|
-
context "when zone is state type" do
|
142
|
-
let(:state_zone) { create(:zone, kind: 'state') }
|
143
|
-
before { state_zone.members.create(zoneable: state) }
|
144
|
-
|
145
|
-
it "should be true" do
|
146
|
-
expect(state_zone.include?(address)).to be true
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
context ".default_tax" do
|
152
|
-
context "when there is a default tax zone specified" do
|
153
|
-
before { @foo_zone = create(:zone, name: 'whatever', default_tax: true) }
|
154
|
-
|
155
|
-
it "should be the correct zone" do
|
156
|
-
foo_zone = create(:zone, name: 'foo')
|
157
|
-
expect(Spree::Zone.default_tax).to eq(@foo_zone)
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
context "when there is no default tax zone specified" do
|
162
|
-
it "should be nil" do
|
163
|
-
expect(Spree::Zone.default_tax).to be_nil
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
|
168
|
-
context "#contains?" do
|
169
|
-
let(:country1) { create(:country) }
|
170
|
-
let(:country2) { create(:country) }
|
171
|
-
let(:country3) { create(:country) }
|
172
|
-
|
173
|
-
let(:state1) { create(:state) }
|
174
|
-
let(:state2) { create(:state) }
|
175
|
-
let(:state3) { create(:state) }
|
176
|
-
|
177
|
-
before do
|
178
|
-
@source = create(:zone, name: 'source', zone_members: [])
|
179
|
-
@target = create(:zone, name: 'target', zone_members: [])
|
180
|
-
end
|
181
|
-
|
182
|
-
context "when the target has no members" do
|
183
|
-
before { @source.members.create(zoneable: country1) }
|
184
|
-
|
185
|
-
it "should be false" do
|
186
|
-
expect(@source.contains?(@target)).to be false
|
187
|
-
end
|
188
|
-
end
|
189
|
-
|
190
|
-
context "when the source has no members" do
|
191
|
-
before { @target.members.create(zoneable: country1) }
|
192
|
-
|
193
|
-
it "should be false" do
|
194
|
-
expect(@source.contains?(@target)).to be false
|
195
|
-
end
|
196
|
-
end
|
197
|
-
|
198
|
-
context "when both zones are the same zone" do
|
199
|
-
before do
|
200
|
-
@source.members.create(zoneable: country1)
|
201
|
-
@target = @source
|
202
|
-
end
|
203
|
-
|
204
|
-
it "should be true" do
|
205
|
-
expect(@source.contains?(@target)).to be true
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
context "when checking countries against countries" do
|
210
|
-
before do
|
211
|
-
@source.members.create(zoneable: country1)
|
212
|
-
@source.members.create(zoneable: country2)
|
213
|
-
end
|
214
|
-
|
215
|
-
context "when all members are included in the zone we check against" do
|
216
|
-
before do
|
217
|
-
@target.members.create(zoneable: country1)
|
218
|
-
@target.members.create(zoneable: country2)
|
219
|
-
end
|
220
|
-
|
221
|
-
it "should be true" do
|
222
|
-
expect(@source.contains?(@target)).to be true
|
223
|
-
end
|
224
|
-
end
|
225
|
-
|
226
|
-
context "when some members are included in the zone we check against" do
|
227
|
-
before do
|
228
|
-
@target.members.create(zoneable: country1)
|
229
|
-
@target.members.create(zoneable: country2)
|
230
|
-
@target.members.create(zoneable: create(:country))
|
231
|
-
end
|
232
|
-
|
233
|
-
it "should be false" do
|
234
|
-
expect(@source.contains?(@target)).to be false
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
238
|
-
context "when none of the members are included in the zone we check against" do
|
239
|
-
before do
|
240
|
-
@target.members.create(zoneable: create(:country))
|
241
|
-
@target.members.create(zoneable: create(:country))
|
242
|
-
end
|
243
|
-
|
244
|
-
it "should be false" do
|
245
|
-
expect(@source.contains?(@target)).to be false
|
246
|
-
end
|
247
|
-
end
|
248
|
-
end
|
249
|
-
|
250
|
-
|
251
|
-
context "when checking states against states" do
|
252
|
-
before do
|
253
|
-
@source.members.create(zoneable: state1)
|
254
|
-
@source.members.create(zoneable: state2)
|
255
|
-
end
|
256
|
-
|
257
|
-
context "when all members are included in the zone we check against" do
|
258
|
-
before do
|
259
|
-
@target.members.create(zoneable: state1)
|
260
|
-
@target.members.create(zoneable: state2)
|
261
|
-
end
|
262
|
-
|
263
|
-
it "should be true" do
|
264
|
-
expect(@source.contains?(@target)).to be true
|
265
|
-
end
|
266
|
-
end
|
267
|
-
|
268
|
-
context "when some members are included in the zone we check against" do
|
269
|
-
before do
|
270
|
-
@target.members.create(zoneable: state1)
|
271
|
-
@target.members.create(zoneable: state2)
|
272
|
-
@target.members.create(zoneable: create(:state))
|
273
|
-
end
|
274
|
-
|
275
|
-
it "should be false" do
|
276
|
-
expect(@source.contains?(@target)).to be false
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
context "when none of the members are included in the zone we check against" do
|
281
|
-
before do
|
282
|
-
@target.members.create(zoneable: create(:state))
|
283
|
-
@target.members.create(zoneable: create(:state))
|
284
|
-
end
|
285
|
-
|
286
|
-
it "should be false" do
|
287
|
-
expect(@source.contains?(@target)).to be false
|
288
|
-
end
|
289
|
-
end
|
290
|
-
end
|
291
|
-
|
292
|
-
context "when checking country against state" do
|
293
|
-
before do
|
294
|
-
@source.members.create(zoneable: create(:state))
|
295
|
-
@target.members.create(zoneable: country1)
|
296
|
-
end
|
297
|
-
|
298
|
-
it "should be false" do
|
299
|
-
expect(@source.contains?(@target)).to be false
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
context "when checking state against country" do
|
304
|
-
before { @source.members.create(zoneable: country1) }
|
305
|
-
|
306
|
-
context "when all states contained in one of the countries we check against" do
|
307
|
-
|
308
|
-
before do
|
309
|
-
state1 = create(:state, country: country1)
|
310
|
-
@target.members.create(zoneable: state1)
|
311
|
-
end
|
312
|
-
|
313
|
-
it "should be true" do
|
314
|
-
expect(@source.contains?(@target)).to be true
|
315
|
-
end
|
316
|
-
end
|
317
|
-
|
318
|
-
context "when some states contained in one of the countries we check against" do
|
319
|
-
before do
|
320
|
-
state1 = create(:state, country: country1)
|
321
|
-
@target.members.create(zoneable: state1)
|
322
|
-
@target.members.create(zoneable: create(:state, country: country2))
|
323
|
-
end
|
324
|
-
|
325
|
-
it "should be false" do
|
326
|
-
expect(@source.contains?(@target)).to be false
|
327
|
-
end
|
328
|
-
end
|
329
|
-
|
330
|
-
context "when none of the states contained in any of the countries we check against" do
|
331
|
-
before do
|
332
|
-
@target.members.create(zoneable: create(:state, country: country2))
|
333
|
-
@target.members.create(zoneable: create(:state, country: country2))
|
334
|
-
end
|
335
|
-
|
336
|
-
it "should be false" do
|
337
|
-
expect(@source.contains?(@target)).to be false
|
338
|
-
end
|
339
|
-
end
|
340
|
-
end
|
341
|
-
end
|
342
|
-
|
343
|
-
context "#save" do
|
344
|
-
context "when default_tax is true" do
|
345
|
-
it "should clear previous default tax zone" do
|
346
|
-
zone1 = create(:zone, name: 'foo', default_tax: true)
|
347
|
-
zone = create(:zone, name: 'bar', default_tax: true)
|
348
|
-
expect(zone1.reload.default_tax).to be false
|
349
|
-
end
|
350
|
-
end
|
351
|
-
|
352
|
-
context "when a zone member country is added to an existing zone consisting of state members" do
|
353
|
-
it "should remove existing state members" do
|
354
|
-
zone = create(:zone, name: 'foo', zone_members: [])
|
355
|
-
state = create(:state)
|
356
|
-
country = create(:country)
|
357
|
-
zone.members.create(zoneable: state)
|
358
|
-
country_member = zone.members.create(zoneable: country)
|
359
|
-
zone.save
|
360
|
-
expect(zone.reload.members).to eq([country_member])
|
361
|
-
end
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
context "#kind" do
|
366
|
-
it "returns whatever value you set" do
|
367
|
-
zone = Spree::Zone.new kind: 'city'
|
368
|
-
expect(zone.kind).to eq 'city'
|
369
|
-
end
|
370
|
-
|
371
|
-
context "when the zone consists of country zone members" do
|
372
|
-
before do
|
373
|
-
@zone = create(:zone, name: 'country', zone_members: [])
|
374
|
-
@zone.members.create(zoneable: create(:country))
|
375
|
-
end
|
376
|
-
|
377
|
-
it "should return the kind of zone member" do
|
378
|
-
expect(@zone.kind).to eq("country")
|
379
|
-
end
|
380
|
-
end
|
381
|
-
end
|
382
|
-
|
383
|
-
context "#potential_matching_zones" do
|
384
|
-
let!(:country) { create(:country) }
|
385
|
-
let!(:country2) { create(:country, name: 'OtherCountry') }
|
386
|
-
let!(:country3) { create(:country, name: 'TaxCountry') }
|
387
|
-
let!(:default_tax_zone) do
|
388
|
-
create(:zone, default_tax: true).tap { |z| z.members.create(zoneable: country3) }
|
389
|
-
end
|
390
|
-
|
391
|
-
context "finding potential matches for a country zone" do
|
392
|
-
let!(:zone) do
|
393
|
-
create(:zone).tap do |z|
|
394
|
-
z.members.create(zoneable: country)
|
395
|
-
z.members.create(zoneable: country2)
|
396
|
-
z.save!
|
397
|
-
end
|
398
|
-
end
|
399
|
-
let!(:zone2) do
|
400
|
-
create(:zone).tap { |z| z.members.create(zoneable: country) && z.save! }
|
401
|
-
end
|
402
|
-
|
403
|
-
before { @result = Spree::Zone.potential_matching_zones(zone) }
|
404
|
-
|
405
|
-
it "will find all zones with countries covered by the passed in zone" do
|
406
|
-
expect(@result).to include(zone, zone2)
|
407
|
-
end
|
408
|
-
|
409
|
-
it "only returns each zone once" do
|
410
|
-
expect(@result.select { |z| z == zone }.size).to be 1
|
411
|
-
end
|
412
|
-
end
|
413
|
-
|
414
|
-
context "finding potential matches for a state zone" do
|
415
|
-
let!(:state) { create(:state, country: country) }
|
416
|
-
let!(:state2) { create(:state, country: country2, name: 'OtherState') }
|
417
|
-
let!(:state3) { create(:state, country: country2, name: 'State') }
|
418
|
-
let!(:zone) do
|
419
|
-
create(:zone).tap do |z|
|
420
|
-
z.members.create(zoneable: state)
|
421
|
-
z.members.create(zoneable: state2)
|
422
|
-
z.save!
|
423
|
-
end
|
424
|
-
end
|
425
|
-
let!(:zone2) do
|
426
|
-
create(:zone).tap { |z| z.members.create(zoneable: state) && z.save! }
|
427
|
-
end
|
428
|
-
let!(:zone3) do
|
429
|
-
create(:zone).tap { |z| z.members.create(zoneable: state2) && z.save! }
|
430
|
-
end
|
431
|
-
|
432
|
-
before { @result = Spree::Zone.potential_matching_zones(zone) }
|
433
|
-
|
434
|
-
it "will find all zones which share states covered by passed in zone" do
|
435
|
-
expect(@result).to include(zone, zone2)
|
436
|
-
end
|
437
|
-
|
438
|
-
it "will find zones that share countries with any states of the passed in zone" do
|
439
|
-
expect(@result).to include(zone3)
|
440
|
-
end
|
441
|
-
|
442
|
-
it "only returns each zone once" do
|
443
|
-
expect(@result.select { |z| z == zone }.size).to be 1
|
444
|
-
end
|
445
|
-
end
|
446
|
-
end
|
447
|
-
|
448
|
-
context "state and country associations" do
|
449
|
-
let!(:country) { create(:country) }
|
450
|
-
|
451
|
-
context "has countries associated" do
|
452
|
-
let!(:zone) do
|
453
|
-
create(:zone, countries: [country])
|
454
|
-
end
|
455
|
-
|
456
|
-
it "can access associated countries" do
|
457
|
-
expect(zone.countries).to include(country)
|
458
|
-
end
|
459
|
-
end
|
460
|
-
|
461
|
-
context "has states associated" do
|
462
|
-
let!(:state) { create(:state, country: country) }
|
463
|
-
let!(:zone) do
|
464
|
-
create(:zone, states: [state])
|
465
|
-
end
|
466
|
-
|
467
|
-
it "can access associated states" do
|
468
|
-
expect(zone.states).to include(state)
|
469
|
-
end
|
470
|
-
end
|
471
|
-
end
|
472
|
-
end
|