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

[7.0-stable] Use alchemy_display_name for page actor names #3028

Merged
merged 1 commit into from
Sep 6, 2024
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
6 changes: 3 additions & 3 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,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 @@ -555,7 +555,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 @@ -564,7 +564,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 @@ -1890,7 +1890,7 @@ def copy_children_to(new_parent)
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 @@ -1918,7 +1918,7 @@ def copy_children_to(new_parent)
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 @@ -1946,11 +1946,11 @@ def copy_children_to(new_parent)
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
Loading