From 2f1b8b8636055fda73f2f3269231398ed0a01312 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Thu, 22 Sep 2022 10:52:37 +0200
Subject: [PATCH 1/5] Remove duplicated code when loading modal window
---
.../issues/_modal_select_projects.html.erb | 30 +++++++++----------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/app/views/issues/_modal_select_projects.html.erb b/app/views/issues/_modal_select_projects.html.erb
index e8c51ae..e10f6b0 100644
--- a/app/views/issues/_modal_select_projects.html.erb
+++ b/app/views/issues/_modal_select_projects.html.erb
@@ -7,36 +7,36 @@
issue_projects = issue_projects | [@issue.project]
allowed_projects = @issue.allowed_target_projects - [@issue.project]
custom_fields = ProjectCustomField.where("name IN (?)", Setting["plugin_redmine_multiprojects_issue"]['custom_fields'])
+ custom_fields_ids = ProjectCustomField.where("name IN (?)", Setting["plugin_redmine_multiprojects_issue"]['custom_fields']).pluck(:id)
custom_values = custom_values_by_projects(allowed_projects, custom_fields)
options_for_selects = {}
- custom_fields.each do |field|
- options_for_selects.merge!(field.id => [])
+ custom_fields_ids.each do |field_id|
+ options_for_selects.merge!(field_id => [])
end
nested_projects_list = render_project_nested_lists(allowed_projects | issue_projects) do |project|
- custom_fields_data = {}
- if allowed_projects.include?(project)
- custom_fields.each do |cf|
- values = custom_values[project.id][cf.id]
+ project_allowed = allowed_projects.include?(project)
+ custom_fields_data = { 'name' => project.name }
+ if project_allowed
+ custom_fields_ids.each do |cf_id|
+ values = custom_values[project.id][cf_id]
if values.present?
values = [values] if values.kind_of?(String)
- custom_fields_data.merge!(cf.id => values.join('|'))
- values.each do |value|
- options_for_selects[cf.id] << value unless options_for_selects[cf.id].include?(value) || value.blank?
- end
+ values.reject!(&:blank?)
+ custom_fields_data.merge!(cf_id => values.join('|'))
+ options_for_selects[cf_id] |= values
end
end
end
- custom_fields_data.merge!('name' => project.name)
content_tag('label',
check_box_tag(
'project_ids[]',
project.id,
- @issue != nil && issue_projects.include?(project),
- disabled: allowed_projects.include?(project) ? false : true,
- :class => "nested_project_#{project.id} #{"inactive" unless allowed_projects.include?(project)}",
+ @issue.present? && issue_projects.include?(project),
+ disabled: !project_allowed,
+ :class => "nested_project_#{project.id} #{"inactive" unless project_allowed}",
data: custom_fields_data
- ) + ' ' + h(project.name), :class => ("inactive" unless allowed_projects.include?(project))
+ ) + ' ' + h(project.name), :class => ("inactive" unless project_allowed)
)
end
%>
From 8d75316c8de4bf09556b5d03e8033806e4034971 Mon Sep 17 00:00:00 2001
From: Vincent Robert
Date: Tue, 18 Jul 2023 16:34:42 +0200
Subject: [PATCH 2/5] Add missing dependency
---
spec/helpers/application_helper_patch_spec.rb | 1 +
1 file changed, 1 insertion(+)
diff --git a/spec/helpers/application_helper_patch_spec.rb b/spec/helpers/application_helper_patch_spec.rb
index 4632474..69c3aaa 100644
--- a/spec/helpers/application_helper_patch_spec.rb
+++ b/spec/helpers/application_helper_patch_spec.rb
@@ -1,5 +1,6 @@
require "spec_helper"
require 'redmine_multiprojects_issue/application_helper_patch'
+require 'erb' # to get "h" method
describe ApplicationHelper, type: :helper do
From 728e0669b38e7d702b3b2a64c6c510168e674faf Mon Sep 17 00:00:00 2001
From: Yalaeddin
Date: Wed, 19 Jul 2023 16:00:09 +0200
Subject: [PATCH 3/5] =?UTF-8?q?Consever=20les=20projets=20s=C3=A9lectionn?=
=?UTF-8?q?=C3=A9s=20lors=20de=20l'envoi=20d'une=20demande=20avec=20des=20?=
=?UTF-8?q?attributs=20invalides?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
app/views/issues/_select_projects.html.erb | 10 +++-
.../issues_controller_patch.rb | 3 +-
spec/system/issue_system_spec.rb | 58 +++++++++++++++++++
3 files changed, 68 insertions(+), 3 deletions(-)
create mode 100644 spec/system/issue_system_spec.rb
diff --git a/app/views/issues/_select_projects.html.erb b/app/views/issues/_select_projects.html.erb
index c6bd154..ff7c074 100644
--- a/app/views/issues/_select_projects.html.erb
+++ b/app/views/issues/_select_projects.html.erb
@@ -4,11 +4,17 @@
<% allowed_projects = @allowed_target_projects.present? ? @allowed_target_projects : @issue.allowed_target_projects %>
- <% select_options = project_tree_options_for_select((allowed_projects | @issue.projects) - [@issue.project], :selected => [@issue.project] | @issue.projects) %>
+
+ <% if @issue.assignable_projects.nil? %>
+ <% select_options = project_tree_options_for_select((allowed_projects | @issue.projects) - [@issue.project], :selected => [@issue.project] | @issue.projects) %>
+ <%= render 'projects_list', issue: @issue, selected_projects: @issue.projects, allowed_target_projects: allowed_projects %>
+ <% else %>
+ <% select_options = project_tree_options_for_select((allowed_projects | @issue.assignable_projects) - [@issue.project], :selected => [@issue.project] | @issue.assignable_projects) %>
+ <%= render 'projects_list', issue: @issue, selected_projects: @issue.assignable_projects, allowed_target_projects: allowed_projects %>
+ <% end %>
<%= f.select :project_ids, select_options, {:label => l("related_projects")},
{:multiple => true, style: "display:none;"} %>
- <%= render 'projects_list', issue: @issue, selected_projects: @issue.projects, allowed_target_projects: allowed_projects %>
<%= l('modify_projects')%>
diff --git a/lib/redmine_multiprojects_issue/issues_controller_patch.rb b/lib/redmine_multiprojects_issue/issues_controller_patch.rb
index d30b9ee..bbcec97 100644
--- a/lib/redmine_multiprojects_issue/issues_controller_patch.rb
+++ b/lib/redmine_multiprojects_issue/issues_controller_patch.rb
@@ -20,7 +20,8 @@ def load_projects_selection
issue_project_attribute = [@issue.project.id, @issue.project.name, @issue.project.status, @issue.project.lft, @issue.project.rgt]
@issue_projects_attributes_array = issue_projects_attributes_array | [issue_project_attribute]
- vals = Rails.env.test? ? JSON.parse(params[:allowed_projects]) : params[:allowed_projects].permit!.to_h.values
+ # This condition(Rails.env.test? && params[:format] == 'js') for the IssuesController test, by post method
+ vals = Rails.env.test? && params[:format] == 'js' ? JSON.parse(params[:allowed_projects]) : params[:allowed_projects].permit!.to_h.values
# convert to int
allowed_target_projects_attributes_array = vals.map do |id, name, status, lft, rgt|
[id.to_i, name, status.to_i, lft.to_i, rgt.to_i]
diff --git a/spec/system/issue_system_spec.rb b/spec/system/issue_system_spec.rb
new file mode 100644
index 0000000..0b14072
--- /dev/null
+++ b/spec/system/issue_system_spec.rb
@@ -0,0 +1,58 @@
+require "spec_helper"
+require "active_support/testing/assertions"
+
+RSpec.describe "/issue/id/edit", type: :system do
+ include ActiveSupport::Testing::Assertions
+
+ fixtures :projects, :users, :issues, :workflows, :members, :member_roles, :roles
+
+ before do
+ visit '/my/page'
+ expect(current_path).to eq '/login'
+
+ click_on("ou s'authentifier par login / mot de passe")
+
+ within('#login-form form') do
+ fill_in 'username', with: 'admin'
+ fill_in 'password', with: 'admin'
+ find('input[name=login]').click
+ end
+ expect(current_path).to eq '/my/page'
+ end
+
+ describe "Fail validation of issue" do
+ let!(:issue) { Issue.first }
+
+ it "Should keep the selected projects" do
+ # Related projects 0
+ expect(issue.projects.count).to eq(0)
+
+ visit edit_issue_path( id: issue.id)
+ # open Related projects modal
+ find('#loadModalProjectsSelection').click
+
+ within '#ajax-modal' do
+ # select projects with id 3 , 5
+ find("input[value='5']").click
+ find("input[value='3']").click
+
+ find("input[id='button_apply_projects']").click
+ end
+
+ # Make fail validation
+ fill_in 'issue_subject', with: ''
+ find("input[id='edit-submit']").click
+
+ expect(page).to have_selector("span", text: "#{Project.find(3).name}")
+ expect(page).to have_selector("span", text: "#{Project.find(5).name}")
+
+ # Remake succes validation
+ fill_in 'issue_subject', with: 'test'
+ find("input[id='edit-submit']").click
+
+ # Related projects 2
+ expect(issue.projects.count).to eq(2)
+ end
+
+ end
+end
From b11085ada15b17850056c9d81f699d240bede8fc Mon Sep 17 00:00:00 2001
From: Yalaeddin
Date: Wed, 19 Jul 2023 16:14:34 +0200
Subject: [PATCH 4/5] =?UTF-8?q?Utiliser=20la=20m=C3=A9thode=20log=5Fuser?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
spec/system/issue_system_spec.rb | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/spec/system/issue_system_spec.rb b/spec/system/issue_system_spec.rb
index 0b14072..a60f805 100644
--- a/spec/system/issue_system_spec.rb
+++ b/spec/system/issue_system_spec.rb
@@ -7,21 +7,11 @@
fixtures :projects, :users, :issues, :workflows, :members, :member_roles, :roles
before do
- visit '/my/page'
- expect(current_path).to eq '/login'
-
- click_on("ou s'authentifier par login / mot de passe")
-
- within('#login-form form') do
- fill_in 'username', with: 'admin'
- fill_in 'password', with: 'admin'
- find('input[name=login]').click
- end
- expect(current_path).to eq '/my/page'
+ log_user('admin', 'admin')
end
describe "Fail validation of issue" do
- let!(:issue) { Issue.first }
+ let!(:issue) { Issue.first }
it "Should keep the selected projects" do
# Related projects 0
From dc458ac7a5a356785a47f03c89047f2db05e26a4 Mon Sep 17 00:00:00 2001
From: Yalaeddin
Date: Thu, 20 Jul 2023 09:51:07 +0200
Subject: [PATCH 5/5] =?UTF-8?q?Ajouter=20la=20m=C3=A9thode=20log=5Fuser=20?=
=?UTF-8?q?dans=20le=20test=20de=20syst=C3=A8me?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
spec/system/issue_system_spec.rb | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/spec/system/issue_system_spec.rb b/spec/system/issue_system_spec.rb
index a60f805..5cef074 100644
--- a/spec/system/issue_system_spec.rb
+++ b/spec/system/issue_system_spec.rb
@@ -6,6 +6,22 @@
fixtures :projects, :users, :issues, :workflows, :members, :member_roles, :roles
+ def log_user(login, password)
+ visit '/my/page'
+ expect(current_path).to eq '/login'
+
+ if Redmine::Plugin.installed?(:redmine_scn)
+ click_on("ou s'authentifier par login / mot de passe")
+ end
+
+ within('#login-form form') do
+ fill_in 'username', with: login
+ fill_in 'password', with: password
+ find('input[name=login]').click
+ end
+ expect(current_path).to eq '/my/page'
+ end
+
before do
log_user('admin', 'admin')
end
@@ -31,14 +47,15 @@
# Make fail validation
fill_in 'issue_subject', with: ''
- find("input[id='edit-submit']").click
+
+ find("input[name='commit']").click
expect(page).to have_selector("span", text: "#{Project.find(3).name}")
expect(page).to have_selector("span", text: "#{Project.find(5).name}")
# Remake succes validation
fill_in 'issue_subject', with: 'test'
- find("input[id='edit-submit']").click
+ find("input[name='commit']").click
# Related projects 2
expect(issue.projects.count).to eq(2)