Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
- else
= result.breadcrumbs.join(' > ')
%td.align-center= result.featured_products.count
%td.align-center= result.product_rules.count
%td.align-center= result.product_rules.size
%td.align-center
= link_to insights_catalog_category_path(result), class: 'link link--no-underline' do
%span.spark{ title: t('workarea.admin.catalog_categories.index.sparkline_title') }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
.view__container
.browsing-controls.browsing-controls--with-divider
%p.browsing-controls__count
= t('workarea.admin.catalog_variants.index.variant_pluralize', count: @variants.count)
= t('workarea.admin.catalog_variants.index.variant_pluralize', count: @variants.size)

- if @variants.any?
%table.index-table
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_can_create_an_import
assert(import.created_by_id.present?)

category.reload
assert_equal(2, category.rates.count)
assert_equal(2, category.rates.size)
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_creation
assert(sku.on_sale?)
assert(sku.discountable?)
assert_nil(sku.msrp)
assert_equal(1, sku.prices.count)
assert_equal(1, sku.prices.size)
assert_equal(10.to_m, sku.prices.first.regular)
assert_nil(sku.prices.first.sale)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def setup_pricing_sku_and_prices
end

def test_sell_prices
assert_equal(@sku.prices.count, @sku.sell_prices.count)
assert_equal(@sku.prices.size, @sku.sell_prices.size)
end

def test_min_price
Expand Down
2 changes: 1 addition & 1 deletion core/app/seeds/workarea/orders_seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def create_order
)
end

