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.
- checksums.yaml +4 -4
- data/app/models/concerns/spree/ransackable_attributes.rb +6 -1
- data/app/models/concerns/spree/user_methods.rb +10 -0
- data/app/models/spree/legacy_user.rb +0 -8
- data/app/models/spree/order.rb +1 -1
- data/app/models/spree/product.rb +8 -0
- data/app/models/spree/product/scopes.rb +7 -3
- data/app/models/spree/stock_transfer.rb +1 -1
- data/config/locales/en.yml +2 -0
- data/lib/spree/core/version.rb +1 -1
- data/spree_core.gemspec +2 -2
- metadata +11 -208
- 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 -296
- 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 -291
- 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 -51
- 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 -55
- 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 -225
- data/spec/models/spree/line_item_spec.rb +0 -327
- 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 -782
- 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 -211
- 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 -238
- data/spec/models/spree/order_merger_spec.rb +0 -135
- data/spec/models/spree/order_spec.rb +0 -967
- 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 -348
- 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 -22
- data/spec/models/spree/product_spec.rb +0 -540
- data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -50
- 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/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 -644
- 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 -7
- 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 -740
- 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 -51
- 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 -194
- 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 -428
- data/spec/models/spree/stock_location_spec.rb +0 -243
- data/spec/models/spree/stock_movement_spec.rb +0 -56
- 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 -542
- data/spec/models/spree/taxon_spec.rb +0 -74
- 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 -795
- data/spec/models/spree/zone_member_spec.rb +0 -38
- data/spec/models/spree/zone_spec.rb +0 -470
- data/spec/spec_helper.rb +0 -77
- 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
- data/spec/validators/db_maximum_length_validator_spec.rb +0 -22
@@ -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,470 +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
|
-
before { country_zone.members.create(zoneable: country) }
|
16
|
-
|
17
|
-
describe 'scopes' do
|
18
|
-
describe '.remove_previous_default' do
|
19
|
-
let(:zone_with_default_tax) { create(:zone, kind: 'country', default_tax: true) }
|
20
|
-
let(:zone_not_with_default_tax) { create(:zone, kind: 'country', default_tax: false) }
|
21
|
-
|
22
|
-
subject { Spree::Zone.with_default_tax }
|
23
|
-
|
24
|
-
it 'is expected to include zone with default tax' do
|
25
|
-
is_expected.to include(zone_with_default_tax)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'is expected to not include zone with default tax' do
|
29
|
-
is_expected.to_not include(zone_not_with_default_tax)
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe 'callbacks' do
|
35
|
-
it { is_expected.to callback(:remove_previous_default).after(:save).if(:default_tax?).if(:default_tax_changed?) }
|
36
|
-
|
37
|
-
describe '#remove_previous_default' do
|
38
|
-
let!(:zone_with_default_tax) { create(:zone, kind: 'country', default_tax: true) }
|
39
|
-
let!(:zone_not_with_default_tax) { create(:zone, kind: 'country', default_tax: false) }
|
40
|
-
|
41
|
-
it 'is expected to make previous default tax zones to non default tax zones' do
|
42
|
-
expect(zone_with_default_tax).to be_default_tax
|
43
|
-
zone_not_with_default_tax.update(default_tax: true)
|
44
|
-
expect(zone_with_default_tax.reload).to_not be_default_tax
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
context "when there is only one qualifying zone" do
|
50
|
-
let(:address) { create(:address, country: country, state: state) }
|
51
|
-
|
52
|
-
it "should return the qualifying zone" do
|
53
|
-
expect(Spree::Zone.match(address)).to eq(country_zone)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
context "when there are two qualified zones with same member type" do
|
58
|
-
let(:address) { create(:address, country: country, state: state) }
|
59
|
-
let(:second_zone) { create(:zone, name: 'SecondZone') }
|
60
|
-
|
61
|
-
before { second_zone.members.create(zoneable: country) }
|
62
|
-
|
63
|
-
context "when both zones have the same number of members" do
|
64
|
-
it "should return the zone that was created first" do
|
65
|
-
Timecop.scale(100) do
|
66
|
-
expect(Spree::Zone.match(address)).to eq(country_zone)
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
context "when one of the zones has fewer members" do
|
72
|
-
let(:country2) { create(:country) }
|
73
|
-
|
74
|
-
before { country_zone.members.create(zoneable: country2) }
|
75
|
-
|
76
|
-
it "should return the zone with fewer members" do
|
77
|
-
expect(Spree::Zone.match(address)).to eq(second_zone)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
context "when there are two qualified zones with different member types" do
|
83
|
-
let(:state_zone) { create(:zone, kind: 'state') }
|
84
|
-
let(:address) { create(:address, country: country, state: state) }
|
85
|
-
|
86
|
-
before { state_zone.members.create!(zoneable: state) }
|
87
|
-
|
88
|
-
it "should return the zone with the more specific member type" do
|
89
|
-
expect(Spree::Zone.match(address)).to eq(state_zone)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
context "when there are no qualifying zones" do
|
94
|
-
it "should return nil" do
|
95
|
-
expect(Spree::Zone.match(Spree::Address.new)).to be_nil
|
96
|
-
end
|
97
|
-
end
|
98
|
-
end
|
99
|
-
|
100
|
-
context "#country_list" do
|
101
|
-
let(:state) { create(:state) }
|
102
|
-
let(:country) { state.country }
|
103
|
-
|
104
|
-
context "when zone consists of countries" do
|
105
|
-
let(:country_zone) { create(:zone, kind: 'country') }
|
106
|
-
|
107
|
-
before { country_zone.members.create(zoneable: country) }
|
108
|
-
|
109
|
-
it 'should return a list of countries' do
|
110
|
-
expect(country_zone.country_list).to eq([country])
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
context "when zone consists of states" do
|
115
|
-
let(:state_zone) { create(:zone, kind: 'state') }
|
116
|
-
|
117
|
-
before { state_zone.members.create(zoneable: state) }
|
118
|
-
|
119
|
-
it 'should return a list of countries' do
|
120
|
-
expect(state_zone.country_list).to eq([state.country])
|
121
|
-
end
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
context "#include?" do
|
126
|
-
let(:state) { create(:state) }
|
127
|
-
let(:country) { state.country }
|
128
|
-
let(:address) { create(:address, state: state) }
|
129
|
-
|
130
|
-
context "when zone is country type" do
|
131
|
-
let(:country_zone) { create(:zone, kind: 'country') }
|
132
|
-
before { country_zone.members.create(zoneable: country) }
|
133
|
-
|
134
|
-
it "should be true" do
|
135
|
-
expect(country_zone.include?(address)).to be true
|
136
|
-
end
|
137
|
-
end
|
138
|
-
|
139
|
-
context "when zone is state type" do
|
140
|
-
let(:state_zone) { create(:zone, kind: 'state') }
|
141
|
-
before { state_zone.members.create(zoneable: state) }
|
142
|
-
|
143
|
-
it "should be true" do
|
144
|
-
expect(state_zone.include?(address)).to be true
|
145
|
-
end
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
context ".default_tax" do
|
150
|
-
context "when there is a default tax zone specified" do
|
151
|
-
before { @foo_zone = create(:zone, name: 'whatever', default_tax: true) }
|
152
|
-
|
153
|
-
it "should be the correct zone" do
|
154
|
-
foo_zone = create(:zone, name: 'foo')
|
155
|
-
expect(Spree::Zone.default_tax).to eq(@foo_zone)
|
156
|
-
end
|
157
|
-
end
|
158
|
-
|
159
|
-
context "when there is no default tax zone specified" do
|
160
|
-
it "should be nil" do
|
161
|
-
expect(Spree::Zone.default_tax).to be_nil
|
162
|
-
end
|
163
|
-
end
|
164
|
-
end
|
165
|
-
|
166
|
-
context "#contains?" do
|
167
|
-
let(:country1) { create(:country) }
|
168
|
-
let(:country2) { create(:country) }
|
169
|
-
let(:country3) { create(:country) }
|
170
|
-
|
171
|
-
let(:state1) { create(:state) }
|
172
|
-
let(:state2) { create(:state) }
|
173
|
-
let(:state3) { create(:state) }
|
174
|
-
|
175
|
-
before do
|
176
|
-
@source = create(:zone, name: 'source', zone_members: [])
|
177
|
-
@target = create(:zone, name: 'target', zone_members: [])
|
178
|
-
end
|
179
|
-
|
180
|
-
context "when the target has no members" do
|
181
|
-
before { @source.members.create(zoneable: country1) }
|
182
|
-
|
183
|
-
it "should be false" do
|
184
|
-
expect(@source.contains?(@target)).to be false
|
185
|
-
end
|
186
|
-
end
|
187
|
-
|
188
|
-
context "when the source has no members" do
|
189
|
-
before { @target.members.create(zoneable: country1) }
|
190
|
-
|
191
|
-
it "should be false" do
|
192
|
-
expect(@source.contains?(@target)).to be false
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
context "when both zones are the same zone" do
|
197
|
-
before do
|
198
|
-
@source.members.create(zoneable: country1)
|
199
|
-
@target = @source
|
200
|
-
end
|
201
|
-
|
202
|
-
it "should be true" do
|
203
|
-
expect(@source.contains?(@target)).to be true
|
204
|
-
end
|
205
|
-
end
|
206
|
-
|
207
|
-
context "when checking countries against countries" do
|
208
|
-
before do
|
209
|
-
@source.members.create(zoneable: country1)
|
210
|
-
@source.members.create(zoneable: country2)
|
211
|
-
end
|
212
|
-
|
213
|
-
context "when all members are included in the zone we check against" do
|
214
|
-
before do
|
215
|
-
@target.members.create(zoneable: country1)
|
216
|
-
@target.members.create(zoneable: country2)
|
217
|
-
end
|
218
|
-
|
219
|
-
it "should be true" do
|
220
|
-
expect(@source.contains?(@target)).to be true
|
221
|
-
end
|
222
|
-
end
|
223
|
-
|
224
|
-
context "when some members are included in the zone we check against" do
|
225
|
-
before do
|
226
|
-
@target.members.create(zoneable: country1)
|
227
|
-
@target.members.create(zoneable: country2)
|
228
|
-
@target.members.create(zoneable: create(:country))
|
229
|
-
end
|
230
|
-
|
231
|
-
it "should be false" do
|
232
|
-
expect(@source.contains?(@target)).to be false
|
233
|
-
end
|
234
|
-
end
|
235
|
-
|
236
|
-
context "when none of the members are included in the zone we check against" do
|
237
|
-
before do
|
238
|
-
@target.members.create(zoneable: create(:country))
|
239
|
-
@target.members.create(zoneable: create(:country))
|
240
|
-
end
|
241
|
-
|
242
|
-
it "should be false" do
|
243
|
-
expect(@source.contains?(@target)).to be false
|
244
|
-
end
|
245
|
-
end
|
246
|
-
end
|
247
|
-
|
248
|
-
|
249
|
-
context "when checking states against states" do
|
250
|
-
before do
|
251
|
-
@source.members.create(zoneable: state1)
|
252
|
-
@source.members.create(zoneable: state2)
|
253
|
-
end
|
254
|
-
|
255
|
-
context "when all members are included in the zone we check against" do
|
256
|
-
before do
|
257
|
-
@target.members.create(zoneable: state1)
|
258
|
-
@target.members.create(zoneable: state2)
|
259
|
-
end
|
260
|
-
|
261
|
-
it "should be true" do
|
262
|
-
expect(@source.contains?(@target)).to be true
|
263
|
-
end
|
264
|
-
end
|
265
|
-
|
266
|
-
context "when some members are included in the zone we check against" do
|
267
|
-
before do
|
268
|
-
@target.members.create(zoneable: state1)
|
269
|
-
@target.members.create(zoneable: state2)
|
270
|
-
@target.members.create(zoneable: create(:state))
|
271
|
-
end
|
272
|
-
|
273
|
-
it "should be false" do
|
274
|
-
expect(@source.contains?(@target)).to be false
|
275
|
-
end
|
276
|
-
end
|
277
|
-
|
278
|
-
context "when none of the members are included in the zone we check against" do
|
279
|
-
before do
|
280
|
-
@target.members.create(zoneable: create(:state))
|
281
|
-
@target.members.create(zoneable: create(:state))
|
282
|
-
end
|
283
|
-
|
284
|
-
it "should be false" do
|
285
|
-
expect(@source.contains?(@target)).to be false
|
286
|
-
end
|
287
|
-
end
|
288
|
-
end
|
289
|
-
|
290
|
-
context "when checking country against state" do
|
291
|
-
before do
|
292
|
-
@source.members.create(zoneable: create(:state))
|
293
|
-
@target.members.create(zoneable: country1)
|
294
|
-
end
|
295
|
-
|
296
|
-
it "should be false" do
|
297
|
-
expect(@source.contains?(@target)).to be false
|
298
|
-
end
|
299
|
-
end
|
300
|
-
|
301
|
-
context "when checking state against country" do
|
302
|
-
before { @source.members.create(zoneable: country1) }
|
303
|
-
|
304
|
-
context "when all states contained in one of the countries we check against" do
|
305
|
-
|
306
|
-
before do
|
307
|
-
state1 = create(:state, country: country1)
|
308
|
-
@target.members.create(zoneable: state1)
|
309
|
-
end
|
310
|
-
|
311
|
-
it "should be true" do
|
312
|
-
expect(@source.contains?(@target)).to be true
|
313
|
-
end
|
314
|
-
end
|
315
|
-
|
316
|
-
context "when some states contained in one of the countries we check against" do
|
317
|
-
before do
|
318
|
-
state1 = create(:state, country: country1)
|
319
|
-
@target.members.create(zoneable: state1)
|
320
|
-
@target.members.create(zoneable: create(:state, country: country2))
|
321
|
-
end
|
322
|
-
|
323
|
-
it "should be false" do
|
324
|
-
expect(@source.contains?(@target)).to be false
|
325
|
-
end
|
326
|
-
end
|
327
|
-
|
328
|
-
context "when none of the states contained in any of the countries we check against" do
|
329
|
-
before do
|
330
|
-
@target.members.create(zoneable: create(:state, country: country2))
|
331
|
-
@target.members.create(zoneable: create(:state, country: country2))
|
332
|
-
end
|
333
|
-
|
334
|
-
it "should be false" do
|
335
|
-
expect(@source.contains?(@target)).to be false
|
336
|
-
end
|
337
|
-
end
|
338
|
-
end
|
339
|
-
end
|
340
|
-
|
341
|
-
context "#save" do
|
342
|
-
context "when default_tax is true" do
|
343
|
-
it "should clear previous default tax zone" do
|
344
|
-
zone1 = create(:zone, name: 'foo', default_tax: true)
|
345
|
-
zone = create(:zone, name: 'bar', default_tax: true)
|
346
|
-
expect(zone1.reload.default_tax).to be false
|
347
|
-
end
|
348
|
-
end
|
349
|
-
|
350
|
-
context "when a zone member country is added to an existing zone consisting of state members" do
|
351
|
-
it "should remove existing state members" do
|
352
|
-
zone = create(:zone, name: 'foo', zone_members: [])
|
353
|
-
state = create(:state)
|
354
|
-
country = create(:country)
|
355
|
-
zone.members.create(zoneable: state)
|
356
|
-
country_member = zone.members.create(zoneable: country)
|
357
|
-
zone.save
|
358
|
-
expect(zone.reload.members).to eq([country_member])
|
359
|
-
end
|
360
|
-
end
|
361
|
-
end
|
362
|
-
|
363
|
-
context "#kind" do
|
364
|
-
it "returns whatever value you set" do
|
365
|
-
zone = Spree::Zone.new kind: 'city'
|
366
|
-
expect(zone.kind).to eq 'city'
|
367
|
-
end
|
368
|
-
|
369
|
-
context "when the zone consists of country zone members" do
|
370
|
-
before do
|
371
|
-
@zone = create(:zone, name: 'country', zone_members: [])
|
372
|
-
@zone.members.create(zoneable: create(:country))
|
373
|
-
end
|
374
|
-
|
375
|
-
it "should return the kind of zone member" do
|
376
|
-
expect(@zone.kind).to eq("country")
|
377
|
-
end
|
378
|
-
end
|
379
|
-
end
|
380
|
-
|
381
|
-
context "#potential_matching_zones" do
|
382
|
-
let!(:country) { create(:country) }
|
383
|
-
let!(:country2) { create(:country, name: 'OtherCountry') }
|
384
|
-
let!(:country3) { create(:country, name: 'TaxCountry') }
|
385
|
-
let!(:default_tax_zone) do
|
386
|
-
create(:zone, default_tax: true).tap { |z| z.members.create(zoneable: country3) }
|
387
|
-
end
|
388
|
-
|
389
|
-
context "finding potential matches for a country zone" do
|
390
|
-
let!(:zone) do
|
391
|
-
create(:zone).tap do |z|
|
392
|
-
z.members.create(zoneable: country)
|
393
|
-
z.members.create(zoneable: country2)
|
394
|
-
z.save!
|
395
|
-
end
|
396
|
-
end
|
397
|
-
let!(:zone2) do
|
398
|
-
create(:zone).tap { |z| z.members.create(zoneable: country) && z.save! }
|
399
|
-
end
|
400
|
-
|
401
|
-
before { @result = Spree::Zone.potential_matching_zones(zone) }
|
402
|
-
|
403
|
-
it "will find all zones with countries covered by the passed in zone" do
|
404
|
-
expect(@result).to include(zone, zone2)
|
405
|
-
end
|
406
|
-
|
407
|
-
it "only returns each zone once" do
|
408
|
-
expect(@result.select { |z| z == zone }.size).to be 1
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
context "finding potential matches for a state zone" do
|
413
|
-
let!(:state) { create(:state, country: country) }
|
414
|
-
let!(:state2) { create(:state, country: country2, name: 'OtherState') }
|
415
|
-
let!(:state3) { create(:state, country: country2, name: 'State') }
|
416
|
-
let!(:zone) do
|
417
|
-
create(:zone).tap do |z|
|
418
|
-
z.members.create(zoneable: state)
|
419
|
-
z.members.create(zoneable: state2)
|
420
|
-
z.save!
|
421
|
-
end
|
422
|
-
end
|
423
|
-
let!(:zone2) do
|
424
|
-
create(:zone).tap { |z| z.members.create(zoneable: state) && z.save! }
|
425
|
-
end
|
426
|
-
let!(:zone3) do
|
427
|
-
create(:zone).tap { |z| z.members.create(zoneable: state2) && z.save! }
|
428
|
-
end
|
429
|
-
|
430
|
-
before { @result = Spree::Zone.potential_matching_zones(zone) }
|
431
|
-
|
432
|
-
it "will find all zones which share states covered by passed in zone" do
|
433
|
-
expect(@result).to include(zone, zone2)
|
434
|
-
end
|
435
|
-
|
436
|
-
it "will find zones that share countries with any states of the passed in zone" do
|
437
|
-
expect(@result).to include(zone3)
|
438
|
-
end
|
439
|
-
|
440
|
-
it "only returns each zone once" do
|
441
|
-
expect(@result.select { |z| z == zone }.size).to be 1
|
442
|
-
end
|
443
|
-
end
|
444
|
-
end
|
445
|
-
|
446
|
-
context "state and country associations" do
|
447
|
-
let!(:country) { create(:country) }
|
448
|
-
|
449
|
-
context "has countries associated" do
|
450
|
-
let!(:zone) do
|
451
|
-
create(:zone, countries: [country])
|
452
|
-
end
|
453
|
-
|
454
|
-
it "can access associated countries" do
|
455
|
-
expect(zone.countries).to include(country)
|
456
|
-
end
|
457
|
-
end
|
458
|
-
|
459
|
-
context "has states associated" do
|
460
|
-
let!(:state) { create(:state, country: country) }
|
461
|
-
let!(:zone) do
|
462
|
-
create(:zone, states: [state])
|
463
|
-
end
|
464
|
-
|
465
|
-
it "can access associated states" do
|
466
|
-
expect(zone.states).to include(state)
|
467
|
-
end
|
468
|
-
end
|
469
|
-
end
|
470
|
-
end
|