diff --git a/lib/puppet/provider/foreman_resource/rest_v3.rb b/lib/puppet/provider/foreman_resource/rest_v3.rb index d68028a75..cf6b85de2 100644 --- a/lib/puppet/provider/foreman_resource/rest_v3.rb +++ b/lib/puppet/provider/foreman_resource/rest_v3.rb @@ -54,7 +54,7 @@ def generate_token OAuth::AccessToken.new(oauth_consumer) end - def request(method, path, params = {}, data = {}, headers = {}) + def request(method, path, params = {}, data = nil, headers = {}) base_url = resource[:base_url] base_url += '/' unless base_url.end_with?('/') diff --git a/spec/unit/foreman_resource_rest_v3_spec.rb b/spec/unit/foreman_resource_rest_v3_spec.rb index 97dad0c09..af24d70d0 100644 --- a/spec/unit/foreman_resource_rest_v3_spec.rb +++ b/spec/unit/foreman_resource_rest_v3_spec.rb @@ -72,12 +72,18 @@ let(:consumer) { mock('oauth_consumer') } let(:effective_user) { 'admin' } - it 'makes request via consumer and returns response' do + it 'makes GET request via consumer and returns response' do response = mock(:code => '200') consumer.expects(:request).with(:get, 'https://foreman.example.com/api/v2/example', is_a(OAuth::AccessToken), {}, is_a(Hash)).returns(response) expect(provider.request(:get, 'api/v2/example')).to eq(response) end + it 'makes PUT request via consumer and returns response' do + response = mock(:code => '200') + consumer.expects(:request).with(:put, 'https://foreman.example.com/api/v2/example', is_a(OAuth::AccessToken), {}, nil, is_a(Hash)).returns(response) + expect(provider.request(:put, 'api/v2/example')).to eq(response) + end + it 'specifies foreman_user header' do consumer.expects(:request).with(:get, anything, anything, anything, has_entry('foreman_user', 'admin')).returns(mock(:code => '200')) provider.request(:get, 'api/v2/example')