Skip to content

Commit

Permalink
Merge pull request #3027 from tvdeyen/use-alchemy_display_name
Browse files Browse the repository at this point in the history
Use alchemy_display_name for page actor names
  • Loading branch information
tvdeyen authored Sep 6, 2024
2 parents 161ab60 + 00dd34e commit dbed496
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 3 additions & 3 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ def public_until
# does not respond to +#name+ it returns +'unknown'+
#
def creator_name
creator.try(:name) || Alchemy.t("unknown")
creator.try(:alchemy_display_name) || Alchemy.t("unknown")
end

# Returns the name of the last updater of this page.
Expand All @@ -500,7 +500,7 @@ def creator_name
# does not respond to +#name+ it returns +'unknown'+
#
def updater_name
updater.try(:name) || Alchemy.t("unknown")
updater.try(:alchemy_display_name) || Alchemy.t("unknown")
end

# Returns the name of the user currently editing this page.
Expand All @@ -509,7 +509,7 @@ def updater_name
# does not respond to +#name+ it returns +'unknown'+
#
def locker_name
locker.try(:name) || Alchemy.t("unknown")
locker.try(:alchemy_display_name) || Alchemy.t("unknown")
end

# Key hint translations by page layout, rather than the default name.
Expand Down
6 changes: 5 additions & 1 deletion spec/dummy/app/models/dummy_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,17 @@ def self.admins
end

def alchemy_roles
@alchemy_roles || %w(admin)
@alchemy_roles || %w[admin]
end

def name
@name || email
end

def alchemy_display_name
name
end

def human_roles_string
alchemy_roles.map(&:humanize)
end
Expand Down
8 changes: 4 additions & 4 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1816,7 +1816,7 @@ module Alchemy
end
end

context "with user class having a name accessor" do
context "with user class having a alchemy_display_name accessor" do
let(:user) { build(:alchemy_dummy_user, name: "Paul Page") }

describe "#creator_name" do
Expand Down Expand Up @@ -1844,7 +1844,7 @@ module Alchemy
end
end

context "with user class returning nil for name" do
context "with user class returning nil for alchemy_display_name" do
let(:user) { Alchemy.user_class.new }

describe "#creator_name" do
Expand Down Expand Up @@ -1872,11 +1872,11 @@ module Alchemy
end
end

context "with user class not responding to name" do
context "with user class not responding to alchemy_display_name" do
let(:user) { Alchemy.user_class.new }

before do
expect(user).to receive(:respond_to?).with(:name) { false }
expect(user).to receive(:respond_to?).with(:alchemy_display_name) { false }
end

describe "#creator_name" do
Expand Down

0 comments on commit dbed496

Please sign in to comment.