From 63f8749130c782ea2bcfe37e329898b74fa5715e Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 6 Sep 2024 13:37:28 +0200 Subject: [PATCH 1/2] Add alchemy_display_name to Spree::User Alchemy uses this to identify users in the admin UI. --- lib/alchemy/solidus/spree_user_extension.rb | 4 ++ spec/models/spree/user_extension_spec.rb | 43 +++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 spec/models/spree/user_extension_spec.rb diff --git a/lib/alchemy/solidus/spree_user_extension.rb b/lib/alchemy/solidus/spree_user_extension.rb index 499189d..8706923 100644 --- a/lib/alchemy/solidus/spree_user_extension.rb +++ b/lib/alchemy/solidus/spree_user_extension.rb @@ -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) diff --git a/spec/models/spree/user_extension_spec.rb b/spec/models/spree/user_extension_spec.rb new file mode 100644 index 0000000..48df90d --- /dev/null +++ b/spec/models/spree/user_extension_spec.rb @@ -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 From a8ee7bef68ab934b2a3c086eef7a6b1ee12d2c7a Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Fri, 6 Sep 2024 15:32:10 +0200 Subject: [PATCH 2/2] CI: Adjust build matrix Reduce the matrix to sane defaults: - Remove Ruby 3.0 - Add Alchemy 7.2 - Remove Solidus 4.0 --- .github/workflows/ci.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 089c9bd..cb94360 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,14 +9,13 @@ 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" @@ -24,7 +23,7 @@ jobs: 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: