spec/models/entity_spec.rb in maestrano-connector-rails-0.2.11 vs spec/models/entity_spec.rb in maestrano-connector-rails-0.2.12
- old
+ new
@@ -225,16 +225,24 @@
end
end
context 'when entity has no idmap' do
let(:entity) { {'id' => id, 'name' => 'John', 'updated_at' => 5.hour.ago } }
+ before {
+ allow(subject).to receive(:object_name_from_connec_entity_hash).and_return('human readable stuff')
+ }
it { expect{ subject.map_to_external_with_idmap(entity, organization) }.to change{Maestrano::Connector::Rails::IdMap.count}.by(1) }
it 'returns the entity with its new idmap' do
expect(subject.map_to_external_with_idmap(entity, organization)).to eql({entity: mapped_entity, idmap: Maestrano::Connector::Rails::IdMap.last})
end
+
+ it 'save the entity name in the idmap' do
+ subject.map_to_external_with_idmap(entity, organization)
+ expect(Maestrano::Connector::Rails::IdMap.last.name).to eql('human readable stuff')
+ end
end
end
end
@@ -358,14 +366,24 @@
allow(subject).to receive(:connec_entity_name).and_return(connec_name)
allow(subject).to receive(:map_to_connec).and_return(mapped_entity)
}
context 'when entity has no idmap' do
+ let(:human_name) { 'alien' }
+ before {
+ allow(subject).to receive(:object_name_from_external_entity_hash).and_return(human_name)
+ }
+
it 'creates an idmap and returns the mapped entity with its new idmap' do
subject.consolidate_and_map_data([], entities, organization)
expect(entities).to eql([{entity: mapped_entity, idmap: Maestrano::Connector::Rails::IdMap.last}])
end
+
+ it 'save the name in the idmap' do
+ subject.consolidate_and_map_data([], entities, organization)
+ expect(Maestrano::Connector::Rails::IdMap.last.name).to eql(human_name)
+ end
end
context 'when entity has an idmap with a last_push_to_connec more recent than date' do
let!(:idmap) { create(:idmap, external_entity: external_name, external_id: id, organization: organization, last_push_to_connec: 2.minute.ago) }
@@ -449,9 +467,17 @@
it { expect{ subject.external_entity_name }.to raise_error('Not implemented') }
end
describe 'mapper_class' do
it { expect{ subject.mapper_class }.to raise_error('Not implemented') }
+ end
+
+ describe 'object_name_from_connec_entity_hash' do
+ it { expect{ subject.object_name_from_connec_entity_hash({}) }.to raise_error('Not implemented') }
+ end
+
+ describe 'object_name_from_external_entity_hash' do
+ it { expect{ subject.object_name_from_external_entity_hash({}) }.to raise_error('Not implemented') }
end
end
end
\ No newline at end of file