Skip to content

Commit

Permalink
Merge pull request #3673 from jacquesporveau/jacquesporveau/stock_mov…
Browse files Browse the repository at this point in the history
…ements_admin

Display originator email in stock movement admin
  • Loading branch information
spaghetticode authored Jun 24, 2020
2 parents 20e622d + b613149 commit 16ed773
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
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

0 comments on commit 16ed773

Please sign in to comment.