2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2017-08-14 11:56:23 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Sequencer::Unit::Common::AttributeMapper, sequencer: :unit do
|
|
|
|
|
2017-10-01 12:25:52 +00:00
|
|
|
let(:map) do
|
2017-08-14 11:56:23 +00:00
|
|
|
{
|
|
|
|
old_key: :new_key,
|
|
|
|
second: :new_second,
|
|
|
|
}
|
2017-10-01 12:25:52 +00:00
|
|
|
end
|
2017-08-14 11:56:23 +00:00
|
|
|
|
|
|
|
it 'expects an implementation of the .map method' do
|
|
|
|
expect do
|
|
|
|
described_class.map
|
|
|
|
end.to raise_error(RuntimeError)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'declares uses from map keys' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(described_class).to receive(:map).and_return(map)
|
2017-08-14 11:56:23 +00:00
|
|
|
expect(described_class.uses).to eq(map.keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'declares provides from map values' do
|
2020-10-22 13:57:01 +00:00
|
|
|
allow(described_class).to receive(:map).and_return(map)
|
2017-08-14 11:56:23 +00:00
|
|
|
expect(described_class.provides).to eq(map.values)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'maps as configured' do
|
|
|
|
|
|
|
|
old = {
|
|
|
|
old_key: :value,
|
|
|
|
second: :second_value,
|
|
|
|
}
|
|
|
|
|
|
|
|
allow(described_class).to receive(:map).and_return(map)
|
|
|
|
result = process(old)
|
|
|
|
|
|
|
|
expect(result.keys.size).to eq 2
|
|
|
|
expect(result[:new_key]).to eq old[:old_key]
|
|
|
|
expect(result[:new_second]).to eq old[:second]
|
|
|
|
end
|
|
|
|
end
|