-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Do not constantize Spree.user_class in UserClassHandle
`Spree.user_class` will constantize the configured user class. If called during Rails start-up, this will autoload the configured user class, which is not necessarily desired. We can do without the autoloading by directly getting the class variable rather than going through `Spree.user_class`. After review I've added a `Spree.user_class_name` method as well that returns the string, and added a test for the `Spree::UserClassHandle` class.
- Loading branch information
Showing
3 changed files
with
43 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |