diff --git a/lib/ansible_tower_client/base_models/credential.rb b/lib/ansible_tower_client/base_models/credential.rb index 8d3ced9..f4f72f4 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