Skip to content

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

refactor: factorize common code

Christophe Bliard3d366c3f828d
diff --git a/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb b/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb
index 2599654d919..1deb3f60078 100644
--- a/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb
+++ b/modules/storages/spec/contracts/storages/project_storages/create_contract_spec.rb
@@ -51,29 +51,24 @@ describe Storages::ProjectStorages::CreateContract do
end
context 'when checking creator_id' do
- let(:current_user) { create(:admin) }
- let(:other_user) { create(:user) }
+ let(:contract) { described_class.new(project_storage, current_user) }
+ let(:project_storage) { build(:project_storage, creator: creator) }
+ let(:current_user) { build_stubbed(:admin) }
- context 'as creator_id == user_id' do
- let(:project_storage) { create(:project_storage, creator: current_user) }
- let(:contract) { described_class.new(project_storage, current_user) }
+ before do
+ login_as(current_user)
+ end
- before do
- login_as(current_user)
- end
+ context 'as creator_id == current_user_id' do
+ let(:creator) { current_user }
it_behaves_like 'contract is valid'
end
- context 'as creator_id != user_id' do
- let(:project_storage) { create(:project_storage, creator: other_user) }
- let(:contract) { described_class.new(project_storage, current_user) }
-
- before do
- login_as(current_user)
- end
+ context 'as creator_id != current_user_id' do
+ let(:creator) { build_stubbed(:user) }
- it_behaves_like 'contract is invalid'
+ it_behaves_like 'contract is invalid', creator: :invalid
end
end
end