diff --git a/core/lib/spree/core.rb b/core/lib/spree/core.rb index c9ca87e1198..e5c3fe42794 100644 --- a/core/lib/spree/core.rb +++ b/core/lib/spree/core.rb @@ -39,6 +39,10 @@ def self.user_class end end + def self.user_class_name + @@user_class + end + # Load the same version defaults for all available Solidus components # # @see Spree::Preferences::Configuration#load_defaults diff --git a/core/lib/spree/user_class_handle.rb b/core/lib/spree/user_class_handle.rb index 9df1da303a2..8e01cd83446 100644 --- a/core/lib/spree/user_class_handle.rb +++ b/core/lib/spree/user_class_handle.rb @@ -21,8 +21,8 @@ class UserClassHandle # @return [String] the name of the user class as a string. # @raise [RuntimeError] if Spree.user_class is nil def to_s - fail "'Spree.user_class' has not been set yet." unless Spree.user_class - "::#{Spree.user_class}" + fail "'Spree.user_class' has not been set yet." unless Spree.user_class_name + "::#{Spree.user_class_name}" end end end diff --git a/core/spec/lib/spree/user_class_handle_spec.rb b/core/spec/lib/spree/user_class_handle_spec.rb new file mode 100644 index 00000000000..b9055b9062d --- /dev/null +++ b/core/spec/lib/spree/user_class_handle_spec.rb @@ -0,0 +1,37 @@ +# frozen_string_literal: true + +require "spec_helper" +require "spree/core" +require "spree/user_class_handle" + +RSpec.describe Spree::UserClassHandle do + describe "#to_s" do + around do |example| + @prev_user_class = Spree.user_class_name + example.run + Spree.user_class = @prev_user_class + end + + subject { described_class.new.to_s } + + context "when Spree.user_class is nil" do + before do + Spree.user_class = nil + end + + it "is expected to fail" do + expect { subject }.to raise_error(RuntimeError, "'Spree.user_class' has not been set yet.") + end + end + + context "when Spree.user_class is not nil" do + before do + Spree.user_class = "Spree::User" + end + + it "is expected to return the user class as a string" do + expect(subject).to eq("::Spree::User") + end + end + end +end