unless user.addresses.count > 0
unless user.addresses.size > 0
user.addresses.create!(
first_name: user.first_name,
last_name: user.last_name,
Expand Down
32 changes: 32 additions & 0 deletions core/test/models/workarea/featured_products_changesets_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'test_helper'

module Workarea
class FeaturedProductsChangesetsTest < TestCase
def test_changesets_finds_by_product_id_in_changeset_and_original
release = create_release

in_changeset = Release::Changeset.create!(
release: release,
changeset: { 'product_ids' => %w(P1 P2) },
original: {}
)

in_original = Release::Changeset.create!(
release: release,
changeset: {},
original: { 'product_ids' => %w(P1) }
)

unrelated = Release::Changeset.create!(
release: release,
changeset: { 'product_ids' => %w(P3) },
original: { 'product_ids' => %w(P4) }
)

results = FeaturedProducts.changesets('P1').to_a
assert_includes(results, in_changeset)
assert_includes(results, in_original)
refute_includes(results, unrelated)
end
end
end
11 changes: 11 additions & 0 deletions core/test/models/workarea/navigation/redirect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,17 @@ def test_sanitizing_paths
end
end

def test_search
path_match = create_redirect(path: '/foo-bar', destination: '/other')
dest_match = create_redirect(path: '/something', destination: '/foo-destination')
no_match = create_redirect(path: '/baz', destination: '/qux')

results = Redirect.search('foo').to_a
assert_includes(results, path_match)
assert_includes(results, dest_match)
refute_includes(results, no_match)
end

def test_handle_invalid_path
path = '/category/FoalBroodmare/Supplements-Mares & Foals/20552.html'
encoded_path = URI::DEFAULT_PARSER.escape(path)
Expand Down
10 changes: 5 additions & 5 deletions core/test/models/workarea/order_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,10 @@ def test_add_item
assert(order.items.last.updated_at.present?)

order.add_item(product_id: '1234', sku: 'SKU', quantity: 2)
assert_equal(1, order.items.count)
assert_equal(1, order.items.size)
assert_equal(4, order.items.last.quantity)

assert_no_changes 'order.items.count' do
assert_no_changes 'order.items.size' do
order.add_item(
product_id: '1234',
sku: 'SKU',
Expand All @@ -96,7 +96,7 @@ def test_add_item

Workarea.config.distinct_order_item_attributes << :discountable

assert_changes 'order.items.count' do
assert_changes 'order.items.size' do
order.add_item(
product_id: '1234',
sku: 'SKU',
Expand All @@ -105,7 +105,7 @@ def test_add_item
)
end

assert_no_changes 'order.items.count' do
assert_no_changes 'order.items.size' do
order.add_item(
product_id: '1234',
sku: 'SKU',
Expand All @@ -123,7 +123,7 @@ def test_update_item
assert_equal(1, order.items.first.quantity)

order.update_item(item.id, sku: 'SKU2')
assert_equal(1, order.items.count)
assert_equal(1, order.items.size)
assert_equal('SKU2', order.items.first.sku)

order = Order.new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@ def test_generated_promo_code
code = GeneratedPromoCode.generate_code('WL-')
assert_match(/WL-/i, code)
end

def test_not_expired_scope
code_list = create_code_list

expired = code_list.promo_codes.create!(code: 'exp', expires_at: 1.day.ago)
nil_expiry = code_list.promo_codes.create!(code: 'nilexp', expires_at: nil)
future = code_list.promo_codes.create!(code: 'future', expires_at: 1.day.from_now)

results = code_list.promo_codes.not_expired.to_a
assert_includes(results, nil_expiry)
assert_includes(results, future)
refute_includes(results, expired)
end
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions core/test/models/workarea/pricing/tax_applier_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def test_with_multiple_tax_codes_and_discount

@shipping.reload

assert_equal(2, @shipping.price_adjustments.count)
assert_equal(2, @shipping.price_adjustments.size)
assert_equal([0.28.to_m, 0.50.to_m], @shipping.price_adjustments.map(&:amount))
end

Expand All @@ -115,7 +115,7 @@ def test_partial_shipping_quantity_tax_calculation
@shipping.save!

@shipping.reload
assert_equal(1, @shipping.price_adjustments.count)
assert_equal(1, @shipping.price_adjustments.size)
price_adjustment = @shipping.price_adjustments.last
assert_equal('tax', price_adjustment.price)
assert_equal(0.15.to_m, price_adjustment.amount)
Expand Down
35 changes: 35 additions & 0 deletions core/test/models/workarea/tax/rate_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
require 'test_helper'

module Workarea
module Tax
class RateTest < TestCase
def test_search
category = create_tax_category(rates: [])

pa_region = category.rates.create!(country: Country['US'], region: 'PA')
zip_code = category.rates.create!(country: Country['US'], postal_code: '19106')
canada = category.rates.create!(country: Country['CA'])
other = category.rates.create!(country: Country['US'], region: 'NJ', postal_code: '07001')

# region match
results = Rate.search('PA').to_a
assert_includes(results, pa_region)
refute_includes(results, zip_code)
refute_includes(results, canada)

# postal code match
results = Rate.search('191').to_a
assert_includes(results, zip_code)
refute_includes(results, pa_region)

# country match
results = Rate.search('CA').to_a
assert_includes(results, canada)

# no match
results = Rate.search('NOPE').to_a
assert_empty(results)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def test_save
assert_equal(1, item.quantity)

order.reload
assert_equal(1, order.items.count)
assert_equal(1, order.items.size)

params = { sku: 'SKU3', quantity: 2 }
item = AddMultipleCartItems::Item.new(order, params)
Expand All @@ -54,7 +54,7 @@ def test_save
)

order.reload
assert_equal(1, order.items.count)
assert_equal(1, order.items.size)
end
end
end
Expand Down
8 changes: 4 additions & 4 deletions core/test/services/workarea/add_multiple_cart_items_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_perform
assert(add_to_cart.perform)

order.reload
assert_equal(2, order.items.count)
assert_equal(2, order.items.size)

item = order.items.first
assert_equal('PROD1', item.product_id)
Expand All @@ -54,7 +54,7 @@ def test_perform_partial_success
assert(add_to_cart.items.first.persisted?)

order.reload
assert_equal(1, order.items.count)
assert_equal(1, order.items.size)

item = add_to_cart.items.first.item
assert(item.persisted?)
Expand Down Expand Up @@ -83,7 +83,7 @@ def test_perform!
refute(add_to_cart.perform!)

order.reload
assert_equal(0, order.items.count)
assert_equal(0, order.items.size)

items_params = [
{ sku: 'sku1', quantity: 2 },
Expand All @@ -94,7 +94,7 @@ def test_perform!
assert(add_to_cart.perform!)

order.reload
assert_equal(2, order.items.count)
assert_equal(2, order.items.size)
end
end
end
2 changes: 1 addition & 1 deletion core/test/services/workarea/cart_cleaner_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def test_removing_inactive_variant_items
@order.add_item(product_id: product.id, sku: product.skus.second)

@cleaner.clean
assert_equal(1, @order.items.count)
assert_equal(1, @order.items.size)
end

def test_removing_items_missing_price
Expand Down
4 changes: 2 additions & 2 deletions core/test/services/workarea/create_fulfillment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ def test_creating_items_per_order_item
CreateFulfillment.new(@order).perform

fulfillment = Fulfillment.find(@order.id)
assert_equal(fulfillment.items.count, 2)
assert_equal(fulfillment.items.size, 2)

CreateFulfillment.new(@order).perform
fulfillment.reload
assert_equal(fulfillment.items.count, 2)
assert_equal(fulfillment.items.size, 2)
end
end
end
2 changes: 1 addition & 1 deletion core/test/services/workarea/inventory_adjustment_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def set_inventory
def test_adjust
adjustment = InventoryAdjustment.new(order).tap(&:perform)

assert_equal(2, order.items.count)
assert_equal(2, order.items.size)
assert_equal(1, order.items[0].quantity)
assert_equal(1, order.items[1].quantity)
assert_nil(order.items.detect { |i| i.sku == 'SKU3' })
Expand Down
2 changes: 1 addition & 1 deletion core/test/services/workarea/order_merge_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_merge

OrderMerge.new(original).merge(other)

assert_equal(3, original.items.count)
assert_equal(3, original.items.size)
assert_equal([1, 1, 1], original.items.map(&:quantity))
assert_equal(%w(PROMOCODE), original.promo_codes)
end
Expand Down
4 changes: 2 additions & 2 deletions docs/source/articles/content.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ A <dfn>content block</dfn> (`Workarea::Content::Block`) is a [releasable](/artic
A newly created content has 0 blocks.

```
content.blocks.count
content.blocks.size
# => 0

content.blocks
Expand All @@ -155,7 +155,7 @@ Create a block within a content by specifying the type of block to be created.
# Create an instance of an 'Image' block
content.blocks.create!(type: 'image')

content.blocks.count
content.blocks.size
# => 1

# Access the block from the content
Expand Down
2 changes: 1 addition & 1 deletion docs/source/articles/order-pricing.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ item_price_adjustments = items.map(&:price_adjustments).reduce(&:+)
shipping_price_adjustments = shippings.map(&:price_adjustments).reduce(&:+)
all_price_adjustments = item_price_adjustments + shipping_price_adjustments

all_price_adjustments.count
all_price_adjustments.size
# => 10
all_price_adjustments.first.class
# => Workarea::PriceAdjustment
Expand Down
2 changes: 1 addition & 1 deletion docs/source/articles/orders-and-items.html.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ Review the implementation of `Storefront::CartItemsController#create` ([source,
Each time an order is priced, the granular pricing details are stored on the item as _price adjustments_, an embedded collection of type `Workarea::PriceAdjustment`. These embedded documents provide the necessary details to determine the total price of an item (in the case of a cart) and a record of how that price was determined (in the case of a placed order).

```
item.price_adjustments.count
item.price_adjustments.size
# => 2

price_adjustment = item.price_adjustments.last
Expand Down
12 changes: 6 additions & 6 deletions docs/source/articles/products.html.md.erb
Original file line number Diff line number Diff line change
Expand Up @@ -1124,9 +1124,9 @@ model = Workarea::Catalog::Product.find_by(name: 'Tropical Drink Mix')
view_model = Workarea::Storefront::ProductViewModel.wrap(model)

# The variants count is the same at this point
model.variants.count
model.variants.size
# => 3
view_model.variants.count
view_model.variants.size
# => 3
```

Expand All @@ -1138,13 +1138,13 @@ The product therefore has 3 variants and 3 options:
# set one of the variants to inactive
model.variants.second.update_attributes!(active: false)
# the model still has 3 variants
model.variants.count
model.variants.size
# => 3

# re-create the view model (to bust cache)
view_model = Workarea::Storefront::ProductViewModel.wrap(model)
# the Storefront view of the product has only 2 variants
view_model.variants.count
view_model.variants.size
# => 2

# choose another variant and make the corresponding
Expand All @@ -1154,12 +1154,12 @@ model.variants.last.tap do |variant|
.find(variant.sku)
.update_attributes!(policy: 'standard', available: '0')
end
model.variants.count
model.variants.size
# => 3

# now the Storefront view of the product contains only a single variant
view_model = Workarea::Storefront::ProductViewModel.wrap(model)
view_model.variants.count
view_model.variants.size
# => 1
```

Expand Down
Loading
Loading