Skip to content

Commit

Permalink
Add alchemy_display_name to Spree::User
Browse files Browse the repository at this point in the history
Alchemy uses this to identify users in the admin UI.
  • Loading branch information
tvdeyen committed Sep 6, 2024
1 parent f64c8a9 commit 63f8749
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/alchemy/solidus/spree_user_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ def self.included(klass)
klass.has_many :folded_pages, class_name: "Alchemy::FoldedPage"
end

def alchemy_display_name
email
end

def alchemy_roles
if has_spree_role?(:admin)
%w(admin)
Expand Down
43 changes: 43 additions & 0 deletions spec/models/spree/user_extension_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# frozen_string_literal: true

require "rails_helper"
require "alchemy/solidus/spree_user_extension"

RSpec.describe Alchemy::Solidus::SpreeUserExtension, type: :model do
let(:spree_user) do
Class.new(ActiveRecord::Base) do
def self.name
"Spree::User"
end

def has_spree_role?(_role)
false
end

include Alchemy::Solidus::SpreeUserExtension
end
end

let(:user) { spree_user.new(email: "spree@example.com") }

describe "#alchemy_roles" do
context "when user is an admin" do
it "returns an array with the admin role" do
allow(user).to receive(:has_spree_role?).with(:admin).and_return(true)
expect(user.alchemy_roles).to eq %w[admin]
end
end

context "when user is not an admin" do
it { expect(user.alchemy_roles).to be_empty }
end
end

describe "#alchemy_display_name" do
context "when user is not an admin" do
it "returns user's email" do
expect(user.alchemy_display_name).to eq "spree@example.com"
end
end
end
end

0 comments on commit 63f8749

Please sign in to comment.