Skip to content

Commit

Permalink
Refactor and add specs to stock locations helper
Browse files Browse the repository at this point in the history
  • Loading branch information
gabrielbaldao authored and waiting-for-dev committed Jun 27, 2022
1 parent 5c0c355 commit 6ef1800
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
4 changes: 1 addition & 3 deletions backend/app/helpers/spree/admin/stock_locations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ module Spree
module Admin
module StockLocationsHelper
def admin_stock_location_display_name(stock_location)
name_parts = [stock_location.admin_name, stock_location.name]
name_parts.delete_if(&:blank?)
name_parts.join(' / ')
[stock_location.admin_name, stock_location.name].reject(&:blank?).join(' / ')
end
end
end
Expand Down
21 changes: 21 additions & 0 deletions backend/spec/helpers/admin/stock_locations_helper_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

require 'spec_helper'

describe Spree::Admin::StockLocationsHelper, type: :helper do
describe "#admin_stock_location_display_name" do
subject { helper.admin_stock_location_display_name(stock_location) }

context "without admin_name" do
let(:stock_location) { create(:stock_location_with_items, name: "NY Warehouse") }

it { is_expected.to eq "NY Warehouse" }
end

context "with admin_name" do
let(:stock_location) { create(:stock_location_with_items, name: "NY Warehouse", admin_name: "solidus") }

it { is_expected.to eq "solidus / NY Warehouse" }
end
end
end

0 comments on commit 6ef1800

Please sign in to comment.