Skip to content

Commit

Permalink
Merge pull request #74 from lfu/go_method_call_via_api
Browse files Browse the repository at this point in the history
Changes for generic object method calls via REST API.
  • Loading branch information
mkanoor authored Oct 4, 2017
2 parents 19843aa + 16fe96e commit 7d0268f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 17 deletions.
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

0 comments on commit 7d0268f

Please sign in to comment.