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

Changes for generic object method calls via REST API. #74

Merged
merged 2 commits into from
Oct 4, 2017
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ def self.clear_stored_workspace
def self.instantiate(uri, user, attrs = {})
User.current_user = user
workspace = MiqAeWorkspaceRuntime.new(attrs)
workspace.instantiate(uri, user, nil)
self.current = workspace
workspace.instantiate(uri, user, nil)
workspace
rescue MiqAeException
ensure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ def remove_from_service(service)
private

def ae_user_identity
@ae_user = MiqAeEngine::DrbRemoteInvoker.workspace.ae_user
workspace = MiqAeEngine::MiqAeWorkspaceRuntime.current || MiqAeEngine::DrbRemoteInvoker.workspace
raise 'Workspace not found when running generic object' unless workspace
@ae_user = workspace.ae_user
ar_method { @object.ae_user_identity(@ae_user, @ae_user.current_group, @ae_user.current_tenant) }
end

Expand Down
45 changes: 30 additions & 15 deletions spec/service_models/miq_ae_service_generic_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,38 @@ module MiqAeServiceGenericObjectSpec
end

describe "call method on generic object" do
before do
allow(MiqAeEngine::DrbRemoteInvoker).to receive('workspace').and_return(workspace)
shared_examples_for "calls into automate" do
it "runs successfully" do
options = {
:object_type => "GenericObject",
:object_id => go.id,
:instance_name => "GenericObject",
:user_id => user.id,
:miq_group_id => user.current_group.id,
:tenant_id => user.current_tenant.id,
:attrs => {:method_name => method_name}
}
svc_obj = MiqAeMethodService::MiqAeServiceGenericObject.find(go.id)
expect(MiqAeEngine).to receive('deliver').with(options).and_return(workspace)

svc_obj.send(method_name)
end
end

context "from Drb method" do
before do
allow(MiqAeEngine::DrbRemoteInvoker).to receive('workspace').and_return(workspace)
end

it_behaves_like "calls into automate"
end

it "calls into automate" do
options = { :object_type => "GenericObject",
:object_id => go.id,
:instance_name => "GenericObject",
:user_id => user.id,
:miq_group_id => user.current_group.id,
:tenant_id => user.current_tenant.id,
:attrs => {:method_name => method_name}
}
svc_obj = MiqAeMethodService::MiqAeServiceGenericObject.find(go.id)
expect(MiqAeEngine).to receive('deliver').with(options).and_return(workspace)

svc_obj.send(method_name)
context "from workspace engine" do
before do
allow(MiqAeEngine::MiqAeWorkspaceRuntime).to receive('current').and_return(workspace)
end

it_behaves_like "calls into automate"
end
end

Expand Down