Add model spec

pull/7924/head
Oliver Günther 5 years ago committed by Wieland Lindenthal
parent 84b4feb1f3
commit fdbe56e00c
  1. 41
      modules/ifc_models/spec/models/ifc_model_spec.rb

@ -0,0 +1,41 @@
require 'spec_helper'
describe ::IFCModels::IFCModel, type: :model do
subject { described_class.new params }
let(:params) { { title: 'foo', is_default: true } }
describe 'converted?' do
let(:attachment) { FactoryBot.build :attachment }
it 'is converted when xkt and metadata attachments are present' do
expect(subject).not_to be_converted
allow(subject).to receive(:xkt_attachment).and_return(attachment)
allow(subject).to receive(:metadata_attachment).and_return(attachment)
expect(subject).to be_converted
end
end
describe 'ifc_attachment=' do
subject { FactoryBot.create :ifc_model_converted }
let(:ifc_attachment) { subject.ifc_attachment }
let(:new_attachment) {
FileHelpers.mock_uploaded_file name: "model.ifc", content_type: 'application/binary', binary: true
}
it 'replaces the previous attachment' do
expect(ifc_attachment).to be_present
expect(subject.xkt_attachment).to be_present
expect(subject.metadata_attachment).to be_present
expect(subject).to be_converted
subject.ifc_attachment = new_attachment
expect { ifc_attachment.reload }.to raise_error(ActiveRecord::RecordNotFound)
expect(subject.ifc_attachment).not_to eq ifc_attachment
expect(subject.ifc_attachment).not_to be_present
expect(subject.xkt_attachment).not_to be_present
expect(subject).not_to be_converted
end
end
end
Loading…
Cancel
Save