-
-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
142 additions
and
13 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
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,46 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rake' | ||
|
||
module TaskHelper | ||
module WorldMethods | ||
def described_task = self.class.metadata[:description_args].first | ||
def run_task(name, *args, &) | ||
task = Rake::Task[name] | ||
|
||
# Ensure task is re-enabled, as Rake tasks are disabled by default | ||
# after running once within a process. | ||
task.reenable | ||
|
||
task.invoke(*args) | ||
|
||
if block_given? | ||
instance_exec(&) | ||
end | ||
end | ||
end | ||
|
||
module ScenarioMethods | ||
def described_task = metadata[:description_args].first | ||
def with_task(name, *args, &) | ||
context "with #{name} Rake task" do | ||
let(:task) { | ||
task = Rake::Task[name] | ||
|
||
# Ensure task is re-enabled, as Rake tasks are disabled by default | ||
# after running once within a process. | ||
task.reenable | ||
|
||
task | ||
} | ||
|
||
instance_exec(&) | ||
end | ||
end | ||
end | ||
|
||
def self.included(klass) | ||
klass.include WorldMethods | ||
klass.extend ScenarioMethods | ||
end | ||
end |
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,72 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'rails_helper' | ||
require 'spec_helper' | ||
|
||
describe 'keygen:permissions:add', type: :task do | ||
let(:account) { create(:account) } | ||
|
||
it 'should add permissions to licenses' do | ||
licenses = create_list(:license, 5, | ||
permissions: License.default_permissions - %w[package.read], | ||
account:, | ||
) | ||
|
||
run_task described_task, :license, licenses.first.id, licenses.third.id, 'package.read' do | ||
expect(licenses.first).to have_permissions 'package.read' | ||
expect(licenses.second).to_not have_permissions 'package.read' | ||
expect(licenses.third).to have_permissions 'package.read' | ||
expect(licenses.fourth).to_not have_permissions 'package.read' | ||
expect(licenses.fifth).to_not have_permissions 'package.read' | ||
end | ||
end | ||
|
||
it 'should add permissions to licenses with default permissions' do | ||
licenses = create_list(:license, 5, | ||
permissions: License.default_permissions - %w[package.read], | ||
account:, | ||
) | ||
|
||
run_task described_task, :license, *licenses.collect(&:id), 'package.read' do | ||
licenses.each do |license| | ||
expect(license).to have_permissions 'package.read' | ||
end | ||
end | ||
end | ||
|
||
it 'should not add permissions to licenses with custom permissions' do | ||
licenses = create_list(:license, 5, | ||
permissions: %w[license.validate license.read], | ||
account:, | ||
) | ||
|
||
run_task described_task, :license, *licenses.collect(&:id), 'machine.create' do | ||
licenses.each do |license| | ||
expect(license).to_not have_permissions 'machine.create' | ||
end | ||
end | ||
end | ||
|
||
it 'should not add permissions to licenses that are not allowed' do | ||
licenses = create_list(:license, 5, | ||
permissions: License.default_permissions, | ||
account:, | ||
) | ||
|
||
run_task described_task, :license, *licenses.collect(&:id), 'license.create' do | ||
licenses.each do |license| | ||
expect(license).to_not have_permissions 'license.create' | ||
end | ||
end | ||
end | ||
|
||
it 'should raise for model without role permissions' do | ||
tokens = create_list(:token, 5, | ||
permissions: License.default_permissions, | ||
account:, | ||
) | ||
|
||
expect { run_task described_task, :token, *tokens.collect(&:id), 'product.create' } | ||
.to raise_error ActiveRecord::AssociationNotFoundError | ||
end | ||
end |