From a95c94949bed096e709d5732a0839d7b89dc3ade Mon Sep 17 00:00:00 2001 From: Marcel Hild Date: Mon, 24 Apr 2017 21:09:13 +0200 Subject: [PATCH] translate organization_id to organization --- lib/ansible_tower_client/base_models/credential.rb | 3 +++ spec/credential_spec.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/ansible_tower_client/base_models/credential.rb b/lib/ansible_tower_client/base_models/credential.rb index 8d3ced9..4045529 100644 --- a/lib/ansible_tower_client/base_models/credential.rb +++ b/lib/ansible_tower_client/base_models/credential.rb @@ -1,4 +1,7 @@ module AnsibleTowerClient class Credential < BaseModel + def override_raw_attributes + { :organization => :organization_id } + end end end diff --git a/spec/credential_spec.rb b/spec/credential_spec.rb index 05e6a2d..b6e7890 100644 --- a/spec/credential_spec.rb +++ b/spec/credential_spec.rb @@ -18,4 +18,16 @@ expect(obj.username).to be_a String expect(obj.name).to be_a String end + + context 'override_raw_attributes' do + let(:obj) { described_class.new(instance_double("Faraday::Connection"), raw_instance) } + let(:instance_api) { obj.instance_variable_get(:@api) } + + it 'translates :organization to :organization_id for update_attributes' do + raw_instance[:organization_id] = 10 + expect(instance_api).to receive(:patch).and_return(instance_double("Faraday::Result", :body => raw_instance.to_json)) + expect(obj.update_attributes(:organization => '5')).to eq true + expect(obj.organization_id).to eq '5' + end + end end