OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub
Ruby agile-developmentangularbcfboardsbug-trackerganttgantt-chartifcissue-trackerjira-alternativekanbanopenprojectproduct-managementproject-managementproject-planningroadmaprubyscrumtimelineworkflows
Fix attachment integration spec
Oliver Günther9e26691db75d
diff --git a/spec/services/attachments/create_service_integration_spec.rb b/spec/services/attachments/create_service_integration_spec.rbindex 135f23d3a7f..ec8c03291f5 100644--- a/spec/services/attachments/create_service_integration_spec.rb+++ b/spec/services/attachments/create_service_integration_spec.rb@@ -29,20 +29,26 @@require 'spec_helper'-describe Attachments::CreateService, 'integration' do- let(:user) { FactoryBot.create(:user) }+describe Attachments::CreateService, 'integration', with_settings: { journal_aggregation_time_minutes: 0 } dolet(:description) { 'a fancy description' }- subject { described_class.new(container, author: user) }+ subject { described_class.new(user: user) }describe '#call' dodef call_tested_method- subject.call uploaded_file: FileHelpers.mock_uploaded_file(name: 'foobar.txt'),+ subject.call container: container,+ file: FileHelpers.mock_uploaded_file(name: 'foobar.txt'),+ filename: 'foobar.txt',description: descriptionendcontext 'when journalized' do- let(:container) { FactoryBot.create(:work_package) }+ shared_let(:container) { FactoryBot.create(:work_package) }+ shared_let(:user) do+ FactoryBot.create :user,+ member_in_project: container.project,+ member_with_permissions: %i[view_work_packages edit_work_packages]+ endshared_examples 'successful creation' doit 'saves the attachment' do@@ -90,26 +96,22 @@ describe Attachments::CreateService, 'integration' doendcontext 'with an invalid attachment', with_settings: { attachment_max_size: 0 } do- it 'raises the exception' do+ it 'does not raise exceptions' doexpect { call_tested_method }- .to raise_exception ActiveRecord::RecordInvalid- end-- it 'does not create the attachment' do- begin- call_tested_method- rescue ActiveRecord::RecordInvalid- # expected- end+ .not_to raise_exception ActiveRecord::RecordInvalid- expect(Attachment.count)- .to eq 0+ expect(call_tested_method.errors[:file]).to include "is too large (maximum size is 0 Bytes)."endendendcontext 'when not journalized' do- let(:container) { FactoryBot.create(:message) }+ shared_let(:container) { FactoryBot.create(:message) }+ shared_let(:user) do+ FactoryBot.create :user,+ member_in_project: container.forum.project,+ member_with_permissions: %i[add_messages edit_messages]+ endshared_examples 'successful creation' doit 'saves the attachment' do@@ -158,6 +160,7 @@ describe Attachments::CreateService, 'integration' docontext "when uncontainered" dolet(:container) { nil }+ let(:user) { FactoryBot.create :admin }before docall_tested_method@@ -169,5 +172,17 @@ describe Attachments::CreateService, 'integration' doexpect(attachment.description).to eq descriptionendend++ context "when user with no permissions" do+ let(:container) { nil }+ let(:user) { FactoryBot.build_stubbed :user }++ it 'does not save an attachment' do+ expect do+ expect(call_tested_method).to be_failure+ expect(call_tested_method.errors[:base]).to include 'may not be accessed.'+ end.not_to change { Attachment.count }+ end+ endendend