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
added project creation and copy feature specs around project custom fields and their activation
Jonas Jabari5101a41ad589
diff --git a/spec/features/projects/copy_spec.rb b/spec/features/projects/copy_spec.rbindex 9ea35aab52b..54da1af6663 100644--- a/spec/features/projects/copy_spec.rb+++ b/spec/features/projects/copy_spec.rb@@ -35,7 +35,12 @@ RSpec.describe 'Projects copy', :js, :with_cuprite doparent: parent_project,types: active_types,members: { user => role },- custom_field_values: { project_custom_field.id => 'some text cf' }).tap do |p|+ # custom_fields which are not used below are not activated for this project+ custom_field_values: {+ project_custom_field.id => 'some text cf',+ optional_project_custom_field.id => 'some optional text cf',+ optional_project_custom_field_with_default.id => 'foo'+ }).tap do |p|p.work_package_custom_fields << wp_custom_fieldp.types.first.custom_fields << wp_custom_field@@ -56,6 +61,12 @@ RSpec.describe 'Projects copy', :js, :with_cuprite dolet!(:project_custom_field) docreate(:text_project_custom_field, is_required: true)end+ let!(:optional_project_custom_field) do+ create(:text_project_custom_field, is_required: false)+ end+ let!(:optional_project_custom_field_with_default) do+ create(:text_project_custom_field, is_required: false, default_value: 'foo')+ endlet!(:wp_custom_field) docreate(:text_wp_custom_field)end@@ -140,6 +151,137 @@ RSpec.describe 'Projects copy', :js, :with_cuprite doclear_performed_jobsend+ context 'with correct project custom field activations' do+ before do+ original_settings_page = Pages::Projects::Settings.new(project)+ original_settings_page.visit!++ find('.toolbar a', text: 'Copy').click++ expect(page).to have_text "Copy project \"#{project.name}\""++ fill_in 'Name', with: 'Copied project'+ end++ it 'enables the same project custom fields as activated on the source project if untouched' do+ expect(project.project_custom_field_ids).to contain_exactly(+ project_custom_field.id,+ optional_project_custom_field.id,+ optional_project_custom_field_with_default.id+ )++ click_button 'Save'++ wait_for_copy_to_finish++ copied_project = Project.find_by(name: 'Copied project')++ expect(copied_project.project_custom_field_ids).to contain_exactly(+ project_custom_field.id,+ optional_project_custom_field.id,+ optional_project_custom_field_with_default.id+ )+ end++ it 'disables optional project custom fields if explicitly set to blank' do+ # Expand advanced settings+ click_on 'Advanced settings'++ editor = Components::WysiwygEditor.new "[data-qa-field-name='customField#{optional_project_custom_field.id}']"+ editor.clear++ click_button 'Save'++ wait_for_copy_to_finish++ copied_project = Project.find_by(name: 'Copied project')++ expect(copied_project.project_custom_field_ids).to contain_exactly(+ project_custom_field.id,+ optional_project_custom_field_with_default.id+ )+ end++ # TBD: Is this intended from a conceptial point of view?+ #+ # If not, I don't know how to change this behavior while keeping the behavior specified in the creation spec where+ # optional custom fields are not activated if the value is set to blank in the form (which seems to be desired from+ # a concpetional point of view)+ it 'does not enable project custom fields (with default values) if set to blank in source project' do+ project.update!(custom_field_values: {+ optional_project_custom_field.id => '',+ optional_project_custom_field_with_default.id => ''+ })++ # the optional custom fields are activated, but set to blank values+ expect(project.project_custom_field_ids).to contain_exactly(+ project_custom_field.id,+ optional_project_custom_field.id,+ optional_project_custom_field_with_default.id+ )++ original_settings_page = Pages::Projects::Settings.new(project)+ original_settings_page.visit!++ find('.toolbar a', text: 'Copy').click++ expect(page).to have_text "Copy project \"#{project.name}\""++ fill_in 'Name', with: 'Copied project'++ click_button 'Save'++ wait_for_copy_to_finish++ copied_project = Project.find_by(name: 'Copied project')++ expect(copied_project.project_custom_field_ids).to contain_exactly(+ project_custom_field.id+ )+ end++ context 'with project custom fields with default values, which are disabled in source project' do+ let!(:optional_boolean_project_custom_field_with_default) do+ create(:boolean_project_custom_field, is_required: false, default_value: true)+ end+ let!(:optional_string_project_custom_field_with_default) do+ create(:string_project_custom_field, is_required: false, default_value: 'bar')+ end++ # TBD: Is this intended from a conceptial point of view?+ #+ # If not, I don't know how to change this behavior while keeping the behavior specified in the creation spec where+ # optional custom fields with default values are activated if the value is untouched in the form (which seems to be desired from+ # a concpetional point of view)+ it 'does enable optional project custom fields with default values although not enabled in source project' do+ # the optional boolean and string fields are not activated in the source project+ expect(project.project_custom_field_ids).to contain_exactly(+ project_custom_field.id,+ optional_project_custom_field.id,+ optional_project_custom_field_with_default.id+ )++ click_button 'Save'++ wait_for_copy_to_finish++ copied_project = Project.find_by(name: 'Copied project')++ # the optional boolean and string fields are activated in the copied project with their default values+ expect(copied_project.project_custom_field_ids).to contain_exactly(+ project_custom_field.id,+ optional_project_custom_field.id,+ optional_project_custom_field_with_default.id,+ optional_boolean_project_custom_field_with_default.id,+ optional_string_project_custom_field_with_default.id+ )++ expect(copied_project.custom_value_for(optional_boolean_project_custom_field_with_default).typed_value).to be_truthy+ expect(copied_project.custom_value_for(optional_string_project_custom_field_with_default).typed_value).to eq('bar')+ end+ end+ end+it 'copies projects and the associated objects' dooriginal_settings_page = Pages::Projects::Settings.new(project)original_settings_page.visit!@@ -159,11 +301,7 @@ RSpec.describe 'Projects copy', :js, :with_cuprite doclick_button 'Save'- expect(page).to have_text 'The job has been queued and will be processed shortly.'-- # ensure all jobs are run especially emails which might be sent later on- while perform_enqueued_jobs > 0- end+ wait_for_copy_to_finishcopied_project = Project.find_by(name: 'Copied project')@@ -300,4 +438,12 @@ RSpec.describe 'Projects copy', :js, :with_cuprite dowp_table.expect_work_package_order *orderendend++ def wait_for_copy_to_finish+ expect(page).to have_text 'The job has been queued and will be processed shortly.'++ # ensure all jobs are run especially emails which might be sent later on+ while perform_enqueued_jobs > 0+ end+ endenddiff --git a/spec/features/projects/create_spec.rb b/spec/features/projects/create_spec.rbindex 0993bbc731a..9ecb723e610 100644--- a/spec/features/projects/create_spec.rb+++ b/spec/features/projects/create_spec.rb@@ -136,6 +136,19 @@ RSpec.describe 'Projects', 'creation',endend+ context 'with correct validations' do+ before do+ visit new_project_path+ end++ it 'requires the required custom field' do+ click_on 'Save'++ expect(page).to have_content "Required Foo can't be blank"+ expect(page).to have_no_content "Optional Foo can't be blank"+ end+ end+context 'with correct custom field activation' dolet!(:unused_custom_field) docreate(:custom_field, name: 'Unused Foo',@@ -235,6 +248,82 @@ RSpec.describe 'Projects', 'creation',expect(project.custom_value_for(custom_field_with_default_value).value).to eq('foo')endend++ context 'with correct handling of optional boolean values' do+ let!(:custom_boolean_field_default_true) do+ create(:custom_field, name: 'Boolean with default true',+ field_format: 'bool',+ default_value: true,+ type: ProjectCustomField,+ is_for_all: true)+ end++ let!(:custom_boolean_field_with_no_default) do+ create(:custom_field, name: 'Boolean with no default',+ field_format: 'bool',+ type: ProjectCustomField,+ is_for_all: true)+ end++ before do+ visit new_project_path+ fill_in 'Name', with: 'Foo bar'+ fill_in 'Required Foo', with: 'Required value'++ click_on 'Advanced settings'+ end++ it 'only enables boolean custom fields with default values if untouched' do+ # do not touch any of the boolean fields+ click_on 'Save'++ expect(page).to have_current_path /\/projects\/foo-bar\/?/++ project = Project.last++ # custom_field_with_default_value should be activated and contain the overwritten value+ expect(project.project_custom_field_ids).to contain_exactly(+ required_custom_field.id, custom_boolean_field_default_true.id+ )++ expect(project.custom_value_for(custom_boolean_field_default_true).typed_value).to be_truthy+ end++ it 'enables boolean custom fields without default values if set to true explicitly' do+ check 'Boolean with no default'++ click_on 'Save'++ expect(page).to have_current_path /\/projects\/foo-bar\/?/++ project = Project.last++ # custom_field_with_default_value should be activated and contain the overwritten value+ expect(project.project_custom_field_ids).to contain_exactly(+ required_custom_field.id, custom_boolean_field_default_true.id, custom_boolean_field_with_no_default.id+ )++ expect(project.custom_value_for(custom_boolean_field_default_true).typed_value).to be_truthy+ expect(project.custom_value_for(custom_boolean_field_with_no_default).typed_value).to be_truthy+ end++ it 'enables boolean custom fields with default values if set to false explicitly' do+ uncheck 'Boolean with default true'++ click_on 'Save'++ expect(page).to have_current_path /\/projects\/foo-bar\/?/++ project = Project.last++ # custom_field_with_default_value should be activated and contain the overwritten value+ expect(project.project_custom_field_ids).to contain_exactly(+ required_custom_field.id, custom_boolean_field_default_true.id+ )++ expect(project.custom_value_for(custom_boolean_field_default_true).typed_value).to be_falsy+ end+ endendendend