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.
Files changed (207) hide show
  1. checksums.yaml +4 -4
  2. data/lib/spree/core/version.rb +1 -1
  3. data/spree_core.gemspec +1 -1
  4. metadata +3 -206
  5. data/spec/fixtures/microdata.html +0 -22
  6. data/spec/fixtures/microdata_itemref.html +0 -15
  7. data/spec/fixtures/microdata_no_itemscope.html +0 -20
  8. data/spec/fixtures/thinking-cat.jpg +0 -0
  9. data/spec/helpers/base_helper_spec.rb +0 -200
  10. data/spec/helpers/products_helper_spec.rb +0 -289
  11. data/spec/lib/calculated_adjustments_spec.rb +0 -7
  12. data/spec/lib/i18n_spec.rb +0 -123
  13. data/spec/lib/search/base_spec.rb +0 -86
  14. data/spec/lib/spree/core/controller_helpers/auth_spec.rb +0 -103
  15. data/spec/lib/spree/core/controller_helpers/order_spec.rb +0 -110
  16. data/spec/lib/spree/core/controller_helpers/search_spec.rb +0 -17
  17. data/spec/lib/spree/core/controller_helpers/store_spec.rb +0 -72
  18. data/spec/lib/spree/core/controller_helpers/strong_parameters_spec.rb +0 -39
  19. data/spec/lib/spree/core/delegate_belongs_to_spec.rb +0 -22
  20. data/spec/lib/spree/core/importer/order_spec.rb +0 -605
  21. data/spec/lib/spree/core/number_generator_spec.rb +0 -175
  22. data/spec/lib/spree/core/token_generator_spec.rb +0 -24
  23. data/spec/lib/spree/core/validators/email_spec.rb +0 -53
  24. data/spec/lib/spree/core_spec.rb +0 -23
  25. data/spec/lib/spree/localized_number_spec.rb +0 -48
  26. data/spec/lib/spree/migrations_spec.rb +0 -36
  27. data/spec/lib/spree/money_spec.rb +0 -122
  28. data/spec/lib/tasks/exchanges_spec.rb +0 -136
  29. data/spec/mailers/order_mailer_spec.rb +0 -122
  30. data/spec/mailers/reimbursement_mailer_spec.rb +0 -47
  31. data/spec/mailers/shipment_mailer_spec.rb +0 -81
  32. data/spec/mailers/test_mailer_spec.rb +0 -38
  33. data/spec/models/option_type_prototype_spec.rb +0 -9
  34. data/spec/models/spree/ability_spec.rb +0 -251
  35. data/spec/models/spree/address_spec.rb +0 -402
  36. data/spec/models/spree/adjustable/adjuster/base_spec.rb +0 -10
  37. data/spec/models/spree/adjustable/adjuster/promotion_spec.rb +0 -211
  38. data/spec/models/spree/adjustable/adjuster/tax_spec.rb +0 -86
  39. data/spec/models/spree/adjustable/adjustments_updater_spec.rb +0 -26
  40. data/spec/models/spree/adjustment_spec.rb +0 -189
  41. data/spec/models/spree/app_configuration_spec.rb +0 -26
  42. data/spec/models/spree/asset_spec.rb +0 -28
  43. data/spec/models/spree/calculator/default_tax_spec.rb +0 -152
  44. data/spec/models/spree/calculator/flat_percent_item_total_spec.rb +0 -25
  45. data/spec/models/spree/calculator/flat_rate_spec.rb +0 -47
  46. data/spec/models/spree/calculator/flexi_rate_spec.rb +0 -41
  47. data/spec/models/spree/calculator/percent_on_line_item_spec.rb +0 -15
  48. data/spec/models/spree/calculator/price_sack_spec.rb +0 -30
  49. data/spec/models/spree/calculator/refunds/default_refund_amount_spec.rb +0 -47
  50. data/spec/models/spree/calculator/shipping.rb +0 -8
  51. data/spec/models/spree/calculator/shipping/flat_percent_item_total_spec.rb +0 -23
  52. data/spec/models/spree/calculator/shipping/flat_rate_spec.rb +0 -13
  53. data/spec/models/spree/calculator/shipping/flexi_rate_spec.rb +0 -52
  54. data/spec/models/spree/calculator/shipping/per_item_spec.rb +0 -20
  55. data/spec/models/spree/calculator/shipping/price_sack_spec.rb +0 -29
  56. data/spec/models/spree/calculator/tiered_flat_rate_spec.rb +0 -40
  57. data/spec/models/spree/calculator/tiered_percent_spec.rb +0 -51
  58. data/spec/models/spree/calculator_spec.rb +0 -69
  59. data/spec/models/spree/classification_spec.rb +0 -93
  60. data/spec/models/spree/concerns/display_money_spec.rb +0 -43
  61. data/spec/models/spree/concerns/user_methods_spec.rb +0 -82
  62. data/spec/models/spree/concerns/vat_price_calculation_spec.rb +0 -66
  63. data/spec/models/spree/country_spec.rb +0 -55
  64. data/spec/models/spree/credit_card_spec.rb +0 -328
  65. data/spec/models/spree/customer_return_spec.rb +0 -240
  66. data/spec/models/spree/exchange_spec.rb +0 -75
  67. data/spec/models/spree/gateway/bogus_simple.rb +0 -20
  68. data/spec/models/spree/gateway/bogus_spec.rb +0 -13
  69. data/spec/models/spree/gateway_spec.rb +0 -61
  70. data/spec/models/spree/image_spec.rb +0 -8
  71. data/spec/models/spree/inventory_unit_spec.rb +0 -256
  72. data/spec/models/spree/line_item_spec.rb +0 -346
  73. data/spec/models/spree/option_type_spec.rb +0 -14
  74. data/spec/models/spree/option_value_spec.rb +0 -18
  75. data/spec/models/spree/order/address_spec.rb +0 -50
  76. data/spec/models/spree/order/adjustments_spec.rb +0 -29
  77. data/spec/models/spree/order/callbacks_spec.rb +0 -42
  78. data/spec/models/spree/order/checkout_spec.rb +0 -770
  79. data/spec/models/spree/order/currency_updater_spec.rb +0 -32
  80. data/spec/models/spree/order/finalizing_spec.rb +0 -114
  81. data/spec/models/spree/order/helpers_spec.rb +0 -5
  82. data/spec/models/spree/order/payment_spec.rb +0 -214
  83. data/spec/models/spree/order/risk_assessment_spec.rb +0 -84
  84. data/spec/models/spree/order/shipments_spec.rb +0 -43
  85. data/spec/models/spree/order/state_machine_spec.rb +0 -212
  86. data/spec/models/spree/order/store_credit_spec.rb +0 -426
  87. data/spec/models/spree/order/tax_spec.rb +0 -84
  88. data/spec/models/spree/order/totals_spec.rb +0 -24
  89. data/spec/models/spree/order/updating_spec.rb +0 -18
  90. data/spec/models/spree/order/validations_spec.rb +0 -15
  91. data/spec/models/spree/order_contents_spec.rb +0 -297
  92. data/spec/models/spree/order_inventory_spec.rb +0 -239
  93. data/spec/models/spree/order_merger_spec.rb +0 -135
  94. data/spec/models/spree/order_spec.rb +0 -1046
  95. data/spec/models/spree/order_updater_spec.rb +0 -305
  96. data/spec/models/spree/payment/gateway_options_spec.rb +0 -127
  97. data/spec/models/spree/payment/store_credit_spec.rb +0 -60
  98. data/spec/models/spree/payment_method/store_credit_spec.rb +0 -291
  99. data/spec/models/spree/payment_method_spec.rb +0 -103
  100. data/spec/models/spree/payment_spec.rb +0 -919
  101. data/spec/models/spree/preference_spec.rb +0 -80
  102. data/spec/models/spree/preferences/configuration_spec.rb +0 -30
  103. data/spec/models/spree/preferences/preferable_spec.rb +0 -344
  104. data/spec/models/spree/preferences/scoped_store_spec.rb +0 -58
  105. data/spec/models/spree/preferences/store_spec.rb +0 -46
  106. data/spec/models/spree/price_spec.rb +0 -128
  107. data/spec/models/spree/product/scopes_spec.rb +0 -183
  108. data/spec/models/spree/product_duplicator_spec.rb +0 -103
  109. data/spec/models/spree/product_filter_spec.rb +0 -26
  110. data/spec/models/spree/product_option_type_spec.rb +0 -9
  111. data/spec/models/spree/product_promotion_rule_spec.rb +0 -9
  112. data/spec/models/spree/product_property_spec.rb +0 -26
  113. data/spec/models/spree/product_spec.rb +0 -629
  114. data/spec/models/spree/promotion/actions/create_adjustment_spec.rb +0 -113
  115. data/spec/models/spree/promotion/actions/create_item_adjustments_spec.rb +0 -148
  116. data/spec/models/spree/promotion/actions/create_line_items_spec.rb +0 -86
  117. data/spec/models/spree/promotion/actions/free_shipping_spec.rb +0 -36
  118. data/spec/models/spree/promotion/rules/country_spec.rb +0 -36
  119. data/spec/models/spree/promotion/rules/first_order_spec.rb +0 -75
  120. data/spec/models/spree/promotion/rules/item_total_spec.rb +0 -282
  121. data/spec/models/spree/promotion/rules/one_use_per_user_spec.rb +0 -42
  122. data/spec/models/spree/promotion/rules/option_value_spec.rb +0 -90
  123. data/spec/models/spree/promotion/rules/product_spec.rb +0 -143
  124. data/spec/models/spree/promotion/rules/taxon_spec.rb +0 -102
  125. data/spec/models/spree/promotion/rules/user_logged_in_spec.rb +0 -27
  126. data/spec/models/spree/promotion/rules/user_spec.rb +0 -45
  127. data/spec/models/spree/promotion_action_spec.rb +0 -10
  128. data/spec/models/spree/promotion_category_spec.rb +0 -17
  129. data/spec/models/spree/promotion_handler/cart_spec.rb +0 -102
  130. data/spec/models/spree/promotion_handler/coupon_spec.rb +0 -323
  131. data/spec/models/spree/promotion_handler/free_shipping_spec.rb +0 -48
  132. data/spec/models/spree/promotion_handler/page_spec.rb +0 -44
  133. data/spec/models/spree/promotion_rule_spec.rb +0 -29
  134. data/spec/models/spree/promotion_rule_taxon_spec.rb +0 -9
  135. data/spec/models/spree/promotion_rule_user_spec.rb +0 -9
  136. data/spec/models/spree/promotion_spec.rb +0 -679
  137. data/spec/models/spree/property_prototype_spec.rb +0 -9
  138. data/spec/models/spree/property_spec.rb +0 -5
  139. data/spec/models/spree/prototype_spec.rb +0 -5
  140. data/spec/models/spree/prototype_taxon_spec.rb +0 -9
  141. data/spec/models/spree/refund_reason_spec.rb +0 -20
  142. data/spec/models/spree/refund_spec.rb +0 -195
  143. data/spec/models/spree/reimbursement/credit_spec.rb +0 -36
  144. data/spec/models/spree/reimbursement/reimbursement_type_engine_spec.rb +0 -140
  145. data/spec/models/spree/reimbursement/reimbursement_type_validator_spec.rb +0 -83
  146. data/spec/models/spree/reimbursement_performer_spec.rb +0 -30
  147. data/spec/models/spree/reimbursement_spec.rb +0 -188
  148. data/spec/models/spree/reimbursement_tax_calculator_spec.rb +0 -63
  149. data/spec/models/spree/reimbursement_type/credit_spec.rb +0 -53
  150. data/spec/models/spree/reimbursement_type/exchange_spec.rb +0 -46
  151. data/spec/models/spree/reimbursement_type/original_payment_spec.rb +0 -55
  152. data/spec/models/spree/reimbursement_type/store_credit_spec.rb +0 -101
  153. data/spec/models/spree/return_authorization_reason_spec.rb +0 -7
  154. data/spec/models/spree/return_authorization_spec.rb +0 -230
  155. data/spec/models/spree/return_item/eligibility_validator/default_spec.rb +0 -77
  156. data/spec/models/spree/return_item/eligibility_validator/inventory_shipped_spec.rb +0 -58
  157. data/spec/models/spree/return_item/eligibility_validator/no_reimbursements_spec.rb +0 -61
  158. data/spec/models/spree/return_item/eligibility_validator/order_completed_spec.rb +0 -32
  159. data/spec/models/spree/return_item/eligibility_validator/rma_required_spec.rb +0 -29
  160. data/spec/models/spree/return_item/eligibility_validator/time_since_purchase_spec.rb +0 -35
  161. data/spec/models/spree/return_item/exchange_variant_eligibility/same_option_value_spec.rb +0 -65
  162. data/spec/models/spree/return_item/exchange_variant_eligibility/same_product_spec.rb +0 -43
  163. data/spec/models/spree/return_item_spec.rb +0 -731
  164. data/spec/models/spree/returns_calculator_spec.rb +0 -14
  165. data/spec/models/spree/role_spec.rb +0 -7
  166. data/spec/models/spree/shipment_spec.rb +0 -742
  167. data/spec/models/spree/shipping_calculator_spec.rb +0 -45
  168. data/spec/models/spree/shipping_category_spec.rb +0 -19
  169. data/spec/models/spree/shipping_method_spec.rb +0 -95
  170. data/spec/models/spree/shipping_rate_spec.rb +0 -140
  171. data/spec/models/spree/state_spec.rb +0 -29
  172. data/spec/models/spree/stock/availability_validator_spec.rb +0 -36
  173. data/spec/models/spree/stock/content_item_spec.rb +0 -31
  174. data/spec/models/spree/stock/coordinator_spec.rb +0 -61
  175. data/spec/models/spree/stock/differentiator_spec.rb +0 -39
  176. data/spec/models/spree/stock/estimator_spec.rb +0 -202
  177. data/spec/models/spree/stock/inventory_unit_builder_spec.rb +0 -38
  178. data/spec/models/spree/stock/package_spec.rb +0 -182
  179. data/spec/models/spree/stock/packer_spec.rb +0 -70
  180. data/spec/models/spree/stock/prioritizer_spec.rb +0 -125
  181. data/spec/models/spree/stock/quantifier_spec.rb +0 -126
  182. data/spec/models/spree/stock/splitter/backordered_spec.rb +0 -29
  183. data/spec/models/spree/stock/splitter/base_spec.rb +0 -21
  184. data/spec/models/spree/stock/splitter/shipping_category_spec.rb +0 -47
  185. data/spec/models/spree/stock/splitter/weight_spec.rb +0 -32
  186. data/spec/models/spree/stock_item_spec.rb +0 -432
  187. data/spec/models/spree/stock_location_spec.rb +0 -243
  188. data/spec/models/spree/stock_movement_spec.rb +0 -120
  189. data/spec/models/spree/stock_transfer_spec.rb +0 -50
  190. data/spec/models/spree/store_credit_event_spec.rb +0 -101
  191. data/spec/models/spree/store_credit_spec.rb +0 -786
  192. data/spec/models/spree/store_spec.rb +0 -78
  193. data/spec/models/spree/tax_category_spec.rb +0 -32
  194. data/spec/models/spree/tax_rate_spec.rb +0 -561
  195. data/spec/models/spree/taxon_spec.rb +0 -85
  196. data/spec/models/spree/taxonomy_spec.rb +0 -18
  197. data/spec/models/spree/tracker_spec.rb +0 -21
  198. data/spec/models/spree/user_spec.rb +0 -203
  199. data/spec/models/spree/variant_spec.rb +0 -818
  200. data/spec/models/spree/zone_member_spec.rb +0 -38
  201. data/spec/models/spree/zone_spec.rb +0 -472
  202. data/spec/spec_helper.rb +0 -79
  203. data/spec/support/big_decimal.rb +0 -5
  204. data/spec/support/concerns/adjustment_source.rb +0 -23
  205. data/spec/support/concerns/default_price.rb +0 -37
  206. data/spec/support/rake.rb +0 -13
  207. 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