Commit fba990f3 authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre

Merge branch 'instance-metadata-model' into 'master'

Wrap instance metadata in a model so that it can have a policy

See merge request gitlab-org/gitlab!47243
parents 61aec427 41f99dc6
......@@ -5,7 +5,7 @@ module Resolvers
type Types::MetadataType, null: false
def resolve(**args)
{ version: Gitlab::VERSION, revision: Gitlab.revision }
::InstanceMetadata.new
end
end
end
# frozen_string_literal: true
class InstanceMetadata
attr_reader :version, :revision
def initialize(version: Gitlab::VERSION, revision: Gitlab.revision)
@version = version
@revision = revision
end
end
# frozen_string_literal: true
class InstanceMetadataPolicy < BasePolicy
delegate { :global }
end
......@@ -7,7 +7,7 @@ RSpec.describe Resolvers::MetadataResolver do
describe '#resolve' do
it 'returns version and revision' do
expect(resolve(described_class)).to eq(version: Gitlab::VERSION, revision: Gitlab.revision)
expect(resolve(described_class)).to have_attributes(version: Gitlab::VERSION, revision: Gitlab.revision)
end
end
end
# frozen_string_literal: true
require 'fast_spec_helper'
RSpec.describe InstanceMetadata do
it 'has the correct properties' do
expect(subject).to have_attributes(
version: Gitlab::VERSION,
revision: Gitlab.revision
)
end
end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe InstanceMetadataPolicy do
subject { described_class.new(user, InstanceMetadata.new) }
context 'for any logged-in user' do
let(:user) { create(:user) }
specify { expect_allowed(:read_instance_metadata) }
end
context 'for anonymous users' do
let(:user) { nil }
specify { expect_disallowed(:read_instance_metadata) }
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