-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from tvdeyen/add-alchemy_display_name
Add alchemy_display_name to Spree::User
- Loading branch information
Showing
3 changed files
with
49 additions
and
3 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,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 |