diff --git a/backend/app/helpers/spree/admin/stock_movements_helper.rb b/backend/app/helpers/spree/admin/stock_movements_helper.rb index 175f125cb6f..dc8db0b0ded 100644 --- a/backend/app/helpers/spree/admin/stock_movements_helper.rb +++ b/backend/app/helpers/spree/admin/stock_movements_helper.rb @@ -4,12 +4,16 @@ module Spree module Admin module StockMovementsHelper def pretty_originator(stock_movement) - if stock_movement.originator.respond_to?(:number) - if stock_movement.originator.respond_to?(:order) - link_to stock_movement.originator.number, [:edit, :admin, stock_movement.originator.order] + originator = stock_movement.originator + + if originator.respond_to?(:number) + if originator.respond_to?(:order) + link_to originator.number, [:edit, :admin, originator.order] else - stock_movement.originator.number + originator.number end + elsif originator.respond_to?(:email) + originator.email else "" end diff --git a/backend/spec/helpers/admin/stock_movements_helper_spec.rb b/backend/spec/helpers/admin/stock_movements_helper_spec.rb index 1ac2d8130ec..830d42444a1 100644 --- a/backend/spec/helpers/admin/stock_movements_helper_spec.rb +++ b/backend/spec/helpers/admin/stock_movements_helper_spec.rb @@ -11,15 +11,23 @@ subject { helper.pretty_originator(stock_movement) } context "originator has a number" do - let(:originator) { create(:order) } + let(:originator) { build(:order) } it "returns the originator's number" do expect(subject).to eq originator.number end end - context "originator doesn't have a number" do - let(:originator) { create(:user) } + context "originator has an email" do + let(:originator) { build(:user, email: "stock_mover@example.com") } + + it "returns the originator's email" do + expect(subject).to eq "stock_mover@example.com" + end + end + + context "the stock movement doesn't have an originator" do + let(:originator) { nil } it "returns an empty string" do expect(subject).to eq ""