Return env var's value if it's public

This commit is contained in:
Piotr Sarnacki 2014-07-16 11:54:31 +02:00
parent 2e8fc35e13
commit cc291446f5
2 changed files with 33 additions and 1 deletions

View File

@ -3,7 +3,19 @@ module Travis
module V2
module Http
class EnvVar < Travis::Api::Serializer
attributes :id, :name, :public
attributes :id, :name, :value, :public
def value
if object.public?
object.value.decrypt
end
end
def serializable_hash
hash = super
hash.delete :value unless object.public?
hash
end
end
end
end

View File

@ -0,0 +1,20 @@
require 'spec_helper'
describe Travis::Api::V2::Http::EnvVar do
let(:env_var) { Repository::Settings::EnvVar.new(name: 'FOO', value: 'bar', public: true) }
let(:data) { Travis::Api::V2::Http::EnvVar.new(env_var) }
it 'returns value' do
data.as_json[:env_var][:value].should == 'bar'
end
describe 'private' do
let(:env_var) { Repository::Settings::EnvVar.new(name: 'FOO', value: 'bar', public: false) }
it "doesn't return the value" do
data.to_json.should_not include('bar')
data.as_json[:env_var].should_not have_key(:value)
data.as_json[:env_var].should_not have_key('value')
end
end
end