|
|
@ -42,45 +42,57 @@ describe AddAttachmentService do |
|
|
|
description: description |
|
|
|
description: description |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context 'happy path' do |
|
|
|
shared_examples 'successful creation' do |
|
|
|
before do |
|
|
|
it 'saves the attachment' do |
|
|
|
call_tested_method |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it 'should save the attachment' do |
|
|
|
|
|
|
|
attachment = Attachment.first |
|
|
|
attachment = Attachment.first |
|
|
|
expect(attachment.filename).to eq 'foobar.txt' |
|
|
|
expect(attachment.filename).to eq 'foobar.txt' |
|
|
|
expect(attachment.description).to eq description |
|
|
|
expect(attachment.description).to eq description |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'should add the attachment to the WP' do |
|
|
|
it 'adds the attachment to the WP' do |
|
|
|
work_package.reload |
|
|
|
work_package.reload |
|
|
|
expect(work_package.attachments).to include Attachment.first |
|
|
|
expect(work_package.attachments).to include Attachment.first |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'should add a journal entry on the WP' do |
|
|
|
it 'adds a journal entry on the WP' do |
|
|
|
expect(work_package.journals.count).to eq 2 # 1 for WP creation + 1 for the attachment |
|
|
|
expect(work_package.journals.count).to eq 2 # 1 for WP creation + 1 for the attachment |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context "can't save work package" do |
|
|
|
context 'happy path' do |
|
|
|
|
|
|
|
before do |
|
|
|
|
|
|
|
call_tested_method |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'successful creation' |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
context "invalid container" do |
|
|
|
before do |
|
|
|
before do |
|
|
|
allow(work_package).to receive(:save!) |
|
|
|
# have an invalid work package |
|
|
|
.and_raise(ActiveRecord::RecordInvalid.new(work_package)) |
|
|
|
work_package.subject = '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
call_tested_method |
|
|
|
|
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it_behaves_like 'successful creation' |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'should raise the exception' do |
|
|
|
context 'invalid attachment', with_settings: { attachment_max_size: 0 } do |
|
|
|
expect { call_tested_method }.to raise_error ActiveRecord::RecordInvalid |
|
|
|
it 'raises the exception' do |
|
|
|
|
|
|
|
expect { call_tested_method } |
|
|
|
|
|
|
|
.to raise_exception ActiveRecord::RecordInvalid |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'should not save the attachment' do |
|
|
|
it 'does not create the attachment' do |
|
|
|
begin |
|
|
|
begin |
|
|
|
call_tested_method |
|
|
|
call_tested_method |
|
|
|
rescue ActiveRecord::RecordInvalid |
|
|
|
rescue ActiveRecord::RecordInvalid |
|
|
|
# we expect that to happen |
|
|
|
# expected |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
expect(Attachment.count).to eq 0 |
|
|
|
expect(Attachment.count) |
|
|
|
|
|
|
|
.to eq 0 |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|