Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display originator email in stock movement admin #3673

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
12 changes: 8 additions & 4 deletions backend/app/helpers/spree/admin/stock_movements_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions backend/spec/helpers/admin/stock_movements_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 ""
Expand Down