Skip to content

Commit

Permalink
Merge pull request #113 from tvdeyen/add-alchemy_display_name
Browse files Browse the repository at this point in the history
Add alchemy_display_name to Spree::User
  • Loading branch information
tvdeyen authored Sep 6, 2024
2 parents f64c8a9 + a8ee7be commit e5aa847
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,21 @@ jobs:
fail-fast: false
matrix:
ruby-version:
- "3.0"
- "3.1"
- "3.2"
- "3.3"
alchemy:
- "7.2-stable"
- "main"
solidus:
- "4.0"
- "4.1"
- "4.2"
- "4.3"
env:
ALCHEMY_VERSION: ${{ matrix.alchemy }}
SOLIDUS_VERSION: ${{ matrix.solidus }}
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
Expand Down
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 e5aa847

Please sign in to comment.