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

Add alchemy_display_name to Spree::User #113

Merged
merged 2 commits 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
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: "[email protected]") }

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 "[email protected]"
end
end
end
end