2016-07-18 08:15:01 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2018-11-29 06:44:48 -05:00
|
|
|
describe Gitlab::Config::Entry::Attributable do
|
2017-08-25 12:26:55 -04:00
|
|
|
let(:node) do
|
|
|
|
Class.new do
|
2018-11-29 06:44:48 -05:00
|
|
|
include Gitlab::Config::Entry::Attributable
|
2017-08-25 12:26:55 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-07-18 08:15:01 -04:00
|
|
|
let(:instance) { node.new }
|
|
|
|
|
|
|
|
before do
|
|
|
|
node.class_eval do
|
|
|
|
attributes :name, :test
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-25 12:26:55 -04:00
|
|
|
context 'when config is a hash' do
|
2016-07-18 08:15:01 -04:00
|
|
|
before do
|
|
|
|
allow(instance)
|
|
|
|
.to receive(:config)
|
|
|
|
.and_return({ name: 'some name', test: 'some test' })
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the value of config' do
|
|
|
|
expect(instance.name).to eq 'some name'
|
|
|
|
expect(instance.test).to eq 'some test'
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns no method error for unknown attributes' do
|
|
|
|
expect { instance.unknown }.to raise_error(NoMethodError)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-08-25 12:26:55 -04:00
|
|
|
context 'when config is not a hash' do
|
2016-07-18 08:15:01 -04:00
|
|
|
before do
|
|
|
|
allow(instance)
|
|
|
|
.to receive(:config)
|
|
|
|
.and_return('some test')
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
expect(instance.test).to be_nil
|
|
|
|
end
|
|
|
|
end
|
2017-08-25 12:26:55 -04:00
|
|
|
|
|
|
|
context 'when method is already defined in a superclass' do
|
|
|
|
it 'raises an error' do
|
|
|
|
expectation = expect do
|
|
|
|
Class.new(String) do
|
2018-11-29 06:44:48 -05:00
|
|
|
include Gitlab::Config::Entry::Attributable
|
2017-08-25 12:26:55 -04:00
|
|
|
|
|
|
|
attributes :length
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
expectation.to raise_error(ArgumentError, 'Method already defined!')
|
|
|
|
end
|
|
|
|
end
|
2016-07-18 08:15:01 -04:00
|
|
|
end
|