diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-19 23:18:09 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-09-19 23:18:09 +0000 |
commit | 6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde (patch) | |
tree | dc4d20fe6064752c0bd323187252c77e0a89144b /spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb | |
parent | 9868dae7fc0655bd7ce4a6887d4e6d487690eeed (diff) | |
download | gitlab-ce-6ed4ec3e0b1340f96b7c043ef51d1b33bbe85fde.tar.gz |
Add latest changes from gitlab-org/gitlab@15-4-stable-eev15.4.0-rc42
Diffstat (limited to 'spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb')
-rw-r--r-- | spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb b/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb index d40be0e841c..43f0198704f 100644 --- a/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb +++ b/spec/lib/gitlab/github_import/representation/expose_attribute_spec.rb @@ -1,21 +1,41 @@ # frozen_string_literal: true -require 'spec_helper' +require 'fast_spec_helper' RSpec.describe Gitlab::GithubImport::Representation::ExposeAttribute do - it 'defines a getter method that returns an attribute value' do - klass = Class.new do + let(:klass) do + Class.new do include Gitlab::GithubImport::Representation::ExposeAttribute expose_attribute :number attr_reader :attributes - def initialize - @attributes = { number: 42 } + def initialize(attributes) + @attributes = attributes + end + end + end + + it 'defines a getter method that returns an attribute value' do + expect(klass.new({ number: 42 }).number).to eq(42) + end + + describe '#[]' do + it 'returns exposed attributes value using array notation' do + expect(klass.new({ number: 42 })[:number]).to eq(42) + end + + context 'when attribute does not exist' do + it 'returns nil' do + expect(klass.new({})[:number]).to eq(nil) end end - expect(klass.new.number).to eq(42) + context 'when attribute is not exposed' do + it 'returns nil' do + expect(klass.new({ not_exposed_attribute: 42 })[:not_exposed_attribute]).to eq(nil) + end + end end end |