Skip to content

Commit

Permalink
Merge pull request ManageIQ#16120 from jntullo/go_set_current_user
Browse files Browse the repository at this point in the history
Set current user for generic object methods
  • Loading branch information
mkanoor authored Oct 6, 2017
2 parents 248dce6 + 53faffd commit c312d93
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions app/models/generic_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ def _property_setter(name, value)
# {:param_1 => 12, :param_1_type => "Vm", :param_2 => 14, :param_2_type => "Integer"}
# the return value from automate is in $evm.root['method_result']
def _call_automate(method_name, *args)
@user ||= User.current_user
@group ||= User.current_user.current_group
@tenant ||= User.current_user.current_tenant
raise "A user is required to send [#{method_name}] to automate." unless @user

attrs = { :method_name => method_name }
Expand Down
16 changes: 15 additions & 1 deletion spec/models/generic_object_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
let(:data_read) { 345.67 }
let(:s_time) { Time.now.utc }
let(:vm1) { FactoryGirl.create(:vm_vmware) }
let(:user) { FactoryGirl.create(:user_with_group) }

let(:definition) do
FactoryGirl.create(
Expand Down Expand Up @@ -172,7 +173,6 @@

describe 'property methods' do
let(:ws) { double("MiqAeWorkspaceRuntime", :root => {"method_result" => "some_return_value"}) }
let(:user) { FactoryGirl.create(:user_with_group) }

before { go.ae_user_identity(user) }

Expand Down Expand Up @@ -231,6 +231,20 @@
end
end

describe 'property methods without user set' do
it 'will set the current user' do
workspace = double("MiqAeWorkspaceRuntime", :root => {"method_result" => "result"})

options = {
:user_id => user.id,
:miq_group_id => user.current_group.id,
:tenant_id => user.current_tenant.id
}
expect(MiqAeEngine).to receive(:deliver).with(hash_including(options)).and_return(workspace)
User.with_user_group(user, user.current_group) { go.my_host }
end
end

describe '#delete_property' do
it 'an attriute' do
max = go.max_number
Expand Down

0 comments on commit c312d93

Please sign in to comment.