Commit 601fba38 authored by Matija Čupić's avatar Matija Čupić

Add EE specific VariableEntity logic

parent 79619560
class VariableEntity < Grape::Entity
prepend ::EE::VariableEntity
expose :id
expose :key
expose :value
......
module EE
module VariableEntity
extend ActiveSupport::Concern
prepended do
expose :environment_scope, if: ->(variable, options) { variable.project.feature_available?(:variable_environment_scope) }
end
end
end
require 'spec_helper'
describe VariableEntity do
let(:variable) { create(:ci_variable) }
let(:entity) { described_class.new(variable) }
describe '#as_json' do
subject { entity.as_json }
context 'when project has variable environment scopes available' do
before do
allow(variable.project).to receive(:feature_available?).with(:variable_environment_scope).and_return(true)
end
it 'contains the environment_scope field' do
expect(subject).to include(:environment_scope)
end
end
context 'when project does not have variable environment scopes available' do
before do
allow(variable.project).to receive(:feature_available?).with(:variable_environment_scope).and_return(false)
end
it 'does not contain the environment_scope field' do
expect(subject).not_to include(:environment_scope)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment