Skip to content

Commit 1f89674

Browse files
authored
Merge pull request #1087 from workarea-commerce/kit/1080-mongoid8-embedded-count
WA-VERIFY-089: use size for embedded association counts (Mongoid 8)
2 parents c34e1ee + 0fea2df commit 1f89674

24 files changed

Lines changed: 224 additions & 34 deletions

admin/app/views/workarea/admin/catalog_categories/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
- else
7171
= result.breadcrumbs.join(' > ')
7272
%td.align-center= result.featured_products.count
73-
%td.align-center= result.product_rules.count
73+
%td.align-center= result.product_rules.size
7474
%td.align-center
7575
= link_to insights_catalog_category_path(result), class: 'link link--no-underline' do
7676
%span.spark{ title: t('workarea.admin.catalog_categories.index.sparkline_title') }

admin/app/views/workarea/admin/catalog_variants/index.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
.view__container
2222
.browsing-controls.browsing-controls--with-divider
2323
%p.browsing-controls__count
24-
= t('workarea.admin.catalog_variants.index.variant_pluralize', count: @variants.count)
24+
= t('workarea.admin.catalog_variants.index.variant_pluralize', count: @variants.size)
2525

2626
- if @variants.any?
2727
%table.index-table

admin/test/integration/workarea/admin/import_taxes_integration_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def test_can_create_an_import
2323
assert(import.created_by_id.present?)
2424

2525
category.reload
26-
assert_equal(2, category.rates.count)
26+
assert_equal(2, category.rates.size)
2727
end
2828
end
2929
end

admin/test/integration/workarea/admin/pricing_skus_integration_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ def test_creation
2929
assert(sku.on_sale?)
3030
assert(sku.discountable?)
3131
assert_nil(sku.msrp)
32-
assert_equal(1, sku.prices.count)
32+
assert_equal(1, sku.prices.size)
3333
assert_equal(10.to_m, sku.prices.first.regular)
3434
assert_nil(sku.prices.first.sale)
3535
end

admin/test/view_models/workarea/admin/pricing_sku_view_model_test.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def setup_pricing_sku_and_prices
2121
end
2222

2323
def test_sell_prices
24-
assert_equal(@sku.prices.count, @sku.sell_prices.count)
24+
assert_equal(@sku.prices.size, @sku.sell_prices.size)
2525
end
2626

2727
def test_min_price

core/app/seeds/workarea/orders_seeds.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def create_order
3434
)
3535
end
3636

37-
unless user.addresses.count > 0
37+
unless user.addresses.size > 0
3838
user.addresses.create!(
3939
first_name: user.first_name,
4040
last_name: user.last_name,
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
require 'test_helper'
2+
3+
module Workarea
4+
class FeaturedProductsChangesetsTest < TestCase
5+
def test_changesets_finds_by_product_id_in_changeset_and_original
6+
release = create_release
7+
8+
in_changeset = Release::Changeset.create!(
9+
release: release,
10+
changeset: { 'product_ids' => %w(P1 P2) },
11+
original: {}
12+
)
13+
14+
in_original = Release::Changeset.create!(
15+
release: release,
16+
changeset: {},
17+
original: { 'product_ids' => %w(P1) }
18+
)
19+
20+
unrelated = Release::Changeset.create!(
21+
release: release,
22+
changeset: { 'product_ids' => %w(P3) },
23+
original: { 'product_ids' => %w(P4) }
24+
)
25+
26+
results = FeaturedProducts.changesets('P1').to_a
27+
assert_includes(results, in_changeset)
28+
assert_includes(results, in_original)
29+
refute_includes(results, unrelated)
30+
end
31+
end
32+
end

core/test/models/workarea/navigation/redirect_test.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def test_sanitizing_paths
2626
end
2727
end
2828

29+
def test_search
30+
path_match = create_redirect(path: '/foo-bar', destination: '/other')
31+
dest_match = create_redirect(path: '/something', destination: '/foo-destination')
32+
no_match = create_redirect(path: '/baz', destination: '/qux')
33+
34+
results = Redirect.search('foo').to_a
35+
assert_includes(results, path_match)
36+
assert_includes(results, dest_match)
37+
refute_includes(results, no_match)
38+
end
39+
2940
def test_handle_invalid_path
3041
path = '/category/FoalBroodmare/Supplements-Mares & Foals/20552.html'
3142
encoded_path = URI::DEFAULT_PARSER.escape(path)

core/test/models/workarea/order_test.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,10 @@ def test_add_item
8383
assert(order.items.last.updated_at.present?)
8484

8585
order.add_item(product_id: '1234', sku: 'SKU', quantity: 2)
86-
assert_equal(1, order.items.count)
86+
assert_equal(1, order.items.size)
8787
assert_equal(4, order.items.last.quantity)
8888

89-
assert_no_changes 'order.items.count' do
89+
assert_no_changes 'order.items.size' do
9090
order.add_item(
9191
product_id: '1234',
9292
sku: 'SKU',
@@ -96,7 +96,7 @@ def test_add_item
9696

9797
Workarea.config.distinct_order_item_attributes << :discountable
9898

99-
assert_changes 'order.items.count' do
99+
assert_changes 'order.items.size' do
100100
order.add_item(
101101
product_id: '1234',
102102
sku: 'SKU',
@@ -105,7 +105,7 @@ def test_add_item
105105
)
106106
end
107107

108-
assert_no_changes 'order.items.count' do
108+
assert_no_changes 'order.items.size' do
109109
order.add_item(
110110
product_id: '1234',
111111
sku: 'SKU',
@@ -123,7 +123,7 @@ def test_update_item
123123
assert_equal(1, order.items.first.quantity)
124124

125125
order.update_item(item.id, sku: 'SKU2')
126-
assert_equal(1, order.items.count)
126+
assert_equal(1, order.items.size)
127127
assert_equal('SKU2', order.items.first.sku)
128128

129129
order = Order.new

core/test/models/workarea/pricing/discount/generated_promo_code_test.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ def test_generated_promo_code
88
code = GeneratedPromoCode.generate_code('WL-')
99
assert_match(/WL-/i, code)
1010
end
11+
12+
def test_not_expired_scope
13+
code_list = create_code_list
14+
15+
expired = code_list.promo_codes.create!(code: 'exp', expires_at: 1.day.ago)
16+
nil_expiry = code_list.promo_codes.create!(code: 'nilexp', expires_at: nil)
17+
future = code_list.promo_codes.create!(code: 'future', expires_at: 1.day.from_now)
18+
19+
results = code_list.promo_codes.not_expired.to_a
20+
assert_includes(results, nil_expiry)
21+
assert_includes(results, future)
22+
refute_includes(results, expired)
23+
end
1124
end
1225
end
1326
end

0 commit comments

Comments
 (0)