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
Add specs for moving callbacks from AAC patch to the contract.
Dombi Attila69b146e82f29
diff --git a/spec/models/projects/customizable_spec.rb b/spec/models/projects/customizable_spec.rbindex 6dc4d64fe22..2f47c31bec8 100644--- a/spec/models/projects/customizable_spec.rb+++ b/spec/models/projects/customizable_spec.rb@@ -429,45 +429,4 @@ RSpec.describe Project, "customizable" doit_behaves_like "implicitly enabled and saved custom values"endend-- context "with hidden custom fields" do- let!(:hidden_custom_field) do- create(:text_project_custom_field, project_custom_field_section: section, visible: false)- end- let(:project) do- create(:project, custom_field_values: {- text_custom_field.id => "foo",- bool_custom_field.id => true,- hidden_custom_field.id => "hidden"- })- end-- before do- User.current = user # needs to be executed before project creation!- end-- context "with admin permission" do- let(:user) { create(:admin) }-- it "does activate hidden custom fields" do- # project creation happens with an admin user as let(:project) called after setting the current user to an admin- expect(project.project_custom_field_project_mappings.pluck(:custom_field_id))- .to contain_exactly(text_custom_field.id, bool_custom_field.id, hidden_custom_field.id)-- expect(project.custom_value_for(hidden_custom_field).typed_value).to eq("hidden")- end- end-- context "without admin permission" do- let(:user) { create(:user) }-- it "does not activate hidden custom fields" do- # project creation happens with an non-admin user as let(:project) called after setting the current user to an non-admin- expect(project.project_custom_field_project_mappings.pluck(:custom_field_id))- .to contain_exactly(text_custom_field.id, bool_custom_field.id)-- expect(project.custom_value_for(hidden_custom_field)).to be_nil- end- end- endenddiff --git a/spec/services/base_services/behaves_like_create_service.rb b/spec/services/base_services/behaves_like_create_service.rbindex 8ac45393273..22ff7db435c 100644--- a/spec/services/base_services/behaves_like_create_service.rb+++ b/spec/services/base_services/behaves_like_create_service.rb@@ -56,6 +56,9 @@ RSpec.shared_examples "BaseServices create service" doendlet!(:model_instance) { build_stubbed(factory) }let!(:set_attributes_service) do+ # Do not stub the SetAttributesService when the model is not stubbed+ next unless stub_model_instance+service = double("set_attributes_service_instance")allow(set_attributes_class)@@ -75,10 +78,11 @@ RSpec.shared_examples "BaseServices create service" dolet(:model_save_result) { true }let(:contract_validate_result) { true }+ let(:stub_model_instance) { true }before doallow(model_instance).to receive(:save).and_return(model_save_result)- allow(instance).to receive(:instance).and_return(model_instance)+ allow(instance).to receive(:instance).and_return(model_instance) if stub_model_instanceendsubject { instance.call(call_attributes) }diff --git a/spec/services/projects/create_service_spec.rb b/spec/services/projects/create_service_spec.rbindex 24cc058eac2..b4dd2aa38e0 100644--- a/spec/services/projects/create_service_spec.rb+++ b/spec/services/projects/create_service_spec.rb@@ -70,5 +70,65 @@ RSpec.describe Projects::CreateService, type: :model do.not_to(have_received(:call))endend++ context "with hidden custom fields" do+ # Skip stubbing in order to execute the real service call+ let(:stub_model_instance) { false }+ let(:call_attributes) do+ attributes_for(:project,+ custom_field_values: {+ text_custom_field.id => "foo",+ bool_custom_field.id => true,+ hidden_custom_field.id => "hidden"+ }).except(:created_at, :updated_at)+ end+ let!(:section) { create(:project_custom_field_section) }+ let!(:bool_custom_field) do+ create(:boolean_project_custom_field, project_custom_field_section: section)+ end+ let!(:text_custom_field) do+ create(:text_project_custom_field, project_custom_field_section: section)+ end+ let!(:list_custom_field) do+ create(:list_project_custom_field, project_custom_field_section: section)+ end+ let!(:hidden_custom_field) do+ create(:text_project_custom_field, project_custom_field_section: section, visible: false)+ end+ let(:project) { subject.result }++ before do+ User.current = user+ end++ context "with admin permission" do+ let(:user) { build_stubbed(:admin) }++ it "does activate hidden custom fields" do+ subject+ expect(project.project_custom_field_project_mappings.pluck(:custom_field_id))+ .to contain_exactly(text_custom_field.id, bool_custom_field.id, hidden_custom_field.id)+ expect(project.custom_value_for(hidden_custom_field).typed_value).to eq("hidden")+ end+ end++ context "without admin permission" do+ let(:user) { create(:user) }++ before do+ mock_permissions_for(user) do |mock|+ mock.allow_globally :add_project+ end+ end++ it "does not activate hidden custom fields" do+ subject++ expect(project.project_custom_field_project_mappings.pluck(:custom_field_id))+ .to contain_exactly(text_custom_field.id, bool_custom_field.id)+ expect(project.custom_value_for(hidden_custom_field)).to be_nil+ end+ end+ endendend