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

Tolerate missing permission set classes #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 7 additions & 1 deletion app/models/spree/role_decorator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
after_save :assign_permissions

def permission_sets_constantized
permission_sets.map(&:set).map(&:constantize)
permission_sets.map(&:set).map { |set_class_name|
begin
set_class_name.constantize
rescue NameError
nil
end
}.compact
end

def assign_permissions
Expand Down
19 changes: 19 additions & 0 deletions spec/models/spree/role_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,25 @@
role
}

context "#permission_sets_constantized" do
context "when a permission set does not exist" do
let(:role) {
role = create(:role)
role.permission_sets = [permission_set, ghost_permission_set]
role
}
let(:permission_set) { create(:permission_set) }
let(:ghost_permission_set) {
create(:permission_set, name: 'WidgetDisplay', set: 'Spree::PermissionSets::WidgetDisplay')
}

it 'returns the remaining permission set classes' do
expect(role.permission_sets_constantized.count).to eq(1)
end
end

end

context "#assign_permissions" do
it 'creates new Spree::RoleConfiguration::Role' do
if SolidusSupport.solidus_gem_version < Gem::Version.new('2.5.x')
Expand Down